/** * @license * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ const t="170dev",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},s={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,n=2,o=3,a=0,h=1,u=2,l=3,c=0,d=1,p=2,m=0,g=1,f=2,y=3,x=4,b=5,v=100,T=101,_=102,w=103,S=104,M=200,A=201,N=202,C=203,R=204,E=205,B=206,I=207,P=208,F=209,U=210,O=211,z=212,L=213,V=214,D=0,k=1,G=2,W=3,j=4,H=5,$=6,q=7,X=0,Y=1,Z=2,J=0,K=1,Q=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,ut=302,lt=303,ct=304,dt=306,pt=1e3,mt=1001,gt=1002,ft=1003,yt=1004,xt=1004,bt=1005,vt=1005,Tt=1006,_t=1007,wt=1007,St=1008,Mt=1008,At=1009,Nt=1010,Ct=1011,Rt=1012,Et=1013,Bt=1014,It=1015,Pt=1016,Ft=1017,Ut=1018,Ot=1020,zt=35902,Lt=1021,Vt=1022,Dt=1023,kt=1024,Gt=1025,Wt=1026,jt=1027,Ht=1028,$t=1029,qt=1030,Xt=1031,Yt=1032,Zt=1033,Jt=33776,Kt=33777,Qt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,ue=37809,le=37810,ce=37811,de=37812,pe=37813,me=37814,ge=37815,fe=37816,ye=37817,xe=37818,be=37819,ve=37820,Te=37821,_e=36492,we=36494,Se=36495,Me=36283,Ae=36284,Ne=36285,Ce=36286,Re=2200,Ee=2201,Be=2202,Ie=2300,Pe=2301,Fe=2302,Ue=2400,Oe=2401,ze=2402,Le=2500,Ve=2501,De=0,ke=1,Ge=2,We=3200,je=3201,He=3202,$e=3203,qe=0,Xe=1,Ye="",Ze="srgb",Je="srgb-linear",Ke="linear",Qe="srgb",ts=0,es=7680,ss=7681,is=7682,rs=7683,ns=34055,os=34056,as=5386,hs=512,us=513,ls=514,cs=515,ds=516,ps=517,ms=518,gs=519,fs=512,ys=513,xs=514,bs=515,vs=516,Ts=517,_s=518,ws=519,Ss=35044,Ms=35048,As=35040,Ns=35045,Cs=35049,Rs=35041,Es=35046,Bs=35050,Is=35042,Ps="100",Fs="300 es",Us=2e3,Os=2001;class zs{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[t]&&-1!==s[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const s=this._listeners[t];if(void 0!==s){const t=s.indexOf(e);-1!==t&&s.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 s=e.slice(0);for(let e=0,i=s.length;e>8&255]+Ls[t>>16&255]+Ls[t>>24&255]+"-"+Ls[255&e]+Ls[e>>8&255]+"-"+Ls[e>>16&15|64]+Ls[e>>24&255]+"-"+Ls[63&s|128]+Ls[s>>8&255]+"-"+Ls[s>>16&255]+Ls[s>>24&255]+Ls[255&i]+Ls[i>>8&255]+Ls[i>>16&255]+Ls[i>>24&255]).toLowerCase()}function Ws(t,e,s){return Math.max(e,Math.min(s,t))}function js(t,e){return(t%e+e)%e}function Hs(t,e,s){return(1-s)*t+s*e}function $s(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 qs(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 Xs={DEG2RAD:Ds,RAD2DEG:ks,generateUUID:Gs,clamp:Ws,euclideanModulo:js,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:Hs,damp:function(t,e,s,i){return Hs(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(js(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-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&&(Vs=t);let e=Vs+=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*Ds},radToDeg:function(t){return t*ks},isPowerOfTwo:function(t){return 0==(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,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((e+i)/2),l=o((e+i)/2),c=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*l,h*c,h*d,a*u);break;case"YZY":t.set(h*d,a*l,h*c,a*u);break;case"ZXZ":t.set(h*c,h*d,a*l,a*u);break;case"XZX":t.set(a*l,h*m,h*p,a*u);break;case"YXY":t.set(h*p,a*l,h*m,a*u);break;case"ZYZ":t.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:qs,denormalize:$s};class Ys{constructor(t=0,e=0){Ys.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,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+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 s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}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 s=this.dot(t)/e;return Math.acos(Ws(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,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 s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Zs{constructor(t,e,s,i,r,n,o,a,h){Zs.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const u=this.elements;return u[0]=t,u[1]=i,u[2]=o,u[3]=e,u[4]=r,u[5]=a,u[6]=s,u[7]=n,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.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 s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],u=s[4],l=s[7],c=s[2],d=s[5],p=s[8],m=i[0],g=i[3],f=i[6],y=i[1],x=i[4],b=i[7],v=i[2],T=i[5],_=i[8];return r[0]=n*m+o*y+a*v,r[3]=n*g+o*x+a*T,r[6]=n*f+o*b+a*_,r[1]=h*m+u*y+l*v,r[4]=h*g+u*x+l*T,r[7]=h*f+u*b+l*_,r[2]=c*m+d*y+p*v,r[5]=c*g+d*x+p*T,r[8]=c*f+d*b+p*_,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],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8];return e*n*u-e*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=e*l+s*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(i*h-u*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(u*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*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,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(Js.makeScale(t,e)),this}rotate(t){return this.premultiply(Js.makeRotation(-t)),this}translate(t,e){return this.premultiply(Js.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),s=Math.sin(t);return this.set(e,-s,0,s,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,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const Js=new Zs;const Ks={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function Qs(t,e){return new Ks[t](e)}function ti(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ei(){const t=ti("canvas");return t.style.display="block",t}const si={};const ii={enabled:!0,workingColorSpace:Je,spaces:{},convert:function(t,e,s){return!1!==this.enabled&&e!==s&&e&&s?(this.spaces[e].transfer===Qe&&(t.r=ri(t.r),t.g=ri(t.g),t.b=ri(t.b)),this.spaces[e].primaries!==this.spaces[s].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[s].fromXYZ)),this.spaces[s].transfer===Qe&&(t.r=ni(t.r),t.g=ni(t.g),t.b=ni(t.b)),t):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 this.spaces[t].primaries},getTransfer:function(t){return t===Ye?Ke:this.spaces[t].transfer},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,s){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[s].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}};function ri(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function ni(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}const oi=[.64,.33,.3,.6,.15,.06],ai=[.2126,.7152,.0722],hi=[.3127,.329],ui=(new Zs).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),li=(new Zs).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);let ci;ii.define({[Je]:{primaries:oi,whitePoint:hi,transfer:Ke,toXYZ:ui,fromXYZ:li,luminanceCoefficients:ai,workingColorSpaceConfig:{unpackColorSpace:Ze},outputColorSpaceConfig:{drawingBufferColorSpace:Ze}},[Ze]:{primaries:oi,whitePoint:hi,transfer:Qe,toXYZ:ui,fromXYZ:li,luminanceCoefficients:ai,outputColorSpaceConfig:{drawingBufferColorSpace:Ze}}});class di{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===ci&&(ci=ti("canvas")),ci.width=t.width,ci.height=t.height;const s=ci.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=ci}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=ti("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)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 gt: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 gt: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++}}yi.DEFAULT_IMAGE=null,yi.DEFAULT_MAPPING=at,yi.DEFAULT_ANISOTROPY=1;class xi{constructor(t=0,e=0,s=0,i=1){xi.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,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,s,i){return this.x=t,this.y=e,this.z=s,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,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,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,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],u=a[4],l=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(u-c)a&&t>y?ty?a=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+c*r,h=h*t+d*r,u=u*t+p*r,l=l*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=t,h*=t,u*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=u,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],u=s[i+3],l=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+u*l+a*d-h*c,t[e+1]=a*p+u*c+h*l-o*d,t[e+2]=h*p+u*d+o*c-a*l,t[e+3]=u*p-o*l-a*c-h*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,s,i){return this._x=t,this._y=e,this._z=s,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 s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),u=o(i/2),l=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"YXZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"ZXY":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"ZYX":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"YZX":this._x=c*u*l+h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l-c*d*p;break;case"XZY":this._x=c*u*l-h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],u=e[6],l=e[10],c=s+o+l;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(u-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(u-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+u)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+u)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return sMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(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=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Ws(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);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 s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,u=e._w;return this._x=s*u+n*o+i*h-r*a,this._y=i*u+n*a+r*o-s*h,this._z=r*u+n*h+s*a-i*o,this._w=n*u-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-e)*u)/h,c=Math.sin(e*u)/h;return this._w=n*l+this._w*c,this._x=s*l+this._x*c,this._y=i*l+this._y*c,this._z=r*l+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*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 Ai{constructor(t=0,e=0,s=0){Ai.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,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(Ci.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ci.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),u=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*u,this.y=s+a*u+o*h-r*l,this.z=i+a*l+r*u-n*h,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,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[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 s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Ni.copy(this).projectOnVector(t),this.sub(Ni)}reflect(t){return this.sub(Ni.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 s=this.dot(t)/e;return Math.acos(Ws(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+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,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,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(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,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,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ni=new Ai,Ci=new Mi;class Ri{constructor(t=new Ai(1/0,1/0,1/0),e=new Ai(-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,s=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,Bi),Bi.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Vi),Di.subVectors(this.max,Vi),Pi.subVectors(t.a,Vi),Fi.subVectors(t.b,Vi),Ui.subVectors(t.c,Vi),Oi.subVectors(Fi,Pi),zi.subVectors(Ui,Fi),Li.subVectors(Pi,Ui);let e=[0,-Oi.z,Oi.y,0,-zi.z,zi.y,0,-Li.z,Li.y,Oi.z,0,-Oi.x,zi.z,0,-zi.x,Li.z,0,-Li.x,-Oi.y,Oi.x,0,-zi.y,zi.x,0,-Li.y,Li.x,0];return!!Wi(e,Pi,Fi,Ui,Di)&&(e=[1,0,0,0,1,0,0,0,1],!!Wi(e,Pi,Fi,Ui,Di)&&(ki.crossVectors(Oi,zi),e=[ki.x,ki.y,ki.z],Wi(e,Pi,Fi,Ui,Di)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Bi).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Bi).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()||(Ei[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ei[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ei[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ei[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ei[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ei[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ei[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ei[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ei)),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 Ei=[new Ai,new Ai,new Ai,new Ai,new Ai,new Ai,new Ai,new Ai],Bi=new Ai,Ii=new Ri,Pi=new Ai,Fi=new Ai,Ui=new Ai,Oi=new Ai,zi=new Ai,Li=new Ai,Vi=new Ai,Di=new Ai,ki=new Ai,Gi=new Ai;function Wi(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){Gi.fromArray(t,n);const o=r.x*Math.abs(Gi.x)+r.y*Math.abs(Gi.y)+r.z*Math.abs(Gi.z),a=e.dot(Gi),h=s.dot(Gi),u=i.dot(Gi);if(Math.max(-Math.max(a,h,u),Math.min(a,h,u))>o)return!1}return!0}const ji=new Ri,Hi=new Ai,$i=new Ai;class qi{constructor(t=new Ai,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 s=this.center;void 0!==e?s.copy(e):ji.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=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;Hi.subVectors(t,this.center);const e=Hi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Hi,s/t),this.radius+=s}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):($i.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Hi.copy(t.center).add($i)),this.expandByPoint(Hi.copy(t.center).sub($i))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Xi=new Ai,Yi=new Ai,Zi=new Ai,Ji=new Ai,Ki=new Ai,Qi=new Ai,tr=new Ai;class er{constructor(t=new Ai,e=new Ai(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,Xi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Xi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Xi.copy(this.origin).addScaledVector(this.direction,e),Xi.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Yi.copy(t).add(e).multiplyScalar(.5),Zi.copy(e).sub(t).normalize(),Ji.copy(this.origin).sub(Yi);const r=.5*t.distanceTo(e),n=-this.direction.dot(Zi),o=Ji.dot(this.direction),a=-Ji.dot(Zi),h=Ji.lengthSq(),u=Math.abs(1-n*n);let l,c,d,p;if(u>0)if(l=n*a-o,c=n*o-a,p=r*u,l>=0)if(c>=-p)if(c<=p){const t=1/u;l*=t,c*=t,d=l*(l+n*c+2*o)+c*(n*l+c+2*a)+h}else c=r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c=-r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c<=-p?(l=Math.max(0,-(-n*r+o)),c=l>0?-r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h):c<=p?(l=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(l=Math.max(0,-(n*r+o)),c=l>0?r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h);else c=n>0?-r:r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,l),i&&i.copy(Yi).addScaledVector(Zi,c),d}intersectSphere(t,e){Xi.subVectors(t.center,this.origin);const s=Xi.dot(this.direction),i=Xi.dot(Xi)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,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 s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,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 s,i,r,n,o,a;const h=1/this.direction.x,u=1/this.direction.y,l=1/this.direction.z,c=this.origin;return h>=0?(s=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(s=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),u>=0?(r=(t.min.y-c.y)*u,n=(t.max.y-c.y)*u):(r=(t.max.y-c.y)*u,n=(t.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n=0?(o=(t.min.z-c.z)*l,a=(t.max.z-c.z)*l):(o=(t.max.z-c.z)*l,a=(t.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,Xi)}intersectTriangle(t,e,s,i,r){Ki.subVectors(e,t),Qi.subVectors(s,t),tr.crossVectors(Ki,Qi);let n,o=this.direction.dot(tr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}Ji.subVectors(this.origin,t);const a=n*this.direction.dot(Qi.crossVectors(Ji,Qi));if(a<0)return null;const h=n*this.direction.dot(Ki.cross(Ji));if(h<0)return null;if(a+h>o)return null;const u=-n*Ji.dot(tr);return u<0?null:this.at(u/o,r)}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 sr{constructor(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){sr.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,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=u,f[10]=l,f[14]=c,f[3]=d,f[7]=p,f[11]=m,f[15]=g,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 sr).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[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,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/ir.setFromMatrixColumn(t,0).length(),r=1/ir.setFromMatrixColumn(t,1).length(),n=1/ir.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),u=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*u,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*u,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*u,e[9]=-o*u,e[2]=-h*u,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=-l,e[8]=h*u,e[1]=t*l+r,e[5]=n*u,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*u,e[10]=r*l+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(nr,t,or)}lookAt(t,e,s){const i=this.elements;return ur.subVectors(t,e),0===ur.lengthSq()&&(ur.z=1),ur.normalize(),ar.crossVectors(s,ur),0===ar.lengthSq()&&(1===Math.abs(s.z)?ur.x+=1e-4:ur.z+=1e-4,ur.normalize(),ar.crossVectors(s,ur)),ar.normalize(),hr.crossVectors(ur,ar),i[0]=ar.x,i[4]=hr.x,i[8]=ur.x,i[1]=ar.y,i[5]=hr.y,i[9]=ur.y,i[2]=ar.z,i[6]=hr.z,i[10]=ur.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],u=s[1],l=s[5],c=s[9],d=s[13],p=s[2],m=s[6],g=s[10],f=s[14],y=s[3],x=s[7],b=s[11],v=s[15],T=i[0],_=i[4],w=i[8],S=i[12],M=i[1],A=i[5],N=i[9],C=i[13],R=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],U=i[11],O=i[15];return r[0]=n*T+o*M+a*R+h*P,r[4]=n*_+o*A+a*E+h*F,r[8]=n*w+o*N+a*B+h*U,r[12]=n*S+o*C+a*I+h*O,r[1]=u*T+l*M+c*R+d*P,r[5]=u*_+l*A+c*E+d*F,r[9]=u*w+l*N+c*B+d*U,r[13]=u*S+l*C+c*I+d*O,r[2]=p*T+m*M+g*R+f*P,r[6]=p*_+m*A+g*E+f*F,r[10]=p*w+m*N+g*B+f*U,r[14]=p*S+m*C+g*I+f*O,r[3]=y*T+x*M+b*R+v*P,r[7]=y*_+x*A+b*E+v*F,r[11]=y*w+x*N+b*B+v*U,r[15]=y*S+x*C+b*I+v*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],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],u=t[2],l=t[6],c=t[10],d=t[14];return t[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+t[11]*(+e*h*l-e*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+t[15]*(-i*o*u-e*a*l+e*o*c+i*n*l-s*n*c+s*a*u)}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,s){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]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=l*g*h-m*c*h+m*a*d-o*g*d-l*a*f+o*c*f,x=p*c*h-u*g*h-p*a*d+n*g*d+u*a*f-n*c*f,b=u*m*h-p*l*h+p*o*d-n*m*d-u*o*f+n*l*f,v=p*l*a-u*m*a-p*o*c+n*m*c+u*o*g-n*l*g,T=e*y+s*x+i*b+r*v;if(0===T)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/T;return t[0]=y*_,t[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,t[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,t[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(u*g*r-p*c*r+p*i*d-e*g*d-u*i*f+e*c*f)*_,t[6]=(p*a*r-n*g*r-p*i*h+e*g*h+n*i*f-e*a*f)*_,t[7]=(n*c*r-u*a*r+u*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*l*r-u*m*r-p*s*d+e*m*d+u*s*f-e*l*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(u*o*r-n*l*r-u*s*h+e*l*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(u*m*i-p*l*i+p*s*c-e*m*c-u*s*g+e*l*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*l*i-u*o*i+u*s*a-e*l*a-n*s*c+e*o*c)*_,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=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,s,i))}makeTranslation(t,e,s){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,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,u=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,u*o+s,u*a-i*n,0,h*a-i*o,u*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,u=n+n,l=o+o,c=r*h,d=r*u,p=r*l,m=n*u,g=n*l,f=o*l,y=a*h,x=a*u,b=a*l,v=s.x,T=s.y,_=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*T,i[5]=(1-(c+f))*T,i[6]=(g+y)*T,i[7]=0,i[8]=(p+x)*_,i[9]=(g-y)*_,i[10]=(1-(c+m))*_,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=ir.set(i[0],i[1],i[2]).length();const n=ir.set(i[4],i[5],i[6]).length(),o=ir.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],rr.copy(this);const a=1/r,h=1/n,u=1/o;return rr.elements[0]*=a,rr.elements[1]*=a,rr.elements[2]*=a,rr.elements[4]*=h,rr.elements[5]*=h,rr.elements[6]*=h,rr.elements[8]*=u,rr.elements[9]*=u,rr.elements[10]*=u,e.setFromRotationMatrix(rr),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),u=2*r/(s-i),l=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===Us)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Os)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=l,a[12]=0,a[1]=0,a[5]=u,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),u=1/(s-i),l=1/(n-r),c=(e+t)*h,d=(s+i)*u;let p,m;if(o===Us)p=(n+r)*l,m=-2*l;else{if(o!==Os)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*l,m=-1*l}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*u,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const ir=new Ai,rr=new sr,nr=new Ai(0,0,0),or=new Ai(1,1,1),ar=new Ai,hr=new Ai,ur=new Ai,lr=new sr,cr=new Mi;class dr{constructor(t=0,e=0,s=0,i=dr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,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,s,i=this._order){return this._x=t,this._y=e,this._z=s,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,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],u=i[9],l=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Ws(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-Ws(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(Ws(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-Ws(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(Ws(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-Ws(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return lr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(lr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return cr.setFromEuler(this),this.setFromQuaternion(cr,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}}dr.DEFAULT_ORDER="XYZ";class pr{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=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),u.length>0&&(s.animations=u),l.length>0&&(s.nodes=l)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];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(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Er.subVectors(i,e),Br.subVectors(s,e),Ir.subVectors(t,e);const n=Er.dot(Er),o=Er.dot(Br),a=Er.dot(Ir),h=Br.dot(Br),u=Br.dot(Ir),l=n*h-o*o;if(0===l)return r.set(0,0,0),null;const c=1/l,d=(h*a-o*u)*c,p=(n*u-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,Pr)&&(Pr.x>=0&&Pr.y>=0&&Pr.x+Pr.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Pr)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,Pr.x),a.addScaledVector(n,Pr.y),a.addScaledVector(o,Pr.z),a)}static getInterpolatedAttribute(t,e,s,i,r,n){return Dr.setScalar(0),kr.setScalar(0),Gr.setScalar(0),Dr.fromBufferAttribute(t,e),kr.fromBufferAttribute(t,s),Gr.fromBufferAttribute(t,i),n.setScalar(0),n.addScaledVector(Dr,r.x),n.addScaledVector(kr,r.y),n.addScaledVector(Gr,r.z),n}static isFrontFacing(t,e,s,i){return Er.subVectors(s,e),Br.subVectors(t,e),Er.cross(Br).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),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 Er.subVectors(this.c,this.b),Br.subVectors(this.a,this.b),.5*Er.cross(Br).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Wr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Wr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return Wr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return Wr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Wr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;Fr.subVectors(i,s),Ur.subVectors(r,s),zr.subVectors(t,s);const a=Fr.dot(zr),h=Ur.dot(zr);if(a<=0&&h<=0)return e.copy(s);Lr.subVectors(t,i);const u=Fr.dot(Lr),l=Ur.dot(Lr);if(u>=0&&l<=u)return e.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),e.copy(s).addScaledVector(Fr,n);Vr.subVectors(t,r);const d=Fr.dot(Vr),p=Ur.dot(Vr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Ur,o);const g=u*p-d*l;if(g<=0&&l-u>=0&&d-p>=0)return Or.subVectors(r,i),o=(l-u)/(l-u+(d-p)),e.copy(i).addScaledVector(Or,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(Fr,n).addScaledVector(Ur,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const jr={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},Hr={h:0,s:0,l:0},$r={h:0,s:0,l:0};function qr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class Xr{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){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,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Ze){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,ii.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=ii.workingColorSpace){return this.r=t,this.g=e,this.b=s,ii.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=ii.workingColorSpace){if(t=js(t,1),e=Ws(e,0,1),s=Ws(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=qr(r,i,t+1/3),this.g=qr(r,i,t),this.b=qr(r,i,t-1/3)}return ii.toWorkingColorSpace(this,i),this}setStyle(t,e=Ze){function s(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 r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,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=Ze){const s=jr[t.toLowerCase()];return void 0!==s?this.setHex(s,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=ri(t.r),this.g=ri(t.g),this.b=ri(t.b),this}copyLinearToSRGB(t){return this.r=ni(t.r),this.g=ni(t.g),this.b=ni(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Ze){return ii.fromWorkingColorSpace(Yr.copy(this),t),65536*Math.round(Ws(255*Yr.r,0,255))+256*Math.round(Ws(255*Yr.g,0,255))+Math.round(Ws(255*Yr.b,0,255))}getHexString(t=Ze){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ii.workingColorSpace){ii.fromWorkingColorSpace(Yr.copy(this),e);const s=Yr.r,i=Yr.g,r=Yr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const u=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=u<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s: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 s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==c&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),this.blendSrc!==R&&(s.blendSrc=this.blendSrc),this.blendDst!==E&&(s.blendDst=this.blendDst),this.blendEquation!==v&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==gs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==es&&(s.stencilFail=this.stencilFail),this.stencilZFail!==es&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==es&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}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 s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,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++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class Kr extends Jr{static get type(){return"MeshBasicMaterial"}constructor(t){super(),this.isMeshBasicMaterial=!0,this.color=new Xr(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 dr,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 Qr=tn();function tn(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function en(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=Ws(t,-65504,65504),Qr.floatView[0]=t;const e=Qr.uint32View[0],s=e>>23&511;return Qr.baseTable[s]+((8388607&e)>>Qr.shiftTable[s])}function sn(t){const e=t>>10;return Qr.uint32View[0]=Qr.mantissaTable[Qr.offsetTable[e]+(1023&t)]+Qr.exponentTable[e],Qr.floatView[0]}const rn={toHalfFloat:en,fromHalfFloat:sn},nn=new Ai,on=new Ys;class an{constructor(t,e,s=!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=s,this.usage=Ss,this.updateRanges=[],this.gpuType=It,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,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i=0;--e)if(t[e]>=65535)return!0;return!1}(t)?mn:dn)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const e=(new Zs).getNormalMatrix(t);s.applyNormalMatrix(e),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return xn.makeRotationFromQuaternion(t),this.applyMatrix4(xn),this}rotateX(t){return xn.makeRotationX(t),this.applyMatrix4(xn),this}rotateY(t){return xn.makeRotationY(t),this.applyMatrix4(xn),this}rotateZ(t){return xn.makeRotationZ(t),this.applyMatrix4(xn),this}translate(t,e,s){return xn.makeTranslation(t,e,s),this.applyMatrix4(xn),this}scale(t,e,s){return xn.makeScale(t,e,s),this.applyMatrix4(xn),this}lookAt(t){return bn.lookAt(t),bn.updateMatrix(),this.applyMatrix4(bn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(vn).negate(),this.translate(vn.x,vn.y,vn.z),this}setFromPoints(t){const e=[];for(let s=0,i=t.length;s0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);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 s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.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 s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t(t.far-t.near)**2)return}Mn.copy(r).invert(),An.copy(t.ray).applyMatrix4(Mn),null!==s.boundingBox&&!1===An.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,An)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,u=r.attributes.uv1,l=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=c.length;rs.far?null:{distance:u,point:Un.clone(),object:t}}(t,e,s,i,Rn,En,Bn,Fn);if(l){const t=new Ai;Wr.getBarycoord(Fn,Rn,En,Bn,t),r&&(l.uv=Wr.getInterpolatedAttribute(r,a,h,u,t,new Ys)),n&&(l.uv1=Wr.getInterpolatedAttribute(n,a,h,u,t,new Ys)),o&&(l.normal=Wr.getInterpolatedAttribute(o,a,h,u,t,new Ai),l.normal.dot(i.direction)>0&&l.normal.multiplyScalar(-1));const e={a:a,b:h,c:u,normal:new Ai,materialIndex:0};Wr.getNormal(Rn,En,Bn,e.normal),l.face=e,l.barycoord=t}return l}class Ln extends Sn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],u=[],l=[];let c=0,d=0;function p(t,e,s,i,r,n,p,m,g,f,y){const x=n/g,b=p/f,v=n/2,T=p/2,_=m/2,w=g+1,S=f+1;let M=0,A=0;const N=new Ai;for(let n=0;n0?1:-1,u.push(N.x,N.y,N.z),l.push(a/g),l.push(1-n/f),M+=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 s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class kn extends Rr{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new sr,this.projectionMatrix=new sr,this.projectionMatrixInverse=new sr,this.coordinateSystem=Us}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 Gn=new Ai,Wn=new Ys,jn=new Ys;class Hn extends kn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,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*ks*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Ds*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*ks*Math.atan(Math.tan(.5*Ds*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,s){Gn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Gn.x,Gn.y).multiplyScalar(-t/Gn.z),Gn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Gn.x,Gn.y).multiplyScalar(-t/Gn.z)}getViewSize(t,e){return this.getViewBounds(t,Wn,jn),e.subVectors(jn,Wn)}setViewOffset(t,e,s,i,r,n){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=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*Ds*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,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 $n=-90;class qn extends Rr{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Hn($n,1,t,e);i.layers=this.layers,this.add(i);const r=new Hn($n,1,t,e);r.layers=this.layers,this.add(r);const n=new Hn($n,1,t,e);n.layers=this.layers,this.add(n);const o=new Hn($n,1,t,e);o.layers=this.layers,this.add(o);const a=new Hn($n,1,t,e);a.layers=this.layers,this.add(a);const h=new Hn($n,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Us)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Os)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,u),t.setRenderTarget(l,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class Xn extends yi{constructor(t,e,s,i,r,n,o,a,h,u){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Yn extends vi{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new Xn(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:Tt}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 s={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 Ln(5,5,5),r=new Dn({name:"CubemapFromEquirect",uniforms:Vn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new On(i,r),o=e.minFilter;e.minFilter===St&&(e.minFilter=Tt);return new qn(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class Zn{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new Xr(t),this.density=e}clone(){return new Zn(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class Jn{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new Xr(t),this.near=e,this.far=s}clone(){return new Jn(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Kn extends Rr{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 dr,this.environmentIntensity=1,this.environmentRotation=new dr,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 Qn{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Ss,this.updateRanges=[],this.version=0,this.uuid=Gs()}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,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;it.far||e.push({distance:a,point:ro.clone(),uv:Wr.getInterpolation(ro,lo,co,po,mo,go,fo,new Ys),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 xo(t,e,s,i,r,n){ao.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(ho.x=n*ao.x-r*ao.y,ho.y=r*ao.x+n*ao.y):ho.copy(ao),t.copy(e),t.x+=ho.x,t.y+=ho.y,t.applyMatrix4(uo)}const bo=new Ai,vo=new Ai;class To extends Rr{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,s=e.length;t0){let s,i;for(s=1,i=e.length;s0){bo.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(bo);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){bo.setFromMatrixPosition(t.matrixWorld),vo.setFromMatrixPosition(this.matrixWorld);const s=bo.distanceTo(vo)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<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 s=e||Xo.getNormalMatrix(t),i=this.coplanarPoint($o).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),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 Zo=new qi,Jo=new Ai;class Ko{constructor(t=new Yo,e=new Yo,s=new Yo,i=new Yo,r=new Yo,n=new Yo){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],u=i[5],l=i[6],c=i[7],d=i[8],p=i[9],m=i[10],g=i[11],f=i[12],y=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,c-h,g-d,b-f).normalize(),s[1].setComponents(a+r,c+h,g+d,b+f).normalize(),s[2].setComponents(a+n,c+u,g+p,b+y).normalize(),s[3].setComponents(a-n,c-u,g-p,b-y).normalize(),s[4].setComponents(a-o,c-l,g-m,b-x).normalize(),e===Us)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(e!==Os)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),Zo.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),Zo.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(Zo)}intersectsSprite(t){return Zo.center.set(0,0,0),Zo.radius=.7071067811865476,Zo.applyMatrix4(t.matrixWorld),this.intersectsSphere(Zo)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)0?t.max.x:t.min.x,Jo.y=i.normal.y>0?t.max.y:t.min.y,Jo.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(Jo)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function Qo(t,e){return t.z-e.z}function ta(t,e){return e.z-t.z}class ea{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s){const i=this.pool,r=this.list;this.index>=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const n=i[this.index];r.push(n),this.index++,n.start=t.start,n.count=t.count,n.z=e,n.index=s}reset(){this.list.length=0,this.index=0}}const sa=new sr,ia=new sr,ra=new sr,na=new Xr(1,1,1),oa=new sr,aa=new Ko,ha=new Ri,ua=new qi,la=new Ai,ca=new Ai,da=new Ai,pa=new ea,ma=new On,ga=[];function fa(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new an(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 s in e.attributes){if(!t.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.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 Ri);const t=this.boundingBox,e=this._drawInfo;t.makeEmpty();for(let s=0,i=e.length;s=this.maxInstanceCount&&0===this._availableInstanceIds.length)throw new Error("BatchedMesh: Maximum item count reached.");const e={visible:!0,active:!0,geometryIndex:t};let s=null;this._availableInstanceIds.length>0?(s=this._availableInstanceIds.pop(),this._drawInfo[s]=e):(s=this._drawInfo.length,this._drawInfo.push(e));const i=this._matricesTexture,r=i.image.data;ra.toArray(r,16*s),i.needsUpdate=!0;const n=this._colorsTexture;return n&&(na.toArray(n.image.data,4*s),n.needsUpdate=!0),s}addGeometry(t,e=-1,s=-1){this._initializeGeometry(t),this._validateGeometry(t);const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let r=null;const n=this._reservedRanges,o=this._drawRanges,a=this._bounds;0!==this._geometryCount&&(r=n[n.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=t.getIndex(),u=null!==h;if(u&&(i.indexCount=-1===s?h.count:s,i.indexStart=null===r?0:r.indexStart+r.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 l={start:u?i.indexStart:i.vertexStart,count:-1,active:!0},c={boxInitialized:!1,box:new Ri,sphereInitialized:!1,sphere:new qi};let d;return this._availableGeometryIds.length>0?(d=this._availableGeometryIds.pop(),n[d]=i,o[d]=l,a[d]=c):(d=this._geometryCount,this._geometryCount++,n.push(i),o.push(l),a.push(c)),this.setGeometryAt(d,t),d}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._reservedRanges[t];if(i&&n.count>o.indexCount||e.attributes.position.count>o.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.vertexCount;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);fa(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t=e.length||!1===e[t].active)return this;const s=this._drawInfo;for(let e=0,i=s.length;e=e.length||!1===e[t].active||(e[t].active=!1,this._availableInstanceIds.push(t),this._visibilityChanged=!0),this}optimize(){let t=0,e=0;const s=this._drawRanges,i=this._reservedRanges,r=this.geometry;for(let n=0,o=s.length;n=this._geometryCount)return null;const s=this._bounds[t],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const e=r.index,n=r.attributes.position,o=this._drawRanges[t];for(let t=o.start,s=o.start+o.count;t=this._geometryCount)return null;const s=this._bounds[t],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,ha),ha.getCenter(i.center);const e=r.index,n=r.attributes.position,o=this._drawRanges[t];let a=0;for(let t=o.start,s=o.start+o.count;t=s.length||!1===s[t].active||(e.toArray(r,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return t>=r.length||!1===r[t].active||(e.toArray(i,4*t),s.needsUpdate=!0),this}getColorAt(t,e){const s=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(s,4*t)}setVisibleAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||s[t].visible===e||(s[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 s=this._drawInfo;return t>=s.length||!1===s[t].active||e<0||e>=this._geometryCount?null:(s[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 s=this._drawRanges[t];return e.start=s.start,e.count=s.count,e}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;ma.material=this.material,ma.geometry.index=n.index,ma.geometry.attributes=n.attributes,null===ma.geometry.boundingBox&&(ma.geometry.boundingBox=new Ri),null===ma.geometry.boundingSphere&&(ma.geometry.boundingSphere=new qi);for(let n=0,o=s.length;n({...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,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._drawInfo,h=this._multiDrawStarts,u=this._multiDrawCounts,l=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(oa.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),aa.setFromProjectionMatrix(oa,t.coordinateSystem));let m=0;if(this.sortObjects){ia.copy(this.matrixWorld).invert(),la.setFromMatrixPosition(s.matrixWorld).applyMatrix4(ia),ca.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(ia);for(let t=0,e=a.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;ti)return;Sa.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Sa);return ae.far?void 0:{distance:a,point:Ma.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:t}}const Ca=new Ai,Ra=new Ai;class Ea extends Aa{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,s=[];for(let t=0,i=e.count;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;tr.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,faceIndex:null,barycoord:null,object:o})}}class Va extends Rr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class Da extends yi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Tt,this.magFilter=void 0!==r?r:Tt,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){u.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 ka extends yi{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ga extends yi{constructor(t,e,s,i,r,n,o,a,h,u,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Wa extends Ga{constructor(t,e,s,i,r,n){super(t,e,s,r,n),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 ja extends Ga{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Ha extends yi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class $a extends yi{constructor(t,e,s,i,r,n,o,a,h,u=1026){if(u!==Wt&&u!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===Wt&&(s=Bt),void 0===s&&u===jt&&(s=Ot),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class qa{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/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 s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const u=s[i];return(i+(n-u)/(s[i+1]-u))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Ys:new Ai);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ai,i=[],r=[],n=[],o=new Ai,a=new sr;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ai)}r[0]=new Ai,n[0]=new Ai;let h=Number.MAX_VALUE;const u=Math.abs(i[0].x),l=Math.abs(i[0].y),c=Math.abs(i[0].z);u<=h&&(h=u,s.set(1,0,0)),l<=h&&(h=l,s.set(0,1,0)),c<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos(Ws(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos(Ws(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}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 Xa extends qa{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Ys){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)i;)r-=i;r0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===u&&h===r-1&&(h=r-2,u=1),this.closed||h>0?o=i[(h-1)%r]:(Ja.subVectors(i[0],i[1]).add(i[0]),o=Ja);const l=i[h%r],c=i[(h+1)%r];if(this.closed||h+2i.length-2?i.length-1:n+1],l=i[n>i.length-3?i.length-1:n+2];return s.set(sh(o,a.x,h.x,u.x,l.x),sh(o,a.y,h.y,u.y,l.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}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 s=0,i=this.curves.length;s1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,s=t.curves.length;e0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),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 gh extends Sn{constructor(t=[new Ys(0,-.5),new Ys(.5,0),new Ys(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=Ws(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/e,l=new Ai,c=new Ys,d=new Ai,p=new Ai,m=new Ai;let g=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){l.x=t[s].x*p,l.y=t[s].y,l.z=t[s].x*m,n.push(l.x,l.y,l.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,u=a[3*s+1],d=a[3*s+0]*m;h.push(i,u,d)}}for(let s=0;s0&&(u.push(r,n,a),x+=3),e>0&&(u.push(n,o,a),x+=3)}h.addGroup(f,x,0),f+=x}(),!1===n&&(t>0&&y(!0),e>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new fn(l,3)),this.setAttribute("normal",new fn(c,3)),this.setAttribute("uv",new fn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new xh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class bh extends xh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new bh(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class vh extends Sn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new fn(r,3)),this.setAttribute("normal",new fn(r.slice(),3)),this.setAttribute("uv",new fn(n,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 vh(t.vertices,t.indices,t.radius,t.details)}}class Th extends vh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;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,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,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 Th(t.radius,t.detail)}}const _h=new Ai,wh=new Ai,Sh=new Ai,Mh=new Wr;class Ah extends Sn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(Ds*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let t=0;t80*s){a=u=t[0],h=l=t[1];for(let e=s;eu&&(u=c),d>l&&(l=d);p=Math.max(u-a,l-h),p=0!==p?32767/p:0}return Bh(n,o,s,a,h,p,0),o};function Rh(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n0)for(n=e;n=e;n-=i)o=Zh(n,t[n],t[n+1],o);return o&&jh(o,o.next)&&(Jh(o),o=o.next),o}function Eh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!jh(i,i.next)&&0!==Wh(i.prev,i,i.next))i=i.next;else{if(Jh(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Bh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=Vh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,u=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(t,i,r,n);let a,h,u=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Ph(t,i,r,n):Ih(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),Jh(t),t=h.next,u=h.next;else if((t=h)===u){o?1===o?Bh(t=Fh(Eh(t),e,s),e,s,i,r,n,2):2===o&&Uh(t,e,s,i,r,n):Bh(Eh(t),e,s,i,r,n,1);break}}function Ih(t){const e=t.prev,s=t,i=t.next;if(Wh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,u=i.y,l=rn?r>o?r:o:n>o?n:o,p=a>h?a>u?a:u:h>u?h:u;let m=i.next;for(;m!==e;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&kh(r,a,n,h,o,u,m.x,m.y)&&Wh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Ph(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Wh(r,n,o)>=0)return!1;const a=r.x,h=n.x,u=o.x,l=r.y,c=n.y,d=o.y,p=ah?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=Vh(p,m,e,s,i),x=Vh(g,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=y&&v&&v.z<=x;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&kh(a,l,h,c,u,d,b.x,b.y)&&Wh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&kh(a,l,h,c,u,d,v.x,v.y)&&Wh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=y;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&kh(a,l,h,c,u,d,b.x,b.y)&&Wh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&kh(a,l,h,c,u,d,v.x,v.y)&&Wh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Fh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!jh(r,n)&&Hh(r,i,i.next,n)&&Xh(r,n)&&Xh(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),Jh(i),Jh(i.next),i=t=n),i=i.next}while(i!==t);return Eh(i)}function Uh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Gh(o,t)){let a=Yh(o,t);return o=Eh(o,o.next),a=Eh(a,a.next),Bh(o,e,s,i,r,n,0),void Bh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Oh(t,e){return t.x-e.x}function zh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x=i.x&&i.x>=h&&n!==i.x&&kh(os.x||i.x===s.x&&Lh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=Yh(s,t);return Eh(i,i.next),Eh(s,s.next)}function Lh(t,e){return Wh(t.prev,t,e.prev)<0&&Wh(e.next,t,t.next)<0}function Vh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Dh(t){let e=t,s=t;do{(e.x=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Gh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Hh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(Xh(t,e)&&Xh(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Wh(t.prev,t,e.prev)||Wh(t,e.prev,e))||jh(t,e)&&Wh(t.prev,t,t.next)>0&&Wh(e.prev,e,e.next)>0)}function Wh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function jh(t,e){return t.x===e.x&&t.y===e.y}function Hh(t,e,s,i){const r=qh(Wh(t,e,s)),n=qh(Wh(t,e,i)),o=qh(Wh(s,i,t)),a=qh(Wh(s,i,e));return r!==n&&o!==a||(!(0!==r||!$h(t,s,e))||(!(0!==n||!$h(t,i,e))||(!(0!==o||!$h(s,t,i))||!(0!==a||!$h(s,e,i)))))}function $h(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function qh(t){return t>0?1:t<0?-1:0}function Xh(t,e){return Wh(t.prev,t,t.next)<0?Wh(t,e,t.next)>=0&&Wh(t,t.prev,e)>=0:Wh(t,e,t.prev)<0||Wh(t,t.next,e)<0}function Yh(t,e){const s=new Kh(t.i,t.x,t.y),i=new Kh(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function Zh(t,e,s,i){const r=new Kh(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Jh(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 Kh(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class Qh{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r2&&t[e-1].equals(t[0])&&t.pop()}function eu(t,e){for(let s=0;sNumber.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=e.x-a/c,m=e.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-t.x,r=m+a*g-t.y;const f=i*i+r*r;if(f<=2)return new Ys(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(u)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new Ys(i/n,r/n)}const B=[];for(let t=0,e=A.length,s=e-1,i=t+1;t=0;t--){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t0)&&d.push(e,r,h),(t!==s-1||a0!=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 Tu extends Jr{static get type(){return"MeshPhongMaterial"}constructor(t){super(),this.isMeshPhongMaterial=!0,this.color=new Xr(16777215),this.specular=new Xr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,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 _u extends Jr{static get type(){return"MeshToonMaterial"}constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.color=new Xr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(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 wu extends Jr{static get type(){return"MeshNormalMaterial"}constructor(t){super(),this.isMeshNormalMaterial=!0,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(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 Su extends Jr{static get type(){return"MeshLambertMaterial"}constructor(t){super(),this.isMeshLambertMaterial=!0,this.color=new Xr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,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 Mu extends Jr{static get type(){return"MeshDepthMaterial"}constructor(t){super(),this.isMeshDepthMaterial=!0,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 Au extends Jr{static get type(){return"MeshDistanceMaterial"}constructor(t){super(),this.isMeshDistanceMaterial=!0,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}}class Nu extends Jr{static get type(){return"MeshMatcapMaterial"}constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.color=new Xr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(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 Cu extends xa{static get type(){return"LineDashedMaterial"}constructor(t){super(),this.isLineDashedMaterial=!0,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 Ru(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Eu(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Bu(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Iu(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Pu(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const Fu={convertArray:Ru,isTypedArray:Eu,getKeyframeOrder:Bu,sortedArray:Iu,flattenJSON:Pu,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t=i)){h.push(e.times[t]);for(let s=0;sn.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t=i.times[c]){const t=c*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Mi).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t=r)break t;{const o=e[1];t=r)break e}n=s,s=0}}for(;s>>1;te;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*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 s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[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!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&Eu(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Fe,r=t.length-1;let n=1;for(let o=1;o0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}Vu.prototype.TimeBufferType=Float32Array,Vu.prototype.ValueBufferType=Float32Array,Vu.prototype.DefaultInterpolation=Pe;class Du extends Vu{constructor(t,e,s){super(t,e,s)}}Du.prototype.ValueTypeName="bool",Du.prototype.ValueBufferType=Array,Du.prototype.DefaultInterpolation=Ie,Du.prototype.InterpolantFactoryMethodLinear=void 0,Du.prototype.InterpolantFactoryMethodSmooth=void 0;class ku extends Vu{}ku.prototype.ValueTypeName="color";class Gu extends Vu{}Gu.prototype.ValueTypeName="number";class Wu extends Uu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Mi.slerpFlat(r,0,n,h-o,n,h,a);return r}}class ju extends Vu{InterpolantFactoryMethodLinear(t){return new Wu(this.times,this.values,this.getValueSize(),t)}}ju.prototype.ValueTypeName="quaternion",ju.prototype.InterpolantFactoryMethodSmooth=void 0;class Hu extends Vu{constructor(t,e,s){super(t,e,s)}}Hu.prototype.ValueTypeName="string",Hu.prototype.ValueBufferType=Array,Hu.prototype.DefaultInterpolation=Ie,Hu.prototype.InterpolantFactoryMethodLinear=void 0,Hu.prototype.InterpolantFactoryMethodSmooth=void 0;class $u extends Vu{}$u.prototype.ValueTypeName="vector";class qu{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=Gs(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(Xu(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(Vu.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Pu(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==Qu[t])return void Qu[t].push({onLoad:e,onProgress:s,onError:i});Qu[t]=[],Qu[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).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 s=Qu[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t{t.error(e)}))}()}});return new Response(h)}throw new tl(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{Yu.add(t,e);const s=Qu[t];delete Qu[t];for(let t=0,i=s.length;t{const s=Qu[t];if(void 0===s)throw this.manager.itemError(t),e;delete Qu[t];for(let t=0,i=s.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 sl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new el(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new Xr).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Ys).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ai).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new xi).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new Zs).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new sr).fromArray(r.value);break;default:i.uniforms[e].value=r.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=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(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 Ys).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(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=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Ys).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return Cl.createMaterialFromType(t)}static createMaterialFromType(t){return new{ShadowMaterial:yu,SpriteMaterial:so,RawShaderMaterial:xu,ShaderMaterial:Dn,PointsMaterial:Ia,MeshPhysicalMaterial:vu,MeshStandardMaterial:bu,MeshPhongMaterial:Tu,MeshToonMaterial:_u,MeshNormalMaterial:wu,MeshLambertMaterial:Su,MeshDepthMaterial:Mu,MeshDistanceMaterial:Au,MeshBasicMaterial:Kr,MeshMatcapMaterial:Nu,LineDashedMaterial:Cu,LineBasicMaterial:xa,Material:Jr}[t]}}class Rl{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 s=0,i=t.length;s0){const s=new Zu(e);r=new rl(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e0){i=new rl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e{const e=new Ri;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new qi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=l(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=l(t.colorsTexture.uuid));break;case"LOD":n=new To;break;case"Line":n=new Aa(h(t.geometry),u(t.material));break;case"LineLoop":n=new Ba(h(t.geometry),u(t.material));break;case"LineSegments":n=new Ea(h(t.geometry),u(t.material));break;case"PointCloud":case"Points":n=new za(h(t.geometry),u(t.material));break;case"Sprite":n=new yo(u(t.material));break;case"Group":n=new Va;break;case"Bone":n=new Io;break;default:n=new Rr}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return Yu.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),Yu.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));Yu.add(t,a),r.manager.itemStart(t)}}let zl;class Ll{static getContext(){return void 0===zl&&(zl=new(window.AudioContext||window.webkitAudioContext)),zl}static setContext(t){zl=t}}class Vl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new el(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Ll.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const Dl=new sr,kl=new sr,Gl=new sr;class Wl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Hn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Hn,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,Gl.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(Ds*e.fov*.5)/e.zoom;let n,o;kl.elements[12]=-s,Dl.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Gl.elements[0]=2*e.near/(o-n),Gl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Gl),n=-r*e.aspect-i,o=r*e.aspect-i,Gl.elements[0]=2*e.near/(o-n),Gl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Gl)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(kl),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Dl)}}class jl extends Hn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Hl{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=$l(),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=$l();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function $l(){return performance.now()}const ql=new Ai,Xl=new Mi,Yl=new Ai,Zl=new Ai;class Jl extends Rr{constructor(){super(),this.type="AudioListener",this.context=Ll.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Hl}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,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(ql,Xl,Yl),Zl.set(0,0,-1).applyQuaternion(Xl),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(ql.x,t),e.positionY.linearRampToValueAtTime(ql.y,t),e.positionZ.linearRampToValueAtTime(ql.z,t),e.forwardX.linearRampToValueAtTime(Zl.x,t),e.forwardY.linearRampToValueAtTime(Zl.y,t),e.forwardZ.linearRampToValueAtTime(Zl.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(ql.x,ql.y,ql.z),e.setOrientation(Zl.x,Zl.y,Zl.z,s.x,s.y,s.z)}}class Kl extends Rr{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.duration)),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(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];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 s=t;s=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Mi.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Mi.multiplyQuaternionsFlat(t,n,t,e,t,s),Mi.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const oc="\\[\\]\\.:\\/",ac=new RegExp("["+oc+"]","g"),hc="[^"+oc+"]",uc="[^"+oc.replace("\\.","")+"]",lc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",hc)+/(WCOD+)?/.source.replace("WCOD",uc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",hc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",hc)+"$"),cc=["material","materials","bones","map"];class dc{constructor(t,e,s){this.path=e,this.parsedPath=s||dc.parseTrackName(e),this.node=dc.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new dc.Composite(t,e,s):new dc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(ac,"")}static parseTrackName(t){const e=lc.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==cc.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i=r){const n=r++,u=t[n];e[u.uuid]=h,t[h]=u,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,u=this.nCachedObjects_,l=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new dc(i,t,e)}return l}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class mc{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Ue,endingEnd:Ue};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),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,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}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,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,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,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.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 s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(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===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=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===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=Oe,i.endingEnd=Oe):(i.endingStart=t?this.zeroSlopeAtStart?Oe:Ue:ze,i.endingEnd=e?this.zeroSlopeAtEnd?Oe:Ue:ze)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const gc=new Float32Array(1);class fc extends zs{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[t]=l;else{if(l=n[t],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;l=new nc(dc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[t]=l}o[t].resultBuffer=l.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}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,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);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,Rc).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 Bc=new Ai,Ic=new Ai;class Pc{constructor(t=new Ai,e=new Ai){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){Bc.subVectors(t,this.start),Ic.subVectors(this.end,this.start);const s=Ic.dot(Ic);let i=Ic.dot(Bc)/s;return e&&(i=Ws(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).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 Fc=new Ai;class Uc extends Rr{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new Sn,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,s=32;t1)for(let s=0;s.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{od.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(od,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),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 ld extends Ea{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new Sn;s.setAttribute("position",new fn(e,3)),s.setAttribute("color",new fn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new xa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new Xr,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class cd{constructor(){this.type="ShapePath",this.color=new Xr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new mh,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;nNumber.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.yo.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=Qh.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Nh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let e=0,o=i.length;e1){let t=!1,s=0;for(let t=0,e=l.length;t0&&!1===t&&(p=u)}for(let t=0,e=l.length;t>>16,2246822507),s^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&i)+(s>>>0)}const yd=t=>fd(t),xd=t=>fd(t),bd=(...t)=>fd(t);function vd(t,e=!1){const s=[];!0===t.isNode&&(s.push(t.id),t=t.getSelf());for(const{property:i,childNode:r}of Td(t))s.push(s,fd(i.slice(0,-4)),r.getCacheKey(e));return fd(s)}function*Td(t,e=!1){for(const s in t){if(!0===s.startsWith("_"))continue;const i=t[s];if(!0===Array.isArray(i))for(let t=0;tt.charCodeAt(0))).buffer}var Ad=Object.freeze({__proto__:null,arrayBufferToBase64:Sd,base64ToArrayBuffer:Md,getCacheKey:vd,getNodeChildren:Td,getValueFromType:wd,getValueType:_d,hash:bd,hashArray:xd,hashString:yd});const Nd={VERTEX:"vertex",FRAGMENT:"fragment"},Cd={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Rd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Ed=["fragment","vertex"],Bd=["setup","analyze","generate"],Id=[...Ed,"compute"],Pd=["x","y","z","w"];let Fd=0;class Ud extends zs{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=Cd.NONE,this.updateBeforeType=Cd.NONE,this.updateAfterType=Cd.NONE,this.uuid=Xs.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Fd++})}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,Cd.FRAME)}onRenderUpdate(t){return this.onUpdate(t,Cd.RENDER)}onObjectUpdate(t){return this.onUpdate(t,Cd.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 Td(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=vd(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 s=0;for(const t of this.getChildren())e["node"+s++]=t;return null}analyze(t){if(1===t.increaseUsage(this)){const e=t.getNodeProperties(this);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let i=null;const r=t.getBuildStage();if("setup"===r){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 s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i?(i=this.generate(t)||"",r.snippet=i):void 0!==r.flowCodes&&void 0!==t.context.nodeBlock&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return Td(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of e)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(t.meta).uuid):s[i]=n.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const r of t.inputNodes[s])i.push(e[r]);this[s]=i}else if("object"==typeof t.inputNodes[s]){const i={};for(const r in t.inputNodes[s]){const n=t.inputNodes[s][r];i[r]=e[n]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const e=n(t.textures),s=n(t.images),i=n(t.nodes);e.length>0&&(r.textures=e),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}class Od extends Ud{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 zd extends Ud{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))null!==s&&t.getTypeLength(e)!==t.getTypeLength(i)||(s=i);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,i=this.getNodeType(t),r=s.build(t,i);return t.format(r,i,e)}}class Ld extends Ud{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 s=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,s,e);if("void"!==s&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,s),n=t.getVarFromNode(this,null,s),o=t.getPropertyName(n);return t.addLineFlowCode(`${o} = ${r}`,this),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}class Vd extends Ld{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,s)=>e+t.getTypeLength(s.getNodeType(t))),0))}generate(t,e){const s=this.getNodeType(t),i=this.nodes,r=t.getComponentType(s),n=[];for(const e of i){let s=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(s=t.format(s,i,r)),n.push(s)}const o=`${t.getType(s)}( ${n.join(", ")} )`;return t.format(o,s,e)}}const Dd=Pd.join("");class kd extends Ud{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(Pd.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 s=this.node,i=t.getTypeLength(s.getNodeType(t));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const o=s.build(t,n);r=this.components.length===i&&this.components===Dd.slice(0,this.components.length)?t.format(o,n,e):t.format(`${o}.${this.components}`,this.getNodeType(t),e)}else r=s.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class Gd extends Ld{static get type(){return"SetNode"}constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,r=this.getNodeType(t),n=t.getTypeFromLength(s.length,i.getNodeType(t)),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),u=[];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"),Zd=t=>Yd(t).split("").sort().join(""),Jd={setup(t,e){const s=e.shift();return t(_p(s),...e)},get(t,e,s){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>($d.assign(s,...t),s);if(qd.has(e)){const i=qd.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&qd.has(e.slice(0,e.length-6))){const i=qd.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>s.assign(t[0],i(...t)):(...t)=>s.assign(i(s,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=Yd(e),Tp(new kd(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Zd(e.slice(3).toLowerCase()),s=>Tp(new Gd(t,e,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Zd(e.slice(4).toLowerCase()),()=>Tp(new Wd(Tp(t),e));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),Tp(new kd(t,e));if(!0===/^\d+$/.test(e))return Tp(new Od(s,new Hd(Number(e),"uint")))}return Reflect.get(t,e,s)},set:(t,e,s,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,s,i):(i[e].assign(s),!0)},Kd=new WeakMap,Qd=new WeakMap,tp=function(t,e=null){for(const s in t)t[s]=Tp(t[s],e);return t},ep=function(t,e=null){const s=t.length;for(let i=0;iTp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...wp(e))):null!==s?(s=Tp(s),(...i)=>r(new t(e,...wp(i),s))):(...s)=>r(new t(e,...wp(s)))},ip=function(t,...e){return Tp(new t(...wp(e)))};class rp extends Ud{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:s}=this,i=t.getNodeProperties(e);if(i.onceOutput)return i.onceOutput;let r=null;if(e.layout){let i=Qd.get(t.constructor);void 0===i&&(i=new WeakMap,Qd.set(t.constructor,i));let n=i.get(e);void 0===n&&(n=Tp(t.buildFunctionNode(e)),i.set(e,n)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(n),r=Tp(n.call(s))}else{const i=e.jsFunc,n=null!==s?i(s,t):i(t);r=Tp(n)}return e.once&&(i.onceOutput=r),r}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 np extends Ud{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 _p(t),Tp(new rp(this,t))}setup(){return this.call()}}const op=[!1,!0],ap=[0,1,2,3],hp=[-1,-2],up=[.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],lp=new Map;for(const t of op)lp.set(t,new Hd(t));const cp=new Map;for(const t of ap)cp.set(t,new Hd(t,"uint"));const dp=new Map([...cp].map((t=>new Hd(t.value,"int"))));for(const t of hp)dp.set(t,new Hd(t,"int"));const pp=new Map([...dp].map((t=>new Hd(t.value))));for(const t of up)pp.set(t,new Hd(t));for(const t of up)pp.set(-t,new Hd(-t));const mp={bool:lp,uint:cp,ints:dp,float:pp},gp=new Map([...lp,...pp]),fp=(t,e)=>gp.has(t)?gp.get(t):!0===t.isNode?t:new Hd(t,e),yp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[wd(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return Tp(e.get(s[0]));if(1===s.length){const e=fp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?Tp(e):Tp(new zd(e,t))}const i=s.map((t=>fp(t)));return Tp(new Vd(i,t))}},xp=t=>"object"==typeof t&&null!==t?t.value:t,bp=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function vp(t,e){return new Proxy(new np(t,e),Jd)}const Tp=(t,e=null)=>function(t,e=null){const s=_d(t);if("node"===s){let e=Kd.get(t);return void 0===e&&(e=new Proxy(t,Jd),Kd.set(t,e),Kd.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Tp(fp(t,e)):"shader"===s?Ap(t):t}(t,e),_p=(t,e=null)=>new tp(t,e),wp=(t,e=null)=>new ep(t,e),Sp=(...t)=>new sp(...t),Mp=(...t)=>new ip(...t),Ap=(t,e)=>{const s=new vp(t,e),i=(...t)=>{let e;return _p(t),e=t[0]&&t[0].isNode?[...t]:t[0],s.call(e)};return i.shaderNode=s,i.setLayout=t=>(s.setLayout(t),i),i.once=()=>(s.once=!0,i),i},Np=(...t)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),Ap(...t));Xd("toGlobal",(t=>(t.global=!0,t)));const Cp=t=>{$d=t},Rp=()=>$d,Ep=(...t)=>$d.If(...t);function Bp(t){return $d&&$d.add(t),t}Xd("append",Bp);const Ip=new yp("color"),Pp=new yp("float",mp.float),Fp=new yp("int",mp.ints),Up=new yp("uint",mp.uint),Op=new yp("bool",mp.bool),zp=new yp("vec2"),Lp=new yp("ivec2"),Vp=new yp("uvec2"),Dp=new yp("bvec2"),kp=new yp("vec3"),Gp=new yp("ivec3"),Wp=new yp("uvec3"),jp=new yp("bvec3"),Hp=new yp("vec4"),$p=new yp("ivec4"),qp=new yp("uvec4"),Xp=new yp("bvec4"),Yp=new yp("mat2"),Zp=new yp("mat3"),Jp=new yp("mat4"),Kp=(t="")=>Tp(new Hd(t,"string")),Qp=t=>Tp(new Hd(t,"ArrayBuffer"));Xd("toColor",Ip),Xd("toFloat",Pp),Xd("toInt",Fp),Xd("toUint",Up),Xd("toBool",Op),Xd("toVec2",zp),Xd("toIVec2",Lp),Xd("toUVec2",Vp),Xd("toBVec2",Dp),Xd("toVec3",kp),Xd("toIVec3",Gp),Xd("toUVec3",Wp),Xd("toBVec3",jp),Xd("toVec4",Hp),Xd("toIVec4",$p),Xd("toUVec4",qp),Xd("toBVec4",Xp),Xd("toMat2",Yp),Xd("toMat3",Zp),Xd("toMat4",Jp);const tm=Sp(Od),em=(t,e)=>Tp(new zd(Tp(t),e)),sm=(t,e)=>Tp(new kd(Tp(t),e));Xd("element",tm),Xd("convert",em);class im extends Ud{static get type(){return"UniformGroupNode"}constructor(t,e=!1,s=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=s,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 rm=t=>new im(t),nm=(t,e=0)=>new im(t,!0,e),om=nm("frame"),am=nm("render"),hm=rm("object");class um extends jd{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=hm}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 s=this.getSelf();return t=t.bind(s),super.onUpdate((e=>{const i=t(e,s);void 0!==i&&(this.value=i)}),e)}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const n=r.getInputType(t),o=t.getUniformFromNode(r,n,t.shaderStage,this.name||t.context.label),a=t.getPropertyName(o);return void 0!==t.context.label&&delete t.context.label,t.format(a,s,e)}}const lm=(t,e)=>{const s=bp(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return Tp(new um(i,s))};class cm extends Ud{static get type(){return"PropertyNode"}constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,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 dm=(t,e)=>Tp(new cm(t,e)),pm=(t,e)=>Tp(new cm(t,e,!0)),mm=Mp(cm,"vec4","DiffuseColor"),gm=Mp(cm,"vec3","EmissiveColor"),fm=Mp(cm,"float","Roughness"),ym=Mp(cm,"float","Metalness"),xm=Mp(cm,"float","Clearcoat"),bm=Mp(cm,"float","ClearcoatRoughness"),vm=Mp(cm,"vec3","Sheen"),Tm=Mp(cm,"float","SheenRoughness"),_m=Mp(cm,"float","Iridescence"),wm=Mp(cm,"float","IridescenceIOR"),Sm=Mp(cm,"float","IridescenceThickness"),Mm=Mp(cm,"float","AlphaT"),Am=Mp(cm,"float","Anisotropy"),Nm=Mp(cm,"vec3","AnisotropyT"),Cm=Mp(cm,"vec3","AnisotropyB"),Rm=Mp(cm,"color","SpecularColor"),Em=Mp(cm,"float","SpecularF90"),Bm=Mp(cm,"float","Shininess"),Im=Mp(cm,"vec4","Output"),Pm=Mp(cm,"float","dashSize"),Fm=Mp(cm,"float","gapSize"),Um=Mp(cm,"float","pointWidth"),Om=Mp(cm,"float","IOR"),zm=Mp(cm,"float","Transmission"),Lm=Mp(cm,"float","Thickness"),Vm=Mp(cm,"float","AttenuationDistance"),Dm=Mp(cm,"color","AttenuationColor"),km=Mp(cm,"float","Dispersion");class Gm extends Ld{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 s=t.getTypeLength(e.node.getNodeType(t));return Pd.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(t),n=s.getNodeType(t),o=s.context({assign:!0}).build(t),a=i.build(t,n),h=i.getNodeType(t),u=t.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==e&&(l=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`,this);const h=s.node.context({assign:!0}).build(t);for(let e=0;e{const i=s.type;let r;return r="pointer"===i?"&"+e.build(t):e.build(t,i),r};if(Array.isArray(r))for(let t=0;t(e=e.length>1||e[0]&&!0===e[0].isNode?wp(e):_p(e[0]),Tp(new jm(Tp(t),e)));Xd("call",Hm);class $m extends Ld{static get type(){return"OperatorNode"}constructor(t,e,s,...i){if(super(),i.length>0){let r=new $m(t,e,s);for(let e=0;e>"===s||"<<"===s)return t.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=e?t.getTypeLength(e):Math.max(t.getTypeLength(n),t.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&t.isMatrix(o)?o:t.isMatrix(n)&&t.isVector(o)?t.getVectorFromMatrix(n):t.isVector(n)&&t.isMatrix(o)?t.getVectorFromMatrix(o):t.getTypeLength(o)>t.getTypeLength(n)?o:n}generate(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(t,e);let o=null,a=null;"void"!==n?(o=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?t.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=t.changeComponentType(a,"uint")):t.isMatrix(o)&&t.isVector(a)?a=t.getVectorFromMatrix(o):o=t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(t,o),u=void 0!==r?r.build(t,a):null,l=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} < ${u} )`,n,e):"<="===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} <= ${u} )`,n,e):">"===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} > ${u} )`,n,e):">="===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} >= ${u} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`( ${h} ${s} ${u} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`${h} ${s} ${u}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const qm=Sp($m,"+"),Xm=Sp($m,"-"),Ym=Sp($m,"*"),Zm=Sp($m,"/"),Jm=Sp($m,"%"),Km=Sp($m,"=="),Qm=Sp($m,"!="),tg=Sp($m,"<"),eg=Sp($m,">"),sg=Sp($m,"<="),ig=Sp($m,">="),rg=Sp($m,"&&"),ng=Sp($m,"||"),og=Sp($m,"!"),ag=Sp($m,"^^"),hg=Sp($m,"&"),ug=Sp($m,"~"),lg=Sp($m,"|"),cg=Sp($m,"^"),dg=Sp($m,"<<"),pg=Sp($m,">>");Xd("add",qm),Xd("sub",Xm),Xd("mul",Ym),Xd("div",Zm),Xd("modInt",Jm),Xd("equal",Km),Xd("notEqual",Qm),Xd("lessThan",tg),Xd("greaterThan",eg),Xd("lessThanEqual",sg),Xd("greaterThanEqual",ig),Xd("and",rg),Xd("or",ng),Xd("not",og),Xd("xor",ag),Xd("bitAnd",hg),Xd("bitNot",ug),Xd("bitOr",lg),Xd("bitXor",cg),Xd("shiftLeft",dg),Xd("shiftRight",pg);const mg=(...t)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Jm(...t));Xd("remainder",mg);class gg extends Ld{static get type(){return"MathNode"}constructor(t,e,s=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s),o=t.isMatrix(i)?0:t.getTypeLength(i);return r>n&&r>o?e:n>o?s:o>r?i:e}getNodeType(t){const e=this.method;return e===gg.LENGTH||e===gg.DISTANCE||e===gg.DOT?"float":e===gg.CROSS?"vec3":e===gg.ALL?"bool":e===gg.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===gg.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),r=this.getInputType(t),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===t.renderer.isWebGLRenderer;if(s===gg.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=Hp(kp(i),0):s=Hp(kp(s),0);const r=Ym(s,i).xyz;return Pg(r).build(t,e)}if(s===gg.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===gg.ONE_MINUS)return Xm(1,n).build(t,e);if(s===gg.RECIPROCAL)return Zm(1,n).build(t,e);if(s===gg.DIFFERENCE)return kg(Xm(n,o)).build(t,e);{const u=[];return s===gg.CROSS||s===gg.MOD?u.push(n.build(t,i),o.build(t,i)):h&&s===gg.STEP?u.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===gg.MIN||s===gg.MAX)||s===gg.MOD?u.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===gg.REFRACT?u.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===gg.MIX?u.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(u.push(n.build(t,r)),null!==o&&u.push(o.build(t,r)),null!==a&&u.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${u.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}gg.ALL="all",gg.ANY="any",gg.EQUALS="equals",gg.RADIANS="radians",gg.DEGREES="degrees",gg.EXP="exp",gg.EXP2="exp2",gg.LOG="log",gg.LOG2="log2",gg.SQRT="sqrt",gg.INVERSE_SQRT="inversesqrt",gg.FLOOR="floor",gg.CEIL="ceil",gg.NORMALIZE="normalize",gg.FRACT="fract",gg.SIN="sin",gg.COS="cos",gg.TAN="tan",gg.ASIN="asin",gg.ACOS="acos",gg.ATAN="atan",gg.ABS="abs",gg.SIGN="sign",gg.LENGTH="length",gg.NEGATE="negate",gg.ONE_MINUS="oneMinus",gg.DFDX="dFdx",gg.DFDY="dFdy",gg.ROUND="round",gg.RECIPROCAL="reciprocal",gg.TRUNC="trunc",gg.FWIDTH="fwidth",gg.BITCAST="bitcast",gg.TRANSPOSE="transpose",gg.ATAN2="atan2",gg.MIN="min",gg.MAX="max",gg.MOD="mod",gg.STEP="step",gg.REFLECT="reflect",gg.DISTANCE="distance",gg.DIFFERENCE="difference",gg.DOT="dot",gg.CROSS="cross",gg.POW="pow",gg.TRANSFORM_DIRECTION="transformDirection",gg.MIX="mix",gg.CLAMP="clamp",gg.REFRACT="refract",gg.SMOOTHSTEP="smoothstep",gg.FACEFORWARD="faceforward";const fg=Pp(1e-6),yg=Pp(1e6),xg=Pp(Math.PI),bg=Pp(2*Math.PI),vg=Sp(gg,gg.ALL),Tg=Sp(gg,gg.ANY),_g=Sp(gg,gg.EQUALS),wg=Sp(gg,gg.RADIANS),Sg=Sp(gg,gg.DEGREES),Mg=Sp(gg,gg.EXP),Ag=Sp(gg,gg.EXP2),Ng=Sp(gg,gg.LOG),Cg=Sp(gg,gg.LOG2),Rg=Sp(gg,gg.SQRT),Eg=Sp(gg,gg.INVERSE_SQRT),Bg=Sp(gg,gg.FLOOR),Ig=Sp(gg,gg.CEIL),Pg=Sp(gg,gg.NORMALIZE),Fg=Sp(gg,gg.FRACT),Ug=Sp(gg,gg.SIN),Og=Sp(gg,gg.COS),zg=Sp(gg,gg.TAN),Lg=Sp(gg,gg.ASIN),Vg=Sp(gg,gg.ACOS),Dg=Sp(gg,gg.ATAN),kg=Sp(gg,gg.ABS),Gg=Sp(gg,gg.SIGN),Wg=Sp(gg,gg.LENGTH),jg=Sp(gg,gg.NEGATE),Hg=Sp(gg,gg.ONE_MINUS),$g=Sp(gg,gg.DFDX),qg=Sp(gg,gg.DFDY),Xg=Sp(gg,gg.ROUND),Yg=Sp(gg,gg.RECIPROCAL),Zg=Sp(gg,gg.TRUNC),Jg=Sp(gg,gg.FWIDTH),Kg=Sp(gg,gg.BITCAST),Qg=Sp(gg,gg.TRANSPOSE),tf=Sp(gg,gg.ATAN2),ef=Sp(gg,gg.MIN),sf=Sp(gg,gg.MAX),rf=Sp(gg,gg.MOD),nf=Sp(gg,gg.STEP),of=Sp(gg,gg.REFLECT),af=Sp(gg,gg.DISTANCE),hf=Sp(gg,gg.DIFFERENCE),uf=Sp(gg,gg.DOT),lf=Sp(gg,gg.CROSS),cf=Sp(gg,gg.POW),df=Sp(gg,gg.POW,2),pf=Sp(gg,gg.POW,3),mf=Sp(gg,gg.POW,4),gf=Sp(gg,gg.TRANSFORM_DIRECTION),ff=t=>Ym(Gg(t),cf(kg(t),1/3)),yf=t=>uf(t,t),xf=Sp(gg,gg.MIX),bf=(t,e=0,s=1)=>Tp(new gg(gg.CLAMP,Tp(t),Tp(e),Tp(s))),vf=t=>bf(t),Tf=Sp(gg,gg.REFRACT),_f=Sp(gg,gg.SMOOTHSTEP),wf=Sp(gg,gg.FACEFORWARD),Sf=Ap((([t])=>{const e=uf(t.xy,zp(12.9898,78.233)),s=rf(e,xg);return Fg(Ug(s).mul(43758.5453))})),Mf=(t,e,s)=>xf(e,s,t),Af=(t,e,s)=>_f(e,s,t);Xd("all",vg),Xd("any",Tg),Xd("equals",_g),Xd("radians",wg),Xd("degrees",Sg),Xd("exp",Mg),Xd("exp2",Ag),Xd("log",Ng),Xd("log2",Cg),Xd("sqrt",Rg),Xd("inverseSqrt",Eg),Xd("floor",Bg),Xd("ceil",Ig),Xd("normalize",Pg),Xd("fract",Fg),Xd("sin",Ug),Xd("cos",Og),Xd("tan",zg),Xd("asin",Lg),Xd("acos",Vg),Xd("atan",Dg),Xd("abs",kg),Xd("sign",Gg),Xd("length",Wg),Xd("lengthSq",yf),Xd("negate",jg),Xd("oneMinus",Hg),Xd("dFdx",$g),Xd("dFdy",qg),Xd("round",Xg),Xd("reciprocal",Yg),Xd("trunc",Zg),Xd("fwidth",Jg),Xd("atan2",tf),Xd("min",ef),Xd("max",sf),Xd("mod",rf),Xd("step",nf),Xd("reflect",of),Xd("distance",af),Xd("dot",uf),Xd("cross",lf),Xd("pow",cf),Xd("pow2",df),Xd("pow3",pf),Xd("pow4",mf),Xd("transformDirection",gf),Xd("mix",Mf),Xd("clamp",bf),Xd("refract",Tf),Xd("smoothstep",Af),Xd("faceForward",wf),Xd("difference",hf),Xd("saturate",vf),Xd("cbrt",ff),Xd("transpose",Qg),Xd("rand",Sf);class Nf extends Ud{static get type(){return"ConditionalNode"}constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=this.condNode.cache(),s=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,r=t.context.nodeBlock;t.getDataFromNode(s).parentNodeBlock=r,null!==i&&(t.getDataFromNode(i).parentNodeBlock=r);const n=t.getNodeProperties(this);n.condNode=e,n.ifNode=s.context({nodeBlock:s}),n.elseNode=i?i.context({nodeBlock:i}):null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=t.getNodeProperties(this),a="void"!==e,h=a?dm(s).build(t):"";i.nodeProperty=h;const u=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(t,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+l+"\n\n"+t.tab+"}"),null!==o){t.addFlowCode(" else {\n\n").addFlowTab();let e=o.build(t,s);e&&(e=a?h+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(h,s,e)}}const Cf=Sp(Nf);Xd("select",Cf);const Rf=(...t)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Cf(...t));Xd("cond",Rf);class Ef extends Ud{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 s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.value});const i=this.node.build(t,e);return t.setContext(s),i}}const Bf=Sp(Ef),If=(t,e)=>Bf(t,{label:e});Xd("context",Bf),Xd("label",If);class Pf extends Ud{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:s}=this,i=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),n=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${n}`,this),r}}const Ff=Sp(Pf);Xd("toVar",((...t)=>Ff(...t).append()));const Uf=t=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Ff(t));Xd("temp",Uf);class Of extends Ud{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 s=e.varying;if(void 0===s){const i=this.name,r=this.getNodeType(t);e.varying=s=t.getVaryingFromNode(this,i,r),e.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===t.shaderStage),s}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),s=this.setupVarying(t);if(void 0===e.propertyName){const i=this.getNodeType(t),r=t.getPropertyName(s,Nd.VERTEX);t.flowNodeFromShaderStage(Nd.VERTEX,this.node,i,r),e.propertyName=r}return t.getPropertyName(s)}}const zf=Sp(Of);Xd("varying",zf);const Lf="WorkingColorSpace",Vf="OutputColorSpace";function Df(t){let e=null;return t===Je?e="Linear":t===Ze&&(e="sRGB"),e}function kf(t,e){return Df(t)+"To"+Df(e)}class Gf extends Ld{static get type(){return"ColorSpaceNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.source=e,this.target=s}getColorSpace(t,e){return e===Lf?ii.workingColorSpace:e===Vf?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{renderer:e}=t,{colorNode:s}=this,i=this.getColorSpace(t,this.source),r=this.getColorSpace(t,this.target);if(i===r)return s;const n=kf(i,r);let o=null;const a=e.nodes.library.getColorSpaceFunction(n);return null!==a?o=Hp(a(s.rgb),s.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",n),o=s),o}}const Wf=t=>Tp(new Gf(Tp(t),Lf,Vf)),jf=t=>Tp(new Gf(Tp(t),Vf,Lf)),Hf=(t,e)=>Tp(new Gf(Tp(t),Lf,e)),$f=(t,e)=>Tp(new Gf(Tp(t),e,Lf));Xd("toOutputColorSpace",Wf),Xd("toWorkingColorSpace",jf),Xd("workingToColorSpace",Hf),Xd("colorSpaceToWorking",$f);let qf=class extends Od{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),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}};class Xf extends Ud{static get type(){return"ReferenceBaseNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=Cd.OBJECT}setGroup(t){return this.group=t,this}element(t){return Tp(new qf(this,Tp(t)))}setNodeType(t){const e=lm(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 s=t[e[0]];for(let t=1;tTp(new Yf(t,e,s));class Jf extends Ld{static get type(){return"ToneMappingNode"}constructor(t,e=Qf,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){return bd(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;let i=null;const r=t.renderer.nodes.library.getToneMappingFunction(s);return null!==r?i=Hp(r(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),i=e),i}}const Kf=(t,e,s)=>Tp(new Jf(t,Tp(e),Tp(s))),Qf=Zf("toneMappingExposure","float");Xd("toneMapping",((t,e,s)=>Kf(e,s,t)));class ty extends jd{static get type(){return"BufferAttributeNode"}constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=Ss,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),s=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new Qn(s,r),a=new eo(o,i,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=zf(this).build(t,e)}return r}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 ey=(t,e,s,i)=>Tp(new ty(t,e,s,i)),sy=(t,e,s,i)=>ey(t,e,s,i).setUsage(Ms),iy=(t,e,s,i)=>ey(t,e,s,i).setInstanced(!0),ry=(t,e,s,i)=>sy(t,e,s,i).setInstanced(!0);Xd("toAttribute",(t=>ey(t.value)));class ny extends Ud{static get type(){return"ComputeNode"}constructor(t,e,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=Cd.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let s=e[0];for(let t=1;tTp(new ny(Tp(t),e,s));Xd("compute",oy);class ay extends Ud{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 s=t.getCache(),i=t.getCacheFromNode(this,this.parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const hy=(t,...e)=>Tp(new ay(Tp(t),...e));Xd("cache",hy);class uy extends Ud{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 ly=Sp(uy);Xd("bypass",ly);class cy extends Ud{static get type(){return"RemapNode"}constructor(t,e,s,i=Pp(0),r=Pp(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=t.sub(e).div(s.sub(e));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const dy=Sp(cy,null,null,{doClamp:!1}),py=Sp(cy);Xd("remap",dy),Xd("remapClamp",py);class my extends Ud{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if("void"!==s)return t.format(`( ${i} )`,s,e);t.addLineFlowCode(i,this)}}const gy=Sp(my),fy=t=>(t?Cf(t,gy("discard")):gy("discard")).append(),yy=()=>gy("return").append();Xd("discard",fy);class xy extends Ld{static get type(){return"RenderOutputNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=(null!==this.toneMapping?this.toneMapping:t.toneMapping)||0,i=(null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace)||Ye;return 0!==s&&(e=e.toneMapping(s)),i!==Ye&&i!==ii.workingColorSpace&&(e=e.workingToColorSpace(i)),e}}const by=(t,e=null,s=null)=>Tp(new xy(Tp(t),e,s));function vy(t){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",t)}Xd("renderOutput",by);class Ty extends Ud{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 s=this.getAttributeName(t);if(t.hasGeometryAttribute(s)){const i=t.geometry.getAttribute(s);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),s=this.getNodeType(t);if(!0===t.hasGeometryAttribute(e)){const i=t.geometry.getAttribute(e),r=t.getTypeFromAttribute(i),n=t.getAttribute(e,r);if("vertex"===t.shaderStage)return t.format(n.name,r,s);return zf(this).build(t,s)}return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(s)}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 _y=(t,e)=>Tp(new Ty(t,e)),wy=t=>_y("uv"+(t>0?t:""),"vec2");class Sy extends Ud{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=null===this.levelNode?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const My=Sp(Sy);class Ay extends um{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=Cd.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&void 0!==s.width){const{width:t,height:e}=s;this.value=Math.log2(Math.max(t,e))}}}const Ny=Sp(Ay);class Cy extends um{static get type(){return"TextureNode"}constructor(t,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Cd.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===Bt?"uvec4":this.value.type===Et?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return wy(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=lm(this.value.matrix)),this._matrixUniform.mul(kp(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?Cd.FRAME:Cd.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=this.sampler?e.flipY():e.setY(Fp(My(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==t.context.forceUVContext||!t.context.getUV||(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=s,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,s,i,r,n,o,a){const h=this.value;let u;return u=i?t.generateTextureLevel(h,e,s,i,n):r?t.generateTextureBias(h,e,s,r,n):a?t.generateTextureGrad(h,e,s,a,n):o?t.generateTextureCompare(h,e,s,o,n):!1===this.sampler?t.generateTextureLoad(h,e,s,n):t.generateTexture(h,e,s,n),u}generate(t,e){const s=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(t,"property");if("sampler"===e)return r+"_sampler";if(t.isReference(e))return r;{const n=t.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:e,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=a?a.build(t,"float"):null,m=u?u.build(t,"int"):null,g=h?h.build(t,"float"):null,f=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,y=t.getVarFromNode(this);o=t.getPropertyName(y);const x=this.generateSnippet(t,r,c,d,p,m,g,f);t.addLineFlowCode(`${o} = ${x}`,this),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsToWorkingColorSpace(i)&&(a=$f(gy(a,h),i.colorSpace).setup(t).build(t,h)),t.format(a,h,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}blur(t){const e=this.clone();return e.biasNode=Tp(t).mul(Ny(e)),e.referenceNode=this.getSelf(),Tp(e)}level(t){const e=this.clone();return e.levelNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}size(t){return My(this,t)}bias(t){const e=this.clone();return e.biasNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}compare(t){const e=this.clone();return e.compareNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}grad(t,e){const s=this.clone();return s.gradNode=[Tp(t),Tp(e)],s.referenceNode=this.getSelf(),Tp(s)}depth(t){const e=this.clone();return e.depthNode=Tp(t),e.referenceNode=this.getSelf(),Tp(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 Ry=Sp(Cy),Ey=(...t)=>Ry(...t).setSampler(!1),By=t=>(!0===t.isNode?t:Ry(t)).convert("sampler"),Iy=lm("float").label("cameraNear").setGroup(am).onRenderUpdate((({camera:t})=>t.near)),Py=lm("float").label("cameraFar").setGroup(am).onRenderUpdate((({camera:t})=>t.far)),Fy=lm("mat4").label("cameraProjectionMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.projectionMatrix)),Uy=lm("mat4").label("cameraProjectionMatrixInverse").setGroup(am).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Oy=lm("mat4").label("cameraViewMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),zy=lm("mat4").label("cameraWorldMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.matrixWorld)),Ly=lm("mat3").label("cameraNormalMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.normalMatrix)),Vy=lm(new Ai).label("cameraPosition").setGroup(am).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Dy extends Ud{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=Cd.OBJECT,this._uniformNode=new um(null)}getNodeType(){const t=this.scope;return t===Dy.WORLD_MATRIX?"mat4":t===Dy.POSITION||t===Dy.VIEW_POSITION||t===Dy.DIRECTION||t===Dy.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Dy.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Dy.POSITION)s.value=s.value||new Ai,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Dy.SCALE)s.value=s.value||new Ai,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Dy.DIRECTION)s.value=s.value||new Ai,e.getWorldDirection(s.value);else if(i===Dy.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ai,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Dy.WORLD_MATRIX?this._uniformNode.nodeType="mat4":e!==Dy.POSITION&&e!==Dy.VIEW_POSITION&&e!==Dy.DIRECTION&&e!==Dy.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}}Dy.WORLD_MATRIX="worldMatrix",Dy.POSITION="position",Dy.SCALE="scale",Dy.VIEW_POSITION="viewPosition",Dy.DIRECTION="direction";const ky=Sp(Dy,Dy.DIRECTION),Gy=Sp(Dy,Dy.WORLD_MATRIX),Wy=Sp(Dy,Dy.POSITION),jy=Sp(Dy,Dy.SCALE),Hy=Sp(Dy,Dy.VIEW_POSITION);class $y extends Dy{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}const qy=Mp($y,$y.DIRECTION),Xy=Mp($y,$y.WORLD_MATRIX),Yy=Mp($y,$y.POSITION),Zy=Mp($y,$y.SCALE),Jy=Mp($y,$y.VIEW_POSITION),Ky=lm(new Zs).onObjectUpdate((({object:t},e)=>e.value.getNormalMatrix(t.matrixWorld))),Qy=lm(new sr).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert())),tx=Oy.mul(Xy).toVar("modelViewMatrix"),ex=Ap((t=>(t.context.isHighPrecisionModelViewMatrix=!0,lm("mat4").onObjectUpdate((({object:t,camera:e})=>t.modelViewMatrix.multiplyMatrices(e.matrixWorldInverse,t.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),sx=Ap((t=>{const e=t.context.isHighPrecisionModelViewMatrix;return lm("mat3").onObjectUpdate((({object:t,camera:s})=>(!0!==e&&t.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),ix=_y("position","vec3"),rx=ix.varying("positionLocal"),nx=ix.varying("positionPrevious"),ox=Xy.mul(rx).xyz.varying("v_positionWorld"),ax=rx.transformDirection(Xy).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),hx=tx.mul(rx).xyz.varying("v_positionView"),ux=hx.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class lx extends Ud{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===Us&&s.side===d?"false":t.getFrontFacing()}}const cx=Mp(lx),dx=Pp(cx).mul(2).sub(1),px=_y("normal","vec3"),mx=Ap((t=>!1===t.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),kp(0,1,0)):px),"vec3").once()().toVar("normalLocal"),gx=hx.dFdx().cross(hx.dFdy()).normalize().toVar("normalFlat"),fx=Ap((t=>{let e;return e=!0===t.material.flatShading?gx:zf(_x(mx),"v_normalView").normalize(),e}),"vec3").once()().toVar("normalView"),yx=zf(fx.transformDirection(Oy),"v_normalWorld").normalize().toVar("normalWorld"),xx=Ap((t=>t.context.setupNormal()),"vec3").once()().mul(dx).toVar("transformedNormalView"),bx=xx.transformDirection(Oy).toVar("transformedNormalWorld"),vx=Ap((t=>t.context.setupClearcoatNormal()),"vec3").once()().mul(dx).toVar("transformedClearcoatNormalView"),Tx=Ap((([t,e=Xy])=>{const s=Zp(e),i=t.div(kp(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(i).xyz})),_x=Ap((([t],e)=>{const s=e.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(t);const i=Ky.mul(t);return Oy.transformDirection(i)})),wx=lm(0).onReference((({material:t})=>t)).onRenderUpdate((({material:t})=>t.refractionRatio)),Sx=ux.negate().reflect(xx),Mx=ux.negate().refract(xx,wx),Ax=Sx.transformDirection(Oy).toVar("reflectVector"),Nx=Mx.transformDirection(Oy).toVar("reflectVector");class Cx extends Cy{static get type(){return"CubeTextureNode"}constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===ht?Ax:t.mapping===ut?Nx:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),kp(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Os&&s.isRenderTargetTexture?e:kp(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const Rx=Sp(Cx);class Ex extends um{static get type(){return"BufferNode"}constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const Bx=(t,e,s)=>Tp(new Ex(t,e,s));class Ix extends Od{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class Px extends Ex{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=Cd.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;sTp(new Px(t,e)),Ux=(t,e)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),Tp(new Px(t,e)));class Ox extends Od{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),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class zx extends Ud{static get type(){return"ReferenceNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=Cd.OBJECT}element(t){return Tp(new Ox(this,Tp(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;e=null!==this.count?Bx(null,t,this.count):Array.isArray(this.getValueFromReference())?Fx(null,t):"texture"===t?Ry(null):"cubeTexture"===t?Rx(null):lm(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 s=t[e[0]];for(let t=1;tTp(new zx(t,e,s)),Vx=(t,e,s,i)=>Tp(new zx(t,e,i,s));class Dx extends zx{static get type(){return"MaterialReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const kx=(t,e,s)=>Tp(new Dx(t,e,s)),Gx=Ap((t=>(!1===t.geometry.hasAttribute("tangent")&&t.geometry.computeTangents(),_y("tangent","vec4"))))(),Wx=Gx.xyz.toVar("tangentLocal"),jx=tx.mul(Hp(Wx,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Hx=jx.transformDirection(Oy).varying("v_tangentWorld").normalize().toVar("tangentWorld"),$x=jx.toVar("transformedTangentView"),qx=$x.transformDirection(Oy).normalize().toVar("transformedTangentWorld"),Xx=t=>t.mul(Gx.w).xyz,Yx=zf(Xx(px.cross(Gx)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),Zx=zf(Xx(mx.cross(Wx)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),Jx=zf(Xx(fx.cross(jx)),"v_bitangentView").normalize().toVar("bitangentView"),Kx=zf(Xx(yx.cross(Hx)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Qx=Xx(xx.cross($x)).normalize().toVar("transformedBitangentView"),tb=Qx.transformDirection(Oy).normalize().toVar("transformedBitangentWorld"),eb=Zp(jx,Jx,fx),sb=ux.mul(eb),ib=(t,e)=>t.sub(sb.mul(e)),rb=(()=>{let t=Cm.cross(ux);return t=t.cross(Cm).normalize(),t=xf(t,xx,Am.mul(fm.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})(),nb=Ap((t=>{const{eye_pos:e,surf_norm:s,mapN:i,uv:r}=t,n=e.dFdx(),o=e.dFdy(),a=r.dFdx(),h=r.dFdy(),u=s,l=o.cross(u),c=u.cross(n),d=l.mul(a.x).add(c.mul(h.x)),p=l.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=dx.mul(m.inverseSqrt());return qm(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()}));class ob extends Ld{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:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=kp(i.xy.mul(s),i.z));let r=null;if(1===e)r=_x(i);else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?eb.mul(i).normalize():nb({eye_pos:hx,surf_norm:fx,mapN:i,uv:wy()})}return r}}const ab=Sp(ob),hb=Ap((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||wy()),forceUVContext:!0}),i=Pp(s((t=>t)));return zp(Pp(s((t=>t.add(t.dFdx())))).sub(i),Pp(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),ub=Ap((t=>{const{surf_pos:e,surf_norm:s,dHdxy:i}=t,r=e.dFdx().normalize(),n=s,o=e.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(dx),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()}));class lb extends Ld{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=hb({textureNode:this.textureNode,bumpScale:t});return ub({surf_pos:hx,surf_norm:fx,dHdxy:e})}}const cb=Sp(lb),db=new Map;class pb extends Ud{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let s=db.get(t);return void 0===s&&(s=kx(t,e),db.set(t,s)),s}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,s=this.scope;let i=null;if(s===pb.COLOR){const t=void 0!==e.color?this.getColor(s):kp();i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===pb.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===pb.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:Pp(1);else if(s===pb.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===pb.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===pb.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===pb.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===pb.EMISSIVE){const t=this.getFloat("emissiveIntensity"),r=this.getColor(s).mul(t);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?r.mul(this.getTexture(s)):r}else if(s===pb.NORMAL)e.normalMap?(i=ab(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=e.normalMapType):i=e.bumpMap?cb(this.getTexture("bump").r,this.getFloat("bumpScale")):fx;else if(s===pb.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===pb.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===pb.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?ab(this.getTexture(s),this.getCache(s+"Scale","vec2")):fx;else if(s===pb.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(s===pb.SHEEN_ROUGHNESS){const t=this.getFloat(s);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(s).a):t,i=i.clamp(.07,1)}else if(s===pb.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=Yp(Jb.x,Jb.y,Jb.y.negate(),Jb.x).mul(t.rg.mul(2).sub(zp(1)).normalize().mul(t.b))}else i=Jb;else if(s===pb.IRIDESCENCE_THICKNESS){const t=Lx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=Lx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===pb.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===pb.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===pb.IOR)i=this.getFloat(s);else if(s===pb.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===pb.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}pb.ALPHA_TEST="alphaTest",pb.COLOR="color",pb.OPACITY="opacity",pb.SHININESS="shininess",pb.SPECULAR="specular",pb.SPECULAR_STRENGTH="specularStrength",pb.SPECULAR_INTENSITY="specularIntensity",pb.SPECULAR_COLOR="specularColor",pb.REFLECTIVITY="reflectivity",pb.ROUGHNESS="roughness",pb.METALNESS="metalness",pb.NORMAL="normal",pb.CLEARCOAT="clearcoat",pb.CLEARCOAT_ROUGHNESS="clearcoatRoughness",pb.CLEARCOAT_NORMAL="clearcoatNormal",pb.EMISSIVE="emissive",pb.ROTATION="rotation",pb.SHEEN="sheen",pb.SHEEN_ROUGHNESS="sheenRoughness",pb.ANISOTROPY="anisotropy",pb.IRIDESCENCE="iridescence",pb.IRIDESCENCE_IOR="iridescenceIOR",pb.IRIDESCENCE_THICKNESS="iridescenceThickness",pb.IOR="ior",pb.TRANSMISSION="transmission",pb.THICKNESS="thickness",pb.ATTENUATION_DISTANCE="attenuationDistance",pb.ATTENUATION_COLOR="attenuationColor",pb.LINE_SCALE="scale",pb.LINE_DASH_SIZE="dashSize",pb.LINE_GAP_SIZE="gapSize",pb.LINE_WIDTH="linewidth",pb.LINE_DASH_OFFSET="dashOffset",pb.POINT_WIDTH="pointWidth",pb.DISPERSION="dispersion",pb.LIGHT_MAP="light",pb.AO_MAP="ao";const mb=Mp(pb,pb.ALPHA_TEST),gb=Mp(pb,pb.COLOR),fb=Mp(pb,pb.SHININESS),yb=Mp(pb,pb.EMISSIVE),xb=Mp(pb,pb.OPACITY),bb=Mp(pb,pb.SPECULAR),vb=Mp(pb,pb.SPECULAR_INTENSITY),Tb=Mp(pb,pb.SPECULAR_COLOR),_b=Mp(pb,pb.SPECULAR_STRENGTH),wb=Mp(pb,pb.REFLECTIVITY),Sb=Mp(pb,pb.ROUGHNESS),Mb=Mp(pb,pb.METALNESS),Ab=Mp(pb,pb.NORMAL).context({getUV:null}),Nb=Mp(pb,pb.CLEARCOAT),Cb=Mp(pb,pb.CLEARCOAT_ROUGHNESS),Rb=Mp(pb,pb.CLEARCOAT_NORMAL).context({getUV:null}),Eb=Mp(pb,pb.ROTATION),Bb=Mp(pb,pb.SHEEN),Ib=Mp(pb,pb.SHEEN_ROUGHNESS),Pb=Mp(pb,pb.ANISOTROPY),Fb=Mp(pb,pb.IRIDESCENCE),Ub=Mp(pb,pb.IRIDESCENCE_IOR),Ob=Mp(pb,pb.IRIDESCENCE_THICKNESS),zb=Mp(pb,pb.TRANSMISSION),Lb=Mp(pb,pb.THICKNESS),Vb=Mp(pb,pb.IOR),Db=Mp(pb,pb.ATTENUATION_DISTANCE),kb=Mp(pb,pb.ATTENUATION_COLOR),Gb=Mp(pb,pb.LINE_SCALE),Wb=Mp(pb,pb.LINE_DASH_SIZE),jb=Mp(pb,pb.LINE_GAP_SIZE),Hb=Mp(pb,pb.LINE_WIDTH),$b=Mp(pb,pb.LINE_DASH_OFFSET),qb=Mp(pb,pb.POINT_WIDTH),Xb=Mp(pb,pb.DISPERSION),Yb=Mp(pb,pb.LIGHT_MAP),Zb=Mp(pb,pb.AO_MAP),Jb=lm(new Ys).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 Kb extends Ld{static get type(){return"ModelViewProjectionNode"}constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return zf(t.context.mvp);const e=this.positionNode||rx,s=t.renderer.nodes.modelViewMatrix||tx;return Fy.mul(s).mul(e)}}const Qb=Sp(Kb);class tv extends Ud{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i,r;if(s===tv.VERTEX)i=t.getVertexIndex();else if(s===tv.INSTANCE)i=t.getInstanceIndex();else if(s===tv.DRAW)i=t.getDrawIndex();else if(s===tv.INVOCATION_LOCAL)i=t.getInvocationLocalIndex();else if(s===tv.INVOCATION_SUBGROUP)i=t.getInvocationSubgroupIndex();else{if(s!==tv.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getSubgroupIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=zf(this).build(t,e)}return r}}tv.VERTEX="vertex",tv.INSTANCE="instance",tv.SUBGROUP="subgroup",tv.INVOCATION_LOCAL="invocationLocal",tv.INVOCATION_SUBGROUP="invocationSubgroup",tv.DRAW="draw";const ev=Mp(tv,tv.VERTEX),sv=Mp(tv,tv.INSTANCE),iv=Mp(tv,tv.SUBGROUP),rv=Mp(tv,tv.INVOCATION_SUBGROUP),nv=Mp(tv,tv.INVOCATION_LOCAL),ov=Mp(tv,tv.DRAW);class av extends Ud{static get type(){return"InstanceNode"}constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Cd.FRAME,this.buffer=null,this.bufferColor=null}setup(t){let e=this.instanceMatrixNode,s=this.instanceColorNode;const i=this.instanceMesh;if(null===e){const t=i.instanceMatrix;if(i.count<=1e3)e=Bx(t.array,"mat4",Math.max(i.count,1)).element(sv);else{const s=new vc(t.array,16,1);this.buffer=s;const i=t.usage===Ms?ry:iy,r=[i(s,"vec4",16,0),i(s,"vec4",16,4),i(s,"vec4",16,8),i(s,"vec4",16,12)];e=Jp(...r)}this.instanceMatrixNode=e}const r=i.instanceColor;if(r&&null===s){const t=new zo(r.array,3),e=r.usage===Ms?ry:iy;this.bufferColor=t,s=kp(e(t,"vec3",3,0)),this.instanceColorNode=s}const n=e.mul(rx).xyz;if(rx.assign(n),t.hasGeometryAttribute("normal")){const t=Tx(mx,e);mx.assign(t)}null!==this.instanceColorNode&&pm("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Ms&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Ms&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const hv=Sp(av);class uv extends Ud{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=sv:this.batchingIdNode=ov);const e=Ap((([t])=>{const e=My(Ey(this.batchMesh._indirectTexture),0),s=Fp(t).modInt(Fp(e)),i=Fp(t).div(Fp(e));return Ey(this.batchMesh._indirectTexture,Lp(s,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=e(Fp(this.batchingIdNode)),i=this.batchMesh._matricesTexture,r=My(Ey(i),0),n=Pp(s).mul(4).toInt().toVar(),o=n.modInt(r),a=n.div(Fp(r)),h=Jp(Ey(i,Lp(o,a)),Ey(i,Lp(o.add(1),a)),Ey(i,Lp(o.add(2),a)),Ey(i,Lp(o.add(3),a))),u=this.batchMesh._colorsTexture;if(null!==u){const t=Ap((([t])=>{const e=My(Ey(u),0).x,s=t,i=s.modInt(e),r=s.div(e);return Ey(u,Lp(i,r)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),e=t(s);pm("vec3","vBatchColor").assign(e)}const l=Zp(h);rx.assign(h.mul(rx));const c=mx.div(kp(l[0].dot(l[0]),l[1].dot(l[1]),l[2].dot(l[2]))),d=l.mul(c).xyz;mx.assign(d),t.hasGeometryAttribute("tangent")&&Wx.mulAssign(l)}}const lv=Sp(uv),cv=new WeakMap;class dv extends Ud{static get type(){return"SkinningNode"}constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=Cd.OBJECT,this.skinIndexNode=_y("skinIndex","uvec4"),this.skinWeightNode=_y("skinWeight","vec4"),e?(s=Lx("bindMatrix","mat4"),i=Lx("bindMatrixInverse","mat4"),r=Vx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=lm(t.bindMatrix,"mat4"),i=lm(t.bindMatrixInverse,"mat4"),r=Bx(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r,this.previousBoneMatricesNode=null}getSkinnedPosition(t=this.boneMatricesNode,e=rx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=t.element(s.x),a=t.element(s.y),h=t.element(s.z),u=t.element(s.w),l=r.mul(e),c=qm(o.mul(i.x).mul(l),a.mul(i.y).mul(l),h.mul(i.z).mul(l),u.mul(i.w).mul(l));return n.mul(c).xyz}getSkinnedNormal(t=this.boneMatricesNode,e=mx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=t.element(s.x),a=t.element(s.y),h=t.element(s.z),u=t.element(s.w);let l=qm(i.x.mul(o),i.y.mul(a),i.z.mul(h),i.w.mul(u));return l=n.mul(l).mul(r),l.transformDirection(e).xyz}getPreviousSkinnedPosition(t){const e=t.object;return null===this.previousBoneMatricesNode&&(e.skeleton.previousBoneMatrices=new Float32Array(e.skeleton.boneMatrices),this.previousBoneMatricesNode=Vx("skeleton.previousBoneMatrices","mat4",e.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,nx)}needsPreviousBoneMatrices(t){const e=t.renderer.getMRT();return e&&e.has("velocity")}setup(t){this.needsPreviousBoneMatrices(t)&&nx.assign(this.getPreviousSkinnedPosition(t));const e=this.getSkinnedPosition();if(rx.assign(e),t.hasGeometryAttribute("normal")){const e=this.getSkinnedNormal();mx.assign(e),t.hasGeometryAttribute("tangent")&&Wx.assign(e)}}generate(t,e){if("void"!==e)return rx.build(t,e)}update(t){const e=(this.useReference?t.object:this.skinnedMesh).skeleton;cv.get(e)!==t.frameId&&(cv.set(e,t.frameId),null!==this.previousBoneMatricesNode&&e.previousBoneMatrices.set(e.boneMatrices),e.update())}}const pv=t=>Tp(new dv(t)),mv=t=>Tp(new dv(t,!0));class gv extends Ud{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 s={};for(let t=0,e=this.params.length-1;tNumber(n)?">=":"<"));const l={start:r,end:n,condition:h},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;t.addFlowCode((0===e?"\n":"")+t.tab+f+" {\n\n").addFlowTab()}const r=i.build(t,"void"),n=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,s=this.params.length-1;eTp(new gv(wp(t,"int"))).append(),yv=()=>gy("continue").append(),xv=()=>gy("break").append(),bv=(...t)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),fv(...t)),vv=new WeakMap,Tv=new xi,_v=Ap((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=Fp(ev).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return Ey(t,Lp(h,a)).depth(r).mul(e)}));class wv extends Ud{static get type(){return"MorphNode"}constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=lm(1),this.updateType=Cd.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=e.hasAttribute("normal")&&void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(t){const e=void 0!==t.morphAttributes.position,s=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0;let o=vv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],u=t.morphAttributes.color||[];let l=0;!0===e&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=t.attributes.position.count*l,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new Ti(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*l;for(let x=0;x{const e=Pp(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(Ey(this.mesh.morphTexture,Lp(Fp(t).add(1),Fp(sv))).r):e.assign(Lx("morphTargetInfluences","float").element(t).toVar()),!0===s&&rx.addAssign(_v({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:Fp(0)})),!0===i&&mx.addAssign(_v({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:Fp(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 Sv=Sp(wv),Mv=(t,e)=>{for(const s of e)if(s.isAnalyticLightNode&&s.light.id===t)return s;return null},Av=new WeakMap;class Nv extends Ud{static get type(){return"LightsNode"}constructor(t=[]){super("vec3"),this.totalDiffuseNode=kp().toVar("totalDiffuse"),this.totalSpecularNode=kp().toVar("totalSpecular"),this.outgoingLightNode=kp().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 s of e.nodes)s.build(t)}setupLightsNode(t){const e=[],s=this._lightNodes,i=(t=>t.sort(((t,e)=>t.id-e.id)))(this._lights),r=t.renderer.nodes.library;for(const t of i)if(t.isNode)e.push(Tp(t));else{let i=null;if(null!==s&&(i=Mv(t.id,s)),null===i){const s=r.getLightNodeClass(t.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${t.constructor.name}`);continue}let i=null;Av.has(t)?i=Av.get(t):(i=new s(t),Av.set(t,i)),e.push(i)}}this._lightNodes=e}setup(t){null===this._lightNodes&&this.setupLightsNode(t);const e=t.context,s=e.lightingModel;let i=this.outgoingLightNode;if(s){const{_lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;e.outgoingLight=i;const a=t.addStack();t.getDataFromNode(this).nodes=a.nodes,s.start(e,a,t);for(const e of r)e.build(t);s.indirect(e,a,t);const{backdrop:h,backdropAlpha:u}=e,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=l.add(d);null!==h&&(m=kp(null!==u?u.mix(m,h):h),e.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(e,a,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 Cv=Sp(Nv);class Rv extends Ud{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class Ev extends Rv{static get type(){return"AONode"}constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}class Bv extends Ef{static get type(){return"LightingContextNode"}constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:kp().toVar("directDiffuse"),directSpecular:kp().toVar("directSpecular"),indirectDiffuse:kp().toVar("indirectDiffuse"),indirectSpecular:kp().toVar("indirectSpecular")};return{radiance:kp().toVar("radiance"),irradiance:kp().toVar("irradiance"),iblIrradiance:kp().toVar("iblIrradiance"),ambientOcclusion:Pp(1).toVar("ambientOcclusion"),reflectedLight:s,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 Iv=Sp(Bv);class Pv extends Rv{static get type(){return"IrradianceNode"}constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let Fv,Uv;class Ov extends Ud{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===Ov.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=Cd.NONE;return this.scope!==Ov.SIZE&&this.scope!==Ov.VIEWPORT||(t=Cd.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===Ov.VIEWPORT?null!==e?Uv.copy(e.viewport):(t.getViewport(Uv),Uv.multiplyScalar(t.getPixelRatio())):null!==e?(Fv.width=e.width,Fv.height=e.height):t.getDrawingBufferSize(Fv)}setup(){const t=this.scope;let e=null;return e=t===Ov.SIZE?lm(Fv||(Fv=new Ys)):t===Ov.VIEWPORT?lm(Uv||(Uv=new xi)):zp(Vv.div(Lv)),e}generate(t){if(this.scope===Ov.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(Lv).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}Ov.COORDINATE="coordinate",Ov.VIEWPORT="viewport",Ov.SIZE="size",Ov.UV="uv";const zv=Mp(Ov,Ov.UV),Lv=Mp(Ov,Ov.SIZE),Vv=Mp(Ov,Ov.COORDINATE),Dv=Mp(Ov,Ov.VIEWPORT),kv=Dv.zw,Gv=Vv.sub(Dv.xy),Wv=Gv.div(kv),jv=Ap((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Lv)),"vec2").once()(),Hv=Ap((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),zv)),"vec2").once()(),$v=Ap((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),zv.flipY())),"vec2").once()(),qv=new Ys;class Xv extends Cy{static get type(){return"ViewportTextureNode"}constructor(t=zv,e=null,s=null){null===s&&((s=new ka).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Cd.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(qv);const s=this.value;s.image.width===qv.width&&s.image.height===qv.height||(s.image.width=qv.width,s.image.height=qv.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const Yv=Sp(Xv),Zv=Sp(Xv,null,null,{generateMipmaps:!0});let Jv=null;class Kv extends Xv{static get type(){return"ViewportDepthTextureNode"}constructor(t=zv,e=null){null===Jv&&(Jv=new $a),super(t,e,Jv)}}const Qv=Sp(Kv);class tT extends Ud{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===tT.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===tT.DEPTH_BASE)null!==s&&(i=oT().assign(s));else if(e===tT.DEPTH)i=t.isPerspectiveCamera?iT(hx.z,Iy,Py):eT(hx.z,Iy,Py);else if(e===tT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=rT(s,Iy,Py);i=eT(t,Iy,Py)}else i=s;else i=eT(hx.z,Iy,Py);return i}}tT.DEPTH_BASE="depthBase",tT.DEPTH="depth",tT.LINEAR_DEPTH="linearDepth";const eT=(t,e,s)=>t.add(e).div(e.sub(s)),sT=(t,e,s)=>e.sub(s).mul(t).sub(e),iT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),rT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s)),nT=(t,e,s)=>{e=e.max(1e-6).toVar();const i=Cg(t.div(e).add(1)),r=Cg(s.div(e).add(1));return i.div(r)},oT=Sp(tT,tT.DEPTH_BASE),aT=Mp(tT,tT.DEPTH),hT=Sp(tT,tT.LINEAR_DEPTH),uT=hT(Qv());aT.assign=t=>oT(t);class lT extends Ud{static get type(){return"ClippingNode"}constructor(t=lT.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=e,n=r+i,o=s?n-i:n;return this.scope===lT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return Ap((()=>{const i=Fx(t),r=dm("float","distanceToPlane"),n=dm("float","distanceToGradient"),o=dm("float","clipOpacity");let a;if(o.assign(1),fv(s,(({i:t})=>{a=i.element(t),r.assign(hx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(_f(n.negate(),n,r)),o.equal(0).discard()})),s{a=i.element(e),r.assign(hx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(_f(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}mm.a.mulAssign(o),mm.a.equal(0).discard()}))()}setupDefault(t,e,s){return Ap((()=>{const i=Fx(t);let r;if(fv(s,(({i:t})=>{r=i.element(t),hx.dot(r.xyz).greaterThan(r.w).discard()})),s{r=i.element(e),t.assign(hx.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}lT.ALPHA_TO_COVERAGE="alphaToCoverage",lT.DEFAULT="default";class cT extends Jr{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.geometryNode=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+vd(this)}build(t){this.setup(t)}setupObserver(t){return new gd(t)}setup(t){let e;t.context.setupNormal=()=>this.setupNormal(t),t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),null!==this.geometryNode&&(t.stack.outputNode=t.stack.outputNode.bypass(this.geometryNode)),t.addFlow("vertex",t.removeStack()),t.addStack();const s=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!==s&&t.stack.add(s);const r=Hp(i,mm.a).max(0);e=this.setupOutput(t,r),Im.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const s=t.renderer.getMRT(),i=this.mrtNode;null!==s?(e=s,null!==i&&(e=s.merge(i))):null!==i&&(e=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=Hp(s)),e=this.setupOutput(t,s)}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:s}=t.clippingContext;let i=null;if(e||s){const e=t.renderer.samples;this.alphaToCoverage&&e>1?i=Tp(new lT(lT.ALPHA_TO_COVERAGE)):t.stack.add(Tp(new lT))}return i}setupDepth(t){const{renderer:e,camera:s}=t;let i=this.depthNode;if(null===i){const t=e.getMRT();t&&t.has("depth")?i=t.get("depth"):!0===e.logarithmicDepthBuffer&&(i=s.isPerspectiveCamera?nT(Qb().w,Iy,Py):eT(hx.z,Iy,Py))}null!==i&&aT.assign(i).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Sv(e).append(),!0===e.isSkinnedMesh&&mv(e).append(),this.displacementMap){const t=kx("displacementMap","texture"),e=kx("displacementScale","float"),s=kx("displacementBias","float");rx.addAssign(mx.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&lv(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&hv(e).append(),null!==this.positionNode&&rx.assign(this.positionNode);const i=Qb();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?Hp(this.colorNode):gb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=Hp(s.xyz.mul(_y("color","vec3")),s.a)),t.instanceColor){s=pm("vec3","vInstanceColor").mul(s)}if(t.isBatchedMesh&&t._colorsTexture){s=pm("vec3","vBatchColor").mul(s)}mm.assign(s);const i=this.opacityNode?Pp(this.opacityNode):xb;if(mm.a.assign(mm.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?Pp(this.alphaTestNode):mb;mm.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&mm.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?kp(0):mm.rgb}setupNormal(){return this.normalNode?kp(this.normalNode):Ab}setupEnvironment(){let t=null;return this.envNode?t=this.envNode:this.envMap&&(t=this.envMap.isCubeTexture?kx("envMap","cubeTexture"):kx("envMap","texture")),t}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new Pv(Yb)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);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:Zb;e.push(new Ev(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=Cv([...r.getLights(),...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let o=this.setupOutgoingLight(t);if(n&&n.getScope().getLights().length>0){const e=this.setupLightingModel(t);o=Iv(n,e,s,i)}else null!==s&&(o=kp(null!==i?xf(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(gm.assign(kp(r||yb)),o=o.add(gm)),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=Hp(s.mix(e.rgb,s.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const s=t[e];void 0===this[e]&&(this[e]=s,s&&s.clone&&(this[e]=s.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 s=Jr.prototype.toJSON.call(this,t),i=Td(this);s.inputNodes={};for(const{property:e,childNode:r}of i)s.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),n=r(t.nodes);e.length>0&&(s.textures=e),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}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.geometryNode=t.geometryNode,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 dT=new Ia;class pT extends cT{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(dT),this.setValues(t)}setup(t){this.setupShaders(t),super.setup(t)}setupShaders({renderer:t}){const e=this.alphaToCoverage,s=this.useColor;this.vertexNode=Ap((()=>{const t=_y("instancePosition").xyz,e=Hp(tx.mul(Hp(t,1))),s=Dv.z.div(Dv.w),i=Fy.mul(e),r=ix.xy.toVar();return r.mulAssign(this.pointWidthNode?this.pointWidthNode:qb),r.assign(r.div(Dv.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.addAssign(Hp(r,0,0)),i}))(),this.fragmentNode=Ap((()=>{const i=Pp(1).toVar(),r=yf(wy().mul(2).sub(1));if(e&&t.samples>1){const t=Pp(r.fwidth()).toVar();i.assign(_f(t.oneMinus(),t.add(1),r).oneMinus())}else r.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=_y("instanceColor").mul(gb)}else n=gb;return i.mulAssign(xb),Hp(n,i)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}const mT=new xa;class gT extends cT{static get type(){return"LineBasicNodeMaterial"}constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(mT),this.setValues(t)}}const fT=new Cu;class yT extends cT{static get type(){return"LineDashedNodeMaterial"}constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(fT),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?Pp(this.dashScaleNode):Gb,s=this.dashSizeNode?Pp(this.dashSizeNode):Wb,i=this.dashSizeNode?Pp(this.dashGapNode):jb;Pm.assign(s),Fm.assign(i);const r=zf(_y("lineDistance").mul(e));(t?r.add(t):r).mod(Pm.add(Fm)).greaterThan(Pm).discard()}}const xT=new Cu;class bT extends cT{static get type(){return"Line2NodeMaterial"}constructor(t={}){super(),this.lights=!1,this.setDefaultValues(xT),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,s=this.useColor,i=this.dashed,r=this.worldUnits,n=Ap((({start:t,end:e})=>{const s=Fy.element(2).element(2),i=Fy.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return Hp(xf(t.xyz,e.xyz,i),e.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=Ap((()=>{const t=_y("instanceStart"),e=_y("instanceEnd"),s=Hp(tx.mul(Hp(t,1))).toVar("start"),o=Hp(tx.mul(Hp(e,1))).toVar("end");r&&(pm("vec3","worldStart").assign(s.xyz),pm("vec3","worldEnd").assign(o.xyz));const a=Dv.z.div(Dv.w),h=Fy.element(2).element(3).equal(-1);Ep(h,(()=>{Ep(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(n({start:o,end:s}))}))}));const u=Fy.mul(s),l=Fy.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=Hp().toVar();if(r){const t=o.xyz.sub(s.xyz).normalize(),e=xf(s.xyz,o.xyz,.5).normalize(),r=t.cross(e).normalize(),n=t.cross(r),a=pm("vec4","worldPos");a.assign(ix.y.lessThan(.5).select(s,o));const h=Hb.mul(.5);a.addAssign(Hp(ix.x.lessThan(0).select(r.mul(h),r.mul(h).negate()),0)),i||(a.addAssign(Hp(ix.y.lessThan(.5).select(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(Hp(n.mul(h),0)),Ep(ix.y.greaterThan(1).or(ix.y.lessThan(0)),(()=>{a.subAssign(Hp(n.mul(2).mul(h),0))}))),m.assign(Fy.mul(a));const u=kp().toVar();u.assign(ix.y.lessThan(.5).select(c,d)),m.z.assign(u.z.mul(m.w))}else{const t=zp(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(ix.x.lessThan(0).select(t.negate(),t)),Ep(ix.y.lessThan(0),(()=>{t.assign(t.sub(p))})).ElseIf(ix.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Hb)),t.assign(t.div(Dv.w)),m.assign(ix.y.lessThan(.5).select(u,l)),t.assign(t.mul(m.w)),m.assign(m.add(Hp(t,0,0)))}return m}))();const o=Ap((({p1:t,p2:e,p3:s,p4:i})=>{const r=t.sub(s),n=i.sub(s),o=e.sub(t),a=r.dot(n),h=n.dot(o),u=r.dot(o),l=n.dot(n),c=o.dot(o).mul(l).sub(h.mul(h)),d=a.mul(h).sub(u.mul(l)).div(c).clamp(),p=a.add(h.mul(d)).div(l).clamp();return zp(d,p)}));this.fragmentNode=Ap((()=>{const n=wy();if(i){const t=this.offsetNode?Pp(this.offsetNodeNode):$b,e=this.dashScaleNode?Pp(this.dashScaleNode):Gb,s=this.dashSizeNode?Pp(this.dashSizeNode):Wb,i=this.dashSizeNode?Pp(this.dashGapNode):jb;Pm.assign(s),Fm.assign(i);const r=_y("instanceDistanceStart"),o=_y("instanceDistanceEnd"),a=ix.y.lessThan(.5).select(e.mul(r),Gb.mul(o)),h=zf(a.add($b)),u=t?h.add(t):h;n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),u.mod(Pm.add(Fm)).greaterThan(Pm).discard()}const a=Pp(1).toVar("alpha");if(r){const s=pm("vec3","worldStart"),r=pm("vec3","worldEnd"),n=pm("vec4","worldPos").xyz.normalize().mul(1e5),h=r.sub(s),u=o({p1:s,p2:r,p3:kp(0,0,0),p4:n}),l=s.add(h.mul(u.x)),c=n.mul(u.y),d=l.sub(c).length().div(Hb);if(!i)if(e&&t.samples>1){const t=d.fwidth();a.assign(_f(t.negate().add(.5),t.add(.5),d).oneMinus())}else d.greaterThan(.5).discard()}else if(e&&t.samples>1){const t=n.x,e=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=t.mul(t).add(e.mul(e)),i=Pp(s.fwidth()).toVar("dlen");Ep(n.y.abs().greaterThan(1),(()=>{a.assign(_f(i.oneMinus(),i.add(1),s).oneMinus())}))}else Ep(n.y.abs().greaterThan(1),(()=>{const t=n.x,e=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let h;if(this.lineColorNode)h=this.lineColorNode;else if(s){const t=_y("instanceColorStart"),e=_y("instanceColorEnd");h=ix.y.lessThan(.5).select(t,e).mul(gb)}else h=gb;return Hp(h,a)}))()}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 vT=t=>Tp(t).mul(.5).add(.5),TT=t=>Tp(t).mul(2).sub(1),_T=new wu;class wT extends cT{static get type(){return"MeshNormalNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(_T),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?Pp(this.opacityNode):xb;mm.assign(Hp(vT(xx),t))}}class ST extends Ld{static get type(){return"EquirectUVNode"}constructor(t=ax){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),s=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return zp(e,s)}}const MT=Sp(ST);class AT extends Yn{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const s=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 r=new Ln(5,5,5),n=MT(ax),o=new cT;o.colorNode=Ry(e,n,0),o.side=d,o.blending=m;const a=new On(r,o),h=new Kn;h.add(a),e.minFilter===St&&(e.minFilter=Tt);const u=new qn(1,10,this),l=t.getMRT();return t.setMRT(null),u.update(t,h),t.setMRT(l),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const NT=new WeakMap;class CT extends Ld{static get type(){return"CubeMapNode"}constructor(t){super("vec3"),this.envNode=t,this._cubeTexture=null,this._cubeTextureNode=Rx();const e=new Xn;e.isRenderTargetTexture=!0,this._defaultTexture=e,this.updateBeforeType=Cd.RENDER}updateBefore(t){const{renderer:e,material:s}=t,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const t=i.isTextureNode?i.value:s[i.property];if(t&&t.isTexture){const s=t.mapping;if(s===lt||s===ct){if(NT.has(t)){const e=NT.get(t);ET(e,t.mapping),this._cubeTexture=e}else{const s=t.image;if(function(t){return null!=t&&t.height>0}(s)){const i=new AT(s.height);i.fromEquirectangularTexture(e,t),ET(i.texture,t.mapping),this._cubeTexture=i.texture,NT.set(t,i.texture),t.addEventListener("dispose",RT)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(t){return this.updateBefore(t),this._cubeTextureNode}}function RT(t){const e=t.target;e.removeEventListener("dispose",RT);const s=NT.get(e);void 0!==s&&(NT.delete(e),s.dispose())}function ET(t,e){e===lt?t.mapping=ht:e===ct&&(t.mapping=ut)}const BT=Sp(CT);class IT extends Rv{static get type(){return"BasicEnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=BT(this.envNode)}}class PT extends Rv{static get type(){return"BasicLightMapNode"}constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=Pp(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}class FT{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class UT extends FT{constructor(){super()}indirect(t,e,s){const i=t.ambientOcclusion,r=t.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(Hp(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(Hp(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(mm.rgb)}finish(t,e,s){const i=s.material,r=t.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(xf(r.rgb,r.rgb.mul(n.rgb),_b.mul(wb)));break;case 1:r.rgb.assign(xf(r.rgb,n.rgb,_b.mul(wb)));break;case 2:r.rgb.addAssign(n.rgb.mul(_b.mul(wb)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const OT=new Kr;class zT extends cT{static get type(){return"MeshBasicNodeMaterial"}constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(OT),this.setValues(t)}setupNormal(){return fx}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new PT(Yb)),e}setupOutgoingLight(){return mm.rgb}setupLightingModel(){return new UT}}const LT=Ap((({f0:t,f90:e,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),VT=Ap((t=>t.diffuseColor.mul(1/Math.PI))),DT=Ap((({dotNH:t})=>Bm.mul(Pp(.5)).add(1).mul(Pp(1/Math.PI)).mul(t.pow(Bm)))),kT=Ap((({lightDirection:t})=>{const e=t.add(ux).normalize(),s=xx.dot(e).clamp(),i=ux.dot(e).clamp(),r=LT({f0:Rm,f90:1,dotVH:i}),n=Pp(.25),o=DT({dotNH:s});return r.mul(n).mul(o)}));class GT extends UT{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=xx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(VT({diffuseColor:mm.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(kT({lightDirection:t})).mul(_b))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(VT({diffuseColor:mm}))),s.indirectDiffuse.mulAssign(t)}}const WT=new Su;class jT extends cT{static get type(){return"MeshLambertNodeMaterial"}constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(WT),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightingModel(){return new GT(!1)}}const HT=new Tu;class $T extends cT{static get type(){return"MeshPhongNodeMaterial"}constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(HT),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightingModel(){return new GT}setupVariants(){const t=(this.shininessNode?Pp(this.shininessNode):fb).max(1e-4);Bm.assign(t);const e=this.specularNode||bb;Rm.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}const qT=Ap((()=>{const t=fx.dFdx().abs().max(fx.dFdy().abs());return t.x.max(t.y).max(t.z)})),XT=Ap((t=>{const{roughness:e}=t,s=qT();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),YT=Ap((({alpha:t,dotNL:e,dotNV:s})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return Zm(.5,r.add(n).max(fg))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),ZT=Ap((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(kp(t.mul(s),e.mul(i),o).length()),u=o.mul(kp(t.mul(r),e.mul(n),a).length());return Zm(.5,h.add(u)).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"}]}),JT=Ap((({alpha:t,dotNH:e})=>{const s=t.pow2(),i=e.pow2().mul(s.oneMinus()).oneMinus();return s.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),KT=Pp(1/Math.PI),QT=Ap((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=kp(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return KT.mul(n.mul(h.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"}]}),t_=Ap((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||xx,u=r.pow2(),l=e.add(ux).normalize(),c=h.dot(e).clamp(),d=h.dot(ux).clamp(),p=h.dot(l).clamp(),m=ux.dot(l).clamp();let g,f,y=LT({f0:s,f90:i,dotVH:m});if(xp(o)&&(y=_m.mix(y,n)),xp(a)){const t=Nm.dot(e),s=Nm.dot(ux),i=Nm.dot(l),r=Cm.dot(e),n=Cm.dot(ux),o=Cm.dot(l);g=ZT({alphaT:Mm,alphaB:u,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=QT({alphaT:Mm,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=YT({alpha:u,dotNL:c,dotNV:d}),f=JT({alpha:u,dotNH:p});return y.mul(g).mul(f)})),e_=Ap((({roughness:t,dotNV:e})=>{const s=Hp(-1,-.0275,-.572,.022),i=Hp(1,.0425,1.04,-.04),r=t.mul(s).add(i),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return zp(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),s_=Ap((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=e_({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),i_=Ap((({f:t,f90:e,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return t.sub(kp(e).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),r_=Ap((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=Pp(1).div(s),r=e.pow2().oneMinus().max(.0078125);return Pp(2).add(i).mul(r.pow(i.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),n_=Ap((({dotNV:t,dotNL:e})=>Pp(1).div(Pp(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),o_=Ap((({lightDirection:t})=>{const e=t.add(ux).normalize(),s=xx.dot(t).clamp(),i=xx.dot(ux).clamp(),r=xx.dot(e).clamp(),n=r_({roughness:Tm,dotNH:r}),o=n_({dotNV:i,dotNL:s});return vm.mul(n).mul(o)})),a_=Ap((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=zp(s,i.oneMinus().sqrt());return r.assign(r.mul(.984375).add(.0078125)),r})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),h_=Ap((({f:t})=>{const e=t.length();return sf(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),u_=Ap((({v1:t,v2:e})=>{const s=t.dot(e),i=s.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),o=r.div(n),a=s.greaterThan(0).select(o,sf(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return t.cross(e).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),l_=Ap((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),u=a.sub(r).toVar(),l=h.cross(u),c=kp().toVar();return Ep(l.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),u=t.cross(h).negate(),l=i.mul(Zp(h,u,t).transpose()).toVar(),d=l.mul(r.sub(s)).normalize().toVar(),p=l.mul(n.sub(s)).normalize().toVar(),m=l.mul(o.sub(s)).normalize().toVar(),g=l.mul(a.sub(s)).normalize().toVar(),f=kp(0).toVar();f.addAssign(u_({v1:d,v2:p})),f.addAssign(u_({v1:p,v2:m})),f.addAssign(u_({v1:m,v2:g})),f.addAssign(u_({v1:g,v2:d})),c.assign(kp(h_({f:f})))})),c})).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"}]}),c_=1/6,d_=t=>Ym(c_,Ym(t,Ym(t,t.negate().add(3)).sub(3)).add(1)),p_=t=>Ym(c_,Ym(t,Ym(t,Ym(3,t).sub(6))).add(4)),m_=t=>Ym(c_,Ym(t,Ym(t,Ym(-3,t).add(3)).add(3)).add(1)),g_=t=>Ym(c_,cf(t,3)),f_=t=>d_(t).add(p_(t)),y_=t=>m_(t).add(g_(t)),x_=t=>qm(-1,p_(t).div(d_(t).add(p_(t)))),b_=t=>qm(1,g_(t).div(m_(t).add(g_(t)))),v_=(t,e,s)=>{const i=t.uvNode,r=Ym(i,e.zw).add(.5),n=Bg(r),o=Fg(r),a=f_(o.x),h=y_(o.x),u=x_(o.x),l=b_(o.x),c=x_(o.y),d=b_(o.y),p=zp(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),m=zp(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),g=zp(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),f=zp(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=f_(o.y).mul(qm(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=y_(o.y).mul(qm(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)},T_=Ap((([t,e=Pp(3)])=>{const s=zp(t.size(Fp(e))),i=zp(t.size(Fp(e.add(1)))),r=Zm(1,s),n=Zm(1,i),o=v_(t,Hp(r,s),Bg(e)),a=v_(t,Hp(n,i),Ig(e));return Fg(e).mix(o,a)})),__=Ap((([t,e,s,i,r])=>{const n=kp(Tf(e.negate(),Pg(t),Zm(1,i))),o=kp(Wg(r[0].xyz),Wg(r[1].xyz),Wg(r[2].xyz));return Pg(n).mul(s.mul(o))})).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"}]}),w_=Ap((([t,e])=>t.mul(bf(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),S_=Zv(),M_=Ap((([t,e,s])=>{const i=S_.uv(t),r=Cg(Pp(Lv.x)).mul(w_(e,s));return T_(i,r)})),A_=Ap((([t,e,s])=>(Ep(s.notEqual(0),(()=>{const i=Ng(e).negate().div(s);return Mg(i.negate().mul(t))})),kp(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),N_=Ap((([t,e,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=Hp().toVar(),f=kp().toVar();const r=l.sub(1).mul(m.mul(.025)),n=kp(l.sub(r),l,l.add(r));fv({start:0,end:3},(({i:r})=>{const l=n.element(r),m=__(t,e,c,l,a),y=o.add(m),x=u.mul(h.mul(Hp(y,1))),b=zp(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(zp(b.x,b.y.oneMinus()));const v=M_(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(A_(Wg(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=__(t,e,c,l,a),n=o.add(r),m=u.mul(h.mul(Hp(n,1))),y=zp(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(zp(y.x,y.y.oneMinus())),g=M_(y,s,l),f=i.mul(A_(Wg(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=kp(s_({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return Hp(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),C_=Zp(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),R_=(t,e)=>t.sub(e).div(t.add(e)).pow2(),E_=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=kp(54856e-17,44201e-17,52481e-17),r=kp(1681e3,1795300,2208400),n=kp(43278e5,93046e5,66121e5),o=Pp(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(e.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(e).cos()).mul(s.pow2().negate().mul(n).exp());a=kp(a.x.add(o),a.y,a.z).div(1.0685e-7);return C_.mul(a)},B_=Ap((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=xf(t,e,_f(0,.03,i)),o=t.div(n).pow2().mul(Pp(1).sub(s.pow2())),a=Pp(1).sub(o).sqrt(),h=R_(n,t),u=LT({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(t).select(Math.PI,0),d=Pp(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return kp(1).add(e).div(kp(1).sub(e))})(r.clamp(0,.9999)),m=R_(p,n.toVec3()),g=LT({f0:m,f90:1,dotVH:a}),f=kp(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(i,a,2),x=kp(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(kp(1).sub(b));let _=u.add(T),w=T.sub(l);for(let t=1;t<=2;++t){w=w.mul(v);const e=E_(Pp(t).mul(y),Pp(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(kp(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"}]}),I_=Ap((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=Cf(s.lessThan(.25),Pp(-339.2).mul(r).add(Pp(161.4).mul(s)).sub(25.9),Pp(-8.48).mul(r).add(Pp(14.3).mul(s)).sub(9.95)),o=Cf(s.lessThan(.25),Pp(44).mul(r).sub(Pp(23.7).mul(s)).add(3.26),Pp(1.97).mul(r).sub(Pp(3.27).mul(s)).add(.72));return Cf(s.lessThan(.25),0,Pp(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),P_=kp(.04),F_=Pp(1);class U_ extends FT{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=s,this.anisotropy=i,this.transmission=r,this.dispersion=n,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=kp().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=kp().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=kp().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=kp().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=kp().toVar("sheenSpecularIndirect")),!0===this.iridescence){const t=xx.dot(ux).clamp();this.iridescenceFresnel=B_({outsideIOR:Pp(1),eta2:wm,cosTheta1:t,thinFilmThickness:Sm,baseF0:Rm}),this.iridescenceF0=i_({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=ox,s=Vy.sub(ox).normalize(),i=bx;t.backdrop=N_(i,s,fm,mm,Rm,Em,e,Xy,Oy,Fy,Om,Lm,Dm,Vm,this.dispersion?km:null),t.backdropAlpha=zm,mm.a.mulAssign(xf(1,t.backdrop.a,zm))}}computeMultiscattering(t,e,s){const i=xx.dot(ux).clamp(),r=e_({roughness:fm,dotNV:i}),n=(this.iridescenceF0?_m.mix(Rm,this.iridescenceF0):Rm).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Rm.add(Rm.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());t.addAssign(n),e.addAssign(h.mul(o))}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=xx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(o_({lightDirection:t}))),!0===this.clearcoat){const s=vx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(t_({lightDirection:t,f0:P_,f90:F_,roughness:bm,normalView:vx})))}s.directDiffuse.addAssign(i.mul(VT({diffuseColor:mm.rgb}))),s.directSpecular.addAssign(i.mul(t_({lightDirection:t,f0:Rm,f90:1,roughness:fm,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=e.add(s).sub(i),h=e.sub(s).sub(i),u=e.sub(s).add(i),l=e.add(s).add(i),c=xx,d=ux,p=hx.toVar(),m=a_({N:c,V:d,roughness:fm}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=Zp(kp(g.x,0,g.y),kp(0,1,0),kp(g.z,0,g.w)).toVar(),x=Rm.mul(f.x).add(Rm.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(l_({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(t.mul(mm).mul(l_({N:c,V:d,P:p,mInv:Zp(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(t,e,s){this.indirectDiffuse(t,e,s),this.indirectSpecular(t,e,s),this.ambientOcclusion(t,e,s)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(VT({diffuseColor:mm})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(vm,I_({normal:xx,viewDir:ux,roughness:Tm}))),!0===this.clearcoat){const t=vx.dot(ux).clamp(),e=s_({dotNV:t,specularColor:P_,specularF90:F_,roughness:bm});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=kp().toVar("singleScattering"),r=kp().toVar("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Em);const o=i.add(r),a=mm.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(t.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const s=xx.dot(ux).clamp().add(t),i=fm.mul(-16).oneMinus().negate().exp2(),r=t.sub(s.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(r)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=vx.dot(ux).clamp(),s=LT({dotVH:t,f0:P_,f90:F_}),i=e.mul(xm.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(xm));e.assign(i)}if(!0===this.sheen){const t=vm.r.max(vm.g).max(vm.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const O_=Pp(1),z_=Pp(-2),L_=Pp(.8),V_=Pp(-1),D_=Pp(.4),k_=Pp(2),G_=Pp(.305),W_=Pp(3),j_=Pp(.21),H_=Pp(4),$_=Pp(4),q_=Pp(16),X_=Ap((([t])=>{const e=kp(kg(t)).toVar(),s=Pp(-1).toVar();return Ep(e.x.greaterThan(e.z),(()=>{Ep(e.x.greaterThan(e.y),(()=>{s.assign(Cf(t.x.greaterThan(0),0,3))})).Else((()=>{s.assign(Cf(t.y.greaterThan(0),1,4))}))})).Else((()=>{Ep(e.z.greaterThan(e.y),(()=>{s.assign(Cf(t.z.greaterThan(0),2,5))})).Else((()=>{s.assign(Cf(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),Y_=Ap((([t,e])=>{const s=zp().toVar();return Ep(e.equal(0),(()=>{s.assign(zp(t.z,t.y).div(kg(t.x)))})).ElseIf(e.equal(1),(()=>{s.assign(zp(t.x.negate(),t.z.negate()).div(kg(t.y)))})).ElseIf(e.equal(2),(()=>{s.assign(zp(t.x.negate(),t.y).div(kg(t.z)))})).ElseIf(e.equal(3),(()=>{s.assign(zp(t.z.negate(),t.y).div(kg(t.x)))})).ElseIf(e.equal(4),(()=>{s.assign(zp(t.x.negate(),t.z).div(kg(t.y)))})).Else((()=>{s.assign(zp(t.x,t.y).div(kg(t.z)))})),Ym(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),Z_=Ap((([t])=>{const e=Pp(0).toVar();return Ep(t.greaterThanEqual(L_),(()=>{e.assign(O_.sub(t).mul(V_.sub(z_)).div(O_.sub(L_)).add(z_))})).ElseIf(t.greaterThanEqual(D_),(()=>{e.assign(L_.sub(t).mul(k_.sub(V_)).div(L_.sub(D_)).add(V_))})).ElseIf(t.greaterThanEqual(G_),(()=>{e.assign(D_.sub(t).mul(W_.sub(k_)).div(D_.sub(G_)).add(k_))})).ElseIf(t.greaterThanEqual(j_),(()=>{e.assign(G_.sub(t).mul(H_.sub(W_)).div(G_.sub(j_)).add(W_))})).Else((()=>{e.assign(Pp(-2).mul(Cg(Ym(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),J_=Ap((([t,e])=>{const s=t.toVar();s.assign(Ym(2,s).sub(1));const i=kp(s,1).toVar();return Ep(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"}]}),K_=Ap((([t,e,s,i,r,n])=>{const o=Pp(s),a=kp(e),h=bf(Z_(o),z_,n),u=Fg(h),l=Bg(h),c=kp(Q_(t,a,l,i,r,n)).toVar();return Ep(u.notEqual(0),(()=>{const e=kp(Q_(t,a,l.add(1),i,r,n)).toVar();c.assign(xf(c,e,u))})),c})),Q_=Ap((([t,e,s,i,r,n])=>{const o=Pp(s).toVar(),a=kp(e),h=Pp(X_(a)).toVar(),u=Pp(sf($_.sub(o),0)).toVar();o.assign(sf(o,$_));const l=Pp(Ag(o)).toVar(),c=zp(Y_(a,h).mul(l.sub(2)).add(1)).toVar();return Ep(h.greaterThan(2),(()=>{c.y.addAssign(l),h.subAssign(3)})),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(Ym(3,q_))),c.y.addAssign(Ym(4,Ag(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(zp(),zp())})),tw=Ap((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=Og(i),u=s.mul(h).add(r.cross(s).mul(Ug(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return Q_(t,u,e,n,o,a)})),ew=Ap((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})=>{const d=kp(Cf(e,s,lf(s,i))).toVar();Ep(vg(d.equals(kp(0))),(()=>{d.assign(kp(i.z,0,i.x.negate()))})),d.assign(Pg(d));const p=kp().toVar();return p.addAssign(r.element(Fp(0)).mul(tw({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),fv({start:Fp(1),end:t},(({i:t})=>{Ep(t.greaterThanEqual(n),(()=>{xv()}));const e=Pp(o.mul(Pp(t))).toVar();p.addAssign(r.element(t).mul(tw({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(tw({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))})),Hp(p,1)}));let sw=null;const iw=new WeakMap;function rw(t){let e=iw.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){const s=t.image;if(t.isCubeTexture){if(!function(t){if(null==t)return!1;let e=0;const s=6;for(let i=0;i0}(s))return null;e=sw.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,iw.set(t,e)}return e.texture}class nw extends Ld{static get type(){return"PMREMNode"}constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null;const i=new yi;i.isRenderTargetTexture=!0,this._texture=Ry(i),this._width=lm(0),this._height=lm(0),this._maxMip=lm(0),this.updateBeforeType=Cd.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,s=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:s,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,s=this._value;e!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:rw(s),null!==t&&(this._pmrem=t,this.updateFromTexture(t)))}setup(t){null===sw&&(sw=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const s=this.value;t.renderer.coordinateSystem===Us&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=kp(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),K_(this._texture,e,i,this._width,this._height,this._maxMip)}}const ow=Sp(nw),aw=new WeakMap;class hw extends Rv{static get type(){return"EnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){const{material:e}=t;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const t=s.isTextureNode?s.value:e[s.property];let i=aw.get(t);void 0===i&&(i=ow(t),aw.set(t,i)),s=i}const i=e.envMap?Lx("envMapIntensity","float",t.material):Lx("environmentIntensity","float",t.scene),r=!0===e.useAnisotropy||e.anisotropy>0?rb:xx,n=s.context(uw(fm,r)).mul(i),o=s.context(lw(bx)).mul(Math.PI).mul(i),a=hy(n),h=hy(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const u=t.context.lightingModel.clearcoatRadiance;if(u){const t=s.context(uw(bm,vx)).mul(i),e=hy(t);u.addAssign(e)}}}const uw=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=ux.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Oy)),s),getTextureLevel:()=>t}},lw=t=>({getUV:()=>t,getTextureLevel:()=>Pp(1)}),cw=new bu;class dw extends cT{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(cw),this.setValues(t)}setupEnvironment(t){let e=super.setupEnvironment(t);return null===e&&t.environmentNode&&(e=t.environmentNode),e?new hw(e):null}setupLightingModel(){return new U_}setupSpecular(){const t=xf(kp(.04),mm.rgb,ym);Rm.assign(t),Em.assign(1)}setupVariants(){const t=this.metalnessNode?Pp(this.metalnessNode):Mb;ym.assign(t);let e=this.roughnessNode?Pp(this.roughnessNode):Sb;e=XT({roughness:e}),fm.assign(e),this.setupSpecular(),mm.assign(Hp(mm.rgb.mul(t.oneMinus()),mm.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}const pw=new vu;class mw extends dw{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(pw),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?Pp(this.iorNode):Vb;Om.assign(t),Rm.assign(xf(ef(df(Om.sub(1).div(Om.add(1))).mul(Tb),kp(1)).mul(vb),mm.rgb,ym)),Em.assign(xf(vb,1,ym))}setupLightingModel(){return new U_(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?Pp(this.clearcoatNode):Nb,e=this.clearcoatRoughnessNode?Pp(this.clearcoatRoughnessNode):Cb;xm.assign(t),bm.assign(XT({roughness:e}))}if(this.useSheen){const t=this.sheenNode?kp(this.sheenNode):Bb,e=this.sheenRoughnessNode?Pp(this.sheenRoughnessNode):Ib;vm.assign(t),Tm.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?Pp(this.iridescenceNode):Fb,e=this.iridescenceIORNode?Pp(this.iridescenceIORNode):Ub,s=this.iridescenceThicknessNode?Pp(this.iridescenceThicknessNode):Ob;_m.assign(t),wm.assign(e),Sm.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?zp(this.anisotropyNode):Pb).toVar();Am.assign(t.length()),Ep(Am.equal(0),(()=>{t.assign(zp(1,0))})).Else((()=>{t.divAssign(zp(Am)),Am.assign(Am.saturate())})),Mm.assign(Am.pow2().mix(fm.pow2(),1)),Nm.assign(eb[0].mul(t.x).add(eb[1].mul(t.y))),Cm.assign(eb[1].mul(t.x).sub(eb[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?Pp(this.transmissionNode):zb,e=this.thicknessNode?Pp(this.thicknessNode):Lb,s=this.attenuationDistanceNode?Pp(this.attenuationDistanceNode):Db,i=this.attenuationColorNode?kp(this.attenuationColorNode):kb;if(zm.assign(t),Lm.assign(e),Vm.assign(s),Dm.assign(i),this.useDispersion){const t=this.dispersionNode?Pp(this.dispersionNode):Xb;km.assign(t)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?kp(this.clearcoatNormalNode):Rb}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 gw extends U_{constructor(t,e,s,i){super(t,e,s),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){if(!0===this.useSSS){const i=r.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:h,thicknessPowerNode:u,thicknessScaleNode:l}=i,c=t.add(xx.mul(o)).normalize(),d=Pp(ux.dot(c.negate()).saturate().pow(u).mul(l)),p=kp(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class fw extends mw{static get type(){return"MeshSSSNodeMaterial"}constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=Pp(.1),this.thicknessAmbientNode=Pp(0),this.thicknessAttenuationNode=Pp(.1),this.thicknessPowerNode=Pp(2),this.thicknessScaleNode=Pp(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new gw(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 yw=Ap((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=zp(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=kx("gradientMap","texture").context({getUV:()=>r});return kp(t.r)}{const t=r.fwidth().mul(.5);return xf(kp(.7),kp(1),_f(Pp(.7).sub(t.x),Pp(.7).add(t.x),r.x))}}));class xw extends FT{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=yw({normal:px,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(VT({diffuseColor:mm.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(VT({diffuseColor:mm}))),s.indirectDiffuse.mulAssign(t)}}const bw=new _u;class vw extends cT{static get type(){return"MeshToonNodeMaterial"}constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(bw),this.setValues(t)}setupLightingModel(){return new xw}}class Tw extends Ld{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const t=kp(ux.z,0,ux.x.negate()).normalize(),e=ux.cross(t);return zp(t.dot(xx),e.dot(xx)).mul(.495).add(.5)}}const _w=Mp(Tw),ww=new Nu;class Sw extends cT{static get type(){return"MeshMatcapNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(ww),this.setValues(t)}setupVariants(t){const e=_w;let s;s=t.material.matcap?kx("matcap","texture").context({getUV:()=>e}):kp(xf(.2,.8,e.y)),mm.rgb.mulAssign(s.rgb)}}const Mw=new Ia;class Aw extends cT{static get type(){return"PointsNodeMaterial"}constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(Mw),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}class Nw extends Ld{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:s}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Yp(t,i,i.negate(),t).mul(s)}{const t=e,i=Jp(Hp(1,0,0,0),Hp(0,Og(t.x),Ug(t.x).negate(),0),Hp(0,Ug(t.x),Og(t.x),0),Hp(0,0,0,1)),r=Jp(Hp(Og(t.y),0,Ug(t.y),0),Hp(0,1,0,0),Hp(Ug(t.y).negate(),0,Og(t.y),0),Hp(0,0,0,1)),n=Jp(Hp(Og(t.z),Ug(t.z).negate(),0,0),Hp(Ug(t.z),Og(t.z),0,0),Hp(0,0,1,0),Hp(0,0,0,1));return i.mul(r).mul(n).mul(Hp(s,1)).xyz}}}const Cw=Sp(Nw),Rw=new so;class Ew extends cT{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(Rw),this.setValues(t)}setupPosition({object:t,camera:e,context:s}){const i=this.sizeAttenuation,{positionNode:r,rotationNode:n,scaleNode:o}=this,a=rx;let h=tx.mul(kp(r||0)),u=zp(Xy[0].xyz.length(),Xy[1].xyz.length());if(null!==o&&(u=u.mul(o)),!i)if(e.isPerspectiveCamera)u=u.mul(h.z.negate());else{const t=Pp(2).div(Fy.element(1).element(1));u=u.mul(t.mul(2))}let l=a.xy;if(t.center&&!0===t.center.isVector2){const t=((t,e,s)=>Tp(new Xf(t,e,s)))("center","vec2");l=l.sub(t.sub(.5))}l=l.mul(u);const c=Pp(n||Eb),d=Cw(l,c);h=Hp(h.xy.add(d),h.zw);const p=Fy.mul(h);return s.vertex=a,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 Bw extends FT{constructor(){super(),this.shadowNode=Pp(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){mm.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(mm.rgb)}}const Iw=new yu;class Pw extends cT{static get type(){return"ShadowNodeMaterial"}constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Iw),this.setValues(t)}setupLightingModel(){return new Bw}}const Fw=Ap((({texture:t,uv:e})=>{const s=1e-4,i=kp().toVar();return Ep(e.x.lessThan(s),(()=>{i.assign(kp(1,0,0))})).ElseIf(e.y.lessThan(s),(()=>{i.assign(kp(0,1,0))})).ElseIf(e.z.lessThan(s),(()=>{i.assign(kp(0,0,1))})).ElseIf(e.x.greaterThan(.9999),(()=>{i.assign(kp(-1,0,0))})).ElseIf(e.y.greaterThan(.9999),(()=>{i.assign(kp(0,-1,0))})).ElseIf(e.z.greaterThan(.9999),(()=>{i.assign(kp(0,0,-1))})).Else((()=>{const s=.01,r=t.uv(e.add(kp(-.01,0,0))).r.sub(t.uv(e.add(kp(s,0,0))).r),n=t.uv(e.add(kp(0,-.01,0))).r.sub(t.uv(e.add(kp(0,s,0))).r),o=t.uv(e.add(kp(0,0,-.01))).r.sub(t.uv(e.add(kp(0,0,s))).r);i.assign(kp(r,n,o))})),i.normalize()}));class Uw extends Cy{static get type(){return"Texture3DNode"}constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return kp(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return Fw({texture:this,uv:t})}}const Ow=Sp(Uw);class zw extends cT{static get type(){return"VolumeNodeMaterial"}constructor(t={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=Ow(this.map,null,0),s=Ap((({orig:t,dir:e})=>{const s=kp(-.5),i=kp(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=ef(n,o),h=sf(n,o),u=sf(a.x,sf(a.y,a.z)),l=ef(h.x,ef(h.y,h.z));return zp(u,l)}));this.fragmentNode=Ap((()=>{const t=zf(kp(Qy.mul(Hp(Vy,1)))),i=zf(ix.sub(t)).normalize(),r=zp(s({orig:t,dir:i})).toVar();r.x.greaterThan(r.y).discard(),r.assign(zp(sf(r.x,0),r.y));const n=kp(t.add(r.x.mul(i))).toVar(),o=kp(i.abs().reciprocal()).toVar(),a=Pp(ef(o.x,ef(o.y,o.z))).toVar("delta");a.divAssign(kx("steps","float"));const h=Hp(kx("base","color"),0).toVar();return fv({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=dm("float","d").assign(e.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:n,finalColor:h}).append():(h.a.assign(1),xv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),Hp(h)}))(),super.setup(t)}}class Lw{constructor(t,e){this.nodes=t,this.info=e,this.animationLoop=null,this.requestId=null,this._init()}_init(){const t=(e,s)=>{this.requestId=self.requestAnimationFrame(t),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(e,s)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class Vw{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let s=this.clippingContext;Array.isArray(e.clippingPlanes)?(s!==t&&s||(s=new kw,this.clippingContext=s),s.update(t,e)):this.clippingContext!==t&&(this.clippingContext=t)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}getAttributes(){if(null!==this.attributes)return this.attributes;const t=this.getNodeBuilderState().nodeAttributes,e=this.geometry,s=[],i=new Set;for(const r of t){const t=r.node&&r.node.attribute?r.node.attribute:e.getAttribute(r.name);if(void 0===t)continue;s.push(t);const n=t.isInterleavedBufferAttribute?t.data:t;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:t,material:e,geometry:s,group:i,drawRange:r}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,h=s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1;if(0===h)return null;if(n.instanceCount=h,!0===t.isBatchedMesh)return n;let u=1;!0!==e.wireframe||t.isPoints||t.isLineSegments||t.isLine||t.isLineLoop||(u=2);let l=r.start*u,c=(r.start+r.count)*u;null!==i&&(l=Math.max(l,i.start*u),c=Math.min(c,(i.start+i.count)*u));const d=!0===a?o.count:s.attributes.position.count;l=Math.max(l,0),c=Math.min(c,d);const p=c-l;return p<0||p===1/0?null:(n.vertexCount=p,n.firstVertex=l,n)}getGeometryCacheKey(){const{geometry:t}=this;let e="";for(const s of Object.keys(t.attributes).sort()){const i=t.attributes[s];e+=s+",",i.data&&(e+=i.data.stride+","),i.offset&&(e+=i.offset+","),i.itemSize&&(e+=i.itemSize+","),i.normalized&&(e+="n,")}return t.index&&(e+="index,"),e}getMaterialCacheKey(){const{object:t,material:e}=this;let s=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let s=Object.getPrototypeOf(t);for(;s;){const t=Object.getOwnPropertyDescriptors(s);for(const s in t)if(void 0!==t[s]){const i=t[s];i&&"function"==typeof i.get&&e.push(s)}s=Object.getPrototypeOf(s)}return e}(e)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(t))continue;const i=e[t];let r;if(null!==i){const t=typeof i;"number"===t?r=0!==i?"1":"0":"object"===t?(r="{",i.isTexture&&(r+=i.mapping),r+="}"):r=String(i)}else r=String(i);s+=r+","}return s+=this.clippingContext.cacheKey+",",t.geometry&&(s+=this.getGeometryCacheKey()),t.skeleton&&(s+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(s+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(s+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(s+=t._colorsTexture.uuid+",")),t.count>1&&(s+=t.uuid+","),yd(s)}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let t=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(t+=1),t}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const jw=[];class Hw{constructor(t,e,s,i,r,n){this.renderer=t,this.nodes=e,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(t,e,s,i,r,n,o){const a=this.getChainMap(o);jw[0]=t,jw[1]=e,jw[2]=n,jw[3]=r;let h=a.get(jw);return void 0===h?(h=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(jw,h)):(h.updateClipping(n.clippingContext),(h.version!==e.version||h.needsUpdate)&&(h.initialCacheKey!==h.getCacheKey()?(h.dispose(),h=this.get(t,e,s,i,r,n,o)):h.version=e.version)),h}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new Vw)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Ww(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),l.delete(c.getChainArray())},c}}class $w{constructor(){this.data=new WeakMap}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}delete(t){let e;return this.data.has(t)&&(e=this.data.get(t),this.data.delete(t)),e}has(t){return this.data.has(t)}dispose(){this.data=new WeakMap}}const qw=1,Xw=2,Yw=4,Zw=16;class Jw extends $w{constructor(t){super(),this.backend=t}delete(t){const e=super.delete(t);return void 0!==e&&this.backend.destroyAttribute(t),e}update(t,e){const s=this.get(t);if(void 0===s.version)e===qw?this.backend.createAttribute(t):e===Xw?this.backend.createIndexAttribute(t):e===Yw&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version=0;--e)if(t[e]>=65535)return!0;return!1}(e)?mn:dn)(e,1);return r.version=Kw(t),r}class tS extends $w{constructor(t,e){super(),this.attributes=t,this.info=e,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(t){const e=t.geometry;return super.has(e)&&!0===this.get(e).initialized}updateForRender(t){!1===this.has(t)&&this.initGeometry(t),this.updateAttributes(t)}initGeometry(t){const e=t.geometry;this.get(e).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=e.index,r=t.getAttributes();null!==i&&this.attributes.delete(i);for(const t of r)this.attributes.delete(t);const n=this.wireframes.get(e);void 0!==n&&this.attributes.delete(n),e.removeEventListener("dispose",s)};e.addEventListener("dispose",s)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,Yw):this.updateAttribute(t,qw);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Xw)}updateAttribute(t,e){const s=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,s)):this.attributeCall.get(t.data)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t.data,s),this.attributeCall.set(t,s)):this.attributeCall.get(t)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t,s))}getIndex(t){const{geometry:e,material:s}=t;let i=e.index;if(!0===s.wireframe){const t=this.wireframes;let s=t.get(e);void 0===s?(s=Qw(e),t.set(e,s)):s.version!==Kw(e)&&(this.attributes.delete(s),s=Qw(e),t.set(e,s)),i=s}return i}}class eS{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(t,e,s){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=s*(e/3):t.isPoints?this.render.points+=s*e:t.isLineSegments?this.render.lines+=s*(e/2):t.isLine?this.render.lines+=s*(e-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(t,e){0===this[t].timestampCalls&&(this[t].timestamp=0),this[t].timestamp+=e,this[t].timestampCalls++,this[t].timestampCalls>=this[t].previousFrameCalls&&(this[t].timestampCalls=0)}reset(){const t=this.render.frameCalls;this.render.previousFrameCalls=t;const e=this.compute.frameCalls;this.compute.previousFrameCalls=e,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class sS{constructor(t){this.cacheKey=t,this.usedTimes=0}}class iS extends sS{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class rS extends sS{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let nS=0;class oS{constructor(t,e,s=null,i=null){this.id=nS++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class aS extends $w{constructor(t,e){super(),this.backend=t,this.nodes=e,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(t,e){const{backend:s}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(t);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new oS(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(t,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(t,o,a,e)),h.usedTimes++,o.usedTimes++,i.version=t.version,i.pipeline=h}return i.pipeline}getForRender(t,e=null){const{backend:s}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=t.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new oS(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),a=new oS(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(t){const e=this.get(t).pipeline;return e&&(e.usedTimes--,0===e.usedTimes&&this._releasePipeline(e),e.isComputePipeline?(e.computeProgram.usedTimes--,0===e.computeProgram.usedTimes&&this._releaseProgram(e.computeProgram)):(e.fragmentProgram.usedTimes--,e.vertexProgram.usedTimes--,0===e.vertexProgram.usedTimes&&this._releaseProgram(e.vertexProgram),0===e.fragmentProgram.usedTimes&&this._releaseProgram(e.fragmentProgram))),super.delete(t)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(t){this.getForRender(t)}_getComputePipeline(t,e,s,i){s=s||this._getComputeCacheKey(t,e);let r=this.caches.get(s);return void 0===r&&(r=new rS(s,e),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,s,i,r){i=i||this._getRenderCacheKey(t,e,s);let n=this.caches.get(i);return void 0===n&&(n=new iS(i,e,s),this.caches.set(i,n),t.pipeline=n,this.backend.createRenderPipeline(t,r)),n}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,s){return e.id+","+s.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,s=t.stage;this.programs[s].delete(e)}_needsComputeUpdate(t){const e=this.get(t);return void 0===e.pipeline||e.version!==t.version}_needsRenderUpdate(t){return void 0===this.get(t).pipeline||this.backend.needsRenderUpdate(t)}}class hS extends $w{constructor(t,e,s,i,r,n){super(),this.backend=t,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=n,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(this.getForCompute(t))}updateForRender(t){this._updateBindings(this.getForRender(t))}_updateBindings(t){for(const e of t)this._update(e,t)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute;this.attributes.update(t,Yw)}}_update(t,e){const{backend:s}=this;let i=!1;for(const e of t.bindings){if(e.isNodeUniformsGroup){if(!this.nodes.updateGroup(e))continue}if(e.isUniformBuffer){e.update()&&s.updateBinding(e)}else if(e.isSampler)e.update();else if(e.isSampledTexture){e.needsBindingsUpdate(this.textures.get(e.texture).generation)&&(i=!0);const t=e.update(),r=e.texture;t&&this.textures.updateTexture(r);const n=s.get(r);if(!0===s.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",e,t,r,e.textureNode.value,i),this.textures.updateTexture(r),i=!0),!0===r.isStorageTexture){const t=this.get(r);!0===e.store?t.needsMipmap=!0:!0===r.generateMipmaps&&this.textures.needsMipmaps(r)&&!0===t.needsMipmap&&(this.backend.generateMipmaps(r),t.needsMipmap=!1)}}}!0===i&&this.backend.updateBindings(t,e)}}class uS{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class lS{constructor(t,e,s){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=s.getSelf()}get value(){return this.node.value}set value(t){this.node.value=t}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class cS{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class dS extends cS{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class pS{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let mS=0;class gS{constructor(t=null){this.id=mS++,this.nodesData=new WeakMap,this.parent=t}getData(t){let e=this.nodesData.get(t);return void 0===e&&null!==this.parent&&(e=this.parent.getData(t)),e}setData(t,e){this.nodesData.set(t,e)}}class fS extends cm{static get type(){return"ParameterNode"}constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const yS=(t,e)=>Tp(new fS(t,e));class xS extends Ud{static get type(){return"CodeNode"}constructor(t="",e=[],s=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=s,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 s of e)s.build(t);const s=t.getCodeFromNode(this,this.getNodeType(t));return s.code=this.code,s.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 bS=Sp(xS),vS=(t,e)=>bS(t,e,"js"),TS=(t,e)=>bS(t,e,"wgsl"),_S=(t,e)=>bS(t,e,"glsl");class wS extends xS{static get type(){return"FunctionNode"}constructor(t="",e=[],s=""){super(t,e,s)}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let s=e.nodeFunction;return void 0===s&&(s=t.parser.parseFunction(this.code),e.nodeFunction=s),s}generate(t,e){super.generate(t);const s=this.getNodeFunction(t),i=s.name,r=s.type,n=t.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=t.getPropertyName(n),a=this.getNodeFunction(t).getCode(o);return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const SS=(t,e=[],s="")=>{for(let t=0;ti.call(...t);return r.functionNode=i,r},MS=(t,e)=>SS(t,e,"glsl"),AS=(t,e)=>SS(t,e,"wgsl");class NS{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 CS extends NS{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class RS extends NS{constructor(t,e=new Ys){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class ES extends NS{constructor(t,e=new Ai){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class BS extends NS{constructor(t,e=new xi){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class IS extends NS{constructor(t,e=new Xr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class PS extends NS{constructor(t,e=new Zs){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class FS extends NS{constructor(t,e=new sr){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class US extends CS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class OS extends RS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class zS extends ES{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class LS extends BS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class VS extends IS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class DS extends PS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class kS extends FS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class GS extends Ud{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 s=new vp(e);return this._currentCond=Cf(t,s),this.add(this._currentCond)}ElseIf(t,e){const s=new vp(e),i=Cf(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(t){return this._currentCond.elseNode=new vp(t),this}build(t,...e){const s=Rp();Cp(this);for(const e of this.nodes)e.build(t,"void");return Cp(s),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 WS=Sp(GS),jS=[.125,.215,.35,.446,.526,.582],HS=20,$S=new Tl(-1,1,1,-1,0,1),qS=new Hn(90,1),XS=new Xr;let YS=null,ZS=0,JS=0;const KS=(1+Math.sqrt(5))/2,QS=1/KS,tM=[new Ai(-KS,QS,0),new Ai(KS,QS,0),new Ai(-QS,0,KS),new Ai(QS,0,KS),new Ai(0,KS,-QS),new Ai(0,KS,QS),new Ai(-1,1,-1),new Ai(1,1,-1),new Ai(-1,1,1),new Ai(1,1,1)],eM=[3,1,5,0,4,2],sM=J_(wy(),_y("faceIndex")).normalize(),iM=kp(sM.x,sM.y.negate(),sM.z);class rM{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(t,e=0,s=.1,i=100){YS=this._renderer.getRenderTarget(),ZS=this._renderer.getActiveCubeFace(),JS=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,s,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}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=hM(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=uM(),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?h=jS[a-t+4-1]:0===a&&(h=0),i.push(h);const u=1/(o-2),l=-u,c=1+u,d=[l,l,c,l,c,c,l,l,c,c,l,c],p=6,m=6,g=3,f=2,y=1,x=new Float32Array(g*m*p),b=new Float32Array(f*m*p),v=new Float32Array(y*m*p);for(let t=0;t2?0:-1,i=[e,s,0,e+2/3,s,0,e+2/3,s+1,0,e,s,0,e+2/3,s+1,0,e,s+1,0],r=eM[t];x.set(i,g*m*r),b.set(d,f*m*r);const n=[r,r,r,r,r,r];v.set(n,y*m*r)}const T=new Sn;T.setAttribute("position",new an(x,g)),T.setAttribute("uv",new an(b,f)),T.setAttribute("faceIndex",new an(v,y)),e.push(T),r.push(new On(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=Fx(new Array(HS).fill(0)),r=lm(new Ai(0,1,0)),n=lm(0),o=Pp(HS),a=lm(0),h=lm(1),u=Ry(null),l=lm(0),c=Pp(1/e),d=Pp(1/s),p=Pp(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:iM,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=aM("blur");return g.uniforms=m,g.fragmentNode=ew({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}async _compileMaterial(t){const e=new On(this._lodPlanes[0],t);await this._renderer.compile(e,$S)}_sceneToCubeUV(t,e,s,i){const r=qS;r.near=e,r.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,h=a.autoClear;a.getClearColor(XS),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const t=new Kr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});u=new On(new Ln,t)}let l=!1;const c=t.background;c?c.isColor&&(u.material.color.copy(c),t.background=null,l=!0):(u.material.color.copy(XS),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let e=0;e<6;e++){const s=e%3;0===s?(r.up.set(0,n[e],0),r.lookAt(o[e],0,0)):1===s?(r.up.set(0,0,n[e]),r.lookAt(0,o[e],0)):(r.up.set(0,n[e],0),r.lookAt(0,0,o[e]));const h=this._cubeSize;oM(i,s*h,e>2?h:0,h,h),a.render(t,r)}a.autoClear=h,t.background=c}_textureToCubeUV(t,e){const s=this._renderer,i=t.mapping===ht||t.mapping===ut;i?null===this._cubemapMaterial&&(this._cubemapMaterial=hM(t)):null===this._equirectMaterial&&(this._equirectMaterial=uM(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;oM(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,$S)}_applyPMREM(t){const e=this._renderer,s=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;eHS&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const g=[];let f=0;for(let t=0;ty-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(u,$S)}}function nM(t,e,s){const i=new bi(t,e,s);return i.texture.mapping=dt,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function oM(t,e,s,i,r){t.viewport.set(e,s,i,r),t.scissor.set(e,s,i,r)}function aM(t){const e=new cT;return e.depthTest=!1,e.depthWrite=!1,e.blending=m,e.name=`PMREM_${t}`,e}function hM(t){const e=aM("cubemap");return e.fragmentNode=Rx(t,iM),e}function uM(t){const e=aM("equirect");return e.fragmentNode=Ry(t,MT(iM),0),e}let lM=0;class cM{constructor(t="",e=[],s=0,i=[]){this.name=t,this.bindings=e,this.index=s,this.bindingsReference=i,this.id=lM++}}const dM=new WeakMap,pM=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),mM=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),gM=t=>/e/g.test(t)?String(t).replace(/\+/g,""):(t=Number(t))+(t%1?"":".0");class fM{constructor(t,e,s){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=s,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=WS(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new gS,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let t=dM.get(this.renderer);return void 0===t&&(t=new Vw,dM.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new bi(t,e,s)}createCubeRenderTarget(t,e){return new AT(t,e)}createPMREMGenerator(){return new rM(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBindGroupsCache(),i=[];let r,n=!0;for(const t of e)i.push(t),n=n&&!0!==t.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new cM(t,i,this.bindingsIndexes[t].group,i),s.set(i,r))):r=new cM(t,i,this.bindingsIndexes[t].group,i),r}getBindGroupArray(t,e){const s=this.bindings[e];let i=s[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},s=this.bindings;for(const t of Id)for(const i in s[t]){const r=s[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const s in e){const i=e[s],r=this._getBindGroup(s,i);t.push(r)}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")}( ${gM(e.r)}, ${gM(e.g)}, ${gM(e.b)} )`;const s=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(s>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(s>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 s=this.attributes;for(const e of s)if(e.name===t)return e;const i=new uS(t,e);return s.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===Et)return"int";if(e===Bt)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 s=pM.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return mM.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const s=e.array,i=t.itemSize,r=t.normalized;let n;return t instanceof gn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(t){const e=this.getVectorType(t),s=/vec([2-4])/.exec(e);return null!==s?Number(s[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=WS(this.stack),this.stacks.push(Rp()||this.stack),Cp(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,Cp(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,s=null){let i=(s=null===s?t.isGlobal(this)?this.globalCache:this.cache:s).getData(t);return void 0===i&&(i={},s.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const s=this.getDataFromNode(t,e);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const s=this.getDataFromNode(t);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new uS("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const s=this.getDataFromNode(t,e);if(void 0===s.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),s.structType=t}return t}getUniformFromNode(t,e,s=this.shaderStage,i=null){const r=this.getDataFromNode(t,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new lS(i||"nodeUniform"+o,e,t),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(t,e=null,s=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let n=r.variable;if(void 0===n){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),n=new cS(e,s),t.push(n),r.variable=n}return n}getVaryingFromNode(t,e=null,s=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,n=t.length;null===e&&(e="nodeVarying"+n),r=new dS(e,s),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,s=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[s]||(this.codes[s]=[]),n=t.length;r=new pS("nodeCode"+n,e),t.push(r),i.code=r}return r}addFlowCodeHierarchy(t,e){const{flowCodes:s,flowCodeBlock:i}=this.getDataFromNode(t);let r=!0,n=e;for(;n;){if(!0===i.get(n)){r=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(r)for(const t of s)this.addLineFlowCode(t)}addLineFlowCodeBlock(t,e,s){const i=this.getDataFromNode(t),r=i.flowCodes||(i.flowCodes=[]),n=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);r.push(e),n.set(s,!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),s=this.flowChildNode(t,e);return this.flowsData.set(t,s),s}buildFunctionNode(t){const e=new wS,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout,s={[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)s[t.name]=new fS(t.type,t.name);t.layout=null;const i=t.call(s),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const s=this.flow,i=this.vars,r=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new gS,this.stack=WS();for(const s of Bd)this.setBuildStage(s),a.result=t.build(this,e);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.cache=r,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(t,e=null){const s=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=s,i}flowNodeFromShaderStage(t,e,s=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const n=this.flowChildNode(e,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[t]=this.flowCode[t]+n.code,this.setShaderStage(r),n}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 s=this.vars[t];if(void 0!==s)for(const t of s)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let s="";if(void 0!==e)for(const t of e)s+=t.code+"\n";return s}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:s}=this;if(null!==e){let t=s.nodes.library.fromMaterial(e);null===t&&(console.error(`NodeMaterial: Material "${e.type}" is not compatible.`),t=new cT),t.build(this)}else this.addFlow("compute",t);for(const t of Bd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Id){this.setShaderStage(e);const s=this.flowNodes[e];for(const e of s)"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 US(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new OS(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new zS(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new LS(t);if("color"===e)return new VS(t);if("mat3"===e)return new DS(t);if("mat4"===e)return new kS(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,s){if((e=this.getVectorType(e))===(s=this.getVectorType(s))||null===s||this.isReference(s))return t;const i=this.getTypeLength(e),r=this.getTypeLength(s);return 16===i&&9===r?`${this.getType(s)}(${t}[0].xyz, ${t}[1].xyz, ${t}[2].xyz)`:9===i&&4===r?`${this.getType(s)}(${t}[0].xy, ${t}[1].xy)`:i>4||r>4||0===r?t:i===r?`${this.getType(s)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(s)&&(t=`${this.getType(this.getComponentType(s))}( ${t} )`),`${this.getType(s)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class yM{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 s=t.get(e);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,s)),s}updateBeforeNode(t){const e=t.getUpdateBeforeType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(s,this.renderId)}else e===Cd.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(s,this.renderId)}else e===Cd.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.frameId&&!1!==t.update(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.renderId&&!1!==t.update(this)&&e.set(s,this.renderId)}else e===Cd.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 xM{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}xM.isNodeFunctionInput=!0;class bM extends Ud{static get type(){return"StructTypeNode"}constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class vM extends Ud{static get type(){return"OutputStructNode"}constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,s=[];for(let i=0;ir&&(i=s,r=n)}}this._candidateFnCall=s=i(...e)}return s}}const AM=Sp(MM),NM=t=>(...e)=>AM(t,...e);class CM extends Ud{static get type(){return"SpriteSheetUVNode"}constructor(t,e=wy(),s=Pp(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=s}setup(){const{frameNode:t,uvNode:e,countNode:s}=this,{width:i,height:r}=s,n=t.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=zp(o,a);return e.add(u).mul(h)}}const RM=Sp(CM);class EM extends Od{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 s;const i=t.context.assign;if(s=!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);s=t.format(s,i,e)}return s}}const BM=Sp(EM);class IM extends Ud{static get type(){return"TriplanarTexturesNode"}constructor(t,e=null,s=null,i=Pp(1),r=rx,n=mx){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:t,textureYNode:e,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(kp(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=t.value,c=null!==e?e.value:l,d=null!==s?s.value:l,p=Ry(l,a).mul(o.x),m=Ry(c,h).mul(o.y),g=Ry(d,u).mul(o.z);return qm(p,m,g)}}const PM=Sp(IM),FM=(...t)=>PM(...t),UM=new Yo,OM=new Ai,zM=new Ai,LM=new Ai,VM=new sr,DM=new Ai(0,0,-1),kM=new xi,GM=new Ai,WM=new Ai,jM=new xi,HM=new Ys,$M=new bi,qM=zv.flipX();let XM=!1;class YM extends Cy{static get type(){return"ReflectorNode"}constructor(t={}){super($M.texture,qM);const{target:e=new Rr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=t;this.target=e,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?Cd.RENDER:Cd.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(HM),t.setSize(Math.round(HM.width*s),Math.round(HM.height*s))}setup(t){return this._updateResolution($M,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 bi(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&&XM)return!1;XM=!0;const{scene:e,camera:s,renderer:i,material:r}=t,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(HM),this._updateResolution(a,i),zM.setFromMatrixPosition(n.matrixWorld),LM.setFromMatrixPosition(s.matrixWorld),VM.extractRotation(n.matrixWorld),OM.set(0,0,1),OM.applyMatrix4(VM),GM.subVectors(zM,LM),GM.dot(OM)>0)return;GM.reflect(OM).negate(),GM.add(zM),VM.extractRotation(s.matrixWorld),DM.set(0,0,-1),DM.applyMatrix4(VM),DM.add(LM),WM.subVectors(zM,DM),WM.reflect(OM).negate(),WM.add(zM),o.coordinateSystem=s.coordinateSystem,o.position.copy(GM),o.up.set(0,1,0),o.up.applyMatrix4(VM),o.up.reflect(OM),o.lookAt(WM),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),UM.setFromNormalAndCoplanarPoint(OM,zM),UM.applyMatrix4(o.matrixWorldInverse),kM.set(UM.normal.x,UM.normal.y,UM.normal.z,UM.constant);const h=o.projectionMatrix;jM.x=(Math.sign(kM.x)+h.elements[8])/h.elements[0],jM.y=(Math.sign(kM.y)+h.elements[9])/h.elements[5],jM.z=-1,jM.w=(1+h.elements[10])/h.elements[14],kM.multiplyScalar(1/kM.dot(jM));h.elements[2]=kM.x,h.elements[6]=kM.y,h.elements[10]=kM.z-0,h.elements[14]=kM.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget(),l=i.getMRT();i.setMRT(null),i.setRenderTarget(a),i.render(e,o),i.setMRT(l),i.setRenderTarget(u),r.visible=!0,XM=!1}}const ZM=t=>Tp(new YM(t)),JM=new Tl(-1,1,1,-1,0,1);class KM extends Sn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new fn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new fn(e,2))}}const QM=new KM;class tA extends On{constructor(t=null){super(QM,t),this.camera=JM,this.isQuadMesh=!0}renderAsync(t){return t.renderAsync(this,JM)}render(t){t.render(this,JM)}}const eA=new Ys;class sA extends Cy{static get type(){return"RTTNode"}constructor(t,e=null,s=null,i={type:Pt}){const r=new bi(e,s,i);super(r.texture,wy()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new tA(new cT),this.updateBeforeType=Cd.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 s=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(s,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(eA);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 Cy(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const iA=(t,...e)=>Tp(new sA(Tp(t),...e)),rA=(t,...e)=>t.isTextureNode?t:iA(t,...e);class nA extends Ty{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 s;return s=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new xi(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const oA=(...t)=>Tp(new nA(...t));class aA extends Ud{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const hA=Mp(aA);class uA extends Ud{static get type(){return"SceneNode"}constructor(t=uA.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=null!==this.scene?this.scene:t.scene;let i;return e===uA.BACKGROUND_BLURRINESS?i=Lx("backgroundBlurriness","float",s):e===uA.BACKGROUND_INTENSITY?i=Lx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}uA.BACKGROUND_BLURRINESS="backgroundBlurriness",uA.BACKGROUND_INTENSITY="backgroundIntensity";const lA=Mp(uA,uA.BACKGROUND_BLURRINESS),cA=Mp(uA,uA.BACKGROUND_INTENSITY),dA="point-list",pA="line-list",mA="line-strip",gA="triangle-list",fA="triangle-strip",yA="never",xA="less",bA="equal",vA="less-equal",TA="greater",_A="not-equal",wA="greater-equal",SA="always",MA="store",AA="load",NA="clear",CA="ccw",RA="none",EA="front",BA="back",IA="uint16",PA="uint32",FA={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},UA="clamp-to-edge",OA="repeat",zA="mirror-repeat",LA="linear",VA="nearest",DA="zero",kA="one",GA="src",WA="one-minus-src",jA="src-alpha",HA="one-minus-src-alpha",$A="dst",qA="one-minus-dst",XA="dst-alpha",YA="one-minus-dst-alpha",ZA="src-alpha-saturated",JA="constant",KA="one-minus-constant",QA="add",tN="subtract",eN="reverse-subtract",sN="min",iN="max",rN=0,nN=15,oN="keep",aN="zero",hN="replace",uN="invert",lN="increment-clamp",cN="decrement-clamp",dN="increment-wrap",pN="decrement-wrap",mN="storage",gN="read-only-storage",fN="write-only",yN="read-only",xN="float",bN="unfilterable-float",vN="depth",TN="sint",_N="uint",wN="2d",SN="3d",MN="2d",AN="2d-array",NN="cube",CN="3d",RN="all",EN="vertex",BN="instance",IN={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class PN extends Ex{static get type(){return"StorageBufferNode"}constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=mN,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,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 BM(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(gN)}setAtomic(t){return this.isAtomic=t,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=ey(this.value),this._varying=zf(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(t){if(t.isAvailable("storageBuffer"))return super.getNodeType(t);const{attribute:e}=this.getAttributeData();return e.getNodeType(t)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const{attribute:e,varying:s}=this.getAttributeData(),i=s.build(t);return t.registerTransform(i,e),i}}const FN=(t,e,s)=>Tp(new PN(t,e,s)),UN=(t,e,s)=>Tp(new PN(t,e,s).setBufferObject(!0));class ON extends Cy{static get type(){return"StorageTextureNode"}constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=fN}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 s;return s=null!==this.storeNode?this.generateStore(t):super.generate(t,e),s}toReadOnly(){return this.setAccess(yN)}toWriteOnly(){return this.setAccess(fN)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:s,storeNode:i}=e,r=super.generate(t,"property"),n=s.build(t,"uvec2"),o=i.build(t,"vec4"),a=t.generateTextureStore(t,r,n,o);t.addLineFlowCode(a,this)}}const zN=Sp(ON),LN=(t,e,s)=>{const i=zN(t,e,s);return null!==s&&i.append(),i};class VN extends zx{static get type(){return"UserDataNode"}constructor(t,e,s=null){super(t,e,s),this.userData=s}updateReference(t){return this.reference=null!==this.userData?this.userData:t.object.userData,this.reference}}const DN=(t,e,s)=>Tp(new VN(t,e,s));class kN extends Ld{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 GN=Sp(kN);let WN=null;class jN extends Xv{static get type(){return"ViewportSharedTextureNode"}constructor(t=zv,e=null){null===WN&&(WN=new ka),super(t,e,WN)}updateReference(){return this}}const HN=Sp(jN),$N=new Ys;class qN extends Cy{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 XN extends qN{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s}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 YN extends Ld{static get type(){return"PassNode"}constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new $a;r.isRenderTargetTexture=!0,r.name="depth";const n=new bi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=Cd.FRAME,this._textures={output:n.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=lm(0),this._cameraFar=lm(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 s=this._textures[t],i=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[i]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return void 0===e&&(this._textureNodes[t]=e=Tp(new XN(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=Tp(new XN(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=rT(this.getTextureNode(t),s,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar,r=this.getViewZNode(t);this._linearDepthNodes[t]=e=eT(r,s,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===YN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize($N);this.setSize(r.width,r.height);const n=e.getRenderTarget(),o=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(s,i),e.setRenderTarget(n),e.setMRT(o)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}YN.COLOR="color",YN.DEPTH="depth";const ZN=(t,e,s)=>Tp(new YN(YN.COLOR,t,e,s)),JN=(t,e)=>Tp(new qN(t,e)),KN=(t,e)=>Tp(new YN(YN.DEPTH,t,e));class QN extends YN{static get type(){return"ToonOutlinePassNode"}constructor(t,e,s,i,r){super(YN.COLOR,t,e),this.colorNode=s,this.thicknessNode=i,this.alphaNode=r,this._materialCache=new WeakMap}updateBefore(t){const{renderer:e}=t,s=e.getRenderObjectFunction();e.setRenderObjectFunction(((t,s,i,r,n,o,a)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const h=this._getOutlineMaterial(n);e.renderObject(t,s,i,r,h,o,a)}e.renderObject(t,s,i,r,n,o,a)})),super.updateBefore(t),e.setRenderObjectFunction(s)}_createMaterial(){const t=new cT;t.isMeshToonOutlineMaterial=!0,t.name="Toon_Outline",t.side=d;const e=mx.negate(),s=Fy.mul(tx),i=Pp(1),r=s.mul(Hp(rx,1)),n=s.mul(Hp(rx.add(e),1)),o=Pg(r.sub(n));return t.vertexNode=r.add(o.mul(this.thicknessNode).mul(r.w).mul(i)),t.colorNode=Hp(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 tC=(t,e,s=new Xr(0,0,0),i=.003,r=1)=>Tp(new QN(t,e,Tp(s),Tp(i),Tp(r)));class eC extends Ud{static get type(){return"ScriptableValueNode"}constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new zs,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:Pp()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=Sd(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?Md(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 sC=Sp(eC);class iC extends Map{get(t,e=null,...s){if(this.has(t))return super.get(t);if(null!==e){const i=e(...s);return this.set(t,i),i}}}class rC{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 nC=new iC;class oC extends Ud{static get type(){return"ScriptableNode"}constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new iC,this._output=sC(),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 s=this._outputs;return void 0===s[t]?s[t]=sC(e):s[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const s=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),s[t]=e,s[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),s[t]=e,s[t].events.addEventListener("refresh",this.onRefresh)):void 0===s[t]?(s[t]=sC(e),s[t].events.addEventListener("refresh",this.onRefresh)):s[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 s=this.getObject()[t];if("function"==typeof s)return s(...e)}async callAsync(t,...e){const s=this.getObject()[t];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...e):s(...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 rC(this),e=nC.get("THREE"),s=nC.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,nC,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,s];this._object=i(...r);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const t of n.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:Pp()}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+" };",s="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),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=[yd(this.source),this.getDefaultOutputNode().getCacheKey(t)];for(const s in this.parameters)e.push(this.parameters[s].getCacheKey(t));return xd(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 aC=Sp(oC);class hC extends Ud{static get type(){return"FogNode"}constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const s=t.context.getViewZ;return void 0!==s&&(e=s(this)),(e||hx.z).negate()}setup(){return this.factorNode}}const uC=Sp(hC);class lC extends hC{static get type(){return"FogRangeNode"}constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return _f(this.nearNode,this.farNode,e)}}const cC=Sp(lC);class dC extends hC{static get type(){return"FogExp2Node"}constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),s=this.densityNode;return s.mul(s,e,e).negate().exp().oneMinus()}}const pC=Sp(dC);let mC=null,gC=null;class fC extends Ud{static get type(){return"RangeNode"}constructor(t=Pp(),e=Pp()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(_d(this.minNode.value)),s=t.getTypeLength(_d(this.maxNode.value));return e>s?e:s}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let s=null;if(e.count>1){const i=this.minNode.value,r=this.maxNode.value,n=t.getTypeLength(_d(i)),o=t.getTypeLength(_d(r));mC=mC||new xi,gC=gC||new xi,mC.setScalar(0),gC.setScalar(0),1===n?mC.setScalar(i):i.isColor?mC.set(i.r,i.g,i.b):mC.set(i.x,i.y,i.z||0,i.w||0),1===o?gC.setScalar(r):r.isColor?gC.set(r.r,r.g,r.b):gC.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,u=new Float32Array(h);for(let t=0;tRy(t,e.xy).compare(e.z))),bC=Ap((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>Ry(t,e).compare(s),r=Lx("mapSize","vec2",s).setGroup(am),n=Lx("radius","float",s).setGroup(am),o=zp(1).div(r),a=o.x.negate().mul(n),h=o.y.negate().mul(n),u=o.x.mul(n),l=o.y.mul(n),c=a.div(2),d=h.div(2),p=u.div(2),m=l.div(2);return qm(i(e.xy.add(zp(a,h)),e.z),i(e.xy.add(zp(0,h)),e.z),i(e.xy.add(zp(u,h)),e.z),i(e.xy.add(zp(c,d)),e.z),i(e.xy.add(zp(0,d)),e.z),i(e.xy.add(zp(p,d)),e.z),i(e.xy.add(zp(a,0)),e.z),i(e.xy.add(zp(c,0)),e.z),i(e.xy,e.z),i(e.xy.add(zp(p,0)),e.z),i(e.xy.add(zp(u,0)),e.z),i(e.xy.add(zp(c,m)),e.z),i(e.xy.add(zp(0,m)),e.z),i(e.xy.add(zp(p,m)),e.z),i(e.xy.add(zp(a,l)),e.z),i(e.xy.add(zp(0,l)),e.z),i(e.xy.add(zp(u,l)),e.z)).mul(1/17)})),vC=Ap((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>Ry(t,e).compare(s),r=Lx("mapSize","vec2",s).setGroup(am),n=zp(1).div(r),o=n.x,a=n.y,h=e.xy,u=Fg(h.mul(r).add(.5));return h.subAssign(u.mul(n)),qm(i(h,e.z),i(h.add(zp(o,0)),e.z),i(h.add(zp(0,a)),e.z),i(h.add(n),e.z),xf(i(h.add(zp(o.negate(),0)),e.z),i(h.add(zp(o.mul(2),0)),e.z),u.x),xf(i(h.add(zp(o.negate(),a)),e.z),i(h.add(zp(o.mul(2),a)),e.z),u.x),xf(i(h.add(zp(0,a.negate())),e.z),i(h.add(zp(0,a.mul(2))),e.z),u.y),xf(i(h.add(zp(o,a.negate())),e.z),i(h.add(zp(o,a.mul(2))),e.z),u.y),xf(xf(i(h.add(zp(o.negate(),a.negate())),e.z),i(h.add(zp(o.mul(2),a.negate())),e.z),u.x),xf(i(h.add(zp(o.negate(),a.mul(2))),e.z),i(h.add(zp(o.mul(2),a.mul(2))),e.z),u.x),u.y)).mul(1/9)})),TC=Ap((({depthTexture:t,shadowCoord:e})=>{const s=Pp(1).toVar(),i=Ry(t).uv(e.xy).rg,r=nf(e.z,i.x);return Ep(r.notEqual(Pp(1)),(()=>{const t=e.z.sub(i.x),n=sf(0,i.y.mul(i.y));let o=n.div(n.add(t.mul(t)));o=bf(Xm(o,.3).div(.95-.3)),s.assign(bf(sf(r,o)))})),s})),_C=Ap((({samples:t,radius:e,size:s,shadowPass:i})=>{const r=Pp(0).toVar(),n=Pp(0).toVar(),o=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(2).div(t.sub(1))),a=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(-1));fv({start:Fp(0),end:Fp(t),type:"int",condition:"<"},(({i:t})=>{const h=a.add(Pp(t).mul(o)),u=i.uv(qm(Vv.xy,zp(0,h).mul(e)).div(s)).x;r.addAssign(u),n.addAssign(u.mul(u))})),r.divAssign(t),n.divAssign(t);const h=Rg(n.sub(r.mul(r)));return zp(r,h)})),wC=Ap((({samples:t,radius:e,size:s,shadowPass:i})=>{const r=Pp(0).toVar(),n=Pp(0).toVar(),o=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(2).div(t.sub(1))),a=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(-1));fv({start:Fp(0),end:Fp(t),type:"int",condition:"<"},(({i:t})=>{const h=a.add(Pp(t).mul(o)),u=i.uv(qm(Vv.xy,zp(h,0).mul(e)).div(s));r.addAssign(u.x),n.addAssign(qm(u.y.mul(u.y),u.x.mul(u.x)))})),r.divAssign(t),n.divAssign(t);const h=Rg(n.sub(r.mul(r)));return zp(r,h)})),SC=[xC,bC,vC,TC];let MC=null;const AC=new tA;class NC extends Rv{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=Cd.FRAME,this.light=t,this.color=new Xr,this.colorNode=lm(this.color).setGroup(am),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 bd(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(t){const{object:e,renderer:s}=t;if(!1===s.shadowMap.enabled)return;let i=this.shadowColorNode;if(null===i){null===MC&&(MC=new cT,MC.fragmentNode=Hp(0,0,0,1),MC.isShadowNodeMaterial=!0,MC.name="ShadowMaterial");const r=s.shadowMap.type,n=this.light.shadow,o=new $a;o.compareFunction=ys;const a=t.createRenderTarget(n.mapSize.width,n.mapSize.height);if(a.depthTexture=o,n.camera.updateProjectionMatrix(),3===r){o.compareFunction=null,this.vsmShadowMapVertical=t.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:qt,type:Pt}),this.vsmShadowMapHorizontal=t.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:qt,type:Pt});const e=Ry(o),s=Ry(this.vsmShadowMapVertical.texture),i=Lx("blurSamples","float",n).setGroup(am),r=Lx("radius","float",n).setGroup(am),a=Lx("mapSize","vec2",n).setGroup(am);let h=this.vsmMaterialVertical||(this.vsmMaterialVertical=new cT);h.fragmentNode=_C({samples:i,radius:r,size:a,shadowPass:e}).context(t.getSharedContext()),h.name="VSMVertical",h=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new cT),h.fragmentNode=wC({samples:i,radius:r,size:a,shadowPass:s}).context(t.getSharedContext()),h.name="VSMHorizontal"}const h=Lx("intensity","float",n).setGroup(am),u=Lx("bias","float",n).setGroup(am),l=Lx("normalBias","float",n).setGroup(am),c=e.material.shadowPositionNode||ox;let d,p=lm(n.matrix).setGroup(am).mul(c.add(yx.mul(l)));if(n.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)p=p.xyz.div(p.w),d=p.z,s.coordinateSystem===Os&&(d=d.mul(2).sub(1));else{const t=p.w;p=p.xy.div(t);const e=lm("float").onRenderUpdate((()=>n.camera.near)),s=lm("float").onRenderUpdate((()=>n.camera.far));d=nT(t,e,s)}p=kp(p.x,p.y.oneMinus(),d.add(u));const m=p.x.greaterThanEqual(0).and(p.x.lessThanEqual(1)).and(p.y.greaterThanEqual(0)).and(p.y.lessThanEqual(1)).and(p.z.lessThanEqual(1)),g=n.filterNode||SC[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const f=Ry(a.texture,p),y=m.select(g({depthTexture:3===r?this.vsmShadowMapHorizontal.texture:o,shadowCoord:p,shadow:n}),Pp(1));this.shadowMap=a,this.light.shadow.map=a,this.shadowNode=y,this.shadowColorNode=i=this.colorNode.mul(xf(1,y.rgb.mix(f,1),h.mul(f.a))),this.baseColorNode=this.colorNode}this.colorNode=i,this.updateBeforeType=Cd.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:s}=this,{renderer:i,scene:r,camera:n}=t,o=i.shadowMap.type,a=e.depthTexture.version;this._depthVersionCached=a;const h=r.overrideMaterial;r.overrideMaterial=MC,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const u=i.getRenderTarget(),l=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{(!0===t.castShadow||t.receiveShadow&&3===o)&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.render(r,s.shadow.camera),i.setRenderObjectFunction(l),!0!==s.isPointLight&&3===o&&this.vsmPass(t,s),i.setRenderTarget(u),r.overrideMaterial=h}vsmPass(t,e){const{renderer:s}=t;this.vsmShadowMapVertical.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),this.vsmShadowMapHorizontal.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),s.setRenderTarget(this.vsmShadowMapVertical),AC.material=this.vsmMaterialVertical,AC.render(s),s.setRenderTarget(this.vsmShadowMapHorizontal),AC.material=this.vsmMaterialHorizontal,AC.render(s)}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=Cd.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 CC=Ap((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).select(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));let RC;function EC(t){RC=RC||new WeakMap;let e=RC.get(t);return void 0===e&&RC.set(t,e={}),e}function BC(t){const e=EC(t);return e.position||(e.position=lm(new Ai).setGroup(am).onRenderUpdate(((e,s)=>s.value.setFromMatrixPosition(t.matrixWorld))))}function IC(t){const e=EC(t);return e.targetPosition||(e.targetPosition=lm(new Ai).setGroup(am).onRenderUpdate(((e,s)=>s.value.setFromMatrixPosition(t.target.matrixWorld))))}function PC(t){const e=EC(t);return e.viewPosition||(e.viewPosition=lm(new Ai).setGroup(am).onRenderUpdate((({camera:e},s)=>{s.value=s.value||new Ai,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(e.matrixWorldInverse)})))}const FC=t=>Oy.transformDirection(BC(t).sub(IC(t))),UC=Ap((([t])=>{const e=t.toUint().mul(747796405).add(2891336453),s=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),OC=(t,e)=>cf(Ym(4,t.mul(Xm(1,t))),e),zC=(t,e)=>t.lessThan(.5)?OC(t.mul(2),e).div(2):Xm(1,OC(Ym(Xm(1,t),2),e).div(2)),LC=(t,e,s)=>cf(Zm(cf(t,e),qm(cf(t,e),cf(Xm(1,t),s))),1/e),VC=(t,e)=>Ug(xg.mul(e.mul(t).sub(1))).div(xg.mul(e.mul(t).sub(1))),DC=Ap((([t])=>t.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),kC=Ap((([t])=>kp(DC(t.z.add(DC(t.y.mul(1)))),DC(t.z.add(DC(t.x.mul(1)))),DC(t.y.add(DC(t.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),GC=Ap((([t,e,s])=>{const i=kp(t).toVar(),r=Pp(1.4).toVar(),n=Pp(0).toVar(),o=kp(i).toVar();return fv({start:Pp(0),end:Pp(3),type:"float",condition:"<="},(()=>{const t=kp(kC(o.mul(2))).toVar();i.addAssign(t.add(s.mul(Pp(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=Pp(DC(i.z.add(DC(i.x.add(DC(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]}),WC=lm(0).setGroup(am).onRenderUpdate((t=>t.time)),jC=lm(0).setGroup(am).onRenderUpdate((t=>t.deltaTime)),HC=lm(0,"uint").setGroup(am).onRenderUpdate((t=>t.frameId)),$C=(t=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),WC.mul(t)),qC=(t=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),WC.mul(t)),XC=(t=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),jC.mul(t)),YC=(t=WC)=>t.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),ZC=(t=WC)=>t.fract().round(),JC=(t=WC)=>t.add(.5).fract().mul(2).sub(1).abs(),KC=(t=WC)=>t.fract(),QC=Ap((([t,e,s=zp(.5)])=>Cw(t.sub(s),e).add(s))),tR=Ap((([t,e,s=zp(.5)])=>{const i=t.sub(s),r=i.dot(i),n=r.mul(r).mul(e);return t.add(i.mul(n))})),eR=Ap((({position:t=null,horizontal:e=!0,vertical:s=!1})=>{let i;null!==t?(i=Xy.toVar(),i[3][0]=t.x,i[3][1]=t.y,i[3][2]=t.z):i=Xy;const r=Oy.mul(i);return xp(e)&&(r[0][0]=Xy[0].length(),r[0][1]=0,r[0][2]=0),xp(s)&&(r[1][0]=0,r[1][1]=Xy[1].length(),r[1][2]=0),r[2][0]=0,r[2][1]=0,r[2][2]=1,Fy.mul(r).mul(rx)})),sR=Ap((([t=null])=>{const e=hT();return hT(Qv(t)).sub(e).lessThan(0).select(zv,t)})),iR=new WeakMap;class rR extends Ld{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.updateType=Cd.OBJECT,this.updateAfterType=Cd.OBJECT,this.previousModelWorldMatrix=lm(new sr),this.previousProjectionMatrix=lm(new sr).setGroup(am),this.previousCameraViewMatrix=lm(new sr)}update({frameId:t,camera:e,object:s}){const i=oR(s);this.previousModelWorldMatrix.value.copy(i);const r=nR(e);r.frameId!==t&&(r.frameId=t,void 0===r.previousProjectionMatrix?(r.previousProjectionMatrix=new sr,r.previousCameraViewMatrix=new sr,r.currentProjectionMatrix=new sr,r.currentCameraViewMatrix=new sr,r.previousProjectionMatrix.copy(e.projectionMatrix),r.previousCameraViewMatrix.copy(e.matrixWorldInverse)):(r.previousProjectionMatrix.copy(r.currentProjectionMatrix),r.previousCameraViewMatrix.copy(r.currentCameraViewMatrix)),r.currentProjectionMatrix.copy(e.projectionMatrix),r.currentCameraViewMatrix.copy(e.matrixWorldInverse),this.previousProjectionMatrix.value.copy(r.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(r.previousCameraViewMatrix))}updateAfter({object:t}){oR(t).copy(t.matrixWorld)}setup(){const t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),e=Fy.mul(tx).mul(rx),s=this.previousProjectionMatrix.mul(t).mul(nx),i=e.xy.div(e.w),r=s.xy.div(s.w);return Xm(i,r)}}function nR(t){let e=iR.get(t);return void 0===e&&(e={},iR.set(t,e)),e}function oR(t,e=0){const s=nR(t);let i=s[e];return void 0===i&&(s[e]=i=new sr),i}const aR=Mp(rR),hR=Ap((([t,e])=>ef(1,t.oneMinus().div(e)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),uR=Ap((([t,e])=>ef(t.div(e.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),lR=Ap((([t,e])=>t.oneMinus().mul(e.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cR=Ap((([t,e])=>xf(t.mul(2).mul(e),t.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),nf(.5,t)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),dR=Ap((([t])=>fR(t.rgb))),pR=Ap((([t,e=Pp(1)])=>e.mix(fR(t.rgb),t.rgb))),mR=Ap((([t,e=Pp(1)])=>{const s=qm(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),r=i.sub(s).mul(e).mul(-3);return xf(t.rgb,i,r)})),gR=Ap((([t,e=Pp(1)])=>{const s=kp(.57735,.57735,.57735),i=e.cos();return kp(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(uf(s,t.rgb).mul(i.oneMinus())))))})),fR=(t,e=kp(ii.getLuminanceCoefficients(new Ai)))=>uf(t,e),yR=(t,e)=>xf(kp(0),t,fR(t).sub(e).max(0)),xR=Ap((([t,e=kp(1),s=kp(0),i=kp(1),r=Pp(1),n=kp(ii.getLuminanceCoefficients(new Ai,Je))])=>{const o=t.rgb.dot(kp(n)),a=sf(t.rgb.mul(e).add(s),0).toVar(),h=a.pow(i).toVar();return Ep(a.r.greaterThan(0),(()=>{a.r.assign(h.r)})),Ep(a.g.greaterThan(0),(()=>{a.g.assign(h.g)})),Ep(a.b.greaterThan(0),(()=>{a.b.assign(h.b)})),a.assign(o.add(a.sub(o).mul(r))),Hp(a.rgb,t.a)})),bR=Ap((([t])=>{const e=t.mul(.9478672986).add(.0521327014).pow(2.4),s=t.mul(.0773993808),i=t.lessThanEqual(.04045);return xf(e,s,i)})).setLayout({name:"sRGBToLinearSRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),vR=Ap((([t])=>{const e=t.pow(.41666).mul(1.055).sub(.055),s=t.mul(12.92),i=t.lessThanEqual(.0031308);return xf(e,s,i)})).setLayout({name:"linearSRGBTosRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),TR=Ap((([t,e])=>t.mul(e).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),_R=Ap((([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"}]}),wR=Ap((([t,e])=>{const s=(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 s.div(i).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),SR=Ap((([t])=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),s=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(s)})),MR=Ap((([t,e])=>{const s=Zp(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Zp(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=SR(t),(t=i.mul(t)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),AR=Zp(kp(1.6605,-.1246,-.0182),kp(-.5876,1.1329,-.1006),kp(-.0728,-.0083,1.1187)),NR=Zp(kp(.6274,.0691,.0164),kp(.3293,.9195,.088),kp(.0433,.0113,.8956)),CR=Ap((([t])=>{const e=kp(t).toVar(),s=kp(e.mul(e)).toVar(),i=kp(s.mul(s)).toVar();return Pp(15.5).mul(i.mul(s)).sub(Ym(40.14,i.mul(e))).add(Ym(31.96,i).sub(Ym(6.868,s.mul(e))).add(Ym(.4298,s).add(Ym(.1191,e).sub(.00232))))})),RR=Ap((([t,e])=>{const s=kp(t).toVar(),i=Zp(kp(.856627153315983,.137318972929847,.11189821299995),kp(.0951212405381588,.761241990602591,.0767994186031903),kp(.0482516061458583,.101439036467562,.811302368396859)),r=Zp(kp(1.1271005818144368,-.1413297634984383,-.14132976349843826),kp(-.11060664309660323,1.157823702216272,-.11060664309660294),kp(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=Pp(-12.47393),o=Pp(4.026069);return s.mulAssign(e),s.assign(NR.mul(s)),s.assign(i.mul(s)),s.assign(sf(s,1e-10)),s.assign(Cg(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(bf(s,0,1)),s.assign(CR(s)),s.assign(r.mul(s)),s.assign(cf(sf(kp(0),s),kp(2.2))),s.assign(AR.mul(s)),s.assign(bf(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),ER=Ap((([t,e])=>{const s=Pp(.76),i=Pp(.15);t=t.mul(e);const r=ef(t.r,ef(t.g,t.b)),n=Cf(r.lessThan(.08),r.sub(Ym(6.25,r.mul(r))),.04);t.subAssign(n);const o=sf(t.r,sf(t.g,t.b));Ep(o.lessThan(s),(()=>t));const a=Xm(1,s),h=Xm(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const u=Xm(1,Zm(1,i.mul(o.sub(h)).add(1)));return xf(t,kp(h),u)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class BR extends Ud{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 s=this.getBuiltinName(t),i=this.getNodeType(t);return"compute"===t.shaderStage?t.format(s,i,e):(console.warn(`ComputeBuiltinNode: Compute built-in value ${s} 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 IR=(t,e)=>Tp(new BR(t,e)),PR=IR("numWorkgroups","uvec3"),FR=IR("workgroupId","uvec3"),UR=IR("localId","uvec3"),OR=IR("subgroupSize","uint");const zR=Sp(class extends Ud{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;!0===s.backend.isWebGLBackend?t.addFlowCode(`\t// ${e}Barrier \n`):t.addLineFlowCode(`${e}Barrier()`,this)}}),LR=()=>zR("workgroup").append(),VR=()=>zR("storage").append(),DR=()=>zR("texture").append();class kR extends Od{constructor(t,e){super(t,e),this.isWorkgroupInfoElementNode=!0}generate(t,e){let s;const i=t.context.assign;if(s=super.generate(t),!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}class GR extends Ud{constructor(t,e,s=0){super(e),this.bufferType=e,this.bufferCount=s,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 Tp(new kR(this,t))}generate(t){return t.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const WR=(t,e)=>Tp(new GR("Workgroup",t,e));class jR extends Ld{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,i=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=i}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),i=this.getInputType(t),r=this.pointerNode,n=this.valueNode,o=[];o.push(`&${r.build(t,i)}`),o.push(n.build(t,i));const a=`${t.getMethod(e,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const e=this.storeNode.build(t,i);t.addLineFlowCode(`${e} = ${a}`,this)}else t.addLineFlowCode(a,this)}}jR.ATOMIC_LOAD="atomicLoad",jR.ATOMIC_STORE="atomicStore",jR.ATOMIC_ADD="atomicAdd",jR.ATOMIC_SUB="atomicSub",jR.ATOMIC_MAX="atomicMax",jR.ATOMIC_MIN="atomicMin",jR.ATOMIC_AND="atomicAnd",jR.ATOMIC_OR="atomicOr",jR.ATOMIC_XOR="atomicXor";const HR=Sp(jR),$R=(t,e,s,i)=>{const r=HR(t,e,s,i);return r.append(),r},qR=(t,e,s=null)=>$R(jR.ATOMIC_STORE,t,e,s),XR=(t,e,s=null)=>$R(jR.ATOMIC_ADD,t,e,s),YR=(t,e,s=null)=>$R(jR.ATOMIC_SUB,t,e,s),ZR=(t,e,s=null)=>$R(jR.ATOMIC_MAX,t,e,s),JR=(t,e,s=null)=>$R(jR.ATOMIC_MIN,t,e,s),KR=(t,e,s=null)=>$R(jR.ATOMIC_AND,t,e,s),QR=(t,e,s=null)=>$R(jR.ATOMIC_OR,t,e,s),tE=(t,e,s=null)=>$R(jR.ATOMIC_XOR,t,e,s),eE=Ap((([t=e()])=>{const e=t.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()})),sE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Op(t).toVar();return Cf(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),iE=Ap((([t,e])=>{const s=Op(e).toVar(),i=Pp(t).toVar();return Cf(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),rE=Ap((([t])=>{const e=Pp(t).toVar();return Fp(Bg(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),nE=Ap((([t,e])=>{const s=Pp(t).toVar();return e.assign(rE(s)),s.sub(Pp(e))})),oE=NM([Ap((([t,e,s,i,r,n])=>{const o=Pp(n).toVar(),a=Pp(r).toVar(),h=Pp(i).toVar(),u=Pp(s).toVar(),l=Pp(e).toVar(),c=Pp(t).toVar(),d=Pp(Xm(1,a)).toVar();return Xm(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).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"}]}),Ap((([t,e,s,i,r,n])=>{const o=Pp(n).toVar(),a=Pp(r).toVar(),h=kp(i).toVar(),u=kp(s).toVar(),l=kp(e).toVar(),c=kp(t).toVar(),d=Pp(Xm(1,a)).toVar();return Xm(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).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"}]})]),aE=NM([Ap((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=Pp(l).toVar(),d=Pp(u).toVar(),p=Pp(h).toVar(),m=Pp(a).toVar(),g=Pp(o).toVar(),f=Pp(n).toVar(),y=Pp(r).toVar(),x=Pp(i).toVar(),b=Pp(s).toVar(),v=Pp(e).toVar(),T=Pp(t).toVar(),_=Pp(Xm(1,p)).toVar(),w=Pp(Xm(1,d)).toVar();return Pp(Xm(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).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"}]}),Ap((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=Pp(l).toVar(),d=Pp(u).toVar(),p=Pp(h).toVar(),m=kp(a).toVar(),g=kp(o).toVar(),f=kp(n).toVar(),y=kp(r).toVar(),x=kp(i).toVar(),b=kp(s).toVar(),v=kp(e).toVar(),T=kp(t).toVar(),_=Pp(Xm(1,p)).toVar(),w=Pp(Xm(1,d)).toVar();return Pp(Xm(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).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"}]})]),hE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Up(t).toVar(),o=Up(n.bitAnd(Up(7))).toVar(),a=Pp(sE(o.lessThan(Up(4)),r,i)).toVar(),h=Pp(Ym(2,sE(o.lessThan(Up(4)),i,r))).toVar();return iE(a,Op(o.bitAnd(Up(1)))).add(iE(h,Op(o.bitAnd(Up(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),uE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Pp(e).toVar(),a=Up(t).toVar(),h=Up(a.bitAnd(Up(15))).toVar(),u=Pp(sE(h.lessThan(Up(8)),o,n)).toVar(),l=Pp(sE(h.lessThan(Up(4)),n,sE(h.equal(Up(12)).or(h.equal(Up(14))),o,r))).toVar();return iE(u,Op(h.bitAnd(Up(1)))).add(iE(l,Op(h.bitAnd(Up(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"}]}),lE=NM([hE,uE]),cE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Wp(t).toVar();return kp(lE(n.x,r,i),lE(n.y,r,i),lE(n.z,r,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),dE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Pp(e).toVar(),a=Wp(t).toVar();return kp(lE(a.x,o,n,r),lE(a.y,o,n,r),lE(a.z,o,n,r))})).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"}]}),pE=NM([cE,dE]),mE=Ap((([t])=>{const e=Pp(t).toVar();return Ym(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),gE=Ap((([t])=>{const e=Pp(t).toVar();return Ym(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),fE=NM([mE,Ap((([t])=>{const e=kp(t).toVar();return Ym(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),yE=NM([gE,Ap((([t])=>{const e=kp(t).toVar();return Ym(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),xE=Ap((([t,e])=>{const s=Fp(e).toVar(),i=Up(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(Fp(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),bE=Ap((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(xE(s,Fp(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(xE(t,Fp(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(xE(e,Fp(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(xE(s,Fp(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(xE(t,Fp(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(xE(e,Fp(4))),e.addAssign(t)})),vE=Ap((([t,e,s])=>{const i=Up(s).toVar(),r=Up(e).toVar(),n=Up(t).toVar();return i.bitXorAssign(r),i.subAssign(xE(r,Fp(14))),n.bitXorAssign(i),n.subAssign(xE(i,Fp(11))),r.bitXorAssign(n),r.subAssign(xE(n,Fp(25))),i.bitXorAssign(r),i.subAssign(xE(r,Fp(16))),n.bitXorAssign(i),n.subAssign(xE(i,Fp(4))),r.bitXorAssign(n),r.subAssign(xE(n,Fp(14))),i.bitXorAssign(r),i.subAssign(xE(r,Fp(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),TE=Ap((([t])=>{const e=Up(t).toVar();return Pp(e).div(Pp(Up(Fp(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),_E=Ap((([t])=>{const e=Pp(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"}]}),wE=NM([Ap((([t])=>{const e=Fp(t).toVar(),s=Up(Up(1)).toVar(),i=Up(Up(Fp(3735928559)).add(s.shiftLeft(Up(2))).add(Up(13))).toVar();return vE(i.add(Up(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Ap((([t,e])=>{const s=Fp(e).toVar(),i=Fp(t).toVar(),r=Up(Up(2)).toVar(),n=Up().toVar(),o=Up().toVar(),a=Up().toVar();return n.assign(o.assign(a.assign(Up(Fp(3735928559)).add(r.shiftLeft(Up(2))).add(Up(13))))),n.addAssign(Up(i)),o.addAssign(Up(s)),vE(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Fp(e).toVar(),n=Fp(t).toVar(),o=Up(Up(3)).toVar(),a=Up().toVar(),h=Up().toVar(),u=Up().toVar();return a.assign(h.assign(u.assign(Up(Fp(3735928559)).add(o.shiftLeft(Up(2))).add(Up(13))))),a.addAssign(Up(n)),h.addAssign(Up(r)),u.addAssign(Up(i)),vE(a,h,u)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Ap((([t,e,s,i])=>{const r=Fp(i).toVar(),n=Fp(s).toVar(),o=Fp(e).toVar(),a=Fp(t).toVar(),h=Up(Up(4)).toVar(),u=Up().toVar(),l=Up().toVar(),c=Up().toVar();return u.assign(l.assign(c.assign(Up(Fp(3735928559)).add(h.shiftLeft(Up(2))).add(Up(13))))),u.addAssign(Up(a)),l.addAssign(Up(o)),c.addAssign(Up(n)),bE(u,l,c),u.addAssign(Up(r)),vE(u,l,c)})).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"}]}),Ap((([t,e,s,i,r])=>{const n=Fp(r).toVar(),o=Fp(i).toVar(),a=Fp(s).toVar(),h=Fp(e).toVar(),u=Fp(t).toVar(),l=Up(Up(5)).toVar(),c=Up().toVar(),d=Up().toVar(),p=Up().toVar();return c.assign(d.assign(p.assign(Up(Fp(3735928559)).add(l.shiftLeft(Up(2))).add(Up(13))))),c.addAssign(Up(u)),d.addAssign(Up(h)),p.addAssign(Up(a)),bE(c,d,p),c.addAssign(Up(o)),d.addAssign(Up(n)),vE(c,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"}]})]),SE=NM([Ap((([t,e])=>{const s=Fp(e).toVar(),i=Fp(t).toVar(),r=Up(wE(i,s)).toVar(),n=Wp().toVar();return n.x.assign(r.bitAnd(Fp(255))),n.y.assign(r.shiftRight(Fp(8)).bitAnd(Fp(255))),n.z.assign(r.shiftRight(Fp(16)).bitAnd(Fp(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Fp(e).toVar(),n=Fp(t).toVar(),o=Up(wE(n,r,i)).toVar(),a=Wp().toVar();return a.x.assign(o.bitAnd(Fp(255))),a.y.assign(o.shiftRight(Fp(8)).bitAnd(Fp(255))),a.z.assign(o.shiftRight(Fp(16)).bitAnd(Fp(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),ME=NM([Ap((([t])=>{const e=zp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Pp(nE(e.x,s)).toVar(),n=Pp(nE(e.y,i)).toVar(),o=Pp(_E(r)).toVar(),a=Pp(_E(n)).toVar(),h=Pp(oE(lE(wE(s,i),r,n),lE(wE(s.add(Fp(1)),i),r.sub(1),n),lE(wE(s,i.add(Fp(1))),r,n.sub(1)),lE(wE(s.add(Fp(1)),i.add(Fp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return fE(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Fp().toVar(),n=Pp(nE(e.x,s)).toVar(),o=Pp(nE(e.y,i)).toVar(),a=Pp(nE(e.z,r)).toVar(),h=Pp(_E(n)).toVar(),u=Pp(_E(o)).toVar(),l=Pp(_E(a)).toVar(),c=Pp(aE(lE(wE(s,i,r),n,o,a),lE(wE(s.add(Fp(1)),i,r),n.sub(1),o,a),lE(wE(s,i.add(Fp(1)),r),n,o.sub(1),a),lE(wE(s.add(Fp(1)),i.add(Fp(1)),r),n.sub(1),o.sub(1),a),lE(wE(s,i,r.add(Fp(1))),n,o,a.sub(1)),lE(wE(s.add(Fp(1)),i,r.add(Fp(1))),n.sub(1),o,a.sub(1)),lE(wE(s,i.add(Fp(1)),r.add(Fp(1))),n,o.sub(1),a.sub(1)),lE(wE(s.add(Fp(1)),i.add(Fp(1)),r.add(Fp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return yE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),AE=NM([Ap((([t])=>{const e=zp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Pp(nE(e.x,s)).toVar(),n=Pp(nE(e.y,i)).toVar(),o=Pp(_E(r)).toVar(),a=Pp(_E(n)).toVar(),h=kp(oE(pE(SE(s,i),r,n),pE(SE(s.add(Fp(1)),i),r.sub(1),n),pE(SE(s,i.add(Fp(1))),r,n.sub(1)),pE(SE(s.add(Fp(1)),i.add(Fp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return fE(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Fp().toVar(),n=Pp(nE(e.x,s)).toVar(),o=Pp(nE(e.y,i)).toVar(),a=Pp(nE(e.z,r)).toVar(),h=Pp(_E(n)).toVar(),u=Pp(_E(o)).toVar(),l=Pp(_E(a)).toVar(),c=kp(aE(pE(SE(s,i,r),n,o,a),pE(SE(s.add(Fp(1)),i,r),n.sub(1),o,a),pE(SE(s,i.add(Fp(1)),r),n,o.sub(1),a),pE(SE(s.add(Fp(1)),i.add(Fp(1)),r),n.sub(1),o.sub(1),a),pE(SE(s,i,r.add(Fp(1))),n,o,a.sub(1)),pE(SE(s.add(Fp(1)),i,r.add(Fp(1))),n.sub(1),o,a.sub(1)),pE(SE(s,i.add(Fp(1)),r.add(Fp(1))),n,o.sub(1),a.sub(1)),pE(SE(s.add(Fp(1)),i.add(Fp(1)),r.add(Fp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return yE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),NE=NM([Ap((([t])=>{const e=Pp(t).toVar(),s=Fp(rE(e)).toVar();return TE(wE(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Ap((([t])=>{const e=zp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar();return TE(wE(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar();return TE(wE(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Ap((([t])=>{const e=Hp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar(),n=Fp(rE(e.w)).toVar();return TE(wE(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),CE=NM([Ap((([t])=>{const e=Pp(t).toVar(),s=Fp(rE(e)).toVar();return kp(TE(wE(s,Fp(0))),TE(wE(s,Fp(1))),TE(wE(s,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Ap((([t])=>{const e=zp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar();return kp(TE(wE(s,i,Fp(0))),TE(wE(s,i,Fp(1))),TE(wE(s,i,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar();return kp(TE(wE(s,i,r,Fp(0))),TE(wE(s,i,r,Fp(1))),TE(wE(s,i,r,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Ap((([t])=>{const e=Hp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar(),n=Fp(rE(e.w)).toVar();return kp(TE(wE(s,i,r,n,Fp(0))),TE(wE(s,i,r,n,Fp(1))),TE(wE(s,i,r,n,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),RE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=Pp(0).toVar(),u=Pp(1).toVar();return fv(o,(()=>{h.addAssign(u.mul(ME(a))),u.mulAssign(r),a.mulAssign(n)})),h})).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"}]}),EE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=kp(0).toVar(),u=Pp(1).toVar();return fv(o,(()=>{h.addAssign(u.mul(AE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).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"}]}),BE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar();return zp(RE(a,o,n,r),RE(a.add(kp(Fp(19),Fp(193),Fp(17))),o,n,r))})).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"}]}),IE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=kp(EE(a,o,n,r)).toVar(),u=Pp(RE(a.add(kp(Fp(19),Fp(193),Fp(17))),o,n,r)).toVar();return Hp(h,u)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),PE=Ap((([t,e,s,i,r,n,o])=>{const a=Fp(o).toVar(),h=Pp(n).toVar(),u=Fp(r).toVar(),l=Fp(i).toVar(),c=Fp(s).toVar(),d=Fp(e).toVar(),p=zp(t).toVar(),m=kp(CE(zp(d.add(l),c.add(u)))).toVar(),g=zp(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=zp(zp(Pp(d),Pp(c)).add(g)).toVar(),y=zp(f.sub(p)).toVar();return Ep(a.equal(Fp(2)),(()=>kg(y.x).add(kg(y.y)))),Ep(a.equal(Fp(3)),(()=>sf(kg(y.x),kg(y.y)))),uf(y,y)})).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"}]}),FE=NM([PE,Ap((([t,e,s,i,r,n,o,a,h])=>{const u=Fp(h).toVar(),l=Pp(a).toVar(),c=Fp(o).toVar(),d=Fp(n).toVar(),p=Fp(r).toVar(),m=Fp(i).toVar(),g=Fp(s).toVar(),f=Fp(e).toVar(),y=kp(t).toVar(),x=kp(CE(kp(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=kp(kp(Pp(f),Pp(g),Pp(m)).add(x)).toVar(),v=kp(b.sub(y)).toVar();return Ep(u.equal(Fp(2)),(()=>kg(v.x).add(kg(v.y)).add(kg(v.z)))),Ep(u.equal(Fp(3)),(()=>sf(sf(kg(v.x),kg(v.y)),kg(v.z)))),uf(v,v)})).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"}]})]),UE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=Pp(1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();u.assign(ef(u,s))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),OE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=zp(1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();Ep(s.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(s)})).ElseIf(s.lessThan(u.y),(()=>{u.y.assign(s)}))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),zE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=kp(1e6,1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();Ep(s.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(s)})).ElseIf(s.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(s)})).ElseIf(s.lessThan(u.z),(()=>{u.z.assign(s)}))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),LE=NM([UE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=Pp(1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();l.assign(ef(l,n))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),VE=NM([OE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=zp(1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();Ep(n.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(n)})).ElseIf(n.lessThan(l.y),(()=>{l.y.assign(n)}))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),DE=NM([zE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=kp(1e6,1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();Ep(n.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(n)})).ElseIf(n.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(n)})).ElseIf(n.lessThan(l.z),(()=>{l.z.assign(n)}))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),kE=Ap((([t])=>{const e=t.y,s=t.z,i=kp().toVar();return Ep(e.lessThan(1e-4),(()=>{i.assign(kp(s,s,s))})).Else((()=>{let r=t.x;r=r.sub(Bg(r)).mul(6).toVar();const n=Fp(Zg(r)),o=r.sub(Pp(n)),a=s.mul(e.oneMinus()),h=s.mul(e.mul(o).oneMinus()),u=s.mul(e.mul(o.oneMinus()).oneMinus());Ep(n.equal(Fp(0)),(()=>{i.assign(kp(s,u,a))})).ElseIf(n.equal(Fp(1)),(()=>{i.assign(kp(h,s,a))})).ElseIf(n.equal(Fp(2)),(()=>{i.assign(kp(a,s,u))})).ElseIf(n.equal(Fp(3)),(()=>{i.assign(kp(a,h,s))})).ElseIf(n.equal(Fp(4)),(()=>{i.assign(kp(u,a,s))})).Else((()=>{i.assign(kp(s,a,h))}))})),i})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),GE=Ap((([t])=>{const e=kp(t).toVar(),s=Pp(e.x).toVar(),i=Pp(e.y).toVar(),r=Pp(e.z).toVar(),n=Pp(ef(s,ef(i,r))).toVar(),o=Pp(sf(s,sf(i,r))).toVar(),a=Pp(o.sub(n)).toVar(),h=Pp().toVar(),u=Pp().toVar(),l=Pp().toVar();return l.assign(o),Ep(o.greaterThan(0),(()=>{u.assign(a.div(o))})).Else((()=>{u.assign(0)})),Ep(u.lessThanEqual(0),(()=>{h.assign(0)})).Else((()=>{Ep(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).ElseIf(i.greaterThanEqual(o),(()=>{h.assign(qm(2,r.sub(s).div(a)))})).Else((()=>{h.assign(qm(4,s.sub(i).div(a)))})),h.mulAssign(1/6),Ep(h.lessThan(0),(()=>{h.addAssign(1)}))})),kp(h,u,l)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),WE=Ap((([t])=>{const e=kp(t).toVar(),s=jp(eg(e,kp(.04045))).toVar(),i=kp(e.div(12.92)).toVar(),r=kp(cf(sf(e.add(kp(.055)),kp(0)).div(1.055),kp(2.4))).toVar();return xf(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),jE=(t,e)=>{t=Pp(t),e=Pp(e);const s=zp(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return _f(t.sub(s),t.add(s),e)},HE=(t,e,s,i)=>xf(t,e,s[i].clamp()),$E=(t,e,s=wy())=>HE(t,e,s,"x"),qE=(t,e,s=wy())=>HE(t,e,s,"y"),XE=(t,e,s,i,r)=>xf(t,e,jE(s,i[r])),YE=(t,e,s,i=wy())=>XE(t,e,s,i,"x"),ZE=(t,e,s,i=wy())=>XE(t,e,s,i,"y"),JE=(t=1,e=0,s=wy())=>s.mul(t).add(e),KE=(t,e=1)=>(t=Pp(t)).abs().pow(e).mul(t.sign()),QE=(t,e=1,s=.5)=>Pp(t).sub(s).mul(e).add(s),tB=(t=wy(),e=1,s=0)=>ME(t.convert("vec2|vec3")).mul(e).add(s),eB=(t=wy(),e=1,s=0)=>AE(t.convert("vec2|vec3")).mul(e).add(s),sB=(t=wy(),e=1,s=0)=>{t=t.convert("vec2|vec3");return Hp(AE(t),ME(t.add(zp(19,73)))).mul(e).add(s)},iB=(t=wy(),e=1)=>LE(t.convert("vec2|vec3"),e,Fp(1)),rB=(t=wy(),e=1)=>VE(t.convert("vec2|vec3"),e,Fp(1)),nB=(t=wy(),e=1)=>DE(t.convert("vec2|vec3"),e,Fp(1)),oB=(t=wy())=>NE(t.convert("vec2|vec3")),aB=(t=wy(),e=3,s=2,i=.5,r=1)=>RE(t,Fp(e),s,i).mul(r),hB=(t=wy(),e=3,s=2,i=.5,r=1)=>BE(t,Fp(e),s,i).mul(r),uB=(t=wy(),e=3,s=2,i=.5,r=1)=>EE(t,Fp(e),s,i).mul(r),lB=(t=wy(),e=3,s=2,i=.5,r=1)=>IE(t,Fp(e),s,i).mul(r),cB=Ap((([t,e])=>{const s=t.x,i=t.y,r=t.z;let n=e.element(0).mul(.886227);return n=n.add(e.element(1).mul(1.023328).mul(i)),n=n.add(e.element(2).mul(1.023328).mul(r)),n=n.add(e.element(3).mul(1.023328).mul(s)),n=n.add(e.element(4).mul(.858086).mul(s).mul(i)),n=n.add(e.element(5).mul(.858086).mul(i).mul(r)),n=n.add(e.element(6).mul(r.mul(r).mul(.743125).sub(.247708))),n=n.add(e.element(7).mul(.858086).mul(s).mul(r)),n=n.add(e.element(8).mul(.429043).mul(Ym(s,s).sub(Ym(i,i)))),n}));class dB extends NC{static get type(){return"PointLightNode"}constructor(t=null){super(t),this.cutoffDistanceNode=lm(0).setGroup(am),this.decayExponentNode=lm(0).setGroup(am)}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:s,decayExponentNode:i,light:r}=this,n=t.context.lightingModel,o=PC(r).sub(hx),a=o.normalize(),h=o.length(),u=CC({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=e.mul(u),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c},t.stack,t)}}class pB extends NC{static get type(){return"DirectionalLightNode"}constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=FC(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r},t.stack,t)}}const mB=new sr,gB=new sr;let fB=null;class yB extends NC{static get type(){return"RectAreaLightNode"}constructor(t=null){super(t),this.halfHeight=lm(new Ai).setGroup(am),this.halfWidth=lm(new Ai).setGroup(am)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;gB.identity(),mB.copy(e.matrixWorld),mB.premultiply(s),gB.extractRotation(mB),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(gB),this.halfHeight.value.applyMatrix4(gB)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=Ry(fB.LTC_FLOAT_1),s=Ry(fB.LTC_FLOAT_2)):(e=Ry(fB.LTC_HALF_1),s=Ry(fB.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=PC(r),a=t.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:e,ltc_2:s},t.stack,t)}static setLTC(t){fB=t}}class xB extends NC{static get type(){return"SpotLightNode"}constructor(t=null){super(t),this.coneCosNode=lm(0).setGroup(am),this.penumbraCosNode=lm(0).setGroup(am),this.cutoffDistanceNode=lm(0).setGroup(am),this.decayExponentNode=lm(0).setGroup(am)}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:s}=this;return _f(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=PC(n).sub(hx),a=o.normalize(),h=a.dot(FC(n)),u=this.getSpotAttenuation(h),l=o.length(),c=CC({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p},t.stack,t)}}class bB extends xB{static get type(){return"IESSpotLightNode"}getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=Ry(e,zp(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}class vB extends NC{static get type(){return"AmbientLightNode"}constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}class TB extends NC{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=BC(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=lm(new Xr).setGroup(am)}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:s,lightDirectionNode:i}=this,r=fx.dot(i).mul(.5).add(.5),n=xf(s,e,r);t.context.irradiance.addAssign(n)}}class _B extends NC{static get type(){return"LightProbeNode"}constructor(t=null){super(t);const e=[];for(let t=0;t<9;t++)e.push(new Ai);this.lightProbe=Fx(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=cB(yx,this.lightProbe);t.context.irradiance.addAssign(e)}}class wB{parseFunction(){console.warn("Abstract function.")}}class SB{constructor(t,e,s="",i=""){this.type=t,this.inputs=e,this.name=s,this.precision=i}getCode(){console.warn("Abstract function.")}}SB.isNodeFunction=!0;const MB=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,AB=/[a-z_0-9]+/gi,NB="#pragma main";class CB extends SB{constructor(t){const{type:e,inputs:s,name:i,precision:r,inputsCode:n,blockCode:o,headerCode:a}=(t=>{const e=(t=t.trim()).indexOf(NB),s=-1!==e?t.slice(e+12):t,i=s.match(MB);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=AB.exec(r));)n.push(o);const a=[];let h=0;for(;h0?this.transparent:this.opaque).push(o)}unshift(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||EB),this.transparent.length>1&&this.transparent.sort(e||BB)}finish(){this.lightsNode.setLights(this.lightsArray);for(let t=this.renderItemsIndex,e=this.renderItems.length;t>e,h=o.height>>e;let u=t.depthTexture||r[e];const l=!0===t.depthBuffer||!0===t.stencilBuffer;let c=!1;void 0===u&&l&&(u=new $a,u.format=t.stencilBuffer?jt:Wt,u.type=t.stencilBuffer?Ot:Bt,u.image.width=a,u.image.height=h,r[e]=u),s.width===o.width&&o.height===s.height||(c=!0,u&&(u.needsUpdate=!0,u.image.width=a,u.image.height=h)),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=u||null,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,u&&(u.needsUpdate=!0),s.sampleCount=i);const d={sampleCount:i};for(let t=0;t{t.removeEventListener("dispose",e);for(let t=0;t0){const i=t.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(t.images){const s=[];for(const e of t.images)s.push(e);e.images=s}else e.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(t,e),s.isDefaultTexture=!1,s.generation=t.version),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0,s.generation=t.version}if(!0!==s.initialized){s.initialized=!0,s.generation=t.version,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}s.version=t.version}getSize(t,e=LB){let s=t.images?t.images[0]:t.image;return s?(void 0!==s.image&&(s=s.image),e.width=s.width,e.height=s.height,e.depth=t.isCubeTexture?6:s.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,s){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,s)))+1,i}needsMipmaps(t){return!!this.isEnvironmentTexture(t)||(!0===t.isCompressedTexture||t.minFilter!==ft&&t.minFilter!==Tt)}isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class DB extends Xr{constructor(t,e,s,i=1){super(t,e,s),this.a=i}set(t,e,s,i=1){return this.a=i,super.set(t,e,s)}copy(t){return void 0!==t.a&&(this.a=t.a),super.copy(t)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const kB=new DB;class GB extends $w{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,s){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let n=!1;if(null===r)i._clearColor.getRGB(kB,Je),kB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(kB,Je),kB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;kB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=Bf(Hp(n).mul(cA),{getUV:()=>yx,getTextureLevel:()=>lA});let e=Qb();e=e.setZ(e.w);const i=new cT;i.name="Background.material",i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new On(new uu(1,32,32),i),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Hp(n).mul(cA),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),e.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){const t=s.clearColorValue;t.r=kB.r,t.g=kB.g,t.b=kB.b,t.a=kB.a,!0!==i.backend.isWebGLBackend&&!0!==i.alpha||(t.r*=t.a,t.g*=t.a,t.b*=t.a),s.depthClearValue=i._clearDepth,s.stencilClearValue=i._clearStencil,s.clearColor=!0===i.autoClearColor,s.clearDepth=!0===i.autoClearDepth,s.clearStencil=!0===i.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}class WB{constructor(t,e,s,i,r,n,o,a,h,u=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==e.bindings[0].groupNode.shared){const s=new cM(e.name,[],e.index,e);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}const jB=new WeakMap;class HB extends $w{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new yM,this.nodeBuilderCache=new Map,this.callHashCache=new Vw,this.groupsData=new Vw}updateGroup(t){const e=t.groupNode,s=e.name;if(s===hm.name)return!0;if(s===am.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===om.name){const e=this.get(t),s=this.nodeFrame.frameId;return e.frameId!==s&&(e.frameId=s,!0)}const i=[e,t];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==e.version&&(r.version=e.version,!0)}getForRenderCacheKey(t){return t.initialCacheKey}getForRender(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(s=i.get(r),void 0===s){const e=this.backend.createNodeBuilder(t.object,this.renderer);e.scene=t.scene,e.material=t.material,e.camera=t.camera,e.context.material=t.material,e.lightsNode=t.lightsNode,e.environmentNode=this.getEnvironmentNode(t.scene),e.fogNode=this.getFogNode(t.scene),e.clippingContext=t.clippingContext,e.build(),s=this._createNodeBuilderState(e),i.set(r,s)}s.usedTimes++,e.nodeBuilderState=s}return s}delete(t){if(t.isRenderObject){const e=this.get(t).nodeBuilderState;e.usedTimes--,0===e.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(t))}return super.delete(t)}getForCompute(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),s=this._createNodeBuilderState(i),e.nodeBuilderState=s}return s}_createNodeBuilderState(t){return new WB(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.monitor,t.transforms)}getEnvironmentNode(t){return t.environmentNode||this.get(t).environmentNode||null}getBackgroundNode(t){return t.backgroundNode||this.get(t).backgroundNode||null}getFogNode(t){return t.fogNode||this.get(t).fogNode||null}getCacheKey(t,e){const s=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(t),o=this.getFogNode(t),a=[];e&&a.push(e.getCacheKey(!0)),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),a.push(this.renderer.shadowMap.enabled?1:0),r={callId:i,cacheKey:xd(a)},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(t){this.updateEnvironment(t),this.updateFog(t),this.updateBackground(t)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(t){const e=this.get(t),s=t.background;if(s){const i=0===t.backgroundBlurriness&&e.backgroundBlurriness>0||t.backgroundBlurriness>0&&0===e.backgroundBlurriness;if(e.background!==s||i){let i=null;if(!0===s.isCubeTexture||s.mapping===lt||s.mapping===ct||s.mapping===dt)if(t.backgroundBlurriness>0||s.mapping===dt)i=ow(s,yx);else{let t;t=!0===s.isCubeTexture?Rx(s):Ry(s),i=BT(t)}else!0===s.isTexture?i=Ry(s,zv.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);e.backgroundNode=i,e.background=s,e.backgroundBlurriness=t.backgroundBlurriness}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),s=t.fog;if(s){if(e.fog!==s){let t=null;if(s.isFogExp2){const e=Lx("color","color",s).setGroup(am),i=Lx("density","float",s).setGroup(am);t=pC(e,i)}else if(s.isFog){const e=Lx("color","color",s).setGroup(am),i=Lx("near","float",s).setGroup(am),r=Lx("far","float",s).setGroup(am);t=cC(e,i,r)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);e.fogNode=t,e.fog=s}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),s=t.environment;if(s){if(e.environment!==s){let t=null;!0===s.isCubeTexture?t=Rx(s):!0===s.isTexture?t=Ry(s):console.error("Nodes: Unsupported environment configuration.",s),e.environmentNode=t,e.environment=s}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=t,n.scene=e,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(t){return this.getNodeFrame(t.renderer,t.scene,t.object,t.camera,t.material)}getOutputCacheKey(){const t=this.renderer;return t.toneMapping+","+t.currentColorSpace}hasOutputChange(t){return jB.get(t)!==this.getOutputCacheKey()}getOutputNode(t){const e=this.renderer,s=this.getOutputCacheKey(),i=Ry(t,zv).renderOutput(e.toneMapping,e.currentColorSpace);return jB.set(t,s),i}updateBefore(t){const e=t.getNodeBuilderState();for(const s of e.updateBeforeNodes)this.getNodeFrameForRender(t).updateBeforeNode(s)}updateAfter(t){const e=t.getNodeBuilderState();for(const s of e.updateAfterNodes)this.getNodeFrameForRender(t).updateAfterNode(s)}updateForCompute(t){const e=this.getNodeFrame(),s=this.getForCompute(t);for(const t of s.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateNodes)e.updateNode(t)}needsRefresh(t){const e=this.getNodeFrameForRender(t);return t.getMonitor().needsRefresh(t,e)}dispose(){super.dispose(),this.nodeFrame=new yM,this.nodeBuilderCache=new Map}}class $B{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class qB{constructor(){this.lists=new Vw}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new $B(t,e),s.set(i,r)),r}dispose(){this.lists=new Vw}}class XB{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map,this.colorSpaceNodes=new Map}fromMaterial(t){if(t.isNodeMaterial)return t;let e=null;const s=this.getMaterialNodeClass(t.type);if(null!==s){e=new s;for(const s in t)e[s]=t[s]}return e}addColorSpace(t,e){this.addType(t,e,this.colorSpaceNodes)}getColorSpaceFunction(t){return this.colorSpaceNodes.get(t)||null}addToneMapping(t,e){this.addType(t,e,this.toneMappingNodes)}getToneMappingFunction(t){return this.toneMappingNodes.get(t)||null}getMaterialNodeClass(t){return this.materialNodes.get(t)||null}addMaterial(t,e){this.addType(t,e.type,this.materialNodes)}getLightNodeClass(t){return this.lightNodes.get(t)||null}addLight(t,e){this.addClass(t,e,this.lightNodes)}addType(t,e,s){if(s.has(e))console.warn(`Redefinition of node ${e}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"==typeof e||"object"==typeof e)throw new Error(`Base class ${e} is not a class.`);s.set(e,t)}}addClass(t,e,s){if(s.has(e))console.warn(`Redefinition of node ${e.name}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"!=typeof e)throw new Error(`Base class ${e.name} is not a class.`);s.set(e,t)}}}const YB=new Kn,ZB=new Ys,JB=new xi,KB=new Ko,QB=new sr,tI=new xi;class eI{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,depth:r=!0,stencil:n=!1,antialias:o=!1,samples:a=0,getFallback:h=null}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=a||!0===o?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Ze,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=n,this.clippingPlanes=[],this.info=new eS,this.nodes={library:new XB,modelViewMatrix:null,modelNormalViewMatrix:null},this._getFallback=h,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new xi(0,0,this._width,this._height),this._scissor=new xi(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new tA(new cT),this._quad.material.type="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const u=!0===this.alpha?0:1;this._clearColor=new DB(0,0,0,u),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:1},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(t,e,s)=>{await this.compileAsync(t,e);const i=this._renderLists.get(t,e),r=this._renderContexts.get(t,e,this._renderTarget),n=t.overrideMaterial||s.material,o=this._objects.get(s,n,t,e,i.lightsNode,r),{fragmentShader:a,vertexShader:h}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:h}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(t,e)=>{let s=this.backend;try{await s.init(this)}catch(t){if(null===this._getFallback)return void e(t);try{this.backend=s=this._getFallback(t),await s.init(this)}catch(t){return void e(t)}}this._nodes=new HB(this,s),this._animation=new Lw(this._nodes,this.info),this._attributes=new Jw(s),this._background=new GB(this,this._nodes),this._geometries=new tS(this._attributes,this.info),this._textures=new VB(this,s,this.info),this._pipelines=new aS(s,this._nodes),this._bindings=new hS(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Hw(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new PB,this._bundles=new qB,this._renderContexts=new zB,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,s=null){!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,h=!0===t.isScene?t:YB;null===s&&(s=t);const u=this._renderTarget,l=this._renderContexts.get(s,e,u),c=this._activeMipmapLevel,d=[];this._currentRenderContext=l,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),l.depth=this.depth,l.stencil=this.stencil,l.clippingContext||(l.clippingContext=new kw),l.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,u);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),s!==t&&s.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const t=this._textures.get(u);l.textures=t.textures,l.depthTexture=t.depthTexture}else l.textures=null,l.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,l);const m=p.opaque,g=p.transparent,f=p.lightsNode;!0===this.opaque&&m.length>0&&this._renderObjects(m,e,h,f),!0===this.transparent&&g.length>0&&this._renderObjects(g,e,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const s=this._renderScene(t,e);await this.backend.resolveTimestampAsync(s,"render")}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_renderBundle(t,e,s){const{bundleGroup:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this._bundles.get(i,r),h=this.backend.get(a);void 0===h.renderContexts&&(h.renderContexts=new Set);const u=i.version!==h.version,l=!1===h.renderContexts.has(o)||u;if(h.renderContexts.add(o),l){this.backend.beginBundle(o),(void 0===h.renderObjects||u)&&(h.renderObjects=[]),this._currentRenderBundle=a;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),h.version=i.version}else{const{renderObjects:t}=h;for(let e=0,s=t.length;e>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(JB),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(JB),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new kw),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),QB.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),KB.setFromProjectionMatrix(QB,m);const v=this._renderLists.get(t,e);if(v.begin(),this._projectObject(t,e,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const t=this._textures.get(d);p.textures=t.textures,p.depthTexture=t.depthTexture,p.width=t.width,p.height=t.height,p.renderTarget=d,p.depth=d.depthBuffer,p.stencil=d.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=l,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const{bundles:T,lightsNode:_,transparent:w,opaque:S}=v;if(T.length>0&&this._renderBundles(T,h,_),!0===this.opaque&&S.length>0&&this._renderObjects(S,e,h,_),!0===this.transparent&&w.length>0&&this._renderObjects(w,e,h,_),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const t=this._quad;this._nodes.hasOutputChange(d.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(d.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}return h.onAfterRender(this,t,e,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(t){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(t)}async getArrayBufferAsync(t){return await this.backend.getArrayBufferAsync(t)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(t){return t.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(t){return t.set(this._width,this._height)}setPixelRatio(t=1){this._pixelRatio=t,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(t,e,s){this._width=t,this._height=e,this._pixelRatio=s,this.domElement.width=Math.floor(t*s),this.domElement.height=Math.floor(e*s),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,s=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===s&&(this.domElement.style.width=t+"px",this.domElement.style.height=e+"px"),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setOpaqueSort(t){this._opaqueSort=t}setTransparentSort(t){this._transparentSort=t}getScissor(t){const e=this._scissor;return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t}setScissor(t,e,s,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,s,i,r=0,n=1){const o=this._viewport;t.isVector4?o.copy(t):o.set(t,e,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(t){return t.copy(this._clearColor)}setClearColor(t,e=1){this._clearColor.set(t),this._clearColor.a=e}getClearAlpha(){return this._clearColor.a}setClearAlpha(t){this._clearColor.a=t}getClearDepth(){return this._clearDepth}setClearDepth(t){this._clearDepth=t}getClearStencil(){return this._clearStencil}setClearStencil(t){this._clearStencil=t}isOccluded(t){const e=this._currentRenderContext;return e&&this.backend.isOccluded(e,t)}clear(t=!0,e=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(t,e,s);const i=this._renderTarget||this._getFrameBufferTarget();let r=null;if(null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget){const t=this._quad;this._nodes.hasOutputChange(i.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(i.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(t=!0,e=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(t,e,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?0:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Je:this.outputColorSpace}dispose(){this.info.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(t,e=0,s=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}compute(t){if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(t);const e=this._nodes.nodeFrame,s=e.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,e.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(t)?t:[t];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of a){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),n.delete(e),o.delete(e)};e.addEventListener("dispose",t);const s=e.onInitFunction;null!==s&&s.call(e,{renderer:this})}o.updateForCompute(e),n.updateForCompute(e);const s=n.getForCompute(e),a=r.getForCompute(e,s);i.compute(t,e,s,a)}i.finishCompute(t),e.renderId=s}async computeAsync(t){!1===this._initialized&&await this.init(),this.compute(t),await this.backend.resolveTimestampAsync(t,"compute")}async hasFeatureAsync(t){return!1===this._initialized&&await this.init(),this.backend.hasFeature(t)}hasFeature(t){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(t)}copyFramebufferToTexture(t,e=null){const s=this._currentRenderContext;this._textures.updateTexture(t),e=null===e?tI.set(0,0,t.image.width,t.image.height):e,this.backend.copyFramebufferToTexture(t,s,e)}copyTextureToTexture(t,e,s=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,s,i,r)}readRenderTargetPixelsAsync(t,e,s,i,r,n=0,o=0){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r,o)}_projectObject(t,e,s,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)s=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)i.pushLight(t);else if(t.isSprite){if(!t.frustumCulled||KB.intersectsSprite(t)){!0===this.sortObjects&&tI.setFromMatrixPosition(t.matrixWorld).applyMatrix4(QB);const{geometry:e,material:r}=t;r.visible&&i.push(t,e,r,s,tI.z,null)}}else if(t.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||KB.intersectsObject(t))){const{geometry:e,material:r}=t;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),tI.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(QB)),Array.isArray(r)){const n=e.groups;for(let o=0,a=n.length;o0?i:"";e=`${t.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,n=!0}const o=r.node.precision;if(null!==o&&(e=fI[o]+" "+e),n){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,s.push(e)}let r="";for(const e in i){const s=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==Et){let s=t;t.isInterleavedBufferAttribute&&(s=t.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(e=e.slice(1))}return e}getAttributes(t){let e="";if("vertex"===t||"compute"===t){const t=this.getAttributesArray();let s=0;for(const i of t)e+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;tt*e),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(t,e,s=this.shaderStage){const i=this.extensions[s]||(this.extensions[s]=new Map);!1===i.has(t)&&i.set(t,{name:t,behavior:e})}getExtensions(t){const e=[];if("vertex"===t){const e=this.renderer.backend.extensions;this.object.isBatchedMesh&&e.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",t)}const s=this.extensions[t];if(void 0!==s)for(const{name:t,behavior:i}of s.values())e.push(`#extension ${t} : ${i}`);return e.join("\n")}isAvailable(t){let e=yI[t];if(void 0===e){if("float32Filterable"===t){const t=this.renderer.backend.extensions;t.has("OES_texture_float_linear")?(t.get("OES_texture_float_linear"),e=!0):e=!1}yI[t]=e}return e}isFlipY(){return!0}registerTransform(t,e){this.transforms.push({varyingName:t,attributeNode:e})}getTransforms(){const t=this.transforms;let e="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,t===r&&"compute"!==e&&(s+="// result\n\t","vertex"===e?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=t[e];n.extensions=this.getExtensions(e),n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.vars=this.getVars(e),n.structs=this.getStructs(e),n.codes=this.getCodes(e),n.transforms=this.getTransforms(e),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=t.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===e)o=new dI(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new pI(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new mI(r.name,r.node,i),h.push(o);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new oI(t,i);e.name=t.name,h.push(e),o=e}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new uI(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let vI=null,TI=null,_I=null;class wI{constructor(t={}){this.parameters=Object.assign({},t),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(t){this.renderer=t}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(t){const{object:e,geometry:s}=t;return s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return vI=vI||new Ys,this.renderer.getDrawingBufferSize(vI)}getScissor(){return TI=TI||new xi,this.renderer.getScissor(TI)}setScissorTest(){}getClearColor(){const t=this.renderer;return _I=_I||new DB,t.getClearColor(_I),_I.getRGB(_I,this.renderer.currentColorSpace),_I}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ei(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${t} webgpu`),this.domElement=e),e}set(t,e){this.data.set(t,e)}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}has(t){return this.data.has(t)}delete(t){this.data.delete(t)}}let SI=0;class MI{constructor(t,e){this.buffers=[t.bufferGPU,e],this.type=t.type,this.bufferType=t.bufferType,this.pbo=t.pbo,this.byteLength=t.byteLength,this.bytesPerElement=t.BYTES_PER_ELEMENT,this.version=t.version,this.isInteger=t.isInteger,this.activeBufferIndex=0,this.baseId=t.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class AI{constructor(t){this.backend=t}createAttribute(t,e){const s=this.backend,{gl:i}=s,r=t.array,n=t.usage||i.STATIC_DRAW,o=t.isInterleavedBufferAttribute?t.data:t,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,e,r,n),a.bufferGPU=u,a.bufferType=e,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)h=i.SHORT;else if(r instanceof Uint32Array)h=i.UNSIGNED_INT;else if(r instanceof Int32Array)h=i.INT;else if(r instanceof Int8Array)h=i.BYTE;else if(r instanceof Uint8Array)h=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);h=i.UNSIGNED_BYTE}let l={bufferGPU:u,bufferType:e,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||t.gpuType===Et,id:SI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);l=new MI(l,t)}s.set(t,l)}updateAttribute(t){const e=this.backend,{gl:s}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,n=e.get(r),o=n.bufferType,a=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let t=0,e=a.length;t1?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE)}setPolygonOffset(t,e,s){const{gl:i}=this;t?(this.enable(i.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===e&&this.currentPolygonOffsetUnits===s||(i.polygonOffset(e,s),this.currentPolygonOffsetFactor=e,this.currentPolygonOffsetUnits=s)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(t){return this.currentProgram!==t&&(this.gl.useProgram(t),this.currentProgram=t,!0)}bindFramebuffer(t,e){const{gl:s,currentBoundFramebuffers:i}=this;return i[t]!==e&&(s.bindFramebuffer(t,e),i[t]=e,t===s.DRAW_FRAMEBUFFER&&(i[s.FRAMEBUFFER]=e),t===s.FRAMEBUFFER&&(i[s.DRAW_FRAMEBUFFER]=e),!0)}drawBuffers(t,e){const{gl:s}=this;let i=[],r=!1;if(null!==t.textures){i=this.currentDrawbuffers.get(e),void 0===i&&(i=[],this.currentDrawbuffers.set(e,i));const n=t.textures;if(i.length!==n.length||i[0]!==s.COLOR_ATTACHMENT0){for(let t=0,e=n.length;t{!function r(){const n=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(n===t.WAIT_FAILED)return t.deleteSync(e),void i();n!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),s()):requestAnimationFrame(r)}()}))}}let II,PI,FI,UI=!1;class OI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===UI&&(this._init(this.gl),UI=!0)}_init(t){II={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},PI={[ft]:t.NEAREST,[yt]:t.NEAREST_MIPMAP_NEAREST,[bt]:t.NEAREST_MIPMAP_LINEAR,[Tt]:t.LINEAR,[_t]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},FI={512:t.NEVER,519:t.ALWAYS,[ys]:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===ft||t===yt||t===bt?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let s;return s=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,s}getInternalFormat(t,e,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==t){if(void 0!==n[t])return n[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let a=e;return e===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=i===Ze&&!1===r?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),e===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),e===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=i===Ze&&!1===r?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),e===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),e===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),e===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(t,e){const{gl:s,extensions:i,backend:r}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,e.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,e.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(t,s.TEXTURE_WRAP_S,II[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,II[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,II[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,PI[e.magFilter]);const n=void 0!==e.mipmaps&&e.mipmaps.length>0,o=e.minFilter===Tt&&n?St:e.minFilter;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,PI[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,FI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===ft)return;if(e.minFilter!==bt&&e.minFilter!==St)return;if(e.type===It&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy()))}}}createDefaultTexture(t){const{gl:e,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(t);let n=i[r];void 0===n&&(n=e.createTexture(),s.state.bindTexture(r,n),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=n),s.set(t,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=e,h=i.utils.convert(t.format,t.colorSpace),u=i.utils.convert(t.type),l=this.getInternalFormat(t.internalFormat,h,u,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),this.setTextureParameters(d,t),t.isDataArrayTexture||t.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:u}=e.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(n,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,h,u,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:s}=this,{width:i,height:r}=e,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const l=t=>t.isDataTexture?t.image.data:t instanceof ImageBitmap||t instanceof OffscreenCanvas||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement?t:t.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,t),t.isCompressedTexture){const i=t.mipmaps,r=e.image;for(let e=0;e0,c=e.renderTarget?e.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(l){const s=0!==o||0!==a;let l,d;if(!0===t.isDepthTexture?(l=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,e.stencil&&(l|=i.STENCIL_BUFFER_BIT)):(l=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),s){const t=this.backend.get(e.renderTarget),s=t.framebuffers[e.getCacheKey()],d=t.msaaFrameBuffer;r.bindFramebuffer(i.DRAW_FRAMEBUFFER,s),r.bindFramebuffer(i.READ_FRAMEBUFFER,d);const p=c-a-u;i.blitFramebuffer(o,p,o+h,p+u,o,p,o+h,p+u,l,i.NEAREST),r.bindFramebuffer(i.READ_FRAMEBUFFER,s),r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,p,h,u),r.unbindTexture()}else{const t=i.createFramebuffer();r.bindFramebuffer(i.DRAW_FRAMEBUFFER,t),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,n,0),i.blitFramebuffer(0,0,h,u,0,0,h,u,l,i.NEAREST),i.deleteFramebuffer(t)}}else r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,c-u-a,h,u),r.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:s}=this,i=e.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,t),o&&!a){let e=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(e=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,e,h,u)):s.renderbufferStorage(s.RENDERBUFFER,e,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,u):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r,n){const{backend:o,gl:a}=this,{textureGPU:h,glFormat:u,glType:l}=this.backend.get(t),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const d=t.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,d,h,0);const p=this._getTypedArrayType(l),m=i*r*this._getBytesPerTexel(l,u),g=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.bufferData(a.PIXEL_PACK_BUFFER,m,a.STREAM_READ),a.readPixels(e,s,i,r,u,l,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(m/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(t){const{gl:e}=this;if(t===e.UNSIGNED_BYTE)return Uint8Array;if(t===e.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(t===e.UNSIGNED_SHORT)return Uint16Array;if(t===e.UNSIGNED_INT)return Uint32Array;if(t===e.HALF_FLOAT)return Uint16Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t,e){const{gl:s}=this;let i=0;return t===s.UNSIGNED_BYTE&&(i=1),t!==s.UNSIGNED_SHORT_4_4_4_4&&t!==s.UNSIGNED_SHORT_5_5_5_1&&t!==s.UNSIGNED_SHORT_5_6_5&&t!==s.UNSIGNED_SHORT&&t!==s.HALF_FLOAT||(i=2),t!==s.UNSIGNED_INT&&t!==s.FLOAT||(i=4),e===s.RGBA?4*i:e===s.RGB?3*i:e===s.ALPHA?i:void 0}}class zI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(t){let e=this.extensions[t];return void 0===e&&(e=this.gl.getExtension(t),this.extensions[t]=e),e}has(t){return this.availableExtensions.includes(t)}}class LI{constructor(t){this.backend=t,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const t=this.backend.gl,e=this.backend.extensions;if(!0===e.has("EXT_texture_filter_anisotropic")){const s=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const VI={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class DI{constructor(t){this.gl=t.gl,this.extensions=t.extensions,this.info=t.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(t,e){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,e,n,t):s.drawArrays(i,t,e),o.update(r,e,i,1)}renderInstances(t,e,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,e,n,t,s):i.drawArraysInstanced(r,t,e,s),h.update(a,e,r,s))}renderMultiDraw(t,e,s){const{extensions:i,mode:r,object:n,info:o}=this;if(0===s)return;const a=i.get("WEBGL_multi_draw");if(null===a)for(let i=0;i0)){const t=e.queryQueue.shift();this.initTimestampQuery(t)}}async resolveTimestampAsync(t,e="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(t);s.gpuQueries||(s.gpuQueries=[]);for(let t=0;t0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(i),s.occlusionQueryObjects=new Array(i),s.occlusionQueryIndex=0)}finishRender(t){const{gl:e,state:s}=this,i=this.get(t),r=i.previousContext,n=t.occlusionQueryCount;n>0&&(n>i.occlusionQueryIndex&&e.endQuery(e.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(t));const o=t.textures;if(null!==o)for(let t=0;t0){const r=i.framebuffers[t.getCacheKey()],n=e.COLOR_BUFFER_BIT,o=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,o),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,r);for(let s=0;s{let o=0;for(let e=0;e0&&t.add(i[e]),s[e]=null,r.deleteQuery(n),o++))}o1?m.renderInstances(y,g,f):m.render(y,g),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r,n){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r,n)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new bI(t,e)}createProgram(t){const e=this.gl,{stage:s,code:i}=t,r="fragment"===s?e.createShader(e.FRAGMENT_SHADER):e.createShader(e.VERTEX_SHADER);e.shaderSource(r,i),e.compileShader(r),this.set(t,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(t,e){const s=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:n}=i,o=s.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,h),s.linkProgram(o),this.set(i,{programGPU:o,fragmentShader:a,vertexShader:h}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(n)};n()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const s=t.split("\n"),i=[],r=Math.max(e-6,0),n=Math.min(e+6,s.length);for(let t=r;t":" "} ${r}: ${s[t]}`)}return i.join("\n")}_getShaderErrors(t,e,s){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const n=/ERROR: 0:(\d+)/.exec(r);if(n){const i=parseInt(n[1]);return s.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(t).trim();if(!1===i.getProgramParameter(t,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,t,s,e);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,e,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(t,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const{state:s,gl:i}=this,r=this.get(e),{programGPU:n,fragmentShader:o,vertexShader:a}=r;!1===i.getProgramParameter(n,i.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const h=t.getBindings();this._setupBindings(h,n),this.set(e,{programGPU:n})}createComputePipeline(t,e){const{state:s,gl:i}=this,r={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(r);const{computeProgram:n}=t,o=i.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU,u=n.transforms,l=[],c=[];for(let t=0;tVI[e]===t)),s=this.extensions;for(let t=0;t0){if(void 0===l){const i=[];l=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,l);const r=[],u=t.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=t.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=t.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(t){let e=this.transferPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({label:`mipmap-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:fA,stripIndexFormat:PA},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({label:`flipY-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:fA,stripIndexFormat:PA},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,s=0){const i=e.format,{width:r,height:n}=e.size,o=this.getTransferPipeline(i),a=this.getFlipYPipeline(i),h=this.device.createTexture({size:{width:r,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,s)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:NA,storeOp:MA,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,u,l),d(a,l,u),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.get(t);void 0===i.useCount&&(i.useCount=0,i.layers=[]);const r=i.layers[s]||this._mipmapCreateBundles(t,e,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,r),this.device.queue.submit([n.finish()]),0!==i.useCount&&(i.layers[s]=r),i.useCount++}_mipmapCreateBundles(t,e,s){const i=this.getTransferPipeline(e.format),r=i.getBindGroupLayout(0);let n=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:s});const o=[];for(let a=1;a1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=l,i.msaaTexture=s.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,s=e.get(t);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),e.delete(t)}destroySampler(t){delete this.backend.get(t).sampler}generateMipmaps(t){const e=this.backend.get(t);if(t.isCubeTexture)for(let t=0;t<6;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t);else{const s=t.image.depth||1;for(let t=0;t1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,QI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,tP={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class eP extends SB{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(KI);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=QI.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let t=0;t "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class sP extends wB{parseFunction(t){return new eP(t)}}const iP=self.GPUShaderStage,rP={vertex:iP?iP.VERTEX:1,fragment:iP?iP.FRAGMENT:2,compute:iP?iP.COMPUTE:4},nP={instance:!0,swizzleAssign:!1,storageBuffer:!0},oP={"^^":"tsl_xor"},aP={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",imat2:"mat2x2",umat2:"mat2x2",bmat2:"mat2x2",mat3:"mat3x3",imat3:"mat3x3",umat3:"mat3x3",bmat3:"mat3x3",mat4:"mat4x4",imat4:"mat4x4",umat4:"mat4x4",bmat4:"mat4x4"},hP={tsl_xor:new xS("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new xS("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new xS("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new xS("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new xS("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new xS("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new xS("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new xS("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new xS("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping:new xS("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new xS("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet iRes = vec2i( textureDimensions( map, level ) );\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},uP={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(hP.pow_float=new xS("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),hP.pow_vec2=new xS("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[hP.pow_float]),hP.pow_vec3=new xS("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[hP.pow_float]),hP.pow_vec4=new xS("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[hP.pow_float]),uP.pow_float="tsl_pow_float",uP.pow_vec2="tsl_pow_vec2",uP.pow_vec3="tsl_pow_vec3",uP.pow_vec4="tsl_pow_vec4");let lP="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(lP+="diagnostic( off, derivative_uniformity );\n");class cP extends fM{constructor(t,e){super(t,e,new sP),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}_generateTextureSample(t,e,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${s}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${s} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s):this.generateTextureLod(t,e,s,"0")}_generateVideoSample(t,e,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(t,e,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${s}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s,i):this.generateTextureLod(t,e,s,i)}generateFilteredTexture(t,e,s,i="0"){return this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, tsl_repeatWrapping( ${s}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,s,i,r="0u"){return i?`textureLoad( ${e}, ${s}, ${i}, ${r} )`:`textureLoad( ${e}, ${s}, ${r} )`}generateTextureStore(t,e,s,i){return`textureStore( ${e}, ${s}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!this.isAvailable("float32Filterable")&&!0===t.isDataTexture&&t.type===It||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,s,i,r=this.shaderStage){let n=null;return n=!0===t.isVideoTexture?this._generateVideoSample(e,s,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,s,"0",i,r):this._generateTextureSample(t,e,s,i,r),n}generateTextureGrad(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${e}, ${e}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(t,e,s,i,r,n=this.shaderStage){let o=null;return o=!0===t.isVideoTexture?this._generateVideoSample(e,s,n):this._generateTextureSampleLevel(t,e,s,i,r,n),o}generateTextureBias(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(t,e=this.shaderStage){if(!0===t.isNodeVarying&&!0===t.needsInterpolation){if("vertex"===e)return`varyings.${t.name}`}else if(!0===t.isNodeUniform){const e=t.name,s=t.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?e:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${t.id}.${e}`:t.groupNode.name+"."+e}return super.getPropertyName(t)}getOutputStructName(){return"output"}_getUniformGroupCount(t){return Object.keys(this.uniforms[t]).length}getFunctionOperator(t){const e=oP[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case yN:return"read";case fN:return"write";default:return"read_write"}else switch(t.access){case mN:return"read_write";case gN:return"read";default:return"write"}}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=t.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let n=null;if("texture"===e||"storageTexture"===e?n=new dI(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new pI(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new mI(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(rP[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new WI(`${r.name}_sampler`,r.node,o);t.setVisibility(rP[s]),h.push(t,n),i=[t,n]}else h.push(n),i=[n]}else if("buffer"===e||"storageBuffer"===e){const r=new("storageBuffer"===e?$I:oI)(t,o);r.setVisibility(rP[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new uI(a,o),n.setVisibility(rP[s]),t[a]=n,h.push(n)),i=this.getNodeUniform(r,e),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(t,e,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(t)&&r.set(t,{name:t,property:e,type:s}),e}hasBuiltin(t,e=this.shaderStage){return void 0!==this.builtins[e]&&this.builtins[e].has(t)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));let r=`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(r+=`\treturn ${s.result};\n`),r+="\n}\n",r}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}enableDirective(t,e=this.shaderStage){(this.directives[e]||(this.directives[e]=new Set)).add(t)}getDirectives(t){const e=[],s=this.directives[t];if(void 0!==s)for(const t of s)e.push(`enable ${t};`);return e.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}getBuiltins(t){const e=[],s=this.builtins[t];if(void 0!==s)for(const{name:t,property:i,type:r}of s.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getScopedArray(t,e,s,i){return!1===this.scopedArrays.has(t)&&this.scopedArrays.set(t,{name:t,scope:e,bufferType:s,bufferCount:i}),t}getScopedArrays(t){if("compute"!==t)return;const e=[];for(const{name:t,scope:s,bufferType:i,bufferCount:r}of this.scopedArrays.values()){const n=this.getType(i);e.push(`var<${s}> ${t}: array< ${n}, ${r} >;`)}return e.join("\n")}getAttributes(t){const e=[];if("compute"===t&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",t),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const s=this.getAttributesArray();for(let t=0,i=s.length;t`)}const i=this.getBuiltins("output");return i&&e.push("\t"+i),e.join(",\n")}getStructs(t){const e=[],s=this.structs[t];for(let t=0,i=s.length;t output : ${r};\n\n`)}return e.join("\n\n")}getVar(t,e){return`var ${e} : ${this.getType(t)}`}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`\t${this.getVar(t.type,t.name)};`);return`\n${e.join("\n")}\n`}getVaryings(t){const e=[];if("vertex"===t&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===t||"fragment"===t){const s=this.varyings,i=this.vars[t];for(let r=0;r";else if(!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture)i="texture_2d_array";else if(!0===e.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===e.isVideoTexture)i="texture_external";else if(!0===e.isData3DTexture)i="texture_3d";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${JI(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),s=t.bufferCount,n=s>0&&"buffer"===r.type?", "+s:"",a=t.isAtomic?`atomic<${e}>`:`${e}`,h=`\t${r.name} : array< ${a}${n} >\n`,u=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,h,u,o.binding++,o.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(n[e]||(n[e]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in n){const e=n[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const e in t){const s=t[e];s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.structs=this.getStructs(e),s.vars=this.getVars(e),s.codes=this.getCodes(e),s.directives=this.getDirectives(e),s.scopedArrays=this.getScopedArrays(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),h=t.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,t===n&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",t),s.structs+="\nvar output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(t.vertex),this.fragmentShader=this._getWGSLFragmentCode(t.fragment)):this.computeShader=this._getWGSLComputeCode(t.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(t,e=null){let s;return null!==e&&(s=this._getWGSLMethod(t+"_"+e)),void 0===s&&(s=this._getWGSLMethod(t)),s||t}getType(t){return aP[t]||t}isAvailable(t){let e=nP[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),nP[t]=e),e}_getWGSLMethod(t){return void 0!==hP[t]&&this._include(t),uP[t]}_include(t){const e=hP[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\n// directives\n${t.directives}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${t.codes}\n\n@vertex\nfn main( ${t.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(t){return`${this.getSignature()}\n// global\n${lP}\n\n// uniforms\n${t.uniforms}\n\n// structs\n${t.structs}\n\n// codes\n${t.codes}\n\n@fragment\nfn main( ${t.varyings} ) -> ${t.returnType} {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLComputeCode(t,e){return`${this.getSignature()}\n// directives\n${t.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${t.scopedArrays}\n\n// uniforms\n${t.uniforms}\n\n// codes\n${t.codes}\n\n@compute @workgroup_size( ${e} )\nfn main( ${t.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${e}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${e});\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLStruct(t,e){return`\nstruct ${t} {\n${e}\n};`}_getWGSLStructBinding(t,e,s,i=0,r=0){const n=t+"Struct";return`${this._getWGSLStruct(n,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${t} : ${n};`}}class dP{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=FA.Depth24PlusStencil8:t.depth&&(e=FA.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):this.getPreferredCanvasFormat(),e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?dA:t.isLineSegments||t.isMesh&&!0===e.wireframe?pA:t.isLine?mA:t.isMesh?gA:void 0}getSampleCount(t){let e=1;return t>1&&(e=Math.pow(2,Math.floor(Math.log2(t))),2===e&&(e=4)),e}getSampleCountRenderContext(t){return null!==t.textures?this.getSampleCount(t.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?FA.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const pP=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),mP=new Map([[gn,["float16"]]]),gP=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class fP{constructor(t){this.backend=t}createAttribute(t,e){const s=this._getBufferAttribute(t),i=this.backend,r=i.get(s);let n=r.buffer;if(void 0===n){const o=i.device;let a=s.array;if(!1===t.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const t=new Uint32Array(a.length);for(let e=0;e1},layout:u.createPipelineLayout({bindGroupLayouts:d})},A={},N=t.context.depth,C=t.context.stencil;if(!0!==N&&!0!==C||(!0===N&&(A.format=w,A.depthWriteEnabled=i.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=f,A.stencilBack={},A.stencilReadMask=i.stencilFuncMask,A.stencilWriteMask=i.stencilWriteMask),M.depthStencil=A),null===e)c.pipeline=u.createRenderPipeline(M);else{const t=new Promise((t=>{u.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t){const e=this.backend,{utils:s,device:i}=e,r=s.getCurrentDepthStencilFormat(t),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(t)],depthStencilFormat:r,sampleCount:this._getSampleCount(t)};return i.createRenderBundleEncoder(n)}createComputePipeline(t,e){const s=this.backend,i=s.device,r=s.get(t.computeProgram).module,n=s.get(t),o=[];for(const t of e){const e=s.get(t);o.push(e.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(t){let e,s;const i=t.blending,r=t.blendSrc,n=t.blendDst,o=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,a=null!==t.blendDstAlpha?t.blendDstAlpha:n,h=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(h)}}else{const r=(t,i,r,n)=>{e={srcFactor:t,dstFactor:i,operation:QA},s={srcFactor:r,dstFactor:n,operation:QA}};if(t.premultipliedAlpha)switch(i){case 1:r(kA,HA,kA,HA);break;case 2:r(kA,kA,kA,kA);break;case 3:r(DA,WA,DA,kA);break;case 4:r(DA,GA,DA,jA)}else switch(i){case 1:r(jA,HA,kA,HA);break;case 2:r(jA,kA,jA,kA);break;case 3:r(DA,WA,DA,kA);break;case 4:r(DA,GA,DA,GA)}}if(void 0!==e&&void 0!==s)return{color:e,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=DA;break;case 201:e=kA;break;case 202:e=GA;break;case 203:e=WA;break;case R:e=jA;break;case E:e=HA;break;case 208:e=$A;break;case 209:e=qA;break;case 206:e=XA;break;case 207:e=YA;break;case 210:e=ZA;break;case 211:e=JA;break;case 212:e=KA;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const s=t.stencilFunc;switch(s){case 512:e=yA;break;case gs:e=SA;break;case 513:e=xA;break;case 515:e=vA;break;case 514:e=bA;break;case 518:e=wA;break;case 516:e=TA;break;case 517:e=_A;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case es:e=oN;break;case 0:e=aN;break;case 7681:e=hN;break;case 5386:e=uN;break;case 7682:e=lN;break;case 7683:e=cN;break;case 34055:e=dN;break;case 34056:e=pN;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=QA;break;case 101:e=tN;break;case 102:e=eN;break;case 103:e=sN;break;case 104:e=iN;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,s),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?IA:PA),s.side){case c:i.frontFace=CA,i.cullMode=BA;break;case d:i.frontFace=CA,i.cullMode=EA;break;case 2:i.frontFace=CA,i.cullMode=RA;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?nN:rN}_getDepthCompare(t){let e;if(!1===t.depthTest)e=SA;else{const s=t.depthFunc;switch(s){case 0:e=yA;break;case 1:e=SA;break;case 2:e=xA;break;case 3:e=vA;break;case 4:e=bA;break;case 5:e=wA;break;case 6:e=TA;break;case 7:e=_A;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class bP extends wI{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.requiredLimits=void 0===t.requiredLimits?{}:t.requiredLimits,this.trackTimestamp=!0===t.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new dP(this),this.attributeUtils=new fP(this),this.bindingUtils=new yP(this),this.pipelineUtils=new xP(this),this.textureUtils=new ZI(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let s;if(void 0===e.device){const t={powerPreference:e.powerPreference},i=await navigator.gpu.requestAdapter(t);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(IN),n=[];for(const t of r)i.features.has(t)&&n.push(t);const o={requiredFeatures:n,requiredLimits:e.requiredLimits};s=await i.requestDevice(o)}else s=e.device;const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=s,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(IN.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Os}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;if(null===t){const e=this.renderer;t={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(t.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const s=t.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const e=t.colorAttachments[0];return this.renderer.samples>0?e.resolveTarget=this.context.getCurrentTexture().createView():e.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;if(void 0===i||s.width!==e.width||s.height!==e.height||s.activeMipmapLevel!==e.activeMipmapLevel||s.samples!==e.samples){i={},s.descriptors=i;const t=()=>{e.removeEventListener("dispose",t),this.delete(e)};e.addEventListener("dispose",t)}const r=t.getCacheKey();let n=i[r];if(void 0===n){const o=t.textures,a=[];for(let e=0;e0&&(e.currentOcclusionQuerySet&&e.currentOcclusionQuerySet.destroy(),e.currentOcclusionQueryBuffer&&e.currentOcclusionQueryBuffer.destroy(),e.currentOcclusionQuerySet=e.occlusionQuerySet,e.currentOcclusionQueryBuffer=e.occlusionQueryBuffer,e.currentOcclusionQueryObjects=e.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),n=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==t.textures){const e=n.colorAttachments;for(let s=0;s0&&e.currentPass.executeBundles(e.renderBundles),s>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),s>0){const i=8*s;let r=this.occludedResolveCache.get(i);void 0===r&&(r=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,r));const n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,s,r,0),e.encoder.copyBufferToBuffer(r,0,n,0,i),e.occlusionQueryBuffer=n,this.resolveOccludedAsync(t)}if(this.prepareTimestampBuffer(t,e.encoder),this.device.queue.submit([e.encoder.finish()]),null!==t.textures){const e=t.textures;for(let t=0;to?(h.x=Math.min(e.dispatchCount,o),h.y=Math.ceil(e.dispatchCount/o)):h.x=e.dispatchCount,r.dispatchWorkgroups(h.x,h.y,h.z)}finishCompute(t){const e=this.get(t);e.passEncoderGPU.end(),this.prepareTimestampBuffer(t,e.cmdEncoderGPU),this.device.queue.submit([e.cmdEncoderGPU.finish()])}draw(t,e){const{object:s,context:i,pipeline:r}=t,n=t.getBindings(),o=this.get(i),a=this.get(r).pipeline,h=o.currentSets,u=o.currentPass,l=t.getDrawParameters();if(null===l)return;h.pipeline!==a&&(u.setPipeline(a),h.pipeline=a);const c=h.bindingGroups;for(let t=0,e=n.length;t1?0:s;u.drawIndexed(e[s],i,t[s]/n,0,o)}}else if(!0===p){const{vertexCount:t,instanceCount:i,firstVertex:r}=l;u.drawIndexed(t,i,r,0,0),e.update(s,t,i)}else{const{vertexCount:t,instanceCount:i,firstVertex:r}=l;u.draw(t,i,r,0),e.update(s,t,i)}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCountRenderContext(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),u=r.getPrimitiveTopology(s,i);let l=!1;return e.material===i&&e.materialVersion===i.version&&e.transparent===i.transparent&&e.blending===i.blending&&e.premultipliedAlpha===i.premultipliedAlpha&&e.blendSrc===i.blendSrc&&e.blendDst===i.blendDst&&e.blendEquation===i.blendEquation&&e.blendSrcAlpha===i.blendSrcAlpha&&e.blendDstAlpha===i.blendDstAlpha&&e.blendEquationAlpha===i.blendEquationAlpha&&e.colorWrite===i.colorWrite&&e.depthWrite===i.depthWrite&&e.depthTest===i.depthTest&&e.depthFunc===i.depthFunc&&e.stencilWrite===i.stencilWrite&&e.stencilFunc===i.stencilFunc&&e.stencilFail===i.stencilFail&&e.stencilZFail===i.stencilZFail&&e.stencilZPass===i.stencilZPass&&e.stencilFuncMask===i.stencilFuncMask&&e.stencilWriteMask===i.stencilWriteMask&&e.side===i.side&&e.alphaToCoverage===i.alphaToCoverage&&e.sampleCount===n&&e.colorSpace===o&&e.colorFormat===a&&e.depthStencilFormat===h&&e.primitiveTopology===u&&e.clippingContextCacheKey===t.clippingContext.cacheKey||(e.material=i,e.materialVersion=i.version,e.transparent=i.transparent,e.blending=i.blending,e.premultipliedAlpha=i.premultipliedAlpha,e.blendSrc=i.blendSrc,e.blendDst=i.blendDst,e.blendEquation=i.blendEquation,e.blendSrcAlpha=i.blendSrcAlpha,e.blendDstAlpha=i.blendDstAlpha,e.blendEquationAlpha=i.blendEquationAlpha,e.colorWrite=i.colorWrite,e.depthWrite=i.depthWrite,e.depthTest=i.depthTest,e.depthFunc=i.depthFunc,e.stencilWrite=i.stencilWrite,e.stencilFunc=i.stencilFunc,e.stencilFail=i.stencilFail,e.stencilZFail=i.stencilZFail,e.stencilZPass=i.stencilZPass,e.stencilFuncMask=i.stencilFuncMask,e.stencilWriteMask=i.stencilWriteMask,e.side=i.side,e.alphaToCoverage=i.alphaToCoverage,e.sampleCount=n,e.colorSpace=o,e.colorFormat=a,e.depthStencilFormat=h,e.primitiveTopology=u,e.clippingContextCacheKey=t.clippingContext.cacheKey,l=!0),l}getRenderCacheKey(t){const{object:e,material:s}=t,i=this.utils,r=t.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContext.cacheKey].join()}createSampler(t){this.textureUtils.createSampler(t)}destroySampler(t){this.textureUtils.destroySampler(t)}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r,n){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r,n)}initTimestampQuery(t,e){if(!this.trackTimestamp)return;const s=this.get(t);if(!s.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),s.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.trackTimestamp)return;const s=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:r,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(e.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.trackTimestamp)return;const s=this.get(t);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=s.currentTimestampQueryBuffers;!0!==r&&(s.currentTimestampQueryBuffers.isMappingPending=!0,i.mapAsync(GPUMapMode.READ).then((()=>{const t=new BigUint64Array(i.getMappedRange()),r=Number(t[1]-t[0])/1e6;this.renderer.info.updateTimestamp(e,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new cP(t,e)}createProgram(t){this.get(t).module={module:this.device.createShaderModule({code:t.code,label:t.stage}),entryPoint:"main"}}destroyProgram(t){this.delete(t)}createRenderPipeline(t,e){this.pipelineUtils.createRenderPipeline(t,e)}createComputePipeline(t,e){this.pipelineUtils.createComputePipeline(t,e)}beginBundle(t){const e=this.get(t);e._currentPass=e.currentPass,e._currentSets=e.currentSets,e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},e.currentPass=this.pipelineUtils.createBundleEncoder(t)}finishBundle(t,e){const s=this.get(t),i=s.currentPass.finish();this.get(e).bundleGPU=i,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(t,e){this.get(t).renderBundles.push(this.get(e).bundleGPU)}createBindings(t){this.bindingUtils.createBindings(t)}updateBindings(t){this.bindingUtils.createBindings(t)}updateBinding(t){this.bindingUtils.updateBinding(t)}createIndexAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(t){return this.device.features.has(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=0,l=0,c=t.image.width,d=t.image.height;null!==s&&(h=s.x,u=s.y,l=s.z||0,c=s.width,d=s.height),null!==i&&(n=i.x,o=i.y,a=i.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),m=this.get(t).texture,g=this.get(e).texture;p.copyTextureToTexture({texture:m,mipLevel:r,origin:{x:h,y:u,z:l}},{texture:g,mipLevel:r,origin:{x:n,y:o,z:a}},[c,d,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(t,e,s){const i=this.get(e),{encoder:r,descriptor:n}=i;let o=null;o=e.renderTarget?t.isDepthTexture?this.get(e.depthTexture).texture:this.get(e.textures[0]).texture:t.isDepthTexture?this.textureUtils.getDepthBuffer(e.depth,e.stencil):this.context.getCurrentTexture();const a=this.get(t).texture;if(o.format===a.format){i.currentPass.end(),r.copyTextureToTexture({texture:o,origin:{x:s.x,y:s.y,z:0}},{texture:a},[s.z,s.w]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t);for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new kI(t)));super(new e(t),t),this.nodes.library=new TP,this.isWebGPURenderer=!0}}const wP=new cT,SP=new tA(wP);class MP{constructor(t,e=Hp(0,0,1,1)){this.renderer=t,this.outputNode=e,this.outputColorTransform=!0,this.needsUpdate=!0,wP.name="PostProcessing"}render(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Je,SP.render(t),t.toneMapping=e,t.outputColorSpace=s}update(){if(!0===this.needsUpdate){const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;SP.material.fragmentNode=!0===this.outputColorTransform?by(this.outputNode,e,s):this.outputNode.context({toneMapping:e,outputColorSpace:s}),SP.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Je,await SP.renderAsync(t),t.toneMapping=e,t.outputColorSpace=s}}class AP extends yi{constructor(t=1,e=1){super(),this.image={width:t,height:e},this.magFilter=Tt,this.minFilter=Tt,this.isStorageTexture=!0}}class NP extends an{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageBufferAttribute=!0}}class CP extends zo{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageInstancedBufferAttribute=!0}}class RP extends Ku{constructor(t){super(t),this.textures={},this.nodes={}}load(t,e,s,i){const r=new el(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(s=>{try{e(this.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),s,i)}parseNodes(t){const e={};if(void 0!==t){for(const s of t){const{uuid:t,type:i}=s;e[t]=this.createNodeFromType(i),e[t].uuid=t}const s={nodes:e,textures:this.textures};for(const i of t){i.meta=s;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=this.createNodeFromType(t.type);e.uuid=t.uuid;const s={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=s,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),Pp()):Tp(new this.nodes[t])}}class EP extends Cl{constructor(t){super(t),this.nodes={},this.nodeMaterials={}}parse(t){const e=super.parse(t),s=this.nodes,i=t.inputNodes;for(const t in i){const r=i[t];e[t]=s[r]}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 BP extends Il{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 s=super.parse(t,e);return this._nodesJSON=null,s}parseNodes(t,e){if(void 0!==t){const s=new RP;return s.setNodes(this.nodes),s.setTextures(e),s.parseNodes(t)}return{}}parseMaterials(t,e){const s={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),r=new EP;r.setTextures(e),r.setNodes(i),r.setNodeMaterials(this.nodeMaterials);for(let e=0,i=t.length;e