- WordPress durch Next.js 16 + Tailwind CSS v4 + Framer Motion ersetzt - 44 Guides + 15 Seiten aus WordPress migriert (HTML -> Markdown) - Emerald Design-System mit Light/Dark Mode Toggle - Sidebar-First Navigation (Dokumentations-Stil) - Difficulty-Badges, Lesezeit, verwandte Guides - Statischer Export fuer Plesk-Hosting - WordPress-DB Backup gesichert (6.2 MB) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
442 lines
790 KiB
JavaScript
442 lines
790 KiB
JavaScript
var $0=0,q0=1,H0=2;var X0=0,ap=1,Y0=2,Wr=3,_s=0,rt=1,$s=2,qs=0,Ht=1,zn=2,Gn=3,Wn=4,$n=5,eu=6,Xt=100,cp=101,lp=102,j0=103,Z0=104,Ni=200,up=201,hp=202,dp=203,Ir=204,Pr=205,pp=206,fp=207,mp=208,gp=209,yp=210;var Oo=0,Vo=1,ko=2,In=3,zo=4,Go=5,Wo=6,$o=7,aa=0,J0=1,Q0=2,Ri=0,K0=1,eb=2,tb=3,sb=4;var ib=6,nb=7;var tu=300,qn=301,ca=302,su=303,iu=304,nu=306,Pn=1e3,bs=1001,Dn=1002,Ue=1003,xp=1004;var $r=1005;var ct=1006,ru=1007;var Ci=1008,rb=1008,lt=1009,Hn=1010,Xn=1011,rn=1012,ut=1013,Oe=1014,Ct=1015,$e=1016,bp=1017,_p=1018,Ei=1020,ou=35902,au=35899,Tp=1021,la=1022,Lt=1023,ns=1026,Hs=1027,ua=1028,ha=1029,Ms=1030,da=1031,ob=1032,pa=1033,qr=33776,Hr=33777,Xr=33778,Yr=33779,cu=35840,lu=35841,uu=35842,hu=35843,fa=36196,ma=37492,ga=37496,ya=37488,xa=37489,jr=37490,ba=37491,_a=37808,Ta=37809,Sa=37810,va=37811,wa=37812,Ma=37813,Aa=37814,Na=37815,Ra=37816,Ca=37817,Ea=37818,Ba=37819,Fa=37820,Ia=37821,Pa=36492,ab=36494,cb=36495,Da=36283,La=36284,Zr=36285,Ua=36286;var qo=2300,ul=2301,cl=2302,Kd=2303,ep=2400,tp=2401,sp=2402;var Xs=0,lb=1,Bi="",Pt="srgb",Ho="srgb-linear",Xo="linear",ne="srgb",du="",Sp="rg",ub="ga",hb=0,Qi=7680,db=7681,pb=7682,fb=7683,mb=34055,gb=34056,yb=5386,xb=512,bb=513,_b=514,Tb=515,Sb=516,vb=517,wb=518,hl=519,vp=512,pu=513,wp=514,Jr=515,Oa=516,Mp=517,Yn=518,Ap=519,Ln=35044,Qr=35048;var Dt=2e3,Yt=2001,As={COMPUTE:"compute",RENDER:"render"};var Ys={TEXTURE_COMPARE:"depthTextureCompare"};function d1(o){for(let e=o.length-1;e>=0;--e)if(o[e]>=65535)return!0;return!1}function Kr(o){return ArrayBuffer.isView(o)&&!(o instanceof DataView)}function dl(o){return document.createElementNS("http://www.w3.org/1999/xhtml",o)}function Mb(){let o=dl("canvas");return o.style.display="block",o}var v0={},Dr=null;function pl(...o){let e="THREE."+o.shift();Dr?Dr("log",e,...o):console.log(e,...o)}function Ab(o){let e=o[0];if(typeof e=="string"&&e.startsWith("TSL:")){let t=o[1];t&&t.isStackTrace?o[0]+=" "+t.getLocation():o[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return o}function z(...o){o=Ab(o);let e="THREE."+o.shift();if(Dr)Dr("warn",e,...o);else{let t=o[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...o)}}function O(...o){o=Ab(o);let e="THREE."+o.shift();if(Dr)Dr("error",e,...o);else{let t=o[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...o)}}function _e(...o){let e=o.join(" ");e in v0||(v0[e]=!0,z(...o))}var Np={[Oo]:Vo,[ko]:Wo,[zo]:$o,[In]:Go,[Vo]:Oo,[Wo]:ko,[$o]:zo,[Go]:In},Ts=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let s=this._listeners;s[e]===void 0&&(s[e]=[]),s[e].indexOf(t)===-1&&s[e].push(t)}hasEventListener(e,t){let s=this._listeners;return s===void 0?!1:s[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){let s=this._listeners;if(s===void 0)return;let i=s[e];if(i!==void 0){let n=i.indexOf(t);n!==-1&&i.splice(n,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let s=t[e.type];if(s!==void 0){e.target=this;let i=s.slice(0);for(let n=0,r=i.length;n<r;n++)i[n].call(this,e);e.target=null}}},mt=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],w0=1234567,Lo=Math.PI/180,Un=180/Math.PI;function wi(){let o=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(mt[o&255]+mt[o>>8&255]+mt[o>>16&255]+mt[o>>24&255]+"-"+mt[e&255]+mt[e>>8&255]+"-"+mt[e>>16&15|64]+mt[e>>24&255]+"-"+mt[t&63|128]+mt[t>>8&255]+"-"+mt[t>>16&255]+mt[t>>24&255]+mt[s&255]+mt[s>>8&255]+mt[s>>16&255]+mt[s>>24&255]).toLowerCase()}function ue(o,e,t){return Math.max(e,Math.min(t,o))}function Rp(o,e){return(o%e+e)%e}function p1(o,e,t,s,i){return s+(o-e)*(i-s)/(t-e)}function f1(o,e,t){return o!==e?(t-o)/(e-o):0}function Uo(o,e,t){return(1-t)*o+t*e}function m1(o,e,t,s){return Uo(o,e,1-Math.exp(-t*s))}function g1(o,e=1){return e-Math.abs(Rp(o,e*2)-e)}function y1(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*(3-2*o))}function x1(o,e,t){return o<=e?0:o>=t?1:(o=(o-e)/(t-e),o*o*o*(o*(o*6-15)+10))}function b1(o,e){return o+Math.floor(Math.random()*(e-o+1))}function _1(o,e){return o+Math.random()*(e-o)}function T1(o){return o*(.5-Math.random())}function S1(o){o!==void 0&&(w0=o);let e=w0+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function v1(o){return o*Lo}function w1(o){return o*Un}function M1(o){return(o&o-1)===0&&o!==0}function A1(o){return Math.pow(2,Math.ceil(Math.log(o)/Math.LN2))}function N1(o){return Math.pow(2,Math.floor(Math.log(o)/Math.LN2))}function R1(o,e,t,s,i){let n=Math.cos,r=Math.sin,a=n(t/2),c=r(t/2),l=n((e+s)/2),u=r((e+s)/2),h=n((e-s)/2),d=r((e-s)/2),p=n((s-e)/2),m=r((s-e)/2);switch(i){case"XYX":o.set(a*u,c*h,c*d,a*l);break;case"YZY":o.set(c*d,a*u,c*h,a*l);break;case"ZXZ":o.set(c*h,c*d,a*u,a*l);break;case"XZX":o.set(a*u,c*m,c*p,a*l);break;case"YXY":o.set(c*p,a*u,c*m,a*l);break;case"ZYZ":o.set(c*m,c*p,a*u,a*l);break;default:z("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function At(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return o/4294967295;case Uint16Array:return o/65535;case Uint8Array:return o/255;case Int32Array:return Math.max(o/2147483647,-1);case Int16Array:return Math.max(o/32767,-1);case Int8Array:return Math.max(o/127,-1);default:throw new Error("Invalid component type.")}}function ce(o,e){switch(e.constructor){case Float32Array:return o;case Uint32Array:return Math.round(o*4294967295);case Uint16Array:return Math.round(o*65535);case Uint8Array:return Math.round(o*255);case Int32Array:return Math.round(o*2147483647);case Int16Array:return Math.round(o*32767);case Int8Array:return Math.round(o*127);default:throw new Error("Invalid component type.")}}var Va={DEG2RAD:Lo,RAD2DEG:Un,generateUUID:wi,clamp:ue,euclideanModulo:Rp,mapLinear:p1,inverseLerp:f1,lerp:Uo,damp:m1,pingpong:g1,smoothstep:y1,smootherstep:x1,randInt:b1,randFloat:_1,randFloatSpread:T1,seededRandom:S1,degToRad:v1,radToDeg:w1,isPowerOfTwo:M1,ceilPowerOfTwo:A1,floorPowerOfTwo:N1,setQuaternionFromProperEuler:R1,normalize:ce,denormalize:At},re=class o{constructor(e=0,t=0){o.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,s=this.y,i=e.elements;return this.x=i[0]*t+i[3]*s+i[6],this.y=i[1]*t+i[4]*s+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ue(this.x,e.x,t.x),this.y=ue(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ue(this.x,e,t),this.y=ue(this.y,e,t),this}clampLength(e,t){let s=this.length();return this.divideScalar(s||1).multiplyScalar(ue(s,e,t))}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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let s=this.dot(e)/t;return Math.acos(ue(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,s=this.y-e.y;return t*t+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let s=Math.cos(t),i=Math.sin(t),n=this.x-e.x,r=this.y-e.y;return this.x=n*s-r*i+e.x,this.y=n*i+r*s+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Ss=class{constructor(e=0,t=0,s=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=s,this._w=i}static slerpFlat(e,t,s,i,n,r,a){let c=s[i+0],l=s[i+1],u=s[i+2],h=s[i+3],d=n[r+0],p=n[r+1],m=n[r+2],g=n[r+3];if(h!==g||c!==d||l!==p||u!==m){let y=c*d+l*p+u*m+h*g;y<0&&(d=-d,p=-p,m=-m,g=-g,y=-y);let x=1-a;if(y<.9995){let _=Math.acos(y),w=Math.sin(_);x=Math.sin(x*_)/w,a=Math.sin(a*_)/w,c=c*x+d*a,l=l*x+p*a,u=u*x+m*a,h=h*x+g*a}else{c=c*x+d*a,l=l*x+p*a,u=u*x+m*a,h=h*x+g*a;let _=1/Math.sqrt(c*c+l*l+u*u+h*h);c*=_,l*=_,u*=_,h*=_}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,s,i,n,r){let a=s[i],c=s[i+1],l=s[i+2],u=s[i+3],h=n[r],d=n[r+1],p=n[r+2],m=n[r+3];return e[t]=a*m+u*h+c*p-l*d,e[t+1]=c*m+u*d+l*h-a*p,e[t+2]=l*m+u*p+a*d-c*h,e[t+3]=u*m-a*h-c*d-l*p,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,s,i){return this._x=e,this._y=t,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let s=e._x,i=e._y,n=e._z,r=e._order,a=Math.cos,c=Math.sin,l=a(s/2),u=a(i/2),h=a(n/2),d=c(s/2),p=c(i/2),m=c(n/2);switch(r){case"XYZ":this._x=d*u*h+l*p*m,this._y=l*p*h-d*u*m,this._z=l*u*m+d*p*h,this._w=l*u*h-d*p*m;break;case"YXZ":this._x=d*u*h+l*p*m,this._y=l*p*h-d*u*m,this._z=l*u*m-d*p*h,this._w=l*u*h+d*p*m;break;case"ZXY":this._x=d*u*h-l*p*m,this._y=l*p*h+d*u*m,this._z=l*u*m+d*p*h,this._w=l*u*h-d*p*m;break;case"ZYX":this._x=d*u*h-l*p*m,this._y=l*p*h+d*u*m,this._z=l*u*m-d*p*h,this._w=l*u*h+d*p*m;break;case"YZX":this._x=d*u*h+l*p*m,this._y=l*p*h+d*u*m,this._z=l*u*m-d*p*h,this._w=l*u*h-d*p*m;break;case"XZY":this._x=d*u*h-l*p*m,this._y=l*p*h-d*u*m,this._z=l*u*m+d*p*h,this._w=l*u*h+d*p*m;break;default:z("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let s=t/2,i=Math.sin(s);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,s=t[0],i=t[4],n=t[8],r=t[1],a=t[5],c=t[9],l=t[2],u=t[6],h=t[10],d=s+a+h;if(d>0){let p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(u-c)*p,this._y=(n-l)*p,this._z=(r-i)*p}else if(s>a&&s>h){let p=2*Math.sqrt(1+s-a-h);this._w=(u-c)/p,this._x=.25*p,this._y=(i+r)/p,this._z=(n+l)/p}else if(a>h){let p=2*Math.sqrt(1+a-s-h);this._w=(n-l)/p,this._x=(i+r)/p,this._y=.25*p,this._z=(c+u)/p}else{let p=2*Math.sqrt(1+h-s-a);this._w=(r-i)/p,this._x=(n+l)/p,this._y=(c+u)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let s=e.dot(t)+1;return s<1e-8?(s=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=s):(this._x=0,this._y=-e.z,this._z=e.y,this._w=s)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=s),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ue(this.dot(e),-1,1)))}rotateTowards(e,t){let s=this.angleTo(e);if(s===0)return this;let i=Math.min(1,t/s);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let s=e._x,i=e._y,n=e._z,r=e._w,a=t._x,c=t._y,l=t._z,u=t._w;return this._x=s*u+r*a+i*l-n*c,this._y=i*u+r*c+n*a-s*l,this._z=n*u+r*l+s*c-i*a,this._w=r*u-s*a-i*c-n*l,this._onChangeCallback(),this}slerp(e,t){let s=e._x,i=e._y,n=e._z,r=e._w,a=this.dot(e);a<0&&(s=-s,i=-i,n=-n,r=-r,a=-a);let c=1-t;if(a<.9995){let l=Math.acos(a),u=Math.sin(l);c=Math.sin(c*l)/u,t=Math.sin(t*l)/u,this._x=this._x*c+s*t,this._y=this._y*c+i*t,this._z=this._z*c+n*t,this._w=this._w*c+r*t,this._onChangeCallback()}else this._x=this._x*c+s*t,this._y=this._y*c+i*t,this._z=this._z*c+n*t,this._w=this._w*c+r*t,this.normalize();return this}slerpQuaternions(e,t,s){return this.copy(e).slerp(t,s)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),n=Math.sqrt(s);return this.set(i*Math.sin(e),i*Math.cos(e),n*Math.sin(t),n*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},R=class o{constructor(e=0,t=0,s=0){o.prototype.isVector3=!0,this.x=e,this.y=t,this.z=s}set(e,t,s){return s===void 0&&(s=this.z),this.x=e,this.y=t,this.z=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(M0.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(M0.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,s=this.y,i=this.z,n=e.elements;return this.x=n[0]*t+n[3]*s+n[6]*i,this.y=n[1]*t+n[4]*s+n[7]*i,this.z=n[2]*t+n[5]*s+n[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,s=this.y,i=this.z,n=e.elements,r=1/(n[3]*t+n[7]*s+n[11]*i+n[15]);return this.x=(n[0]*t+n[4]*s+n[8]*i+n[12])*r,this.y=(n[1]*t+n[5]*s+n[9]*i+n[13])*r,this.z=(n[2]*t+n[6]*s+n[10]*i+n[14])*r,this}applyQuaternion(e){let t=this.x,s=this.y,i=this.z,n=e.x,r=e.y,a=e.z,c=e.w,l=2*(r*i-a*s),u=2*(a*t-n*i),h=2*(n*s-r*t);return this.x=t+c*l+r*h-a*u,this.y=s+c*u+a*l-n*h,this.z=i+c*h+n*u-r*l,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,s=this.y,i=this.z,n=e.elements;return this.x=n[0]*t+n[4]*s+n[8]*i,this.y=n[1]*t+n[5]*s+n[9]*i,this.z=n[2]*t+n[6]*s+n[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ue(this.x,e.x,t.x),this.y=ue(this.y,e.y,t.y),this.z=ue(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ue(this.x,e,t),this.y=ue(this.y,e,t),this.z=ue(this.z,e,t),this}clampLength(e,t){let s=this.length();return this.divideScalar(s||1).multiplyScalar(ue(s,e,t))}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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let s=e.x,i=e.y,n=e.z,r=t.x,a=t.y,c=t.z;return this.x=i*c-n*a,this.y=n*r-s*c,this.z=s*a-i*r,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let s=e.dot(this)/t;return this.copy(e).multiplyScalar(s)}projectOnPlane(e){return Bd.copy(this).projectOnVector(e),this.sub(Bd)}reflect(e){return this.sub(Bd.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let s=this.dot(e)/t;return Math.acos(ue(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,s=this.y-e.y,i=this.z-e.z;return t*t+s*s+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,s){let i=Math.sin(t)*e;return this.x=i*Math.sin(s),this.y=Math.cos(t)*e,this.z=i*Math.cos(s),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,s){return this.x=e*Math.sin(t),this.y=s,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),s=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=s,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,s=Math.sqrt(1-t*t);return this.x=s*Math.cos(e),this.y=t,this.z=s*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Bd=new R,M0=new Ss,Nt=class o{constructor(e,t,s,i,n,r,a,c,l){o.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,s,i,n,r,a,c,l)}set(e,t,s,i,n,r,a,c,l){let u=this.elements;return u[0]=e,u[1]=i,u[2]=a,u[3]=t,u[4]=n,u[5]=c,u[6]=s,u[7]=r,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],this}extractBasis(e,t,s){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let s=e.elements,i=t.elements,n=this.elements,r=s[0],a=s[3],c=s[6],l=s[1],u=s[4],h=s[7],d=s[2],p=s[5],m=s[8],g=i[0],y=i[3],x=i[6],_=i[1],w=i[4],S=i[7],E=i[2],B=i[5],N=i[8];return n[0]=r*g+a*_+c*E,n[3]=r*y+a*w+c*B,n[6]=r*x+a*S+c*N,n[1]=l*g+u*_+h*E,n[4]=l*y+u*w+h*B,n[7]=l*x+u*S+h*N,n[2]=d*g+p*_+m*E,n[5]=d*y+p*w+m*B,n[8]=d*x+p*S+m*N,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],a=e[5],c=e[6],l=e[7],u=e[8];return t*r*u-t*a*l-s*n*u+s*a*c+i*n*l-i*r*c}invert(){let e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=u*r-a*l,d=a*c-u*n,p=l*n-r*c,m=t*h+s*d+i*p;if(m===0)return this.set(0,0,0,0,0,0,0,0,0);let g=1/m;return e[0]=h*g,e[1]=(i*l-u*s)*g,e[2]=(a*s-i*r)*g,e[3]=d*g,e[4]=(u*t-i*c)*g,e[5]=(i*n-a*t)*g,e[6]=p*g,e[7]=(s*c-l*t)*g,e[8]=(r*t-s*n)*g,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,s,i,n,r,a){let c=Math.cos(n),l=Math.sin(n);return this.set(s*c,s*l,-s*(c*r+l*a)+r+e,-i*l,i*c,-i*(-l*r+c*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(Fd.makeScale(e,t)),this}rotate(e){return this.premultiply(Fd.makeRotation(-e)),this}translate(e,t){return this.premultiply(Fd.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,s,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,s=e.elements;for(let i=0;i<9;i++)if(t[i]!==s[i])return!1;return!0}fromArray(e,t=0){for(let s=0;s<9;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){let s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e}clone(){return new this.constructor().fromArray(this.elements)}},Fd=new Nt,A0=new Nt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),N0=new Nt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function C1(){let o={enabled:!0,workingColorSpace:Ho,spaces:{},convert:function(i,n,r){return this.enabled===!1||n===r||!n||!r||(this.spaces[n].transfer===ne&&(i.r=Mi(i.r),i.g=Mi(i.g),i.b=Mi(i.b)),this.spaces[n].primaries!==this.spaces[r].primaries&&(i.applyMatrix3(this.spaces[n].toXYZ),i.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===ne&&(i.r=Fr(i.r),i.g=Fr(i.g),i.b=Fr(i.b))),i},workingToColorSpace:function(i,n){return this.convert(i,this.workingColorSpace,n)},colorSpaceToWorking:function(i,n){return this.convert(i,n,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===Bi?Xo:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,n=this.workingColorSpace){return i.fromArray(this.spaces[n].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,n,r){return i.copy(this.spaces[n].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,n){return _e("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),o.workingToColorSpace(i,n)},toWorkingColorSpace:function(i,n){return _e("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),o.colorSpaceToWorking(i,n)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],s=[.3127,.329];return o.define({[Ho]:{primaries:e,whitePoint:s,transfer:Xo,toXYZ:A0,fromXYZ:N0,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:Pt},outputColorSpaceConfig:{drawingBufferColorSpace:Pt}},[Pt]:{primaries:e,whitePoint:s,transfer:ne,toXYZ:A0,fromXYZ:N0,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:Pt}}}),o}var me=C1();function Mi(o){return o<.04045?o*.0773993808:Math.pow(o*.9478672986+.0521327014,2.4)}function Fr(o){return o<.0031308?o*12.92:1.055*Math.pow(o,.41666)-.055}var br,fl=class{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let s;if(e instanceof HTMLCanvasElement)s=e;else{br===void 0&&(br=dl("canvas")),br.width=e.width,br.height=e.height;let i=br.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),s=br}return s.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){let t=dl("canvas");t.width=e.width,t.height=e.height;let s=t.getContext("2d");s.drawImage(e,0,0,e.width,e.height);let i=s.getImageData(0,0,e.width,e.height),n=i.data;for(let r=0;r<n.length;r++)n[r]=Mi(n[r]/255)*255;return s.putImageData(i,0,0),t}else if(e.data){let t=e.data.slice(0);for(let s=0;s<t.length;s++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[s]=Math.floor(Mi(t[s]/255)*255):t[s]=Mi(t[s]);return{data:t,width:e.width,height:e.height}}else return z("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}},E1=0,Lr=class{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:E1++}),this.uuid=wi(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayHeight,t.displayWidth,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let s={uuid:this.uuid,url:""},i=this.data;if(i!==null){let n;if(Array.isArray(i)){n=[];for(let r=0,a=i.length;r<a;r++)i[r].isDataTexture?n.push(Id(i[r].image)):n.push(Id(i[r]))}else n=Id(i);s.url=n}return t||(e.images[this.uuid]=s),s}};function Id(o){return typeof HTMLImageElement<"u"&&o instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&o instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&o instanceof ImageBitmap?fl.getDataURL(o):o.data?{data:Array.from(o.data),width:o.width,height:o.height,type:o.data.constructor.name}:(z("Texture: Unable to serialize Texture."),{})}var B1=0,Pd=new R,xt=class o extends Ts{constructor(e=o.DEFAULT_IMAGE,t=o.DEFAULT_MAPPING,s=bs,i=bs,n=ct,r=Ci,a=Lt,c=lt,l=o.DEFAULT_ANISOTROPY,u=Bi){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:B1++}),this.uuid=wi(),this.name="",this.source=new Lr(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=n,this.minFilter=r,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=c,this.offset=new re(0,0),this.repeat=new re(1,1),this.center=new re(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Nt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(Pd).x}get height(){return this.source.getSize(Pd).y}get depth(){return this.source.getSize(Pd).z}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(let t in e){let s=e[t];if(s===void 0){z(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){z(`Texture.setValues(): property '${t}' does not exist.`);continue}i&&s&&i.isVector2&&s.isVector2||i&&s&&i.isVector3&&s.isVector3||i&&s&&i.isMatrix3&&s.isMatrix3?i.copy(s):this[t]=s}}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let s={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),t||(e.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==tu)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Pn:e.x=e.x-Math.floor(e.x);break;case bs:e.x=e.x<0?0:1;break;case Dn:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Pn:e.y=e.y-Math.floor(e.y);break;case bs:e.y=e.y<0?0:1;break;case Dn:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};xt.DEFAULT_IMAGE=null;xt.DEFAULT_MAPPING=tu;xt.DEFAULT_ANISOTROPY=1;var Te=class o{constructor(e=0,t=0,s=0,i=1){o.prototype.isVector4=!0,this.x=e,this.y=t,this.z=s,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,s,i){return this.x=e,this.y=t,this.z=s,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,s=this.y,i=this.z,n=this.w,r=e.elements;return this.x=r[0]*t+r[4]*s+r[8]*i+r[12]*n,this.y=r[1]*t+r[5]*s+r[9]*i+r[13]*n,this.z=r[2]*t+r[6]*s+r[10]*i+r[14]*n,this.w=r[3]*t+r[7]*s+r[11]*i+r[15]*n,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,s,i,n,c=e.elements,l=c[0],u=c[4],h=c[8],d=c[1],p=c[5],m=c[9],g=c[2],y=c[6],x=c[10];if(Math.abs(u-d)<.01&&Math.abs(h-g)<.01&&Math.abs(m-y)<.01){if(Math.abs(u+d)<.1&&Math.abs(h+g)<.1&&Math.abs(m+y)<.1&&Math.abs(l+p+x-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;let w=(l+1)/2,S=(p+1)/2,E=(x+1)/2,B=(u+d)/4,N=(h+g)/4,C=(m+y)/4;return w>S&&w>E?w<.01?(s=0,i=.707106781,n=.707106781):(s=Math.sqrt(w),i=B/s,n=N/s):S>E?S<.01?(s=.707106781,i=0,n=.707106781):(i=Math.sqrt(S),s=B/i,n=C/i):E<.01?(s=.707106781,i=.707106781,n=0):(n=Math.sqrt(E),s=N/n,i=C/n),this.set(s,i,n,t),this}let _=Math.sqrt((y-m)*(y-m)+(h-g)*(h-g)+(d-u)*(d-u));return Math.abs(_)<.001&&(_=1),this.x=(y-m)/_,this.y=(h-g)/_,this.z=(d-u)/_,this.w=Math.acos((l+p+x-1)/2),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ue(this.x,e.x,t.x),this.y=ue(this.y,e.y,t.y),this.z=ue(this.z,e.z,t.z),this.w=ue(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ue(this.x,e,t),this.y=ue(this.y,e,t),this.z=ue(this.z,e,t),this.w=ue(this.w,e,t),this}clampLength(e,t){let s=this.length();return this.divideScalar(s||1).multiplyScalar(ue(s,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this.w=e.w+(t.w-e.w)*s,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},bt=class extends Ts{constructor(e=1,t=1,s={}){super(),s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:ct,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},s),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=s.depth,this.scissor=new Te(0,0,e,t),this.scissorTest=!1,this.viewport=new Te(0,0,e,t),this.textures=[];let i={width:e,height:t,depth:s.depth},n=new xt(i),r=s.count;for(let a=0;a<r;a++)this.textures[a]=n.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(s),this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=s.depthTexture,this.samples=s.samples,this.multiview=s.multiview}_setTextureOptions(e={}){let t={minFilter:ct,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let s=0;s<this.textures.length;s++)this.textures[s].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,s=1){if(this.width!==e||this.height!==t||this.depth!==s){this.width=e,this.height=t,this.depth=s;for(let i=0,n=this.textures.length;i<n;i++)this.textures[i].image.width=e,this.textures[i].image.height=t,this.textures[i].image.depth=s,this.textures[i].isData3DTexture!==!0&&(this.textures[i].isArrayTexture=this.textures[i].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,s=e.textures.length;t<s;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;let i=Object.assign({},e.textures[t].image);this.textures[t].source=new Lr(i)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}};var ml=class extends xt{constructor(e=null,t=1,s=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:s,depth:i},this.magFilter=Ue,this.minFilter=Ue,this.wrapR=bs,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}};var de=class o{constructor(e,t,s,i,n,r,a,c,l,u,h,d,p,m,g,y){o.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,s,i,n,r,a,c,l,u,h,d,p,m,g,y)}set(e,t,s,i,n,r,a,c,l,u,h,d,p,m,g,y){let x=this.elements;return x[0]=e,x[4]=t,x[8]=s,x[12]=i,x[1]=n,x[5]=r,x[9]=a,x[13]=c,x[2]=l,x[6]=u,x[10]=h,x[14]=d,x[3]=p,x[7]=m,x[11]=g,x[15]=y,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 o().fromArray(this.elements)}copy(e){let t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],t[9]=s[9],t[10]=s[10],t[11]=s[11],t[12]=s[12],t[13]=s[13],t[14]=s[14],t[15]=s[15],this}copyPosition(e){let t=this.elements,s=e.elements;return t[12]=s[12],t[13]=s[13],t[14]=s[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,s){return this.determinant()===0?(e.set(1,0,0),t.set(0,1,0),s.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(e,t,s){return this.set(e.x,t.x,s.x,0,e.y,t.y,s.y,0,e.z,t.z,s.z,0,0,0,0,1),this}extractRotation(e){if(e.determinant()===0)return this.identity();let t=this.elements,s=e.elements,i=1/_r.setFromMatrixColumn(e,0).length(),n=1/_r.setFromMatrixColumn(e,1).length(),r=1/_r.setFromMatrixColumn(e,2).length();return t[0]=s[0]*i,t[1]=s[1]*i,t[2]=s[2]*i,t[3]=0,t[4]=s[4]*n,t[5]=s[5]*n,t[6]=s[6]*n,t[7]=0,t[8]=s[8]*r,t[9]=s[9]*r,t[10]=s[10]*r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,s=e.x,i=e.y,n=e.z,r=Math.cos(s),a=Math.sin(s),c=Math.cos(i),l=Math.sin(i),u=Math.cos(n),h=Math.sin(n);if(e.order==="XYZ"){let d=r*u,p=r*h,m=a*u,g=a*h;t[0]=c*u,t[4]=-c*h,t[8]=l,t[1]=p+m*l,t[5]=d-g*l,t[9]=-a*c,t[2]=g-d*l,t[6]=m+p*l,t[10]=r*c}else if(e.order==="YXZ"){let d=c*u,p=c*h,m=l*u,g=l*h;t[0]=d+g*a,t[4]=m*a-p,t[8]=r*l,t[1]=r*h,t[5]=r*u,t[9]=-a,t[2]=p*a-m,t[6]=g+d*a,t[10]=r*c}else if(e.order==="ZXY"){let d=c*u,p=c*h,m=l*u,g=l*h;t[0]=d-g*a,t[4]=-r*h,t[8]=m+p*a,t[1]=p+m*a,t[5]=r*u,t[9]=g-d*a,t[2]=-r*l,t[6]=a,t[10]=r*c}else if(e.order==="ZYX"){let d=r*u,p=r*h,m=a*u,g=a*h;t[0]=c*u,t[4]=m*l-p,t[8]=d*l+g,t[1]=c*h,t[5]=g*l+d,t[9]=p*l-m,t[2]=-l,t[6]=a*c,t[10]=r*c}else if(e.order==="YZX"){let d=r*c,p=r*l,m=a*c,g=a*l;t[0]=c*u,t[4]=g-d*h,t[8]=m*h+p,t[1]=h,t[5]=r*u,t[9]=-a*u,t[2]=-l*u,t[6]=p*h+m,t[10]=d-g*h}else if(e.order==="XZY"){let d=r*c,p=r*l,m=a*c,g=a*l;t[0]=c*u,t[4]=-h,t[8]=l*u,t[1]=d*h+g,t[5]=r*u,t[9]=p*h-m,t[2]=m*h-p,t[6]=a*u,t[10]=g*h+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(F1,e,I1)}lookAt(e,t,s){let i=this.elements;return Wt.subVectors(e,t),Wt.lengthSq()===0&&(Wt.z=1),Wt.normalize(),Hi.crossVectors(s,Wt),Hi.lengthSq()===0&&(Math.abs(s.z)===1?Wt.x+=1e-4:Wt.z+=1e-4,Wt.normalize(),Hi.crossVectors(s,Wt)),Hi.normalize(),zc.crossVectors(Wt,Hi),i[0]=Hi.x,i[4]=zc.x,i[8]=Wt.x,i[1]=Hi.y,i[5]=zc.y,i[9]=Wt.y,i[2]=Hi.z,i[6]=zc.z,i[10]=Wt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let s=e.elements,i=t.elements,n=this.elements,r=s[0],a=s[4],c=s[8],l=s[12],u=s[1],h=s[5],d=s[9],p=s[13],m=s[2],g=s[6],y=s[10],x=s[14],_=s[3],w=s[7],S=s[11],E=s[15],B=i[0],N=i[4],C=i[8],I=i[12],k=i[1],W=i[5],X=i[9],Y=i[13],ee=i[2],Q=i[6],ie=i[10],Pe=i[14],Se=i[3],ae=i[7],fe=i[11],Fe=i[15];return n[0]=r*B+a*k+c*ee+l*Se,n[4]=r*N+a*W+c*Q+l*ae,n[8]=r*C+a*X+c*ie+l*fe,n[12]=r*I+a*Y+c*Pe+l*Fe,n[1]=u*B+h*k+d*ee+p*Se,n[5]=u*N+h*W+d*Q+p*ae,n[9]=u*C+h*X+d*ie+p*fe,n[13]=u*I+h*Y+d*Pe+p*Fe,n[2]=m*B+g*k+y*ee+x*Se,n[6]=m*N+g*W+y*Q+x*ae,n[10]=m*C+g*X+y*ie+x*fe,n[14]=m*I+g*Y+y*Pe+x*Fe,n[3]=_*B+w*k+S*ee+E*Se,n[7]=_*N+w*W+S*Q+E*ae,n[11]=_*C+w*X+S*ie+E*fe,n[15]=_*I+w*Y+S*Pe+E*Fe,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],s=e[4],i=e[8],n=e[12],r=e[1],a=e[5],c=e[9],l=e[13],u=e[2],h=e[6],d=e[10],p=e[14],m=e[3],g=e[7],y=e[11],x=e[15],_=c*p-l*d,w=a*p-l*h,S=a*d-c*h,E=r*p-l*u,B=r*d-c*u,N=r*h-a*u;return t*(g*_-y*w+x*S)-s*(m*_-y*E+x*B)+i*(m*w-g*E+x*N)-n*(m*S-g*B+y*N)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,s){let i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=s),this}invert(){let e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],p=e[11],m=e[12],g=e[13],y=e[14],x=e[15],_=t*a-s*r,w=t*c-i*r,S=t*l-n*r,E=s*c-i*a,B=s*l-n*a,N=i*l-n*c,C=u*g-h*m,I=u*y-d*m,k=u*x-p*m,W=h*y-d*g,X=h*x-p*g,Y=d*x-p*y,ee=_*Y-w*X+S*W+E*k-B*I+N*C;if(ee===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let Q=1/ee;return e[0]=(a*Y-c*X+l*W)*Q,e[1]=(i*X-s*Y-n*W)*Q,e[2]=(g*N-y*B+x*E)*Q,e[3]=(d*B-h*N-p*E)*Q,e[4]=(c*k-r*Y-l*I)*Q,e[5]=(t*Y-i*k+n*I)*Q,e[6]=(y*S-m*N-x*w)*Q,e[7]=(u*N-d*S+p*w)*Q,e[8]=(r*X-a*k+l*C)*Q,e[9]=(s*k-t*X-n*C)*Q,e[10]=(m*B-g*S+x*_)*Q,e[11]=(h*S-u*B-p*_)*Q,e[12]=(a*I-r*W-c*C)*Q,e[13]=(t*W-s*I+i*C)*Q,e[14]=(g*w-m*E-y*_)*Q,e[15]=(u*E-h*w+d*_)*Q,this}scale(e){let t=this.elements,s=e.x,i=e.y,n=e.z;return t[0]*=s,t[4]*=i,t[8]*=n,t[1]*=s,t[5]*=i,t[9]*=n,t[2]*=s,t[6]*=i,t[10]*=n,t[3]*=s,t[7]*=i,t[11]*=n,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],s=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,s,i))}makeTranslation(e,t,s){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,s,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),s=Math.sin(e);return this.set(1,0,0,0,0,t,-s,0,0,s,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),s=Math.sin(e);return this.set(t,0,s,0,0,1,0,0,-s,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,0,s,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let s=Math.cos(t),i=Math.sin(t),n=1-s,r=e.x,a=e.y,c=e.z,l=n*r,u=n*a;return this.set(l*r+s,l*a-i*c,l*c+i*a,0,l*a+i*c,u*a+s,u*c-i*r,0,l*c-i*a,u*c+i*r,n*c*c+s,0,0,0,0,1),this}makeScale(e,t,s){return this.set(e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1),this}makeShear(e,t,s,i,n,r){return this.set(1,s,n,0,e,1,r,0,t,i,1,0,0,0,0,1),this}compose(e,t,s){let i=this.elements,n=t._x,r=t._y,a=t._z,c=t._w,l=n+n,u=r+r,h=a+a,d=n*l,p=n*u,m=n*h,g=r*u,y=r*h,x=a*h,_=c*l,w=c*u,S=c*h,E=s.x,B=s.y,N=s.z;return i[0]=(1-(g+x))*E,i[1]=(p+S)*E,i[2]=(m-w)*E,i[3]=0,i[4]=(p-S)*B,i[5]=(1-(d+x))*B,i[6]=(y+_)*B,i[7]=0,i[8]=(m+w)*N,i[9]=(y-_)*N,i[10]=(1-(d+g))*N,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,s){let i=this.elements;e.x=i[12],e.y=i[13],e.z=i[14];let n=this.determinant();if(n===0)return s.set(1,1,1),t.identity(),this;let r=_r.set(i[0],i[1],i[2]).length(),a=_r.set(i[4],i[5],i[6]).length(),c=_r.set(i[8],i[9],i[10]).length();n<0&&(r=-r),ms.copy(this);let l=1/r,u=1/a,h=1/c;return ms.elements[0]*=l,ms.elements[1]*=l,ms.elements[2]*=l,ms.elements[4]*=u,ms.elements[5]*=u,ms.elements[6]*=u,ms.elements[8]*=h,ms.elements[9]*=h,ms.elements[10]*=h,t.setFromRotationMatrix(ms),s.x=r,s.y=a,s.z=c,this}makePerspective(e,t,s,i,n,r,a=Dt,c=!1){let l=this.elements,u=2*n/(t-e),h=2*n/(s-i),d=(t+e)/(t-e),p=(s+i)/(s-i),m,g;if(c)m=n/(r-n),g=r*n/(r-n);else if(a===Dt)m=-(r+n)/(r-n),g=-2*r*n/(r-n);else if(a===Yt)m=-r/(r-n),g=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=u,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=h,l[9]=p,l[13]=0,l[2]=0,l[6]=0,l[10]=m,l[14]=g,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(e,t,s,i,n,r,a=Dt,c=!1){let l=this.elements,u=2/(t-e),h=2/(s-i),d=-(t+e)/(t-e),p=-(s+i)/(s-i),m,g;if(c)m=1/(r-n),g=r/(r-n);else if(a===Dt)m=-2/(r-n),g=-(r+n)/(r-n);else if(a===Yt)m=-1/(r-n),g=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=u,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=h,l[9]=0,l[13]=p,l[2]=0,l[6]=0,l[10]=m,l[14]=g,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(e){let t=this.elements,s=e.elements;for(let i=0;i<16;i++)if(t[i]!==s[i])return!1;return!0}fromArray(e,t=0){for(let s=0;s<16;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){let s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e[t+9]=s[9],e[t+10]=s[10],e[t+11]=s[11],e[t+12]=s[12],e[t+13]=s[13],e[t+14]=s[14],e[t+15]=s[15],e}},_r=new R,ms=new de,F1=new R(0,0,0),I1=new R(1,1,1),Hi=new R,zc=new R,Wt=new R,R0=new de,C0=new Ss,jt=class o{constructor(e=0,t=0,s=0,i=o.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=s,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,s,i=this._order){return this._x=e,this._y=t,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,s=!0){let i=e.elements,n=i[0],r=i[4],a=i[8],c=i[1],l=i[5],u=i[9],h=i[2],d=i[6],p=i[10];switch(t){case"XYZ":this._y=Math.asin(ue(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,p),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-ue(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,p),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-h,n),this._z=0);break;case"ZXY":this._x=Math.asin(ue(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-h,p),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(c,n));break;case"ZYX":this._y=Math.asin(-ue(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,n)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(ue(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-h,n)):(this._x=0,this._y=Math.atan2(a,p));break;case"XZY":this._z=Math.asin(-ue(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-u,p),this._y=0);break;default:z("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,s===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,s){return R0.makeRotationFromQuaternion(e),this.setFromRotationMatrix(R0,t,s)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return C0.setFromEuler(this),this.setFromQuaternion(C0,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};jt.DEFAULT_ORDER="XYZ";var gl=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}},P1=0,E0=new R,Tr=new Ss,xi=new de,Gc=new R,Fo=new R,D1=new R,L1=new Ss,B0=new R(1,0,0),F0=new R(0,1,0),I0=new R(0,0,1),P0={type:"added"},U1={type:"removed"},Sr={type:"childadded",child:null},Dd={type:"childremoved",child:null},tt=class o extends Ts{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:P1++}),this.uuid=wi(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=o.DEFAULT_UP.clone();let e=new R,t=new jt,s=new Ss,i=new R(1,1,1);function n(){s.setFromEuler(t,!1)}function r(){t.setFromQuaternion(s,void 0,!1)}t._onChange(n),s._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new de},normalMatrix:{value:new Nt}}),this.matrix=new de,this.matrixWorld=new de,this.matrixAutoUpdate=o.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=o.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new gl,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Tr.setFromAxisAngle(e,t),this.quaternion.multiply(Tr),this}rotateOnWorldAxis(e,t){return Tr.setFromAxisAngle(e,t),this.quaternion.premultiply(Tr),this}rotateX(e){return this.rotateOnAxis(B0,e)}rotateY(e){return this.rotateOnAxis(F0,e)}rotateZ(e){return this.rotateOnAxis(I0,e)}translateOnAxis(e,t){return E0.copy(e).applyQuaternion(this.quaternion),this.position.add(E0.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(B0,e)}translateY(e){return this.translateOnAxis(F0,e)}translateZ(e){return this.translateOnAxis(I0,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(xi.copy(this.matrixWorld).invert())}lookAt(e,t,s){e.isVector3?Gc.copy(e):Gc.set(e,t,s);let i=this.parent;this.updateWorldMatrix(!0,!1),Fo.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?xi.lookAt(Fo,Gc,this.up):xi.lookAt(Gc,Fo,this.up),this.quaternion.setFromRotationMatrix(xi),i&&(xi.extractRotation(i.matrixWorld),Tr.setFromRotationMatrix(xi),this.quaternion.premultiply(Tr.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(O("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(P0),Sr.child=e,this.dispatchEvent(Sr),Sr.child=null):O("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(U1),Dd.child=e,this.dispatchEvent(Dd),Dd.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),xi.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),xi.multiply(e.parent.matrixWorld)),e.applyMatrix4(xi),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(P0),Sr.child=e,this.dispatchEvent(Sr),Sr.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let s=0,i=this.children.length;s<i;s++){let r=this.children[s].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,s=[]){this[e]===t&&s.push(this);let i=this.children;for(let n=0,r=i.length;n<r;n++)i[n].getObjectsByProperty(e,t,s);return s}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Fo,e,D1),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Fo,L1,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);let t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);let e=this.pivot;if(e!==null){let t=e.x,s=e.y,i=e.z,n=this.matrix.elements;n[12]+=t-n[0]*t-n[4]*s-n[8]*i,n[13]+=s-n[1]*t-n[5]*s-n[9]*i,n[14]+=i-n[2]*t-n[6]*s-n[10]*i}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].updateMatrixWorld(e)}updateWorldMatrix(e,t){let s=this.parent;if(e===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),t===!0){let i=this.children;for(let n=0,r=i.length;n<r;n++)i[n].updateWorldMatrix(!1,!0)}}toJSON(e){let t=e===void 0||typeof e=="string",s={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});let i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),this.static!==!1&&(i.static=this.static),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.pivot!==null&&(i.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(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.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function n(a,c){return a[c.uuid]===void 0&&(a[c.uuid]=c.toJSON(e)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=n(e.geometries,this.geometry);let a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){let c=a.shapes;if(Array.isArray(c))for(let l=0,u=c.length;l<u;l++){let h=c[l];n(e.shapes,h)}else n(e.shapes,c)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let a=[];for(let c=0,l=this.material.length;c<l;c++)a.push(n(e.materials,this.material[c]));i.material=a}else i.material=n(e.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){let c=this.animations[a];i.animations.push(n(e.animations,c))}}if(t){let a=r(e.geometries),c=r(e.materials),l=r(e.textures),u=r(e.images),h=r(e.shapes),d=r(e.skeletons),p=r(e.animations),m=r(e.nodes);a.length>0&&(s.geometries=a),c.length>0&&(s.materials=c),l.length>0&&(s.textures=l),u.length>0&&(s.images=u),h.length>0&&(s.shapes=h),d.length>0&&(s.skeletons=d),p.length>0&&(s.animations=p),m.length>0&&(s.nodes=m)}return s.object=i,s;function r(a){let c=[];for(let l in a){let u=a[l];delete u.metadata,c.push(u)}return c}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),e.pivot!==null&&(this.pivot=e.pivot.clone()),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let s=0;s<e.children.length;s++){let i=e.children[s];this.add(i.clone())}return this}};tt.DEFAULT_UP=new R(0,1,0);tt.DEFAULT_MATRIX_AUTO_UPDATE=!0;tt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var Fn=class extends tt{constructor(){super(),this.isGroup=!0,this.type="Group"}},O1={type:"move"},yl=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Fn,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Fn,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Fn,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){let t=this._hand;if(t)for(let s of e.hand.values())this._getHandJoint(t,s)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,s){let i=null,n=null,r=null,a=this._targetRay,c=this._grip,l=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(l&&e.hand){r=!0;for(let g of e.hand.values()){let y=t.getJointPose(g,s),x=this._getHandJoint(l,g);y!==null&&(x.matrix.fromArray(y.transform.matrix),x.matrix.decompose(x.position,x.rotation,x.scale),x.matrixWorldNeedsUpdate=!0,x.jointRadius=y.radius),x.visible=y!==null}let u=l.joints["index-finger-tip"],h=l.joints["thumb-tip"],d=u.position.distanceTo(h.position),p=.02,m=.005;l.inputState.pinching&&d>p+m?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!l.inputState.pinching&&d<=p-m&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else c!==null&&e.gripSpace&&(n=t.getPose(e.gripSpace,s),n!==null&&(c.matrix.fromArray(n.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,n.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(n.linearVelocity)):c.hasLinearVelocity=!1,n.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(n.angularVelocity)):c.hasAngularVelocity=!1));a!==null&&(i=t.getPose(e.targetRaySpace,s),i===null&&n!==null&&(i=n),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(O1)))}return a!==null&&(a.visible=i!==null),c!==null&&(c.visible=n!==null),l!==null&&(l.visible=r!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let s=new Fn;s.matrixAutoUpdate=!1,s.visible=!1,e.joints[t.jointName]=s,e.add(s)}return e.joints[t.jointName]}},Nb={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},Xi={h:0,s:0,l:0},Wc={h:0,s:0,l:0};function Ld(o,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?o+(e-o)*6*t:t<1/2?e:t<2/3?o+(e-o)*6*(2/3-t):o}var ge=class{constructor(e,t,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,s)}set(e,t,s){if(t===void 0&&s===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,s);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Pt){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,me.colorSpaceToWorking(this,t),this}setRGB(e,t,s,i=me.workingColorSpace){return this.r=e,this.g=t,this.b=s,me.colorSpaceToWorking(this,i),this}setHSL(e,t,s,i=me.workingColorSpace){if(e=Rp(e,1),t=ue(t,0,1),s=ue(s,0,1),t===0)this.r=this.g=this.b=s;else{let n=s<=.5?s*(1+t):s+t-s*t,r=2*s-n;this.r=Ld(r,n,e+1/3),this.g=Ld(r,n,e),this.b=Ld(r,n,e-1/3)}return me.colorSpaceToWorking(this,i),this}setStyle(e,t=Pt){function s(n){n!==void 0&&parseFloat(n)<1&&z("Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let n,r=i[1],a=i[2];switch(r){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,t);if(n=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,t);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,t);break;default:z("Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let n=i[1],r=n.length;if(r===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(r===6)return this.setHex(parseInt(n,16),t);z("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Pt){let s=Nb[e.toLowerCase()];return s!==void 0?this.setHex(s,t):z("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Mi(e.r),this.g=Mi(e.g),this.b=Mi(e.b),this}copyLinearToSRGB(e){return this.r=Fr(e.r),this.g=Fr(e.g),this.b=Fr(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Pt){return me.workingToColorSpace(gt.copy(this),e),Math.round(ue(gt.r*255,0,255))*65536+Math.round(ue(gt.g*255,0,255))*256+Math.round(ue(gt.b*255,0,255))}getHexString(e=Pt){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=me.workingColorSpace){me.workingToColorSpace(gt.copy(this),t);let s=gt.r,i=gt.g,n=gt.b,r=Math.max(s,i,n),a=Math.min(s,i,n),c,l,u=(a+r)/2;if(a===r)c=0,l=0;else{let h=r-a;switch(l=u<=.5?h/(r+a):h/(2-r-a),r){case s:c=(i-n)/h+(i<n?6:0);break;case i:c=(n-s)/h+2;break;case n:c=(s-i)/h+4;break}c/=6}return e.h=c,e.s=l,e.l=u,e}getRGB(e,t=me.workingColorSpace){return me.workingToColorSpace(gt.copy(this),t),e.r=gt.r,e.g=gt.g,e.b=gt.b,e}getStyle(e=Pt){me.workingToColorSpace(gt.copy(this),e);let t=gt.r,s=gt.g,i=gt.b;return e!==Pt?`color(${e} ${t.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(s*255)},${Math.round(i*255)})`}offsetHSL(e,t,s){return this.getHSL(Xi),this.setHSL(Xi.h+e,Xi.s+t,Xi.l+s)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,s){return this.r=e.r+(t.r-e.r)*s,this.g=e.g+(t.g-e.g)*s,this.b=e.b+(t.b-e.b)*s,this}lerpHSL(e,t){this.getHSL(Xi),e.getHSL(Wc);let s=Uo(Xi.h,Wc.h,t),i=Uo(Xi.s,Wc.s,t),n=Uo(Xi.l,Wc.l,t);return this.setHSL(s,i,n),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,s=this.g,i=this.b,n=e.elements;return this.r=n[0]*t+n[3]*s+n[6]*i,this.g=n[1]*t+n[4]*s+n[7]*i,this.b=n[2]*t+n[5]*s+n[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},gt=new ge;ge.NAMES=Nb;var On=class extends tt{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 jt,this.environmentIntensity=1,this.environmentRotation=new jt,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){let t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}},gs=new R,bi=new R,Ud=new R,_i=new R,vr=new R,wr=new R,D0=new R,Od=new R,Vd=new R,kd=new R,zd=new Te,Gd=new Te,Wd=new Te,Ki=class o{constructor(e=new R,t=new R,s=new R){this.a=e,this.b=t,this.c=s}static getNormal(e,t,s,i){i.subVectors(s,t),gs.subVectors(e,t),i.cross(gs);let n=i.lengthSq();return n>0?i.multiplyScalar(1/Math.sqrt(n)):i.set(0,0,0)}static getBarycoord(e,t,s,i,n){gs.subVectors(i,t),bi.subVectors(s,t),Ud.subVectors(e,t);let r=gs.dot(gs),a=gs.dot(bi),c=gs.dot(Ud),l=bi.dot(bi),u=bi.dot(Ud),h=r*l-a*a;if(h===0)return n.set(0,0,0),null;let d=1/h,p=(l*c-a*u)*d,m=(r*u-a*c)*d;return n.set(1-p-m,m,p)}static containsPoint(e,t,s,i){return this.getBarycoord(e,t,s,i,_i)===null?!1:_i.x>=0&&_i.y>=0&&_i.x+_i.y<=1}static getInterpolation(e,t,s,i,n,r,a,c){return this.getBarycoord(e,t,s,i,_i)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(n,_i.x),c.addScaledVector(r,_i.y),c.addScaledVector(a,_i.z),c)}static getInterpolatedAttribute(e,t,s,i,n,r){return zd.setScalar(0),Gd.setScalar(0),Wd.setScalar(0),zd.fromBufferAttribute(e,t),Gd.fromBufferAttribute(e,s),Wd.fromBufferAttribute(e,i),r.setScalar(0),r.addScaledVector(zd,n.x),r.addScaledVector(Gd,n.y),r.addScaledVector(Wd,n.z),r}static isFrontFacing(e,t,s,i){return gs.subVectors(s,t),bi.subVectors(e,t),gs.cross(bi).dot(i)<0}set(e,t,s){return this.a.copy(e),this.b.copy(t),this.c.copy(s),this}setFromPointsAndIndices(e,t,s,i){return this.a.copy(e[t]),this.b.copy(e[s]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,s,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,s),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return gs.subVectors(this.c,this.b),bi.subVectors(this.a,this.b),gs.cross(bi).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return o.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return o.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,s,i,n){return o.getInterpolation(e,this.a,this.b,this.c,t,s,i,n)}containsPoint(e){return o.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return o.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let s=this.a,i=this.b,n=this.c,r,a;vr.subVectors(i,s),wr.subVectors(n,s),Od.subVectors(e,s);let c=vr.dot(Od),l=wr.dot(Od);if(c<=0&&l<=0)return t.copy(s);Vd.subVectors(e,i);let u=vr.dot(Vd),h=wr.dot(Vd);if(u>=0&&h<=u)return t.copy(i);let d=c*h-u*l;if(d<=0&&c>=0&&u<=0)return r=c/(c-u),t.copy(s).addScaledVector(vr,r);kd.subVectors(e,n);let p=vr.dot(kd),m=wr.dot(kd);if(m>=0&&p<=m)return t.copy(n);let g=p*l-c*m;if(g<=0&&l>=0&&m<=0)return a=l/(l-m),t.copy(s).addScaledVector(wr,a);let y=u*m-p*h;if(y<=0&&h-u>=0&&p-m>=0)return D0.subVectors(n,i),a=(h-u)/(h-u+(p-m)),t.copy(i).addScaledVector(D0,a);let x=1/(y+g+d);return r=g*x,a=d*x,t.copy(s).addScaledVector(vr,r).addScaledVector(wr,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},en=class{constructor(e=new R(1/0,1/0,1/0),t=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,s=e.length;t<s;t+=3)this.expandByPoint(ys.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,s=e.count;t<s;t++)this.expandByPoint(ys.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,s=e.length;t<s;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let s=ys.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(s),this.max.copy(e).add(s),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let s=e.geometry;if(s!==void 0){let n=s.getAttribute("position");if(t===!0&&n!==void 0&&e.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)e.isMesh===!0?e.getVertexPosition(r,ys):ys.fromBufferAttribute(n,r),ys.applyMatrix4(e.matrixWorld),this.expandByPoint(ys);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),$c.copy(e.boundingBox)):(s.boundingBox===null&&s.computeBoundingBox(),$c.copy(s.boundingBox)),$c.applyMatrix4(e.matrixWorld),this.union($c)}let i=e.children;for(let n=0,r=i.length;n<r;n++)this.expandByObject(i[n],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,ys),ys.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,s;return e.normal.x>0?(t=e.normal.x*this.min.x,s=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,s=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,s+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,s+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,s+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,s+=e.normal.z*this.min.z),t<=-e.constant&&s>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Io),qc.subVectors(this.max,Io),Mr.subVectors(e.a,Io),Ar.subVectors(e.b,Io),Nr.subVectors(e.c,Io),Yi.subVectors(Ar,Mr),ji.subVectors(Nr,Ar),Rn.subVectors(Mr,Nr);let t=[0,-Yi.z,Yi.y,0,-ji.z,ji.y,0,-Rn.z,Rn.y,Yi.z,0,-Yi.x,ji.z,0,-ji.x,Rn.z,0,-Rn.x,-Yi.y,Yi.x,0,-ji.y,ji.x,0,-Rn.y,Rn.x,0];return!$d(t,Mr,Ar,Nr,qc)||(t=[1,0,0,0,1,0,0,0,1],!$d(t,Mr,Ar,Nr,qc))?!1:(Hc.crossVectors(Yi,ji),t=[Hc.x,Hc.y,Hc.z],$d(t,Mr,Ar,Nr,qc))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,ys).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(ys).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Ti[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Ti[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Ti[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Ti[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Ti[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Ti[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Ti[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Ti[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Ti),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},Ti=[new R,new R,new R,new R,new R,new R,new R,new R],ys=new R,$c=new en,Mr=new R,Ar=new R,Nr=new R,Yi=new R,ji=new R,Rn=new R,Io=new R,qc=new R,Hc=new R,Cn=new R;function $d(o,e,t,s,i){for(let n=0,r=o.length-3;n<=r;n+=3){Cn.fromArray(o,n);let a=i.x*Math.abs(Cn.x)+i.y*Math.abs(Cn.y)+i.z*Math.abs(Cn.z),c=e.dot(Cn),l=t.dot(Cn),u=s.dot(Cn);if(Math.max(-Math.max(c,l,u),Math.min(c,l,u))>a)return!1}return!0}var vi=V1();function V1(){let o=new ArrayBuffer(4),e=new Float32Array(o),t=new Uint32Array(o),s=new Uint32Array(512),i=new Uint32Array(512);for(let c=0;c<256;++c){let l=c-127;l<-27?(s[c]=0,s[c|256]=32768,i[c]=24,i[c|256]=24):l<-14?(s[c]=1024>>-l-14,s[c|256]=1024>>-l-14|32768,i[c]=-l-1,i[c|256]=-l-1):l<=15?(s[c]=l+15<<10,s[c|256]=l+15<<10|32768,i[c]=13,i[c|256]=13):l<128?(s[c]=31744,s[c|256]=64512,i[c]=24,i[c|256]=24):(s[c]=31744,s[c|256]=64512,i[c]=13,i[c|256]=13)}let n=new Uint32Array(2048),r=new Uint32Array(64),a=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,u=0;for(;(l&8388608)===0;)l<<=1,u-=8388608;l&=-8388609,u+=947912704,n[c]=l|u}for(let c=1024;c<2048;++c)n[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)r[c]=c<<23;r[31]=1199570944,r[32]=2147483648;for(let c=33;c<63;++c)r[c]=2147483648+(c-32<<23);r[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(a[c]=1024);return{floatView:e,uint32View:t,baseTable:s,shiftTable:i,mantissaTable:n,exponentTable:r,offsetTable:a}}function $t(o){Math.abs(o)>65504&&z("DataUtils.toHalfFloat(): Value out of range."),o=ue(o,-65504,65504),vi.floatView[0]=o;let e=vi.uint32View[0],t=e>>23&511;return vi.baseTable[t]+((e&8388607)>>vi.shiftTable[t])}function Xc(o){let e=o>>10;return vi.uint32View[0]=vi.mantissaTable[vi.offsetTable[e]+(o&1023)]+vi.exponentTable[e],vi.floatView[0]}var Je=new R,Yc=new re,k1=0,yt=class{constructor(e,t,s=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:k1++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=s,this.usage=Ln,this.updateRanges=[],this.gpuType=Ct,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,s){e*=this.itemSize,s*=t.itemSize;for(let i=0,n=this.itemSize;i<n;i++)this.array[e+i]=t.array[s+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,s=this.count;t<s;t++)Yc.fromBufferAttribute(this,t),Yc.applyMatrix3(e),this.setXY(t,Yc.x,Yc.y);else if(this.itemSize===3)for(let t=0,s=this.count;t<s;t++)Je.fromBufferAttribute(this,t),Je.applyMatrix3(e),this.setXYZ(t,Je.x,Je.y,Je.z);return this}applyMatrix4(e){for(let t=0,s=this.count;t<s;t++)Je.fromBufferAttribute(this,t),Je.applyMatrix4(e),this.setXYZ(t,Je.x,Je.y,Je.z);return this}applyNormalMatrix(e){for(let t=0,s=this.count;t<s;t++)Je.fromBufferAttribute(this,t),Je.applyNormalMatrix(e),this.setXYZ(t,Je.x,Je.y,Je.z);return this}transformDirection(e){for(let t=0,s=this.count;t<s;t++)Je.fromBufferAttribute(this,t),Je.transformDirection(e),this.setXYZ(t,Je.x,Je.y,Je.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let s=this.array[e*this.itemSize+t];return this.normalized&&(s=At(s,this.array)),s}setComponent(e,t,s){return this.normalized&&(s=ce(s,this.array)),this.array[e*this.itemSize+t]=s,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=At(t,this.array)),t}setX(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=At(t,this.array)),t}setY(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=At(t,this.array)),t}setZ(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=At(t,this.array)),t}setW(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array)),this.array[e+0]=t,this.array[e+1]=s,this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this}setXYZW(e,t,s,i,n){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array),n=ce(n,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this.array[e+3]=n,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==Ln&&(e.usage=this.usage),e}};var Yo=class extends yt{constructor(e,t,s){super(new Uint16Array(e),t,s)}};var jo=class extends yt{constructor(e,t,s){super(new Uint32Array(e),t,s)}},Zo=class extends yt{constructor(e,t,s){super(new Uint16Array(e),t,s),this.isFloat16BufferAttribute=!0}getX(e){let t=Xc(this.array[e*this.itemSize]);return this.normalized&&(t=At(t,this.array)),t}setX(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize]=$t(t),this}getY(e){let t=Xc(this.array[e*this.itemSize+1]);return this.normalized&&(t=At(t,this.array)),t}setY(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+1]=$t(t),this}getZ(e){let t=Xc(this.array[e*this.itemSize+2]);return this.normalized&&(t=At(t,this.array)),t}setZ(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+2]=$t(t),this}getW(e){let t=Xc(this.array[e*this.itemSize+3]);return this.normalized&&(t=At(t,this.array)),t}setW(e,t){return this.normalized&&(t=ce(t,this.array)),this.array[e*this.itemSize+3]=$t(t),this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array)),this.array[e+0]=$t(t),this.array[e+1]=$t(s),this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array)),this.array[e+0]=$t(t),this.array[e+1]=$t(s),this.array[e+2]=$t(i),this}setXYZW(e,t,s,i,n){return e*=this.itemSize,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array),n=ce(n,this.array)),this.array[e+0]=$t(t),this.array[e+1]=$t(s),this.array[e+2]=$t(i),this.array[e+3]=$t(n),this}},nt=class extends yt{constructor(e,t,s){super(new Float32Array(e),t,s)}},z1=new en,Po=new R,qd=new R,Vn=class{constructor(e=new R,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let s=this.center;t!==void 0?s.copy(t):z1.setFromPoints(e).getCenter(s);let i=0;for(let n=0,r=e.length;n<r;n++)i=Math.max(i,s.distanceToSquared(e[n]));return this.radius=Math.sqrt(i),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let s=this.center.distanceToSquared(e);return t.copy(e),s>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Po.subVectors(e,this.center);let t=Po.lengthSq();if(t>this.radius*this.radius){let s=Math.sqrt(t),i=(s-this.radius)*.5;this.center.addScaledVector(Po,i/s),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(qd.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Po.copy(e.center).add(qd)),this.expandByPoint(Po.copy(e.center).sub(qd))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}},G1=0,is=new de,Hd=new tt,Rr=new R,qt=new en,Do=new en,st=new R,vs=class o extends Ts{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:G1++}),this.uuid=wi(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(d1(e)?jo:Yo)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,s=0){this.groups.push({start:e,count:t,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let s=this.attributes.normal;if(s!==void 0){let n=new Nt().getNormalMatrix(e);s.applyNormalMatrix(n),s.needsUpdate=!0}let i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(e),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return is.makeRotationFromQuaternion(e),this.applyMatrix4(is),this}rotateX(e){return is.makeRotationX(e),this.applyMatrix4(is),this}rotateY(e){return is.makeRotationY(e),this.applyMatrix4(is),this}rotateZ(e){return is.makeRotationZ(e),this.applyMatrix4(is),this}translate(e,t,s){return is.makeTranslation(e,t,s),this.applyMatrix4(is),this}scale(e,t,s){return is.makeScale(e,t,s),this.applyMatrix4(is),this}lookAt(e){return Hd.lookAt(e),Hd.updateMatrix(),this.applyMatrix4(Hd.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Rr).negate(),this.translate(Rr.x,Rr.y,Rr.z),this}setFromPoints(e){let t=this.getAttribute("position");if(t===void 0){let s=[];for(let i=0,n=e.length;i<n;i++){let r=e[i];s.push(r.x,r.y,r.z||0)}this.setAttribute("position",new nt(s,3))}else{let s=Math.min(e.length,t.count);for(let i=0;i<s;i++){let n=e[i];t.setXYZ(i,n.x,n.y,n.z||0)}e.length>t.count&&z("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new en);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){O("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let s=0,i=t.length;s<i;s++){let n=t[s];qt.setFromBufferAttribute(n),this.morphTargetsRelative?(st.addVectors(this.boundingBox.min,qt.min),this.boundingBox.expandByPoint(st),st.addVectors(this.boundingBox.max,qt.max),this.boundingBox.expandByPoint(st)):(this.boundingBox.expandByPoint(qt.min),this.boundingBox.expandByPoint(qt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&O('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Vn);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){O("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new R,1/0);return}if(e){let s=this.boundingSphere.center;if(qt.setFromBufferAttribute(e),t)for(let n=0,r=t.length;n<r;n++){let a=t[n];Do.setFromBufferAttribute(a),this.morphTargetsRelative?(st.addVectors(qt.min,Do.min),qt.expandByPoint(st),st.addVectors(qt.max,Do.max),qt.expandByPoint(st)):(qt.expandByPoint(Do.min),qt.expandByPoint(Do.max))}qt.getCenter(s);let i=0;for(let n=0,r=e.count;n<r;n++)st.fromBufferAttribute(e,n),i=Math.max(i,s.distanceToSquared(st));if(t)for(let n=0,r=t.length;n<r;n++){let a=t[n],c=this.morphTargetsRelative;for(let l=0,u=a.count;l<u;l++)st.fromBufferAttribute(a,l),c&&(Rr.fromBufferAttribute(e,l),st.add(Rr)),i=Math.max(i,s.distanceToSquared(st))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&O('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){O("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}let s=t.position,i=t.normal,n=t.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new yt(new Float32Array(4*s.count),4));let r=this.getAttribute("tangent"),a=[],c=[];for(let C=0;C<s.count;C++)a[C]=new R,c[C]=new R;let l=new R,u=new R,h=new R,d=new re,p=new re,m=new re,g=new R,y=new R;function x(C,I,k){l.fromBufferAttribute(s,C),u.fromBufferAttribute(s,I),h.fromBufferAttribute(s,k),d.fromBufferAttribute(n,C),p.fromBufferAttribute(n,I),m.fromBufferAttribute(n,k),u.sub(l),h.sub(l),p.sub(d),m.sub(d);let W=1/(p.x*m.y-m.x*p.y);isFinite(W)&&(g.copy(u).multiplyScalar(m.y).addScaledVector(h,-p.y).multiplyScalar(W),y.copy(h).multiplyScalar(p.x).addScaledVector(u,-m.x).multiplyScalar(W),a[C].add(g),a[I].add(g),a[k].add(g),c[C].add(y),c[I].add(y),c[k].add(y))}let _=this.groups;_.length===0&&(_=[{start:0,count:e.count}]);for(let C=0,I=_.length;C<I;++C){let k=_[C],W=k.start,X=k.count;for(let Y=W,ee=W+X;Y<ee;Y+=3)x(e.getX(Y+0),e.getX(Y+1),e.getX(Y+2))}let w=new R,S=new R,E=new R,B=new R;function N(C){E.fromBufferAttribute(i,C),B.copy(E);let I=a[C];w.copy(I),w.sub(E.multiplyScalar(E.dot(I))).normalize(),S.crossVectors(B,I);let W=S.dot(c[C])<0?-1:1;r.setXYZW(C,w.x,w.y,w.z,W)}for(let C=0,I=_.length;C<I;++C){let k=_[C],W=k.start,X=k.count;for(let Y=W,ee=W+X;Y<ee;Y+=3)N(e.getX(Y+0)),N(e.getX(Y+1)),N(e.getX(Y+2))}}computeVertexNormals(){let e=this.index,t=this.getAttribute("position");if(t!==void 0){let s=this.getAttribute("normal");if(s===void 0)s=new yt(new Float32Array(t.count*3),3),this.setAttribute("normal",s);else for(let d=0,p=s.count;d<p;d++)s.setXYZ(d,0,0,0);let i=new R,n=new R,r=new R,a=new R,c=new R,l=new R,u=new R,h=new R;if(e)for(let d=0,p=e.count;d<p;d+=3){let m=e.getX(d+0),g=e.getX(d+1),y=e.getX(d+2);i.fromBufferAttribute(t,m),n.fromBufferAttribute(t,g),r.fromBufferAttribute(t,y),u.subVectors(r,n),h.subVectors(i,n),u.cross(h),a.fromBufferAttribute(s,m),c.fromBufferAttribute(s,g),l.fromBufferAttribute(s,y),a.add(u),c.add(u),l.add(u),s.setXYZ(m,a.x,a.y,a.z),s.setXYZ(g,c.x,c.y,c.z),s.setXYZ(y,l.x,l.y,l.z)}else for(let d=0,p=t.count;d<p;d+=3)i.fromBufferAttribute(t,d+0),n.fromBufferAttribute(t,d+1),r.fromBufferAttribute(t,d+2),u.subVectors(r,n),h.subVectors(i,n),u.cross(h),s.setXYZ(d+0,u.x,u.y,u.z),s.setXYZ(d+1,u.x,u.y,u.z),s.setXYZ(d+2,u.x,u.y,u.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,s=e.count;t<s;t++)st.fromBufferAttribute(e,t),st.normalize(),e.setXYZ(t,st.x,st.y,st.z)}toNonIndexed(){function e(a,c){let l=a.array,u=a.itemSize,h=a.normalized,d=new l.constructor(c.length*u),p=0,m=0;for(let g=0,y=c.length;g<y;g++){a.isInterleavedBufferAttribute?p=c[g]*a.data.stride+a.offset:p=c[g]*u;for(let x=0;x<u;x++)d[m++]=l[p++]}return new yt(d,u,h)}if(this.index===null)return z("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;let t=new o,s=this.index.array,i=this.attributes;for(let a in i){let c=i[a],l=e(c,s);t.setAttribute(a,l)}let n=this.morphAttributes;for(let a in n){let c=[],l=n[a];for(let u=0,h=l.length;u<h;u++){let d=l[u],p=e(d,s);c.push(p)}t.morphAttributes[a]=c}t.morphTargetsRelative=this.morphTargetsRelative;let r=this.groups;for(let a=0,c=r.length;a<c;a++){let l=r[a];t.addGroup(l.start,l.count,l.materialIndex)}return t}toJSON(){let e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){let c=this.parameters;for(let l in c)c[l]!==void 0&&(e[l]=c[l]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let s=this.attributes;for(let c in s){let l=s[c];e.data.attributes[c]=l.toJSON(e.data)}let i={},n=!1;for(let c in this.morphAttributes){let l=this.morphAttributes[c],u=[];for(let h=0,d=l.length;h<d;h++){let p=l[h];u.push(p.toJSON(e.data))}u.length>0&&(i[c]=u,n=!0)}n&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);let r=this.groups;r.length>0&&(e.data.groups=JSON.parse(JSON.stringify(r)));let a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let s=e.index;s!==null&&this.setIndex(s.clone());let i=e.attributes;for(let l in i){let u=i[l];this.setAttribute(l,u.clone(t))}let n=e.morphAttributes;for(let l in n){let u=[],h=n[l];for(let d=0,p=h.length;d<p;d++)u.push(h[d].clone(t));this.morphAttributes[l]=u}this.morphTargetsRelative=e.morphTargetsRelative;let r=e.groups;for(let l=0,u=r.length;l<u;l++){let h=r[l];this.addGroup(h.start,h.count,h.materialIndex)}let a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());let c=e.boundingSphere;return c!==null&&(this.boundingSphere=c.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}},Jo=class{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=Ln,this.updateRanges=[],this.version=0,this.uuid=wi()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,s){e*=this.stride,s*=t.stride;for(let i=0,n=this.stride;i<n;i++)this.array[e+i]=t.array[s+i];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=wi()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);let t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(t,this.stride);return s.setUsage(this.usage),s}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=wi()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}},Mt=new R,xl=class o{constructor(e,t,s,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=s,this.normalized=i}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,s=this.data.count;t<s;t++)Mt.fromBufferAttribute(this,t),Mt.applyMatrix4(e),this.setXYZ(t,Mt.x,Mt.y,Mt.z);return this}applyNormalMatrix(e){for(let t=0,s=this.count;t<s;t++)Mt.fromBufferAttribute(this,t),Mt.applyNormalMatrix(e),this.setXYZ(t,Mt.x,Mt.y,Mt.z);return this}transformDirection(e){for(let t=0,s=this.count;t<s;t++)Mt.fromBufferAttribute(this,t),Mt.transformDirection(e),this.setXYZ(t,Mt.x,Mt.y,Mt.z);return this}getComponent(e,t){let s=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(s=At(s,this.array)),s}setComponent(e,t,s){return this.normalized&&(s=ce(s,this.array)),this.data.array[e*this.data.stride+this.offset+t]=s,this}setX(e,t){return this.normalized&&(t=ce(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=ce(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=ce(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=ce(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=At(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=At(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=At(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=At(t,this.array)),t}setXY(e,t,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this}setXYZ(e,t,s,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this.data.array[e+2]=i,this}setXYZW(e,t,s,i,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=ce(t,this.array),s=ce(s,this.array),i=ce(i,this.array),n=ce(n,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=s,this.data.array[e+2]=i,this.data.array[e+3]=n,this}clone(e){if(e===void 0){pl("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let s=0;s<this.count;s++){let i=s*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)t.push(this.data.array[i+n])}return new yt(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new o(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){pl("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let s=0;s<this.count;s++){let i=s*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)t.push(this.data.array[i+n])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}},W1=0,_t=class extends Ts{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:W1++}),this.uuid=wi(),this.name="",this.type="Material",this.blending=Ht,this.side=_s,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Ir,this.blendDst=Pr,this.blendEquation=Xt,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new ge(0,0,0),this.blendAlpha=0,this.depthFunc=In,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=hl,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Qi,this.stencilZFail=Qi,this.stencilZPass=Qi,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let s=e[t];if(s===void 0){z(`Material: parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){z(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[t]=s}}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});let s={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),this.roughness!==void 0&&(s.roughness=this.roughness),this.metalness!==void 0&&(s.metalness=this.metalness),this.sheen!==void 0&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(s.shininess=this.shininess),this.clearcoat!==void 0&&(s.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(s.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(s.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(s.dispersion=this.dispersion),this.iridescence!==void 0&&(s.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(s.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(s.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(e).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(e).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(e).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(e).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(e).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(s.combine=this.combine)),this.envMapRotation!==void 0&&(s.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(s.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(s.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(s.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(s.size=this.size),this.shadowSide!==null&&(s.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(s.sizeAttenuation=this.sizeAttenuation),this.blending!==Ht&&(s.blending=this.blending),this.side!==_s&&(s.side=this.side),this.vertexColors===!0&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),this.transparent===!0&&(s.transparent=!0),this.blendSrc!==Ir&&(s.blendSrc=this.blendSrc),this.blendDst!==Pr&&(s.blendDst=this.blendDst),this.blendEquation!==Xt&&(s.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(s.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(s.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(s.blendAlpha=this.blendAlpha),this.depthFunc!==In&&(s.depthFunc=this.depthFunc),this.depthTest===!1&&(s.depthTest=this.depthTest),this.depthWrite===!1&&(s.depthWrite=this.depthWrite),this.colorWrite===!1&&(s.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==hl&&(s.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(s.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Qi&&(s.stencilFail=this.stencilFail),this.stencilZFail!==Qi&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==Qi&&(s.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(s.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(s.rotation=this.rotation),this.polygonOffset===!0&&(s.polygonOffset=!0),this.polygonOffsetFactor!==0&&(s.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(s.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(s.linewidth=this.linewidth),this.dashSize!==void 0&&(s.dashSize=this.dashSize),this.gapSize!==void 0&&(s.gapSize=this.gapSize),this.scale!==void 0&&(s.scale=this.scale),this.dithering===!0&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),this.alphaHash===!0&&(s.alphaHash=!0),this.alphaToCoverage===!0&&(s.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(s.premultipliedAlpha=!0),this.forceSinglePass===!0&&(s.forceSinglePass=!0),this.allowOverride===!1&&(s.allowOverride=!1),this.wireframe===!0&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(s.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(s.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(s.flatShading=!0),this.visible===!1&&(s.visible=!1),this.toneMapped===!1&&(s.toneMapped=!1),this.fog===!1&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData);function i(n){let r=[];for(let a in n){let c=n[a];delete c.metadata,r.push(c)}return r}if(t){let n=i(e.textures),r=i(e.images);n.length>0&&(s.textures=n),r.length>0&&(s.images=r)}return s}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,s=null;if(t!==null){let i=t.length;s=new Array(i);for(let n=0;n!==i;++n)s[n]=t[n].clone()}return this.clippingPlanes=s,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}},bl=class extends _t{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new ge(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}};var Si=new R,Xd=new R,jc=new R,Zi=new R,Yd=new R,Zc=new R,jd=new R,_l=class{constructor(e=new R,t=new R(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Si)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let s=t.dot(this.direction);return s<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=Si.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Si.copy(this.origin).addScaledVector(this.direction,t),Si.distanceToSquared(e))}distanceSqToSegment(e,t,s,i){Xd.copy(e).add(t).multiplyScalar(.5),jc.copy(t).sub(e).normalize(),Zi.copy(this.origin).sub(Xd);let n=e.distanceTo(t)*.5,r=-this.direction.dot(jc),a=Zi.dot(this.direction),c=-Zi.dot(jc),l=Zi.lengthSq(),u=Math.abs(1-r*r),h,d,p,m;if(u>0)if(h=r*c-a,d=r*a-c,m=n*u,h>=0)if(d>=-m)if(d<=m){let g=1/u;h*=g,d*=g,p=h*(h+r*d+2*a)+d*(r*h+d+2*c)+l}else d=n,h=Math.max(0,-(r*d+a)),p=-h*h+d*(d+2*c)+l;else d=-n,h=Math.max(0,-(r*d+a)),p=-h*h+d*(d+2*c)+l;else d<=-m?(h=Math.max(0,-(-r*n+a)),d=h>0?-n:Math.min(Math.max(-n,-c),n),p=-h*h+d*(d+2*c)+l):d<=m?(h=0,d=Math.min(Math.max(-n,-c),n),p=d*(d+2*c)+l):(h=Math.max(0,-(r*n+a)),d=h>0?n:Math.min(Math.max(-n,-c),n),p=-h*h+d*(d+2*c)+l);else d=r>0?-n:n,h=Math.max(0,-(r*d+a)),p=-h*h+d*(d+2*c)+l;return s&&s.copy(this.origin).addScaledVector(this.direction,h),i&&i.copy(Xd).addScaledVector(jc,d),p}intersectSphere(e,t){Si.subVectors(e.center,this.origin);let s=Si.dot(this.direction),i=Si.dot(Si)-s*s,n=e.radius*e.radius;if(i>n)return null;let r=Math.sqrt(n-i),a=s-r,c=s+r;return c<0?null:a<0?this.at(c,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let s=-(this.origin.dot(e.normal)+e.constant)/t;return s>=0?s:null}intersectPlane(e,t){let s=this.distanceToPlane(e);return s===null?null:this.at(s,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let s,i,n,r,a,c,l=1/this.direction.x,u=1/this.direction.y,h=1/this.direction.z,d=this.origin;return l>=0?(s=(e.min.x-d.x)*l,i=(e.max.x-d.x)*l):(s=(e.max.x-d.x)*l,i=(e.min.x-d.x)*l),u>=0?(n=(e.min.y-d.y)*u,r=(e.max.y-d.y)*u):(n=(e.max.y-d.y)*u,r=(e.min.y-d.y)*u),s>r||n>i||((n>s||isNaN(s))&&(s=n),(r<i||isNaN(i))&&(i=r),h>=0?(a=(e.min.z-d.z)*h,c=(e.max.z-d.z)*h):(a=(e.max.z-d.z)*h,c=(e.min.z-d.z)*h),s>c||a>i)||((a>s||s!==s)&&(s=a),(c<i||i!==i)&&(i=c),i<0)?null:this.at(s>=0?s:i,t)}intersectsBox(e){return this.intersectBox(e,Si)!==null}intersectTriangle(e,t,s,i,n){Yd.subVectors(t,e),Zc.subVectors(s,e),jd.crossVectors(Yd,Zc);let r=this.direction.dot(jd),a;if(r>0){if(i)return null;a=1}else if(r<0)a=-1,r=-r;else return null;Zi.subVectors(this.origin,e);let c=a*this.direction.dot(Zc.crossVectors(Zi,Zc));if(c<0)return null;let l=a*this.direction.dot(Yd.cross(Zi));if(l<0||c+l>r)return null;let u=-a*Zi.dot(jd);return u<0?null:this.at(u/r,n)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},ws=class extends _t{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ge(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 jt,this.combine=aa,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},L0=new de,En=new _l,Jc=new Vn,U0=new R,Qc=new R,Kc=new R,el=new R,Zd=new R,tl=new R,O0=new R,sl=new R,Zt=class extends tt{constructor(e=new vs,t=new ws){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let t=this.geometry.morphAttributes,s=Object.keys(t);if(s.length>0){let i=t[s[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let n=0,r=i.length;n<r;n++){let a=i[n].name||String(n);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=n}}}}getVertexPosition(e,t){let s=this.geometry,i=s.attributes.position,n=s.morphAttributes.position,r=s.morphTargetsRelative;t.fromBufferAttribute(i,e);let a=this.morphTargetInfluences;if(n&&a){tl.set(0,0,0);for(let c=0,l=n.length;c<l;c++){let u=a[c],h=n[c];u!==0&&(Zd.fromBufferAttribute(h,e),r?tl.addScaledVector(Zd,u):tl.addScaledVector(Zd.sub(t),u))}t.add(tl)}return t}raycast(e,t){let s=this.geometry,i=this.material,n=this.matrixWorld;i!==void 0&&(s.boundingSphere===null&&s.computeBoundingSphere(),Jc.copy(s.boundingSphere),Jc.applyMatrix4(n),En.copy(e.ray).recast(e.near),!(Jc.containsPoint(En.origin)===!1&&(En.intersectSphere(Jc,U0)===null||En.origin.distanceToSquared(U0)>(e.far-e.near)**2))&&(L0.copy(n).invert(),En.copy(e.ray).applyMatrix4(L0),!(s.boundingBox!==null&&En.intersectsBox(s.boundingBox)===!1)&&this._computeIntersections(e,t,En)))}_computeIntersections(e,t,s){let i,n=this.geometry,r=this.material,a=n.index,c=n.attributes.position,l=n.attributes.uv,u=n.attributes.uv1,h=n.attributes.normal,d=n.groups,p=n.drawRange;if(a!==null)if(Array.isArray(r))for(let m=0,g=d.length;m<g;m++){let y=d[m],x=r[y.materialIndex],_=Math.max(y.start,p.start),w=Math.min(a.count,Math.min(y.start+y.count,p.start+p.count));for(let S=_,E=w;S<E;S+=3){let B=a.getX(S),N=a.getX(S+1),C=a.getX(S+2);i=il(this,x,e,s,l,u,h,B,N,C),i&&(i.faceIndex=Math.floor(S/3),i.face.materialIndex=y.materialIndex,t.push(i))}}else{let m=Math.max(0,p.start),g=Math.min(a.count,p.start+p.count);for(let y=m,x=g;y<x;y+=3){let _=a.getX(y),w=a.getX(y+1),S=a.getX(y+2);i=il(this,r,e,s,l,u,h,_,w,S),i&&(i.faceIndex=Math.floor(y/3),t.push(i))}}else if(c!==void 0)if(Array.isArray(r))for(let m=0,g=d.length;m<g;m++){let y=d[m],x=r[y.materialIndex],_=Math.max(y.start,p.start),w=Math.min(c.count,Math.min(y.start+y.count,p.start+p.count));for(let S=_,E=w;S<E;S+=3){let B=S,N=S+1,C=S+2;i=il(this,x,e,s,l,u,h,B,N,C),i&&(i.faceIndex=Math.floor(S/3),i.face.materialIndex=y.materialIndex,t.push(i))}}else{let m=Math.max(0,p.start),g=Math.min(c.count,p.start+p.count);for(let y=m,x=g;y<x;y+=3){let _=y,w=y+1,S=y+2;i=il(this,r,e,s,l,u,h,_,w,S),i&&(i.faceIndex=Math.floor(y/3),t.push(i))}}}};function $1(o,e,t,s,i,n,r,a){let c;if(e.side===rt?c=s.intersectTriangle(r,n,i,!0,a):c=s.intersectTriangle(i,n,r,e.side===_s,a),c===null)return null;sl.copy(a),sl.applyMatrix4(o.matrixWorld);let l=t.ray.origin.distanceTo(sl);return l<t.near||l>t.far?null:{distance:l,point:sl.clone(),object:o}}function il(o,e,t,s,i,n,r,a,c,l){o.getVertexPosition(a,Qc),o.getVertexPosition(c,Kc),o.getVertexPosition(l,el);let u=$1(o,e,t,s,Qc,Kc,el,O0);if(u){let h=new R;Ki.getBarycoord(O0,Qc,Kc,el,h),i&&(u.uv=Ki.getInterpolatedAttribute(i,a,c,l,h,new re)),n&&(u.uv1=Ki.getInterpolatedAttribute(n,a,c,l,h,new re)),r&&(u.normal=Ki.getInterpolatedAttribute(r,a,c,l,h,new R),u.normal.dot(s.direction)>0&&u.normal.multiplyScalar(-1));let d={a,b:c,c:l,normal:new R,materialIndex:0};Ki.getNormal(Qc,Kc,el,d.normal),u.face=d,u.barycoord=h}return u}var Qo=class extends xt{constructor(e=null,t=1,s=1,i,n,r,a,c,l=Ue,u=Ue,h,d){super(null,r,a,c,l,u,i,n,h,d),this.isDataTexture=!0,this.image={data:e,width:t,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}};var Ai=class extends yt{constructor(e,t,s,i=1){super(e,t,s),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){let e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}};var Jd=new R,q1=new R,H1=new Nt,xs=class{constructor(e=new R(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,s,i){return this.normal.set(e,t,s),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,s){let i=Jd.subVectors(s,t).cross(q1.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){let s=e.delta(Jd),i=this.normal.dot(s);if(i===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let n=-(e.start.dot(this.normal)+this.constant)/i;return n<0||n>1?null:t.copy(e.start).addScaledVector(s,n)}intersectsLine(e){let t=this.distanceToPoint(e.start),s=this.distanceToPoint(e.end);return t<0&&s>0||s<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let s=t||H1.getNormalMatrix(e),i=this.coplanarPoint(Jd).applyMatrix4(e),n=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(n),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}},Bn=new Vn,X1=new re(.5,.5),nl=new R,Ur=class{constructor(e=new xs,t=new xs,s=new xs,i=new xs,n=new xs,r=new xs){this.planes=[e,t,s,i,n,r]}set(e,t,s,i,n,r){let a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(s),a[3].copy(i),a[4].copy(n),a[5].copy(r),this}copy(e){let t=this.planes;for(let s=0;s<6;s++)t[s].copy(e.planes[s]);return this}setFromProjectionMatrix(e,t=Dt,s=!1){let i=this.planes,n=e.elements,r=n[0],a=n[1],c=n[2],l=n[3],u=n[4],h=n[5],d=n[6],p=n[7],m=n[8],g=n[9],y=n[10],x=n[11],_=n[12],w=n[13],S=n[14],E=n[15];if(i[0].setComponents(l-r,p-u,x-m,E-_).normalize(),i[1].setComponents(l+r,p+u,x+m,E+_).normalize(),i[2].setComponents(l+a,p+h,x+g,E+w).normalize(),i[3].setComponents(l-a,p-h,x-g,E-w).normalize(),s)i[4].setComponents(c,d,y,S).normalize(),i[5].setComponents(l-c,p-d,x-y,E-S).normalize();else if(i[4].setComponents(l-c,p-d,x-y,E-S).normalize(),t===Dt)i[5].setComponents(l+c,p+d,x+y,E+S).normalize();else if(t===Yt)i[5].setComponents(c,d,y,S).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Bn.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Bn.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Bn)}intersectsSprite(e){Bn.center.set(0,0,0);let t=X1.distanceTo(e.center);return Bn.radius=.7071067811865476+t,Bn.applyMatrix4(e.matrixWorld),this.intersectsSphere(Bn)}intersectsSphere(e){let t=this.planes,s=e.center,i=-e.radius;for(let n=0;n<6;n++)if(t[n].distanceToPoint(s)<i)return!1;return!0}intersectsBox(e){let t=this.planes;for(let s=0;s<6;s++){let i=t[s];if(nl.x=i.normal.x>0?e.max.x:e.min.x,nl.y=i.normal.y>0?e.max.y:e.min.y,nl.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(nl)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let s=0;s<6;s++)if(t[s].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}},ks=new de,zs=new Ur,Tl=class o{constructor(){this.coordinateSystem=Dt}intersectsObject(e,t){if(!t.isArrayCamera||t.cameras.length===0)return!1;for(let s=0;s<t.cameras.length;s++){let i=t.cameras[s];if(ks.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),zs.setFromProjectionMatrix(ks,i.coordinateSystem,i.reversedDepth),zs.intersectsObject(e))return!0}return!1}intersectsSprite(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let s=0;s<t.cameras.length;s++){let i=t.cameras[s];if(ks.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),zs.setFromProjectionMatrix(ks,i.coordinateSystem,i.reversedDepth),zs.intersectsSprite(e))return!0}return!1}intersectsSphere(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let s=0;s<t.cameras.length;s++){let i=t.cameras[s];if(ks.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),zs.setFromProjectionMatrix(ks,i.coordinateSystem,i.reversedDepth),zs.intersectsSphere(e))return!0}return!1}intersectsBox(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let s=0;s<t.cameras.length;s++){let i=t.cameras[s];if(ks.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),zs.setFromProjectionMatrix(ks,i.coordinateSystem,i.reversedDepth),zs.intersectsBox(e))return!0}return!1}containsPoint(e,t){if(!t||!t.cameras||t.cameras.length===0)return!1;for(let s=0;s<t.cameras.length;s++){let i=t.cameras[s];if(ks.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),zs.setFromProjectionMatrix(ks,i.coordinateSystem,i.reversedDepth),zs.containsPoint(e))return!0}return!1}clone(){return new o}};var Ko=class extends _t{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new ge(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}};var Sl=class extends _t{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new ge(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}};var Or=class extends xt{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=Ue,this.minFilter=Ue,this.generateMipmaps=!1,this.needsUpdate=!0}};var kn=class extends xt{constructor(e=[],t=qn,s,i,n,r,a,c,l,u){super(e,t,s,i,n,r,a,c,l,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}};var Rt=class extends xt{constructor(e,t,s=Oe,i,n,r,a=Ue,c=Ue,l,u=ns,h=1){if(u!==ns&&u!==Hs)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");let d={width:e,height:t,depth:h};super(d,i,n,r,a,c,u,s,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new Lr(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}},vl=class extends Rt{constructor(e,t=Oe,s=qn,i,n,r=Ue,a=Ue,c,l=ns){let u={width:e,height:e,depth:1},h=[u,u,u,u,u,u];super(e,e,t,s,i,n,r,a,c,l),this.image=h,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}};var ea=class o extends vs{constructor(e=1,t=1,s=1,i=1,n=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:s,widthSegments:i,heightSegments:n,depthSegments:r};let a=this;i=Math.floor(i),n=Math.floor(n),r=Math.floor(r);let c=[],l=[],u=[],h=[],d=0,p=0;m("z","y","x",-1,-1,s,t,e,r,n,0),m("z","y","x",1,-1,s,t,-e,r,n,1),m("x","z","y",1,1,e,s,t,i,r,2),m("x","z","y",1,-1,e,s,-t,i,r,3),m("x","y","z",1,-1,e,t,s,i,n,4),m("x","y","z",-1,-1,e,t,-s,i,n,5),this.setIndex(c),this.setAttribute("position",new nt(l,3)),this.setAttribute("normal",new nt(u,3)),this.setAttribute("uv",new nt(h,2));function m(g,y,x,_,w,S,E,B,N,C,I){let k=S/N,W=E/C,X=S/2,Y=E/2,ee=B/2,Q=N+1,ie=C+1,Pe=0,Se=0,ae=new R;for(let fe=0;fe<ie;fe++){let Fe=fe*W-Y;for(let Gt=0;Gt<Q;Gt++){let Vs=Gt*k-X;ae[g]=Vs*_,ae[y]=Fe*w,ae[x]=ee,l.push(ae.x,ae.y,ae.z),ae[g]=0,ae[y]=0,ae[x]=B>0?1:-1,u.push(ae.x,ae.y,ae.z),h.push(Gt/N),h.push(1-fe/C),Pe+=1}}for(let fe=0;fe<C;fe++)for(let Fe=0;Fe<N;Fe++){let Gt=d+Fe+Q*fe,Vs=d+Fe+Q*(fe+1),Ed=d+(Fe+1)+Q*(fe+1),kc=d+(Fe+1)+Q*fe;c.push(Gt,Vs,kc),c.push(Vs,Ed,kc),Se+=6}a.addGroup(p,Se,I),p+=Se,d+=Pe}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new o(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}};var wl=class o extends vs{constructor(e=1,t=1,s=1,i=32,n=1,r=!1,a=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:s,radialSegments:i,heightSegments:n,openEnded:r,thetaStart:a,thetaLength:c};let l=this;i=Math.floor(i),n=Math.floor(n);let u=[],h=[],d=[],p=[],m=0,g=[],y=s/2,x=0;_(),r===!1&&(e>0&&w(!0),t>0&&w(!1)),this.setIndex(u),this.setAttribute("position",new nt(h,3)),this.setAttribute("normal",new nt(d,3)),this.setAttribute("uv",new nt(p,2));function _(){let S=new R,E=new R,B=0,N=(t-e)/s;for(let C=0;C<=n;C++){let I=[],k=C/n,W=k*(t-e)+e;for(let X=0;X<=i;X++){let Y=X/i,ee=Y*c+a,Q=Math.sin(ee),ie=Math.cos(ee);E.x=W*Q,E.y=-k*s+y,E.z=W*ie,h.push(E.x,E.y,E.z),S.set(Q,N,ie).normalize(),d.push(S.x,S.y,S.z),p.push(Y,1-k),I.push(m++)}g.push(I)}for(let C=0;C<i;C++)for(let I=0;I<n;I++){let k=g[I][C],W=g[I+1][C],X=g[I+1][C+1],Y=g[I][C+1];(e>0||I!==0)&&(u.push(k,W,Y),B+=3),(t>0||I!==n-1)&&(u.push(W,X,Y),B+=3)}l.addGroup(x,B,0),x+=B}function w(S){let E=m,B=new re,N=new R,C=0,I=S===!0?e:t,k=S===!0?1:-1;for(let X=1;X<=i;X++)h.push(0,y*k,0),d.push(0,k,0),p.push(.5,.5),m++;let W=m;for(let X=0;X<=i;X++){let ee=X/i*c+a,Q=Math.cos(ee),ie=Math.sin(ee);N.x=I*ie,N.y=y*k,N.z=I*Q,h.push(N.x,N.y,N.z),d.push(0,k,0),B.x=Q*.5+.5,B.y=ie*.5*k+.5,p.push(B.x,B.y),m++}for(let X=0;X<i;X++){let Y=E+X,ee=W+X;S===!0?u.push(ee,ee+1,Y):u.push(ee+1,ee,Y),C+=3}l.addGroup(x,C,S===!0?1:2),x+=C}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new o(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}};var Vr=class o extends vs{constructor(e=1,t=1,s=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:s,heightSegments:i};let n=e/2,r=t/2,a=Math.floor(s),c=Math.floor(i),l=a+1,u=c+1,h=e/a,d=t/c,p=[],m=[],g=[],y=[];for(let x=0;x<u;x++){let _=x*d-r;for(let w=0;w<l;w++){let S=w*h-n;m.push(S,-_,0),g.push(0,0,1),y.push(w/a),y.push(1-x/c)}}for(let x=0;x<c;x++)for(let _=0;_<a;_++){let w=_+l*x,S=_+l*(x+1),E=_+1+l*(x+1),B=_+1+l*x;p.push(w,S,B),p.push(S,E,B)}this.setIndex(p),this.setAttribute("position",new nt(m,3)),this.setAttribute("normal",new nt(g,3)),this.setAttribute("uv",new nt(y,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new o(e.width,e.height,e.widthSegments,e.heightSegments)}};var Ml=class o extends vs{constructor(e=1,t=32,s=16,i=0,n=Math.PI*2,r=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:s,phiStart:i,phiLength:n,thetaStart:r,thetaLength:a},t=Math.max(3,Math.floor(t)),s=Math.max(2,Math.floor(s));let c=Math.min(r+a,Math.PI),l=0,u=[],h=new R,d=new R,p=[],m=[],g=[],y=[];for(let x=0;x<=s;x++){let _=[],w=x/s,S=0;x===0&&r===0?S=.5/t:x===s&&c===Math.PI&&(S=-.5/t);for(let E=0;E<=t;E++){let B=E/t;h.x=-e*Math.cos(i+B*n)*Math.sin(r+w*a),h.y=e*Math.cos(r+w*a),h.z=e*Math.sin(i+B*n)*Math.sin(r+w*a),m.push(h.x,h.y,h.z),d.copy(h).normalize(),g.push(d.x,d.y,d.z),y.push(B+S,1-w),_.push(l++)}u.push(_)}for(let x=0;x<s;x++)for(let _=0;_<t;_++){let w=u[x][_+1],S=u[x][_],E=u[x+1][_],B=u[x+1][_+1];(x!==0||r>0)&&p.push(w,S,B),(x!==s-1||c<Math.PI)&&p.push(S,E,B)}this.setIndex(p),this.setAttribute("position",new nt(m,3)),this.setAttribute("normal",new nt(g,3)),this.setAttribute("uv",new nt(y,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new o(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}};var Al=class extends _t{constructor(e){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new ge(0),this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.fog=e.fog,this}};var ta=class extends _t{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new ge(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ge(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new jt,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},Nl=class extends ta{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new re(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return ue(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new ge(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new ge(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new ge(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}},Rl=class extends _t{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new ge(16777215),this.specular=new ge(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ge(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new jt,this.combine=aa,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},Cl=class extends _t{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new ge(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ge(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},El=class extends _t{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}},Bl=class extends _t{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new ge(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ge(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new jt,this.combine=aa,this.reflectivity=1,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.envMapIntensity=e.envMapIntensity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}};var Fl=class extends _t{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new ge(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Xs,this.normalScale=new re(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this.fog=e.fog,this}},Il=class extends Ko{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}};function rl(o,e){return!o||o.constructor===e?o:typeof e.BYTES_PER_ELEMENT=="number"?new e(o):Array.prototype.slice.call(o)}var tn=class{constructor(e,t,s,i){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=i!==void 0?i:new t.constructor(s),this.sampleValues=t,this.valueSize=s,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,s=this._cachedIndex,i=t[s],n=t[s-1];s:{e:{let r;t:{i:if(!(e<i)){for(let a=s+2;;){if(i===void 0){if(e<n)break i;return s=t.length,this._cachedIndex=s,this.copySampleValue_(s-1)}if(s===a)break;if(n=i,i=t[++s],e<i)break e}r=t.length;break t}if(!(e>=n)){let a=t[1];e<a&&(s=2,n=a);for(let c=s-2;;){if(n===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(s===c)break;if(i=n,n=t[--s-1],e>=n)break e}r=s,s=0;break t}break s}for(;s<r;){let a=s+r>>>1;e<t[a]?r=a:s=a+1}if(i=t[s],n=t[s-1],n===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===void 0)return s=t.length,this._cachedIndex=s,this.copySampleValue_(s-1)}this._cachedIndex=s,this.intervalChanged_(s,n,i)}return this.interpolate_(s,n,e,i)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){let t=this.resultBuffer,s=this.sampleValues,i=this.valueSize,n=e*i;for(let r=0;r!==i;++r)t[r]=s[n+r];return t}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}},Pl=class extends tn{constructor(e,t,s,i){super(e,t,s,i),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:ep,endingEnd:ep}}intervalChanged_(e,t,s){let i=this.parameterPositions,n=e-2,r=e+1,a=i[n],c=i[r];if(a===void 0)switch(this.getSettings_().endingStart){case tp:n=e,a=2*t-s;break;case sp:n=i.length-2,a=t+i[n]-i[n+1];break;default:n=e,a=s}if(c===void 0)switch(this.getSettings_().endingEnd){case tp:r=e,c=2*s-t;break;case sp:r=1,c=s+i[1]-i[0];break;default:r=e-1,c=t}let l=(s-t)*.5,u=this.valueSize;this._weightPrev=l/(t-a),this._weightNext=l/(c-s),this._offsetPrev=n*u,this._offsetNext=r*u}interpolate_(e,t,s,i){let n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,c=e*a,l=c-a,u=this._offsetPrev,h=this._offsetNext,d=this._weightPrev,p=this._weightNext,m=(s-t)/(i-t),g=m*m,y=g*m,x=-d*y+2*d*g-d*m,_=(1+d)*y+(-1.5-2*d)*g+(-.5+d)*m+1,w=(-1-p)*y+(1.5+p)*g+.5*m,S=p*y-p*g;for(let E=0;E!==a;++E)n[E]=x*r[u+E]+_*r[l+E]+w*r[c+E]+S*r[h+E];return n}},Dl=class extends tn{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e,t,s,i){let n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,c=e*a,l=c-a,u=(s-t)/(i-t),h=1-u;for(let d=0;d!==a;++d)n[d]=r[l+d]*h+r[c+d]*u;return n}},Ll=class extends tn{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e){return this.copySampleValue_(e-1)}},Ul=class extends tn{interpolate_(e,t,s,i){let n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,c=e*a,l=c-a,u=this.settings||this.DefaultSettings_,h=u.inTangents,d=u.outTangents;if(!h||!d){let g=(s-t)/(i-t),y=1-g;for(let x=0;x!==a;++x)n[x]=r[l+x]*y+r[c+x]*g;return n}let p=a*2,m=e-1;for(let g=0;g!==a;++g){let y=r[l+g],x=r[c+g],_=m*p+g*2,w=d[_],S=d[_+1],E=e*p+g*2,B=h[E],N=h[E+1],C=(s-t)/(i-t),I,k,W,X,Y;for(let ee=0;ee<8;ee++){I=C*C,k=I*C,W=1-C,X=W*W,Y=X*W;let ie=Y*t+3*X*C*w+3*W*I*B+k*i-s;if(Math.abs(ie)<1e-10)break;let Pe=3*X*(w-t)+6*W*C*(B-w)+3*I*(i-B);if(Math.abs(Pe)<1e-10)break;C=C-ie/Pe,C=Math.max(0,Math.min(1,C))}n[g]=Y*y+3*X*C*S+3*W*I*N+k*x}return n}},Jt=class{constructor(e,t,s,i){if(e===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(t===void 0||t.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+e);this.name=e,this.times=rl(t,this.TimeBufferType),this.values=rl(s,this.ValueBufferType),this.setInterpolation(i||this.DefaultInterpolation)}static toJSON(e){let t=e.constructor,s;if(t.toJSON!==this.toJSON)s=t.toJSON(e);else{s={name:e.name,times:rl(e.times,Array),values:rl(e.values,Array)};let i=e.getInterpolation();i!==e.DefaultInterpolation&&(s.interpolation=i)}return s.type=e.ValueTypeName,s}InterpolantFactoryMethodDiscrete(e){return new Ll(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new Dl(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Pl(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){let t=new Ul(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.settings=this.settings),t}setInterpolation(e){let t;switch(e){case qo:t=this.InterpolantFactoryMethodDiscrete;break;case ul:t=this.InterpolantFactoryMethodLinear;break;case cl:t=this.InterpolantFactoryMethodSmooth;break;case Kd:t=this.InterpolantFactoryMethodBezier;break}if(t===void 0){let s="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(s);return z("KeyframeTrack:",s),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return qo;case this.InterpolantFactoryMethodLinear:return ul;case this.InterpolantFactoryMethodSmooth:return cl;case this.InterpolantFactoryMethodBezier:return Kd}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){let t=this.times;for(let s=0,i=t.length;s!==i;++s)t[s]+=e}return this}scale(e){if(e!==1){let t=this.times;for(let s=0,i=t.length;s!==i;++s)t[s]*=e}return this}trim(e,t){let s=this.times,i=s.length,n=0,r=i-1;for(;n!==i&&s[n]<e;)++n;for(;r!==-1&&s[r]>t;)--r;if(++r,n!==0||r!==i){n>=r&&(r=Math.max(r,1),n=r-1);let a=this.getValueSize();this.times=s.slice(n,r),this.values=this.values.slice(n*a,r*a)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(O("KeyframeTrack: Invalid value size in track.",this),e=!1);let s=this.times,i=this.values,n=s.length;n===0&&(O("KeyframeTrack: Track is empty.",this),e=!1);let r=null;for(let a=0;a!==n;a++){let c=s[a];if(typeof c=="number"&&isNaN(c)){O("KeyframeTrack: Time is not a valid number.",this,a,c),e=!1;break}if(r!==null&&r>c){O("KeyframeTrack: Out of order keys.",this,a,c,r),e=!1;break}r=c}if(i!==void 0&&Kr(i))for(let a=0,c=i.length;a!==c;++a){let l=i[a];if(isNaN(l)){O("KeyframeTrack: Value is not a valid number.",this,a,l),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===cl,n=e.length-1,r=1;for(let a=1;a<n;++a){let c=!1,l=e[a],u=e[a+1];if(l!==u&&(a!==1||l!==e[0]))if(i)c=!0;else{let h=a*s,d=h-s,p=h+s;for(let m=0;m!==s;++m){let g=t[h+m];if(g!==t[d+m]||g!==t[p+m]){c=!0;break}}}if(c){if(a!==r){e[r]=e[a];let h=a*s,d=r*s;for(let p=0;p!==s;++p)t[d+p]=t[h+p]}++r}}if(n>0){e[r]=e[n];for(let a=n*s,c=r*s,l=0;l!==s;++l)t[c+l]=t[a+l];++r}return r!==e.length?(this.times=e.slice(0,r),this.values=t.slice(0,r*s)):(this.times=e,this.values=t),this}clone(){let e=this.times.slice(),t=this.values.slice(),s=this.constructor,i=new s(this.name,e,t);return i.createInterpolant=this.createInterpolant,i}};Jt.prototype.ValueTypeName="";Jt.prototype.TimeBufferType=Float32Array;Jt.prototype.ValueBufferType=Float32Array;Jt.prototype.DefaultInterpolation=ul;var sn=class extends Jt{constructor(e,t,s){super(e,t,s)}};sn.prototype.ValueTypeName="bool";sn.prototype.ValueBufferType=Array;sn.prototype.DefaultInterpolation=qo;sn.prototype.InterpolantFactoryMethodLinear=void 0;sn.prototype.InterpolantFactoryMethodSmooth=void 0;var Ol=class extends Jt{constructor(e,t,s,i){super(e,t,s,i)}};Ol.prototype.ValueTypeName="color";var Vl=class extends Jt{constructor(e,t,s,i){super(e,t,s,i)}};Vl.prototype.ValueTypeName="number";var kl=class extends tn{constructor(e,t,s,i){super(e,t,s,i)}interpolate_(e,t,s,i){let n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,c=(s-t)/(i-t),l=e*a;for(let u=l+a;l!==u;l+=4)Ss.slerpFlat(n,0,r,l-a,r,l,c);return n}},sa=class extends Jt{constructor(e,t,s,i){super(e,t,s,i)}InterpolantFactoryMethodLinear(e){return new kl(this.times,this.values,this.getValueSize(),e)}};sa.prototype.ValueTypeName="quaternion";sa.prototype.InterpolantFactoryMethodSmooth=void 0;var nn=class extends Jt{constructor(e,t,s){super(e,t,s)}};nn.prototype.ValueTypeName="string";nn.prototype.ValueBufferType=Array;nn.prototype.DefaultInterpolation=qo;nn.prototype.InterpolantFactoryMethodLinear=void 0;nn.prototype.InterpolantFactoryMethodSmooth=void 0;var zl=class extends Jt{constructor(e,t,s,i){super(e,t,s,i)}};zl.prototype.ValueTypeName="vector";var ll={enabled:!1,files:{},add:function(o,e){this.enabled!==!1&&(V0(o)||(this.files[o]=e))},get:function(o){if(this.enabled!==!1&&!V0(o))return this.files[o]},remove:function(o){delete this.files[o]},clear:function(){this.files={}}};function V0(o){try{let e=o.slice(o.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}var Gl=class{constructor(e,t,s){let i=this,n=!1,r=0,a=0,c,l=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s,this._abortController=null,this.itemStart=function(u){a++,n===!1&&i.onStart!==void 0&&i.onStart(u,r,a),n=!0},this.itemEnd=function(u){r++,i.onProgress!==void 0&&i.onProgress(u,r,a),r===a&&(n=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return c?c(u):u},this.setURLModifier=function(u){return c=u,this},this.addHandler=function(u,h){return l.push(u,h),this},this.removeHandler=function(u){let h=l.indexOf(u);return h!==-1&&l.splice(h,2),this},this.getHandler=function(u){for(let h=0,d=l.length;h<d;h+=2){let p=l[h],m=l[h+1];if(p.global&&(p.lastIndex=0),p.test(u))return m}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}},Rb=new Gl,kr=class{constructor(e){this.manager=e!==void 0?e:Rb,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){let s=this;return new Promise(function(i,n){s.load(e,i,t,n)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}abort(){return this}};kr.DEFAULT_MATERIAL_NAME="__DEFAULT";var Cr=new WeakMap,Wl=class extends kr{constructor(e){super(e)}load(e,t,s,i){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let n=this,r=ll.get(`image:${e}`);if(r!==void 0){if(r.complete===!0)n.manager.itemStart(e),setTimeout(function(){t&&t(r),n.manager.itemEnd(e)},0);else{let h=Cr.get(r);h===void 0&&(h=[],Cr.set(r,h)),h.push({onLoad:t,onError:i})}return r}let a=dl("img");function c(){u(),t&&t(this);let h=Cr.get(this)||[];for(let d=0;d<h.length;d++){let p=h[d];p.onLoad&&p.onLoad(this)}Cr.delete(this),n.manager.itemEnd(e)}function l(h){u(),i&&i(h),ll.remove(`image:${e}`);let d=Cr.get(this)||[];for(let p=0;p<d.length;p++){let m=d[p];m.onError&&m.onError(h)}Cr.delete(this),n.manager.itemError(e),n.manager.itemEnd(e)}function u(){a.removeEventListener("load",c,!1),a.removeEventListener("error",l,!1)}return a.addEventListener("load",c,!1),a.addEventListener("error",l,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),ll.add(`image:${e}`,a),n.manager.itemStart(e),a.src=e,a}};var ia=class extends kr{constructor(e){super(e)}load(e,t,s,i){let n=new xt,r=new Wl(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(e,function(a){n.image=a,n.needsUpdate=!0,t!==void 0&&t(n)},s,i),n}},Ws=class extends tt{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new ge(e),this.intensity=t}dispose(){this.dispatchEvent({type:"dispose"})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){let t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}},$l=class extends Ws{constructor(e,t,s){super(e,s),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.groundColor=new ge(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){let t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}},Qd=new de,k0=new R,z0=new R,na=class{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new re(512,512),this.mapType=lt,this.map=null,this.mapPass=null,this.matrix=new de,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ur,this._frameExtents=new re(1,1),this._viewportCount=1,this._viewports=[new Te(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera,s=this.matrix;k0.setFromMatrixPosition(e.matrixWorld),t.position.copy(k0),z0.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(z0),t.updateMatrixWorld(),Qd.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Qd,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===Yt||t.reversedDepth?s.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):s.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),s.multiply(Qd)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){let e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}},ol=new R,al=new Ss,Gs=new R,ra=class extends tt{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new de,this.projectionMatrix=new de,this.projectionMatrixInverse=new de,this.coordinateSystem=Dt,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(ol,al,Gs),Gs.x===1&&Gs.y===1&&Gs.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(ol,al,Gs.set(1,1,1)).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorld.decompose(ol,al,Gs),Gs.x===1&&Gs.y===1&&Gs.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(ol,al,Gs.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}},Ji=new R,G0=new re,W0=new re,it=class extends ra{constructor(e=50,t=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=Un*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(Lo*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return Un*2*Math.atan(Math.tan(Lo*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,s){Ji.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Ji.x,Ji.y).multiplyScalar(-e/Ji.z),Ji.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Ji.x,Ji.y).multiplyScalar(-e/Ji.z)}getViewSize(e,t){return this.getViewBounds(e,G0,W0),t.subVectors(W0,G0)}setViewOffset(e,t,s,i,n,r){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=s,this.view.offsetY=i,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(Lo*.5*this.fov)/this.zoom,s=2*t,i=this.aspect*s,n=-.5*i,r=this.view;if(this.view!==null&&this.view.enabled){let c=r.fullWidth,l=r.fullHeight;n+=r.offsetX*i/c,t-=r.offsetY*s/l,i*=r.width/c,s*=r.height/l}let a=this.filmOffset;a!==0&&(n+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(n,n+i,t,t-s,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}},ip=class extends na{constructor(){super(new it(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){let t=this.camera,s=Un*2*e.angle*this.focus,i=this.mapSize.width/this.mapSize.height*this.aspect,n=e.distance||t.far;(s!==t.fov||i!==t.aspect||n!==t.far)&&(t.fov=s,t.aspect=i,t.far=n,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this}},zr=class extends Ws{constructor(e,t,s=0,i=Math.PI/3,n=0,r=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.target=new tt,this.distance=s,this.angle=i,this.penumbra=n,this.decay=r,this.map=null,this.shadow=new ip}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}},np=class extends na{constructor(){super(new it(90,1,.5,500)),this.isPointLightShadow=!0}},ql=class extends Ws{constructor(e,t,s=0,i=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=s,this.decay=i,this.shadow=new np}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}},Gr=class extends ra{constructor(e=-1,t=1,s=1,i=-1,n=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=s,this.bottom=i,this.near=n,this.far=r,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,s,i,n,r){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=s,this.view.offsetY=i,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),s=(this.right+this.left)/2,i=(this.top+this.bottom)/2,n=s-e,r=s+e,a=i+t,c=i-t;if(this.view!==null&&this.view.enabled){let l=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;n+=l*this.view.offsetX,r=n+l*this.view.width,a-=u*this.view.offsetY,c=a-u*this.view.height}this.projectionMatrix.makeOrthographic(n,r,a,c,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}},rp=class extends na{constructor(){super(new Gr(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}},Hl=class extends Ws{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.target=new tt,this.shadow=new rp}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}},Xl=class extends Ws{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}},Yl=class extends Ws{constructor(e,t,s=10,i=10){super(e,t),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=s,this.height=i}get power(){return this.intensity*this.width*this.height*Math.PI}set power(e){this.intensity=e/(this.width*this.height*Math.PI)}copy(e){return super.copy(e),this.width=e.width,this.height=e.height,this}toJSON(e){let t=super.toJSON(e);return t.object.width=this.width,t.object.height=this.height,t}},jl=class{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let e=0;e<9;e++)this.coefficients.push(new R)}set(e){for(let t=0;t<9;t++)this.coefficients[t].copy(e[t]);return this}zero(){for(let e=0;e<9;e++)this.coefficients[e].set(0,0,0);return this}getAt(e,t){let s=e.x,i=e.y,n=e.z,r=this.coefficients;return t.copy(r[0]).multiplyScalar(.282095),t.addScaledVector(r[1],.488603*i),t.addScaledVector(r[2],.488603*n),t.addScaledVector(r[3],.488603*s),t.addScaledVector(r[4],1.092548*(s*i)),t.addScaledVector(r[5],1.092548*(i*n)),t.addScaledVector(r[6],.315392*(3*n*n-1)),t.addScaledVector(r[7],1.092548*(s*n)),t.addScaledVector(r[8],.546274*(s*s-i*i)),t}getIrradianceAt(e,t){let s=e.x,i=e.y,n=e.z,r=this.coefficients;return t.copy(r[0]).multiplyScalar(.886227),t.addScaledVector(r[1],2*.511664*i),t.addScaledVector(r[2],2*.511664*n),t.addScaledVector(r[3],2*.511664*s),t.addScaledVector(r[4],2*.429043*s*i),t.addScaledVector(r[5],2*.429043*i*n),t.addScaledVector(r[6],.743125*n*n-.247708),t.addScaledVector(r[7],2*.429043*s*n),t.addScaledVector(r[8],.429043*(s*s-i*i)),t}add(e){for(let t=0;t<9;t++)this.coefficients[t].add(e.coefficients[t]);return this}addScaledSH(e,t){for(let s=0;s<9;s++)this.coefficients[s].addScaledVector(e.coefficients[s],t);return this}scale(e){for(let t=0;t<9;t++)this.coefficients[t].multiplyScalar(e);return this}lerp(e,t){for(let s=0;s<9;s++)this.coefficients[s].lerp(e.coefficients[s],t);return this}equals(e){for(let t=0;t<9;t++)if(!this.coefficients[t].equals(e.coefficients[t]))return!1;return!0}copy(e){return this.set(e.coefficients)}clone(){return new this.constructor().copy(this)}fromArray(e,t=0){let s=this.coefficients;for(let i=0;i<9;i++)s[i].fromArray(e,t+i*3);return this}toArray(e=[],t=0){let s=this.coefficients;for(let i=0;i<9;i++)s[i].toArray(e,t+i*3);return e}static getBasisAt(e,t){let s=e.x,i=e.y,n=e.z;t[0]=.282095,t[1]=.488603*i,t[2]=.488603*n,t[3]=.488603*s,t[4]=1.092548*s*i,t[5]=1.092548*i*n,t[6]=.315392*(3*n*n-1),t[7]=1.092548*s*n,t[8]=.546274*(s*s-i*i)}},Zl=class extends Ws{constructor(e=new jl,t=1){super(void 0,t),this.isLightProbe=!0,this.sh=e}copy(e){return super.copy(e),this.sh.copy(e.sh),this}toJSON(e){let t=super.toJSON(e);return t.object.sh=this.sh.toArray(),t}};var Er=-90,Br=1,Jl=class extends tt{constructor(e,t,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;let i=new it(Er,Br,e,t);i.layers=this.layers,this.add(i);let n=new it(Er,Br,e,t);n.layers=this.layers,this.add(n);let r=new it(Er,Br,e,t);r.layers=this.layers,this.add(r);let a=new it(Er,Br,e,t);a.layers=this.layers,this.add(a);let c=new it(Er,Br,e,t);c.layers=this.layers,this.add(c);let l=new it(Er,Br,e,t);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[s,i,n,r,a,c]=t;for(let l of t)this.remove(l);if(e===Dt)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),n.up.set(0,0,-1),n.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(e===Yt)s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),n.up.set(0,0,1),n.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(let l of t)this.add(l),l.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[n,r,a,c,l,u]=this.children,h=e.getRenderTarget(),d=e.getActiveCubeFace(),p=e.getActiveMipmapLevel(),m=e.xr.enabled;e.xr.enabled=!1;let g=s.texture.generateMipmaps;s.texture.generateMipmaps=!1;let y=!1;e.isWebGLRenderer===!0?y=e.state.buffers.depth.getReversed():y=e.reversedDepthBuffer,e.setRenderTarget(s,0,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,n),e.setRenderTarget(s,1,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,r),e.setRenderTarget(s,2,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(s,3,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),e.setRenderTarget(s,4,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),s.texture.generateMipmaps=g,e.setRenderTarget(s,5,i),y&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),e.setRenderTarget(h,d,p),e.xr.enabled=m,s.texture.needsPMREMUpdate=!0}},Ql=class extends it{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}};var Cp="\\[\\]\\.:\\/",Y1=new RegExp("["+Cp+"]","g"),Ep="[^"+Cp+"]",j1="[^"+Cp.replace("\\.","")+"]",Z1=/((?:WC+[\/:])*)/.source.replace("WC",Ep),J1=/(WCOD+)?/.source.replace("WCOD",j1),Q1=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Ep),K1=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Ep),eM=new RegExp("^"+Z1+J1+Q1+K1+"$"),tM=["material","materials","bones","map"],op=class{constructor(e,t,s){let i=s||De.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,i)}getValue(e,t){this.bind();let s=this._targetGroup.nCachedObjects_,i=this._bindings[s];i!==void 0&&i.getValue(e,t)}setValue(e,t){let s=this._bindings;for(let i=this._targetGroup.nCachedObjects_,n=s.length;i!==n;++i)s[i].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,s=e.length;t!==s;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,s=e.length;t!==s;++t)e[t].unbind()}},De=class o{constructor(e,t,s){this.path=t,this.parsedPath=s||o.parseTrackName(t),this.node=o.findNode(e,this.parsedPath.nodeName),this.rootNode=e,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(e,t,s){return e&&e.isAnimationObjectGroup?new o.Composite(e,t,s):new o(e,t,s)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(Y1,"")}static parseTrackName(e){let t=eM.exec(e);if(t===null)throw new Error("PropertyBinding: Cannot parse trackName: "+e);let s={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(i!==void 0&&i!==-1){let n=s.nodeName.substring(i+1);tM.indexOf(n)!==-1&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=n)}if(s.propertyName===null||s.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+e);return s}static findNode(e,t){if(t===void 0||t===""||t==="."||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let s=e.skeleton.getBoneByName(t);if(s!==void 0)return s}if(e.children){let s=function(n){for(let r=0;r<n.length;r++){let a=n[r];if(a.name===t||a.uuid===t)return a;let c=s(a.children);if(c)return c}return null},i=s(e.children);if(i)return i}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){let s=this.resolvedProperty;for(let i=0,n=s.length;i!==n;++i)e[t++]=s[i]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){let s=this.resolvedProperty;for(let i=0,n=s.length;i!==n;++i)s[i]=e[t++]}_setValue_array_setNeedsUpdate(e,t){let s=this.resolvedProperty;for(let i=0,n=s.length;i!==n;++i)s[i]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){let s=this.resolvedProperty;for(let i=0,n=s.length;i!==n;++i)s[i]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let e=this.node,t=this.parsedPath,s=t.objectName,i=t.propertyName,n=t.propertyIndex;if(e||(e=o.findNode(this.rootNode,t.nodeName),this.node=e),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!e){z("PropertyBinding: No target node found for track: "+this.path+".");return}if(s){let l=t.objectIndex;switch(s){case"materials":if(!e.material){O("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.materials){O("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}e=e.material.materials;break;case"bones":if(!e.skeleton){O("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}e=e.skeleton.bones;for(let u=0;u<e.length;u++)if(e[u].name===l){l=u;break}break;case"map":if("map"in e){e=e.map;break}if(!e.material){O("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.map){O("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}e=e.material.map;break;default:if(e[s]===void 0){O("PropertyBinding: Can not bind to objectName of node undefined.",this);return}e=e[s]}if(l!==void 0){if(e[l]===void 0){O("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,e);return}e=e[l]}}let r=e[i];if(r===void 0){let l=t.nodeName;O("PropertyBinding: Trying to update property for track: "+l+"."+i+" but it wasn't found.",e);return}let a=this.Versioning.None;this.targetObject=e,e.isMaterial===!0?a=this.Versioning.NeedsUpdate:e.isObject3D===!0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let c=this.BindingType.Direct;if(n!==void 0){if(i==="morphTargetInfluences"){if(!e.geometry){O("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!e.geometry.morphAttributes){O("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}e.morphTargetDictionary[n]!==void 0&&(n=e.morphTargetDictionary[n])}c=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=n}else r.fromArray!==void 0&&r.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(c=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=i;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};De.Composite=op;De.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};De.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};De.prototype.GetterByBindingType=[De.prototype._getValue_direct,De.prototype._getValue_array,De.prototype._getValue_arrayElement,De.prototype._getValue_toArray];De.prototype.SetterByBindingTypeAndVersioning=[[De.prototype._setValue_direct,De.prototype._setValue_direct_setNeedsUpdate,De.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[De.prototype._setValue_array,De.prototype._setValue_array_setNeedsUpdate,De.prototype._setValue_array_setMatrixWorldNeedsUpdate],[De.prototype._setValue_arrayElement,De.prototype._setValue_arrayElement_setNeedsUpdate,De.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[De.prototype._setValue_fromArray,De.prototype._setValue_fromArray_setNeedsUpdate,De.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var yI=new Float32Array(1);var Kl=class extends Jo{constructor(e,t,s=1){super(e,t),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=s}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}clone(e){let t=super.clone(e);return t.meshPerAttribute=this.meshPerAttribute,t}toJSON(e){let t=super.toJSON(e);return t.isInstancedInterleavedBuffer=!0,t.meshPerAttribute=this.meshPerAttribute,t}};var oa=class o{constructor(e,t,s,i){o.prototype.isMatrix2=!0,this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let s=0;s<4;s++)this.elements[s]=e[s+t];return this}set(e,t,s,i){let n=this.elements;return n[0]=e,n[2]=t,n[1]=s,n[3]=i,this}};function Cb(o,e,t,s){let i=sM(s);switch(t){case Tp:return o*e;case ua:return o*e/i.components*i.byteLength;case ha:return o*e/i.components*i.byteLength;case Ms:return o*e*2/i.components*i.byteLength;case da:return o*e*2/i.components*i.byteLength;case la:return o*e*3/i.components*i.byteLength;case Lt:return o*e*4/i.components*i.byteLength;case pa:return o*e*4/i.components*i.byteLength;case qr:case Hr:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case Xr:case Yr:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case lu:case hu:return Math.max(o,16)*Math.max(e,8)/4;case cu:case uu:return Math.max(o,8)*Math.max(e,8)/2;case fa:case ma:case ya:case xa:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*8;case ga:case jr:case ba:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case _a:return Math.floor((o+3)/4)*Math.floor((e+3)/4)*16;case Ta:return Math.floor((o+4)/5)*Math.floor((e+3)/4)*16;case Sa:return Math.floor((o+4)/5)*Math.floor((e+4)/5)*16;case va:return Math.floor((o+5)/6)*Math.floor((e+4)/5)*16;case wa:return Math.floor((o+5)/6)*Math.floor((e+5)/6)*16;case Ma:return Math.floor((o+7)/8)*Math.floor((e+4)/5)*16;case Aa:return Math.floor((o+7)/8)*Math.floor((e+5)/6)*16;case Na:return Math.floor((o+7)/8)*Math.floor((e+7)/8)*16;case Ra:return Math.floor((o+9)/10)*Math.floor((e+4)/5)*16;case Ca:return Math.floor((o+9)/10)*Math.floor((e+5)/6)*16;case Ea:return Math.floor((o+9)/10)*Math.floor((e+7)/8)*16;case Ba:return Math.floor((o+9)/10)*Math.floor((e+9)/10)*16;case Fa:return Math.floor((o+11)/12)*Math.floor((e+9)/10)*16;case Ia:return Math.floor((o+11)/12)*Math.floor((e+11)/12)*16;case Pa:case ab:case cb:return Math.ceil(o/4)*Math.ceil(e/4)*16;case Da:case La:return Math.ceil(o/4)*Math.ceil(e/4)*8;case Zr:case Ua:return Math.ceil(o/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function sM(o){switch(o){case lt:case Hn:return{byteLength:1,components:1};case rn:case Xn:case $e:return{byteLength:2,components:1};case bp:case _p:return{byteLength:2,components:4};case Oe:case ut:case Ct:return{byteLength:4,components:1};case ou:case au:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${o}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"183"}}));typeof window<"u"&&(window.__THREE__?z("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="183");var iM=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],Bp=new WeakMap,ff=class{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=e.object.isSkinnedMesh===!0,this.refreshUniforms=iM,this.renderId=0}firstInitialization(e){return this.renderObjects.has(e)===!1?(this.getRenderObjectData(e),!0):!1}needsVelocity(e){let t=e.getMRT();return t!==null&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(t===void 0){let{geometry:s,material:i,object:n}=e;if(t={material:this.getMaterialData(i),geometry:{id:s.id,attributes:this.getAttributesData(s.attributes),indexId:s.index?s.index.id:null,indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:n.matrixWorld.clone()},n.center&&(t.center=n.center.clone()),n.morphTargetInfluences&&(t.morphTargetInfluences=n.morphTargetInfluences.slice()),e.bundle!==null&&(t.version=e.bundle.version),t.material.transmission>0){let{width:r,height:a}=e.context;t.bufferWidth=r,t.bufferHeight=a}t.lights=this.getLightsData(e.lightsNode.getLights()),this.renderObjects.set(e,t)}return t}getAttributesData(e){let t={};for(let s in e){let i=e[s];t[s]={id:i.id,version:i.version}}return t}containsNode(e){let t=e.material;for(let s in t)if(t[s]&&t[s].isNode)return!0;return!!(e.context.modelViewMatrix||e.context.modelNormalViewMatrix||e.context.getAO||e.context.getShadow)}getMaterialData(e){let t={};for(let s of this.refreshUniforms){let i=e[s];i!=null&&(typeof i=="object"&&i.clone!==void 0?i.isTexture===!0?t[s]={id:i.id,version:i.version}:t[s]=i.clone():t[s]=i)}return t}equals(e,t){let{object:s,material:i,geometry:n}=e,r=this.getRenderObjectData(e);if(r.worldMatrix.equals(s.matrixWorld)!==!0)return r.worldMatrix.copy(s.matrixWorld),!1;let a=r.material;for(let _ in a){let w=a[_],S=i[_];if(w.equals!==void 0){if(w.equals(S)===!1)return w.copy(S),!1}else if(S.isTexture===!0){if(w.id!==S.id||w.version!==S.version)return w.id=S.id,w.version=S.version,!1}else if(w!==S)return a[_]=S,!1}if(a.transmission>0){let{width:_,height:w}=e.context;if(r.bufferWidth!==_||r.bufferHeight!==w)return r.bufferWidth=_,r.bufferHeight=w,!1}let c=r.geometry,l=n.attributes,u=c.attributes,h=Object.keys(u),d=Object.keys(l);if(c.id!==n.id)return c.id=n.id,!1;if(h.length!==d.length)return r.geometry.attributes=this.getAttributesData(l),!1;for(let _ of h){let w=u[_],S=l[_];if(S===void 0)return delete u[_],!1;if(w.id!==S.id||w.version!==S.version)return w.id=S.id,w.version=S.version,!1}let p=n.index,m=c.indexId,g=c.indexVersion,y=p?p.id:null,x=p?p.version:null;if(m!==y||g!==x)return c.indexId=y,c.indexVersion=x,!1;if(c.drawRange.start!==n.drawRange.start||c.drawRange.count!==n.drawRange.count)return c.drawRange.start=n.drawRange.start,c.drawRange.count=n.drawRange.count,!1;if(r.morphTargetInfluences){let _=!1;for(let w=0;w<r.morphTargetInfluences.length;w++)r.morphTargetInfluences[w]!==s.morphTargetInfluences[w]&&(r.morphTargetInfluences[w]=s.morphTargetInfluences[w],_=!0);if(_)return!1}if(r.lights){for(let _=0;_<t.length;_++)if(r.lights[_].map!==t[_].map)return!1}return r.center&&r.center.equals(s.center)===!1?(r.center.copy(s.center),!0):(e.bundle!==null&&(r.version=e.bundle.version),!0)}getLightsData(e){let t=[];for(let s of e)s.isSpotLight===!0&&s.map!==null&&t.push({map:s.map.version});return t}getLights(e,t){if(Bp.has(e)){let i=Bp.get(e);if(i.renderId===t)return i.lightsData}let s=this.getLightsData(e.getLights());return Bp.set(e,{renderId:t,lightsData:s}),s}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.firstInitialization(e)||this.needsVelocity(t.renderer))return!0;let{renderId:s}=t;if(this.renderId!==s)return this.renderId=s,!0;let i=e.object.static===!0,n=e.bundle!==null&&e.bundle.static===!0&&this.getRenderObjectData(e).version===e.bundle.version;if(i||n)return!1;let r=this.getLights(e.lightsNode,s);return this.equals(e,r)!==!0}},nM=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];function rM(o){let e=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return o.split(`
|
|
`).map(t=>{let s=t.match(e);if(!s)return null;let i=s[1]||s[2]||"",n=s[3].split("?")[0],r=parseInt(s[4],10),a=parseInt(s[5],10),c=n.split("/").pop();return{fn:i,file:c,line:r,column:a}}).filter(t=>t&&!nM.some(s=>s.test(t.file)))}var ke=class{constructor(e=null){this.isStackTrace=!0,this.stack=rM(e||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";let e=this.stack[0],t=e.fn;return`${t?`"${t}()" at `:""}"${e.file}:${e.line}"`}getError(e){if(this.stack.length===0)return e;let t=this.stack.map(s=>{let i=`${s.file}:${s.line}:${s.column}`;return s.fn?` at ${s.fn} (${i})`:` at ${i}`}).join(`
|
|
`);return`${e}
|
|
${t}`}};function jy(o,e=0){let t=3735928559^e,s=1103547991^e;if(o instanceof Array)for(let i=0,n;i<o.length;i++)n=o[i],t=Math.imul(t^n,2654435761),s=Math.imul(s^n,1597334677);else for(let i=0,n;i<o.length;i++)n=o.charCodeAt(i),t=Math.imul(t^n,2654435761),s=Math.imul(s^n,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&s)+(t>>>0)}var Ro=o=>jy(o),Ec=o=>jy(o),sc=(...o)=>jy(o),oM=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Eb=new WeakMap;function Y_(o){return oM.get(o)}function Yu(o){if(/[iu]?vec\d/.test(o))return o.startsWith("ivec")?Int32Array:o.startsWith("uvec")?Uint32Array:Float32Array;if(/mat\d/.test(o)||/float/.test(o))return Float32Array;if(/uint/.test(o))return Uint32Array;if(/int/.test(o))return Int32Array;throw new Error(`THREE.NodeUtils: Unsupported type: ${o}`)}function j_(o){if(/float|int|uint/.test(o))return 1;if(/vec2/.test(o))return 2;if(/vec3/.test(o))return 3;if(/vec4/.test(o)||/mat2/.test(o))return 4;if(/mat3/.test(o))return 9;if(/mat4/.test(o))return 16;O(`TSL: Unsupported type: ${o}`,new ke)}function aM(o){if(/float|int|uint/.test(o))return 1;if(/vec2/.test(o))return 2;if(/vec3/.test(o))return 3;if(/vec4/.test(o)||/mat2/.test(o))return 4;if(/mat3/.test(o))return 12;if(/mat4/.test(o))return 16;O(`TSL: Unsupported type: ${o}`,new ke)}function cM(o){if(/float|int|uint/.test(o))return 4;if(/vec2/.test(o))return 8;if(/vec3/.test(o)||/vec4/.test(o))return 16;if(/mat2/.test(o))return 8;if(/mat3/.test(o)||/mat4/.test(o))return 16;O(`TSL: Unsupported type: ${o}`,new ke)}function fn(o){if(o==null)return null;let e=typeof o;return o.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":o.isVector2===!0?"vec2":o.isVector3===!0?"vec3":o.isVector4===!0?"vec4":o.isMatrix2===!0?"mat2":o.isMatrix3===!0?"mat3":o.isMatrix4===!0?"mat4":o.isColor===!0?"color":o instanceof ArrayBuffer?"ArrayBuffer":null}function Zy(o,...e){let t=o?o.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),o==="color"?new ge(...e):t==="vec2"?new re(...e):t==="vec3"?new R(...e):t==="vec4"?new Te(...e):t==="mat2"?new oa(...e):t==="mat3"?new Nt(...e):t==="mat4"?new de(...e):o==="bool"?e[0]||!1:o==="float"||o==="int"||o==="uint"?e[0]||0:o==="string"?e[0]||"":o==="ArrayBuffer"?uM(e[0]):null}function Z_(o){let e=Eb.get(o);return e===void 0&&(e={},Eb.set(o,e)),e}function lM(o){let e="",t=new Uint8Array(o);for(let s=0;s<t.length;s++)e+=String.fromCharCode(t[s]);return btoa(e)}function uM(o){return Uint8Array.from(atob(o),e=>e.charCodeAt(0)).buffer}var ec={VERTEX:"vertex",FRAGMENT:"fragment"},te={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},hM={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},dt={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},J_=["fragment","vertex"],mf=["setup","analyze","generate"],gf=[...J_,"compute"],fr=["x","y","z","w"],dM={analyze:"setup",generate:"analyze"},pM=0,H=class o extends Ts{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=te.NONE,this.updateBeforeType=te.NONE,this.updateAfterType=te.NONE,this.uuid=Va.generateUUID(),this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:pM++}),this.stackTrace=null,o.captureStackTrace===!0&&(this.stackTrace=new ke)}set needsUpdate(e){e===!0&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,te.FRAME)}onRenderUpdate(e){return this.onUpdate(e,te.RENDER)}onObjectUpdate(e){return this.onUpdate(e,te.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(let{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(let t of this.getChildren())t.traverse(e)}_getChildren(e=new Set){let t=[];e.add(this);for(let s of Object.getOwnPropertyNames(this)){let i=this[s];if(!(s.startsWith("_")===!0||e.has(i))){if(Array.isArray(i)===!0)for(let n=0;n<i.length;n++){let r=i[n];r&&r.isNode===!0&&t.push({property:s,index:n,childNode:r})}else if(i&&i.isNode===!0)t.push({property:s,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(let n in i){if(n.startsWith("_")===!0)continue;let r=i[n];r&&r.isNode===!0&&t.push({property:s,index:n,childNode:r})}}}return t}getCacheKey(e=!1,t=null){if(e=e||this.version!==this._cacheKeyVersion,e===!0||this._cacheKey===null){t===null&&(t=new Set);let s=[];for(let{property:i,childNode:n}of this._getChildren(t))s.push(Ro(i.slice(0,-4)),n.getCacheKey(e,t));this._cacheKey=sc(Ec(s),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){let t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e){let t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){let t=this.getHash(e);return e.getNodeFromHash(t)||this}getArrayCount(){return null}setup(e){let t=e.getNodeProperties(this),s=0;for(let i of this.getChildren())t["node"+s++]=i;return t.outputNode||null}analyze(e,t=null){let s=e.increaseUsage(this);if(this.parents===!0){let i=e.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[e.shaderStage]=i.stages[e.shaderStage]||[],i.stages[e.shaderStage].push(t)}if(s===1){let i=e.getNodeProperties(this);for(let n of Object.values(i))n&&n.isNode===!0&&n.build(e,this)}}generate(e,t){let{outputNode:s}=e.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(e,t)}updateBefore(){z("Abstract function.")}updateAfter(){z("Abstract function.")}update(){z("Abstract function.")}before(e){return this._beforeNodes===null&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){let s=this.getShared(e);if(this!==s)return s.build(e,t);if(this._beforeNodes!==null){let c=this._beforeNodes;this._beforeNodes=null;for(let l of c)l.build(e,t);this._beforeNodes=c}let i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;let n=dM[e.buildStage];if(n&&i.buildStages[n]!==!0){let c=e.getBuildStage();e.setBuildStage(n),this.build(e),e.setBuildStage(c)}e.addChain(this);let r=null,a=e.getBuildStage();if(a==="setup"){e.addNode(this),this.updateReference(e);let c=e.getNodeProperties(this);if(c.initialized!==!0){c.initialized=!0,c.outputNode=this.setup(e)||c.outputNode||null;for(let l of Object.values(c))if(l&&l.isNode===!0){if(l.parents===!0){let u=e.getNodeProperties(l);u.parents=u.parents||[],u.parents.push(this)}l.build(e)}e.addSequentialNode(this)}r=c.outputNode}else if(a==="analyze")this.analyze(e,t);else if(a==="generate"){if(this.generate.length<2){let l=this.getNodeType(e),u=e.getDataFromNode(this);r=u.snippet,r===void 0?u.generated===void 0?(u.generated=!0,r=this.generate(e)||"",u.snippet=r):(z("Node: Recursion detected.",this),r="/* Recursion detected. */"):u.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,l,t)}else r=this.generate(e,t)||"";r===""&&t!==null&&t!=="void"&&t!=="OutputType"&&(O(`TSL: Invalid generated code, expected a "${t}".`),r=e.generateConst(t))}return e.removeChain(this),r}getSerializeChildren(){return this._getChildren()}serialize(e){let t=this.getSerializeChildren(),s={};for(let{property:i,index:n,childNode:r}of t)n!==void 0?(s[i]===void 0&&(s[i]=Number.isInteger(n)?[]:{}),s[i][n]=r.toJSON(e.meta).uuid):s[i]=r.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(e.inputNodes!==void 0){let t=e.meta.nodes;for(let s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){let i=[];for(let n of e.inputNodes[s])i.push(t[n]);this[s]=i}else if(typeof e.inputNodes[s]=="object"){let i={};for(let n in e.inputNodes[s]){let r=e.inputNodes[s][n];i[n]=t[r]}this[s]=i}else{let i=e.inputNodes[s];this[s]=t[i]}}}toJSON(e){let{uuid:t,type:s}=this,i=e===void 0||typeof e=="string";i&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];n===void 0&&(n={uuid:t,type:s,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta);function r(a){let c=[];for(let l in a){let u=a[l];delete u.metadata,c.push(u)}return c}if(i){let a=r(e.textures),c=r(e.images),l=r(e.nodes);a.length>0&&(n.textures=a),c.length>0&&(n.images=c),l.length>0&&(n.nodes=l)}return n}};H.captureStackTrace=!1;var Vi=class extends H{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){let t=this.indexNode.getNodeType(e),s=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${s}[ ${i} ]`}},ju=class extends H{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){let t=this.node.getNodeType(e),s=null;for(let i of this.convertTo.split("|"))(s===null||e.getTypeLength(t)===e.getTypeLength(i))&&(s=i);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let s=this.node,i=this.getNodeType(e),n=s.build(e,i);return e.format(n,i,t)}},Be=class extends H{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){let i=e.getVectorType(this.getNodeType(e,t)),n=e.getDataFromNode(this);if(n.propertyName!==void 0)return e.format(n.propertyName,i,t);if(i!=="void"&&t!=="void"&&this.hasDependencies(e)){let r=super.build(e,i),a=e.getVarFromNode(this,null,i),c=e.getPropertyName(a);return e.addLineFlowCode(`${c} = ${r}`,this),n.snippet=r,n.propertyName=c,e.format(n.propertyName,i,t)}}return super.build(e,t)}},yf=class extends Be{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,s)=>t+e.getTypeLength(s.getNodeType(e)),0))}generate(e,t){let s=this.getNodeType(e),i=e.getTypeLength(s),n=this.nodes,r=e.getComponentType(s),a=[],c=0;for(let u of n){if(c>=i){O(`TSL: Length of parameters exceeds maximum length of function '${s}()' type.`,this.stackTrace);break}let h=u.getNodeType(e),d=e.getTypeLength(h),p;if(c+d>i&&(O(`TSL: Length of '${s}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-c,h=e.getTypeFromLength(d)),c+=d,p=u.build(e,h),e.getComponentType(h)!==r){let g=e.getTypeFromLength(d,r);p=e.format(p,h,g)}a.push(p)}let l=`${e.getType(s)}( ${a.join(", ")} )`;return e.format(l,s,t)}},fM=fr.join(""),Zu=class extends H{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(let t of this.components)e=Math.max(fr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){let s=this.node,i=e.getTypeLength(s.getNodeType(e)),n=null;if(i>1){let r=null;this.getVectorLength()>=i&&(r=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let c=s.build(e,r);this.components.length===i&&this.components===fM.slice(0,this.components.length)?n=e.format(c,r,t):n=e.format(`${c}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}},xf=class extends Be{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:s,targetNode:i}=this,n=this.getNodeType(e),r=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(s.length,r),c=i.build(e,a),l=t.build(e,n),u=e.getTypeLength(n),h=[];for(let d=0;d<u;d++){let p=fr[d];p===s[0]?(h.push(c),d+=s.length-1):h.push(l+"."+p)}return`${e.getType(n)}( ${h.join(", ")} )`}},bf=class extends Be{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{components:t,sourceNode:s}=this,i=this.getNodeType(e),n=s.build(e),r=e.getVarFromNode(this),a=e.getPropertyName(r);e.addLineFlowCode(a+" = "+n,this);let c=e.getTypeLength(i),l=[],u=0;for(let h=0;h<c;h++){let d=fr[h];d===t[u]?(l.push("1.0 - "+(a+"."+d)),u++):l.push(a+"."+d)}return`${e.getType(i)}( ${l.join(", ")} )`}},hc=class extends H{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return this.nodeType===null?fn(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=fn(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=lM(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?Zy(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){z("Abstract function.")}},Bb=/float|u?int/,Ot=class extends hc{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){let s=this.getNodeType(e);return Bb.test(s)&&Bb.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),s,t)}},_f=class extends H{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return this.structNode.isMemberNode&&this.structNode.hasMember(e)===!1?!1:this.structNode.getMemberType(e,this.property)!=="void"}getNodeType(e){return this.hasMember(e)===!1?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(this.hasMember(e)===!1)return"float";let s=this.getNodeType(e);return e.getStructTypeNode(s).getMemberType(e,t)}generate(e){if(this.hasMember(e)===!1){z(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);let s=this.getNodeType(e);return e.generateConst(s)}return this.structNode.build(e)+"."+this.property}},bn=null,Tf=new Map;function P(o,e){if(Tf.has(o)){z(`TSL: Redefinition of method chaining '${o}'.`);return}if(typeof e!="function")throw new Error(`THREE.TSL: Node element ${o} is not a function`);Tf.set(o,e),o!=="assign"&&(H.prototype[o]=function(...t){return this.isStackNode?this.addToStack(e(...t)):e(this,...t)},H.prototype[o+"Assign"]=function(...t){return this.isStackNode?this.assign(t[0],e(...t)):this.assign(e(this,...t))})}var mM=o=>o.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Fb=o=>mM(o).split("").sort().join("");H.prototype.assign=function(...o){if(this.isStackNode!==!0)return bn!==null?bn.assign(this,...o):O("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new ke),this;{let e=Tf.get("assign");return this.addToStack(e(...o))}};H.prototype.toVarIntent=function(){return this};H.prototype.get=function(o){return new _f(this,o)};var ic={};function fu(o,e,t){ic[o]=ic[e]=ic[t]={get(){this._cache=this._cache||{};let r=this._cache[o];return r===void 0&&(r=new Zu(this,o),this._cache[o]=r),r},set(r){this[o].assign(q(r))}};let s=o.toUpperCase(),i=e.toUpperCase(),n=t.toUpperCase();H.prototype["set"+s]=H.prototype["set"+i]=H.prototype["set"+n]=function(r){let a=Fb(o);return new xf(this,a,q(r))},H.prototype["flip"+s]=H.prototype["flip"+i]=H.prototype["flip"+n]=function(){let r=Fb(o);return new bf(this,r)}}var js=["x","y","z","w"],Zs=["r","g","b","a"],Js=["s","t","p","q"];for(let o=0;o<4;o++){let e=js[o],t=Zs[o],s=Js[o];fu(e,t,s);for(let i=0;i<4;i++){e=js[o]+js[i],t=Zs[o]+Zs[i],s=Js[o]+Js[i],fu(e,t,s);for(let n=0;n<4;n++){e=js[o]+js[i]+js[n],t=Zs[o]+Zs[i]+Zs[n],s=Js[o]+Js[i]+Js[n],fu(e,t,s);for(let r=0;r<4;r++)e=js[o]+js[i]+js[n]+js[r],t=Zs[o]+Zs[i]+Zs[n]+Zs[r],s=Js[o]+Js[i]+Js[n]+Js[r],fu(e,t,s)}}}for(let o=0;o<32;o++)ic[o]={get(){this._cache=this._cache||{};let e=this._cache[o];return e===void 0&&(e=new Vi(this,new Ot(o,"uint")),this._cache[o]=e),e},set(e){this[o].assign(q(e))}};Object.defineProperties(H.prototype,ic);var Ib=new WeakMap,gM=function(o,e=null){let t=fn(o);return t==="node"?o:e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string"?q(wf(o,e)):t==="shader"?o.isFn?o:A(o):o},yM=function(o,e=null){for(let t in o)o[t]=q(o[t],e);return o},xM=function(o,e=null){let t=o.length;for(let s=0;s<t;s++)o[s]=q(o[s],e);return o},Q_=function(o,e=null,t=null,s=null){function i(u){return s!==null?(u=q(Object.assign(u,s)),s.intent===!0&&(u=u.toVarIntent())):u=q(u),u}let n,r=e,a,c;function l(u){let h;return r?h=/[a-z]/i.test(r)?r+"()":r:h=o.type,a!==void 0&&u.length<a?(O(`TSL: "${h}" parameter length is less than minimum required.`,new ke),u.concat(new Array(a-u.length).fill(0))):c!==void 0&&u.length>c?(O(`TSL: "${h}" parameter length exceeds limit.`,new ke),u.slice(0,c)):u}return e===null?n=(...u)=>i(new o(...or(l(u)))):t!==null?(t=q(t),n=(...u)=>i(new o(e,...or(l(u)),t))):n=(...u)=>i(new o(e,...or(l(u)))),n.setParameterLength=(...u)=>(u.length===1?a=c=u[0]:u.length===2&&([a,c]=u),n),n.setName=u=>(r=u,n),n},bM=function(o,...e){return new o(...or(e))},Sf=class extends H{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){let{shaderNode:t,rawInputs:s}=this,i=e.getNodeProperties(t),n=e.getClosestSubBuild(t.subBuilds)||"",r=n||"default";if(i[r])return i[r];let a=e.subBuildFn,c=e.fnCall;e.subBuildFn=n,e.fnCall=this;let l=null;if(t.layout){let u=Ib.get(e.constructor);u===void 0&&(u=new WeakMap,Ib.set(e.constructor,u));let h=u.get(t);h===void 0&&(h=q(e.buildFunctionNode(t)),u.set(t,h)),e.addInclude(h);let d=s?_M(s):null;l=q(h.call(d))}else{let u=new Proxy(e,{get:(g,y,x)=>{let _;return Symbol.iterator===y?_=function*(){yield void 0}:_=Reflect.get(g,y,x),_}}),h=s?TM(s):null,d=Array.isArray(s)?s.length>0:s!==null,p=t.jsFunc,m=d||p.length>1?p(h,u):p(u);l=q(m)}return e.subBuildFn=a,e.fnCall=c,t.once&&(i[r]=l),l}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){let t=e.getNodeProperties(this),s=e.getSubBuildOutput(this);return t[s]=t[s]||this.setupOutput(e),t[s].subBuild=e.getClosestSubBuild(this),t[s]}build(e,t=null){let s=null,i=e.getBuildStage(),n=e.getNodeProperties(this),r=e.getSubBuildOutput(this),a=this.getOutputNode(e),c=e.fnCall;if(e.fnCall=this,i==="setup"){let l=e.getSubBuildProperty("initialized",this);if(n[l]!==!0&&(n[l]=!0,n[r]=this.getOutputNode(e),n[r].build(e),this.shaderNode.subBuilds))for(let u of e.chaining){let h=e.getDataFromNode(u,"any");h.subBuilds=h.subBuilds||new Set;for(let d of this.shaderNode.subBuilds)h.subBuilds.add(d)}s=n[r]}else i==="analyze"?a.build(e,t):i==="generate"&&(s=a.build(e,t)||"");return e.fnCall=c,s}};function _M(o){let e;return id(o),o[0]&&(o[0].isNode||Object.getPrototypeOf(o[0])!==Object.prototype)?e=[...o]:e=o[0],e}function TM(o){let e=0;return id(o),new Proxy(o,{get:(t,s,i)=>{let n;if(s==="length")return n=o.length,n;if(Symbol.iterator===s)n=function*(){for(let r of o)yield q(r)};else{if(o.length>0)if(Object.getPrototypeOf(o[0])===Object.prototype){let r=o[0];r[s]===void 0?n=r[e++]:n=Reflect.get(r,s,i)}else o[0]instanceof H&&(o[s]===void 0?n=o[e++]:n=Reflect.get(o,s,i));else n=Reflect.get(t,s,i);n=q(n)}return n}})}var vf=class extends H{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new Sf(this,e)}setup(){return this.call()}},SM=[!1,!0],vM=[0,1,2,3],wM=[-1,-2],K_=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Jy=new Map;for(let o of SM)Jy.set(o,new Ot(o));var Qy=new Map;for(let o of vM)Qy.set(o,new Ot(o,"uint"));var Ky=new Map([...Qy].map(o=>new Ot(o.value,"int")));for(let o of wM)Ky.set(o,new Ot(o,"int"));var td=new Map([...Ky].map(o=>new Ot(o.value)));for(let o of K_)td.set(o,new Ot(o));for(let o of K_)td.set(-o,new Ot(-o));var sd={bool:Jy,uint:Qy,ints:Ky,float:td},Pb=new Map([...Jy,...td]),wf=(o,e)=>Pb.has(o)?Pb.get(o):o.isNode===!0?o:new Ot(o,e),et=function(o,e=null){return(...t)=>{for(let i of t)if(i===void 0)return O(`TSL: Invalid parameter for the type "${o}".`,new ke),new Ot(0,o);if((t.length===0||!["bool","float","int","uint"].includes(o)&&t.every(i=>{let n=typeof i;return n!=="object"&&n!=="function"}))&&(t=[Zy(o,...t)]),t.length===1&&e!==null&&e.has(t[0]))return tc(e.get(t[0]));if(t.length===1){let i=wf(t[0],o);return i.nodeType===o?tc(i):tc(new ju(i,o))}let s=t.map(i=>wf(i));return tc(new yf(s,o))}},dc=o=>typeof o=="object"&&o!==null?o.value:o,eT=o=>o!=null?o.nodeType||o.convertTo||(typeof o=="string"?o:null):null;function ho(o,e){return new vf(o,e)}var q=(o,e=null)=>gM(o,e),tc=(o,e=null)=>q(o,e).toVarIntent(),id=(o,e=null)=>new yM(o,e),or=(o,e=null)=>new xM(o,e),oe=(o,e=null,t=null,s=null)=>new Q_(o,e,t,s),G=(o,...e)=>new bM(o,...e),V=(o,e=null,t=null,s={})=>new Q_(o,e,t,{...s,intent:!0}),MM=0,Mf=class extends H{constructor(e,t=null){super();let s=null;t!==null&&(typeof t=="object"?s=t.return:(typeof t=="string"?s=t:O("TSL: Invalid layout type.",new ke),t=null)),this.shaderNode=new ho(e,s),t!==null&&this.setLayout(t),this.isFn=!0}setLayout(e){let t=this.shaderNode.nodeType;if(typeof e.inputs!="object"){let s={name:"fn"+MM++,type:t,inputs:[]};for(let i in e)i!=="return"&&s.inputs.push({name:i,type:e[i]});e=s}return this.shaderNode.setLayout(e),this}getNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){let t=this.shaderNode.call(e);return this.shaderNode.nodeType==="void"&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){let t=this.getNodeType(e);return O('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}};function A(o,e=null){let t=new Mf(o,e);return new Proxy(()=>{},{apply(s,i,n){return t.call(...n)},get(s,i,n){return Reflect.get(t,i,n)},set(s,i,n,r){return Reflect.set(t,i,n,r)}})}var pc=o=>{bn=o},ex=()=>bn,K=(...o)=>bn.If(...o),AM=(...o)=>bn.Switch(...o);function nd(o){return bn&&bn.addToStack(o),o}P("toStack",nd);var tT=new et("color"),b=new et("float",sd.float),T=new et("int",sd.ints),D=new et("uint",sd.uint),hs=new et("bool",sd.bool),U=new et("vec2"),Qe=new et("ivec2"),tx=new et("uvec2"),sT=new et("bvec2"),v=new et("vec3"),sx=new et("ivec3"),mr=new et("uvec3"),ix=new et("bvec3"),Z=new et("vec4"),nx=new et("ivec4"),rx=new et("uvec4"),iT=new et("bvec4"),rd=new et("mat2"),at=new et("mat3"),gn=new et("mat4"),NM=(o="")=>new Ot(o,"string"),RM=o=>new Ot(o,"ArrayBuffer");P("toColor",tT);P("toFloat",b);P("toInt",T);P("toUint",D);P("toBool",hs);P("toVec2",U);P("toIVec2",Qe);P("toUVec2",tx);P("toBVec2",sT);P("toVec3",v);P("toIVec3",sx);P("toUVec3",mr);P("toBVec3",ix);P("toVec4",Z);P("toIVec4",nx);P("toUVec4",rx);P("toBVec4",iT);P("toMat2",rd);P("toMat3",at);P("toMat4",gn);var nT=oe(Vi).setParameterLength(2),rT=(o,e)=>new ju(q(o),e),CM=(o,e)=>new Zu(q(o),e);P("element",nT);P("convert",rT);var EM=o=>(z("TSL: append() has been renamed to Stack().",new ke),nd(o));P("append",o=>(z("TSL: .append() has been renamed to .toStack().",new ke),nd(o)));var be=class extends H{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return Ro(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;return this.varying===!0?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}},Ui=(o,e)=>new be(o,e),fc=(o,e)=>new be(o,e,!0),we=G(be,"vec4","DiffuseColor"),er=G(be,"vec3","DiffuseContribution"),Af=G(be,"vec3","EmissiveColor"),ii=G(be,"float","Roughness"),Li=G(be,"float","Metalness"),Ju=G(be,"float","Clearcoat"),po=G(be,"float","ClearcoatRoughness"),Kt=G(be,"vec3","Sheen"),ln=G(be,"float","SheenRoughness"),od=G(be,"float","Iridescence"),Qu=G(be,"float","IridescenceIOR"),Ku=G(be,"float","IridescenceThickness"),eh=G(be,"float","AlphaT"),cn=G(be,"float","Anisotropy"),nc=G(be,"vec3","AnisotropyT"),ar=G(be,"vec3","AnisotropyB"),_n=G(be,"color","SpecularColor"),sr=G(be,"color","SpecularColorBlended"),ir=G(be,"float","SpecularF90"),th=G(be,"float","Shininess"),fo=G(be,"vec4","Output"),$u=G(be,"float","dashSize"),Nf=G(be,"float","gapSize"),BM=G(be,"float","pointWidth"),rc=G(be,"float","IOR"),sh=G(be,"float","Transmission"),ox=G(be,"float","Thickness"),ax=G(be,"float","AttenuationDistance"),cx=G(be,"color","AttenuationColor"),lx=G(be,"float","Dispersion"),ih=class extends H{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.shared=t,this.order=s,this.isUniformGroup=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}},oT=o=>new ih(o),ad=(o,e=0)=>new ih(o,!0,e),aT=ad("frame"),J=ad("render"),ux=oT("object"),lr=class extends hc{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=ux}setName(e){return this.name=e,this}label(e){return z('TSL: "label()" has been deprecated. Use "setName()" instead.',new ke),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){return e=e.bind(this),super.onUpdate(s=>{let i=e(s,this);i!==void 0&&(this.value=i)},t)}getInputType(e){let t=super.getInputType(e);return t==="bool"&&(t="uint"),t}generate(e,t){let s=this.getNodeType(e),i=this.getUniformHash(e),n=e.getNodeFromHash(i);n===void 0&&(e.setHashNode(this,i),n=this);let r=n.getInputType(e),a=e.getUniformFromNode(n,r,e.shaderStage,this.name||e.context.nodeName),c=e.getPropertyName(a);e.context.nodeName!==void 0&&delete e.context.nodeName;let l=c;if(s==="bool"){let u=e.getDataFromNode(this),h=u.propertyName;if(h===void 0){let d=e.getVarFromNode(this,null,"bool");h=e.getPropertyName(d),u.propertyName=h,l=e.format(c,r,s),e.addLineFlowCode(`${h} = ${l}`,this)}l=h}return e.format(l,s,t)}},j=(o,e)=>{let t=eT(e||o);if(t===o&&(o=Zy(t)),o&&o.isNode===!0){let s=o.value;o.traverse(i=>{i.isConstNode===!0&&(s=i.value)}),o=s}return new lr(o,t)},nh=class extends Be{static get type(){return"ArrayNode"}constructor(e,t,s=null){super(e),this.count=t,this.values=s,this.isArrayNode=!0}getArrayCount(){return this.count}getNodeType(e){return this.nodeType===null?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return this.nodeType===null?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){let t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}},cT=(...o)=>{let e;if(o.length===1){let t=o[0];e=new nh(null,t.length,t)}else{let t=o[0],s=o[1];e=new nh(t,s)}return q(e)};P("toArray",(o,e)=>cT(Array(e).fill(o)));var Rf=class extends Be{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}getNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){let{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){let s=e.getTypeLength(t.node.getNodeType(e));return fr.join("").slice(0,s)!==t.components}return!1}setup(e){let{targetNode:t,sourceNode:s}=this,i=t.getScope(),n=e.getDataFromNode(i);n.assign=!0;let r=e.getNodeProperties(this);r.sourceNode=s,r.targetNode=t.context({assign:!0})}generate(e,t){let{targetNode:s,sourceNode:i}=e.getNodeProperties(this),n=this.needsSplitAssign(e),r=s.build(e),a=s.getNodeType(e),c=i.build(e,a),l=i.getNodeType(e),u=e.getDataFromNode(this),h;if(u.initialized===!0)t!=="void"&&(h=r);else if(n){let d=e.getVarFromNode(this,null,a),p=e.getPropertyName(d);e.addLineFlowCode(`${p} = ${c}`,this);let m=s.node,y=m.node.context({assign:!0}).build(e);for(let x=0;x<m.components.length;x++){let _=m.components[x];e.addLineFlowCode(`${y}.${_} = ${p}[ ${x} ]`,this)}t!=="void"&&(h=r)}else h=`${r} = ${c}`,(t==="void"||l==="void")&&(e.addLineFlowCode(h,this),t!=="void"&&(h=r));return u.initialized=!0,e.format(h,a,t)}},lT=oe(Rf).setParameterLength(2);P("assign",lT);var Cf=class extends Be{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){let t=[],s=this.functionNode,i=s.getInputs(e),n=this.parameters,r=(c,l)=>{let u=l.type,h=u==="pointer",d;return h?d="&"+c.build(e):d=c.build(e,u),d};if(Array.isArray(n)){if(n.length>i.length)O("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),n.length=i.length;else if(n.length<i.length)for(O("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");n.length<i.length;)n.push(b(0));for(let c=0;c<n.length;c++)t.push(r(n[c],i[c]))}else for(let c of i){let l=n[c.name];l!==void 0?t.push(r(l,c)):(O(`TSL: Input '${c.name}' not found in 'Fn()'.`),t.push(r(b(0),c)))}return`${s.build(e,"property")}( ${t.join(", ")} )`}},uT=(o,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?or(e):id(e[0]),new Cf(q(o),e));P("call",uT);var FM={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"},We=class o extends Be{static get type(){return"OperatorNode"}constructor(e,t,s,...i){if(super(),i.length>0){let n=new o(e,t,s);for(let r=0;r<i.length-1;r++)n=new o(e,n,i[r]);t=n,s=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=s,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(FM[this.op],t)}getNodeType(e,t=null){let s=this.op,i=this.aNode,n=this.bNode,r=i.getNodeType(e),a=n?n.getNodeType(e):null;if(r==="void"||a==="void")return t||"void";if(s==="%")return r;if(s==="~"||s==="&"||s==="|"||s==="^"||s===">>"||s==="<<")return e.getIntegerType(r);if(s==="!"||s==="&&"||s==="||"||s==="^^")return"bool";if(s==="=="||s==="!="||s==="<"||s===">"||s==="<="||s===">="){let c=Math.max(e.getTypeLength(r),e.getTypeLength(a));return c>1?`bvec${c}`:"bool"}else{if(e.isMatrix(r)){if(a==="float")return r;if(e.isVector(a))return e.getVectorFromMatrix(r);if(e.isMatrix(a))return r}else if(e.isMatrix(a)){if(r==="float")return a;if(e.isVector(r))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(r)?a:r}}generate(e,t){let s=this.op,{aNode:i,bNode:n}=this,r=this.getNodeType(e,t),a=null,c=null;r!=="void"?(a=i.getNodeType(e),c=n?n.getNodeType(e):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="||s==="!="?e.isVector(a)?c=a:e.isVector(c)?a=c:a!==c&&(a=c="float"):s===">>"||s==="<<"?(a=r,c=e.changeComponentType(c,"uint")):s==="%"?(a=r,c=e.isInteger(a)&&e.isInteger(c)?c:a):e.isMatrix(a)?c==="float"?c="float":e.isVector(c)?c=e.getVectorFromMatrix(a):e.isMatrix(c)||(a=c=r):e.isMatrix(c)?a==="float"?a="float":e.isVector(a)?a=e.getVectorFromMatrix(c):a=c=r:a=c=r):a=c=r;let l=i.build(e,a),u=n?n.build(e,c):null,h=e.getFunctionOperator(s);if(t!=="void"){let d=e.renderer.coordinateSystem===Dt;if(s==="=="||s==="!="||s==="<"||s===">"||s==="<="||s===">=")return d?e.isVector(a)?e.format(`${this.getOperatorMethod(e,t)}( ${l}, ${u} )`,r,t):e.format(`( ${l} ${s} ${u} )`,r,t):e.format(`( ${l} ${s} ${u} )`,r,t);if(s==="%")return e.isInteger(c)?e.format(`( ${l} % ${u} )`,r,t):e.format(`${this.getOperatorMethod(e,r)}( ${l}, ${u} )`,r,t);if(s==="!"||s==="~")return e.format(`(${s}${l})`,a,t);if(h)return e.format(`${h}( ${l}, ${u} )`,r,t);if(e.isMatrix(a)&&c==="float")return e.format(`( ${u} ${s} ${l} )`,r,t);if(a==="float"&&e.isMatrix(c))return e.format(`${l} ${s} ${u}`,r,t);{let p=`( ${l} ${s} ${u} )`;return!d&&r==="bool"&&e.isVector(a)&&e.isVector(c)&&(p=`all${p}`),e.format(p,r,t)}}else if(a!=="void")return h?e.format(`${h}( ${l}, ${u} )`,r,t):e.isMatrix(a)&&c==="float"?e.format(`${u} ${s} ${l}`,r,t):e.format(`${l} ${s} ${u}`,r,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}},Ye=V(We,"+").setParameterLength(2,1/0).setName("add"),he=V(We,"-").setParameterLength(2,1/0).setName("sub"),se=V(We,"*").setParameterLength(2,1/0).setName("mul"),ss=V(We,"/").setParameterLength(2,1/0).setName("div"),Bc=V(We,"%").setParameterLength(2).setName("mod"),hT=V(We,"==").setParameterLength(2).setName("equal"),dT=V(We,"!=").setParameterLength(2).setName("notEqual"),pT=V(We,"<").setParameterLength(2).setName("lessThan"),hx=V(We,">").setParameterLength(2).setName("greaterThan"),fT=V(We,"<=").setParameterLength(2).setName("lessThanEqual"),mT=V(We,">=").setParameterLength(2).setName("greaterThanEqual"),gT=V(We,"&&").setParameterLength(2,1/0).setName("and"),yT=V(We,"||").setParameterLength(2,1/0).setName("or"),xT=V(We,"!").setParameterLength(1).setName("not"),bT=V(We,"^^").setParameterLength(2).setName("xor"),_T=V(We,"&").setParameterLength(2).setName("bitAnd"),TT=V(We,"~").setParameterLength(1).setName("bitNot"),ST=V(We,"|").setParameterLength(2).setName("bitOr"),vT=V(We,"^").setParameterLength(2).setName("bitXor"),wT=V(We,"<<").setParameterLength(2).setName("shiftLeft"),MT=V(We,">>").setParameterLength(2).setName("shiftRight"),AT=A(([o])=>(o.addAssign(1),o)),NT=A(([o])=>(o.subAssign(1),o)),RT=A(([o])=>{let e=T(o).toConst();return o.addAssign(1),e}),CT=A(([o])=>{let e=T(o).toConst();return o.subAssign(1),e});P("add",Ye);P("sub",he);P("mul",se);P("div",ss);P("mod",Bc);P("equal",hT);P("notEqual",dT);P("lessThan",pT);P("greaterThan",hx);P("lessThanEqual",fT);P("greaterThanEqual",mT);P("and",gT);P("or",yT);P("not",xT);P("xor",bT);P("bitAnd",_T);P("bitNot",TT);P("bitOr",ST);P("bitXor",vT);P("shiftLeft",wT);P("shiftRight",MT);P("incrementBefore",AT);P("decrementBefore",NT);P("increment",RT);P("decrement",CT);var ET=(o,e)=>(z('TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.',new ke),Bc(T(o),T(e)));P("modInt",ET);var F=class o extends Be{static get type(){return"MathNode"}constructor(e,t,s=null,i=null){if(super(),(e===o.MAX||e===o.MIN)&&arguments.length>3){let n=new o(e,t,s);for(let r=2;r<arguments.length-1;r++)n=new o(e,n,arguments[r]);t=n,s=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=s,this.cNode=i,this.isMathNode=!0}getInputType(e){let t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),r=e.isMatrix(s)?0:e.getTypeLength(s),a=e.isMatrix(i)?0:e.getTypeLength(i);return n>r&&n>a?t:r>a?s:a>n?i:t}getNodeType(e){let t=this.method;return t===o.LENGTH||t===o.DISTANCE||t===o.DOT?"float":t===o.CROSS?"vec3":t===o.ALL||t===o.ANY?"bool":t===o.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){let{aNode:t,bNode:s,method:i}=this,n=null;if(i===o.ONE_MINUS)n=he(1,t);else if(i===o.RECIPROCAL)n=ss(1,t);else if(i===o.DIFFERENCE)n=Ee(he(t,s));else if(i===o.TRANSFORM_DIRECTION){let r=t,a=s;e.isMatrix(r.getNodeType(e))?a=Z(v(a),0):r=Z(v(r),0);let c=se(r,a).xyz;n=Ut(c)}return n!==null?n:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let i=this.method,n=this.getNodeType(e),r=this.getInputType(e),a=this.aNode,c=this.bNode,l=this.cNode,u=e.renderer.coordinateSystem;if(i===o.NEGATE)return e.format("( - "+a.build(e,r)+" )",n,t);{let h=[];return i===o.CROSS?h.push(a.build(e,n),c.build(e,n)):u===Dt&&i===o.STEP?h.push(a.build(e,e.getTypeLength(a.getNodeType(e))===1?"float":r),c.build(e,r)):u===Dt&&(i===o.MIN||i===o.MAX)?h.push(a.build(e,r),c.build(e,e.getTypeLength(c.getNodeType(e))===1?"float":r)):i===o.REFRACT?h.push(a.build(e,r),c.build(e,r),l.build(e,"float")):i===o.MIX?h.push(a.build(e,r),c.build(e,r),l.build(e,e.getTypeLength(l.getNodeType(e))===1?"float":r)):(u===Yt&&i===o.ATAN&&c!==null&&(i="atan2"),e.shaderStage!=="fragment"&&(i===o.DFDX||i===o.DFDY)&&(z(`TSL: '${i}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),h.push(a.build(e,r)),c!==null&&h.push(c.build(e,r)),l!==null&&h.push(l.build(e,r))),e.format(`${e.getMethod(i,n)}( ${h.join(", ")} )`,n,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}};F.ALL="all";F.ANY="any";F.RADIANS="radians";F.DEGREES="degrees";F.EXP="exp";F.EXP2="exp2";F.LOG="log";F.LOG2="log2";F.SQRT="sqrt";F.INVERSE_SQRT="inversesqrt";F.FLOOR="floor";F.CEIL="ceil";F.NORMALIZE="normalize";F.FRACT="fract";F.SIN="sin";F.COS="cos";F.TAN="tan";F.ASIN="asin";F.ACOS="acos";F.ATAN="atan";F.ABS="abs";F.SIGN="sign";F.LENGTH="length";F.NEGATE="negate";F.ONE_MINUS="oneMinus";F.DFDX="dFdx";F.DFDY="dFdy";F.ROUND="round";F.RECIPROCAL="reciprocal";F.TRUNC="trunc";F.FWIDTH="fwidth";F.TRANSPOSE="transpose";F.DETERMINANT="determinant";F.INVERSE="inverse";F.EQUALS="equals";F.MIN="min";F.MAX="max";F.STEP="step";F.REFLECT="reflect";F.DISTANCE="distance";F.DIFFERENCE="difference";F.DOT="dot";F.CROSS="cross";F.POW="pow";F.TRANSFORM_DIRECTION="transformDirection";F.MIX="mix";F.CLAMP="clamp";F.REFRACT="refract";F.SMOOTHSTEP="smoothstep";F.FACEFORWARD="faceforward";var dx=b(1e-6),IM=b(1e6),rh=b(Math.PI),PM=b(Math.PI*2),DM=b(Math.PI*2),LM=b(Math.PI*.5),BT=V(F,F.ALL).setParameterLength(1),FT=V(F,F.ANY).setParameterLength(1),IT=V(F,F.RADIANS).setParameterLength(1),PT=V(F,F.DEGREES).setParameterLength(1),px=V(F,F.EXP).setParameterLength(1),bo=V(F,F.EXP2).setParameterLength(1),cd=V(F,F.LOG).setParameterLength(1),ri=V(F,F.LOG2).setParameterLength(1),It=V(F,F.SQRT).setParameterLength(1),fx=V(F,F.INVERSE_SQRT).setParameterLength(1),oi=V(F,F.FLOOR).setParameterLength(1),ld=V(F,F.CEIL).setParameterLength(1),Ut=V(F,F.NORMALIZE).setParameterLength(1),Es=V(F,F.FRACT).setParameterLength(1),Bt=V(F,F.SIN).setParameterLength(1),Rs=V(F,F.COS).setParameterLength(1),DT=V(F,F.TAN).setParameterLength(1),LT=V(F,F.ASIN).setParameterLength(1),mx=V(F,F.ACOS).setParameterLength(1),gx=V(F,F.ATAN).setParameterLength(1,2),Ee=V(F,F.ABS).setParameterLength(1),yx=V(F,F.SIGN).setParameterLength(1),ai=V(F,F.LENGTH).setParameterLength(1),xx=V(F,F.NEGATE).setParameterLength(1),UT=V(F,F.ONE_MINUS).setParameterLength(1),bx=V(F,F.DFDX).setParameterLength(1),_x=V(F,F.DFDY).setParameterLength(1),OT=V(F,F.ROUND).setParameterLength(1),VT=V(F,F.RECIPROCAL).setParameterLength(1),Tx=V(F,F.TRUNC).setParameterLength(1),Sx=V(F,F.FWIDTH).setParameterLength(1),kT=V(F,F.TRANSPOSE).setParameterLength(1),zT=V(F,F.DETERMINANT).setParameterLength(1),GT=V(F,F.INVERSE).setParameterLength(1),Vt=V(F,F.MIN).setParameterLength(2,1/0),ze=V(F,F.MAX).setParameterLength(2,1/0),ur=V(F,F.STEP).setParameterLength(2),WT=V(F,F.REFLECT).setParameterLength(2),$T=V(F,F.DISTANCE).setParameterLength(2),qT=V(F,F.DIFFERENCE).setParameterLength(2),ds=V(F,F.DOT).setParameterLength(2),ki=V(F,F.CROSS).setParameterLength(2),cs=V(F,F.POW).setParameterLength(2),vx=o=>se(o,o),HT=o=>se(o,o,o),wx=o=>se(o,o,o,o),XT=V(F,F.TRANSFORM_DIRECTION).setParameterLength(2),YT=o=>se(yx(o),cs(Ee(o),1/3)),Mx=o=>ds(o,o),le=V(F,F.MIX).setParameterLength(3),Bs=(o,e=0,t=1)=>new F(F.CLAMP,q(o),q(e),q(t)),ud=o=>Bs(o),Ax=V(F,F.REFRACT).setParameterLength(3),Fs=V(F,F.SMOOTHSTEP).setParameterLength(3),Nx=V(F,F.FACEFORWARD).setParameterLength(3),jT=A(([o])=>{let s=43758.5453,i=ds(o.xy,U(12.9898,78.233)),n=Bc(i,rh);return Es(Bt(n).mul(s))}),ZT=(o,e,t)=>le(e,t,o),JT=(o,e,t)=>Fs(e,t,o),QT=(o,e)=>ur(e,o),UM=Nx,OM=fx;P("all",BT);P("any",FT);P("radians",IT);P("degrees",PT);P("exp",px);P("exp2",bo);P("log",cd);P("log2",ri);P("sqrt",It);P("inverseSqrt",fx);P("floor",oi);P("ceil",ld);P("normalize",Ut);P("fract",Es);P("sin",Bt);P("cos",Rs);P("tan",DT);P("asin",LT);P("acos",mx);P("atan",gx);P("abs",Ee);P("sign",yx);P("length",ai);P("lengthSq",Mx);P("negate",xx);P("oneMinus",UT);P("dFdx",bx);P("dFdy",_x);P("round",OT);P("reciprocal",VT);P("trunc",Tx);P("fwidth",Sx);P("min",Vt);P("max",ze);P("step",QT);P("reflect",WT);P("distance",$T);P("dot",ds);P("cross",ki);P("pow",cs);P("pow2",vx);P("pow3",HT);P("pow4",wx);P("transformDirection",XT);P("mix",ZT);P("clamp",Bs);P("refract",Ax);P("smoothstep",JT);P("faceForward",Nx);P("difference",qT);P("saturate",ud);P("cbrt",YT);P("transpose",kT);P("determinant",zT);P("inverse",GT);P("rand",jT);var Ef=class extends H{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){let{ifNode:t,elseNode:s}=e.getNodeProperties(this);if(t===void 0)return e.flowBuildStage(this,"setup"),this.getNodeType(e);let i=t.getNodeType(e);if(s!==null){let n=s.getNodeType(e);if(e.getTypeLength(n)>e.getTypeLength(i))return n}return i}setup(e){let t=this.condNode,s=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,i!==null&&(e.getDataFromNode(i).parentNodeBlock=n);let r=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=r?s:s.context({nodeBlock:s}),a.elseNode=i?r?i:i.context({nodeBlock:i}):null}generate(e,t){let s=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;let{condNode:n,ifNode:r,elseNode:a}=e.getNodeProperties(this),c=e.currentFunctionNode,l=t!=="void",u=l?Ui(s).build(e):"";i.nodeProperty=u;let h=n.build(e,"bool");if(e.context.uniformFlow&&a!==null){let m=r.build(e,s),g=a.build(e,s),y=e.getTernary(h,m,g);return e.format(y,s,t)}e.addFlowCode(`
|
|
${e.tab}if ( ${h} ) {
|
|
|
|
`).addFlowTab();let p=r.build(e,s);if(p&&(l?p=u+" = "+p+";":(p="return "+p+";",c===null&&(z("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),p="// "+p))),e.removeFlowTab().addFlowCode(e.tab+" "+p+`
|
|
|
|
`+e.tab+"}"),a!==null){e.addFlowCode(` else {
|
|
|
|
`).addFlowTab();let m=a.build(e,s);m&&(l?m=u+" = "+m+";":(m="return "+m+";",c===null&&(z("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),m="// "+m))),e.removeFlowTab().addFlowCode(e.tab+" "+m+`
|
|
|
|
`+e.tab+`}
|
|
|
|
`)}else e.addFlowCode(`
|
|
|
|
`);return e.format(u,s,t)}},vt=oe(Ef).setParameterLength(2,3);P("select",vt);var oh=class extends H{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){let e=[];return this.traverse(t=>{t.isContextNode===!0&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}setup(e){let t=e.addContext(this.value);this.node.build(e),e.setContext(t)}generate(e,t){let s=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(s),i}},$i=(o=null,e={})=>{let t=o;return(t===null||t.isNode!==!0)&&(e=t||e,t=null),new oh(t,e)},KT=o=>$i(o,{uniformFlow:!0}),Rx=(o,e)=>$i(o,{nodeName:e});function eS(o,e,t=null){return $i(t,{getShadow:({light:s,shadowColorNode:i})=>e===s?i.mul(o):i})}function tS(o,e=null){return $i(e,{getAO:(t,{material:s})=>s.transparent===!0?t:t!==null?t.mul(o):o})}function sS(o,e){return z('TSL: "label()" has been deprecated. Use "setName()" instead.'),Rx(o,e)}P("context",$i);P("label",sS);P("uniformFlow",KT);P("setName",Rx);P("builtinShadowContext",(o,e,t)=>eS(e,t,o));P("builtinAOContext",(o,e)=>tS(e,o));var mo=class extends H{static get type(){return"VarNode"}constructor(e,t=null,s=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=s,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return e.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}getNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){let t=e[0];if(this._hasStack(t)===!1&&t.buildStage==="setup"&&(t.context.nodeLoop||t.context.nodeBlock)){let s=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop){let r=t.getDataFromNode(this);r.forceDeclaration=!0,s=!0}let i=t.getBaseStack();s?i.addToStackBefore(this):i.addToStack(this)}return this.isIntent(t)&&this.isAssign(t)!==!0?this.node.build(...e):super.build(...e)}generate(e){let{node:t,name:s,readOnly:i}=this,{renderer:n}=e,r=n.backend.isWebGPUBackend===!0,a=!1,c=!1;i&&(a=e.isDeterministic(t),c=r?i:a);let l=this.getNodeType(e);if(l=="void")return this.isIntent(e)!==!0&&O('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);let u=e.getVectorType(l),h=t.build(e,u),d=e.getVarFromNode(this,s,u,void 0,c),p=e.getPropertyName(d),m=p;if(c)if(r)m=a?`const ${p}`:`let ${p}`;else{let g=t.getArrayCount(e);m=`const ${e.getVar(d.type,p,g)}`}return e.addLineFlowCode(`${m} = ${h}`,this),p}_hasStack(e){return e.getDataFromNode(this).stack!==void 0}},Cx=oe(mo),iS=(o,e=null)=>Cx(o,e).toStack(),nS=(o,e=null)=>Cx(o,e,!0).toStack(),rS=o=>Cx(o).setIntent(!0).toStack();P("toVar",iS);P("toConst",nS);P("toVarIntent",rS);var Bf=class extends H{static get type(){return"SubBuild"}constructor(e,t,s=null){super(s),this.node=e,this.name=t,this.isSubBuildNode=!0}getNodeType(e){if(this.nodeType!==null)return this.nodeType;e.addSubBuild(this.name);let t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);let s=this.node.build(e,...t);return e.removeSubBuild(),s}},cr=(o,e,t=null)=>new Bf(q(o),e,t),Ff=class extends H{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=cr(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){let t=e.getNodeProperties(this),s=t.varying;if(s===void 0){let i=this.name,n=this.getNodeType(e),r=this.interpolationType,a=this.interpolationSampling;t.varying=s=e.getVaryingFromNode(this,i,n,r,a),t.node=cr(this.node,"VERTEX")}return s.needsInterpolation||(s.needsInterpolation=e.shaderStage==="fragment"),s}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(ec.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(ec.VERTEX,this.node)}generate(e){let t=e.getSubBuildProperty("property",e.currentStack),s=e.getNodeProperties(this),i=this.setupVarying(e);if(s[t]===void 0){let n=this.getNodeType(e),r=e.getPropertyName(i,ec.VERTEX);e.flowNodeFromShaderStage(ec.VERTEX,s.node,n,r),s[t]=r}return e.getPropertyName(i)}},Sn=oe(Ff).setParameterLength(1,2),oS=o=>Sn(o);P("toVarying",Sn);P("toVertexStage",oS);var aS=A(([o])=>{let e=o.mul(.9478672986).add(.0521327014).pow(2.4),t=o.mul(.0773993808),s=o.lessThanEqual(.04045);return le(e,t,s)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),cS=A(([o])=>{let e=o.pow(.41666).mul(1.055).sub(.055),t=o.mul(12.92),s=o.lessThanEqual(.0031308);return le(e,t,s)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ex="WorkingColorSpace",VM="OutputColorSpace",mc=class extends Be{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ex?me.workingColorSpace:t===VM?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){let{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target),n=t;return me.enabled===!1||s===i||!s||!i||(me.getTransfer(s)===ne&&(n=Z(aS(n.rgb),n.a)),me.getPrimaries(s)!==me.getPrimaries(i)&&(n=Z(at(me._getMatrix(new Nt,s,i)).mul(n.rgb),n.a)),me.getTransfer(i)===ne&&(n=Z(cS(n.rgb),n.a))),n}},lS=(o,e)=>new mc(q(o),Ex,e),hd=(o,e)=>new mc(q(o),e,Ex),kM=(o,e,t)=>new mc(q(o),e,t);P("workingToColorSpace",lS);P("colorSpaceToWorking",hd);var zM=class extends Vi{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),s=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,s,i)}},ah=class extends H{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,i=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=i,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=te.OBJECT}setGroup(e){return this.group=e,this}element(e){return new zM(this,q(e))}setNodeType(e){let t=j(null,e);this.group!==null&&t.setGroup(this.group),this.node=t}getNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,s=e[t[0]];for(let i=1;i<t.length;i++)s=s[t[i]];return s}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}},GM=(o,e,t)=>new ah(o,e,t),If=class extends ah{static get type(){return"RendererReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.renderer=s,this.setGroup(J)}updateReference(e){return this.reference=this.renderer!==null?this.renderer:e.renderer,this.reference}},uS=(o,e,t=null)=>new If(o,e,t),Pf=class extends Be{static get type(){return"ToneMappingNode"}constructor(e,t=dS,s=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=s}customCacheKey(){return sc(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){let t=this.colorNode||e.context.color,s=this._toneMapping;if(s===Ri)return t;let i=null,n=e.renderer.library.getToneMappingFunction(s);return n!==null?i=Z(n(t.rgb,this.exposureNode),t.a):(O("ToneMappingNode: Unsupported Tone Mapping configuration.",s),i=t),i}},hS=(o,e,t)=>new Pf(o,q(e),q(t)),dS=uS("toneMappingExposure","float");P("toneMapping",(o,e,t)=>hS(e,t,o));var Db=new WeakMap;function Lb(o,e){let t=Db.get(o);return t===void 0&&(t=new Jo(o,e),Db.set(o,t)),t}var ti=class extends hc{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=i,this.usage=Ln,this.instanced=!1,this.attribute=null,this.global=!0,e&&e.isBufferAttribute===!0&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(this.bufferStride===0&&this.bufferOffset===0){let t=e.globalCache.getData(this.value);return t===void 0&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return this.bufferType===null&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(this.attribute!==null)return;let t=this.getNodeType(e),s=e.getTypeLength(t),i=this.value,n=this.bufferStride||s,r=this.bufferOffset,a;i.isInterleavedBuffer===!0?a=i:i.isBufferAttribute===!0?a=Lb(i.array,n):a=Lb(i,n);let c=new xl(a,s,r);a.setUsage(this.usage),this.attribute=c,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){let t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),i=e.getPropertyName(s),n=null;return e.shaderStage==="vertex"||e.shaderStage==="compute"?(this.name=i,n=i):n=Sn(this).build(e,t),n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}};function dd(o,e=null,t=0,s=0,i=Ln,n=!1){return e==="mat3"||e===null&&o.itemSize===9?at(new ti(o,"vec3",9,0).setUsage(i).setInstanced(n),new ti(o,"vec3",9,3).setUsage(i).setInstanced(n),new ti(o,"vec3",9,6).setUsage(i).setInstanced(n)):e==="mat4"||e===null&&o.itemSize===16?gn(new ti(o,"vec4",16,0).setUsage(i).setInstanced(n),new ti(o,"vec4",16,4).setUsage(i).setInstanced(n),new ti(o,"vec4",16,8).setUsage(i).setInstanced(n),new ti(o,"vec4",16,12).setUsage(i).setInstanced(n)):new ti(o,e,t,s).setUsage(i)}var Bx=(o,e=null,t=0,s=0)=>dd(o,e,t,s),WM=(o,e=null,t=0,s=0)=>dd(o,e,t,s,Qr),ch=(o,e=null,t=0,s=0)=>dd(o,e,t,s,Ln,!0),Df=(o,e=null,t=0,s=0)=>dd(o,e,t,s,Qr,!0);P("toAttribute",o=>Bx(o.value));var Lf=class extends H{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.version=1,this.name="",this.updateBeforeType=te.OBJECT,this.onInitFunction=null}setCount(e){return this.count=e,this}getCount(){return this.count}dispose(){this.dispatchEvent({type:"dispose"})}setName(e){return this.name=e,this}label(e){return z('TSL: "label()" has been deprecated. Use "setName()" instead.',new ke),this.setName(e)}onInit(e){return this.onInitFunction=e,this}updateBefore({renderer:e}){e.compute(this)}setup(e){let t=this.computeNode.build(e);if(t){let s=e.getNodeProperties(this);s.outputComputeNode=t.outputNode,t.outputNode=null}return t}generate(e,t){let{shaderStage:s}=e;if(s==="compute"){let i=this.computeNode.build(e,"void");i!==""&&e.addLineFlowCode(i,this)}else{let n=e.getNodeProperties(this).outputComputeNode;if(n)return n.build(e,t)}}},Fx=(o,e=[64])=>{(e.length===0||e.length>3)&&O("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new ke);for(let t=0;t<e.length;t++){let s=e[t];(typeof s!="number"||s<=0||!Number.isInteger(s))&&O(`TSL: compute() workgroupSize element at index [ ${t} ] must be a positive integer`,new ke)}for(;e.length<3;)e.push(1);return new Lf(q(o),e)},pS=(o,e,t)=>Fx(o,t).setCount(e);P("compute",pS);P("computeKernel",Fx);var Uf=class extends H{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}getNodeType(e){let t=e.getCache(),s=e.getCacheFromNode(this,this.parent);e.setCache(s);let i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){let s=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);let n=this.node.build(e,...t);return e.setCache(s),n}setParent(e){return this.parent=e,this}getParent(){return this.parent}},go=o=>new Uf(q(o));function fS(o,e=!0){return z('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),go(o).setParent(e)}P("cache",fS);P("isolate",go);var Of=class extends H{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){let t=this.callNode.build(e,"void");return t!==""&&e.addLineFlowCode(t,this),this.outputNode.build(e)}},mS=oe(Of).setParameterLength(2);P("bypass",mS);var lh=class extends H{static get type(){return"RemapNode"}constructor(e,t,s,i=b(0),n=b(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=i,this.outHighNode=n,this.doClamp=!0}setup(){let{node:e,inLowNode:t,inHighNode:s,outLowNode:i,outHighNode:n,doClamp:r}=this,a=e.sub(t).div(s.sub(t));return r===!0&&(a=a.clamp()),a.mul(n.sub(i)).add(i)}},gS=oe(lh,null,null,{doClamp:!1}).setParameterLength(3,5),yS=oe(lh).setParameterLength(3,5);P("remap",gS);P("remapClamp",yS);var yo=class extends H{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){let s=this.getNodeType(e),i=this.snippet;if(s==="void")e.addLineFlowCode(i,this);else return e.format(i,s,t)}},ts=oe(yo).setParameterLength(1,2),xS=o=>(o?vt(o,ts("discard")):ts("discard")).toStack(),$M=()=>ts("return").toStack();P("discard",xS);var Vf=class extends Be{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=s,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color,s=(this._toneMapping!==null?this._toneMapping:e.toneMapping)||Ri,i=(this.outputColorSpace!==null?this.outputColorSpace:e.outputColorSpace)||Bi;return s!==Ri&&(t=t.toneMapping(s)),i!==Bi&&i!==me.workingColorSpace&&(t=t.workingToColorSpace(i)),t}},Ix=(o,e=null,t=null)=>new Vf(q(o),e,t);P("renderOutput",Ix);var kf=class extends Be{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}getNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){let t=this.callback,s=this.node.build(e);if(t!==null)t(e,s);else{let i="--- TSL debug - "+e.shaderStage+" shader ---",n="-".repeat(i.length),r="";r+="// #"+i+`#
|
|
`,r+=e.flow.code.replace(/^\t/mg,"")+`
|
|
`,r+="/* ... */ "+s+` /* ... */
|
|
`,r+="// #"+n+`#
|
|
`,pl(r)}return s}},bS=(o,e=null)=>new kf(q(o),e).toStack();P("debug",bS);var uh=class{constructor(){this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}},zf=class extends H{static get type(){return"InspectorNode"}constructor(e,t="",s=null){super(),this.node=e,this.name=t,this.callback=s,this.updateType=te.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}getNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return e.context.inspector===!0&&this.callback!==null&&(t=this.callback(t)),e.renderer.backend.isWebGPUBackend!==!0&&e.renderer.inspector.constructor!==uh&&_e('TSL: ".toInspector()" is only available with WebGPU.'),t}};function _S(o,e="",t=null){return o=q(o),o.before(new zf(o,e,t))}P("toInspector",_S);function qM(o){z("TSL: AddNodeElement has been removed in favor of tree-shaking. Trying add",o)}var hh=class extends H{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(t===null){let s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){let i=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){let t=this.getAttributeName(e),s=this.getNodeType(e);if(e.hasGeometryAttribute(t)===!0){let n=e.geometry.getAttribute(t),r=e.getTypeFromAttribute(n),a=e.getAttribute(t,r);return e.shaderStage==="vertex"?e.format(a.name,r,s):Sn(this).build(e,s)}else return z(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}},zi=(o,e=null)=>new hh(o,e),Re=(o=0)=>zi("uv"+(o>0?o:""),"vec2"),Gf=class extends H{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){let s=this.textureNode.build(e,"property"),i=this.levelNode===null?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(e),t)}},yn=oe(Gf).setParameterLength(1,2),Wf=class extends lr{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=te.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){let e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&s.width!==void 0){let{width:i,height:n}=s;this.value=Math.log2(Math.max(i,n))}}},Px=oe(Wf).setParameterLength(1),dh=class extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}},Dx=new xt,ps=class extends lr{static get type(){return"TextureNode"}constructor(e=Dx,t=null,s=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=te.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(t===null)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return this.value.isDepthTexture===!0?"float":this.value.type===Oe?"uvec4":this.value.type===ut?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return Re(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return this._matrixUniform===null&&(this._matrixUniform=j(this.value.matrix)),this._matrixUniform.mul(v(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=j(!1)),t=t.toVar(),this.sampler?t=this._flipYUniform.select(t.flipY(),t):t=this._flipYUniform.select(t.setY(T(yn(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){let t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.value;if(!s||s.isTexture!==!0)throw new dh("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);let i=A(()=>{let c=this.uvNode;return(c===null||e.context.forceUVContext===!0)&&e.context.getUV&&(c=e.context.getUV(this,e)),c||(c=this.getDefaultUV()),this.updateMatrix===!0&&(c=this.getTransformedUV(c)),c=this.setupUV(e,c),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?te.OBJECT:te.NONE,c})(),n=this.levelNode;n===null&&e.context.getTextureLevel&&(n=e.context.getTextureLevel(this));let r=null,a=null;if(this.compareNode!==null)if(e.renderer.hasCompatibility(Ys.TEXTURE_COMPARE))r=this.compareNode;else{let c=s.compareFunction;c===null||c===pu||c===Jr||c===Oa||c===Yn?a=this.compareNode:(r=this.compareNode,_e('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=n,t.biasNode=this.biasNode,t.compareNode=r,t.compareStepNode=a,t.gradNode=this.gradNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,this.sampler===!0?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,s,i,n,r,a,c,l){let u=this.value,h;return n?h=e.generateTextureBias(u,t,s,n,r,l):c?h=e.generateTextureGrad(u,t,s,c,r,l):a?h=e.generateTextureCompare(u,t,s,a,r,l):this.sampler===!1?h=e.generateTextureLoad(u,t,s,i,r,l):i?h=e.generateTextureLevel(u,t,s,i,r,l):h=e.generateTexture(u,t,s,r,l),h}generate(e,t){let s=this.value,i=e.getNodeProperties(this),n=super.generate(e,"property");if(/^sampler/.test(t))return n+"_sampler";if(e.isReference(t))return n;{let r=e.getDataFromNode(this),a=this.getNodeType(e),c=r.propertyName;if(c===void 0){let{uvNode:u,levelNode:h,biasNode:d,compareNode:p,compareStepNode:m,depthNode:g,gradNode:y,offsetNode:x}=i,_=this.generateUV(e,u),w=h?h.build(e,"float"):null,S=d?d.build(e,"float"):null,E=g?g.build(e,"int"):null,B=p?p.build(e,"float"):null,N=m?m.build(e,"float"):null,C=y?[y[0].build(e,"vec2"),y[1].build(e,"vec2")]:null,I=x?this.generateOffset(e,x):null,k=e.getVarFromNode(this);c=e.getPropertyName(k);let W=this.generateSnippet(e,n,_,w,S,E,B,C,I);if(N!==null){let X=s.compareFunction;X===Oa||X===Yn?W=ur(ts(W,a),ts(N,"float")).build(e,a):W=ur(ts(N,"float"),ts(W,a)).build(e,a)}e.addLineFlowCode(`${c} = ${W}`,this),r.snippet=W,r.propertyName=c}let l=c;return e.needsToWorkingColorSpace(s)&&(l=hd(ts(l,a),s.colorSpace).setup(e).build(e,a)),e.format(l,a,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){let t=this.clone();return t.uvNode=q(e),t.referenceNode=this.getBase(),q(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){let t=this.clone();t.biasNode=q(e).mul(Px(t)),t.referenceNode=this.getBase();let s=t.value;return t.generateMipmaps===!1&&(s&&s.generateMipmaps===!1||s.minFilter===Ue||s.magFilter===Ue)&&(z("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),q(t)}level(e){let t=this.clone();return t.levelNode=q(e),t.referenceNode=this.getBase(),q(t)}size(e){return yn(this,e)}bias(e){let t=this.clone();return t.biasNode=q(e),t.referenceNode=this.getBase(),q(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){let t=this.clone();return t.compareNode=q(e),t.referenceNode=this.getBase(),q(t)}grad(e,t){let s=this.clone();return s.gradNode=[q(e),q(t)],s.referenceNode=this.getBase(),q(s)}depth(e){let t=this.clone();return t.depthNode=q(e),t.referenceNode=this.getBase(),q(t)}offset(e){let t=this.clone();return t.offsetNode=q(e),t.referenceNode=this.getBase(),q(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){let e=this.value,t=this._matrixUniform;t!==null&&(t.value=e.matrix),e.matrixAutoUpdate===!0&&e.updateMatrix();let s=this._flipYUniform;s!==null&&(s.value=e.image instanceof ImageBitmap&&e.flipY===!0||e.isRenderTargetTexture===!0||e.isFramebufferTexture===!0||e.isDepthTexture===!0)}clone(){let e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}},HM=oe(ps).setParameterLength(1,4).setName("texture"),xe=(o=Dx,e=null,t=null,s=null)=>{let i;return o&&o.isTextureNode===!0?(i=q(o.clone()),i.referenceNode=o.getBase(),e!==null&&(i.uvNode=q(e)),t!==null&&(i.levelNode=q(t)),s!==null&&(i.biasNode=q(s))):i=HM(o,e,t,s),i},XM=(o=Dx)=>xe(o),Ge=(...o)=>xe(...o).setSampler(!1),YM=(o,e,t)=>xe(o,e).level(t),jM=o=>(o.isNode===!0?o:xe(o)).convert("sampler"),ZM=o=>(o.isNode===!0?o:xe(o)).convert("samplerComparison"),gc=class extends lr{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}},Fc=(o,e,t)=>new gc(o,e,t),$f=class extends Vi{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){let t=super.generate(e),s=this.getNodeType(),i=this.node.getPaddedType();return e.format(t,i,s)}},qf=class extends gc{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=t===null?fn(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=te.RENDER,this.isArrayBufferNode=!0}getNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){let e=this.elementType,t="vec4";return e==="mat2"?t="mat2":/mat/.test(e)===!0?t="mat4":e.charAt(0)==="i"?t="ivec4":e.charAt(0)==="u"&&(t="uvec4"),t}update(){let{array:e,value:t}=this,s=this.elementType;if(s==="float"||s==="int"||s==="uint")for(let i=0;i<e.length;i++){let n=i*4;t[n]=e[i]}else if(s==="color")for(let i=0;i<e.length;i++){let n=i*4,r=e[i];t[n]=r.r,t[n+1]=r.g,t[n+2]=r.b||0}else if(s==="mat2")for(let i=0;i<e.length;i++){let n=i*4,r=e[i];t[n]=r.elements[0],t[n+1]=r.elements[1],t[n+2]=r.elements[2],t[n+3]=r.elements[3]}else if(s==="mat3")for(let i=0;i<e.length;i++){let n=i*16,r=e[i];t[n]=r.elements[0],t[n+1]=r.elements[1],t[n+2]=r.elements[2],t[n+4]=r.elements[3],t[n+5]=r.elements[4],t[n+6]=r.elements[5],t[n+8]=r.elements[6],t[n+9]=r.elements[7],t[n+10]=r.elements[8],t[n+15]=1}else if(s==="mat4")for(let i=0;i<e.length;i++){let n=i*16,r=e[i];for(let a=0;a<r.elements.length;a++)t[n+a]=r.elements[a]}else for(let i=0;i<e.length;i++){let n=i*4,r=e[i];t[n]=r.x,t[n+1]=r.y,t[n+2]=r.z||0,t[n+3]=r.w||0}}setup(e){let t=this.array.length,s=this.elementType,i=Float32Array,n=this.paddedType,r=e.getTypeLength(n);return s.charAt(0)==="i"&&(i=Int32Array),s.charAt(0)==="u"&&(i=Uint32Array),this.value=new i(t*r),this.bufferCount=t,this.bufferType=n,this.update(),super.setup(e)}element(e){return new $f(this,q(e))}},St=(o,e)=>new qf(o,e),Hf=class extends H{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}},qi=oe(Hf).setParameterLength(1),ka,za,pt=class o extends H{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this._output=null,this.isViewportNode=!0}getNodeType(){return this.scope===o.DPR?"float":this.scope===o.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=te.NONE;return(this.scope===o.SIZE||this.scope===o.VIEWPORT||this.scope===o.DPR)&&(e=te.RENDER),this.updateType=e,e}update({renderer:e}){let t=e.getRenderTarget();this.scope===o.VIEWPORT?t!==null?za.copy(t.viewport):(e.getViewport(za),za.multiplyScalar(e.getPixelRatio())):this.scope===o.DPR?this._output.value=e.getPixelRatio():t!==null?(ka.width=t.width,ka.height=t.height):e.getDrawingBufferSize(ka)}setup(){let e=this.scope,t=null;return e===o.SIZE?t=j(ka||(ka=new re)):e===o.VIEWPORT?t=j(za||(za=new Te)):e===o.DPR?t=j(1):t=U(gr.div(hr)),this._output=t,t}generate(e){if(this.scope===o.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){let s=e.getNodeProperties(hr).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}};pt.COORDINATE="coordinate";pt.VIEWPORT="viewport";pt.SIZE="size";pt.UV="uv";pt.DPR="dpr";var TS=G(pt,pt.DPR),ci=G(pt,pt.UV),hr=G(pt,pt.SIZE),gr=G(pt,pt.COORDINATE),Lx=G(pt,pt.VIEWPORT),Ux=Lx.zw,SS=gr.sub(Lx.xy),JM=SS.div(Ux),QM=A(()=>(z('TSL: "viewportResolution" is deprecated. Use "screenSize" instead.',new ke),hr),"vec2").once()(),Fp=null,mu=null,Ip=null,gu=null,Pp=null,yu=null,Dp=null,xu=null,Lp=null,bu=null,Up=null,_u=null,Op=null,Tu=null,vn=j(0,"uint").setName("u_cameraIndex").setGroup(ad("cameraIndex")).toVarying("v_cameraIndex"),un=j("float").setName("cameraNear").setGroup(J).onRenderUpdate(({camera:o})=>o.near),hn=j("float").setName("cameraFar").setGroup(J).onRenderUpdate(({camera:o})=>o.far),Oi=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.projectionMatrix);mu===null?mu=St(t).setGroup(J).setName("cameraProjectionMatrices"):mu.array=t,e=mu.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraProjectionMatrix")}else Fp===null&&(Fp=j(o.projectionMatrix).setName("cameraProjectionMatrix").setGroup(J).onRenderUpdate(({camera:t})=>t.projectionMatrix)),e=Fp;return e}).once()(),vS=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.projectionMatrixInverse);gu===null?gu=St(t).setGroup(J).setName("cameraProjectionMatricesInverse"):gu.array=t,e=gu.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraProjectionMatrixInverse")}else Ip===null&&(Ip=j(o.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(J).onRenderUpdate(({camera:t})=>t.projectionMatrixInverse)),e=Ip;return e}).once()(),fs=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.matrixWorldInverse);yu===null?yu=St(t).setGroup(J).setName("cameraViewMatrices"):yu.array=t,e=yu.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraViewMatrix")}else Pp===null&&(Pp=j(o.matrixWorldInverse).setName("cameraViewMatrix").setGroup(J).onRenderUpdate(({camera:t})=>t.matrixWorldInverse)),e=Pp;return e}).once()(),KM=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.matrixWorld);xu===null?xu=St(t).setGroup(J).setName("cameraWorldMatrices"):xu.array=t,e=xu.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraWorldMatrix")}else Dp===null&&(Dp=j(o.matrixWorld).setName("cameraWorldMatrix").setGroup(J).onRenderUpdate(({camera:t})=>t.matrixWorld)),e=Dp;return e}).once()(),eA=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.normalMatrix);bu===null?bu=St(t).setGroup(J).setName("cameraNormalMatrices"):bu.array=t,e=bu.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraNormalMatrix")}else Lp===null&&(Lp=j(o.normalMatrix).setName("cameraNormalMatrix").setGroup(J).onRenderUpdate(({camera:t})=>t.normalMatrix)),e=Lp;return e}).once()(),wS=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s=0,i=o.cameras.length;s<i;s++)t.push(new R);_u===null?_u=St(t).setGroup(J).setName("cameraPositions").onRenderUpdate(({camera:s},i)=>{let n=s.cameras,r=i.array;for(let a=0,c=n.length;a<c;a++)r[a].setFromMatrixPosition(n[a].matrixWorld)}):_u.array=t,e=_u.element(o.isMultiViewCamera?qi("gl_ViewID_OVR"):vn).toConst("cameraPosition")}else Up===null&&(Up=j(new R).setName("cameraPosition").setGroup(J).onRenderUpdate(({camera:t},s)=>s.value.setFromMatrixPosition(t.matrixWorld))),e=Up;return e}).once()(),tA=A(({camera:o})=>{let e;if(o.isArrayCamera&&o.cameras.length>0){let t=[];for(let s of o.cameras)t.push(s.viewport);Tu===null?Tu=St(t,"vec4").setGroup(J).setName("cameraViewports"):Tu.array=t,e=Tu.element(vn).toConst("cameraViewport")}else Op===null&&(Op=Z(0,0,hr.x,hr.y).toConst("cameraViewport")),e=Op;return e}).once()(),Ub=new Vn,je=class o extends H{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=te.OBJECT,this.uniformNode=new lr(null)}getNodeType(){let e=this.scope;if(e===o.WORLD_MATRIX)return"mat4";if(e===o.POSITION||e===o.VIEW_POSITION||e===o.DIRECTION||e===o.SCALE)return"vec3";if(e===o.RADIUS)return"float"}update(e){let t=this.object3d,s=this.uniformNode,i=this.scope;if(i===o.WORLD_MATRIX)s.value=t.matrixWorld;else if(i===o.POSITION)s.value=s.value||new R,s.value.setFromMatrixPosition(t.matrixWorld);else if(i===o.SCALE)s.value=s.value||new R,s.value.setFromMatrixScale(t.matrixWorld);else if(i===o.DIRECTION)s.value=s.value||new R,t.getWorldDirection(s.value);else if(i===o.VIEW_POSITION){let n=e.camera;s.value=s.value||new R,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(n.matrixWorldInverse)}else if(i===o.RADIUS){let n=e.object.geometry;n.boundingSphere===null&&n.computeBoundingSphere(),Ub.copy(n.boundingSphere).applyMatrix4(t.matrixWorld),s.value=Ub.radius}}generate(e){let t=this.scope;return t===o.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===o.POSITION||t===o.VIEW_POSITION||t===o.DIRECTION||t===o.SCALE?this.uniformNode.nodeType="vec3":t===o.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}};je.WORLD_MATRIX="worldMatrix";je.POSITION="position";je.SCALE="scale";je.VIEW_POSITION="viewPosition";je.DIRECTION="direction";je.RADIUS="radius";var sA=oe(je,je.DIRECTION).setParameterLength(1),iA=oe(je,je.WORLD_MATRIX).setParameterLength(1),nA=oe(je,je.POSITION).setParameterLength(1),rA=oe(je,je.SCALE).setParameterLength(1),oA=oe(je,je.VIEW_POSITION).setParameterLength(1),aA=oe(je,je.RADIUS).setParameterLength(1),kt=class extends je{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}},cA=G(kt,kt.DIRECTION),ls=G(kt,kt.WORLD_MATRIX),lA=G(kt,kt.POSITION),uA=G(kt,kt.SCALE),hA=G(kt,kt.VIEW_POSITION),dA=G(kt,kt.RADIUS),MS=j(new Nt).onObjectUpdate(({object:o},e)=>e.value.getNormalMatrix(o.matrixWorld)),pA=j(new de).onObjectUpdate(({object:o},e)=>e.value.copy(o.matrixWorld).invert()),wn=A(o=>o.context.modelViewMatrix||AS).once()().toVar("modelViewMatrix"),AS=fs.mul(ls),Xf=A(o=>(o.context.isHighPrecisionModelViewMatrix=!0,j("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))).once()().toVar("highpModelViewMatrix"),Yf=A(o=>{let e=o.context.isHighPrecisionModelViewMatrix;return j("mat3").onObjectUpdate(({object:t,camera:s})=>(e!==!0&&t.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix)))}).once()().toVar("highpModelNormalViewMatrix"),NS=A(o=>o.shaderStage!=="fragment"?(_e("TSL: `clipSpace` is only available in fragment stage."),Z()):o.context.clipSpace.toVarying("v_clipSpace")).once()(),Ic=zi("position","vec3"),Ve=Ic.toVarying("positionLocal"),_o=Ic.toVarying("positionPrevious"),li=A(o=>ls.mul(Ve).xyz.toVarying(o.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),Ox=A(()=>Ve.transformDirection(ls).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),qe=A(o=>{if(o.shaderStage==="fragment"&&o.material.vertexNode){let e=vS.mul(NS);return e.xyz.div(e.w).toVar("positionView")}return o.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),Ce=A(o=>{let e;return o.camera.isOrthographicCamera?e=v(0,0,1):e=qe.negate().toVarying("v_positionViewDirection").normalize(),e.toVar("positionViewDirection")},"vec3").once(["POSITION"])(),jf=class extends H{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if(e.shaderStage!=="fragment")return"true";let{material:t}=e;return t.side===rt?"false":e.getFrontFacing()}},RS=G(jf),Vx=b(RS).mul(2).sub(1),Co=A(([o],{material:e})=>{let t=e.side;return t===rt?o=o.mul(-1):t===$s&&(o=o.mul(Vx)),o}),pd=zi("normal","vec3"),zt=A(o=>o.geometry.hasAttribute("normal")===!1?(z('TSL: Vertex attribute "normal" not found on geometry.'),v(0,1,0)):pd,"vec3").once()().toVar("normalLocal"),CS=qe.dFdx().cross(qe.dFdy()).normalize().toVar("normalFlat"),To=A(o=>{let e;return o.isFlatShading()?e=CS:e=kx(zt).toVarying("v_normalViewGeometry").normalize(),e},"vec3").once()().toVar("normalViewGeometry"),ES=A(o=>{let e=To.transformDirection(fs);return o.isFlatShading()!==!0&&(e=e.toVarying("v_normalWorldGeometry")),e.normalize().toVar("normalWorldGeometry")},"vec3").once()(),ye=A(o=>{let e;return o.subBuildFn==="NORMAL"||o.subBuildFn==="VERTEX"?(e=To,o.isFlatShading()!==!0&&(e=Co(e))):e=o.context.setupNormal().context({getUV:null,getTextureLevel:null}),e},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),Mn=ye.transformDirection(fs).toVar("normalWorld"),dn=A(({subBuildFn:o,context:e})=>{let t;return o==="NORMAL"||o==="VERTEX"?t=ye:t=e.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),BS=A(([o,e=ls])=>{let t=at(e),s=o.div(v(t[0].dot(t[0]),t[1].dot(t[1]),t[2].dot(t[2])));return t.mul(s).xyz}),kx=A(([o],e)=>{let t=e.context.modelNormalViewMatrix;if(t)return t.transformDirection(o);let s=MS.mul(o);return fs.transformDirection(s)}),fA=A(()=>(z('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),ye)).once(["NORMAL","VERTEX"])(),mA=A(()=>(z('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),Mn)).once(["NORMAL","VERTEX"])(),gA=A(()=>(z('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),dn)).once(["NORMAL","VERTEX"])(),Ob=new jt,Vp=new de,FS=j(0).onReference(({material:o})=>o).onObjectUpdate(({material:o})=>o.refractionRatio),qu=j(1).onReference(({material:o})=>o).onObjectUpdate(function({material:o,scene:e}){return o.envMap?o.envMapIntensity:e.environmentIntensity}),zx=j(new de).onReference(function(o){return o.material}).onObjectUpdate(function({material:o,scene:e}){let t=e.environment!==null&&o.envMap===null?e.environmentRotation:o.envMapRotation;return t?(Ob.copy(t),Vp.makeRotationFromEuler(Ob)):Vp.identity(),Vp}),IS=Ce.negate().reflect(ye),PS=Ce.negate().refract(ye,FS),DS=IS.transformDirection(fs).toVar("reflectVector"),LS=PS.transformDirection(fs).toVar("reflectVector"),US=new kn,Zf=class extends ps{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,i=null){super(e,t,s,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){let e=this.value;return e.mapping===qn?DS:e.mapping===ca?LS:(O('CubeTextureNode: Mapping "%s" not supported.',e.mapping),v(0,0,0))}setUpdateMatrix(){}setupUV(e,t){let s=this.value;return s.isDepthTexture===!0?e.renderer.coordinateSystem===Yt?v(t.x,t.y.negate(),t.z):t:((e.renderer.coordinateSystem===Yt||!s.isRenderTargetTexture)&&(t=v(t.x.negate(),t.yz)),zx.mul(t))}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}},Gx=oe(Zf).setParameterLength(1,4).setName("cubeTexture"),Ft=(o=US,e=null,t=null,s=null)=>{let i;return o&&o.isCubeTextureNode===!0?(i=q(o.clone()),i.referenceNode=o,e!==null&&(i.uvNode=q(e)),t!==null&&(i.levelNode=q(t)),s!==null&&(i.biasNode=q(s))):i=Gx(o,e,t,s),i},yA=(o=US)=>Gx(o),Jf=class extends Vi{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),s=this.referenceNode.getNodeType(),i=this.getNodeType();return e.format(t,s,i)}},So=class extends H{static get type(){return"ReferenceNode"}constructor(e,t,s=null,i=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=i,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=te.OBJECT}element(e){return new Jf(this,q(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return z('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;this.count!==null?t=Fc(null,e,this.count):Array.isArray(this.getValueFromReference())?t=St(null,e):e==="texture"?t=xe(null):e==="cubeTexture"?t=Ft(null):t=j(null,e),this.group!==null&&t.setGroup(this.group),this.name!==null&&t.setName(this.name),this.node=t}getNodeType(e){return this.node===null&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,s=e[t[0]];for(let i=1;i<t.length;i++)s=s[t[i]];return s}updateReference(e){return this.reference=this.object!==null?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}},Ie=(o,e,t)=>new So(o,e,t),Qf=(o,e,t,s)=>new So(o,e,s,t),Kf=class extends So{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=this.material!==null?this.material:e.material,this.reference}},Di=(o,e,t=null)=>new Kf(o,e,t),OS=Re(),xA=qe.dFdx(),bA=qe.dFdy(),VS=OS.dFdx(),kS=OS.dFdy(),zS=ye,GS=bA.cross(zS),WS=zS.cross(xA),em=GS.mul(VS.x).add(WS.mul(kS.x)),tm=GS.mul(VS.y).add(WS.mul(kS.y)),Vb=em.dot(em).max(tm.dot(tm)),$S=Vb.equal(0).select(0,Vb.inverseSqrt()),_A=em.mul($S).toVar("tangentViewFrame"),TA=tm.mul($S).toVar("bitangentViewFrame"),fd=zi("tangent","vec4"),vo=fd.xyz.toVar("tangentLocal"),md=A(o=>{let e;return o.subBuildFn==="VERTEX"||o.geometry.hasAttribute("tangent")?e=wn.mul(Z(vo,0)).xyz.toVarying("v_tangentView").normalize():e=_A,o.isFlatShading()!==!0&&(e=Co(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),qS=md.transformDirection(fs).toVarying("v_tangentWorld").normalize().toVar("tangentWorld"),gd=A(([o,e],t)=>{let s=o.mul(fd.w).xyz;return t.subBuildFn==="NORMAL"&&t.isFlatShading()!==!0&&(s=s.toVarying(e)),s}).once(["NORMAL"]),SA=gd(pd.cross(fd),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),vA=gd(zt.cross(vo),"v_bitangentLocal").normalize().toVar("bitangentLocal"),HS=A(o=>{let e;return o.subBuildFn==="VERTEX"||o.geometry.hasAttribute("tangent")?e=gd(ye.cross(md),"v_bitangentView").normalize():e=TA,o.isFlatShading()!==!0&&(e=Co(e)),e},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),wA=gd(Mn.cross(qS),"v_bitangentWorld").normalize().toVar("bitangentWorld"),nr=at(md,HS,ye).toVar("TBNViewMatrix"),XS=Ce.mul(nr),MA=(o,e)=>o.sub(XS.mul(e)),YS=A(()=>{let o=ar.cross(Ce);return o=o.cross(ar).normalize(),o=le(o,ye,cn.mul(ii.oneMinus()).oneMinus().pow2().pow2()).normalize(),o}).once()(),jS=o=>q(o).mul(.5).add(.5),AA=o=>q(o).mul(2).sub(1),sm=o=>v(o,It(ud(b(1).sub(ds(o,o))))),im=class extends Be{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=Xs,this.unpackNormalMode=du}setup(e){let{normalMapType:t,scaleNode:s,unpackNormalMode:i}=this,n=this.node.mul(2).sub(1);if(t===Xs?i===Sp?n=sm(n.xy):i===ub?n=sm(n.yw):i!==du&&console.error(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==du&&console.error(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),s!==null){let a=s;e.isFlatShading()===!0&&(a=Co(a)),n=v(n.xy.mul(a),n.z)}let r=null;return t===lb?r=kx(n):t===Xs?r=nr.mul(n).normalize():(O(`NodeMaterial: Unsupported normal map type: ${t}`),r=ye),r}},nm=oe(im).setParameterLength(1,2),NA=A(({textureNode:o,bumpScale:e})=>{let t=i=>o.isolate().context({getUV:n=>i(n.uvNode||Re()),forceUVContext:!0}),s=b(t(i=>i));return U(b(t(i=>i.add(i.dFdx()))).sub(s),b(t(i=>i.add(i.dFdy()))).sub(s)).mul(e)}),RA=A(o=>{let{surf_pos:e,surf_norm:t,dHdxy:s}=o,i=e.dFdx().normalize(),n=e.dFdy().normalize(),r=t,a=n.cross(r),c=r.cross(i),l=i.dot(a).mul(Vx),u=l.sign().mul(s.x.mul(a).add(s.y.mul(c)));return l.abs().mul(t).sub(u).normalize()}),rm=class extends Be{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){let e=this.scaleNode!==null?this.scaleNode:1,t=NA({textureNode:this.textureNode,bumpScale:e});return RA({surf_pos:qe,surf_norm:ye,dHdxy:t})}},Wx=oe(rm).setParameterLength(1,2),kb=new Map,L=class o extends H{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=kb.get(e);return s===void 0&&(s=Di(e,t),kb.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache(e==="map"?"map":e+"Map","texture")}setup(e){let t=e.context.material,s=this.scope,i=null;if(s===o.COLOR){let n=t.color!==void 0?this.getColor(s):v();t.map&&t.map.isTexture===!0?i=n.mul(this.getTexture("map")):i=n}else if(s===o.OPACITY){let n=this.getFloat(s);t.alphaMap&&t.alphaMap.isTexture===!0?i=n.mul(this.getTexture("alpha")):i=n}else if(s===o.SPECULAR_STRENGTH)t.specularMap&&t.specularMap.isTexture===!0?i=this.getTexture("specular").r:i=b(1);else if(s===o.SPECULAR_INTENSITY){let n=this.getFloat(s);t.specularIntensityMap&&t.specularIntensityMap.isTexture===!0?i=n.mul(this.getTexture(s).a):i=n}else if(s===o.SPECULAR_COLOR){let n=this.getColor(s);t.specularColorMap&&t.specularColorMap.isTexture===!0?i=n.mul(this.getTexture(s).rgb):i=n}else if(s===o.ROUGHNESS){let n=this.getFloat(s);t.roughnessMap&&t.roughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).g):i=n}else if(s===o.METALNESS){let n=this.getFloat(s);t.metalnessMap&&t.metalnessMap.isTexture===!0?i=n.mul(this.getTexture(s).b):i=n}else if(s===o.EMISSIVE){let n=this.getFloat("emissiveIntensity"),r=this.getColor(s).mul(n);t.emissiveMap&&t.emissiveMap.isTexture===!0?i=r.mul(this.getTexture(s)):i=r}else if(s===o.NORMAL)t.normalMap?(i=nm(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=t.normalMapType,(t.normalMap.format==Ms||t.normalMap.format==Zr||t.normalMap.format==jr)&&(i.unpackNormalMode=Sp)):t.bumpMap?i=Wx(this.getTexture("bump").r,this.getFloat("bumpScale")):i=ye;else if(s===o.CLEARCOAT){let n=this.getFloat(s);t.clearcoatMap&&t.clearcoatMap.isTexture===!0?i=n.mul(this.getTexture(s).r):i=n}else if(s===o.CLEARCOAT_ROUGHNESS){let n=this.getFloat(s);t.clearcoatRoughnessMap&&t.clearcoatRoughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).r):i=n}else if(s===o.CLEARCOAT_NORMAL)t.clearcoatNormalMap?i=nm(this.getTexture(s),this.getCache(s+"Scale","vec2")):i=ye;else if(s===o.SHEEN){let n=this.getColor("sheenColor").mul(this.getFloat("sheen"));t.sheenColorMap&&t.sheenColorMap.isTexture===!0?i=n.mul(this.getTexture("sheenColor").rgb):i=n}else if(s===o.SHEEN_ROUGHNESS){let n=this.getFloat(s);t.sheenRoughnessMap&&t.sheenRoughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).a):i=n,i=i.clamp(1e-4,1)}else if(s===o.ANISOTROPY)if(t.anisotropyMap&&t.anisotropyMap.isTexture===!0){let n=this.getTexture(s);i=rd(lo.x,lo.y,lo.y.negate(),lo.x).mul(n.rg.mul(2).sub(U(1)).normalize().mul(n.b))}else i=lo;else if(s===o.IRIDESCENCE_THICKNESS){let n=Ie("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){let r=Ie("0","float",t.iridescenceThicknessRange);i=n.sub(r).mul(this.getTexture(s).g).add(r)}else i=n}else if(s===o.TRANSMISSION){let n=this.getFloat(s);t.transmissionMap?i=n.mul(this.getTexture(s).r):i=n}else if(s===o.THICKNESS){let n=this.getFloat(s);t.thicknessMap?i=n.mul(this.getTexture(s).g):i=n}else if(s===o.IOR)i=this.getFloat(s);else if(s===o.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===o.AO)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else if(s===o.LINE_DASH_OFFSET)i=t.dashOffset?this.getFloat(s):b(0);else{let n=this.getNodeType(e);i=this.getCache(s,n)}return i}};L.ALPHA_TEST="alphaTest";L.COLOR="color";L.OPACITY="opacity";L.SHININESS="shininess";L.SPECULAR="specular";L.SPECULAR_STRENGTH="specularStrength";L.SPECULAR_INTENSITY="specularIntensity";L.SPECULAR_COLOR="specularColor";L.REFLECTIVITY="reflectivity";L.ROUGHNESS="roughness";L.METALNESS="metalness";L.NORMAL="normal";L.CLEARCOAT="clearcoat";L.CLEARCOAT_ROUGHNESS="clearcoatRoughness";L.CLEARCOAT_NORMAL="clearcoatNormal";L.EMISSIVE="emissive";L.ROTATION="rotation";L.SHEEN="sheen";L.SHEEN_ROUGHNESS="sheenRoughness";L.ANISOTROPY="anisotropy";L.IRIDESCENCE="iridescence";L.IRIDESCENCE_IOR="iridescenceIOR";L.IRIDESCENCE_THICKNESS="iridescenceThickness";L.IOR="ior";L.TRANSMISSION="transmission";L.THICKNESS="thickness";L.ATTENUATION_DISTANCE="attenuationDistance";L.ATTENUATION_COLOR="attenuationColor";L.LINE_SCALE="scale";L.LINE_DASH_SIZE="dashSize";L.LINE_GAP_SIZE="gapSize";L.LINE_WIDTH="linewidth";L.LINE_DASH_OFFSET="dashOffset";L.POINT_SIZE="size";L.DISPERSION="dispersion";L.LIGHT_MAP="light";L.AO="ao";var ZS=G(L,L.ALPHA_TEST),JS=G(L,L.COLOR),QS=G(L,L.SHININESS),KS=G(L,L.EMISSIVE),$x=G(L,L.OPACITY),ev=G(L,L.SPECULAR),om=G(L,L.SPECULAR_INTENSITY),tv=G(L,L.SPECULAR_COLOR),oc=G(L,L.SPECULAR_STRENGTH),Hu=G(L,L.REFLECTIVITY),sv=G(L,L.ROUGHNESS),iv=G(L,L.METALNESS),nv=G(L,L.NORMAL),rv=G(L,L.CLEARCOAT),ov=G(L,L.CLEARCOAT_ROUGHNESS),av=G(L,L.CLEARCOAT_NORMAL),cv=G(L,L.ROTATION),lv=G(L,L.SHEEN),uv=G(L,L.SHEEN_ROUGHNESS),hv=G(L,L.ANISOTROPY),dv=G(L,L.IRIDESCENCE),pv=G(L,L.IRIDESCENCE_IOR),fv=G(L,L.IRIDESCENCE_THICKNESS),mv=G(L,L.TRANSMISSION),gv=G(L,L.THICKNESS),yv=G(L,L.IOR),xv=G(L,L.ATTENUATION_DISTANCE),bv=G(L,L.ATTENUATION_COLOR),_v=G(L,L.LINE_SCALE),Tv=G(L,L.LINE_DASH_SIZE),Sv=G(L,L.LINE_GAP_SIZE),CA=G(L,L.LINE_WIDTH),vv=G(L,L.LINE_DASH_OFFSET),wv=G(L,L.POINT_SIZE),Mv=G(L,L.DISPERSION),qx=G(L,L.LIGHT_MAP),Av=G(L,L.AO),lo=j(new re).onReference(function(o){return o.material}).onRenderUpdate(function({material:o}){this.value.set(o.anisotropy*Math.cos(o.anisotropyRotation),o.anisotropy*Math.sin(o.anisotropyRotation))}),Nv=A(o=>o.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection"),am=class extends Vi{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){let s=this.storageBufferNode.structTypeNode;return s?s.getMemberType(e,t):"void"}setup(e){return e.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s,i=e.context.assign;if(e.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||e.shaderStage!=="compute")?s=e.generatePBO(this):s=this.node.build(e):s=super.generate(e),i!==!0){let n=this.getNodeType(e);s=e.format(s,n,t)}return s}},EA=oe(am).setParameterLength(2),cm=class extends gc{static get type(){return"StorageBufferNode"}constructor(e,t=null,s=0){let i,n=null;t&&t.isStruct?(i="struct",n=t.layout,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(s=e.count)):t===null&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)?(i=Y_(e.itemSize),s=e.count):i=t,super(e,i,s),this.isStorageBufferNode=!0,this.structTypeNode=n,this.access=dt.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,e.isStorageBufferAttribute!==!0&&e.isStorageInstancedBufferAttribute!==!0&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(this.bufferCount===0){let t=e.globalCache.getData(this.value);return t===void 0&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return EA(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(dt.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=Bx(this.value),this._varying=Sn(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);let{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return this.structTypeNode!==null?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(this.structTypeNode!==null&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);let{attribute:t,varying:s}=this.getAttributeData(),i=s.build(e);return e.registerTransform(i,t),i}},xn=(o,e=null,t=0)=>new cm(o,e,t),Ke=class o extends H{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){let t=this.getNodeType(e),s=this.scope,i;if(s===o.VERTEX)i=e.getVertexIndex();else if(s===o.INSTANCE)i=e.getInstanceIndex();else if(s===o.DRAW)i=e.getDrawIndex();else if(s===o.INVOCATION_LOCAL)i=e.getInvocationLocalIndex();else if(s===o.INVOCATION_SUBGROUP)i=e.getInvocationSubgroupIndex();else if(s===o.SUBGROUP)i=e.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+s);let n;return e.shaderStage==="vertex"||e.shaderStage==="compute"?n=i:n=Sn(this).build(e,t),n}};Ke.VERTEX="vertex";Ke.INSTANCE="instance";Ke.SUBGROUP="subgroup";Ke.INVOCATION_LOCAL="invocationLocal";Ke.INVOCATION_SUBGROUP="invocationSubgroup";Ke.DRAW="draw";var Rv=G(Ke,Ke.VERTEX),ui=G(Ke,Ke.INSTANCE),BA=G(Ke,Ke.SUBGROUP),FA=G(Ke,Ke.INVOCATION_SUBGROUP),IA=G(Ke,Ke.INVOCATION_LOCAL),Cv=G(Ke,Ke.DRAW),ph=class extends H{static get type(){return"InstanceNode"}constructor(e,t,s=null){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=s,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=te.FRAME,this.buffer=null,this.bufferColor=null,this.previousInstanceMatrixNode=null}get isStorageMatrix(){let{instanceMatrix:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}get isStorageColor(){let{instanceColor:e}=this;return e&&e.isStorageInstancedBufferAttribute===!0}setup(e){let{instanceMatrixNode:t,instanceColorNode:s}=this;t===null&&(t=this._createInstanceMatrixNode(!0,e),this.instanceMatrixNode=t);let{instanceColor:i,isStorageColor:n}=this;if(i&&s===null){if(n)s=xn(i,"vec3",Math.max(i.count,1)).element(ui);else{let a=new Ai(i.array,3),c=i.usage===Qr?Df:ch;this.bufferColor=a,s=v(c(a,"vec3",3,0))}this.instanceColorNode=s}let r=t.mul(Ve).xyz;if(Ve.assign(r),e.needsPreviousData()&&_o.assign(this.getPreviousInstancedPosition(e)),e.hasGeometryAttribute("normal")){let a=BS(zt,t);zt.assign(a)}this.instanceColorNode!==null&&fc("vec3","vInstanceColor").assign(this.instanceColorNode)}update(e){this.buffer!==null&&this.isStorageMatrix!==!0&&(this.buffer.clearUpdateRanges(),this.buffer.updateRanges.push(...this.instanceMatrix.updateRanges),this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version)),this.instanceColor&&this.bufferColor!==null&&this.isStorageColor!==!0&&(this.bufferColor.clearUpdateRanges(),this.bufferColor.updateRanges.push(...this.instanceColor.updateRanges),this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)),this.previousInstanceMatrixNode!==null&&e.object.previousInstanceMatrix.array.set(this.instanceMatrix.array)}getPreviousInstancedPosition(e){let t=e.object;return this.previousInstanceMatrixNode===null&&(t.previousInstanceMatrix=this.instanceMatrix.clone(),this.previousInstanceMatrixNode=this._createInstanceMatrixNode(!1,e)),this.previousInstanceMatrixNode.mul(_o).xyz}_createInstanceMatrixNode(e,t){let s,{instanceMatrix:i}=this,{count:n}=i;if(this.isStorageMatrix)s=xn(i,"mat4",Math.max(n,1)).element(ui);else if(n*16*4<=t.getUniformBufferLimit())s=Fc(i.array,"mat4",Math.max(n,1)).element(ui);else{let a=new Kl(i.array,16,1);e===!0&&(this.buffer=a);let c=i.usage===Qr?Df:ch,l=[c(a,"vec4",16,0),c(a,"vec4",16,4),c(a,"vec4",16,8),c(a,"vec4",16,12)];s=gn(...l)}return s}},PA=oe(ph).setParameterLength(2,3),lm=class extends ph{static get type(){return"InstancedMeshNode"}constructor(e){let{count:t,instanceMatrix:s,instanceColor:i}=e;super(t,s,i),this.instancedMesh=e}},Ev=oe(lm).setParameterLength(1),um=class extends H{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){this.batchingIdNode===null&&(e.getDrawIndex()===null?this.batchingIdNode=ui:this.batchingIdNode=Cv);let s=A(([m])=>{let g=T(yn(Ge(this.batchMesh._indirectTexture),0).x).toConst(),y=T(m).mod(g).toConst(),x=T(m).div(g).toConst();return Ge(this.batchMesh._indirectTexture,Qe(y,x)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(T(this.batchingIdNode)),i=this.batchMesh._matricesTexture,n=T(yn(Ge(i),0).x).toConst(),r=b(s).mul(4).toInt().toConst(),a=r.mod(n).toConst(),c=r.div(n).toConst(),l=gn(Ge(i,Qe(a,c)),Ge(i,Qe(a.add(1),c)),Ge(i,Qe(a.add(2),c)),Ge(i,Qe(a.add(3),c))),u=this.batchMesh._colorsTexture;if(u!==null){let g=A(([y])=>{let x=T(yn(Ge(u),0).x).toConst(),_=y,w=_.mod(x).toConst(),S=_.div(x).toConst();return Ge(u,Qe(w,S)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(s);fc("vec3","vBatchColor").assign(g)}let h=at(l);Ve.assign(l.mul(Ve));let d=zt.div(v(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),p=h.mul(d).xyz;zt.assign(p),e.hasGeometryAttribute("tangent")&&vo.mulAssign(h)}},Bv=oe(um).setParameterLength(1),zb=new WeakMap,fh=class extends H{static get type(){return"SkinningNode"}constructor(e){super("void"),this.skinnedMesh=e,this.updateType=te.OBJECT,this.skinIndexNode=zi("skinIndex","uvec4"),this.skinWeightNode=zi("skinWeight","vec4"),this.bindMatrixNode=Ie("bindMatrix","mat4"),this.bindMatrixInverseNode=Ie("bindMatrixInverse","mat4"),this.boneMatricesNode=Qf("skeleton.boneMatrices","mat4",e.skeleton.bones.length),this.positionNode=Ve,this.toPositionNode=Ve,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=this.positionNode){let{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:n,bindMatrixInverseNode:r}=this,a=e.element(s.x),c=e.element(s.y),l=e.element(s.z),u=e.element(s.w),h=n.mul(t),d=Ye(a.mul(i.x).mul(h),c.mul(i.y).mul(h),l.mul(i.z).mul(h),u.mul(i.w).mul(h));return r.mul(d).xyz}getSkinnedNormalAndTangent(e=this.boneMatricesNode,t=zt,s=vo){let{skinIndexNode:i,skinWeightNode:n,bindMatrixNode:r,bindMatrixInverseNode:a}=this,c=e.element(i.x),l=e.element(i.y),u=e.element(i.z),h=e.element(i.w),d=Ye(n.x.mul(c),n.y.mul(l),n.z.mul(u),n.w.mul(h));d=a.mul(d).mul(r);let p=d.transformDirection(t).xyz,m=d.transformDirection(s).xyz;return{skinNormal:p,skinTangent:m}}getPreviousSkinnedPosition(e){let t=e.object;return this.previousBoneMatricesNode===null&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Qf("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,_o)}setup(e){e.needsPreviousData()&&_o.assign(this.getPreviousSkinnedPosition(e));let t=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(t),e.hasGeometryAttribute("normal")){let{skinNormal:s,skinTangent:i}=this.getSkinnedNormalAndTangent();zt.assign(s),e.hasGeometryAttribute("tangent")&&vo.assign(i)}return t}generate(e,t){if(t!=="void")return super.generate(e,t)}update(e){let t=e.object&&e.object.skeleton?e.object.skeleton:this.skinnedMesh.skeleton;zb.get(t)!==e.frameId&&(zb.set(t,e.frameId),this.previousBoneMatricesNode!==null&&(t.previousBoneMatrices===null&&(t.previousBoneMatrices=new Float32Array(t.boneMatrices)),t.previousBoneMatrices.set(t.boneMatrices)),t.update())}},Fv=o=>new fh(o),DA=(o,e=null)=>{let t=new fh(o);return t.positionNode=xn(new Ai(o.geometry.getAttribute("position").array,3),"vec3").setPBO(!0).toReadOnly().element(ui).toVar(),t.skinIndexNode=xn(new Ai(new Uint32Array(o.geometry.getAttribute("skinIndex").array),4),"uvec4").setPBO(!0).toReadOnly().element(ui).toVar(),t.skinWeightNode=xn(new Ai(o.geometry.getAttribute("skinWeight").array,4),"vec4").setPBO(!0).toReadOnly().element(ui).toVar(),t.bindMatrixNode=j(o.bindMatrix,"mat4"),t.bindMatrixInverseNode=j(o.bindMatrixInverse,"mat4"),t.boneMatricesNode=Fc(o.skeleton.boneMatrices,"mat4",o.skeleton.bones.length),t.toPositionNode=e,q(t)},hm=class extends H{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){let t=e.getNodeProperties(this);if(t.stackNode!==void 0)return t;let s={};for(let a=0,c=this.params.length-1;a<c;a++){let l=this.params[a],u=l.isNode!==!0&&l.name||this.getVarName(a),h=l.isNode!==!0&&l.type||"int";s[u]=ts(u,h)}let i=e.addStack(),n=this.params[this.params.length-1](s);t.returnsNode=n.context({nodeLoop:n}),t.stackNode=i;let r=this.params[0];if(r.isNode!==!0&&typeof r.update=="function"){let a=A(this.params[0].update)(s);t.updateNode=a.context({nodeLoop:a})}return e.removeStack(),t}setup(e){if(this.getProperties(e),e.fnCall){let t=e.getDataFromNode(e.fnCall.shaderNode);t.hasLoop=!0}}generate(e){let t=this.getProperties(e),s=this.params,i=t.stackNode;for(let r=0,a=s.length-1;r<a;r++){let c=s[r],l=!1,u=null,h=null,d=null,p=null,m=null,g=null;c.isNode?c.getNodeType(e)==="bool"?(l=!0,p="bool",h=c.build(e,p)):(p="int",d=this.getVarName(r),u="0",h=c.build(e,p),m="<"):(p=c.type||"int",d=c.name||this.getVarName(r),u=c.start,h=c.end,m=c.condition,g=c.update,typeof u=="number"?u=e.generateConst(p,u):u&&u.isNode&&(u=u.build(e,p)),typeof h=="number"?h=e.generateConst(p,h):h&&h.isNode&&(h=h.build(e,p)),u!==void 0&&h===void 0?(u=u+" - 1",h="0",m=">="):h!==void 0&&u===void 0&&(u="0",m="<"),m===void 0&&(Number(u)>Number(h)?m=">=":m="<"));let y;if(l)y=`while ( ${h} )`;else{let x={start:u,end:h},_=x.start,w=x.end,S,E=()=>m.includes("<")?"+=":"-=";if(g!=null)switch(typeof g){case"function":S=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":S=d+" "+E()+" "+e.generateConst(p,g);break;case"string":S=d+" "+g;break;default:g.isNode?S=d+" "+E()+" "+g.build(e):(O("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),S="break /* invalid update */")}else p==="int"||p==="uint"?g=m.includes("<")?"++":"--":g=E()+" 1.",S=d+" "+g;let B=e.getVar(p,d)+" = "+_,N=d+" "+m+" "+w;y=`for ( ${B}; ${N}; ${S} )`}e.addFlowCode((r===0?`
|
|
`:"")+e.tab+y+` {
|
|
|
|
`).addFlowTab()}let n=i.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode(`
|
|
`+e.tab+n);for(let r=0,a=this.params.length-1;r<a;r++)e.addFlowCode((r===0?"":e.tab)+`}
|
|
|
|
`).removeFlowTab();e.addFlowTab()}},Me=(...o)=>new hm(or(o,"int")).toStack(),LA=()=>ts("continue").toStack(),Iv=()=>ts("break").toStack(),kp=new WeakMap,Qt=new Te,Gb=A(({bufferMap:o,influence:e,stride:t,width:s,depth:i,offset:n})=>{let r=T(Rv).mul(t).add(n),a=r.div(s),c=r.sub(a.mul(s));return Ge(o,Qe(c,a)).depth(i).xyz.mul(e)});function UA(o){let e=o.morphAttributes.position!==void 0,t=o.morphAttributes.normal!==void 0,s=o.morphAttributes.color!==void 0,i=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,n=i!==void 0?i.length:0,r=kp.get(o);if(r===void 0||r.count!==n){let x=function(){g.dispose(),kp.delete(o),o.removeEventListener("dispose",x)};r!==void 0&&r.texture.dispose();let a=o.morphAttributes.position||[],c=o.morphAttributes.normal||[],l=o.morphAttributes.color||[],u=0;e===!0&&(u=1),t===!0&&(u=2),s===!0&&(u=3);let h=o.attributes.position.count*u,d=1,p=4096;h>p&&(d=Math.ceil(h/p),h=p);let m=new Float32Array(h*d*4*n),g=new ml(m,h,d,n);g.type=Ct,g.needsUpdate=!0;let y=u*4;for(let _=0;_<n;_++){let w=a[_],S=c[_],E=l[_],B=h*d*4*_;for(let N=0;N<w.count;N++){let C=N*y;e===!0&&(Qt.fromBufferAttribute(w,N),m[B+C+0]=Qt.x,m[B+C+1]=Qt.y,m[B+C+2]=Qt.z,m[B+C+3]=0),t===!0&&(Qt.fromBufferAttribute(S,N),m[B+C+4]=Qt.x,m[B+C+5]=Qt.y,m[B+C+6]=Qt.z,m[B+C+7]=0),s===!0&&(Qt.fromBufferAttribute(E,N),m[B+C+8]=Qt.x,m[B+C+9]=Qt.y,m[B+C+10]=Qt.z,m[B+C+11]=E.itemSize===4?Qt.w:1)}}r={count:n,texture:g,stride:u,size:new re(h,d)},kp.set(o,r),o.addEventListener("dispose",x)}return r}var dm=class extends H{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=j(1),this.updateType=te.OBJECT}setup(e){let{geometry:t}=e,s=t.morphAttributes.position!==void 0,i=t.hasAttribute("normal")&&t.morphAttributes.normal!==void 0,n=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,r=n!==void 0?n.length:0,{texture:a,stride:c,size:l}=UA(t);s===!0&&Ve.mulAssign(this.morphBaseInfluence),i===!0&&zt.mulAssign(this.morphBaseInfluence);let u=T(l.width);Me(r,({i:h})=>{let d=b(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?d.assign(Ge(this.mesh.morphTexture,Qe(T(h).add(1),T(ui))).r):d.assign(Ie("morphTargetInfluences","float").element(h).toVar()),K(d.notEqual(0),()=>{s===!0&&Ve.addAssign(Gb({bufferMap:a,influence:d,stride:c,width:u,depth:h,offset:T(0)})),i===!0&&zt.addAssign(Gb({bufferMap:a,influence:d,stride:c,width:u,depth:h,offset:T(1)}))})})}update(){let e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce((t,s)=>t+s,0)}},Pv=oe(dm).setParameterLength(1),Tn=class extends H{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}},pm=class extends Tn{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}},fm=class extends oh{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,i=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=i,this._value=null}getContext(){let{backdropNode:e,backdropAlphaNode:t}=this,s=v().toVar("directDiffuse"),i=v().toVar("directSpecular"),n=v().toVar("indirectDiffuse"),r=v().toVar("indirectSpecular"),a={directDiffuse:s,directSpecular:i,indirectDiffuse:n,indirectSpecular:r};return{radiance:v().toVar("radiance"),irradiance:v().toVar("irradiance"),iblIrradiance:v().toVar("iblIrradiance"),ambientOcclusion:b(1).toVar("ambientOcclusion"),reflectedLight:a,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}},Dv=oe(fm),mm=class extends Tn{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}},eo=new re,wo=class extends ps{static get type(){return"ViewportTextureNode"}constructor(e=ci,t=null,s=null){let i=null;s===null?(i=new Or,i.minFilter=Ci,s=i):i=s,super(s,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=te.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,s;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,s=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,s=this._cacheTextures),e===null)return t;if(s.has(e)===!1){let i=t.clone();s.set(e,i)}return s.get(e)}updateReference(e){let t=e.renderer.getRenderTarget();return this.value=this.getTextureForReference(t),this.value}updateBefore(e){let t=e.renderer,s=t.getRenderTarget();s===null?t.getDrawingBufferSize(eo):eo.set(s.width,s.height);let i=this.getTextureForReference(s);(i.image.width!==eo.width||i.image.height!==eo.height)&&(i.image.width=eo.width,i.image.height=eo.height,i.needsUpdate=!0);let n=i.generateMipmaps;i.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(i),i.generateMipmaps=n}clone(){let e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}},OA=oe(wo).setParameterLength(0,3),Hx=oe(wo,null,null,{generateMipmaps:!0}).setParameterLength(0,3),VA=Hx(),Lv=(o=ci,e=null)=>VA.sample(o,e),Su=null,gm=class extends wo{static get type(){return"ViewportDepthTextureNode"}constructor(e=ci,t=null){Su===null&&(Su=new Rt),super(e,t,Su)}getTextureForReference(){return Su}},Xx=oe(gm).setParameterLength(0,2),Is=class o extends H{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){let{scope:t}=this;return t===o.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){let{scope:t}=this,s=this.valueNode,i=null;if(t===o.DEPTH_BASE)s!==null&&(i=Ov().assign(s));else if(t===o.DEPTH)e.isPerspectiveCamera?i=Yx(qe.z,un,hn):i=xo(qe.z,un,hn);else if(t===o.LINEAR_DEPTH)if(s!==null)if(e.isPerspectiveCamera){let n=jx(s,un,hn);i=xo(n,un,hn)}else i=s;else i=xo(qe.z,un,hn);return i}};Is.DEPTH_BASE="depthBase";Is.DEPTH="depth";Is.LINEAR_DEPTH="linearDepth";var xo=(o,e,t)=>o.add(e).div(e.sub(t)),kA=(o,e,t)=>o.add(t).div(t.sub(e)),zA=A(([o,e,t],s)=>s.renderer.reversedDepthBuffer===!0?t.sub(e).mul(o).sub(t):e.sub(t).mul(o).sub(e)),Yx=(o,e,t)=>e.add(o).mul(t).div(t.sub(e).mul(o)),Uv=(o,e,t)=>e.mul(o.add(t)).div(o.mul(e.sub(t))),jx=A(([o,e,t],s)=>s.renderer.reversedDepthBuffer===!0?e.mul(t).div(e.sub(t).mul(o).sub(e)):e.mul(t).div(t.sub(e).mul(o).sub(t))),Zx=(o,e,t)=>{e=e.max(1e-6).toVar();let s=ri(o.negate().div(e)),i=ri(t.div(e));return s.div(i)},GA=(o,e,t)=>{let s=o.mul(cd(t.div(e)));return b(Math.E).pow(s).mul(e).negate()},Ov=oe(Is,Is.DEPTH_BASE),Jx=G(Is,Is.DEPTH),mh=oe(Is,Is.LINEAR_DEPTH).setParameterLength(0,1),WA=mh(Xx());Jx.assign=o=>Ov(o);var di=class o extends H{static get type(){return"ClippingNode"}constructor(e=o.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);let t=e.clippingContext,{intersectionPlanes:s,unionPlanes:i}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===o.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,i):this.scope===o.HARDWARE?this.setupHardwareClipping(i,e):this.setupDefault(s,i)}setupAlphaToCoverage(e,t){return A(()=>{let s=b().toVar("distanceToPlane"),i=b().toVar("distanceToGradient"),n=b(1).toVar("clipOpacity"),r=t.length;if(this.hardwareClipping===!1&&r>0){let c=St(t).setGroup(J);Me(r,({i:l})=>{let u=c.element(l);s.assign(qe.dot(u.xyz).negate().add(u.w)),i.assign(s.fwidth().div(2)),n.mulAssign(Fs(i.negate(),i,s))})}let a=e.length;if(a>0){let c=St(e).setGroup(J),l=b(1).toVar("intersectionClipOpacity");Me(a,({i:u})=>{let h=c.element(u);s.assign(qe.dot(h.xyz).negate().add(h.w)),i.assign(s.fwidth().div(2)),l.mulAssign(Fs(i.negate(),i,s).oneMinus())}),n.mulAssign(l.oneMinus())}we.a.mulAssign(n),we.a.equal(0).discard()})()}setupDefault(e,t){return A(()=>{let s=t.length;if(this.hardwareClipping===!1&&s>0){let n=St(t).setGroup(J);Me(s,({i:r})=>{let a=n.element(r);qe.dot(a.xyz).greaterThan(a.w).discard()})}let i=e.length;if(i>0){let n=St(e).setGroup(J),r=hs(!0).toVar("clipped");Me(i,({i:a})=>{let c=n.element(a);r.assign(qe.dot(c.xyz).greaterThan(c.w).and(r))}),r.discard()}})()}setupHardwareClipping(e,t){let s=e.length;return t.enableHardwareClipping(s),A(()=>{let i=St(e).setGroup(J),n=qi(t.getClipDistance());Me(s,({i:r})=>{let a=i.element(r),c=qe.dot(a.xyz).sub(a.w).negate();n.element(r).assign(c)})})()}};di.ALPHA_TO_COVERAGE="alphaToCoverage";di.DEFAULT="default";di.HARDWARE="hardware";var $A=()=>new di,qA=()=>new di(di.ALPHA_TO_COVERAGE),HA=()=>new di(di.HARDWARE),XA=.05,Wb=A(([o])=>Es(se(1e4,Bt(se(17,o.x).add(se(.1,o.y)))).mul(Ye(.1,Ee(Bt(se(13,o.y).add(o.x))))))),$b=A(([o])=>Wb(U(Wb(o.xy),o.z))),YA=A(([o])=>{let e=ze(ai(bx(o.xyz)),ai(_x(o.xyz))),t=b(1).div(b(XA).mul(e)).toVar("pixScale"),s=U(bo(oi(ri(t))),bo(ld(ri(t)))),i=U($b(oi(s.x.mul(o.xyz))),$b(oi(s.y.mul(o.xyz)))),n=Es(ri(t)),r=Ye(se(n.oneMinus(),i.x),se(n,i.y)),a=Vt(n,n.oneMinus()),c=v(r.mul(r).div(se(2,a).mul(he(1,a))),r.sub(se(.5,a)).div(he(1,a)),he(1,he(1,r).mul(he(1,r)).div(se(2,a).mul(he(1,a))))),l=r.lessThan(a.oneMinus()).select(r.lessThan(a).select(c.x,c.y),c.z);return Bs(l,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]}),ym=class extends hh{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){let e=this.index;return"color"+(e>0?e:"")}generate(e){let t=this.getAttributeName(e),s=e.hasGeometryAttribute(t),i;return s===!0?i=super.generate(e):i=e.generateConst(this.nodeType,new Te(1,1,1,1)),i}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}},Vv=(o=0)=>new ym(o),jA=A(([o,e])=>Vt(1,o.oneMinus().div(e)).oneMinus()).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),ZA=A(([o,e])=>Vt(o.div(e.oneMinus()),1)).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),JA=A(([o,e])=>o.oneMinus().mul(e.oneMinus()).oneMinus()).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),QA=A(([o,e])=>le(o.mul(2).mul(e),o.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),ur(.5,o))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),KA=A(([o,e])=>{let t=e.a.add(o.a.mul(e.a.oneMinus()));return Z(e.rgb.mul(e.a).add(o.rgb.mul(o.a).mul(e.a.oneMinus())).div(t),t)}).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),kv=A(([o])=>Z(o.rgb.mul(o.a),o.a),{color:"vec4",return:"vec4"}),eN=A(([o])=>(K(o.a.equal(0),()=>Z(0)),Z(o.rgb.div(o.a),o.a)),{color:"vec4",return:"vec4"}),Ne=class extends _t{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){let e=[];for(let t of Object.getOwnPropertyNames(this)){if(t.startsWith("_")===!0)continue;let s=this[t];s&&s.isNode===!0&&e.push({property:t,childNode:s})}return e}customProgramCacheKey(){let e=[];for(let{property:t,childNode:s}of this._getNodeChildren())e.push(Ro(t.slice(0,-4)),s.getCacheKey());return this.type+Ec(e)}build(e){this.setup(e)}setupObserver(e){return new ff(e)}setup(e){e.context.setupNormal=()=>cr(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);let t=e.renderer,s=t.getRenderTarget();t.contextNode.isContextNode===!0?e.context={...e.context,...t.contextNode.getFlowContextData()}:O('NodeMaterial: "renderer.contextNode" must be an instance of `context()`.'),this.contextNode!==null&&(this.contextNode.isContextNode===!0?e.context={...e.context,...this.contextNode.getFlowContextData()}:O('NodeMaterial: "material.contextNode" must be an instance of `context()`.')),e.addStack();let i=this.setupVertex(e),n=cr(this.vertexNode||i,"VERTEX");e.context.clipSpace=n,e.stack.outputNode=n,this.setupHardwareClipping(e),this.geometryNode!==null&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let r,a=this.setupClipping(e);if((this.depthWrite===!0||this.depthTest===!0)&&(s!==null?s.depthBuffer===!0&&this.setupDepth(e):t.depth===!0&&this.setupDepth(e)),this.fragmentNode===null){this.setupDiffuseColor(e),this.setupVariants(e);let c=this.setupLighting(e);a!==null&&e.stack.addToStack(a);let l=Z(c,we.a).max(0);r=this.setupOutput(e,l),fo.assign(r);let u=this.outputNode!==null;if(u&&(r=this.outputNode),e.context.getOutput&&(r=e.context.getOutput(r,e)),s!==null){let h=t.getMRT(),d=this.mrtNode;h!==null?(u&&fo.assign(r),r=h,d!==null&&(r=h.merge(d))):d!==null&&(r=d)}}else{let c=this.fragmentNode;c.isOutputStructNode!==!0&&(c=Z(c)),r=this.setupOutput(e,c)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(e.clippingContext===null)return null;let{unionPlanes:t,intersectionPlanes:s}=e.clippingContext,i=null;if(t.length>0||s.length>0){let n=e.renderer.currentSamples;this.alphaToCoverage&&n>1?i=qA():e.stack.addToStack($A())}return i}setupHardwareClipping(e){if(this.hardwareClipping=!1,e.clippingContext===null)return;let t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(HA()),this.hardwareClipping=!0)}setupDepth(e){let{renderer:t,camera:s}=e,i=this.depthNode;if(i===null){let n=t.getMRT();n&&n.has("depth")?i=n.get("depth"):t.logarithmicDepthBuffer===!0&&(s.isPerspectiveCamera?i=Zx(qe.z,un,hn):i=xo(qe.z,un,hn))}i!==null&&Jx.assign(i).toStack()}setupPositionView(){return wn.mul(Ve).xyz}setupModelViewProjection(){return Oi.mul(qe)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),Nv}setupPosition(e){let{object:t,geometry:s}=e;if((s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Pv(t).toStack(),t.isSkinnedMesh===!0&&Fv(t).toStack(),this.displacementMap){let i=Di("displacementMap","texture"),n=Di("displacementScale","float"),r=Di("displacementBias","float");Ve.addAssign(zt.normalize().mul(i.x.mul(n).add(r)))}return t.isBatchedMesh&&Bv(t).toStack(),t.isInstancedMesh&&t.instanceMatrix&&t.instanceMatrix.isInstancedBufferAttribute===!0&&Ev(t).toStack(),this.positionNode!==null&&Ve.assign(cr(this.positionNode,"POSITION","vec3")),Ve}setupDiffuseColor(e){let{object:t,geometry:s}=e;this.maskNode!==null&&hs(this.maskNode).not().discard();let i=this.colorNode?Z(this.colorNode):JS;this.vertexColors===!0&&s.hasAttribute("color")&&(i=i.mul(Vv())),t.instanceColor&&(i=fc("vec3","vInstanceColor").mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=fc("vec3","vBatchColor").mul(i)),we.assign(i);let n=this.opacityNode?b(this.opacityNode):$x;we.a.assign(we.a.mul(n));let r=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(r=this.alphaTestNode!==null?b(this.alphaTestNode):ZS,this.alphaToCoverage===!0?(we.a=Fs(r,r.add(Sx(we.a)),we.a),we.a.lessThanEqual(0).discard()):we.a.lessThanEqual(r).discard()),this.alphaHash===!0&&we.a.lessThan(YA(Ve)).discard(),e.isOpaque()&&we.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?v(0):we.rgb}setupNormal(){return this.normalNode?v(this.normalNode):nv}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Di("envMap","cubeTexture"):Di("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new mm(qx)),t}setupLights(e){let t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);let i=this.setupLightMap(e);i&&i.isLightingNode&&t.push(i);let n=this.aoNode;n===null&&e.material.aoMap&&(n=Av),e.context.getAO&&(n=e.context.getAO(n,e)),n&&t.push(new pm(n));let r=this.lightsNode||e.lightsNode;return t.length>0&&(r=e.renderer.lighting.createNode([...r.getLights(),...t])),r}setupLightingModel(){}setupLighting(e){let{material:t}=e,{backdropNode:s,backdropAlphaNode:i,emissiveNode:n}=this,a=this.lights===!0||this.lightsNode!==null?this.setupLights(e):null,c=this.setupOutgoingLight(e);if(a&&a.getScope().hasLights){let l=this.setupLightingModel(e)||null;c=Dv(a,l,s,i)}else s!==null&&(c=v(i!==null?le(c,s,i):s));return(n&&n.isNode===!0||t.emissive&&t.emissive.isColor===!0)&&(Af.assign(v(n||KS)),c=c.add(Af)),c}setupFog(e,t){let s=e.fogNode;return s&&(fo.assign(t),t=Z(s.toVar())),t}setupPremultipliedAlpha(e,t){return kv(t)}setupOutput(e,t){return this.fog===!0&&(t=this.setupFog(e,t)),this.premultipliedAlpha===!0&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(let s in e){let i=e[s];this[s]===void 0&&(this[s]=i,i&&i.clone&&(this[s]=i.clone()))}let t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(let s in t)Object.getOwnPropertyDescriptor(this.constructor.prototype,s)===void 0&&t[s].get!==void 0&&Object.defineProperty(this.constructor.prototype,s,t[s])}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{},nodes:{}});let s=_t.prototype.toJSON.call(this,e);s.inputNodes={};for(let{property:n,childNode:r}of this._getNodeChildren())s.inputNodes[n]=r.toJSON(e).uuid;function i(n){let r=[];for(let a in n){let c=n[a];delete c.metadata,r.push(c)}return r}if(t){let n=i(e.textures),r=i(e.images),a=i(e.nodes);n.length>0&&(s.textures=n),r.length>0&&(s.images=r),a.length>0&&(s.nodes=a)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.aoNode=e.aoNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.maskNode=e.maskNode,this.maskShadowNode=e.maskShadowNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.receivedShadowPositionNode=e.receivedShadowPositionNode,this.castShadowPositionNode=e.castShadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,this.contextNode=e.contextNode,super.copy(e)}},tN=new Ko,xm=class extends Ne{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(tN),this.setValues(e)}},sN=new Il,bm=class extends Ne{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(sN),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){let e=this.offsetNode?b(this.offsetNode):vv,t=this.dashScaleNode?b(this.dashScaleNode):_v,s=this.dashSizeNode?b(this.dashSizeNode):Tv,i=this.gapSizeNode?b(this.gapSizeNode):Sv;$u.assign(s),Nf.assign(i);let n=Sn(zi("lineDistance").mul(t));(e?n.add(e):n).mod($u.add(Nf)).greaterThan($u).discard()}};var iN=new El,_m=class extends Ne{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(iN),this.setValues(e)}setupDiffuseColor(){let e=this.opacityNode?b(this.opacityNode):$x;we.assign(hd(Z(jS(ye),e),Pt))}},Qx=A(([o=Ox])=>{let e=o.z.atan(o.x).mul(1/(Math.PI*2)).add(.5),t=o.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return U(e,t)}),gh=class extends bt{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;let s={width:e,height:e,depth:1},i=[s,s,s,s,s,s];this.texture=new kn(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){let s=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let n=new ea(5,5,5),r=Qx(Ox),a=new Ne;a.colorNode=xe(t,r,0),a.side=rt,a.blending=qs;let c=new Zt(n,a),l=new On;l.add(c),t.minFilter===Ci&&(t.minFilter=ct);let u=new Jl(1,10,this),h=e.getMRT();return e.setMRT(null),u.update(e,l),e.setMRT(h),t.minFilter=s,t.currentGenerateMipmaps=i,c.geometry.dispose(),c.material.dispose(),this}clear(e,t=!0,s=!0,i=!0){let n=e.getRenderTarget();for(let r=0;r<6;r++)e.setRenderTarget(this,r),e.clear(t,s,i);e.setRenderTarget(n)}},ac=new WeakMap,Tm=class extends Be{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=Ft(null);let t=new kn;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=te.RENDER}updateBefore(e){let{renderer:t,material:s}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){let n=i.isTextureNode?i.value:s[i.property];if(n&&n.isTexture){let r=n.mapping;if(r===su||r===iu){if(ac.has(n)){let a=ac.get(n);qb(a,n.mapping),this._cubeTexture=a}else{let a=n.image;if(nN(a)){let c=new gh(a.height);c.fromEquirectangularTexture(t,n),qb(c.texture,n.mapping),this._cubeTexture=c.texture,ac.set(n,c.texture),n.addEventListener("dispose",zv)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}};function nN(o){return o==null?!1:o.height>0}function zv(o){let e=o.target;e.removeEventListener("dispose",zv);let t=ac.get(e);t!==void 0&&(ac.delete(e),t.dispose())}function qb(o,e){e===su?o.mapping=qn:e===iu&&(o.mapping=ca)}var Gv=oe(Tm).setParameterLength(1),yc=class extends Tn{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Gv(this.envNode)}},Sm=class extends Tn{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){let t=b(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}},Mo=class{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}},yh=class extends Mo{constructor(){super()}indirect({context:e}){let t=e.ambientOcclusion,s=e.reflectedLight,i=e.irradianceLightMap;s.indirectDiffuse.assign(Z(0)),i?s.indirectDiffuse.addAssign(i):s.indirectDiffuse.addAssign(Z(1,1,1,0)),s.indirectDiffuse.mulAssign(t),s.indirectDiffuse.mulAssign(we.rgb)}finish(e){let{material:t,context:s}=e,i=s.outgoingLight,n=e.context.environment;if(n)switch(t.combine){case aa:i.rgb.assign(le(i.rgb,i.rgb.mul(n.rgb),oc.mul(Hu)));break;case J0:i.rgb.assign(le(i.rgb,n.rgb,oc.mul(Hu)));break;case Q0:i.rgb.addAssign(n.rgb.mul(oc.mul(Hu)));break;default:z("BasicLightingModel: Unsupported .combine value:",t.combine);break}}},rN=new ws,xc=class extends Ne{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(rN),this.setValues(e)}setupNormal(){return Co(To)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new yc(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Sm(qx)),t}setupOutgoingLight(){return we.rgb}setupLightingModel(){return new yh}},Ao=A(({f0:o,f90:e,dotVH:t})=>{let s=t.mul(-5.55473).sub(6.98316).mul(t).exp2();return o.mul(s.oneMinus()).add(e.mul(s))}),dr=A(o=>o.diffuseColor.mul(1/Math.PI)),oN=()=>b(.25),aN=A(({dotNH:o})=>th.mul(b(.5)).add(1).mul(b(1/Math.PI)).mul(o.pow(th))),cN=A(({lightDirection:o})=>{let e=o.add(Ce).normalize(),t=ye.dot(e).clamp(),s=Ce.dot(e).clamp(),i=Ao({f0:_n,f90:1,dotVH:s}),n=oN(),r=aN({dotNH:t});return i.mul(n).mul(r)}),xh=class extends yh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){let n=ye.dot(e).clamp().mul(t);s.directDiffuse.addAssign(n.mul(dr({diffuseColor:we.rgb}))),this.specular===!0&&s.directSpecular.addAssign(n.mul(cN({lightDirection:e})).mul(oc))}indirect(e){let{ambientOcclusion:t,irradiance:s,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(s.mul(dr({diffuseColor:we}))),i.indirectDiffuse.mulAssign(t)}},lN=new Bl,vm=class extends Ne{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(lN),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new yc(t):null}setupLightingModel(){return new xh(!1)}},uN=new Rl,wm=class extends Ne{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(uN),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new yc(t):null}setupLightingModel(){return new xh}setupVariants(){let e=(this.shininessNode?b(this.shininessNode):QS).max(1e-4);th.assign(e);let t=this.specularNode||ev;_n.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}},Wv=A(o=>{if(o.geometry.hasAttribute("normal")===!1)return b(0);let e=To.dFdx().abs().max(To.dFdy().abs());return e.x.max(e.y).max(e.z)}),Kx=A(o=>{let{roughness:e}=o,t=Wv(),s=e.max(.0525);return s=s.add(t),s=s.min(1),s}),$v=A(({alpha:o,dotNL:e,dotNV:t})=>{let s=o.pow2(),i=e.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt()),n=t.mul(s.add(s.oneMinus().mul(e.pow2())).sqrt());return ss(.5,i.add(n).max(dx))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),hN=A(({alphaT:o,alphaB:e,dotTV:t,dotBV:s,dotTL:i,dotBL:n,dotNV:r,dotNL:a})=>{let c=a.mul(v(o.mul(t),e.mul(s),r).length()),l=r.mul(v(o.mul(i),e.mul(n),a).length());return ss(.5,c.add(l))}).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"}]}),qv=A(({alpha:o,dotNH:e})=>{let t=o.pow2(),s=e.pow2().mul(t.oneMinus()).oneMinus();return t.div(s.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),dN=b(1/Math.PI),pN=A(({alphaT:o,alphaB:e,dotNH:t,dotTH:s,dotBH:i})=>{let n=o.mul(e),r=v(e.mul(s),o.mul(i),n.mul(t)),a=r.dot(r),c=n.div(a);return dN.mul(n.mul(c.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"}]}),e0=A(({lightDirection:o,f0:e,f90:t,roughness:s,f:i,normalView:n=ye,USE_IRIDESCENCE:r,USE_ANISOTROPY:a})=>{let c=s.pow2(),l=o.add(Ce).normalize(),u=n.dot(o).clamp(),h=n.dot(Ce).clamp(),d=n.dot(l).clamp(),p=Ce.dot(l).clamp(),m=Ao({f0:e,f90:t,dotVH:p}),g,y;if(dc(r)&&(m=od.mix(m,i)),dc(a)){let x=nc.dot(o),_=nc.dot(Ce),w=nc.dot(l),S=ar.dot(o),E=ar.dot(Ce),B=ar.dot(l);g=hN({alphaT:eh,alphaB:c,dotTV:_,dotBV:E,dotTL:x,dotBL:S,dotNV:h,dotNL:u}),y=pN({alphaT:eh,alphaB:c,dotNH:d,dotTH:w,dotBH:B})}else g=$v({alpha:c,dotNL:u,dotNV:h}),y=qv({alpha:c,dotNH:d});return m.mul(g).mul(y)}),fN=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),Qs=null,bc=A(({roughness:o,dotNV:e})=>{Qs===null&&(Qs=new Qo(fN,16,16,Ms,$e),Qs.name="DFG_LUT",Qs.minFilter=ct,Qs.magFilter=ct,Qs.wrapS=bs,Qs.wrapT=bs,Qs.generateMipmaps=!1,Qs.needsUpdate=!0);let t=U(o,e);return xe(Qs,t).rg}),mN=A(({lightDirection:o,f0:e,f90:t,roughness:s,f:i,USE_IRIDESCENCE:n,USE_ANISOTROPY:r})=>{let a=e0({lightDirection:o,f0:e,f90:t,roughness:s,f:i,USE_IRIDESCENCE:n,USE_ANISOTROPY:r}),c=ye.dot(o).clamp(),l=ye.dot(Ce).clamp(),u=bc({roughness:s,dotNV:l}),h=bc({roughness:s,dotNV:c}),d=e.mul(u.x).add(t.mul(u.y)),p=e.mul(h.x).add(t.mul(h.y)),m=u.x.add(u.y),g=h.x.add(h.y),y=b(1).sub(m),x=b(1).sub(g),_=e.add(e.oneMinus().mul(.047619)),w=d.mul(p).mul(_).div(b(1).sub(y.mul(x).mul(_).mul(_)).add(dx)),S=y.mul(x),E=w.mul(S);return a.add(E)}),Hv=A(o=>{let{dotNV:e,specularColor:t,specularF90:s,roughness:i}=o,n=bc({dotNV:e,roughness:i});return t.mul(n.x).add(s.mul(n.y))}),Mm=A(({f:o,f90:e,dotVH:t})=>{let s=t.oneMinus().saturate(),i=s.mul(s),n=s.mul(i,i).clamp(0,.9999);return o.sub(v(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"}]}),gN=A(({roughness:o,dotNH:e})=>{let t=o.pow2(),s=b(1).div(t),n=e.pow2().oneMinus().max(.0078125);return b(2).add(s).mul(n.pow(s.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),yN=A(({dotNV:o,dotNL:e})=>b(1).div(b(4).mul(e.add(o).sub(e.mul(o))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),xN=A(({lightDirection:o})=>{let e=o.add(Ce).normalize(),t=ye.dot(o).clamp(),s=ye.dot(Ce).clamp(),i=ye.dot(e).clamp(),n=gN({roughness:ln,dotNH:i}),r=yN({dotNV:s,dotNL:t});return Kt.mul(n).mul(r)}),Hb=A(({N:o,V:e,roughness:t})=>{let n=.0078125,r=o.dot(e).saturate(),a=U(t,r.oneMinus().sqrt());return a.assign(a.mul(.984375).add(n)),a}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),bN=A(({f:o})=>{let e=o.length();return ze(e.mul(e).add(o.z).div(e.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),vu=A(({v1:o,v2:e})=>{let t=o.dot(e),s=t.abs().toVar(),i=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),n=s.add(4.1616724).mul(s).add(3.417594).toVar(),r=i.div(n),a=t.greaterThan(0).select(r,ze(t.mul(t).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(r));return o.cross(e).mul(a)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),zp=A(({N:o,V:e,P:t,mInv:s,p0:i,p1:n,p2:r,p3:a})=>{let c=n.sub(i).toVar(),l=a.sub(i).toVar(),u=c.cross(l),h=v().toVar();return K(u.dot(t.sub(i)).greaterThanEqual(0),()=>{let d=e.sub(o.mul(e.dot(o))).normalize(),p=o.cross(d).negate(),m=s.mul(at(d,p,o).transpose()).toVar(),g=m.mul(i.sub(t)).normalize().toVar(),y=m.mul(n.sub(t)).normalize().toVar(),x=m.mul(r.sub(t)).normalize().toVar(),_=m.mul(a.sub(t)).normalize().toVar(),w=v(0).toVar();w.addAssign(vu({v1:g,v2:y})),w.addAssign(vu({v1:y,v2:x})),w.addAssign(vu({v1:x,v2:_})),w.addAssign(vu({v1:_,v2:g})),h.assign(v(bN({f:w})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]});var yd=1/6,Xv=o=>se(yd,se(o,se(o,o.negate().add(3)).sub(3)).add(1)),Am=o=>se(yd,se(o,se(o,se(3,o).sub(6))).add(4)),Yv=o=>se(yd,se(o,se(o,se(-3,o).add(3)).add(3)).add(1)),Nm=o=>se(yd,cs(o,3)),Xb=o=>Xv(o).add(Am(o)),Yb=o=>Yv(o).add(Nm(o)),jb=o=>Ye(-1,Am(o).div(Xv(o).add(Am(o)))),Zb=o=>Ye(1,Nm(o).div(Yv(o).add(Nm(o)))),Jb=(o,e,t)=>{let s=o.uvNode,i=se(s,e.zw).add(.5),n=oi(i),r=Es(i),a=Xb(r.x),c=Yb(r.x),l=jb(r.x),u=Zb(r.x),h=jb(r.y),d=Zb(r.y),p=U(n.x.add(l),n.y.add(h)).sub(.5).mul(e.xy),m=U(n.x.add(u),n.y.add(h)).sub(.5).mul(e.xy),g=U(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=U(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),x=Xb(r.y).mul(Ye(a.mul(o.sample(p).level(t)),c.mul(o.sample(m).level(t)))),_=Yb(r.y).mul(Ye(a.mul(o.sample(g).level(t)),c.mul(o.sample(y).level(t))));return x.add(_)},t0=A(([o,e])=>{let t=U(o.size(T(e))),s=U(o.size(T(e.add(1)))),i=ss(1,t),n=ss(1,s),r=Jb(o,Z(i,t),oi(e)),a=Jb(o,Z(n,s),ld(e));return Es(e).mix(r,a)}),_N=A(([o,e])=>{let t=e.mul(Px(o));return t0(o,t)}),Qb=A(([o,e,t,s,i])=>{let n=v(Ax(e.negate(),Ut(o),ss(1,s))),r=v(ai(i[0].xyz),ai(i[1].xyz),ai(i[2].xyz));return Ut(n).mul(t.mul(r))}).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"}]}),TN=A(([o,e])=>o.mul(Bs(e.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),SN=Hx(),vN=Lv(),Kb=A(([o,e,t],{material:s})=>{let n=(s.side===rt?SN:vN).sample(o),r=ri(hr.x).mul(TN(e,t));return t0(n,r)}),e_=A(([o,e,t])=>(K(t.notEqual(0),()=>{let s=cd(e).negate().div(t);return px(s.negate().mul(o))}),v(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),wN=A(([o,e,t,s,i,n,r,a,c,l,u,h,d,p,m])=>{let g,y;if(m){g=Z().toVar(),y=v().toVar();let E=u.sub(1).mul(m.mul(.025)),B=v(u.sub(E),u,u.add(E));Me({start:0,end:3},({i:N})=>{let C=B.element(N),I=Qb(o,e,h,C,a),k=r.add(I),W=l.mul(c.mul(Z(k,1))),X=U(W.xy.div(W.w)).toVar();X.addAssign(1),X.divAssign(2),X.assign(U(X.x,X.y.oneMinus()));let Y=Kb(X,t,C);g.element(N).assign(Y.element(N)),g.a.addAssign(Y.a),y.element(N).assign(s.element(N).mul(e_(ai(I),d,p).element(N)))}),g.a.divAssign(3)}else{let E=Qb(o,e,h,u,a),B=r.add(E),N=l.mul(c.mul(Z(B,1))),C=U(N.xy.div(N.w)).toVar();C.addAssign(1),C.divAssign(2),C.assign(U(C.x,C.y.oneMinus())),g=Kb(C,t,u),y=s.mul(e_(ai(E),d,p))}let x=y.rgb.mul(g.rgb),_=o.dot(e).clamp(),w=v(Hv({dotNV:_,specularColor:i,specularF90:n,roughness:t})),S=y.r.add(y.g,y.b).div(3);return Z(w.oneMinus().mul(x),g.a.oneMinus().mul(S).oneMinus())}),MN=at(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),AN=o=>{let e=o.sqrt();return v(1).add(e).div(v(1).sub(e))},t_=(o,e)=>o.sub(e).div(o.add(e)).pow2(),NN=(o,e)=>{let t=o.mul(2*Math.PI*1e-9),s=v(54856e-17,44201e-17,52481e-17),i=v(1681e3,1795300,2208400),n=v(43278e5,93046e5,66121e5),r=b(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(t.mul(2239900).add(e.x).cos()).mul(t.pow2().mul(-45282e5).exp()),a=s.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(t).add(e).cos()).mul(t.pow2().negate().mul(n).exp());return a=v(a.x.add(r),a.y,a.z).div(10685e-11),MN.mul(a)},s_=A(({outsideIOR:o,eta2:e,cosTheta1:t,thinFilmThickness:s,baseF0:i})=>{let n=le(o,e,Fs(0,.03,s)),a=o.div(n).pow2().mul(t.pow2().oneMinus()).oneMinus();K(a.lessThan(0),()=>v(1));let c=a.sqrt(),l=t_(n,o),u=Ao({f0:l,f90:1,dotVH:t}),h=u.oneMinus(),d=n.lessThan(o).select(Math.PI,0),p=b(Math.PI).sub(d),m=AN(i.clamp(0,.9999)),g=t_(m,n.toVec3()),y=Ao({f0:g,f90:1,dotVH:c}),x=v(m.x.lessThan(n).select(Math.PI,0),m.y.lessThan(n).select(Math.PI,0),m.z.lessThan(n).select(Math.PI,0)),_=n.mul(s,c,2),w=v(p).add(x),S=u.mul(y).clamp(1e-5,.9999),E=S.sqrt(),B=h.pow2().mul(y).div(v(1).sub(S)),C=u.add(B).toVar(),I=B.sub(h).toVar();return Me({start:1,end:2,condition:"<=",name:"m"},({m:k})=>{I.mulAssign(E);let W=NN(b(k).mul(_),b(k).mul(w)).mul(2);C.addAssign(I.mul(W))}),C.max(v(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"}]}),Ga=A(({normal:o,viewDir:e,roughness:t})=>{let s=o.dot(e).saturate(),i=t.mul(t),n=t.add(.1).reciprocal(),r=b(-1.9362).add(t.mul(1.0678)).add(i.mul(.4573)).sub(n.mul(.8469)),a=b(-.6014).add(t.mul(.5538)).sub(i.mul(.467)).sub(n.mul(.1255));return r.mul(s).add(a).exp().saturate()}),Wa=v(.04),wu=b(1),bh=class extends Mo{constructor(e=!1,t=!1,s=!1,i=!1,n=!1,r=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=i,this.transmission=n,this.dispersion=r,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null}start(e){if(this.clearcoat===!0&&(this.clearcoatRadiance=v().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=v().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=v().toVar("clearcoatSpecularIndirect")),this.sheen===!0&&(this.sheenSpecularDirect=v().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=v().toVar("sheenSpecularIndirect")),this.iridescence===!0){let t=ye.dot(Ce).clamp(),s=s_({outsideIOR:b(1),eta2:Qu,cosTheta1:t,thinFilmThickness:Ku,baseF0:_n}),i=s_({outsideIOR:b(1),eta2:Qu,cosTheta1:t,thinFilmThickness:Ku,baseF0:we.rgb});this.iridescenceFresnel=le(s,i,Li),this.iridescenceF0Dielectric=Mm({f:s,f90:1,dotVH:t}),this.iridescenceF0Metallic=Mm({f:i,f90:1,dotVH:t}),this.iridescenceF0=le(this.iridescenceF0Dielectric,this.iridescenceF0Metallic,Li)}if(this.transmission===!0){let t=li,s=wS.sub(li).normalize(),i=Mn,n=e.context;n.backdrop=wN(i,s,ii,er,sr,ir,t,ls,fs,Oi,rc,ox,cx,ax,this.dispersion?lx:null),n.backdropAlpha=sh,we.a.mulAssign(le(1,n.backdrop.a,sh))}super.start(e)}computeMultiscattering(e,t,s,i,n=null){let r=ye.dot(Ce).clamp(),a=bc({roughness:ii,dotNV:r}),c=n?od.mix(i,n):i,l=c.mul(a.x).add(s.mul(a.y)),h=a.x.add(a.y).oneMinus(),d=c.add(c.oneMinus().mul(.047619)),p=l.mul(d).div(h.mul(d).oneMinus());e.addAssign(l),t.addAssign(p.mul(h))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){let n=ye.dot(e).clamp().mul(t).toVar();if(this.sheen===!0){this.sheenSpecularDirect.addAssign(n.mul(xN({lightDirection:e})));let r=Ga({normal:ye,viewDir:Ce,roughness:ln}),a=Ga({normal:ye,viewDir:e,roughness:ln}),c=Kt.r.max(Kt.g).max(Kt.b).mul(r.max(a)).oneMinus();n.mulAssign(c)}if(this.clearcoat===!0){let a=dn.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(a.mul(e0({lightDirection:e,f0:Wa,f90:wu,roughness:po,normalView:dn})))}s.directDiffuse.addAssign(n.mul(dr({diffuseColor:er}))),s.directSpecular.addAssign(n.mul(mN({lightDirection:e,f0:sr,f90:1,roughness:ii,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:i,reflectedLight:n,ltc_1:r,ltc_2:a}){let c=t.add(s).sub(i),l=t.sub(s).sub(i),u=t.sub(s).add(i),h=t.add(s).add(i),d=ye,p=Ce,m=qe.toVar(),g=Hb({N:d,V:p,roughness:ii}),y=r.sample(g).toVar(),x=a.sample(g).toVar(),_=at(v(y.x,0,y.y),v(0,1,0),v(y.z,0,y.w)).toVar(),w=sr.mul(x.x).add(ir.sub(sr).mul(x.y)).toVar();if(n.directSpecular.addAssign(e.mul(w).mul(zp({N:d,V:p,P:m,mInv:_,p0:c,p1:l,p2:u,p3:h}))),n.directDiffuse.addAssign(e.mul(er).mul(zp({N:d,V:p,P:m,mInv:at(1,0,0,0,1,0,0,0,1),p0:c,p1:l,p2:u,p3:h}))),this.clearcoat===!0){let S=dn,E=Hb({N:S,V:p,roughness:po}),B=r.sample(E),N=a.sample(E),C=at(v(B.x,0,B.y),v(0,1,0),v(B.z,0,B.w)),I=Wa.mul(N.x).add(wu.sub(Wa).mul(N.y));this.clearcoatSpecularDirect.addAssign(e.mul(I).mul(zp({N:S,V:p,P:m,mInv:C,p0:c,p1:l,p2:u,p3:h})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){let{irradiance:t,reflectedLight:s}=e.context,i=t.mul(dr({diffuseColor:er})).toVar();if(this.sheen===!0){let n=Ga({normal:ye,viewDir:Ce,roughness:ln}),r=Kt.r.max(Kt.g).max(Kt.b).mul(n).oneMinus();i.mulAssign(r)}s.indirectDiffuse.addAssign(i)}indirectSpecular(e){let{radiance:t,iblIrradiance:s,reflectedLight:i}=e.context;if(this.sheen===!0&&this.sheenSpecularIndirect.addAssign(s.mul(Kt,Ga({normal:ye,viewDir:Ce,roughness:ln}))),this.clearcoat===!0){let y=dn.dot(Ce).clamp(),x=Hv({dotNV:y,specularColor:Wa,specularF90:wu,roughness:po});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(x))}let n=v().toVar("singleScatteringDielectric"),r=v().toVar("multiScatteringDielectric"),a=v().toVar("singleScatteringMetallic"),c=v().toVar("multiScatteringMetallic");this.computeMultiscattering(n,r,ir,_n,this.iridescenceF0Dielectric),this.computeMultiscattering(a,c,ir,we.rgb,this.iridescenceF0Metallic);let l=le(n,a,Li),u=le(r,c,Li),h=n.add(r),d=er.mul(h.oneMinus()),p=s.mul(1/Math.PI),m=t.mul(l).add(u.mul(p)).toVar(),g=d.mul(p).toVar();if(this.sheen===!0){let y=Ga({normal:ye,viewDir:Ce,roughness:ln}),x=Kt.r.max(Kt.g).max(Kt.b).mul(y).oneMinus();m.mulAssign(x),g.mulAssign(x)}i.indirectSpecular.addAssign(m),i.indirectDiffuse.addAssign(g)}ambientOcclusion(e){let{ambientOcclusion:t,reflectedLight:s}=e.context,n=ye.dot(Ce).clamp().add(t),r=ii.mul(-16).oneMinus().negate().exp2(),a=t.sub(n.pow(r).oneMinus()).clamp();this.clearcoat===!0&&this.clearcoatSpecularIndirect.mulAssign(t),this.sheen===!0&&this.sheenSpecularIndirect.mulAssign(t),s.indirectDiffuse.mulAssign(t),s.indirectSpecular.mulAssign(a)}finish({context:e}){let{outgoingLight:t}=e;if(this.clearcoat===!0){let s=dn.dot(Ce).clamp(),i=Ao({dotVH:s,f0:Wa,f90:wu}),n=t.mul(Ju.mul(i).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(Ju));t.assign(n)}if(this.sheen===!0){let s=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect.mul(1/Math.PI));t.assign(s)}}},i_=b(1),Rm=b(-2),Mu=b(.8),Gp=b(-1),Au=b(.4),Wp=b(2),Nu=b(.305),$p=b(3),n_=b(.21),RN=b(4),r_=b(4),CN=b(16),EN=A(([o])=>{let e=v(Ee(o)).toVar(),t=b(-1).toVar();return K(e.x.greaterThan(e.z),()=>{K(e.x.greaterThan(e.y),()=>{t.assign(vt(o.x.greaterThan(0),0,3))}).Else(()=>{t.assign(vt(o.y.greaterThan(0),1,4))})}).Else(()=>{K(e.z.greaterThan(e.y),()=>{t.assign(vt(o.z.greaterThan(0),2,5))}).Else(()=>{t.assign(vt(o.y.greaterThan(0),1,4))})}),t}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),BN=A(([o,e])=>{let t=U().toVar();return K(e.equal(0),()=>{t.assign(U(o.z,o.y).div(Ee(o.x)))}).ElseIf(e.equal(1),()=>{t.assign(U(o.x.negate(),o.z.negate()).div(Ee(o.y)))}).ElseIf(e.equal(2),()=>{t.assign(U(o.x.negate(),o.y).div(Ee(o.z)))}).ElseIf(e.equal(3),()=>{t.assign(U(o.z.negate(),o.y).div(Ee(o.x)))}).ElseIf(e.equal(4),()=>{t.assign(U(o.x.negate(),o.z).div(Ee(o.y)))}).Else(()=>{t.assign(U(o.x,o.y).div(Ee(o.z)))}),se(.5,t.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),FN=A(([o])=>{let e=b(0).toVar();return K(o.greaterThanEqual(Mu),()=>{e.assign(i_.sub(o).mul(Gp.sub(Rm)).div(i_.sub(Mu)).add(Rm))}).ElseIf(o.greaterThanEqual(Au),()=>{e.assign(Mu.sub(o).mul(Wp.sub(Gp)).div(Mu.sub(Au)).add(Gp))}).ElseIf(o.greaterThanEqual(Nu),()=>{e.assign(Au.sub(o).mul($p.sub(Wp)).div(Au.sub(Nu)).add(Wp))}).ElseIf(o.greaterThanEqual(n_),()=>{e.assign(Nu.sub(o).mul(RN.sub($p)).div(Nu.sub(n_)).add($p))}).Else(()=>{e.assign(b(-2).mul(ri(se(1.16,o))))}),e}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),jv=A(([o,e])=>{let t=o.toVar();t.assign(se(2,t).sub(1));let s=v(t,1).toVar();return K(e.equal(0),()=>{s.assign(s.zyx)}).ElseIf(e.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(e.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(e.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(e.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(e.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Zv=A(([o,e,t,s,i,n])=>{let r=b(t),a=v(e),c=Bs(FN(r),Rm,n),l=Es(c),u=oi(c),h=v(_c(o,a,u,s,i,n)).toVar();return K(l.notEqual(0),()=>{let d=v(_c(o,a,u.add(1),s,i,n)).toVar();h.assign(le(h,d,l))}),h}),_c=A(([o,e,t,s,i,n])=>{let r=b(t).toVar(),a=v(e),c=b(EN(a)).toVar(),l=b(ze(r_.sub(r),0)).toVar();r.assign(ze(r,r_));let u=b(bo(r)).toVar(),h=U(BN(a,c).mul(u.sub(2)).add(1)).toVar();return K(c.greaterThan(2),()=>{h.y.addAssign(u),c.subAssign(3)}),h.x.addAssign(c.mul(u)),h.x.addAssign(l.mul(se(3,CN))),h.y.addAssign(se(4,bo(n).sub(u))),h.x.mulAssign(s),h.y.mulAssign(i),o.sample(h).grad(U(),U())}),qp=A(({envMap:o,mipInt:e,outputDirection:t,theta:s,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:r,CUBEUV_MAX_MIP:a})=>{let c=Rs(s),l=t.mul(c).add(i.cross(t).mul(Bt(s))).add(i.mul(i.dot(t).mul(c.oneMinus())));return _c(o,l,e,n,r,a)}),Jv=A(({n:o,latitudinal:e,poleAxis:t,outputDirection:s,weights:i,samples:n,dTheta:r,mipInt:a,envMap:c,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})=>{let d=v(vt(e,t,ki(t,s))).toVar();K(d.equal(v(0)),()=>{d.assign(v(s.z,0,s.x.negate()))}),d.assign(Ut(d));let p=v().toVar();return p.addAssign(i.element(0).mul(qp({theta:0,axis:d,outputDirection:s,mipInt:a,envMap:c,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),Me({start:T(1),end:o},({i:m})=>{K(m.greaterThanEqual(n),()=>{Iv()});let g=b(r.mul(b(m))).toVar();p.addAssign(i.element(m).mul(qp({theta:g.mul(-1),axis:d,outputDirection:s,mipInt:a,envMap:c,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h}))),p.addAssign(i.element(m).mul(qp({theta:g,axis:d,outputDirection:s,mipInt:a,envMap:c,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:h})))}),Z(p,1)}),IN=A(([o])=>{let e=D(o).toVar();return e.assign(e.shiftLeft(D(16)).bitOr(e.shiftRight(D(16)))),e.assign(e.bitAnd(D(1431655765)).shiftLeft(D(1)).bitOr(e.bitAnd(D(2863311530)).shiftRight(D(1)))),e.assign(e.bitAnd(D(858993459)).shiftLeft(D(2)).bitOr(e.bitAnd(D(3435973836)).shiftRight(D(2)))),e.assign(e.bitAnd(D(252645135)).shiftLeft(D(4)).bitOr(e.bitAnd(D(4042322160)).shiftRight(D(4)))),e.assign(e.bitAnd(D(16711935)).shiftLeft(D(8)).bitOr(e.bitAnd(D(4278255360)).shiftRight(D(8)))),b(e).mul(23283064365386963e-26)}),PN=A(([o,e])=>U(b(o).div(b(e)),IN(o))),DN=A(([o,e,t])=>{let s=t.mul(t).toConst(),i=v(1,0,0).toConst(),n=ki(e,i).toConst(),r=It(o.x).toConst(),a=se(2,3.14159265359).mul(o.y).toConst(),c=r.mul(Rs(a)).toConst(),l=r.mul(Bt(a)).toVar(),u=se(.5,e.z.add(1)).toConst();l.assign(u.oneMinus().mul(It(c.mul(c).oneMinus())).add(u.mul(l)));let h=i.mul(c).add(n.mul(l)).add(e.mul(It(ze(0,c.mul(c).add(l.mul(l)).oneMinus()))));return Ut(v(s.mul(h.x),s.mul(h.y),ze(0,h.z)))}),Qv=A(({roughness:o,mipInt:e,envMap:t,N_immutable:s,GGX_SAMPLES:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:r,CUBEUV_MAX_MIP:a})=>{let c=v(s).toVar(),l=v(0).toVar(),u=b(0).toVar();return K(o.lessThan(.001),()=>{l.assign(_c(t,c,e,n,r,a))}).Else(()=>{let h=vt(Ee(c.z).lessThan(.999),v(0,0,1),v(1,0,0)),d=Ut(ki(h,c)).toVar(),p=ki(c,d).toVar();Me({start:D(0),end:i},({i:m})=>{let g=PN(m,i),y=DN(g,v(0,0,1),o),x=Ut(d.mul(y.x).add(p.mul(y.y)).add(c.mul(y.z))),_=Ut(x.mul(ds(c,x).mul(2)).sub(c)),w=ze(ds(c,_),0);K(w.greaterThan(0),()=>{let S=_c(t,_,e,n,r,a);l.addAssign(S.mul(w)),u.addAssign(w)})}),K(u.greaterThan(0),()=>{l.assign(l.div(u))})}),Z(l,1)}),mn=4,o_=[.125,.215,.35,.446,.526,.582],tr=20,LN=512,$a=new Gr(-1,1,1,-1,0,1),UN=new it(90,1),a_=new ge,Hp=null,Xp=0,Yp=0,ON=new R,_h=new WeakMap,VN=[3,1,5,0,4,2],jp=jv(Re(),zi("faceIndex")).normalize(),xd=v(jp.x,jp.y,jp.z),Cm=class{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,s=.1,i=100,n={}){let{size:r=256,position:a=ON,renderTarget:c=null}=n;if(this._setSize(r),this._hasInitialized===!1){z('PMREMGenerator: ".fromScene()" called before the backend is initialized. Try using "await renderer.init()" instead.');let u=c||this._allocateTarget();return n.renderTarget=u,this.fromSceneAsync(e,t,s,i,n),u}Hp=this._renderer.getRenderTarget(),Xp=this._renderer.getActiveCubeFace(),Yp=this._renderer.getActiveMipmapLevel();let l=c||this._allocateTarget();return l.depthBuffer=!0,this._init(l),this._sceneToCubeUV(e,s,i,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}async fromSceneAsync(e,t=0,s=.1,i=100,n={}){return _e('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,s,i,n)}fromEquirectangular(e,t=null){if(this._hasInitialized===!1){z('PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using "await renderer.init()" instead.'),this._setSizeFromTexture(e);let s=t||this._allocateTarget();return this.fromEquirectangularAsync(e,s),s}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return _e('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(this._hasInitialized===!1){z("PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);let s=t||this._allocateTarget();return this.fromCubemapAsync(e,t),s}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return _e('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=l_(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=u_(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===qn||e.mapping===ca?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(Hp,Xp,Yp),e.scissorTest=!1,to(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),Hp=this._renderer.getRenderTarget(),Xp=this._renderer.getActiveCubeFace(),Yp=this._renderer.getActiveMipmapLevel();let s=t||this._allocateTarget();return this._init(s),this._textureToCubeUV(e,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTarget(){let e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize;return c_(e,t)}_init(e){if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=c_(e.width,e.height);let{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=kN(t)),this._blurMaterial=zN(t,e.width,e.height),this._ggxMaterial=GN(t,e.width,e.height)}}async _compileMaterial(e){let t=new Zt(new vs,e);await this._renderer.compile(t,$a)}_sceneToCubeUV(e,t,s,i,n){let r=UN;r.near=t,r.far=s;let a=[1,1,1,1,-1,1],c=[1,-1,1,-1,1,-1],l=this._renderer,u=l.autoClear;l.getClearColor(a_),l.autoClear=!1,this._backgroundBox===null&&(this._backgroundBox=new Zt(new ea,new ws({name:"PMREM.Background",side:rt,depthWrite:!1,depthTest:!1})));let h=this._backgroundBox,d=h.material,p=!1,m=e.background;m?m.isColor&&(d.color.copy(m),e.background=null,p=!0):(d.color.copy(a_),p=!0),l.setRenderTarget(i),l.clear(),p&&l.render(h,r);for(let g=0;g<6;g++){let y=g%3;y===0?(r.up.set(0,a[g],0),r.position.set(n.x,n.y,n.z),r.lookAt(n.x+c[g],n.y,n.z)):y===1?(r.up.set(0,0,a[g]),r.position.set(n.x,n.y,n.z),r.lookAt(n.x,n.y+c[g],n.z)):(r.up.set(0,a[g],0),r.position.set(n.x,n.y,n.z),r.lookAt(n.x,n.y,n.z+c[g]));let x=this._cubeSize;to(i,y*x,g>2?x:0,x,x),l.render(e,r)}l.autoClear=u,e.background=m}_textureToCubeUV(e,t){let s=this._renderer,i=e.mapping===qn||e.mapping===ca;i?this._cubemapMaterial===null&&(this._cubemapMaterial=l_(e)):this._equirectMaterial===null&&(this._equirectMaterial=u_(e));let n=i?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;let r=this._lodMeshes[0];r.material=n;let a=this._cubeSize;to(t,0,0,3*a,2*a),s.setRenderTarget(t),s.render(r,$a)}_applyPMREM(e){let t=this._renderer,s=t.autoClear;t.autoClear=!1;let i=this._lodMeshes.length;for(let n=1;n<i;n++)this._applyGGXFilter(e,n-1,n);t.autoClear=s}_applyGGXFilter(e,t,s){let i=this._renderer,n=this._pingPongRenderTarget,r=this._ggxMaterial,a=this._lodMeshes[s];a.material=r;let c=_h.get(r),l=s/(this._lodMeshes.length-1),u=t/(this._lodMeshes.length-1),h=Math.sqrt(l*l-u*u),d=0+l*1.25,p=h*d,{_lodMax:m}=this,g=this._sizeLods[s],y=3*g*(s>m-mn?s-m+mn:0),x=4*(this._cubeSize-g);e.texture.frame=(e.texture.frame||0)+1,c.envMap.value=e.texture,c.roughness.value=p,c.mipInt.value=m-t,to(n,y,x,3*g,2*g),i.setRenderTarget(n),i.render(a,$a),n.texture.frame=(n.texture.frame||0)+1,c.envMap.value=n.texture,c.roughness.value=0,c.mipInt.value=m-s,to(e,y,x,3*g,2*g),i.setRenderTarget(e),i.render(a,$a)}_blur(e,t,s,i,n){let r=this._pingPongRenderTarget;this._halfBlur(e,r,t,s,i,"latitudinal",n),this._halfBlur(r,e,s,s,i,"longitudinal",n)}_halfBlur(e,t,s,i,n,r,a){let c=this._renderer,l=this._blurMaterial;r!=="latitudinal"&&r!=="longitudinal"&&O("blur direction must be either latitudinal or longitudinal!");let u=3,h=this._lodMeshes[i];h.material=l;let d=_h.get(l),p=this._sizeLods[s]-1,m=isFinite(n)?Math.PI/(2*p):2*Math.PI/(2*tr-1),g=n/m,y=isFinite(n)?1+Math.floor(u*g):tr;y>tr&&z(`sigmaRadians, ${n}, is too large and will clip, as it requested ${y} samples when the maximum is set to ${tr}`);let x=[],_=0;for(let N=0;N<tr;++N){let C=N/g,I=Math.exp(-C*C/2);x.push(I),N===0?_+=I:N<y&&(_+=2*I)}for(let N=0;N<x.length;N++)x[N]=x[N]/_;e.texture.frame=(e.texture.frame||0)+1,d.envMap.value=e.texture,d.samples.value=y,d.weights.array=x,d.latitudinal.value=r==="latitudinal"?1:0,a&&(d.poleAxis.value=a);let{_lodMax:w}=this;d.dTheta.value=m,d.mipInt.value=w-s;let S=this._sizeLods[i],E=3*S*(i>w-mn?i-w+mn:0),B=4*(this._cubeSize-S);to(t,E,B,3*S,2*S),c.setRenderTarget(t),c.render(h,$a)}};function kN(o){let e=[],t=[],s=[],i=o,n=o-mn+1+o_.length;for(let r=0;r<n;r++){let a=Math.pow(2,i);e.push(a);let c=1/a;r>o-mn?c=o_[r-o+mn-1]:r===0&&(c=0),t.push(c);let l=1/(a-2),u=-l,h=1+l,d=[u,u,h,u,h,h,u,u,h,h,u,h],p=6,m=6,g=3,y=2,x=1,_=new Float32Array(g*m*p),w=new Float32Array(y*m*p),S=new Float32Array(x*m*p);for(let B=0;B<p;B++){let N=B%3*2/3-1,C=B>2?0:-1,I=[N,C,0,N+2/3,C,0,N+2/3,C+1,0,N,C,0,N+2/3,C+1,0,N,C+1,0],k=VN[B];_.set(I,g*m*k),w.set(d,y*m*k);let W=[k,k,k,k,k,k];S.set(W,x*m*k)}let E=new vs;E.setAttribute("position",new yt(_,g)),E.setAttribute("uv",new yt(w,y)),E.setAttribute("faceIndex",new yt(S,x)),s.push(new Zt(E,null)),i>mn&&i--}return{lodMeshes:s,sizeLods:e,sigmas:t}}function c_(o,e){let t={magFilter:ct,minFilter:ct,generateMipmaps:!1,type:$e,format:Lt,colorSpace:Ho},s=new bt(o,e,t);return s.texture.mapping=nu,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function to(o,e,t,s,i){o.viewport.set(e,t,s,i),o.scissor.set(e,t,s,i)}function bd(o){let e=new Ne;return e.depthTest=!1,e.depthWrite=!1,e.blending=qs,e.name=`PMREM_${o}`,e}function zN(o,e,t){let s=St(new Array(tr).fill(0)),i=j(new R(0,1,0)),n=j(0),r=b(tr),a=j(0),c=j(1),l=xe(),u=j(0),h=b(1/e),d=b(1/t),p=b(o),m={n:r,latitudinal:a,weights:s,poleAxis:i,outputDirection:xd,dTheta:n,samples:c,envMap:l,mipInt:u,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=bd("blur");return g.fragmentNode=Jv({...m,latitudinal:a.equal(1)}),_h.set(g,m),g}function GN(o,e,t){let s=xe(),i=j(0),n=j(0),r=b(1/e),a=b(1/t),c=b(o),l={envMap:s,roughness:i,mipInt:n,CUBEUV_TEXEL_WIDTH:r,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:c},u=bd("ggx");return u.fragmentNode=Qv({...l,N_immutable:xd,GGX_SAMPLES:D(LN)}),_h.set(u,l),u}function l_(o){let e=bd("cubemap");return e.fragmentNode=Ft(o,xd),e}function u_(o){let e=bd("equirect");return e.fragmentNode=xe(o,Qx(xd),0),e}var h_=new WeakMap;function WN(o){let e=Math.log2(o)-2,t=1/o;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:t,maxMip:e}}function $N(o,e,t){let s=qN(e),i=s.get(o);if((i!==void 0?i.pmremVersion:-1)!==o.pmremVersion){let r=o.image;if(o.isCubeTexture)if(HN(r))i=t.fromCubemap(o,i);else return null;else if(XN(r))i=t.fromEquirectangular(o,i);else return null;i.pmremVersion=o.pmremVersion,s.set(o,i)}return i.texture}function qN(o){let e=h_.get(o);return e===void 0&&(e=new WeakMap,h_.set(o,e)),e}var Em=class extends Be{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;let i=new xt;i.isRenderTargetTexture=!0,this._texture=xe(i),this._width=j(0),this._height=j(0),this._maxMip=j(0),this.updateBeforeType=te.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){let t=WN(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem,s=t?t.pmremVersion:-1,i=this._value;s!==i.pmremVersion&&(i.isPMREMTexture===!0?t=i:t=$N(i,e.renderer,this._generator),t!==null&&(this._pmrem=t,this.updateFromTexture(t)))}setup(e){this._generator===null&&(this._generator=new Cm(e.renderer)),this.updateBefore(e);let t=this.uvNode;t===null&&e.context.getUV&&(t=e.context.getUV(this,e)),t=zx.mul(v(t.x,t.y.negate(),t.z));let s=this.levelNode;return s===null&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),Zv(this._texture,t,s,this._width,this._height,this._maxMip)}dispose(){super.dispose(),this._generator!==null&&this._generator.dispose()}};function HN(o){if(o==null)return!1;let e=0,t=6;for(let s=0;s<t;s++)o[s]!==void 0&&e++;return e===t}function XN(o){return o==null?!1:o.height>0}var s0=oe(Em).setParameterLength(1,3),d_=new WeakMap,Bm=class extends Tn{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){let{material:t}=e,s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){let h=s.isTextureNode?s.value:t[s.property],d=this._getPMREMNodeCache(e.renderer),p=d.get(h);p===void 0&&(p=s0(h),d.set(h,p)),s=p}let n=t.useAnisotropy===!0||t.anisotropy>0?YS:ye,r=s.context(p_(ii,n)).mul(qu),a=s.context(YN(Mn)).mul(Math.PI).mul(qu),c=go(r),l=go(a);e.context.radiance.addAssign(c),e.context.iblIrradiance.addAssign(l);let u=e.context.lightingModel.clearcoatRadiance;if(u){let h=s.context(p_(po,dn)).mul(qu),d=go(h);u.addAssign(d)}}_getPMREMNodeCache(e){let t=d_.get(e);return t===void 0&&(t=new WeakMap,d_.set(e,t)),t}},p_=(o,e)=>{let t=null;return{getUV:()=>(t===null&&(t=Ce.negate().reflect(e),t=wx(o).mix(t,e).normalize(),t=t.transformDirection(fs)),t),getTextureLevel:()=>o}},YN=o=>({getUV:()=>o,getTextureLevel:()=>b(1)}),jN=new ta,Th=class extends Ne{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(jN),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t===null&&e.environmentNode&&(t=e.environmentNode),t?new Bm(t):null}setupLightingModel(){return new bh}setupSpecular(){let e=le(v(.04),we.rgb,Li);_n.assign(v(.04)),sr.assign(e),ir.assign(1)}setupVariants(){let e=this.metalnessNode?b(this.metalnessNode):iv;Li.assign(e);let t=this.roughnessNode?b(this.roughnessNode):sv;t=Kx({roughness:t}),ii.assign(t),this.setupSpecular(),er.assign(we.rgb.mul(e.oneMinus()))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}},ZN=new Nl,Fm=class extends Th{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(ZN),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||this.clearcoatNode!==null}get useIridescence(){return this.iridescence>0||this.iridescenceNode!==null}get useSheen(){return this.sheen>0||this.sheenNode!==null}get useAnisotropy(){return this.anisotropy>0||this.anisotropyNode!==null}get useTransmission(){return this.transmission>0||this.transmissionNode!==null}get useDispersion(){return this.dispersion>0||this.dispersionNode!==null}setupSpecular(){let e=this.iorNode?b(this.iorNode):yv;rc.assign(e),_n.assign(Vt(vx(rc.sub(1).div(rc.add(1))).mul(tv),v(1)).mul(om)),sr.assign(le(_n,we.rgb,Li)),ir.assign(le(om,1,Li))}setupLightingModel(){return new bh(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){let t=this.clearcoatNode?b(this.clearcoatNode):rv,s=this.clearcoatRoughnessNode?b(this.clearcoatRoughnessNode):ov;Ju.assign(t),po.assign(Kx({roughness:s}))}if(this.useSheen){let t=this.sheenNode?v(this.sheenNode):lv,s=this.sheenRoughnessNode?b(this.sheenRoughnessNode):uv;Kt.assign(t),ln.assign(s)}if(this.useIridescence){let t=this.iridescenceNode?b(this.iridescenceNode):dv,s=this.iridescenceIORNode?b(this.iridescenceIORNode):pv,i=this.iridescenceThicknessNode?b(this.iridescenceThicknessNode):fv;od.assign(t),Qu.assign(s),Ku.assign(i)}if(this.useAnisotropy){let t=(this.anisotropyNode?U(this.anisotropyNode):hv).toVar();cn.assign(t.length()),K(cn.equal(0),()=>{t.assign(U(1,0))}).Else(()=>{t.divAssign(U(cn)),cn.assign(cn.saturate())}),eh.assign(cn.pow2().mix(ii.pow2(),1)),nc.assign(nr[0].mul(t.x).add(nr[1].mul(t.y))),ar.assign(nr[1].mul(t.x).sub(nr[0].mul(t.y)))}if(this.useTransmission){let t=this.transmissionNode?b(this.transmissionNode):mv,s=this.thicknessNode?b(this.thicknessNode):gv,i=this.attenuationDistanceNode?b(this.attenuationDistanceNode):xv,n=this.attenuationColorNode?v(this.attenuationColorNode):bv;if(sh.assign(t),ox.assign(s),ax.assign(i),cx.assign(n),this.useDispersion){let r=this.dispersionNode?b(this.dispersionNode):Mv;lx.assign(r)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?v(this.clearcoatNormalNode):av}setup(e){e.context.setupClearcoatNormal=()=>cr(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.iorNode=e.iorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}};var JN=A(({normal:o,lightDirection:e,builder:t})=>{let s=o.dot(e),i=U(s.mul(.5).add(.5),0);if(t.material.gradientMap){let n=Di("gradientMap","texture").context({getUV:()=>i});return v(n.r)}else{let n=i.fwidth().mul(.5);return le(v(.7),v(1),Fs(b(.7).sub(n.x),b(.7).add(n.x),i.x))}}),Im=class extends Mo{direct({lightDirection:e,lightColor:t,reflectedLight:s},i){let n=JN({normal:pd,lightDirection:e,builder:i}).mul(t);s.directDiffuse.addAssign(n.mul(dr({diffuseColor:we.rgb})))}indirect(e){let{ambientOcclusion:t,irradiance:s,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(s.mul(dr({diffuseColor:we}))),i.indirectDiffuse.mulAssign(t)}},QN=new Cl,Pm=class extends Ne{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(QN),this.setValues(e)}setupLightingModel(){return new Im}},Kv=A(()=>{let o=v(Ce.z,0,Ce.x.negate()).normalize(),e=Ce.cross(o);return U(o.dot(ye),e.dot(ye)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),KN=new Fl,Dm=class extends Ne{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(KN),this.setValues(e)}setupVariants(e){let t=Kv,s;e.material.matcap?s=Di("matcap","texture").context({getUV:()=>t}):s=v(le(.2,.8,t.y)),we.rgb.mulAssign(s.rgb)}},Lm=class extends Be{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){let{rotationNode:t,positionNode:s}=this;if(this.getNodeType(e)==="vec2"){let n=t.cos(),r=t.sin();return rd(n,r,r.negate(),n).mul(s)}else{let n=t,r=gn(Z(1,0,0,0),Z(0,Rs(n.x),Bt(n.x).negate(),0),Z(0,Bt(n.x),Rs(n.x),0),Z(0,0,0,1)),a=gn(Z(Rs(n.y),0,Bt(n.y),0),Z(0,1,0,0),Z(Bt(n.y).negate(),0,Rs(n.y),0),Z(0,0,0,1)),c=gn(Z(Rs(n.z),Bt(n.z).negate(),0,0),Z(Bt(n.z),Rs(n.z),0,0),Z(0,0,1,0),Z(0,0,0,1));return r.mul(a).mul(c).mul(Z(s,1)).xyz}}},Pc=oe(Lm).setParameterLength(2),eR=new bl,Sh=class extends Ne{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(eR),this.setValues(e)}setupPositionView(e){let{object:t,camera:s}=e,{positionNode:i,rotationNode:n,scaleNode:r,sizeAttenuation:a}=this,c=wn.mul(v(i||0)),l=U(ls[0].xyz.length(),ls[1].xyz.length());r!==null&&(l=l.mul(U(r))),s.isPerspectiveCamera&&a===!1&&(l=l.mul(c.z.negate()));let u=Ic.xy;if(t.center&&t.center.isVector2===!0){let p=GM("center","vec2",t);u=u.sub(p.sub(.5))}u=u.mul(l);let h=b(n||cv),d=Pc(u,h);return Z(c.xy.add(d),c.zw)}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}},tR=new Sl,sR=new re,Um=class extends Sh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(tR),this.setValues(e)}setupPositionView(){let{positionNode:e}=this;return wn.mul(v(e||Ve)).xyz}setupVertexSprite(e){let{material:t,camera:s}=e,{rotationNode:i,scaleNode:n,sizeNode:r,sizeAttenuation:a}=this,c=super.setupVertex(e);if(t.isNodeMaterial!==!0)return c;let l=r!==null?U(r):wv;l=l.mul(TS),s.isPerspectiveCamera&&a===!0&&(l=l.mul(iR.div(qe.z.negate()))),n&&n.isNode&&(l=l.mul(U(n)));let u=Ic.xy;if(i&&i.isNode){let h=b(i);u=Pc(u,h)}return u=u.mul(l),u=u.div(Ux.div(2)),u=u.mul(c.w),c=c.add(Z(u,0,0)),c}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}},iR=j(1).onFrameUpdate(function({renderer:o}){let e=o.getSize(sR);this.value=.5*e.y}),Om=class extends Mo{constructor(){super(),this.shadowNode=b(1).toVar("shadowMask")}direct({lightNode:e}){e.shadowNode!==null&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){we.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(we.rgb)}},nR=new Al,Vm=class extends Ne{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(nR),this.setValues(e)}setupLightingModel(){return new Om}},fD=Ui("vec3"),mD=Ui("vec3"),gD=Ui("vec3");var km=class{constructor(e,t,s){this.renderer=e,this.nodes=t,this.info=s,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){let e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),this._animationLoop!==null&&this._animationLoop(t,s),this.renderer._inspector.finish()};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}},pi=class{constructor(){this.weakMaps={}}_getWeakMap(e){let t=e.length,s=this.weakMaps[t];return s===void 0&&(s=new WeakMap,this.weakMaps[t]=s),s}get(e){let t=this._getWeakMap(e);for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let s=this._getWeakMap(e);for(let i=0;i<e.length-1;i++){let n=e[i];s.has(n)===!1&&s.set(n,new WeakMap),s=s.get(n)}return s.set(e[e.length-1],t),this}delete(e){let t=this._getWeakMap(e);for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return!1;return t.delete(e[e.length-1])}},rR=0;function oR(o){let e=Object.keys(o),t=Object.getPrototypeOf(o);for(;t;){let s=Object.getOwnPropertyDescriptors(t);for(let i in s)if(s[i]!==void 0){let n=s[i];n&&typeof n.get=="function"&&e.push(i)}t=Object.getPrototypeOf(t)}return e}var zm=class{constructor(e,t,s,i,n,r,a,c,l,u){this.id=rR++,this._nodes=e,this._geometries=t,this.renderer=s,this.object=i,this.material=n,this.scene=r,this.camera=a,this.lightsNode=c,this.context=l,this.geometry=i.geometry,this.version=n.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=u,this.clippingContextCacheKey=u!==null?u.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(let t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(this.attributes!==null)return this.attributes;let e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],i=new Set,n={};for(let r of e){let a;if(r.node&&r.node.attribute?a=r.node.attribute:(a=t.getAttribute(r.name),n[r.name]=a.id),a===void 0)continue;s.push(a);let c=a.isInterleavedBufferAttribute?a.data:a;i.add(c)}return this.attributes=s,this.attributesId=n,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){let{object:e,material:t,geometry:s,group:i,drawRange:n}=this,r=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),c=a!==null,l=1;if(s.isInstancedBufferGeometry===!0?l=s.instanceCount:e.count!==void 0&&(l=Math.max(0,e.count)),l===0)return null;if(r.instanceCount=l,e.isBatchedMesh===!0)return r;let u=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(u=2);let h=n.start*u,d=(n.start+n.count)*u;i!==null&&(h=Math.max(h,i.start*u),d=Math.min(d,(i.start+i.count)*u));let p=s.attributes.position,m=1/0;c?m=a.count:p!=null&&(m=p.count),h=Math.max(h,0),d=Math.min(d,m);let g=d-h;return g<0||g===1/0?null:(r.vertexCount=g,r.firstVertex=h,r)}getGeometryCacheKey(){let{geometry:e}=this,t="";for(let s of Object.keys(e.attributes).sort()){let i=e.attributes[s];t+=s+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(let s of Object.keys(e.morphAttributes).sort()){let i=e.morphAttributes[s];t+="morph-"+s+",";for(let n=0,r=i.length;n<r;n++){let a=i[n];t+=a.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){let{object:e,material:t,renderer:s}=this,i=t.customProgramCacheKey();for(let n of oR(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(n))continue;let r=t[n],a;if(r!==null){let c=typeof r;c==="number"?a=r!==0?"1":"0":c==="object"?(a="{",r.isTexture&&(a+=r.mapping,s.backend.isWebGPUBackend===!0&&(a+=r.magFilter,a+=r.minFilter,a+=r.wrapS,a+=r.wrapT,a+=r.wrapR)),a+="}"):a=String(r)}else a=String(r);i+=a+","}return i+=this.clippingContextCacheKey+",",e.geometry&&(i+=this.getGeometryCacheKey()),e.skeleton&&(i+=e.skeleton.bones.length+","),e.isBatchedMesh&&(i+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(i+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1||Array.isArray(e.morphTargetInfluences))&&(i+=e.uuid+","),i+=this.context.id+",",i+=e.receiveShadow+",",Ro(i)}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(this.attributes!==null){let e=this.attributesId;for(let t in e){let s=this.geometry.getAttribute(t);if(s===void 0||e[t]!==s.id)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=sc(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=sc(e,1)),e=sc(e,this.renderer.contextNode.id,this.renderer.contextNode.version),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),this.onDispose()}},Ks=[],Gm=class{constructor(e,t,s,i,n,r){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=i,this.bindings=n,this.info=r,this.chainMaps={}}get(e,t,s,i,n,r,a,c){let l=this.getChainMap(c);Ks[0]=e,Ks[1]=t,Ks[2]=r,Ks[3]=n;let u=l.get(Ks);return u===void 0?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,i,n,r,a,c),l.set(Ks,u)):(u.camera=i,u.updateClipping(a),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(e,t,s,i,n,r,a,c)):u.version=t.version)),Ks[0]=null,Ks[1]=null,Ks[2]=null,Ks[3]=null,u}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new pi)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,i,n,r,a,c,l,u,h){let d=this.getChainMap(h),p=new zm(e,t,s,i,n,r,a,c,l,u);return p.onDispose=()=>{this.pipelines.delete(p),this.bindings.deleteForRender(p),this.nodes.delete(p),d.delete(p.getChainArray())},p}},fi=class{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}},us={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},pn=16,aR=211,cR=212,Wm=class extends fi{constructor(e){super(),this.backend=e}delete(e){let t=super.delete(e);return t!==null&&this.backend.destroyAttribute(e),t}update(e,t){let s=this.get(e);if(s.version===void 0)t===us.VERTEX?this.backend.createAttribute(e):t===us.INDEX?this.backend.createIndexAttribute(e):t===us.STORAGE?this.backend.createStorageAttribute(e):t===us.INDIRECT&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{let i=this._getBufferAttribute(e);(s.version<i.version||i.usage===Qr)&&(this.backend.updateAttribute(e),s.version=i.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}};function ew(o){return o.index!==null?o.index.version:o.attributes.position.version}function tw(o){return o.index!==null?o.index.id:o.attributes.position.id}function f_(o){let e=[],t=o.index,s=o.attributes.position;if(t!==null){let n=t.array;for(let r=0,a=n.length;r<a;r+=3){let c=n[r+0],l=n[r+1],u=n[r+2];e.push(c,l,l,u,u,c)}}else{let n=s.array;for(let r=0,a=n.length/3-1;r<a;r+=3){let c=r+0,l=r+1,u=r+2;e.push(c,l,l,u,u,c)}}let i=new(s.count>=65535?jo:Yo)(e,1);return i.version=ew(o),i.__id=tw(o),i}var $m=class extends fi{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){let t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){let t=e.geometry,s=this.get(t);s.initialized=!0,this.info.memory.geometries++;let i=()=>{this.info.memory.geometries--;let n=t.index,r=e.getAttributes();n!==null&&this.attributes.delete(n);for(let c of r)this.attributes.delete(c);let a=this.wireframes.get(t);a!==void 0&&this.attributes.delete(a),t.removeEventListener("dispose",i),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",i),this._geometryDisposeListeners.set(t,i)}updateAttributes(e){let t=e.getAttributes();for(let n of t)n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute?this.updateAttribute(n,us.STORAGE):this.updateAttribute(n,us.VERTEX);let s=this.getIndex(e);s!==null&&this.updateAttribute(s,us.INDEX);let i=e.geometry.indirect;i!==null&&this.updateAttribute(i,us.INDIRECT)}updateAttribute(e,t){let s=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){let{geometry:t,material:s}=e,i=t.index;if(s.wireframe===!0){let n=this.wireframes,r=n.get(t);r===void 0?(r=f_(t),n.set(t,r)):(r.version!==ew(t)||r.__id!==tw(t))&&(this.attributes.delete(r),r=f_(t),n.set(t,r)),i=r}return i}dispose(){for(let[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}},qm=class{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):O("WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}},vh=class{constructor(e){this.cacheKey=e,this.usedTimes=0}},Hm=class extends vh{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}},Xm=class extends vh{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}},lR=0,cc=class{constructor(e,t,s,i=null,n=null){this.id=lR++,this.code=e,this.stage=t,this.name=s,this.transforms=i,this.attributes=n,this.usedTimes=0}},Ym=class extends fi{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){let{backend:s}=this,i=this.get(e);if(this._needsComputeUpdate(e)){let n=i.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);let r=this.nodes.getForCompute(e),a=this.programs.compute.get(r.computeShader);a===void 0&&(n&&n.computeProgram.usedTimes===0&&this._releaseProgram(n.computeProgram),a=new cc(r.computeShader,"compute",e.name,r.transforms,r.nodeAttributes),this.programs.compute.set(r.computeShader,a),s.createProgram(a));let c=this._getComputeCacheKey(e,a),l=this.caches.get(c);l===void 0&&(n&&n.usedTimes===0&&this._releasePipeline(n),l=this._getComputePipeline(e,a,c,t)),l.usedTimes++,a.usedTimes++,i.version=e.version,i.pipeline=l}return i.pipeline}getForRender(e,t=null){let{backend:s}=this,i=this.get(e);if(this._needsRenderUpdate(e)){let n=i.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);let r=e.getNodeBuilderState(),a=e.material?e.material.name:"",c=this.programs.vertex.get(r.vertexShader);c===void 0&&(n&&n.vertexProgram.usedTimes===0&&this._releaseProgram(n.vertexProgram),c=new cc(r.vertexShader,"vertex",a),this.programs.vertex.set(r.vertexShader,c),s.createProgram(c));let l=this.programs.fragment.get(r.fragmentShader);l===void 0&&(n&&n.fragmentProgram.usedTimes===0&&this._releaseProgram(n.fragmentProgram),l=new cc(r.fragmentShader,"fragment",a),this.programs.fragment.set(r.fragmentShader,l),s.createProgram(l));let u=this._getRenderCacheKey(e,c,l),h=this.caches.get(u);h===void 0?(n&&n.usedTimes===0&&this._releasePipeline(n),h=this._getRenderPipeline(e,c,l,u,t)):e.pipeline=h,h.usedTimes++,c.usedTimes++,l.usedTimes++,i.pipeline=h}return i.pipeline}delete(e){let t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,i){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return n===void 0&&(n=new Xm(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,i)),n}_getRenderPipeline(e,t,s,i,n){i=i||this._getRenderCacheKey(e,t,s);let r=this.caches.get(i);return r===void 0&&(r=new Hm(i,t,s),this.caches.set(i,r),e.pipeline=r,this.backend.createRenderPipeline(e,n)),r}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){let t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){let t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}},jm=class extends fi{constructor(e,t,s,i,n,r){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=i,this.nodes=t,this.info=r,this.pipelines.bindings=this}getForRender(e){let t=e.getBindings();for(let s of t){let i=this.get(s);i.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),i.bindGroup=s)}return t}getForCompute(e){let t=this.nodes.getForCompute(e).bindings;for(let s of t){let i=this.get(s);i.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),i.bindGroup=s)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}deleteForCompute(e){let t=this.nodes.getForCompute(e).bindings;for(let s of t)this.backend.deleteBindGroupData(s),this.delete(s)}deleteForRender(e){let t=e.getBindings();for(let s of t)this.backend.deleteBindGroupData(s),this.delete(s)}_updateBindings(e){for(let t of e)this._update(t,e)}_init(e){for(let t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isSampler)this.textures.updateSampler(t.texture);else if(t.isStorageBuffer){let s=t.attribute,i=s.isIndirectStorageBufferAttribute?us.INDIRECT:us.STORAGE;this.attributes.update(s,i)}}_update(e,t){let{backend:s}=this,i=!1,n=!0,r=0,a=0;for(let c of e.bindings)if(this.nodes.updateGroup(c)!==!1){if(c.isStorageBuffer){let u=c.attribute,h=u.isIndirectStorageBufferAttribute?us.INDIRECT:us.STORAGE,d=s.get(c);this.attributes.update(u,h),d.attribute!==u&&(d.attribute=u,i=!0)}if(c.isUniformBuffer)c.update()&&s.updateBinding(c);else if(c.isSampledTexture){let u=c.update(),h=c.texture,d=this.textures.get(h);if(u&&(this.textures.updateTexture(h),c.generation!==d.generation&&(c.generation=d.generation,i=!0),d.bindGroups.add(e)),s.get(h).externalTexture!==void 0||d.isDefaultTexture?n=!1:(r=r*10+h.id,a+=h.version),h.isStorageTexture===!0&&h.mipmapsAutoUpdate===!0){let m=this.get(h);c.store===!0?m.needsMipmap=!0:this.textures.needsMipmaps(h)&&m.needsMipmap===!0&&(this.backend.generateMipmaps(h),m.needsMipmap=!1)}}else if(c.isSampler&&c.update()){let h=this.textures.updateSampler(c.texture);c.samplerKey!==h&&(c.samplerKey=h,i=!0)}c.isBuffer&&c.updateRanges.length>0&&c.clearUpdateRanges()}i===!0&&this.backend.updateBindings(e,t,n?r:0,a)}};function uR(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?o.z-e.z:o.id-e.id}function m_(o,e){return o.groupOrder!==e.groupOrder?o.groupOrder-e.groupOrder:o.renderOrder!==e.renderOrder?o.renderOrder-e.renderOrder:o.z!==e.z?e.z-o.z:o.id-e.id}function g_(o){return(o.transmission>0||o.transmissionNode&&o.transmissionNode.isNode)&&o.side===$s&&o.forceSinglePass===!1}var Zm=class{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,i,n,r,a){let c=this.renderItems[this.renderItemsIndex];return c===void 0?(c={id:e.id,object:e,geometry:t,material:s,groupOrder:i,renderOrder:e.renderOrder,z:n,group:r,clippingContext:a},this.renderItems[this.renderItemsIndex]=c):(c.id=e.id,c.object=e,c.geometry=t,c.material=s,c.groupOrder=i,c.renderOrder=e.renderOrder,c.z=n,c.group=r,c.clippingContext=a),this.renderItemsIndex++,c}push(e,t,s,i,n,r,a){let c=this.getNextRenderItem(e,t,s,i,n,r,a);e.occlusionTest===!0&&this.occlusionQueryCount++,s.transparent===!0||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode?(g_(s)&&this.transparentDoublePass.push(c),this.transparent.push(c)):this.opaque.push(c)}unshift(e,t,s,i,n,r,a){let c=this.getNextRenderItem(e,t,s,i,n,r,a);s.transparent===!0||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode?(g_(s)&&this.transparentDoublePass.unshift(c),this.transparent.unshift(c)):this.opaque.unshift(c)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||uR),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||m_),this.transparent.length>1&&this.transparent.sort(t||m_)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){let s=this.renderItems[e];if(s.id===null)break;s.id=null,s.object=null,s.geometry=null,s.material=null,s.groupOrder=null,s.renderOrder=null,s.z=null,s.group=null,s.clippingContext=null}}},so=[],Jm=class{constructor(e){this.lighting=e,this.lists=new pi}get(e,t){let s=this.lists;so[0]=e,so[1]=t;let i=s.get(so);return i===void 0&&(i=new Zm(this.lighting,e,t),s.set(so,i)),so[0]=null,so[1]=null,i}dispose(){this.lists=new pi}},hR=0,Qm=class{constructor(){this.id=hR++,this.mrt=null,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new Te,this.scissor=!1,this.scissorValue=new Te,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.camera=null,this.isRenderContext=!0}getCacheKey(){return sw(this)}};function sw(o){let{textures:e,activeCubeFace:t,activeMipmapLevel:s}=o,i=[t,s];for(let n of e)i.push(n.id);return Ec(i)}var Km=class{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,s=0){let i;if(e===null)i="default";else{let c=e.texture.format,l=e.texture.type;i=`${e.textures.length}:${c}:${l}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}let n=t!==null?t.id:"default",r=i+"-"+n+"-"+s,a=this._renderContexts[r];return a===void 0&&(a=new Qm,a.mrt=t,this._renderContexts[r]=a),e!==null&&(a.sampleCount=e.samples===0?1:e.samples),a.clearDepthValue=this.renderer.getClearDepth(),a.clearStencilValue=this.renderer.getClearStencil(),a}dispose(){this._renderContexts={}}},dR=new R,eg=class extends fi{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){let s=this.get(e),i=e.samples===0?1:e.samples,n=s.depthTextureMips||(s.depthTextureMips={}),r=e.textures,a=this.getSize(r[0]),c=a.width>>t,l=a.height>>t,u=e.depthTexture||n[t],h=e.depthBuffer===!0||e.stencilBuffer===!0,d=!1;u===void 0&&h&&(u=new Rt,u.format=e.stencilBuffer?Hs:ns,u.type=e.stencilBuffer?Ei:Oe,u.image.width=c,u.image.height=l,u.image.depth=a.depth,u.renderTarget=e,u.isArrayTexture=e.multiview===!0&&a.depth>1,n[t]=u),(s.width!==a.width||a.height!==s.height)&&(d=!0,u&&(u.needsUpdate=!0,u.image.width=c,u.image.height=l,u.image.depth=u.isArrayTexture?u.image.depth:1)),s.width=a.width,s.height=a.height,s.textures=r,s.depthTexture=u||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==i&&(d=!0,u&&(u.needsUpdate=!0),s.sampleCount=i);let p={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let m=0;m<r.length;m++){let g=r[m];d&&(g.needsUpdate=!0),this.updateTexture(g,p)}u&&this.updateTexture(u,p)}s.initialized!==!0&&(s.initialized=!0,s.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",s.onDispose))}updateTexture(e,t={}){let s=this.get(e);if(s.initialized===!0&&s.version===e.version)return;let i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,n=this.backend;if(i&&s.initialized===!0&&n.destroyTexture(e),e.isFramebufferTexture){let l=this.renderer.getRenderTarget();l?e.type=l.texture.type:e.type=lt}let{width:r,height:a,depth:c}=this.getSize(e);if(t.width=r,t.height=a,t.depth=c,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,r,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||e.isStorageTexture===!0||e.isExternalTexture===!0)n.createTexture(e,t),s.generation=e.version;else if(e.version>0){let l=e.image;if(l===void 0)z("Renderer: Texture marked for update but image is undefined.");else if(l.complete===!1)z("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){let h=[];for(let d of e.images)h.push(d);t.images=h}else t.image=l;(s.isDefaultTexture===void 0||s.isDefaultTexture===!0)&&(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),e.source.dataReady===!0&&n.updateTexture(e,t);let u=e.isStorageTexture===!0&&e.mipmapsAutoUpdate===!1;t.needsMipmaps&&e.mipmaps.length===0&&!u&&n.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version;s.initialized!==!0&&(s.initialized=!0,s.generation=e.version,s.bindGroups=new Set,this.info.memory.textures++,e.isVideoTexture&&me.enabled===!0&&me.getTransfer(e.colorSpace)!==ne&&z("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),s.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",s.onDispose)),s.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=dR){let s=e.images?e.images[0]:e.image;return s?(s.image!==void 0&&(s=s.image),typeof HTMLVideoElement<"u"&&s instanceof HTMLVideoElement?(t.width=s.videoWidth||1,t.height=s.videoHeight||1,t.depth=1):typeof VideoFrame<"u"&&s instanceof VideoFrame?(t.width=s.displayWidth||1,t.height=s.displayHeight||1,t.depth=1):(t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let i;return e.mipmaps.length>0?i=e.mipmaps.length:e.isCompressedTexture===!0?i=1:i=Math.floor(Math.log2(Math.max(t,s)))+1,i}needsMipmaps(e){return e.generateMipmaps===!0||e.mipmaps.length>0}_destroyRenderTarget(e){if(this.has(e)===!0){let t=this.get(e),s=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let n=0;n<s.length;n++)this._destroyTexture(s[n]);i&&this._destroyTexture(i),this.delete(e),this.backend.delete(e)}}_destroyTexture(e){if(this.has(e)===!0){let t=this.get(e);e.removeEventListener("dispose",t.onDispose);let s=t.isDefaultTexture;if(this.backend.destroyTexture(e,s),t.bindGroups)for(let i of t.bindGroups){let n=this.backend.get(i);n.groups=void 0,n.versions=void 0}this.delete(e),this.info.memory.textures--}}},Tc=class extends ge{constructor(e,t,s,i=1){super(e,t,s),this.a=i}set(e,t,s,i=1){return this.a=i,super.set(e,t,s)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}},wh=class extends be{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){let s=this.getNodeType(e),i=e.getStructTypeNode(s),n;return i!==null?n=i.getMemberType(e,t):(O(`TSL: Member "${t}" not found in struct "${s}".`,new ke),n="float"),n}getHash(){return this.uuid}generate(){return this.name}},pR=(o,e)=>new wh(o,e),tg=class extends H{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this.isStackNode=!0}getElementType(e){return this.hasOutput(e)?this.outputNode.getElementType(e):"void"}getNodeType(e){return this.hasOutput(e)?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.hasOutput(e)?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=this.nodes.length){return e.isNode!==!0?(O("TSL: Invalid node added to stack.",new ke),this):(this.nodes.splice(t,0,e),this)}addToStackBefore(e){let t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){let s=new ho(t);return this._currentCond=vt(e,s),this.addToStack(this._currentCond)}ElseIf(e,t){let s=new ho(t),i=vt(e,s);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(e){return this._currentCond.elseNode=new ho(e),this}Switch(e){return this._expressionNode=q(e),this}Case(...e){let t=[];if(e.length>=2)for(let a=0;a<e.length-1;a++)t.push(this._expressionNode.equal(q(e[a])));else O("TSL: Invalid parameter length. Case() requires at least two parameters.",new ke);let s=e[e.length-1],i=new ho(s),n=t[0];for(let a=1;a<t.length;a++)n=n.or(t[a]);let r=vt(n,i);return this._currentCond===null?(this._currentCond=r,this.addToStack(this._currentCond)):(this._currentCond.elseNode=r,this._currentCond=r,this)}Default(e){return this.Else(e),this}setup(e){let t=e.getNodeProperties(this),s=0;for(let i of this.getChildren())i.isVarNode&&i.isIntent(e)&&i.isAssign(e)!==!0||(t["node"+s++]=i);return t.outputNode||null}hasOutput(e){return this.outputNode&&this.outputNode.isNode&&this.outputNode.getNodeType(e)!=="void"}build(e,...t){let s=ex(),i=e.buildStage;pc(this),e.setActiveStack(this);let n=l=>{if(this._currentNode=l,!(l.isVarNode&&l.isIntent(e)&&l.isAssign(e)!==!0)){if(i==="setup")l.build(e);else if(i==="analyze")l.build(e,this);else if(i==="generate"){let u=e.getDataFromNode(l,"any").stages,h=u&&u[e.shaderStage];if(l.isVarNode&&h&&h.length===1&&h[0]&&h[0].isStackNode)return;l.build(e,"void")}}},r=[...this.nodes];for(let l of r)n(l);this._currentNode=null;let a=this.nodes.filter(l=>r.indexOf(l)===-1);for(let l of a)n(l);let c;return this.hasOutput(e)?c=this.outputNode.build(e,...t):c=super.build(e,...t),pc(s),e.removeActiveStack(this),c}},Xu=oe(tg).setParameterLength(0,1);function fR(o){return Object.entries(o).map(([e,t])=>typeof t=="string"?{name:e,type:t,atomic:!1}:{name:e,type:t.type,atomic:t.atomic||!1})}var sg=class extends H{static get type(){return"StructTypeNode"}constructor(e,t=null){super("struct"),this.membersLayout=fR(e),this.name=t,this.isStructLayoutNode=!0}getLength(){let e=Float32Array.BYTES_PER_ELEMENT,t=1,s=0;for(let i of this.membersLayout){let n=i.type,r=aM(n),a=cM(n)/e;t=Math.max(t,a);let l=s%t%a;l!==0&&(s+=a-l),s+=r}return Math.ceil(s/t)*t}getMemberType(e,t){let s=this.membersLayout.find(i=>i.name===t);return s?s.type:"void"}getNodeType(e){return e.getStructTypeFromNode(this,this.membersLayout,this.name).name}setup(e){e.getStructTypeFromNode(this,this.membersLayout,this.name),e.addInclude(this)}generate(e){return this.getNodeType(e)}},ig=class extends H{static get type(){return"StructNode"}constructor(e,t){super("vec3"),this.structTypeNode=e,this.values=t,this.isStructNode=!0}getNodeType(e){return this.structTypeNode.getNodeType(e)}getMemberType(e,t){return this.structTypeNode.getMemberType(e,t)}_getChildren(){let e=super._getChildren(),t=e.find(s=>s.childNode===this.structTypeNode);return e.splice(e.indexOf(t),1),e.push(t),e}generate(e){let t=e.getVarFromNode(this),s=t.type,i=e.getPropertyName(t);return e.addLineFlowCode(`${i} = ${e.generateStruct(s,this.structTypeNode.membersLayout,this.values)}`,this),t.name}},mR=(o,e=null)=>{let t=new sg(o,e),s=(...i)=>{let n=null;if(i.length>0)if(i[0].isNode){n={};let r=Object.keys(o);for(let a=0;a<i.length;a++)n[r[a]]=i[a]}else n=i[0];return new ig(t,n)};return s.layout=t,s.isStruct=!0,s},Mh=class extends H{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}getNodeType(){return"OutputType"}generate(e){let t=e.getDataFromNode(this);if(t.membersLayout===void 0){let r=this.members,a=[];for(let c=0;c<r.length;c++){let l="m"+c,u=r[c].getNodeType(e);a.push({name:l,type:u,index:c})}t.membersLayout=a,t.structType=e.getOutputStructTypeFromNode(this,t.membersLayout)}let s=e.getOutputStructName(),i=this.members,n=s!==""?s+".":"";for(let r=0;r<i.length;r++){let a=i[r].build(e);e.addLineFlowCode(`${n}m${r} = ${a}`,this)}return s}},gR=oe(Mh),Ah=class{constructor(e=Ht){this.blending=e,this.blendSrc=Ir,this.blendDst=Pr,this.blendEquation=Xt,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.premultiplyAlpha=!1}copy(e){return this.blending=e.blending,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.premultiplyAlpha=e.premultiplyAlpha,this}clone(){return new this.constructor().copy(this)}},yR=new Ah(qs),xR=new Ah(eu);function iw(o,e){for(let t=0;t<o.length;t++)if(o[t].name===e)return t;return-1}var ng=class extends Mh{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.blendModes={output:xR},this.isMRTNode=!0}setBlendMode(e,t){return this.blendModes[e]=t,this}getBlendMode(e){return this.blendModes[e]||yR}has(e){return this.outputNodes[e]!==void 0}get(e){return this.outputNodes[e]}merge(e){let t={...this.outputNodes,...e.outputNodes},s={...this.blendModes,...e.blendModes},i=nw(t);return i.blendings=s,i}setup(e){let t=this.outputNodes,s=e.renderer.getRenderTarget(),i=[],n=s.textures;for(let r in t){let a=iw(n,r);i[a]=Z(t[r])}return this.members=i,super.setup(e)}},nw=oe(ng),pr=class extends Be{static get type(){return"BitcastNode"}constructor(e,t,s=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=s,this.isBitcastNode=!0}getNodeType(e){if(this.inputType!==null){let t=this.valueNode.getNodeType(e),s=e.getTypeLength(t);return e.getTypeFromLength(s,this.conversionType)}return this.conversionType}generate(e){let t=this.getNodeType(e),s="";if(this.inputType!==null){let i=this.valueNode.getNodeType(e);s=e.getTypeLength(i)===1?this.inputType:e.changeComponentType(i,this.inputType)}else s=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,s)}( ${this.valueNode.build(e,s)} )`}},rw=V(pr).setParameterLength(2),bR=o=>new pr(o,"int","float"),ow=o=>new pr(o,"uint","float"),_R=o=>new pr(o,"float","int"),TR=o=>new pr(o,"float","uint"),Ru={},Ps=class o extends F{static get type(){return"BitcountNode"}constructor(e,t){super(e,t),this.isBitcountNode=!0}_resolveElementType(e,t,s){s==="int"?t.assign(rw(e,"uint")):t.assign(e)}_returnDataNode(e){switch(e){case"uint":return D;case"int":return T;case"uvec2":return tx;case"uvec3":return mr;case"uvec4":return rx;case"ivec2":return Qe;case"ivec3":return sx;case"ivec4":return nx}}_createTrailingZerosBaseLayout(e,t){let s=this._returnDataNode(t);return A(([n])=>{let r=D(0);this._resolveElementType(n,r,t);let a=b(r.bitAnd(xx(r))),l=ow(a).shiftRight(23).sub(127);return s(l)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createLeadingZerosBaseLayout(e,t){let s=this._returnDataNode(t);return A(([n])=>{K(n.equal(D(0)),()=>D(32));let r=D(0),a=D(0);return this._resolveElementType(n,r,t),K(r.shiftRight(16).equal(0),()=>{a.addAssign(16),r.shiftLeftAssign(16)}),K(r.shiftRight(24).equal(0),()=>{a.addAssign(8),r.shiftLeftAssign(8)}),K(r.shiftRight(28).equal(0),()=>{a.addAssign(4),r.shiftLeftAssign(4)}),K(r.shiftRight(30).equal(0),()=>{a.addAssign(2),r.shiftLeftAssign(2)}),K(r.shiftRight(31).equal(0),()=>{a.addAssign(1)}),s(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createOneBitsBaseLayout(e,t){let s=this._returnDataNode(t);return A(([n])=>{let r=D(0);this._resolveElementType(n,r,t),r.assign(r.sub(r.shiftRight(D(1)).bitAnd(D(1431655765)))),r.assign(r.bitAnd(D(858993459)).add(r.shiftRight(D(2)).bitAnd(D(858993459))));let a=r.add(r.shiftRight(D(4))).bitAnd(D(252645135)).mul(D(16843009)).shiftRight(D(24));return s(a)}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}_createMainLayout(e,t,s,i){let n=this._returnDataNode(t);return A(([a])=>{if(s===1)return n(i(a));{let c=n(0),l=["x","y","z","w"];for(let u=0;u<s;u++){let h=l[u];c[h].assign(i(a[h]))}return c}}).setLayout({name:e,type:t,inputs:[{name:"value",type:t}]})}setup(e){let{method:t,aNode:s}=this,{renderer:i}=e;if(i.backend.isWebGPUBackend)return super.setup(e);let n=this.getInputType(e),r=e.getElementType(n),a=e.getTypeLength(n),c=`${t}_base_${r}`,l=`${t}_${n}`,u=Ru[c];if(u===void 0){switch(t){case o.COUNT_LEADING_ZEROS:{u=this._createLeadingZerosBaseLayout(c,r);break}case o.COUNT_TRAILING_ZEROS:{u=this._createTrailingZerosBaseLayout(c,r);break}case o.COUNT_ONE_BITS:{u=this._createOneBitsBaseLayout(c,r);break}}Ru[c]=u}let h=Ru[l];return h===void 0&&(h=this._createMainLayout(l,n,a,u),Ru[l]=h),A(()=>h(s))()}};Ps.COUNT_TRAILING_ZEROS="countTrailingZeros";Ps.COUNT_LEADING_ZEROS="countLeadingZeros";Ps.COUNT_ONE_BITS="countOneBits";var SR=V(Ps,Ps.COUNT_TRAILING_ZEROS).setParameterLength(1),vR=V(Ps,Ps.COUNT_LEADING_ZEROS).setParameterLength(1),wR=V(Ps,Ps.COUNT_ONE_BITS).setParameterLength(1),MR=A(([o])=>{let e=o.toUint().mul(747796405).add(2891336453),t=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return t.shiftRight(22).bitXor(t).toFloat().mul(1/2**32)}),rg=(o,e)=>cs(se(4,o.mul(he(1,o))),e),AR=(o,e)=>o.lessThan(.5)?rg(o.mul(2),e).div(2):he(1,rg(se(he(1,o),2),e).div(2)),NR=(o,e,t)=>cs(ss(cs(o,e),Ye(cs(o,e),cs(he(1,o),t))),1/e),RR=(o,e)=>Bt(rh.mul(e.mul(o).sub(1))).div(rh.mul(e.mul(o).sub(1))),Sc=class extends Be{static get type(){return"PackFloatNode"}constructor(e,t){super(),this.vectorNode=t,this.encoding=e,this.isPackFloatNode=!0}getNodeType(){return"uint"}generate(e){let t=this.vectorNode.getNodeType(e);return`${e.getFloatPackingMethod(this.encoding)}(${this.vectorNode.build(e,t)})`}},CR=V(Sc,"snorm").setParameterLength(1),ER=V(Sc,"unorm").setParameterLength(1),BR=V(Sc,"float16").setParameterLength(1),vc=class extends Be{static get type(){return"UnpackFloatNode"}constructor(e,t){super(),this.uintNode=t,this.encoding=e,this.isUnpackFloatNode=!0}getNodeType(){return"vec2"}generate(e){let t=this.uintNode.getNodeType(e);return`${e.getFloatUnpackingMethod(this.encoding)}(${this.uintNode.build(e,t)})`}},FR=V(vc,"snorm").setParameterLength(1),IR=V(vc,"unorm").setParameterLength(1),PR=V(vc,"float16").setParameterLength(1),Pi=A(([o])=>o.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),DR=A(([o])=>v(Pi(o.z.add(Pi(o.y.mul(1)))),Pi(o.z.add(Pi(o.x.mul(1)))),Pi(o.y.add(Pi(o.x.mul(1)))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),LR=A(([o,e,t])=>{let s=v(o).toVar(),i=b(1.4).toVar(),n=b(0).toVar(),r=v(s).toVar();return Me({start:b(0),end:b(3),type:"float",condition:"<="},()=>{let a=v(DR(r.mul(2))).toVar();s.addAssign(a.add(t.mul(b(.1).mul(e)))),r.mulAssign(1.8),i.mulAssign(1.5),s.mulAssign(1.2);let c=b(Pi(s.z.add(Pi(s.x.add(Pi(s.y)))))).toVar();n.addAssign(c.div(i)),r.addAssign(.14)}),n}).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"position",type:"vec3"},{name:"speed",type:"float"},{name:"time",type:"float"}]}),og=class extends H{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFn=null,this.global=!0}getNodeType(e){return this.getCandidateFn(e).shaderNode.layout.type}getCandidateFn(e){let t=this.parametersNodes,s=this._candidateFn;if(s===null){let i=null,n=-1;for(let r of this.functionNodes){let c=r.shaderNode.layout;if(c===null)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");let l=c.inputs;if(t.length===l.length){let u=0;for(let h=0;h<t.length;h++){let d=t[h],p=l[h];d.getNodeType(e)===p.type&&u++}u>n&&(i=r,n=u)}}this._candidateFn=s=i}return s}setup(e){return this.getCandidateFn(e)(...this.parametersNodes)}},UR=oe(og),ft=o=>(...e)=>UR(o,...e),Eo=j(0).setGroup(J).onRenderUpdate(o=>o.time),OR=j(0).setGroup(J).onRenderUpdate(o=>o.deltaTime),aw=j(0,"uint").setGroup(J).onRenderUpdate(o=>o.frameId),VR=(o=Eo)=>o.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5),kR=(o=Eo)=>o.fract().round(),zR=(o=Eo)=>o.add(.5).fract().mul(2).sub(1).abs(),GR=(o=Eo)=>o.fract();function WR(o,e=null){return $i(e,{getUV:typeof o=="function"?o:()=>o})}var $R=A(([o,e,t=U(.5)])=>Pc(o.sub(t),e).add(t)),qR=A(([o,e,t=U(.5)])=>{let s=o.sub(t),i=s.dot(s),r=i.mul(i).mul(e);return o.add(s.mul(r))}),HR=A(({position:o=null,horizontal:e=!0,vertical:t=!1})=>{let s;o!==null?(s=ls.toVar(),s[3][0]=o.x,s[3][1]=o.y,s[3][2]=o.z):s=ls;let i=fs.mul(s);return dc(e)&&(i[0][0]=ls[0].length(),i[0][1]=0,i[0][2]=0),dc(t)&&(i[1][0]=0,i[1][1]=ls[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,Oi.mul(i).mul(Ve)}),XR=A(([o=null])=>{let e=mh();return mh(Xx(o)).sub(e).lessThan(0).select(ci,o)}),YR=A(([o,e=Re(),t=b(0)])=>{let s=o.x,i=o.y,n=t.mod(s.mul(i)).floor(),r=n.mod(s),a=i.sub(n.add(1).div(s).ceil()),c=o.reciprocal(),l=U(r,a);return e.add(l).mul(c)}),cw=A(([o,e=null,t=null,s=b(1),i=Ve,n=zt])=>{let r=n.abs().normalize();r=r.div(r.dot(v(1)));let a=i.yz.mul(s),c=i.zx.mul(s),l=i.xy.mul(s),u=o.value,h=e!==null?e.value:u,d=t!==null?t.value:u,p=xe(u,a).mul(r.x),m=xe(h,c).mul(r.y),g=xe(d,l).mul(r.z);return Ye(p,m,g)}),jR=(...o)=>cw(...o),io=new xs,jn=new R,no=new R,Zp=new R,qa=new de,Cu=new R(0,0,-1),ei=new Te,Ha=new R,Eu=new R,Xa=new Te,Bu=new re,Nh=new bt,ZR=ci.flipX();Nh.depthTexture=new Rt(1,1);var Fu=!1,ag=class o extends ps{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||Nh.texture,ZR),this._reflectorBaseNode=e.reflector||new cg(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(this._depthNode===null){if(this._reflectorBaseNode.depth!==!0)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=new o({defaultTexture:Nh.depthTexture,reflector:this._reflectorBaseNode})}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){let e=new this.constructor(this.reflectorNode);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e._reflectorBaseNode=this._reflectorBaseNode,e}dispose(){super.dispose(),this._reflectorBaseNode.dispose()}},cg=class extends H{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();let{target:s=new tt,resolutionScale:i=1,generateMipmaps:n=!1,bounces:r=!0,depth:a=!1,samples:c=0}=t;this.textureNode=e,this.target=s,this.resolutionScale=i,t.resolution!==void 0&&(_e('ReflectorNode: The "resolution" parameter has been renamed to "resolutionScale".'),this.resolutionScale=t.resolution),this.generateMipmaps=n,this.bounces=r,this.depth=a,this.samples=c,this.updateBeforeType=r?te.RENDER:te.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new Map,this.forceUpdate=!1,this.hasOutput=!1}_updateResolution(e,t){let s=this.resolutionScale;t.getDrawingBufferSize(Bu),e.setSize(Math.round(Bu.width*s),Math.round(Bu.height*s))}setup(e){return this._updateResolution(Nh,e.renderer),super.setup(e)}dispose(){super.dispose();for(let e of this.renderTargets.values())e.dispose()}getVirtualCamera(e){let t=this.virtualCameras.get(e);return t===void 0&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return t===void 0&&(t=new bt(0,0,{type:$e,samples:this.samples}),this.generateMipmaps===!0&&(t.texture.minFilter=rb,t.texture.generateMipmaps=!0),this.depth===!0&&(t.depthTexture=new Rt),this.renderTargets.set(e,t)),t}updateBefore(e){if(this.bounces===!1&&Fu)return!1;Fu=!0;let{scene:t,camera:s,renderer:i,material:n}=e,{target:r}=this,a=this.getVirtualCamera(s),c=this.getRenderTarget(a);i.getDrawingBufferSize(Bu),this._updateResolution(c,i),no.setFromMatrixPosition(r.matrixWorld),Zp.setFromMatrixPosition(s.matrixWorld),qa.extractRotation(r.matrixWorld),jn.set(0,0,1),jn.applyMatrix4(qa),Ha.subVectors(no,Zp);let l=Ha.dot(jn)>0,u=!1;if(l===!0&&this.forceUpdate===!1){if(this.hasOutput===!1){Fu=!1;return}u=!0}Ha.reflect(jn).negate(),Ha.add(no),qa.extractRotation(s.matrixWorld),Cu.set(0,0,-1),Cu.applyMatrix4(qa),Cu.add(Zp),Eu.subVectors(no,Cu),Eu.reflect(jn).negate(),Eu.add(no),a.coordinateSystem=s.coordinateSystem,a.position.copy(Ha),a.up.set(0,1,0),a.up.applyMatrix4(qa),a.up.reflect(jn),a.lookAt(Eu),a.near=s.near,a.far=s.far,a.updateMatrixWorld(),a.projectionMatrix.copy(s.projectionMatrix),io.setFromNormalAndCoplanarPoint(jn,no),io.applyMatrix4(a.matrixWorldInverse),ei.set(io.normal.x,io.normal.y,io.normal.z,io.constant);let h=a.projectionMatrix;Xa.x=(Math.sign(ei.x)+h.elements[8])/h.elements[0],Xa.y=(Math.sign(ei.y)+h.elements[9])/h.elements[5],Xa.z=-1,Xa.w=(1+h.elements[10])/h.elements[14],ei.multiplyScalar(1/ei.dot(Xa));let d=0;h.elements[2]=ei.x,h.elements[6]=ei.y,h.elements[10]=i.coordinateSystem===Yt?ei.z-d:ei.z+1-d,h.elements[14]=ei.w,this.textureNode.value=c.texture,this.depth===!0&&(this.textureNode.getDepthNode().value=c.depthTexture),n.visible=!1;let p=i.getRenderTarget(),m=i.getMRT(),g=i.autoClear;i.setMRT(null),i.setRenderTarget(c),i.autoClear=!0;let y=t.name;t.name=(t.name||"Scene")+" [ Reflector ]",u?(i.clear(),this.hasOutput=!1):(i.render(t,a),this.hasOutput=!0),t.name=y,i.setMRT(m),i.setRenderTarget(p),i.autoClear=g,n.visible=!0,Fu=!1,this.forceUpdate=!1}get resolution(){return _e('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale}set resolution(e){_e('ReflectorNode: The "resolution" property has been renamed to "resolutionScale".'),this.resolutionScale=e}},JR=o=>new ag(o),Jp=new Gr(-1,1,1,-1,0,1),lg=class extends vs{constructor(e=!1){super();let t=e===!1?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new nt([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new nt(t,2))}},QR=new lg,Gi=class extends Zt{constructor(e=null){super(QR,e),this.camera=Jp,this.isQuadMesh=!0}async renderAsync(e){_e('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,Jp)}render(e){e.render(this,Jp)}},KR=new re,ug=class extends ps{static get type(){return"RTTNode"}constructor(e,t=null,s=null,i={type:$e}){let n=new bt(t,s,i);super(n.texture,Re()),this.isRTTNode=!0,this.node=e,this.width=t,this.height=s,this.pixelRatio=1,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this._rttNode=null,this._quadMesh=new Gi(new Ne),this.updateBeforeType=te.RENDER}get autoResize(){return this.width===null}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;let s=e*this.pixelRatio,i=t*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(this.textureNeedsUpdate===!1&&this.autoUpdate===!1)return;if(this.textureNeedsUpdate=!1,this.autoResize===!0){let i=e.getPixelRatio(),n=e.getSize(KR),r=Math.floor(n.width*i),a=Math.floor(n.height*i);(r!==this.renderTarget.width||a!==this.renderTarget.height)&&(this.renderTarget.setSize(r,a),this.textureNeedsUpdate=!0)}let t="RTT";this.node.name&&(t=this.node.name+" [ "+t+" ]"),this._quadMesh.material.fragmentNode=this._rttNode,this._quadMesh.name=t;let s=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(s)}clone(){let e=new ps(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}},lw=(o,...e)=>new ug(q(o),...e),eC=(o,...e)=>o.isSampleNode||o.isTextureNode?o:o.isPassNode?o.getTextureNode():lw(o,...e),uo=A(([o,e,t],s)=>{let i;s.renderer.coordinateSystem===Yt?(o=U(o.x,o.y.oneMinus()).mul(2).sub(1),i=Z(v(o,e),1)):i=Z(v(o.x,o.y.oneMinus(),e).mul(2).sub(1),1);let n=Z(t.mul(i));return n.xyz.div(n.w)}),tC=A(([o,e])=>{let t=e.mul(Z(o,1)),s=t.xy.div(t.w).mul(.5).add(.5).toVar();return U(s.x,s.y.oneMinus())}),sC=A(([o,e,t])=>{let s=yn(Ge(e)),i=Qe(o.mul(s)).toVar(),n=Ge(e,i).toVar(),r=Ge(e,i.sub(Qe(2,0))).toVar(),a=Ge(e,i.sub(Qe(1,0))).toVar(),c=Ge(e,i.add(Qe(1,0))).toVar(),l=Ge(e,i.add(Qe(2,0))).toVar(),u=Ge(e,i.add(Qe(0,2))).toVar(),h=Ge(e,i.add(Qe(0,1))).toVar(),d=Ge(e,i.sub(Qe(0,1))).toVar(),p=Ge(e,i.sub(Qe(0,2))).toVar(),m=Ee(he(b(2).mul(a).sub(r),n)).toVar(),g=Ee(he(b(2).mul(c).sub(l),n)).toVar(),y=Ee(he(b(2).mul(h).sub(u),n)).toVar(),x=Ee(he(b(2).mul(d).sub(p),n)).toVar(),_=uo(o,n,t).toVar(),w=m.lessThan(g).select(_.sub(uo(o.sub(U(b(1).div(s.x),0)),a,t)),_.negate().add(uo(o.add(U(b(1).div(s.x),0)),c,t))),S=y.lessThan(x).select(_.sub(uo(o.add(U(0,b(1).div(s.y))),h,t)),_.negate().add(uo(o.sub(U(0,b(1).div(s.y))),d,t)));return Ut(ki(w,S))}),i0=A(([o])=>Es(b(52.9829189).mul(Es(ds(o,U(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),Cs=A(([o,e,t])=>{let s=b(2.399963229728653),i=It(b(o).add(.5).div(b(e))),n=b(o).mul(s).add(t);return U(Rs(n),Bt(n)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]}),hg=class extends H{static get type(){return"SampleNode"}constructor(e,t=null){super(),this.callback=e,this.uvNode=t,this.isSampleNode=!0}setup(){return this.sample(Re())}sample(e){return this.callback(e)}},iC=(o,e=null)=>new hg(o,q(e)),Ds=class o extends H{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===o.OBJECT?this.updateType=te.OBJECT:e===o.MATERIAL?this.updateType=te.RENDER:e===o.BEFORE_OBJECT?this.updateBeforeType=te.OBJECT:e===o.BEFORE_MATERIAL&&(this.updateBeforeType=te.RENDER)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}};Ds.OBJECT="object";Ds.MATERIAL="material";Ds.BEFORE_OBJECT="beforeObject";Ds.BEFORE_MATERIAL="beforeMaterial";var _d=(o,e)=>new Ds(o,e).toStack(),nC=o=>_d(Ds.OBJECT,o),rC=o=>_d(Ds.MATERIAL,o),oC=o=>_d(Ds.BEFORE_OBJECT,o),aC=o=>_d(Ds.BEFORE_MATERIAL,o),dg=class extends Ai{constructor(e,t,s=Float32Array){let i=ArrayBuffer.isView(e)?e:new s(e*t);super(i,t),this.isStorageInstancedBufferAttribute=!0}},pg=class extends yt{constructor(e,t,s=Float32Array){let i=ArrayBuffer.isView(e)?e:new s(e*t);super(i,t),this.isStorageBufferAttribute=!0}},cC=(o,e="float")=>{let t,s;e.isStruct===!0?(t=e.layout.getLength(),s=Yu("float")):(t=j_(e),s=Yu(e));let i=new pg(o,t,s);return xn(i,e,o)},lC=(o,e="float")=>{let t,s;e.isStruct===!0?(t=e.layout.getLength(),s=Yu("float")):(t=j_(e),s=Yu(e));let i=new dg(o,t,s);return xn(i,e,i.count)},fg=class extends H{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}},uC=G(fg),Ya=new jt,Qp=new de,uw=j(0).setGroup(J).onRenderUpdate(({scene:o})=>o.backgroundBlurriness),mg=j(1).setGroup(J).onRenderUpdate(({scene:o})=>o.backgroundIntensity),hw=j(new de).setGroup(J).onRenderUpdate(({scene:o})=>{let e=o.background;return e!==null&&e.isTexture&&e.mapping!==tu?(Ya.copy(o.backgroundRotation),Ya.x*=-1,Ya.y*=-1,Ya.z*=-1,Qp.makeRotationFromEuler(Ya)):Qp.identity(),Qp}),gg=class extends ps{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.mipLevel=0,this.isStorageTextureNode=!0,this.access=dt.WRITE_ONLY}getInputType(){return"storageTexture"}setup(e){super.setup(e);let t=e.getNodeProperties(this);return t.storeNode=this.storeNode,t}setAccess(e){return this.access=e,this}setMipLevel(e){return this.mipLevel=e,this}generate(e,t){let s;return this.storeNode!==null?s=this.generateStore(e):s=super.generate(e,t),s}generateSnippet(e,t,s,i,n,r,a,c,l){let u=this.value;return e.generateStorageTextureLoad(u,t,s,i,r,l)}toReadWrite(){return this.setAccess(dt.READ_WRITE)}toReadOnly(){return this.setAccess(dt.READ_ONLY)}toWriteOnly(){return this.setAccess(dt.WRITE_ONLY)}generateStore(e){let t=e.getNodeProperties(this),{uvNode:s,storeNode:i,depthNode:n}=t,r=super.generate(e,"property"),a=s.build(e,this.value.is3DTexture===!0?"uvec3":"uvec2"),c=i.build(e,"vec4"),l=n?n.build(e,"int"):null,u=e.generateTextureStore(e,r,a,l,c);e.addLineFlowCode(u,this)}clone(){let e=super.clone();return e.storeNode=this.storeNode,e.mipLevel=this.mipLevel,e.access=this.access,e}},dw=oe(gg).setParameterLength(1,3),hC=(o,e,t)=>{let s;return o.isStorageTextureNode===!0?(s=o.clone(),s.uvNode=e,s.storeNode=t):s=dw(o,e,t),t!==null&&s.toStack(),s},dC=A(({texture:o,uv:e})=>{let s=v().toVar();return K(e.x.lessThan(1e-4),()=>{s.assign(v(1,0,0))}).ElseIf(e.y.lessThan(1e-4),()=>{s.assign(v(0,1,0))}).ElseIf(e.z.lessThan(1e-4),()=>{s.assign(v(0,0,1))}).ElseIf(e.x.greaterThan(1-1e-4),()=>{s.assign(v(-1,0,0))}).ElseIf(e.y.greaterThan(1-1e-4),()=>{s.assign(v(0,-1,0))}).ElseIf(e.z.greaterThan(1-1e-4),()=>{s.assign(v(0,0,-1))}).Else(()=>{let n=o.sample(e.add(v(-.01,0,0))).r.sub(o.sample(e.add(v(.01,0,0))).r),r=o.sample(e.add(v(0,-.01,0))).r.sub(o.sample(e.add(v(0,.01,0))).r),a=o.sample(e.add(v(0,0,-.01))).r.sub(o.sample(e.add(v(0,0,.01))).r);s.assign(v(n,r,a))}),s.normalize()}),yg=class extends ps{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return v(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,this.sampler===!0?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}normal(e){return dC({texture:this,uv:e})}},Td=oe(yg).setParameterLength(1,3),pC=(...o)=>Td(...o).setSampler(!1),fC=(o,e,t)=>Td(o,e).level(t),xg=class extends So{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=this.userData!==null?this.userData:e.object.userData,this.reference}},mC=(o,e,t)=>new xg(o,e,t),y_=new WeakMap,bg=class extends Be{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=te.OBJECT,this.updateAfterType=te.OBJECT,this.previousModelWorldMatrix=j(new de),this.previousProjectionMatrix=j(new de).setGroup(J),this.previousCameraViewMatrix=j(new de)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){let i=x_(s);this.previousModelWorldMatrix.value.copy(i);let n=pw(t);n.frameId!==e&&(n.frameId=e,n.previousProjectionMatrix===void 0?(n.previousProjectionMatrix=new de,n.previousCameraViewMatrix=new de,n.currentProjectionMatrix=new de,n.currentCameraViewMatrix=new de,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){x_(e).copy(e.matrixWorld)}setup(){let e=this.projectionMatrix===null?Oi:j(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(wn).mul(Ve),i=this.previousProjectionMatrix.mul(t).mul(_o),n=s.xy.div(s.w),r=i.xy.div(i.w);return he(n,r)}};function pw(o){let e=y_.get(o);return e===void 0&&(e={},y_.set(o,e)),e}function x_(o,e=0){let t=pw(o),s=t[e];return s===void 0&&(t[e]=s=new de,t[e].copy(o.matrixWorld)),s}var gC=G(bg),yC=A(([o])=>n0(o.rgb)),xC=A(([o,e=b(1)])=>e.mix(n0(o.rgb),o.rgb)),bC=A(([o,e=b(1)])=>{let t=Ye(o.r,o.g,o.b).div(3),s=o.r.max(o.g.max(o.b)),i=s.sub(t).mul(e).mul(-3);return le(o.rgb,s,i)}),_C=A(([o,e=b(1)])=>{let t=v(.57735,.57735,.57735),s=e.cos();return v(o.rgb.mul(s).add(t.cross(o.rgb).mul(e.sin()).add(t.mul(ds(t,o.rgb).mul(s.oneMinus())))))}),n0=(o,e=v(me.getLuminanceCoefficients(new R)))=>ds(o,e),TC=A(([o,e=v(1),t=v(0),s=v(1),i=b(1),n=v(me.getLuminanceCoefficients(new R,Ho))])=>{let r=o.rgb.dot(v(n)),a=ze(o.rgb.mul(e).add(t),0).toVar(),c=a.pow(s).toVar();return K(a.r.greaterThan(0),()=>{a.r.assign(c.r)}),K(a.g.greaterThan(0),()=>{a.g.assign(c.g)}),K(a.b.greaterThan(0),()=>{a.b.assign(c.b)}),a.assign(r.add(a.sub(r).mul(i))),Z(a.rgb,o.a)}),SC=A(([o,e])=>o.mul(e).floor().div(e)),Iu=null,_g=class extends wo{static get type(){return"ViewportSharedTextureNode"}constructor(e=ci,t=null){Iu===null&&(Iu=new Or),super(e,t,Iu)}getTextureForReference(){return Iu}updateReference(){return this}},vC=oe(_g).setParameterLength(0,2),Pu=new re,Rh=class extends ps{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(e){let t=e.getNodeProperties(this);return t.passNode=this.passNode,super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}},Ch=class extends Rh{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){let e=new this.constructor(this.passNode,this.textureName,this.previousTexture);return e.uvNode=this.uvNode,e.levelNode=this.levelNode,e.biasNode=this.biasNode,e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.offsetNode=this.offsetNode,e}},mi=class o extends Be{static get type(){return"PassNode"}constructor(e,t,s,i={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;let n=new Rt;n.isRenderTargetTexture=!0,n.name="depth";let r=new bt(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:$e,...i});r.texture.name="output",r.depthTexture=n,this.renderTarget=r,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:r.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=j(0),this._cameraFar=j(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=te.FRAME,this.global=!0}setResolutionScale(e){return this._resolutionScale=e,this}getResolutionScale(){return this._resolutionScale}setResolution(e){return z("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(e)}getResolution(){return z("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(e){return this._layers=e,this}getLayers(){return this._layers}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getTexture(e){let t=this._textures[e];return t===void 0&&(t=this.renderTarget.texture.clone(),t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)),t}getPreviousTexture(e){let t=this._previousTextures[e];return t===void 0&&(t=this.getTexture(e).clone(),this._previousTextures[e]=t),t}toggleTexture(e){let t=this._previousTextures[e];if(t!==void 0){let s=this._textures[e],i=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[i]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return t===void 0&&(t=new Ch(this,e),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return t===void 0&&(this._textureNodes[e]===void 0&&this.getTextureNode(e),t=new Ch(this,e,!0),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(t===void 0){let s=this._cameraNear,i=this._cameraFar;this._viewZNodes[e]=t=jx(this.getTextureNode(e),s,i)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(t===void 0){let s=this._cameraNear,i=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=xo(n,s,i)}return t}async compileAsync(e){let t=e.getRenderTarget(),s=e.getMRT();e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),await e.compileAsync(this.scene,this.camera),e.setRenderTarget(t),e.setMRT(s)}setup({renderer:e}){return this.renderTarget.samples=this.options.samples===void 0?e.samples:this.options.samples,this.renderTarget.texture.type=e.getOutputBufferType(),this.scope===o.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){let{renderer:t}=e,{scene:s}=this,i,n,r=t.getOutputRenderTarget();r&&r.isXRRenderTarget===!0?(n=1,i=t.xr.getCamera(),t.xr.updateCamera(i),Pu.set(r.width,r.height)):(i=this.camera,n=t.getPixelRatio(),t.getSize(Pu)),this._pixelRatio=n,this.setSize(Pu.width,Pu.height);let a=t.getRenderTarget(),c=t.getMRT(),l=t.autoClear,u=t.transparent,h=t.opaque,d=i.layers.mask,p=t.contextNode,m=s.overrideMaterial;this._cameraNear.value=i.near,this._cameraFar.value=i.far,this._layers!==null&&(i.layers.mask=this._layers.mask);for(let y in this._previousTextures)this.toggleTexture(y);this.overrideMaterial!==null&&(s.overrideMaterial=this.overrideMaterial),t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.autoClear=!0,t.transparent=this.transparent,t.opaque=this.opaque,this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:$i({...t.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),t.contextNode=this._contextNodeCache.context);let g=s.name;s.name=this.name?this.name:s.name,t.render(s,i),s.name=g,s.overrideMaterial=m,t.setRenderTarget(a),t.setMRT(c),t.autoClear=l,t.transparent=u,t.opaque=h,t.contextNode=p,i.layers.mask=d}setSize(e,t){this._width=e,this._height=t;let s=Math.floor(this._width*this._pixelRatio*this._resolutionScale),i=Math.floor(this._height*this._pixelRatio*this._resolutionScale);this.renderTarget.setSize(s,i),this._scissor!==null&&this.renderTarget.scissor.copy(this._scissor),this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport)}setScissor(e,t,s,i){e===null?this._scissor=null:(this._scissor===null&&(this._scissor=new Te),e.isVector4?this._scissor.copy(e):this._scissor.set(e,t,s,i),this._scissor.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setViewport(e,t,s,i){e===null?this._viewport=null:(this._viewport===null&&(this._viewport=new Te),e.isVector4?this._viewport.copy(e):this._viewport.set(e,t,s,i),this._viewport.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}};mi.COLOR="color";mi.DEPTH="depth";var wC=(o,e,t)=>new mi(mi.COLOR,o,e,t),MC=(o,e)=>new Rh(o,e),AC=(o,e,t)=>new mi(mi.DEPTH,o,e,t),Tg=class extends mi{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,i,n){super(mi.COLOR,e,t),this.colorNode=s,this.thicknessNode=i,this.alphaNode=n,this._materialCache=new WeakMap,this.name="Outline Pass"}updateBefore(e){let{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction((i,n,r,a,c,l,u,h)=>{if((c.isMeshToonMaterial||c.isMeshToonNodeMaterial)&&c.wireframe===!1){let d=this._getOutlineMaterial(c);t.renderObject(i,n,r,a,d,l,u,h)}t.renderObject(i,n,r,a,c,l,u,h)}),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){let e=new Ne;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=rt;let t=zt.negate(),s=Oi.mul(wn),i=b(1),n=s.mul(Z(Ve,1)),r=s.mul(Z(Ve.add(t),1)),a=Ut(n.sub(r));return e.vertexNode=n.add(a.mul(this.thicknessNode).mul(n.w).mul(i)),e.colorNode=Z(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return t===void 0&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}},NC=(o,e,t=new ge(0,0,0),s=.003,i=1)=>new Tg(o,e,q(t),q(s),q(i)),fw=A(([o,e])=>o.mul(e).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),mw=A(([o,e])=>(o=o.mul(e),o.div(o.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),gw=A(([o,e])=>{o=o.mul(e),o=o.sub(.004).max(0);let t=o.mul(o.mul(6.2).add(.5)),s=o.mul(o.mul(6.2).add(1.7)).add(.06);return t.div(s).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),RC=A(([o])=>{let e=o.mul(o.add(.0245786)).sub(90537e-9),t=o.mul(o.add(.432951).mul(.983729)).add(.238081);return e.div(t)}),yw=A(([o,e])=>{let t=at(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=at(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return o=o.mul(e).div(.6),o=t.mul(o),o=RC(o),o=s.mul(o),o.clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),CC=at(v(1.6605,-.1246,-.0182),v(-.5876,1.1329,-.1006),v(-.0728,-.0083,1.1187)),EC=at(v(.6274,.0691,.0164),v(.3293,.9195,.088),v(.0433,.0113,.8956)),BC=A(([o])=>{let e=v(o).toVar(),t=v(e.mul(e)).toVar(),s=v(t.mul(t)).toVar();return b(15.5).mul(s.mul(t)).sub(se(40.14,s.mul(e))).add(se(31.96,s).sub(se(6.868,t.mul(e))).add(se(.4298,t).add(se(.1191,e).sub(.00232))))}),xw=A(([o,e])=>{let t=v(o).toVar(),s=at(v(.856627153315983,.137318972929847,.11189821299995),v(.0951212405381588,.761241990602591,.0767994186031903),v(.0482516061458583,.101439036467562,.811302368396859)),i=at(v(1.1271005818144368,-.1413297634984383,-.14132976349843826),v(-.11060664309660323,1.157823702216272,-.11060664309660294),v(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=b(-12.47393),r=b(4.026069);return t.mulAssign(e),t.assign(EC.mul(t)),t.assign(s.mul(t)),t.assign(ze(t,1e-10)),t.assign(ri(t)),t.assign(t.sub(n).div(r.sub(n))),t.assign(Bs(t,0,1)),t.assign(BC(t)),t.assign(i.mul(t)),t.assign(cs(ze(v(0),t),v(2.2))),t.assign(CC.mul(t)),t.assign(Bs(t,0,1)),t}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),bw=A(([o,e])=>{let t=b(.76),s=b(.15);o=o.mul(e);let i=Vt(o.r,Vt(o.g,o.b)),n=vt(i.lessThan(.08),i.sub(se(6.25,i.mul(i))),.04);o.subAssign(n);let r=ze(o.r,ze(o.g,o.b));K(r.lessThan(t),()=>o);let a=he(1,t),c=he(1,a.mul(a).div(r.add(a.sub(t))));o.mulAssign(c.div(r));let l=he(1,ss(1,s.mul(r.sub(c)).add(1)));return le(o,v(c),l)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),He=class extends H{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=s}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){let t=this.getIncludes(e);for(let i of t)i.build(e);let s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}},Sd=oe(He).setParameterLength(1,3),FC=(o,e)=>Sd(o,e,"js"),IC=(o,e)=>Sd(o,e,"wgsl"),PC=(o,e)=>Sd(o,e,"glsl"),Eh=class extends He{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){let s=this.getNodeType(e);return e.getStructTypeNode(s).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){let t=e.getDataFromNode(this),s=t.nodeFunction;return s===void 0&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);let s=this.getNodeFunction(e),i=s.name,n=s.type,r=e.getCodeFromNode(this,n);i!==""&&(r.name=i);let a=e.getPropertyName(r),c=this.getNodeFunction(e).getCode(a);return r.code=c+`
|
|
`,t==="property"?a:e.format(`${a}()`,n,t)}},_w=(o,e=[],t="")=>{for(let n=0;n<e.length;n++){let r=e[n];typeof r=="function"&&(e[n]=r.functionNode)}let s=new Eh(o,e,t),i=(...n)=>s.call(...n);return i.functionNode=s,i},DC=(o,e)=>_w(o,e,"glsl"),LC=(o,e)=>_w(o,e,"wgsl");function r0(o){let e,t=o.context.getViewZ;return t!==void 0&&(e=t(this)),(e||qe.z).negate()}var Tw=A(([o,e],t)=>{let s=r0(t);return Fs(o,e,s)}),Sw=A(([o],e)=>{let t=r0(e);return o.mul(o,t,t).negate().exp().oneMinus()}),UC=A(([o,e],t)=>{let s=r0(t),n=e.sub(li.y).max(0).toConst().mul(s).toConst();return o.mul(o,n,n).negate().exp().oneMinus()}),Sg=A(([o,e])=>Z(e.toFloat().mix(fo.rgb,o.toVec3()),fo.a)),Zn=null,Jn=null,vg=class extends H{static get type(){return"RangeNode"}constructor(e=b(),t=b()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){let t=this.getConstNode(this.minNode),s=this.getConstNode(this.maxNode),i=e.getTypeLength(fn(t.value)),n=e.getTypeLength(fn(s.value));return i>n?i:n}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}getConstNode(e){let t=null;if(e.traverse(s=>{s.isConstNode===!0&&(t=s)}),t===null)throw new dh('THREE.TSL: No "ConstNode" found in node graph.',this.stackTrace);return t}setup(e){let t=e.object,s=null;if(t.count>1){let i=this.getConstNode(this.minNode),n=this.getConstNode(this.maxNode),r=i.value,a=n.value,c=e.getTypeLength(fn(r)),l=e.getTypeLength(fn(a));Zn=Zn||new Te,Jn=Jn||new Te,Zn.setScalar(0),Jn.setScalar(0),c===1?Zn.setScalar(r):r.isColor?Zn.set(r.r,r.g,r.b,1):Zn.set(r.x,r.y,r.z||0,r.w||0),l===1?Jn.setScalar(a):a.isColor?Jn.set(a.r,a.g,a.b,1):Jn.set(a.x,a.y,a.z||0,a.w||0);let u=4,h=u*t.count,d=new Float32Array(h);for(let g=0;g<h;g++){let y=g%u,x=Zn.getComponent(y),_=Jn.getComponent(y);d[g]=Va.lerp(x,_,Math.random())}let p=this.getNodeType(e);if(t.count*4*4<=e.getUniformBufferLimit())s=Fc(d,"vec4",t.count).element(ui).convert(p);else{let g=new Ai(d,4);e.geometry.setAttribute("__range"+this.id,g),s=ch(g).convert(p)}}else s=b(0);return s}},OC=oe(vg).setParameterLength(2),wg=class extends H{static get type(){return"ComputeBuiltinNode"}constructor(e,t){super(t),this._builtinName=e}getHash(e){return this.getBuiltinName(e)}getNodeType(){return this.nodeType}setBuiltinName(e){return this._builtinName=e,this}getBuiltinName(){return this._builtinName}hasBuiltin(e){return e.hasBuiltin(this._builtinName)}generate(e,t){let s=this.getBuiltinName(e),i=this.getNodeType(e);return e.shaderStage==="compute"?e.format(s,i,t):(z(`ComputeBuiltinNode: Compute built-in value ${s} can not be accessed in the ${e.shaderStage} stage`),e.generateConst(i))}serialize(e){super.serialize(e),e.global=this.global,e._builtinName=this._builtinName}deserialize(e){super.deserialize(e),this.global=e.global,this._builtinName=e._builtinName}},Dc=(o,e)=>new wg(o,e),VC=Dc("numWorkgroups","uvec3"),kC=Dc("workgroupId","uvec3"),zC=Dc("globalId","uvec3"),GC=Dc("localId","uvec3"),WC=Dc("subgroupSize","uint"),Mg=class extends H{constructor(e){super(),this.scope=e}generate(e){let{scope:t}=this,{renderer:s}=e;s.backend.isWebGLBackend===!0?e.addFlowCode(` // ${t}Barrier
|
|
`):e.addLineFlowCode(`${t}Barrier()`,this)}},o0=oe(Mg),$C=()=>o0("workgroup").toStack(),qC=()=>o0("storage").toStack(),HC=()=>o0("texture").toStack(),Ag=class extends Vi{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s,i=e.context.assign;if(s=super.generate(e),i!==!0){let n=this.getNodeType(e);s=e.format(s,n,t)}return s}},Ng=class extends H{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.elementType=t,this.scope=e,this.name=""}setName(e){return this.name=e,this}label(e){return z('TSL: "label()" has been deprecated. Use "setName()" instead.',new ke),this.setName(e)}setScope(e){return this.scope=e,this}getElementType(){return this.elementType}getInputType(){return`${this.scope}Array`}element(e){return new Ag(this,e)}generate(e){let t=this.name!==""?this.name:`${this.scope}Array_${this.id}`;return e.getScopedArray(t,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}},XC=(o,e)=>new Ng("Workgroup",o,e),Ze=class extends H{static get type(){return"AtomicFunctionNode"}constructor(e,t,s){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){let t=e.getNodeProperties(this),s=t.parents,i=this.method,n=this.getNodeType(e),r=this.getInputType(e),a=this.pointerNode,c=this.valueNode,l=[];l.push(`&${a.build(e,r)}`),c!==null&&l.push(c.build(e,r));let u=`${e.getMethod(i,n)}( ${l.join(", ")} )`;if(s?s.length===1&&s[0].isStackNode===!0:!1)e.addLineFlowCode(u,this);else return t.constNode===void 0&&(t.constNode=ts(u,n).toConst()),t.constNode.build(e)}};Ze.ATOMIC_LOAD="atomicLoad";Ze.ATOMIC_STORE="atomicStore";Ze.ATOMIC_ADD="atomicAdd";Ze.ATOMIC_SUB="atomicSub";Ze.ATOMIC_MAX="atomicMax";Ze.ATOMIC_MIN="atomicMin";Ze.ATOMIC_AND="atomicAnd";Ze.ATOMIC_OR="atomicOr";Ze.ATOMIC_XOR="atomicXor";var YC=oe(Ze),yi=(o,e,t)=>YC(o,e,t).toStack(),jC=o=>yi(Ze.ATOMIC_LOAD,o,null),ZC=(o,e)=>yi(Ze.ATOMIC_STORE,o,e),JC=(o,e)=>yi(Ze.ATOMIC_ADD,o,e),QC=(o,e)=>yi(Ze.ATOMIC_SUB,o,e),KC=(o,e)=>yi(Ze.ATOMIC_MAX,o,e),eE=(o,e)=>yi(Ze.ATOMIC_MIN,o,e),tE=(o,e)=>yi(Ze.ATOMIC_AND,o,e),sE=(o,e)=>yi(Ze.ATOMIC_OR,o,e),iE=(o,e)=>yi(Ze.ATOMIC_XOR,o,e),$=class o extends Be{static get type(){return"SubgroupFunctionNode"}constructor(e,t=null,s=null){super(),this.method=e,this.aNode=t,this.bNode=s}getInputType(e){let t=this.aNode?this.aNode.getNodeType(e):null,s=this.bNode?this.bNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(s)?0:e.getTypeLength(s);return i>n?t:s}getNodeType(e){let t=this.method;return t===o.SUBGROUP_ELECT?"bool":t===o.SUBGROUP_BALLOT?"uvec4":this.getInputType(e)}generate(e,t){let s=this.method,i=this.getNodeType(e),n=this.getInputType(e),r=this.aNode,a=this.bNode,c=[];if(s===o.SUBGROUP_BROADCAST||s===o.SUBGROUP_SHUFFLE||s===o.QUAD_BROADCAST){let u=a.getNodeType(e);c.push(r.build(e,i),a.build(e,u==="float"?"int":i))}else s===o.SUBGROUP_SHUFFLE_XOR||s===o.SUBGROUP_SHUFFLE_DOWN||s===o.SUBGROUP_SHUFFLE_UP?c.push(r.build(e,i),a.build(e,"uint")):(r!==null&&c.push(r.build(e,n)),a!==null&&c.push(a.build(e,n)));let l=c.length===0?"()":`( ${c.join(", ")} )`;return e.format(`${e.getMethod(s,i)}${l}`,i,t)}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}};$.SUBGROUP_ELECT="subgroupElect";$.SUBGROUP_BALLOT="subgroupBallot";$.SUBGROUP_ADD="subgroupAdd";$.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd";$.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd";$.SUBGROUP_MUL="subgroupMul";$.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul";$.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul";$.SUBGROUP_AND="subgroupAnd";$.SUBGROUP_OR="subgroupOr";$.SUBGROUP_XOR="subgroupXor";$.SUBGROUP_MIN="subgroupMin";$.SUBGROUP_MAX="subgroupMax";$.SUBGROUP_ALL="subgroupAll";$.SUBGROUP_ANY="subgroupAny";$.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst";$.QUAD_SWAP_X="quadSwapX";$.QUAD_SWAP_Y="quadSwapY";$.QUAD_SWAP_DIAGONAL="quadSwapDiagonal";$.SUBGROUP_BROADCAST="subgroupBroadcast";$.SUBGROUP_SHUFFLE="subgroupShuffle";$.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor";$.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp";$.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown";$.QUAD_BROADCAST="quadBroadcast";var nE=V($,$.SUBGROUP_ELECT).setParameterLength(0),rE=V($,$.SUBGROUP_BALLOT).setParameterLength(1),oE=V($,$.SUBGROUP_ADD).setParameterLength(1),aE=V($,$.SUBGROUP_INCLUSIVE_ADD).setParameterLength(1),cE=V($,$.SUBGROUP_EXCLUSIVE_AND).setParameterLength(1),lE=V($,$.SUBGROUP_MUL).setParameterLength(1),uE=V($,$.SUBGROUP_INCLUSIVE_MUL).setParameterLength(1),hE=V($,$.SUBGROUP_EXCLUSIVE_MUL).setParameterLength(1),dE=V($,$.SUBGROUP_AND).setParameterLength(1),pE=V($,$.SUBGROUP_OR).setParameterLength(1),fE=V($,$.SUBGROUP_XOR).setParameterLength(1),mE=V($,$.SUBGROUP_MIN).setParameterLength(1),gE=V($,$.SUBGROUP_MAX).setParameterLength(1),yE=V($,$.SUBGROUP_ALL).setParameterLength(0),xE=V($,$.SUBGROUP_ANY).setParameterLength(0),bE=V($,$.SUBGROUP_BROADCAST_FIRST).setParameterLength(2),_E=V($,$.QUAD_SWAP_X).setParameterLength(1),TE=V($,$.QUAD_SWAP_Y).setParameterLength(1),SE=V($,$.QUAD_SWAP_DIAGONAL).setParameterLength(1),vE=V($,$.SUBGROUP_BROADCAST).setParameterLength(2),wE=V($,$.SUBGROUP_SHUFFLE).setParameterLength(2),ME=V($,$.SUBGROUP_SHUFFLE_XOR).setParameterLength(2),AE=V($,$.SUBGROUP_SHUFFLE_UP).setParameterLength(2),NE=V($,$.SUBGROUP_SHUFFLE_DOWN).setParameterLength(2),RE=V($,$.QUAD_BROADCAST).setParameterLength(1),Du;function vd(o){Du=Du||new WeakMap;let e=Du.get(o);return e===void 0&&Du.set(o,e={}),e}function wd(o){let e=vd(o);return e.shadowMatrix||(e.shadowMatrix=j("mat4").setGroup(J).onRenderUpdate(t=>((o.castShadow!==!0||t.renderer.shadowMap.enabled===!1)&&(o.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(o.shadow.camera.coordinateSystem=t.camera.coordinateSystem,o.shadow.camera.updateProjectionMatrix()),o.shadow.updateMatrices(o)),o.shadow.matrix)))}function vw(o,e=li){let t=wd(o).mul(e);return t.xyz.div(t.w)}function a0(o){let e=vd(o);return e.position||(e.position=j(new R).setGroup(J).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.matrixWorld)))}function ww(o){let e=vd(o);return e.targetPosition||(e.targetPosition=j(new R).setGroup(J).onRenderUpdate((t,s)=>s.value.setFromMatrixPosition(o.target.matrixWorld)))}function c0(o){let e=vd(o);return e.viewPosition||(e.viewPosition=j(new R).setGroup(J).onRenderUpdate(({camera:t},s)=>{s.value=s.value||new R,s.value.setFromMatrixPosition(o.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)}))}var l0=o=>fs.transformDirection(a0(o).sub(ww(o))),CE=o=>o.sort((e,t)=>e.id-t.id),EE=(o,e)=>{for(let t of e)if(t.isAnalyticLightNode&&t.light.id===o)return t;return null},Kp=new WeakMap,ja=[],wc=class extends H{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Ui("vec3","totalDiffuse"),this.totalSpecularNode=Ui("vec3","totalSpecular"),this.outgoingLightNode=Ui("vec3","outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}customCacheKey(){let e=this._lights;for(let s=0;s<e.length;s++){let i=e[s];if(ja.push(i.id),ja.push(i.castShadow?1:0),i.isSpotLight===!0){let n=i.map!==null?i.map.id:-1,r=i.colorNode?i.colorNode.getCacheKey():-1;ja.push(n,r)}}let t=Ec(ja);return ja.length=0,t}getHash(e){if(this._lightNodesHash===null){this._lightNodes===null&&this.setupLightsNode(e);let t=[];for(let s of this._lightNodes)t.push(s.getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){let t=e.getNodeProperties(this);for(let s of t.nodes)s.build(e);t.outputNode.build(e)}setupLightsNode(e){let t=[],s=this._lightNodes,i=CE(this._lights),n=e.renderer.library;for(let r of i)if(r.isNode)t.push(q(r));else{let a=null;if(s!==null&&(a=EE(r.id,s)),a===null){let c=n.getLightNodeClass(r.constructor);if(c===null){z(`LightsNode.setupNodeLights: Light node not found for ${r.constructor.name}`);continue}let l=null;Kp.has(r)?l=Kp.get(r):(l=new c(r),Kp.set(r,l)),t.push(l)}}this._lightNodes=t}setupDirectLight(e,t,s){let{lightingModel:i,reflectedLight:n}=e.context;i.direct({...s,lightNode:t,reflectedLight:n},e)}setupDirectRectAreaLight(e,t,s){let{lightingModel:i,reflectedLight:n}=e.context;i.directRectArea({...s,lightNode:t,reflectedLight:n},e)}setupLights(e,t){for(let s of t)s.build(e)}getLightNodes(e){return this._lightNodes===null&&this.setupLightsNode(e),this._lightNodes}setup(e){let t=e.lightsNode;e.lightsNode=this;let s=this.outgoingLightNode,i=e.context,n=i.lightingModel,r=e.getNodeProperties(this);if(n){let{totalDiffuseNode:a,totalSpecularNode:c}=this;i.outgoingLight=s;let l=e.addStack();r.nodes=l.nodes,n.start(e);let{backdrop:u,backdropAlpha:h}=i,{directDiffuse:d,directSpecular:p,indirectDiffuse:m,indirectSpecular:g}=i.reflectedLight,y=d.add(m);u!==null&&(h!==null?y=v(h.mix(y,u)):y=v(u)),a.assign(y),c.assign(p.add(g)),s.assign(a.add(c)),n.finish(e),s=s.bypass(e.removeStack())}else r.nodes=[];return e.lightsNode=t,s}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}},BE=(o=[])=>new wc().setLights(o),Rg=class extends H{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=te.RENDER,this.isShadowBaseNode=!0}setupShadowPosition({context:e,material:t}){u0.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||li)}},u0=Ui("vec3","shadowPositionWorld");function h0(o,e={}){return e.toneMapping=o.toneMapping,e.toneMappingExposure=o.toneMappingExposure,e.outputColorSpace=o.outputColorSpace,e.renderTarget=o.getRenderTarget(),e.activeCubeFace=o.getActiveCubeFace(),e.activeMipmapLevel=o.getActiveMipmapLevel(),e.renderObjectFunction=o.getRenderObjectFunction(),e.pixelRatio=o.getPixelRatio(),e.mrt=o.getMRT(),e.clearColor=o.getClearColor(e.clearColor||new ge),e.clearAlpha=o.getClearAlpha(),e.autoClear=o.autoClear,e.scissorTest=o.getScissorTest(),e}function Mw(o,e){return e=h0(o,e),o.setMRT(null),o.setRenderObjectFunction(null),o.setClearColor(0,1),o.autoClear=!0,e}function Aw(o,e){o.toneMapping=e.toneMapping,o.toneMappingExposure=e.toneMappingExposure,o.outputColorSpace=e.outputColorSpace,o.setRenderTarget(e.renderTarget,e.activeCubeFace,e.activeMipmapLevel),o.setRenderObjectFunction(e.renderObjectFunction),o.setPixelRatio(e.pixelRatio),o.setMRT(e.mrt),o.setClearColor(e.clearColor,e.clearAlpha),o.autoClear=e.autoClear,o.setScissorTest(e.scissorTest)}function d0(o,e={}){return e.background=o.background,e.backgroundNode=o.backgroundNode,e.overrideMaterial=o.overrideMaterial,e}function Nw(o,e){return e=d0(o,e),o.background=null,o.backgroundNode=null,o.overrideMaterial=null,e}function Rw(o,e){o.background=e.background,o.backgroundNode=e.backgroundNode,o.overrideMaterial=e.overrideMaterial}function FE(o,e,t={}){return t=h0(o,t),t=d0(e,t),t}function Cw(o,e,t){return t=Mw(o,t),t=Nw(e,t),t}function Ew(o,e,t){Aw(o,t),Rw(e,t)}var p0=Object.freeze({__proto__:null,resetRendererAndSceneState:Cw,resetRendererState:Mw,resetSceneState:Nw,restoreRendererAndSceneState:Ew,restoreRendererState:Aw,restoreSceneState:Rw,saveRendererAndSceneState:FE,saveRendererState:h0,saveSceneState:d0}),Bh=new WeakMap,Bw=A(({depthTexture:o,shadowCoord:e,depthLayer:t})=>{let s=xe(o,e.xy).setName("t_basic");return o.isArrayTexture&&(s=s.depth(t)),s.compare(e.z)}),Fw=A(({depthTexture:o,shadowCoord:e,shadow:t,depthLayer:s})=>{let i=(u,h)=>{let d=xe(o,u);return o.isArrayTexture&&(d=d.depth(s)),d.compare(h)},n=Ie("mapSize","vec2",t).setGroup(J),r=Ie("radius","float",t).setGroup(J),a=U(1).div(n),c=r.mul(a.x),l=i0(gr.xy).mul(6.28318530718);return Ye(i(e.xy.add(Cs(0,5,l).mul(c)),e.z),i(e.xy.add(Cs(1,5,l).mul(c)),e.z),i(e.xy.add(Cs(2,5,l).mul(c)),e.z),i(e.xy.add(Cs(3,5,l).mul(c)),e.z),i(e.xy.add(Cs(4,5,l).mul(c)),e.z)).mul(1/5)}),Iw=A(({depthTexture:o,shadowCoord:e,shadow:t,depthLayer:s})=>{let i=(h,d)=>{let p=xe(o,h);return o.isArrayTexture&&(p=p.depth(s)),p.compare(d)},n=Ie("mapSize","vec2",t).setGroup(J),r=U(1).div(n),a=r.x,c=r.y,l=e.xy,u=Es(l.mul(n).add(.5));return l.subAssign(u.mul(r)),Ye(i(l,e.z),i(l.add(U(a,0)),e.z),i(l.add(U(0,c)),e.z),i(l.add(r),e.z),le(i(l.add(U(a.negate(),0)),e.z),i(l.add(U(a.mul(2),0)),e.z),u.x),le(i(l.add(U(a.negate(),c)),e.z),i(l.add(U(a.mul(2),c)),e.z),u.x),le(i(l.add(U(0,c.negate())),e.z),i(l.add(U(0,c.mul(2))),e.z),u.y),le(i(l.add(U(a,c.negate())),e.z),i(l.add(U(a,c.mul(2))),e.z),u.y),le(le(i(l.add(U(a.negate(),c.negate())),e.z),i(l.add(U(a.mul(2),c.negate())),e.z),u.x),le(i(l.add(U(a.negate(),c.mul(2))),e.z),i(l.add(U(a.mul(2),c.mul(2))),e.z),u.x),u.y)).mul(1/9)}),Pw=A(({depthTexture:o,shadowCoord:e,depthLayer:t},s)=>{let i=xe(o).sample(e.xy);o.isArrayTexture&&(i=i.depth(t)),i=i.rg;let n=i.x,r=ze(1e-7,i.y.mul(i.y)),a=s.renderer.reversedDepthBuffer?ur(n,e.z):ur(e.z,n),c=b(1).toVar();return K(a.notEqual(1),()=>{let l=e.z.sub(n),u=r.div(r.add(l.mul(l)));u=Bs(he(u,.3).div(.65)),c.assign(ze(a,u))}),c}),Dw=o=>{let e=Bh.get(o);return e===void 0&&(e=new Ne,e.colorNode=Z(0,0,0,1),e.isShadowPassMaterial=!0,e.name="ShadowMaterial",e.blending=qs,e.fog=!1,Bh.set(o,e)),e},Lw=o=>{let e=Bh.get(o);e!==void 0&&(e.dispose(),Bh.delete(o))},b_=new pi,ro=[],Uw=(o,e,t,s)=>{ro[0]=o,ro[1]=e;let i=b_.get(ro);return(i===void 0||i.shadowType!==t||i.useVelocity!==s)&&(i=(n,r,a,c,l,u,...h)=>{(n.castShadow===!0||n.receiveShadow&&t===Wr)&&(s&&(Z_(n).useVelocity=!0),n.onBeforeShadow(o,n,a,e.camera,c,r.overrideMaterial,u),o.renderObject(n,r,a,c,l,u,...h),n.onAfterShadow(o,n,a,e.camera,c,r.overrideMaterial,u))},i.shadowType=t,i.useVelocity=s,b_.set(ro,i)),ro[0]=null,ro[1]=null,i},IE=A(({samples:o,radius:e,size:t,shadowPass:s,depthLayer:i})=>{let n=b(0).toVar("meanVertical"),r=b(0).toVar("squareMeanVertical"),a=o.lessThanEqual(b(1)).select(b(0),b(2).div(o.sub(1))),c=o.lessThanEqual(b(1)).select(b(0),b(-1));Me({start:T(0),end:T(o),type:"int",condition:"<"},({i:u})=>{let h=c.add(b(u).mul(a)),d=s.sample(Ye(gr.xy,U(0,h).mul(e)).div(t));s.value.isArrayTexture&&(d=d.depth(i)),d=d.x,n.addAssign(d),r.addAssign(d.mul(d))}),n.divAssign(o),r.divAssign(o);let l=It(r.sub(n.mul(n)).max(0));return U(n,l)}),PE=A(({samples:o,radius:e,size:t,shadowPass:s,depthLayer:i})=>{let n=b(0).toVar("meanHorizontal"),r=b(0).toVar("squareMeanHorizontal"),a=o.lessThanEqual(b(1)).select(b(0),b(2).div(o.sub(1))),c=o.lessThanEqual(b(1)).select(b(0),b(-1));Me({start:T(0),end:T(o),type:"int",condition:"<"},({i:u})=>{let h=c.add(b(u).mul(a)),d=s.sample(Ye(gr.xy,U(h,0).mul(e)).div(t));s.value.isArrayTexture&&(d=d.depth(i)),n.addAssign(d.x),r.addAssign(Ye(d.y.mul(d.y),d.x.mul(d.x)))}),n.divAssign(o),r.divAssign(o);let l=It(r.sub(n.mul(n)).max(0));return U(n,l)}),DE=[Bw,Fw,Iw,Pw],ef,Lu=new Gi,Fh=class extends Rg{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:s,shadowCoord:i,shadow:n,depthLayer:r}){let a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),c=t({depthTexture:s,shadowCoord:i,shadow:n,depthLayer:r});return a.select(c,b(1))}setupShadowCoord(e,t){let{shadow:s}=this,{renderer:i}=e,n=s.biasNode||Ie("bias","float",s).setGroup(J),r=t,a;if(s.camera.isOrthographicCamera||i.logarithmicDepthBuffer!==!0)r=r.xyz.div(r.w),a=r.z;else{let c=r.w;r=r.xy.div(c);let l=Ie("near","float",s.camera).setGroup(J),u=Ie("far","float",s.camera).setGroup(J);a=Zx(c.negate(),l,u)}return r=v(r.x,r.y.oneMinus(),i.reversedDepthBuffer?a.sub(n):a.add(n)),r}getShadowFilterFn(e){return DE[e]}setupRenderTarget(e,t){let s=new Rt(e.mapSize.width,e.mapSize.height);s.name="ShadowDepthTexture",s.compareFunction=t.renderer.reversedDepthBuffer?Yn:Jr;let i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=s,{shadowMap:i,depthTexture:s}}setupShadow(e){let{renderer:t,camera:s}=e,{light:i,shadow:n}=this,{depthTexture:r,shadowMap:a}=this.setupRenderTarget(n,e),c=t.shadowMap.type,l=t.hasCompatibility(Ys.TEXTURE_COMPARE);if((c===ap||c===Y0)&&l?(r.minFilter=ct,r.magFilter=ct):(r.minFilter=Ue,r.magFilter=Ue),n.camera.coordinateSystem=s.coordinateSystem,n.camera.updateProjectionMatrix(),c===Wr&&n.isPointLightShadow!==!0){r.compareFunction=null,a.depth>1?(a._vsmShadowMapVertical||(a._vsmShadowMapVertical=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ms,type:$e,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=a._vsmShadowMapVertical,a._vsmShadowMapHorizontal||(a._vsmShadowMapHorizontal=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ms,type:$e,depth:a.depth,depthBuffer:!1}),a._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=a._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ms,type:$e,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:Ms,type:$e,depthBuffer:!1}));let S=xe(r);r.isArrayTexture&&(S=S.depth(this.depthLayer));let E=xe(this.vsmShadowMapVertical.texture);r.isArrayTexture&&(E=E.depth(this.depthLayer));let B=Ie("blurSamples","float",n).setGroup(J),N=Ie("radius","float",n).setGroup(J),C=Ie("mapSize","vec2",n).setGroup(J),I=this.vsmMaterialVertical||(this.vsmMaterialVertical=new Ne);I.fragmentNode=IE({samples:B,radius:N,size:C,shadowPass:S,depthLayer:this.depthLayer}).context(e.getSharedContext()),I.name="VSMVertical",I=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new Ne),I.fragmentNode=PE({samples:B,radius:N,size:C,shadowPass:E,depthLayer:this.depthLayer}).context(e.getSharedContext()),I.name="VSMHorizontal"}let u=Ie("intensity","float",n).setGroup(J),h=Ie("normalBias","float",n).setGroup(J),d=wd(i).mul(u0.add(Mn.mul(h))),p=this.setupShadowCoord(e,d),m=n.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(m===null)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");let g=c===Wr&&n.isPointLightShadow!==!0?this.vsmShadowMapHorizontal.texture:r,y=this.setupShadowFilter(e,{filterFn:m,shadowTexture:a.texture,depthTexture:g,shadowCoord:p,shadow:n,depthLayer:this.depthLayer}),x;t.shadowMap.transmitted===!0&&(a.texture.isCubeTexture?x=Ft(a.texture,p.xyz):(x=xe(a.texture,p),r.isArrayTexture&&(x=x.depth(this.depthLayer))));let _;x?_=le(1,y.rgb.mix(x,1),u.mul(x.a)).toVar():_=le(1,y,u).toVar(),this.shadowMap=a,this.shadow.map=a;let w=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return x&&_.toInspector(`${w} / Color`,()=>this.shadowMap.texture.isCubeTexture?Ft(this.shadowMap.texture):xe(this.shadowMap.texture)),_.toInspector(`${w} / Depth`,()=>this.shadowMap.texture.isCubeTexture?Ft(this.shadowMap.texture).r.oneMinus():Ge(this.shadowMap.depthTexture,Re().mul(yn(xe(this.shadowMap.depthTexture)))).r.oneMinus())}setup(e){if(e.renderer.shadowMap.enabled!==!1)return A(()=>{let t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let s=this._node;return this.setupShadowPosition(e),s===null&&(this._node=s=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(s=e.material.receivedShadowNode(s)),s})()}renderShadow(e){let{shadow:t,shadowMap:s,light:i}=this,{renderer:n,scene:r}=e;t.updateMatrices(i),s.setSize(t.mapSize.width,t.mapSize.height,s.depth);let a=r.name;r.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,n.render(r,t.camera),r.name=a}updateShadow(e){let{shadowMap:t,light:s,shadow:i}=this,{renderer:n,scene:r,camera:a}=e,c=n.shadowMap.type,l=t.depthTexture.version;this._depthVersionCached=l;let u=i.camera.layers.mask;(i.camera.layers.mask&4294967294)===0&&(i.camera.layers.mask=a.layers.mask);let h=n.getRenderObjectFunction(),d=n.getMRT(),p=d?d.has("velocity"):!1;ef=Cw(n,r,ef),r.overrideMaterial=Dw(s),n.setRenderObjectFunction(Uw(n,i,c,p)),n.setClearColor(0,0),n.setRenderTarget(t),this.renderShadow(e),n.setRenderObjectFunction(h),c===Wr&&i.isPointLightShadow!==!0&&this.vsmPass(n),i.camera.layers.mask=u,Ew(n,r,ef)}vsmPass(e){let{shadow:t}=this,s=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,s),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,s),e.setRenderTarget(this.vsmShadowMapVertical),Lu.material=this.vsmMaterialVertical,Lu.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),Lu.material=this.vsmMaterialHorizontal,Lu.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,Lw(this.light),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),this.vsmShadowMapVertical!==null&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),this.vsmShadowMapHorizontal!==null&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){let{shadow:t}=this,s=t.needsUpdate||t.autoUpdate;s&&(this._cameraFrameId[e.camera]===e.frameId&&(s=!1),this._cameraFrameId[e.camera]=e.frameId),s&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}},Ow=(o,e)=>new Fh(o,e),LE=new ge,__=new de,Za=new R,tf=new R,UE=[new R(1,0,0),new R(-1,0,0),new R(0,-1,0),new R(0,1,0),new R(0,0,1),new R(0,0,-1)],OE=[new R(0,-1,0),new R(0,-1,0),new R(0,0,-1),new R(0,0,1),new R(0,-1,0),new R(0,-1,0)],VE=[new R(1,0,0),new R(-1,0,0),new R(0,1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1)],kE=[new R(0,-1,0),new R(0,-1,0),new R(0,0,1),new R(0,0,-1),new R(0,-1,0),new R(0,-1,0)],Vw=A(({depthTexture:o,bd3D:e,dp:t})=>Ft(o,e).compare(t)),kw=A(({depthTexture:o,bd3D:e,dp:t,shadow:s})=>{let i=Ie("radius","float",s).setGroup(J),n=Ie("mapSize","vec2",s).setGroup(J),r=i.div(n.x),a=Ee(e),c=Ut(ki(e,a.x.greaterThan(a.z).select(v(0,1,0),v(1,0,0)))),l=ki(e,c),u=i0(gr.xy).mul(6.28318530718),h=Cs(0,5,u),d=Cs(1,5,u),p=Cs(2,5,u),m=Cs(3,5,u),g=Cs(4,5,u);return Ft(o,e.add(c.mul(h.x).add(l.mul(h.y)).mul(r))).compare(t).add(Ft(o,e.add(c.mul(d.x).add(l.mul(d.y)).mul(r))).compare(t)).add(Ft(o,e.add(c.mul(p.x).add(l.mul(p.y)).mul(r))).compare(t)).add(Ft(o,e.add(c.mul(m.x).add(l.mul(m.y)).mul(r))).compare(t)).add(Ft(o,e.add(c.mul(g.x).add(l.mul(g.y)).mul(r))).compare(t)).mul(1/5)}),zE=A(({filterFn:o,depthTexture:e,shadowCoord:t,shadow:s},i)=>{let n=t.xyz.toConst(),r=n.abs().toConst(),a=r.x.max(r.y).max(r.z),c=j("float").setGroup(J).onRenderUpdate(()=>s.camera.near),l=j("float").setGroup(J).onRenderUpdate(()=>s.camera.far),u=Ie("bias","float",s).setGroup(J),h=b(1).toVar();return K(a.sub(l).lessThanEqual(0).and(a.sub(c).greaterThanEqual(0)),()=>{let d;i.renderer.reversedDepthBuffer?(d=Uv(a.negate(),c,l),d.subAssign(u)):(d=Yx(a.negate(),c,l),d.addAssign(u));let p=n.normalize();h.assign(o({depthTexture:e,bd3D:p,dp:d,shadow:s}))}),h}),Cg=class extends Fh{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===X0?Vw:kw}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:s,shadowCoord:i,shadow:n}){return zE({filterFn:t,depthTexture:s,shadowCoord:i,shadow:n})}setupRenderTarget(e,t){let s=new vl(e.mapSize.width);s.name="PointShadowDepthTexture",s.compareFunction=t.renderer.reversedDepthBuffer?Yn:Jr;let i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=s,{shadowMap:i,depthTexture:s}}renderShadow(e){let{shadow:t,shadowMap:s,light:i}=this,{renderer:n,scene:r}=e,a=t.camera,c=t.matrix,l=n.coordinateSystem===Yt,u=l?UE:VE,h=l?OE:kE;s.setSize(t.mapSize.width,t.mapSize.width);let d=n.autoClear,p=n.getClearColor(LE),m=n.getClearAlpha();n.autoClear=!1,n.setClearColor(t.clearColor,t.clearAlpha);for(let g=0;g<6;g++){n.setRenderTarget(s,g),n.clear();let y=i.distance||a.far;y!==a.far&&(a.far=y,a.updateProjectionMatrix()),Za.setFromMatrixPosition(i.matrixWorld),a.position.copy(Za),tf.copy(a.position),tf.add(u[g]),a.up.copy(h[g]),a.lookAt(tf),a.updateMatrixWorld(),c.makeTranslation(-Za.x,-Za.y,-Za.z),__.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(__,a.coordinateSystem,a.reversedDepth);let x=r.name;r.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${g+1}`,n.render(r,a),r.name=x}n.autoClear=d,n.setClearColor(p,m)}},zw=(o,e)=>new Cg(o,e),Wi=class extends Tn{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new ge,this.colorNode=e&&e.colorNode||j(this.color).setGroup(J),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=te.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,this.baseColorNode!==null&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return c0(this.light).sub(e.context.positionView||qe)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){return Ow(this.light)}setupShadow(e){let{renderer:t}=e;if(t.shadowMap.enabled===!1)return;let s=this.shadowColorNode;if(s===null){let i=this.light.shadow.shadowNode,n;i!==void 0?n=q(i):n=this.setupShadowNode(),this.shadowNode=n,this.shadowColorNode=s=this.colorNode.mul(n),this.baseColorNode=this.colorNode}e.context.getShadow&&(s=e.context.getShadow(this,e)),this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):this.shadowNode!==null&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);let t=this.setupDirect(e),s=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),s&&e.lightsNode.setupDirectRectAreaLight(e,this,s)}update(){let{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}},f0=A(({lightDistance:o,cutoffDistance:e,decayExponent:t})=>{let s=o.pow(t).max(.01).reciprocal();return e.greaterThan(0).select(s.mul(o.div(e).pow4().oneMinus().clamp().pow2()),s)}),Gw=({color:o,lightVector:e,cutoffDistance:t,decayExponent:s})=>{let i=e.normalize(),n=e.length(),r=f0({lightDistance:n,cutoffDistance:t,decayExponent:s}),a=o.mul(r);return{lightDirection:i,lightColor:a}},Eg=class extends Wi{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=j(0).setGroup(J),this.decayExponentNode=j(2).setGroup(J)}update(e){let{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return zw(this.light)}setupDirect(e){return Gw({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}},GE=A(([o=Re()])=>{let e=o.mul(2),t=e.x.floor(),s=e.y.floor();return t.add(s).mod(2).sign()}),WE=A(([o=Re()],{renderer:e,material:t})=>{let s=Mx(o.mul(2).sub(1)),i;if(t.alphaToCoverage&&e.currentSamples>0){let n=b(s.fwidth()).toVar();i=Fs(n.oneMinus(),n.add(1),s).oneMinus()}else i=vt(s.greaterThan(1),0,1);return i}),lc=A(([o,e,t])=>{let s=b(t).toVar(),i=b(e).toVar(),n=hs(o).toVar();return vt(n,i,s)}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),Ih=A(([o,e])=>{let t=hs(e).toVar(),s=b(o).toVar();return vt(t,s.negate(),s)}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),Xe=A(([o])=>{let e=b(o).toVar();return T(oi(e))}).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),Le=A(([o,e])=>{let t=b(o).toVar();return e.assign(Xe(t)),t.sub(b(e))}),$E=A(([o,e,t,s,i,n])=>{let r=b(n).toVar(),a=b(i).toVar(),c=b(s).toVar(),l=b(t).toVar(),u=b(e).toVar(),h=b(o).toVar(),d=b(he(1,a)).toVar();return he(1,r).mul(h.mul(d).add(u.mul(a))).add(r.mul(l.mul(d).add(c.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"}]}),qE=A(([o,e,t,s,i,n])=>{let r=b(n).toVar(),a=b(i).toVar(),c=v(s).toVar(),l=v(t).toVar(),u=v(e).toVar(),h=v(o).toVar(),d=b(he(1,a)).toVar();return he(1,r).mul(h.mul(d).add(u.mul(a))).add(r.mul(l.mul(d).add(c.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"}]}),Ww=ft([$E,qE]),HE=A(([o,e,t,s,i,n,r,a,c,l,u])=>{let h=b(u).toVar(),d=b(l).toVar(),p=b(c).toVar(),m=b(a).toVar(),g=b(r).toVar(),y=b(n).toVar(),x=b(i).toVar(),_=b(s).toVar(),w=b(t).toVar(),S=b(e).toVar(),E=b(o).toVar(),B=b(he(1,p)).toVar(),N=b(he(1,d)).toVar();return b(he(1,h)).toVar().mul(N.mul(E.mul(B).add(S.mul(p))).add(d.mul(w.mul(B).add(_.mul(p))))).add(h.mul(N.mul(x.mul(B).add(y.mul(p))).add(d.mul(g.mul(B).add(m.mul(p))))))}).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),XE=A(([o,e,t,s,i,n,r,a,c,l,u])=>{let h=b(u).toVar(),d=b(l).toVar(),p=b(c).toVar(),m=v(a).toVar(),g=v(r).toVar(),y=v(n).toVar(),x=v(i).toVar(),_=v(s).toVar(),w=v(t).toVar(),S=v(e).toVar(),E=v(o).toVar(),B=b(he(1,p)).toVar(),N=b(he(1,d)).toVar();return b(he(1,h)).toVar().mul(N.mul(E.mul(B).add(S.mul(p))).add(d.mul(w.mul(B).add(_.mul(p))))).add(h.mul(N.mul(x.mul(B).add(y.mul(p))).add(d.mul(g.mul(B).add(m.mul(p))))))}).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),$w=ft([HE,XE]),YE=A(([o,e,t])=>{let s=b(t).toVar(),i=b(e).toVar(),n=D(o).toVar(),r=D(n.bitAnd(D(7))).toVar(),a=b(lc(r.lessThan(D(4)),i,s)).toVar(),c=b(se(2,lc(r.lessThan(D(4)),s,i))).toVar();return Ih(a,hs(r.bitAnd(D(1)))).add(Ih(c,hs(r.bitAnd(D(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),jE=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=b(e).toVar(),a=D(o).toVar(),c=D(a.bitAnd(D(15))).toVar(),l=b(lc(c.lessThan(D(8)),r,n)).toVar(),u=b(lc(c.lessThan(D(4)),n,lc(c.equal(D(12)).or(c.equal(D(14))),r,i))).toVar();return Ih(l,hs(c.bitAnd(D(1)))).add(Ih(u,hs(c.bitAnd(D(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"}]}),ot=ft([YE,jE]),ZE=A(([o,e,t])=>{let s=b(t).toVar(),i=b(e).toVar(),n=mr(o).toVar();return v(ot(n.x,i,s),ot(n.y,i,s),ot(n.z,i,s))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),JE=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=b(e).toVar(),a=mr(o).toVar();return v(ot(a.x,r,n,i),ot(a.y,r,n,i),ot(a.z,r,n,i))}).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"}]}),os=ft([ZE,JE]),QE=A(([o])=>{let e=b(o).toVar();return se(.6616,e)}).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),KE=A(([o])=>{let e=b(o).toVar();return se(.982,e)}).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),eB=A(([o])=>{let e=v(o).toVar();return se(.6616,e)}).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),qw=ft([QE,eB]),tB=A(([o])=>{let e=v(o).toVar();return se(.982,e)}).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]}),Hw=ft([KE,tB]),es=A(([o,e])=>{let t=T(e).toVar(),s=D(o).toVar();return s.shiftLeft(t).bitOr(s.shiftRight(T(32).sub(t)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),Xw=A(([o,e,t])=>{o.subAssign(t),o.bitXorAssign(es(t,T(4))),t.addAssign(e),e.subAssign(o),e.bitXorAssign(es(o,T(6))),o.addAssign(t),t.subAssign(e),t.bitXorAssign(es(e,T(8))),e.addAssign(o),o.subAssign(t),o.bitXorAssign(es(t,T(16))),t.addAssign(e),e.subAssign(o),e.bitXorAssign(es(o,T(19))),o.addAssign(t),t.subAssign(e),t.bitXorAssign(es(e,T(4))),e.addAssign(o)}),Lc=A(([o,e,t])=>{let s=D(t).toVar(),i=D(e).toVar(),n=D(o).toVar();return s.bitXorAssign(i),s.subAssign(es(i,T(14))),n.bitXorAssign(s),n.subAssign(es(s,T(11))),i.bitXorAssign(n),i.subAssign(es(n,T(25))),s.bitXorAssign(i),s.subAssign(es(i,T(16))),n.bitXorAssign(s),n.subAssign(es(s,T(4))),i.bitXorAssign(n),i.subAssign(es(n,T(14))),s.bitXorAssign(i),s.subAssign(es(i,T(24))),s}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),wt=A(([o])=>{let e=D(o).toVar();return b(e).div(b(D(T(4294967295))))}).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),hi=A(([o])=>{let e=b(o).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"}]}),sB=A(([o])=>{let e=T(o).toVar(),t=D(D(1)).toVar(),s=D(D(T(3735928559)).add(t.shiftLeft(D(2))).add(D(13))).toVar();return Lc(s.add(D(e)),s,s)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),iB=A(([o,e])=>{let t=T(e).toVar(),s=T(o).toVar(),i=D(D(2)).toVar(),n=D().toVar(),r=D().toVar(),a=D().toVar();return n.assign(r.assign(a.assign(D(T(3735928559)).add(i.shiftLeft(D(2))).add(D(13))))),n.addAssign(D(s)),r.addAssign(D(t)),Lc(n,r,a)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),nB=A(([o,e,t])=>{let s=T(t).toVar(),i=T(e).toVar(),n=T(o).toVar(),r=D(D(3)).toVar(),a=D().toVar(),c=D().toVar(),l=D().toVar();return a.assign(c.assign(l.assign(D(T(3735928559)).add(r.shiftLeft(D(2))).add(D(13))))),a.addAssign(D(n)),c.addAssign(D(i)),l.addAssign(D(s)),Lc(a,c,l)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),rB=A(([o,e,t,s])=>{let i=T(s).toVar(),n=T(t).toVar(),r=T(e).toVar(),a=T(o).toVar(),c=D(D(4)).toVar(),l=D().toVar(),u=D().toVar(),h=D().toVar();return l.assign(u.assign(h.assign(D(T(3735928559)).add(c.shiftLeft(D(2))).add(D(13))))),l.addAssign(D(a)),u.addAssign(D(r)),h.addAssign(D(n)),Xw(l,u,h),l.addAssign(D(i)),Lc(l,u,h)}).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),oB=A(([o,e,t,s,i])=>{let n=T(i).toVar(),r=T(s).toVar(),a=T(t).toVar(),c=T(e).toVar(),l=T(o).toVar(),u=D(D(5)).toVar(),h=D().toVar(),d=D().toVar(),p=D().toVar();return h.assign(d.assign(p.assign(D(T(3735928559)).add(u.shiftLeft(D(2))).add(D(13))))),h.addAssign(D(l)),d.addAssign(D(c)),p.addAssign(D(a)),Xw(h,d,p),h.addAssign(D(r)),d.addAssign(D(n)),Lc(h,d,p)}).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]}),Ae=ft([sB,iB,nB,rB,oB]),aB=A(([o,e])=>{let t=T(e).toVar(),s=T(o).toVar(),i=D(Ae(s,t)).toVar(),n=mr().toVar();return n.x.assign(i.bitAnd(T(255))),n.y.assign(i.shiftRight(T(8)).bitAnd(T(255))),n.z.assign(i.shiftRight(T(16)).bitAnd(T(255))),n}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),cB=A(([o,e,t])=>{let s=T(t).toVar(),i=T(e).toVar(),n=T(o).toVar(),r=D(Ae(n,i,s)).toVar(),a=mr().toVar();return a.x.assign(r.bitAnd(T(255))),a.y.assign(r.shiftRight(T(8)).bitAnd(T(255))),a.z.assign(r.shiftRight(T(16)).bitAnd(T(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),as=ft([aB,cB]),lB=A(([o])=>{let e=U(o).toVar(),t=T().toVar(),s=T().toVar(),i=b(Le(e.x,t)).toVar(),n=b(Le(e.y,s)).toVar(),r=b(hi(i)).toVar(),a=b(hi(n)).toVar(),c=b(Ww(ot(Ae(t,s),i,n),ot(Ae(t.add(T(1)),s),i.sub(1),n),ot(Ae(t,s.add(T(1))),i,n.sub(1)),ot(Ae(t.add(T(1)),s.add(T(1))),i.sub(1),n.sub(1)),r,a)).toVar();return qw(c)}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),uB=A(([o])=>{let e=v(o).toVar(),t=T().toVar(),s=T().toVar(),i=T().toVar(),n=b(Le(e.x,t)).toVar(),r=b(Le(e.y,s)).toVar(),a=b(Le(e.z,i)).toVar(),c=b(hi(n)).toVar(),l=b(hi(r)).toVar(),u=b(hi(a)).toVar(),h=b($w(ot(Ae(t,s,i),n,r,a),ot(Ae(t.add(T(1)),s,i),n.sub(1),r,a),ot(Ae(t,s.add(T(1)),i),n,r.sub(1),a),ot(Ae(t.add(T(1)),s.add(T(1)),i),n.sub(1),r.sub(1),a),ot(Ae(t,s,i.add(T(1))),n,r,a.sub(1)),ot(Ae(t.add(T(1)),s,i.add(T(1))),n.sub(1),r,a.sub(1)),ot(Ae(t,s.add(T(1)),i.add(T(1))),n,r.sub(1),a.sub(1)),ot(Ae(t.add(T(1)),s.add(T(1)),i.add(T(1))),n.sub(1),r.sub(1),a.sub(1)),c,l,u)).toVar();return Hw(h)}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]}),m0=ft([lB,uB]),hB=A(([o])=>{let e=U(o).toVar(),t=T().toVar(),s=T().toVar(),i=b(Le(e.x,t)).toVar(),n=b(Le(e.y,s)).toVar(),r=b(hi(i)).toVar(),a=b(hi(n)).toVar(),c=v(Ww(os(as(t,s),i,n),os(as(t.add(T(1)),s),i.sub(1),n),os(as(t,s.add(T(1))),i,n.sub(1)),os(as(t.add(T(1)),s.add(T(1))),i.sub(1),n.sub(1)),r,a)).toVar();return qw(c)}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),dB=A(([o])=>{let e=v(o).toVar(),t=T().toVar(),s=T().toVar(),i=T().toVar(),n=b(Le(e.x,t)).toVar(),r=b(Le(e.y,s)).toVar(),a=b(Le(e.z,i)).toVar(),c=b(hi(n)).toVar(),l=b(hi(r)).toVar(),u=b(hi(a)).toVar(),h=v($w(os(as(t,s,i),n,r,a),os(as(t.add(T(1)),s,i),n.sub(1),r,a),os(as(t,s.add(T(1)),i),n,r.sub(1),a),os(as(t.add(T(1)),s.add(T(1)),i),n.sub(1),r.sub(1),a),os(as(t,s,i.add(T(1))),n,r,a.sub(1)),os(as(t.add(T(1)),s,i.add(T(1))),n.sub(1),r,a.sub(1)),os(as(t,s.add(T(1)),i.add(T(1))),n,r.sub(1),a.sub(1)),os(as(t.add(T(1)),s.add(T(1)),i.add(T(1))),n.sub(1),r.sub(1),a.sub(1)),c,l,u)).toVar();return Hw(h)}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Uc=ft([hB,dB]),pB=A(([o])=>{let e=b(o).toVar(),t=T(Xe(e)).toVar();return wt(Ae(t))}).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),fB=A(([o])=>{let e=U(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar();return wt(Ae(t,s))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),mB=A(([o])=>{let e=v(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar(),i=T(Xe(e.z)).toVar();return wt(Ae(t,s,i))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),gB=A(([o])=>{let e=Z(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar(),i=T(Xe(e.z)).toVar(),n=T(Xe(e.w)).toVar();return wt(Ae(t,s,i,n))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]}),yB=ft([pB,fB,mB,gB]),xB=A(([o])=>{let e=b(o).toVar(),t=T(Xe(e)).toVar();return v(wt(Ae(t,T(0))),wt(Ae(t,T(1))),wt(Ae(t,T(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),bB=A(([o])=>{let e=U(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar();return v(wt(Ae(t,s,T(0))),wt(Ae(t,s,T(1))),wt(Ae(t,s,T(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),_B=A(([o])=>{let e=v(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar(),i=T(Xe(e.z)).toVar();return v(wt(Ae(t,s,i,T(0))),wt(Ae(t,s,i,T(1))),wt(Ae(t,s,i,T(2))))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),TB=A(([o])=>{let e=Z(o).toVar(),t=T(Xe(e.x)).toVar(),s=T(Xe(e.y)).toVar(),i=T(Xe(e.z)).toVar(),n=T(Xe(e.w)).toVar();return v(wt(Ae(t,s,i,n,T(0))),wt(Ae(t,s,i,n,T(1))),wt(Ae(t,s,i,n,T(2))))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]}),Md=ft([xB,bB,_B,TB]),Ph=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=T(e).toVar(),a=v(o).toVar(),c=b(0).toVar(),l=b(1).toVar();return Me(r,()=>{c.addAssign(l.mul(m0(a))),l.mulAssign(i),a.mulAssign(n)}),c}).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"}]}),Ad=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=T(e).toVar(),a=v(o).toVar(),c=v(0).toVar(),l=b(1).toVar();return Me(r,()=>{c.addAssign(l.mul(Uc(a))),l.mulAssign(i),a.mulAssign(n)}),c}).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"}]}),SB=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=T(e).toVar(),a=v(o).toVar();return U(Ph(a,r,n,i),Ph(a.add(v(T(19),T(193),T(17))),r,n,i))}).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"}]}),vB=A(([o,e,t,s])=>{let i=b(s).toVar(),n=b(t).toVar(),r=T(e).toVar(),a=v(o).toVar(),c=v(Ad(a,r,n,i)).toVar(),l=b(Ph(a.add(v(T(19),T(193),T(17))),r,n,i)).toVar();return Z(c,l)}).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"}]}),wB=A(([o,e,t,s,i,n,r])=>{let a=T(r).toVar(),c=b(n).toVar(),l=T(i).toVar(),u=T(s).toVar(),h=T(t).toVar(),d=T(e).toVar(),p=U(o).toVar(),m=v(Md(U(d.add(u),h.add(l)))).toVar(),g=U(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(c),g.addAssign(.5);let y=U(U(b(d),b(h)).add(g)).toVar(),x=U(y.sub(p)).toVar();return K(a.equal(T(2)),()=>Ee(x.x).add(Ee(x.y))),K(a.equal(T(3)),()=>ze(Ee(x.x),Ee(x.y))),ds(x,x)}).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"}]}),MB=A(([o,e,t,s,i,n,r,a,c])=>{let l=T(c).toVar(),u=b(a).toVar(),h=T(r).toVar(),d=T(n).toVar(),p=T(i).toVar(),m=T(s).toVar(),g=T(t).toVar(),y=T(e).toVar(),x=v(o).toVar(),_=v(Md(v(y.add(p),g.add(d),m.add(h)))).toVar();_.subAssign(.5),_.mulAssign(u),_.addAssign(.5);let w=v(v(b(y),b(g),b(m)).add(_)).toVar(),S=v(w.sub(x)).toVar();return K(l.equal(T(2)),()=>Ee(S.x).add(Ee(S.y)).add(Ee(S.z))),K(l.equal(T(3)),()=>ze(Ee(S.x),Ee(S.y),Ee(S.z))),ds(S,S)}).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"}]}),Bo=ft([wB,MB]),AB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=U(o).toVar(),r=T().toVar(),a=T().toVar(),c=U(Le(n.x,r),Le(n.y,a)).toVar(),l=b(1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:u})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:h})=>{let d=b(Bo(c,u,h,r,a,i,s)).toVar();l.assign(Vt(l,d))})}),K(s.equal(T(0)),()=>{l.assign(It(l))}),l}).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),NB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=U(o).toVar(),r=T().toVar(),a=T().toVar(),c=U(Le(n.x,r),Le(n.y,a)).toVar(),l=U(1e6,1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:u})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:h})=>{let d=b(Bo(c,u,h,r,a,i,s)).toVar();K(d.lessThan(l.x),()=>{l.y.assign(l.x),l.x.assign(d)}).ElseIf(d.lessThan(l.y),()=>{l.y.assign(d)})})}),K(s.equal(T(0)),()=>{l.assign(It(l))}),l}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),RB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=U(o).toVar(),r=T().toVar(),a=T().toVar(),c=U(Le(n.x,r),Le(n.y,a)).toVar(),l=v(1e6,1e6,1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:u})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:h})=>{let d=b(Bo(c,u,h,r,a,i,s)).toVar();K(d.lessThan(l.x),()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(d)}).ElseIf(d.lessThan(l.y),()=>{l.z.assign(l.y),l.y.assign(d)}).ElseIf(d.lessThan(l.z),()=>{l.z.assign(d)})})}),K(s.equal(T(0)),()=>{l.assign(It(l))}),l}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),CB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=v(o).toVar(),r=T().toVar(),a=T().toVar(),c=T().toVar(),l=v(Le(n.x,r),Le(n.y,a),Le(n.z,c)).toVar(),u=b(1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:h})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:d})=>{Me({start:-1,end:T(1),name:"z",condition:"<="},({z:p})=>{let m=b(Bo(l,h,d,p,r,a,c,i,s)).toVar();u.assign(Vt(u,m))})})}),K(s.equal(T(0)),()=>{u.assign(It(u))}),u}).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),EB=ft([AB,CB]),BB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=v(o).toVar(),r=T().toVar(),a=T().toVar(),c=T().toVar(),l=v(Le(n.x,r),Le(n.y,a),Le(n.z,c)).toVar(),u=U(1e6,1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:h})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:d})=>{Me({start:-1,end:T(1),name:"z",condition:"<="},({z:p})=>{let m=b(Bo(l,h,d,p,r,a,c,i,s)).toVar();K(m.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(m)}).ElseIf(m.lessThan(u.y),()=>{u.y.assign(m)})})})}),K(s.equal(T(0)),()=>{u.assign(It(u))}),u}).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),FB=ft([NB,BB]),IB=A(([o,e,t])=>{let s=T(t).toVar(),i=b(e).toVar(),n=v(o).toVar(),r=T().toVar(),a=T().toVar(),c=T().toVar(),l=v(Le(n.x,r),Le(n.y,a),Le(n.z,c)).toVar(),u=v(1e6,1e6,1e6).toVar();return Me({start:-1,end:T(1),name:"x",condition:"<="},({x:h})=>{Me({start:-1,end:T(1),name:"y",condition:"<="},({y:d})=>{Me({start:-1,end:T(1),name:"z",condition:"<="},({z:p})=>{let m=b(Bo(l,h,d,p,r,a,c,i,s)).toVar();K(m.lessThan(u.x),()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(m)}).ElseIf(m.lessThan(u.y),()=>{u.z.assign(u.y),u.y.assign(m)}).ElseIf(m.lessThan(u.z),()=>{u.z.assign(m)})})})}),K(s.equal(T(0)),()=>{u.assign(It(u))}),u}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),g0=ft([RB,IB]),PB=A(([o,e,t,s,i,n,r,a,c,l,u])=>{let h=T(o).toVar(),d=U(e).toVar(),p=U(t).toVar(),m=U(s).toVar(),g=b(i).toVar(),y=b(n).toVar(),x=b(r).toVar(),_=hs(a).toVar(),w=T(c).toVar(),S=b(l).toVar(),E=b(u).toVar(),B=d.mul(p).add(m),N=b(0).toVar();return K(h.equal(T(0)),()=>{N.assign(Uc(B))}),K(h.equal(T(1)),()=>{N.assign(Md(B))}),K(h.equal(T(2)),()=>{N.assign(g0(B,g,T(0)))}),K(h.equal(T(3)),()=>{N.assign(Ad(v(B,0),w,S,E))}),N.assign(N.mul(x.sub(y)).add(y)),K(_,()=>{N.assign(Bs(N,y,x))}),N}).setLayout({name:"mx_unifiednoise2d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"texcoord",type:"vec2"},{name:"freq",type:"vec2"},{name:"offset",type:"vec2"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),DB=A(([o,e,t,s,i,n,r,a,c,l,u])=>{let h=T(o).toVar(),d=v(e).toVar(),p=v(t).toVar(),m=v(s).toVar(),g=b(i).toVar(),y=b(n).toVar(),x=b(r).toVar(),_=hs(a).toVar(),w=T(c).toVar(),S=b(l).toVar(),E=b(u).toVar(),B=d.mul(p).add(m),N=b(0).toVar();return K(h.equal(T(0)),()=>{N.assign(Uc(B))}),K(h.equal(T(1)),()=>{N.assign(Md(B))}),K(h.equal(T(2)),()=>{N.assign(g0(B,g,T(0)))}),K(h.equal(T(3)),()=>{N.assign(Ad(B,w,S,E))}),N.assign(N.mul(x.sub(y)).add(y)),K(_,()=>{N.assign(Bs(N,y,x))}),N}).setLayout({name:"mx_unifiednoise3d",type:"float",inputs:[{name:"noiseType",type:"int"},{name:"position",type:"vec3"},{name:"freq",type:"vec3"},{name:"offset",type:"vec3"},{name:"jitter",type:"float"},{name:"outmin",type:"float"},{name:"outmax",type:"float"},{name:"clampoutput",type:"bool"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),LB=A(([o])=>{let e=o.y,t=o.z,s=v().toVar();return K(e.lessThan(1e-4),()=>{s.assign(v(t,t,t))}).Else(()=>{let i=o.x;i=i.sub(oi(i)).mul(6).toVar();let n=T(Tx(i)),r=i.sub(b(n)),a=t.mul(e.oneMinus()),c=t.mul(e.mul(r).oneMinus()),l=t.mul(e.mul(r.oneMinus()).oneMinus());K(n.equal(T(0)),()=>{s.assign(v(t,l,a))}).ElseIf(n.equal(T(1)),()=>{s.assign(v(c,t,a))}).ElseIf(n.equal(T(2)),()=>{s.assign(v(a,t,l))}).ElseIf(n.equal(T(3)),()=>{s.assign(v(a,c,t))}).ElseIf(n.equal(T(4)),()=>{s.assign(v(l,a,t))}).Else(()=>{s.assign(v(t,a,c))})}),s}).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),UB=A(([o])=>{let e=v(o).toVar(),t=b(e.x).toVar(),s=b(e.y).toVar(),i=b(e.z).toVar(),n=b(Vt(t,Vt(s,i))).toVar(),r=b(ze(t,ze(s,i))).toVar(),a=b(r.sub(n)).toVar(),c=b().toVar(),l=b().toVar(),u=b().toVar();return u.assign(r),K(r.greaterThan(0),()=>{l.assign(a.div(r))}).Else(()=>{l.assign(0)}),K(l.lessThanEqual(0),()=>{c.assign(0)}).Else(()=>{K(t.greaterThanEqual(r),()=>{c.assign(s.sub(i).div(a))}).ElseIf(s.greaterThanEqual(r),()=>{c.assign(Ye(2,i.sub(t).div(a)))}).Else(()=>{c.assign(Ye(4,t.sub(s).div(a)))}),c.mulAssign(1/6),K(c.lessThan(0),()=>{c.addAssign(1)})}),v(c,l,u)}).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),OB=A(([o])=>{let e=v(o).toVar(),t=ix(hx(e,v(.04045))).toVar(),s=v(e.div(12.92)).toVar(),i=v(cs(ze(e.add(v(.055)),v(0)).div(1.055),v(2.4))).toVar();return le(s,i,t)}).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Yw=(o,e)=>{o=b(o),e=b(e);let t=U(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return Fs(o.sub(t),o.add(t),e)},jw=(o,e,t,s)=>le(o,e,t[s].clamp()),VB=(o,e,t=Re())=>jw(o,e,t,"x"),kB=(o,e,t=Re())=>jw(o,e,t,"y"),zB=(o,e,t,s,i=Re())=>{let n=i.x.clamp(),r=i.y.clamp(),a=le(o,e,n),c=le(t,s,n);return le(a,c,r)},Zw=(o,e,t,s,i)=>le(o,e,Yw(t,s[i])),GB=(o,e,t,s=Re())=>Zw(o,e,t,s,"x"),WB=(o,e,t,s=Re())=>Zw(o,e,t,s,"y"),$B=(o=1,e=0,t=Re())=>t.mul(o).add(e),qB=(o,e=1)=>(o=b(o),o.abs().pow(e).mul(o.sign())),HB=(o,e=1,t=.5)=>b(o).sub(t).mul(e).add(t),XB=(o=Re(),e=1,t=0)=>m0(o.convert("vec2|vec3")).mul(e).add(t),YB=(o=Re(),e=1,t=0)=>Uc(o.convert("vec2|vec3")).mul(e).add(t),jB=(o=Re(),e=1,t=0)=>(o=o.convert("vec2|vec3"),Z(Uc(o),m0(o.add(U(19,73)))).mul(e).add(t)),ZB=(o,e=Re(),t=U(1,1),s=U(0,0),i=1,n=0,r=1,a=!1,c=1,l=2,u=.5)=>PB(o,e.convert("vec2|vec3"),t,s,i,n,r,a,c,l,u),JB=(o,e=Re(),t=U(1,1),s=U(0,0),i=1,n=0,r=1,a=!1,c=1,l=2,u=.5)=>DB(o,e.convert("vec2|vec3"),t,s,i,n,r,a,c,l,u),QB=(o=Re(),e=1)=>EB(o.convert("vec2|vec3"),e,T(1)),KB=(o=Re(),e=1)=>FB(o.convert("vec2|vec3"),e,T(1)),eF=(o=Re(),e=1)=>g0(o.convert("vec2|vec3"),e,T(1)),tF=(o=Re())=>yB(o.convert("vec2|vec3")),sF=(o=Re(),e=3,t=2,s=.5,i=1)=>Ph(o,T(e),t,s).mul(i),iF=(o=Re(),e=3,t=2,s=.5,i=1)=>SB(o,T(e),t,s).mul(i),nF=(o=Re(),e=3,t=2,s=.5,i=1)=>Ad(o,T(e),t,s).mul(i),rF=(o=Re(),e=3,t=2,s=.5,i=1)=>vB(o,T(e),t,s).mul(i),oF=(o,e=b(0))=>Ye(o,e),aF=(o,e=b(0))=>he(o,e),cF=(o,e=b(1))=>se(o,e),lF=(o,e=b(1))=>ss(o,e),uF=(o,e=b(1))=>Bc(o,e),hF=(o,e=b(1))=>cs(o,e),dF=(o=b(0),e=b(1))=>gx(o,e),pF=()=>Eo,fF=()=>aw,mF=(o,e=b(1))=>he(e,o),gF=(o,e,t,s)=>o.greaterThan(e).mix(t,s),yF=(o,e,t,s)=>o.greaterThanEqual(e).mix(t,s),xF=(o,e,t,s)=>o.equal(e).mix(t,s),bF=(o,e=null)=>{if(typeof e=="string"){let t={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3},s=e.replace(/^out/,"").toLowerCase();if(t[s]!==void 0)return o.element(t[s])}if(typeof e=="number")return o.element(e);if(typeof e=="string"&&e.length===1){let t={x:0,r:0,y:1,g:1,z:2,b:2,w:3,a:3};if(t[e]!==void 0)return o.element(t[e])}return o},_F=(o,e=U(.5,.5),t=U(1,1),s=b(0),i=U(0,0))=>{let n=o;if(e&&(n=n.sub(e)),t&&(n=n.mul(t)),s){let r=s.mul(Math.PI/180),a=r.cos(),c=r.sin();n=U(n.x.mul(a).sub(n.y.mul(c)),n.x.mul(c).add(n.y.mul(a)))}return e&&(n=n.add(e)),i&&(n=n.add(i)),n},TF=(o,e)=>{o=U(o),e=b(e);let t=e.mul(Math.PI/180);return Pc(o,t)},SF=(o,e,t)=>{o=v(o),e=b(e),t=v(t);let s=e.mul(Math.PI/180),i=t.normalize(),n=s.cos(),r=s.sin(),a=b(1).sub(n);return o.mul(n).add(i.cross(o).mul(r)).add(i.mul(i.dot(o)).mul(a))},vF=(o,e)=>(o=v(o),e=b(e),Wx(o,e)),wF=A(([o,e,t])=>{let s=Ut(o).toVar(),i=he(b(.5).mul(e.sub(t)),li).div(s).toVar(),n=he(b(-.5).mul(e.sub(t)),li).div(s).toVar(),r=v().toVar();r.x=s.x.greaterThan(b(0)).select(i.x,n.x),r.y=s.y.greaterThan(b(0)).select(i.y,n.y),r.z=s.z.greaterThan(b(0)).select(i.z,n.z);let a=Vt(r.x,r.y,r.z).toVar();return li.add(s.mul(a)).toVar().sub(t)}),Jw=A(([o,e])=>{let t=o.x,s=o.y,i=o.z,n=e.element(0).mul(.886227);return n=n.add(e.element(1).mul(2*.511664).mul(s)),n=n.add(e.element(2).mul(2*.511664).mul(i)),n=n.add(e.element(3).mul(2*.511664).mul(t)),n=n.add(e.element(4).mul(2*.429043).mul(t).mul(s)),n=n.add(e.element(5).mul(2*.429043).mul(s).mul(i)),n=n.add(e.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(e.element(7).mul(2*.429043).mul(t).mul(i)),n=n.add(e.element(8).mul(.429043).mul(se(t,t).sub(se(s,s)))),n}),f=Object.freeze({__proto__:null,BRDF_GGX:e0,BRDF_Lambert:dr,BasicPointShadowFilter:Vw,BasicShadowFilter:Bw,Break:Iv,Const:nS,Continue:LA,DFGLUT:bc,D_GGX:qv,Discard:xS,EPSILON:dx,F_Schlick:Ao,Fn:A,HALF_PI:LM,INFINITY:IM,If:K,Loop:Me,NodeAccess:dt,NodeShaderStage:ec,NodeType:hM,NodeUpdateType:te,OnBeforeMaterialUpdate:aC,OnBeforeObjectUpdate:oC,OnMaterialUpdate:rC,OnObjectUpdate:nC,PCFShadowFilter:Fw,PCFSoftShadowFilter:Iw,PI:rh,PI2:PM,PointShadowFilter:kw,Return:$M,Schlick_to_F0:Mm,ShaderNode:ho,Stack:nd,Switch:AM,TBNViewMatrix:nr,TWO_PI:DM,VSMShadowFilter:Pw,V_GGX_SmithCorrelated:$v,Var:iS,VarIntent:rS,abs:Ee,acesFilmicToneMapping:yw,acos:mx,add:Ye,addMethodChaining:P,addNodeElement:qM,agxToneMapping:xw,all:BT,alphaT:eh,and:gT,anisotropy:cn,anisotropyB:ar,anisotropyT:nc,any:FT,append:EM,array:cT,arrayBuffer:RM,asin:LT,assign:lT,atan:gx,atomicAdd:JC,atomicAnd:tE,atomicFunc:yi,atomicLoad:jC,atomicMax:KC,atomicMin:eE,atomicOr:sE,atomicStore:ZC,atomicSub:QC,atomicXor:iE,attenuationColor:cx,attenuationDistance:ax,attribute:zi,attributeArray:cC,backgroundBlurriness:uw,backgroundIntensity:mg,backgroundRotation:hw,batch:Bv,bentNormalView:YS,billboarding:HR,bitAnd:_T,bitNot:TT,bitOr:ST,bitXor:vT,bitangentGeometry:SA,bitangentLocal:vA,bitangentView:HS,bitangentWorld:wA,bitcast:rw,blendBurn:jA,blendColor:KA,blendDodge:ZA,blendOverlay:QA,blendScreen:JA,blur:Jv,bool:hs,buffer:Fc,bufferAttribute:Bx,builtin:qi,builtinAOContext:tS,builtinShadowContext:eS,bumpMap:Wx,bvec2:sT,bvec3:ix,bvec4:iT,bypass:mS,cache:fS,call:uT,cameraFar:hn,cameraIndex:vn,cameraNear:un,cameraNormalMatrix:eA,cameraPosition:wS,cameraProjectionMatrix:Oi,cameraProjectionMatrixInverse:vS,cameraViewMatrix:fs,cameraViewport:tA,cameraWorldMatrix:KM,cbrt:YT,cdl:TC,ceil:ld,checker:GE,cineonToneMapping:gw,clamp:Bs,clearcoat:Ju,clearcoatNormalView:dn,clearcoatRoughness:po,clipSpace:NS,code:Sd,color:tT,colorSpaceToWorking:hd,colorToDirection:AA,compute:pS,computeKernel:Fx,computeSkinning:DA,context:$i,convert:rT,convertColorSpace:kM,convertToTexture:eC,cos:Rs,countLeadingZeros:vR,countOneBits:wR,countTrailingZeros:SR,cross:ki,cubeTexture:Ft,cubeTextureBase:Gx,dFdx:bx,dFdy:_x,dashSize:$u,debug:bS,decrement:CT,decrementBefore:NT,defaultBuildStages:mf,defaultShaderStages:J_,defined:dc,degrees:PT,deltaTime:OR,densityFogFactor:Sw,depth:Jx,depthPass:AC,determinant:zT,difference:qT,diffuseColor:we,diffuseContribution:er,directPointLight:Gw,directionToColor:jS,directionToFaceDirection:Co,dispersion:lx,disposeShadowMaterial:Lw,distance:$T,div:ss,dot:ds,drawIndex:Cv,dynamicBufferAttribute:WM,element:nT,emissive:Af,equal:hT,equirectUV:Qx,exp:px,exp2:bo,exponentialHeightFogFactor:UC,expression:ts,faceDirection:Vx,faceForward:Nx,faceforward:UM,float:b,floatBitsToInt:bR,floatBitsToUint:ow,floor:oi,fog:Sg,fract:Es,frameGroup:aT,frameId:aw,frontFacing:RS,fwidth:Sx,gain:AR,gapSize:Nf,getConstNodeType:eT,getCurrentStack:ex,getDirection:jv,getDistanceAttenuation:f0,getGeometryRoughness:Wv,getNormalFromDepth:sC,getParallaxCorrectNormal:wF,getRoughness:Kx,getScreenPosition:tC,getShIrradianceAt:Jw,getShadowMaterial:Dw,getShadowRenderObjectFunction:Uw,getTextureIndex:iw,getViewPosition:uo,ggxConvolution:Qv,globalId:zC,glsl:PC,glslFn:DC,grayscale:yC,greaterThan:hx,greaterThanEqual:mT,hash:MR,highpModelNormalViewMatrix:Yf,highpModelViewMatrix:Xf,hue:_C,increment:RT,incrementBefore:AT,inspector:_S,instance:PA,instanceIndex:ui,instancedArray:lC,instancedBufferAttribute:ch,instancedDynamicBufferAttribute:Df,instancedMesh:Ev,int:T,intBitsToFloat:_R,interleavedGradientNoise:i0,inverse:GT,inverseSqrt:fx,inversesqrt:OM,invocationLocalIndex:IA,invocationSubgroupIndex:FA,ior:rc,iridescence:od,iridescenceIOR:Qu,iridescenceThickness:Ku,isolate:go,ivec2:Qe,ivec3:sx,ivec4:nx,js:FC,label:sS,length:ai,lengthSq:Mx,lessThan:pT,lessThanEqual:fT,lightPosition:a0,lightProjectionUV:vw,lightShadowMatrix:wd,lightTargetDirection:l0,lightTargetPosition:ww,lightViewPosition:c0,lightingContext:Dv,lights:BE,linearDepth:mh,linearToneMapping:fw,localId:GC,log:cd,log2:ri,logarithmicDepthToViewZ:GA,luminance:n0,mat2:rd,mat3:at,mat4:gn,matcapUV:Kv,materialAO:Av,materialAlphaTest:ZS,materialAnisotropy:hv,materialAnisotropyVector:lo,materialAttenuationColor:bv,materialAttenuationDistance:xv,materialClearcoat:rv,materialClearcoatNormal:av,materialClearcoatRoughness:ov,materialColor:JS,materialDispersion:Mv,materialEmissive:KS,materialEnvIntensity:qu,materialEnvRotation:zx,materialIOR:yv,materialIridescence:dv,materialIridescenceIOR:pv,materialIridescenceThickness:fv,materialLightMap:qx,materialLineDashOffset:vv,materialLineDashSize:Tv,materialLineGapSize:Sv,materialLineScale:_v,materialLineWidth:CA,materialMetalness:iv,materialNormal:nv,materialOpacity:$x,materialPointSize:wv,materialReference:Di,materialReflectivity:Hu,materialRefractionRatio:FS,materialRotation:cv,materialRoughness:sv,materialSheen:lv,materialSheenRoughness:uv,materialShininess:QS,materialSpecular:ev,materialSpecularColor:tv,materialSpecularIntensity:om,materialSpecularStrength:oc,materialThickness:gv,materialTransmission:mv,max:ze,maxMipLevel:Px,mediumpModelViewMatrix:AS,metalness:Li,min:Vt,mix:le,mixElement:ZT,mod:Bc,modInt:ET,modelDirection:cA,modelNormalMatrix:MS,modelPosition:lA,modelRadius:dA,modelScale:uA,modelViewMatrix:wn,modelViewPosition:hA,modelViewProjection:Nv,modelWorldMatrix:ls,modelWorldMatrixInverse:pA,morphReference:Pv,mrt:nw,mul:se,mx_aastep:Yw,mx_add:oF,mx_atan2:dF,mx_cell_noise_float:tF,mx_contrast:HB,mx_divide:lF,mx_fractal_noise_float:sF,mx_fractal_noise_vec2:iF,mx_fractal_noise_vec3:nF,mx_fractal_noise_vec4:rF,mx_frame:fF,mx_heighttonormal:vF,mx_hsvtorgb:LB,mx_ifequal:xF,mx_ifgreater:gF,mx_ifgreatereq:yF,mx_invert:mF,mx_modulo:uF,mx_multiply:cF,mx_noise_float:XB,mx_noise_vec3:YB,mx_noise_vec4:jB,mx_place2d:_F,mx_power:hF,mx_ramp4:zB,mx_ramplr:VB,mx_ramptb:kB,mx_rgbtohsv:UB,mx_rotate2d:TF,mx_rotate3d:SF,mx_safepower:qB,mx_separate:bF,mx_splitlr:GB,mx_splittb:WB,mx_srgb_texture_to_lin_rec709:OB,mx_subtract:aF,mx_timer:pF,mx_transform_uv:$B,mx_unifiednoise2d:ZB,mx_unifiednoise3d:JB,mx_worley_noise_float:QB,mx_worley_noise_vec2:KB,mx_worley_noise_vec3:eF,negate:xx,neutralToneMapping:bw,nodeArray:or,nodeImmutable:G,nodeObject:q,nodeObjectIntent:tc,nodeObjects:id,nodeProxy:oe,nodeProxyIntent:V,normalFlat:CS,normalGeometry:pd,normalLocal:zt,normalMap:nm,normalView:ye,normalViewGeometry:To,normalWorld:Mn,normalWorldGeometry:ES,normalize:Ut,not:xT,notEqual:dT,numWorkgroups:VC,objectDirection:sA,objectGroup:ux,objectPosition:nA,objectRadius:aA,objectScale:rA,objectViewPosition:oA,objectWorldMatrix:iA,oneMinus:UT,or:yT,orthographicDepthToViewZ:zA,oscSawtooth:GR,oscSine:VR,oscSquare:kR,oscTriangle:zR,output:fo,outputStruct:gR,overloadingFn:ft,packHalf2x16:BR,packSnorm2x16:CR,packUnorm2x16:ER,parabola:rg,parallaxDirection:XS,parallaxUV:MA,parameter:pR,pass:wC,passTexture:MC,pcurve:NR,perspectiveDepthToViewZ:jx,pmremTexture:s0,pointShadow:zw,pointUV:uC,pointWidth:BM,positionGeometry:Ic,positionLocal:Ve,positionPrevious:_o,positionView:qe,positionViewDirection:Ce,positionWorld:li,positionWorldDirection:Ox,posterize:SC,pow:cs,pow2:vx,pow3:HT,pow4:wx,premultiplyAlpha:kv,property:Ui,quadBroadcast:RE,quadSwapDiagonal:SE,quadSwapX:_E,quadSwapY:TE,radians:IT,rand:jT,range:OC,rangeFogFactor:Tw,reciprocal:VT,reference:Ie,referenceBuffer:Qf,reflect:WT,reflectVector:DS,reflectView:IS,reflector:JR,refract:Ax,refractVector:LS,refractView:PS,reinhardToneMapping:mw,remap:gS,remapClamp:yS,renderGroup:J,renderOutput:Ix,rendererReference:uS,replaceDefaultUV:WR,rotate:Pc,rotateUV:$R,roughness:ii,round:OT,rtt:lw,sRGBTransferEOTF:aS,sRGBTransferOETF:cS,sample:iC,sampler:jM,samplerComparison:ZM,saturate:ud,saturation:xC,screenCoordinate:gr,screenDPR:TS,screenSize:hr,screenUV:ci,select:vt,setCurrentStack:pc,setName:Rx,shaderStages:gf,shadow:Ow,shadowPositionWorld:u0,shapeCircle:WE,sharedUniformGroup:ad,sheen:Kt,sheenRoughness:ln,shiftLeft:wT,shiftRight:MT,shininess:th,sign:yx,sin:Bt,sinc:RR,skinning:Fv,smoothstep:Fs,smoothstepElement:JT,specularColor:_n,specularColorBlended:sr,specularF90:ir,spherizeUV:qR,split:CM,spritesheetUV:YR,sqrt:It,stack:Xu,step:ur,stepElement:QT,storage:xn,storageBarrier:qC,storageTexture:dw,string:NM,struct:mR,sub:he,subBuild:cr,subgroupAdd:oE,subgroupAll:yE,subgroupAnd:dE,subgroupAny:xE,subgroupBallot:rE,subgroupBroadcast:vE,subgroupBroadcastFirst:bE,subgroupElect:nE,subgroupExclusiveAdd:cE,subgroupExclusiveMul:hE,subgroupInclusiveAdd:aE,subgroupInclusiveMul:uE,subgroupIndex:BA,subgroupMax:gE,subgroupMin:mE,subgroupMul:lE,subgroupOr:pE,subgroupShuffle:wE,subgroupShuffleDown:NE,subgroupShuffleUp:AE,subgroupShuffleXor:ME,subgroupSize:WC,subgroupXor:fE,tan:DT,tangentGeometry:fd,tangentLocal:vo,tangentView:md,tangentWorld:qS,texture:xe,texture3D:Td,texture3DLevel:fC,texture3DLoad:pC,textureBarrier:HC,textureBicubic:_N,textureBicubicLevel:t0,textureCubeUV:Zv,textureLevel:YM,textureLoad:Ge,textureSize:yn,textureStore:hC,thickness:ox,time:Eo,toneMapping:hS,toneMappingExposure:dS,toonOutlinePass:NC,transformDirection:XT,transformNormal:BS,transformNormalToView:kx,transformedClearcoatNormalView:gA,transformedNormalView:fA,transformedNormalWorld:mA,transmission:sh,transpose:kT,triNoise3D:LR,triplanarTexture:jR,triplanarTextures:cw,trunc:Tx,uint:D,uintBitsToFloat:TR,uniform:j,uniformArray:St,uniformCubeTexture:yA,uniformFlow:KT,uniformGroup:oT,uniformTexture:XM,unpackHalf2x16:PR,unpackNormal:sm,unpackSnorm2x16:FR,unpackUnorm2x16:IR,unpremultiplyAlpha:eN,userData:mC,uv:Re,uvec2:tx,uvec3:mr,uvec4:rx,varying:Sn,varyingProperty:fc,vec2:U,vec3:v,vec4:Z,vectorComponents:fr,velocity:gC,vertexColor:Vv,vertexIndex:Rv,vertexStage:oS,vibrance:bC,viewZToLogarithmicDepth:Zx,viewZToOrthographicDepth:xo,viewZToPerspectiveDepth:Yx,viewZToReversedOrthographicDepth:kA,viewZToReversedPerspectiveDepth:Uv,viewport:Lx,viewportCoordinate:SS,viewportDepthTexture:Xx,viewportLinearDepth:WA,viewportMipTexture:Hx,viewportOpaqueMipTexture:Lv,viewportResolution:QM,viewportSafeUV:XR,viewportSharedTexture:vC,viewportSize:Ux,viewportTexture:OA,viewportUV:JM,vogelDiskSample:Cs,wgsl:IC,wgslFn:LC,workgroupArray:XC,workgroupBarrier:$C,workgroupId:kC,workingToColorSpace:lS,xor:bT}),Ns=new Tc,Bg=class extends fi{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){let i=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background,r=!1;if(n===null)i._clearColor.getRGB(Ns),Ns.a=i._clearColor.a;else if(n.isColor===!0)n.getRGB(Ns),Ns.a=1,r=!0;else if(n.isNode===!0){let c=this.get(e),l=n;Ns.copy(i._clearColor);let u=c.backgroundMesh;if(u===void 0){let w=function(){n.removeEventListener("dispose",w),u.material.dispose(),u.geometry.dispose()},d=Z(l).mul(mg).context({getUV:()=>hw.mul(ES),getTextureLevel:()=>uw}),p=Oi.element(3).element(3).equal(1),m=ss(1,Oi.element(1).element(1)).mul(3),g=p.select(Ve.mul(m),Ve),y=wn.mul(Z(g,0)),x=Oi.mul(Z(y.xyz,1));x=x.setZ(x.w);let _=new Ne;_.name="Background.material",_.side=rt,_.depthTest=!1,_.depthWrite=!1,_.allowOverride=!1,_.fog=!1,_.lights=!1,_.vertexNode=x,_.colorNode=d,c.backgroundMeshNode=d,c.backgroundMesh=u=new Zt(new Ml(1,32,32),_),u.frustumCulled=!1,u.name="Background.mesh",n.addEventListener("dispose",w)}let h=l.getCacheKey();c.backgroundCacheKey!==h&&(c.backgroundMeshNode.node=Z(l).mul(mg),c.backgroundMeshNode.needsUpdate=!0,u.material.needsUpdate=!0,c.backgroundCacheKey=h),t.unshift(u,u.geometry,u.material,0,0,null,null)}else O("Renderer: Unsupported background configuration.",n);let a=i.xr.getEnvironmentBlendMode();if(a==="additive"?Ns.set(0,0,0,1):a==="alpha-blend"&&Ns.set(0,0,0,0),i.autoClear===!0||r===!0){let c=s.clearColorValue;c.r=Ns.r,c.g=Ns.g,c.b=Ns.b,c.a=Ns.a,(i.backend.isWebGLBackend===!0||i.alpha===!0)&&(c.r*=c.a,c.g*=c.a,c.b*=c.a),s.depthClearValue=i.getClearDepth(),s.stencilClearValue=i.getClearStencil(),s.clearColor=i.autoClearColor===!0,s.clearDepth=i.autoClearDepth===!0,s.clearStencil=i.autoClearStencil===!0}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}},MF=0,Mc=class{constructor(e="",t=[],s=0){this.name=e,this.bindings=t,this.index=s,this.id=MF++}},Fg=class{constructor(e,t,s,i,n,r,a,c,l,u=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=n,this.updateNodes=r,this.updateBeforeNodes=a,this.updateAfterNodes=c,this.observer=l,this.usedTimes=0}createBindings(){let e=[];for(let t of this.bindings)if(t.bindings[0].groupNode.shared!==!0){let i=new Mc(t.name,[],t.index);e.push(i);for(let n of t.bindings)i.bindings.push(n.clone())}else e.push(t);return e}},Dh=class{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}},Ig=class{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}},Lh=class{constructor(e,t,s=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=s,this.count=i}},Pg=class extends Lh{constructor(e,t,s=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=s,this.interpolationSampling=i}},Dg=class{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}},AF=0,uc=class{constructor(e=null){this.id=AF++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return t===void 0&&this.parent!==null&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}},Lg=class{constructor(e,t){this.name=e,this.members=t,this.output=!1}},gi=class{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}},Ug=class extends gi{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}},Og=class extends gi{constructor(e,t=new re){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}},Vg=class extends gi{constructor(e,t=new R){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}},kg=class extends gi{constructor(e,t=new Te){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}},zg=class extends gi{constructor(e,t=new ge){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}},Gg=class extends gi{constructor(e,t=new oa){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}},Wg=class extends gi{constructor(e,t=new Nt){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}},$g=class extends gi{constructor(e,t=new de){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}},qg=class extends Ug{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Hg=class extends Og{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Xg=class extends Vg{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Yg=class extends kg{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},jg=class extends zg{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Zg=class extends Gg{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Jg=class extends Wg{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},Qg=class extends $g{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}},NF=0,T_=new WeakMap,RF=new WeakMap,CF=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),Uu=o=>/e/g.test(o)?String(o).replace(/\+/g,""):(o=Number(o),o+(o%1?"":".0")),Uh=class{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=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.types={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=Xu(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new uc,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:NF++})}isFlatShading(){return this.material.flatShading===!0||this.geometry.hasAttribute("normal")===!1}isOpaque(){let e=this.material;return e.transparent===!1&&e.blending===Ht&&e.alphaToCoverage===!1}createRenderTarget(e,t,s){return new bt(e,t,s)}createCubeRenderTarget(e,t){return new gh(e,t)}includes(e){return this.nodes.includes(e)}getOutputStructName(){}_getBindGroup(e,t){let s=t[0].groupNode,i=s.shared;if(i)for(let r=1;r<t.length;r++)s!==t[r].groupNode&&(i=!1);let n;if(i){let r="";for(let u of t)if(u.isNodeUniformsGroup){u.uniforms.sort((h,d)=>h.nodeUniform.node.id-d.nodeUniform.node.id);for(let h of u.uniforms)r+=h.nodeUniform.node.id}else r+=u.nodeUniform.id;let a=this.renderer._currentRenderContext||this.renderer,c=T_.get(a);c===void 0&&(c=new Map,T_.set(a,c));let l=Ro(r);n=c.get(l),n===void 0&&(n=new Mc(e,t,this.bindingsIndexes[e].group),c.set(l,n))}else n=new Mc(e,t,this.bindingsIndexes[e].group);return n}getBindGroupArray(e,t){let s=this.bindings[t],i=s[e];return i===void 0&&(this.bindingsIndexes[e]===void 0&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(e===null){let t={},s=this.bindings;for(let i of gf)for(let n in s[i]){let r=s[i][n],a=t[n]||(t[n]=[]);for(let c of r)a.includes(c)===!1&&a.push(c)}e=[];for(let i in t){let n=t[i],r=this._getBindGroup(i,n);e.push(r)}this.bindGroups=e}return e}sortBindingGroups(){let e=this.getBindings();e.sort((t,s)=>t.bindings[0].groupNode.order-s.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){let s=e[t];this.bindingsIndexes[s.name].group=t,s.index=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){this.nodes.includes(e)===!1&&(this.nodes.push(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){let t=e.getUpdateBeforeType(),s=e.getUpdateAfterType();(t!==te.NONE||s!==te.NONE)&&this.sequentialNodes.includes(e)===!1&&this.sequentialNodes.push(e)}buildUpdateNodes(){for(let e of this.nodes)e.getUpdateType()!==te.NONE&&this.updateNodes.push(e);for(let e of this.sequentialNodes){let t=e.getUpdateBeforeType(),s=e.getUpdateAfterType();t!==te.NONE&&this.updateBeforeNodes.push(e),s!==te.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(e){return e.magFilter===ct||e.magFilter===ru||e.magFilter===$r||e.magFilter===Ci||e.minFilter===ct||e.minFilter===ru||e.minFilter===$r||e.minFilter===Ci}getUniformBufferLimit(){return 16384}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getTernary(){return null}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}addContext(e){let t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){let e={...this.context};return delete e.material,delete e.getUV,delete e.getOutput,delete e.getTextureLevel,delete e.getAO,delete e.getShadow,e}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){let s=this.getDataFromNode(e);return s.cache===void 0&&(s.cache=new uc(t?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){z("Abstract function.")}getInstanceIndex(){z("Abstract function.")}getDrawIndex(){z("Abstract function.")}getFrontFacing(){z("Abstract function.")}getFragCoord(){z("Abstract function.")}isFlipY(){return!1}increaseUsage(e){let t=this.getDataFromNode(e);return t.usageCount=t.usageCount===void 0?1:t.usageCount+1,t.usageCount}generateTexture(){z("Abstract function.")}generateTextureLod(){z("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,s=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let n=0;n<t;n++){let r=s?s[n]:null;r!==null?i+=r.build(this,e):i+=this.generateConst(e),n<t-1&&(i+=", ")}return i+=" )",i}generateStruct(e,t,s=null){let i=[];for(let n of t){let{name:r,type:a}=n;s&&s[r]&&s[r].isNode?i.push(s[r].build(this,a)):i.push(this.generateConst(a))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(t===null&&(e==="float"||e==="int"||e==="uint"?t=0:e==="bool"?t=!1:e==="color"?t=new ge:e==="vec2"||e==="uvec2"||e==="ivec2"?t=new re:e==="vec3"||e==="uvec3"||e==="ivec3"?t=new R:(e==="vec4"||e==="uvec4"||e==="ivec4")&&(t=new Te)),e==="float")return Uu(t);if(e==="int")return`${Math.round(t)}`;if(e==="uint")return t>=0?`${Math.round(t)}u`:"0u";if(e==="bool")return t?"true":"false";if(e==="color")return`${this.getType("vec3")}( ${Uu(t.r)}, ${Uu(t.g)}, ${Uu(t.b)} )`;let s=this.getTypeLength(e),i=this.getComponentType(e),n=r=>this.generateConst(i,r);if(s===2)return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)} )`;if(s===3)return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)}, ${n(t.z)} )`;if(s===4&&e!=="mat2")return`${this.getType(e)}( ${n(t.x)}, ${n(t.y)}, ${n(t.z)}, ${n(t.w)} )`;if(s>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(n).join(", ")} )`;if(s>4)return`${this.getType(e)}()`;throw new Error(`NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return e==="color"?"vec3":e}hasGeometryAttribute(e){return this.geometry&&this.geometry.getAttribute(e)!==void 0}getAttribute(e,t){let s=this.attributes;for(let n of s)if(n.name===e)return n;let i=new Dh(e,t);return this.registerDeclaration(i),s.push(i),i}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return e==="void"||e==="property"||e==="sampler"||e==="samplerComparison"||e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="depthTexture"||e==="texture3D"}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){let t=e.type;if(e.isDataTexture){if(t===ut)return"int";if(t===Oe)return"uint"}return"float"}getElementType(e){return e==="mat2"?"vec2":e==="mat3"?"vec3":e==="mat4"?"vec4":this.getComponentType(e)}getComponentType(e){if(e=this.getVectorType(e),e==="float"||e==="bool"||e==="int"||e==="uint")return e;let t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return t===null?null:t[1]==="b"?"bool":t[1]==="i"?"int":t[1]==="u"?"uint":"float"}getVectorType(e){return e==="color"?"vec3":e==="texture"||e==="cubeTexture"||e==="storageTexture"||e==="texture3D"?"vec4":e}getTypeFromLength(e,t="float"){if(e===1)return t;let s=Y_(e),i=t==="float"?"":t[0];return/mat2/.test(t)===!0&&(s=s.replace("vec","mat")),i+s}getTypeFromArray(e){return CF.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);let s=t.array,i=e.itemSize,n=e.normalized,r;return!(e instanceof Zo)&&n!==!0&&(r=this.getTypeFromArray(s)),this.getTypeFromLength(i,r)}getTypeLength(e){let t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return s!==null?Number(s[1]):t==="float"||t==="bool"||t==="int"||t==="uint"?1:/mat2/.test(e)===!0?4:/mat3/.test(e)===!0?9:/mat4/.test(e)===!0?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){let t=this.getComponentType(e);return t==="int"||t==="uint"?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw new Error("NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=Xu(this.stack);let e=ex();return this.stacks.push(e),pc(this.stack),this.stack}removeStack(){let e=this.stack;for(let t of e.nodes){let s=this.getDataFromNode(t);s.stack=e}return this.stack=e.parent,pc(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){s=s===null?e.isGlobal(this)?this.globalCache:this.cache:s;let i=s.getData(e);i===void 0&&(i={},s.setData(e,i)),i[t]===void 0&&(i[t]={});let n=i[t],r=i.any?i.any.subBuilds:null,a=this.getClosestSubBuild(r);return a&&(n.subBuildsCache===void 0&&(n.subBuildsCache={}),n=n.subBuildsCache[a]||(n.subBuildsCache[a]={}),n.subBuilds=r),n}getNodeProperties(e,t="any"){let s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){let s=this.getDataFromNode(e,"vertex"),i=s.bufferAttribute;if(i===void 0){let n=this.uniforms.index++;i=new Dh("nodeAttribute"+n,t,e),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,s=null,i=this.shaderStage){let n=this.getDataFromNode(e,i,this.globalCache),r=n.structType;if(r===void 0){let a=this.structs.index++;s===null&&(s="StructType"+a),r=new Lg(s,t),this.structs[i].push(r),this.types[i][s]=e,n.structType=r}return r}getOutputStructTypeFromNode(e,t){let s=this.getStructTypeFromNode(e,t,"OutputType","fragment");return s.output=!0,s}getUniformFromNode(e,t,s=this.shaderStage,i=null){let n=this.getDataFromNode(e,s,this.globalCache),r=n.uniform;if(r===void 0){let a=this.uniforms.index++;r=new Ig(i||"nodeUniform"+a,t,e),this.uniforms[s].push(r),this.registerDeclaration(r),n.uniform=r}return r}getVarFromNode(e,t=null,s=e.getNodeType(this),i=this.shaderStage,n=!1){let r=this.getDataFromNode(e,i),a=this.getSubBuildProperty("variable",r.subBuilds),c=r[a];if(c===void 0){let l=n?"_const":"_var",u=this.vars[i]||(this.vars[i]=[]),h=this.vars[l]||(this.vars[l]=0);t===null&&(t=(n?"nodeConst":"nodeVar")+h,this.vars[l]++),a!=="variable"&&(t=this.getSubBuildProperty(t,r.subBuilds));let d=e.getArrayCount(this);c=new Lh(t,s,n,d),n||u.push(c),this.registerDeclaration(c),r[a]=c}return c}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0)&&(e.cNode?this.isDeterministic(e.cNode):!0);if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(e.bNode?this.isDeterministic(e.bNode):!0);if(e.isArrayNode){if(e.values!==null){for(let t of e.values)if(!this.isDeterministic(t))return!1}return!0}else if(e.isConstNode)return!0;return!1}getVaryingFromNode(e,t=null,s=e.getNodeType(this),i=null,n=null){let r=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",r.subBuilds),c=r[a];if(c===void 0){let l=this.varyings,u=l.length;t===null&&(t="nodeVarying"+u),a!=="varying"&&(t=this.getSubBuildProperty(t,r.subBuilds)),c=new Pg(t,s,i,n),l.push(c),this.registerDeclaration(c),r[a]=c}return c}registerDeclaration(e){let t=this.shaderStage,s=this.declarations[t]||(this.declarations[t]={}),i=this.getPropertyName(e),n=1,r=i;for(;s[r]!==void 0;)r=i+"_"+n++;n>1&&(e.name=r,z(`TSL: Declaration name '${i}' of '${e.type}' already in use. Renamed to '${r}'.`)),s[r]=e}getCodeFromNode(e,t,s=this.shaderStage){let i=this.getDataFromNode(e),n=i.code;if(n===void 0){let r=this.codes[s]||(this.codes[s]=[]),a=r.length;n=new Dg("nodeCode"+a,t),r.push(n),i.code=n}return n}addFlowCodeHierarchy(e,t){let{flowCodes:s,flowCodeBlock:i}=this.getDataFromNode(e),n=!0,r=t;for(;r;){if(i.get(r)===!0){n=!1;break}r=this.getDataFromNode(r).parentNodeBlock}if(n)for(let a of s)this.addLineFlowCode(a)}addLineFlowCodeBlock(e,t,s){let i=this.getDataFromNode(e),n=i.flowCodes||(i.flowCodes=[]),r=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);n.push(t),r.set(s,!0)}addLineFlowCode(e,t=null){return e===""?this:(t!==null&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e=e+`;
|
|
`),this.flow.code+=e,this)}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){let t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}addInclude(e){this.currentFunctionNode!==null&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){let t=new Eh,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){let t=e.layout,s={[Symbol.iterator](){let r=0,a=Object.values(this);return{next:()=>({value:a[r],done:r++>=a.length})}}};for(let r of t.inputs)s[r.name]=new wh(r.type,r.name);e.layout=null;let i=e.call(s),n=this.flowStagesNode(i,t.type);return e.layout=t,n}flowBuildStage(e,t,s=null){let i=this.getBuildStage();this.setBuildStage(t);let n=e.build(this,s);return this.setBuildStage(i),n}flowStagesNode(e,t=null){let s=this.flow,i=this.vars,n=this.declarations,r=this.cache,a=this.buildStage,c=this.stack,l={code:""};this.flow=l,this.vars={},this.declarations={},this.cache=new uc,this.stack=Xu();for(let u of mf)this.setBuildStage(u),l.result=e.build(this,t);return l.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.declarations=n,this.cache=r,this.stack=c,this.setBuildStage(a),l}getFunctionOperator(){return null}buildFunctionCode(){z("Abstract function.")}flowChildNode(e,t=null){let s=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=s,i}flowNodeFromShaderStage(e,t,s=null,i=null){let n=this.tab,r=this.cache,a=this.shaderStage,c=this.context;this.setShaderStage(e);let l={...this.context};delete l.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=l;let u=null;if(this.buildStage==="generate"){let h=this.flowChildNode(t,s);i!==null&&(h.code+=`${this.tab+i} = ${h.result};
|
|
`),this.flowCode[e]=this.flowCode[e]+h.code,u=h}else u=t.build(this);return this.setShaderStage(a),this.cache=r,this.tab=n,this.context=c,u}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){z("Abstract function.")}getVaryings(){z("Abstract function.")}getVar(e,t,s=null){return`${s!==null?this.generateArrayDeclaration(e,s):this.getType(e)} ${t}`}getVars(e){let t="",s=this.vars[e];if(s!==void 0)for(let i of s)t+=`${this.getVar(i.type,i.name)}; `;return t}getUniforms(){z("Abstract function.")}getCodes(e){let t=this.codes[e],s="";if(t!==void 0)for(let i of t)s+=i.code+`
|
|
`;return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){z("Abstract function.")}get subBuild(){return this.subBuildLayers[this.subBuildLayers.length-1]||null}addSubBuild(e){this.subBuildLayers.push(e)}removeSubBuild(){return this.subBuildLayers.pop()}getClosestSubBuild(e){let t;if(e&&e.isNode?e.isShaderCallNodeInternal?t=e.shaderNode.subBuilds:e.isStackNode?t=[e.subBuild]:t=this.getDataFromNode(e,"any").subBuilds:e instanceof Set?t=[...e]:t=e,!t)return null;let s=this.subBuildLayers;for(let i=t.length-1;i>=0;i--){let n=t[i];if(s.includes(n))return n}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let s;t!==null?s=this.getClosestSubBuild(t):s=this.subBuildFn;let i;return s?i=e?s+"_"+e:s:i=e,i}build(){let{object:e,material:t,renderer:s}=this;if(t!==null){let i=s.library.fromMaterial(t);i===null&&(O(`NodeMaterial: Material "${t.type}" is not compatible.`),i=new Ne),i.build(this)}else this.addFlow("compute",e);for(let i of mf){this.setBuildStage(i),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position);for(let n of gf){this.setShaderStage(n);let r=this.flowNodes[n];for(let a of r)i==="generate"?this.flowNode(a):a.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=RF.get(e);return t===void 0&&(t={}),t}getNodeUniform(e,t){let s=this.getSharedDataFromNode(e),i=s.cache;if(i===void 0){if(t==="float"||t==="int"||t==="uint")i=new qg(e);else if(t==="vec2"||t==="ivec2"||t==="uvec2")i=new Hg(e);else if(t==="vec3"||t==="ivec3"||t==="uvec3")i=new Xg(e);else if(t==="vec4"||t==="ivec4"||t==="uvec4")i=new Yg(e);else if(t==="color")i=new jg(e);else if(t==="mat2")i=new Zg(e);else if(t==="mat3")i=new Jg(e);else if(t==="mat4")i=new Qg(e);else throw new Error(`Uniform "${t}" not implemented.`);s.cache=i}return i}format(e,t,s){if(t=this.getVectorType(t),s=this.getVectorType(s),t===s||s===null||this.isReference(s))return e;let i=this.getTypeLength(t),n=this.getTypeLength(s);return i===16&&n===9?`${this.getType(s)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:i===9&&n===4?`${this.getType(s)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||n>4||n===0?e:i===n?`${this.getType(s)}( ${e} )`:i>n?(e=s==="bool"?`all( ${e} )`:`${e}.${"xyz".slice(0,n)}`,this.format(e,this.getTypeFromLength(n,this.getComponentType(t)),s)):n===4&&i>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:i===2?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(i===1&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${"183"} - Node System
|
|
`}needsPreviousData(){let e=this.renderer.getMRT();return e&&e.has("velocity")||Z_(this.object).useVelocity===!0}},Oh=class{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return s===void 0&&(s={renderId:0,frameId:0},e.set(t,s)),s}updateBeforeNode(e){let t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===te.FRAME){let i=this._getMaps(this.updateBeforeMap,s);if(i.frameId!==this.frameId){let n=i.frameId;i.frameId=this.frameId,e.updateBefore(this)===!1&&(i.frameId=n)}}else if(t===te.RENDER){let i=this._getMaps(this.updateBeforeMap,s);if(i.renderId!==this.renderId){let n=i.renderId;i.renderId=this.renderId,e.updateBefore(this)===!1&&(i.renderId=n)}}else t===te.OBJECT&&e.updateBefore(this)}updateAfterNode(e){let t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===te.FRAME){let i=this._getMaps(this.updateAfterMap,s);i.frameId!==this.frameId&&e.updateAfter(this)!==!1&&(i.frameId=this.frameId)}else if(t===te.RENDER){let i=this._getMaps(this.updateAfterMap,s);i.renderId!==this.renderId&&e.updateAfter(this)!==!1&&(i.renderId=this.renderId)}else t===te.OBJECT&&e.updateAfter(this)}updateNode(e){let t=e.getUpdateType(),s=e.updateReference(this);if(t===te.FRAME){let i=this._getMaps(this.updateMap,s);i.frameId!==this.frameId&&e.update(this)!==!1&&(i.frameId=this.frameId)}else if(t===te.RENDER){let i=this._getMaps(this.updateMap,s);i.renderId!==this.renderId&&e.update(this)!==!1&&(i.renderId=this.renderId)}else t===te.OBJECT&&e.update(this)}update(){this.frameId++,this.lastTime===void 0&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}},Ac=class{constructor(e,t,s=null,i="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=i,this.isConst=n}};Ac.isNodeFunctionInput=!0;var Kg=class extends Wi{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}},ey=class extends Wi{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){let e=this.colorNode;return{lightDirection:l0(this.light),lightColor:e}}},ty=class extends Wi{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=a0(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=j(new ge).setGroup(J)}update(e){let{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){let{colorNode:t,groundColorNode:s,lightDirectionNode:i}=this,r=Mn.dot(i).mul(.5).add(.5),a=le(s,t,r);e.context.irradiance.addAssign(a)}},Nc=class extends Wi{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=j(0).setGroup(J),this.penumbraCosNode=j(0).setGroup(J),this.cutoffDistanceNode=j(0).setGroup(J),this.decayExponentNode=j(0).setGroup(J),this.colorNode=j(this.color).setGroup(J)}update(e){super.update(e);let{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){let{coneCosNode:s,penumbraCosNode:i}=this;return Fs(s,i,t)}getLightCoord(e){let t=e.getNodeProperties(this),s=t.projectionUV;return s===void 0&&(s=vw(this.light,e.context.positionWorld),t.projectionUV=s),s}setupDirect(e){let{colorNode:t,cutoffDistanceNode:s,decayExponentNode:i,light:n}=this,r=this.getLightVector(e),a=r.normalize(),c=a.dot(l0(n)),l=this.getSpotAttenuation(e,c),u=r.length(),h=f0({lightDistance:u,cutoffDistance:s,decayExponent:i}),d=t.mul(l).mul(h),p,m;return n.colorNode?(m=this.getLightCoord(e),p=n.colorNode(m)):n.map&&(m=this.getLightCoord(e),p=xe(n.map,m.xy).onRenderUpdate(()=>n.map)),p&&(d=m.mul(2).sub(1).abs().lessThan(1).all().select(d.mul(p),d)),{lightColor:d,lightDirection:a}}},sy=class extends Nc{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e,t){let s=this.light.iesMap,i=null;if(s&&s.isTexture===!0){let n=t.acos().mul(1/Math.PI);i=xe(s,U(n,0),0).r}else i=super.getSpotAttenuation(t);return i}},iy=class extends Wi{static get type(){return"LightProbeNode"}constructor(e=null){super(e);let t=[];for(let s=0;s<9;s++)t.push(new R);this.lightProbe=St(t)}update(e){let{light:t}=this;super.update(e);for(let s=0;s<9;s++)this.lightProbe.array[s].copy(t.sh.coefficients[s]).multiplyScalar(t.intensity)}setup(e){let t=Jw(Mn,this.lightProbe);e.context.irradiance.addAssign(t)}},EF=A(([o,e])=>{let t=o.abs().sub(e);return ai(ze(t,0)).add(Vt(ze(t.x,t.y),0))}),ny=class extends Nc{static get type(){return"ProjectorLightNode"}update(e){super.update(e);let t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),t.aspect===null){let s=1;t.map!==null&&(s=t.map.width/t.map.height),t.shadow.aspect=s}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){let t=b(0),s=this.penumbraCosNode,i=wd(this.light).mul(e.context.positionWorld||li);return K(i.w.greaterThan(0),()=>{let n=i.xyz.div(i.w),r=EF(n.xy.sub(U(.5)),U(.5)),a=ss(-1,he(1,mx(s)).sub(1));t.assign(ud(r.mul(-2).mul(a)))}),t}},sf=new de,Ou=new de,Ja=null,ry=class extends Wi{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=j(new R).setGroup(J),this.halfWidth=j(new R).setGroup(J),this.updateType=te.RENDER}update(e){super.update(e);let{light:t}=this,s=e.camera.matrixWorldInverse;Ou.identity(),sf.copy(t.matrixWorld),sf.premultiply(s),Ou.extractRotation(sf),this.halfWidth.value.set(t.width*.5,0,0),this.halfHeight.value.set(0,t.height*.5,0),this.halfWidth.value.applyMatrix4(Ou),this.halfHeight.value.applyMatrix4(Ou)}setupDirectRectArea(e){let t,s;e.isAvailable("float32Filterable")?(t=xe(Ja.LTC_FLOAT_1),s=xe(Ja.LTC_FLOAT_2)):(t=xe(Ja.LTC_HALF_1),s=xe(Ja.LTC_HALF_2));let{colorNode:i,light:n}=this,r=c0(n);return{lightColor:i,lightPosition:r,halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:s}}static setLTC(e){Ja=e}},Vh=class{parseFunction(){z("Abstract function.")}},Rc=class{constructor(e,t,s="",i=""){this.type=e,this.inputs=t,this.name=s,this.precision=i}getCode(){z("Abstract function.")}};Rc.isNodeFunction=!0;var BF=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,FF=/[a-z_0-9]+/ig,S_="#pragma main",IF=o=>{o=o.trim();let e=o.indexOf(S_),t=e!==-1?o.slice(e+S_.length):o,s=t.match(BF);if(s!==null&&s.length===5){let i=s[4],n=[],r=null;for(;(r=FF.exec(i))!==null;)n.push(r);let a=[],c=0;for(;c<n.length;){let m=n[c][0]==="const";m===!0&&c++;let g=n[c][0];g==="in"||g==="out"||g==="inout"?c++:g="";let y=n[c++][0],x=Number.parseInt(n[c][0]);Number.isNaN(x)===!1?c++:x=null;let _=n[c++][0];a.push(new Ac(y,_,x,g,m))}let l=t.substring(s[0].length),u=s[3]!==void 0?s[3]:"",h=s[2],d=s[1]!==void 0?s[1]:"",p=e!==-1?o.slice(0,e):"";return{type:h,inputs:a,name:u,precision:d,inputsCode:i,blockCode:l,headerCode:p}}else throw new Error("FunctionNode: Function is not a GLSL code.")},oy=class extends Rc{constructor(e){let{type:t,inputs:s,name:i,precision:n,inputsCode:r,blockCode:a,headerCode:c}=IF(e);super(t,s,i,n),this.inputsCode=r,this.blockCode=a,this.headerCode=c}getCode(e=this.name){let t,s=this.blockCode;if(s!==""){let{type:i,inputsCode:n,headerCode:r,precision:a}=this,c=`${i} ${e} ( ${n.trim()} )`;a!==""&&(c=`${a} ${c}`),t=r+c+s}else t="";return t}},ay=class extends Vh{parseFunction(e){return new oy(e)}},v_=new WeakMap,rs=[],on=[],cy=class extends fi{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new Oh,this.nodeBuilderCache=new Map,this.callHashCache=new pi,this.groupsData=new pi,this.cacheLib={}}updateGroup(e){let t=e.groupNode,s=t.name;if(s===ux.name)return!0;if(s===J.name){let n=this.get(e),r=this.nodeFrame.renderId;return n.renderId!==r?(n.renderId=r,!0):!1}if(s===aT.name){let n=this.get(e),r=this.nodeFrame.frameId;return n.frameId!==r?(n.frameId=r,!0):!1}rs[0]=t,rs[1]=e;let i=this.groupsData.get(rs);return i===void 0&&this.groupsData.set(rs,i={}),rs[0]=null,rs[1]=null,i.version!==t.version?(i.version=t.version,!0):!1}getForRenderCacheKey(e){return e.initialCacheKey}getForRender(e){let t=this.get(e),s=t.nodeBuilderState;if(s===void 0){let{nodeBuilderCache:i}=this,n=this.getForRenderCacheKey(e);if(s=i.get(n),s===void 0){let r=c=>{let l=this.backend.createNodeBuilder(e.object,this.renderer);return l.scene=e.scene,l.material=c,l.camera=e.camera,l.context.material=c,l.lightsNode=e.lightsNode,l.environmentNode=this.getEnvironmentNode(e.scene),l.fogNode=this.getFogNode(e.scene),l.clippingContext=e.clippingContext,this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview&&l.enableMultiview(),l},a=r(e.material);try{a.build()}catch(c){a=r(new Ne),a.build();let l=c.stackTrace;!l&&c.stack&&(l=new ke(c.stack)),O("TSL: "+c,l)}s=this._createNodeBuilderState(a),i.set(n,s)}s.usedTimes++,t.nodeBuilderState=s}return s}delete(e){if(e.isRenderObject){let t=this.get(e).nodeBuilderState;t.usedTimes--,t.usedTimes===0&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e))}return super.delete(e)}getForCompute(e){let t=this.get(e),s=t.nodeBuilderState;if(s===void 0){let i=this.backend.createNodeBuilder(e,this.renderer);i.build(),s=this._createNodeBuilderState(i),t.nodeBuilderState=s}return s}_createNodeBuilderState(e){return new Fg(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.transforms)}getEnvironmentNode(e){this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{let s=this.get(e);s.environmentNode&&(t=s.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{let s=this.get(e);s.backgroundNode&&(t=s.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){rs[0]=e,rs[1]=t;let s=this.renderer.info.calls,i=this.callHashCache.get(rs)||{};if(i.callId!==s){let n=this.getEnvironmentNode(e),r=this.getFogNode(e);t&&on.push(t.getCacheKey(!0)),n&&on.push(n.getCacheKey()),r&&on.push(r.getCacheKey()),on.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),on.push(this.renderer.shadowMap.enabled?1:0),on.push(this.renderer.shadowMap.type),i.callId=s,i.cacheKey=Ec(on),this.callHashCache.set(rs,i),on.length=0}return rs[0]=null,rs[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){let t=this.get(e),s=e.background;if(s){let i=e.backgroundBlurriness===0&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&t.backgroundBlurriness===0;if(t.background!==s||i){let n=this.getCacheNode("background",s,()=>{if(s.isCubeTexture===!0||s.mapping===su||s.mapping===iu||s.mapping===nu){if(e.backgroundBlurriness>0||s.mapping===nu)return s0(s);{let r;return s.isCubeTexture===!0?r=Ft(s):r=xe(s),Gv(r)}}else{if(s.isTexture===!0)return xe(s,ci.flipY()).setUpdateMatrix(!0);s.isColor!==!0&&O("WebGPUNodes: Unsupported background configuration.",s)}},i);t.backgroundNode=n,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,s,i=!1){let n=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap),r=n.get(t);return(r===void 0||i)&&(r=s(),n.set(t,r)),r}updateFog(e){let t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let i=this.getCacheNode("fog",s,()=>{if(s.isFogExp2){let n=Ie("color","color",s).setGroup(J),r=Ie("density","float",s).setGroup(J);return Sg(n,Sw(r))}else if(s.isFog){let n=Ie("color","color",s).setGroup(J),r=Ie("near","float",s).setGroup(J),a=Ie("far","float",s).setGroup(J);return Sg(n,Tw(r,a))}else O("Renderer: Unsupported fog configuration.",s)});t.fogNode=i,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){let t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let i=this.getCacheNode("environment",s,()=>{if(s.isCubeTexture===!0)return Ft(s);if(s.isTexture===!0)return xe(s);O("Nodes: Unsupported environment configuration.",s)});t.environmentNode=i,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,i=null,n=null){let r=this.nodeFrame;return r.renderer=e,r.scene=t,r.object=s,r.camera=i,r.material=n,r}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){let e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}hasOutputChange(e){return v_.get(e)!==this.getOutputCacheKey()}getOutputNode(e){let t=this.renderer,s=this.getOutputCacheKey(),i=e.isArrayTexture?Td(e,v(ci,qi("gl_ViewID_OVR"))).renderOutput(t.toneMapping,t.currentColorSpace):xe(e,ci).renderOutput(t.toneMapping,t.currentColorSpace);return v_.set(e,s),i}updateBefore(e){let t=e.getNodeBuilderState();for(let s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){let t=e.getNodeBuilderState();for(let s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){let t=this.getNodeFrame(),s=this.getForCompute(e);for(let i of s.updateNodes)t.updateNode(i)}updateForRender(e){let t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(let i of s.updateNodes)t.updateNode(i)}needsRefresh(e){let t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new Oh,this.nodeBuilderCache=new Map,this.cacheLib={}}},nf=new xs,kh=class o{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewNormalMatrix=new Nt,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,e!==null&&(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix)}projectPlanes(e,t,s){let i=e.length;for(let n=0;n<i;n++){nf.copy(e[n]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);let r=t[s+n],a=nf.normal;r.x=-a.x,r.y=-a.y,r.z=-a.z,r.w=nf.constant}}updateGlobal(e,t){this.shadowPass=e.overrideMaterial!==null&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix=t.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let s=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);let i=t.clippingPlanes,n=i.length,r,a;if(this.clipIntersection?(r=this.intersectionPlanes,a=e.intersectionPlanes.length):(r=this.unionPlanes,a=e.unionPlanes.length),r.length!==a+n){r.length=a+n;for(let c=0;c<n;c++)r[a+c]=new Te;s=!0}this.projectPlanes(i,r,a),s&&(this.version++,this.cacheKey=`${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return t===void 0&&(t=new o(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}},ly=class{constructor(e,t){this.bundleGroup=e,this.camera=t}},oo=[],uy=class{constructor(){this.bundles=new pi}get(e,t){let s=this.bundles;oo[0]=e,oo[1]=t;let i=s.get(oo);return i===void 0&&(i=new ly(e,t),s.set(oo,i)),oo[0]=null,oo[1]=null,i}dispose(){this.bundles=new pi}},zh=class{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null,s=this.getMaterialNodeClass(e.type);if(s!==null){t=new s;for(let i in e)t[i]=e[i]}return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,s){if(s.has(t)){z(`Redefinition of node ${t}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t=="function"||typeof t=="object")throw new Error(`Base class ${t} is not a class.`);s.set(t,e)}addClass(e,t,s){if(s.has(t)){z(`Redefinition of node ${t.name}`);return}if(typeof e!="function")throw new Error(`Node class ${e.name} is not a class.`);if(typeof t!="function")throw new Error(`Base class ${t.name} is not a class.`);s.set(t,e)}},PF=new wc,w_=new WeakMap,hy=class{createNode(e=[]){return new wc().setLights(e)}getNode(e){if(e.isQuadMesh)return PF;let t=w_.get(e);return t===void 0&&(t=this.createNode(),w_.set(e,t)),t}},rr=class extends bt{constructor(e=1,t=1,s={}){super(e,t,s),this.isXRRenderTarget=!0,this._hasExternalTextures=!1,this._autoAllocateDepthBuffer=!0,this._isOpaqueFramebuffer=!1}copy(e){return super.copy(e),this._hasExternalTextures=e._hasExternalTextures,this._autoAllocateDepthBuffer=e._autoAllocateDepthBuffer,this._isOpaqueFramebuffer=e._isOpaqueFramebuffer,this}},M_=new R,A_=new R,dy=class extends Ts{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new it,this._cameraL.viewport=new Te,this._cameraR=new it,this._cameraR.viewport=new Te,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new Ql,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding=typeof XRWebGLBinding<"u",this._frameBufferTargets=null,this._createXRLayer=kF.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new re,this._onSessionEvent=UF.bind(this),this._onSessionEnd=OF.bind(this),this._onInputSourcesChange=VF.bind(this),this._onAnimationFrame=zF.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){if(!(this._glProjLayer===null&&this._glBaseLayer===null))return this._foveation}setFoveation(e){this._foveation=e,this._glProjLayer!==null&&(this._glProjLayer.fixedFoveation=e),this._glBaseLayer!==null&&this._glBaseLayer.fixedFoveation!==void 0&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,this.isPresenting===!0&&z("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,this.isPresenting===!0&&z("XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(this._session!==null)return this._session.environmentBlendMode}getBinding(){return this._glBinding===null&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,s,i,n,r,a,c={}){let l=new Vr(e,t),u=new rr(n,r,{format:Lt,type:lt,depthTexture:new Rt(n,r,c.stencil?Ei:Oe,void 0,void 0,void 0,void 0,void 0,void 0,c.stencil?Hs:ns),stencilBuffer:c.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});u._autoAllocateDepthBuffer=!0;let h=new ws({color:16777215,side:_s});h.map=u.texture,h.map.offset.y=1,h.map.repeat.y=-1;let d=new Zt(l,h);d.position.copy(s),d.quaternion.copy(i);let p={type:"quad",width:e,height:t,translation:s,quaternion:i,pixelwidth:n,pixelheight:r,plane:d,material:h,rendercall:a,renderTarget:u};if(this._layers.push(p),this._session!==null){p.plane.material=new ws({color:16777215,side:_s}),p.plane.material.blending=$n,p.plane.material.blendEquation=Xt,p.plane.material.blendSrc=Ni,p.plane.material.blendDst=Ni,p.xrlayer=this._createXRLayer(p);let m=this._session.renderState.layers;m.unshift(p.xrlayer),this._session.updateRenderState({layers:m})}else u.isXRRenderTarget=!1;return d}createCylinderLayer(e,t,s,i,n,r,a,c,l={}){let u=new wl(e,e,e*t/s,64,64,!0,Math.PI-t/2,t),h=new rr(r,a,{format:Lt,type:lt,depthTexture:new Rt(r,a,l.stencil?Ei:Oe,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?Hs:ns),stencilBuffer:l.stencil,resolveDepthBuffer:!1,resolveStencilBuffer:!1});h._autoAllocateDepthBuffer=!0;let d=new ws({color:16777215,side:rt});d.map=h.texture,d.map.offset.y=1,d.map.repeat.y=-1;let p=new Zt(u,d);p.position.copy(i),p.quaternion.copy(n);let m={type:"cylinder",radius:e,centralAngle:t,aspectratio:s,translation:i,quaternion:n,pixelwidth:r,pixelheight:a,plane:p,material:d,rendercall:c,renderTarget:h};if(this._layers.push(m),this._session!==null){m.plane.material=new ws({color:16777215,side:rt}),m.plane.material.blending=$n,m.plane.material.blendEquation=Xt,m.plane.material.blendSrc=Ni,m.plane.material.blendDst=Ni,m.xrlayer=this._createXRLayer(m);let g=this._session.renderState.layers;g.unshift(m.xrlayer),this._session.updateRenderState({layers:g})}else h.isXRRenderTarget=!1;return p}renderLayers(){let e=new R,t=new Ss,s=this._renderer,i=this.isPresenting,n=s.getOutputRenderTarget(),r=s._frameBufferTarget;this.isPresenting=!1;let a=new re;s.getSize(a);let c=s._quad;for(let l of this._layers)if(l.renderTarget.isXRRenderTarget=this._session!==null,l.renderTarget._hasExternalTextures=l.renderTarget.isXRRenderTarget,l.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){l.xrlayer.transform=new XRRigidTransform(l.plane.getWorldPosition(e),l.plane.getWorldQuaternion(t));let u=this._glBinding.getSubImage(l.xrlayer,this._xrFrame);s.backend.setXRRenderTargetTextures(l.renderTarget,u.colorTexture,void 0),s._setXRLayerSize(l.renderTarget.width,l.renderTarget.height),s.setOutputRenderTarget(l.renderTarget),s.setRenderTarget(null),s._frameBufferTarget=null,this._frameBufferTargets||(this._frameBufferTargets=new WeakMap);let{frameBufferTarget:h,quad:d}=this._frameBufferTargets.get(l.renderTarget)||{frameBufferTarget:null,quad:null};h?(s._frameBufferTarget=h,s._quad=d):(s._quad=new Gi(new Ne),this._frameBufferTargets.set(l.renderTarget,{frameBufferTarget:s._getFrameBufferTarget(),quad:s._quad})),l.rendercall(),s._frameBufferTarget=null}else s.setRenderTarget(l.renderTarget),l.rendercall();s.setRenderTarget(null),s.setOutputRenderTarget(n),s._frameBufferTarget=r,s._setXRLayerSize(a.x,a.y),s._quad=c,this.isPresenting=i}getSession(){return this._session}async setSession(e){let t=this._renderer,s=t.backend;this._gl=t.getContext();let i=this._gl,n=i.getContextAttributes();if(this._session=e,e!==null){if(s.isWebGPUBackend===!0)throw new Error('THREE.XRManager: XR is currently not supported with a WebGPU backend. Use WebGL by passing "{ forceWebGL: true }" to the constructor of the renderer.');if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),await s.makeXRCompatible(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._supportsLayers===!0){let r=null,a=null,c=null;t.depth&&(c=t.stencil?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24,r=t.stencil?Hs:ns,a=t.stencil?Ei:Oe);let l={colorFormat:i.RGBA8,depthFormat:c,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(l.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();let u=this._glBinding.createProjectionLayer(l),h=[u];this._glProjLayer=u,t.setPixelRatio(1),t._setXRLayerSize(u.textureWidth,u.textureHeight);let d=this._useMultiview?2:1,p=new Rt(u.textureWidth,u.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,r,d);if(this._xrRenderTarget=new rr(u.textureWidth,u.textureHeight,{format:Lt,type:lt,colorSpace:t.outputColorSpace,depthTexture:p,stencilBuffer:t.stencil,samples:n.antialias?4:0,resolveDepthBuffer:u.ignoreDepthValues===!1,resolveStencilBuffer:u.ignoreDepthValues===!1,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(let m of this._layers)m.plane.material=new ws({color:16777215,side:m.type==="cylinder"?rt:_s}),m.plane.material.blending=$n,m.plane.material.blendEquation=Xt,m.plane.material.blendSrc=Ni,m.plane.material.blendDst=Ni,m.xrlayer=this._createXRLayer(m),h.unshift(m.xrlayer);e.updateRenderState({layers:h})}else{let r={antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()},a=new XRWebGLLayer(e,i,r);this._glBaseLayer=a,e.updateRenderState({baseLayer:a}),t.setPixelRatio(1),t._setXRLayerSize(a.framebufferWidth,a.framebufferHeight),this._xrRenderTarget=new rr(a.framebufferWidth,a.framebufferHeight,{format:Lt,type:lt,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil,resolveDepthBuffer:a.ignoreDepthValues===!1,resolveStencilBuffer:a.ignoreDepthValues===!1}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}this.setFoveation(this.getFoveation()),t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){let t=this._session;if(t===null)return;let s=e.near,i=e.far,n=this._cameraXR,r=this._cameraL,a=this._cameraR;n.near=a.near=r.near=s,n.far=a.far=r.far=i,n.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==n.near||this._currentDepthFar!==n.far)&&(t.updateRenderState({depthNear:n.near,depthFar:n.far}),this._currentDepthNear=n.near,this._currentDepthFar=n.far),n.layers.mask=e.layers.mask|6,r.layers.mask=n.layers.mask&-5,a.layers.mask=n.layers.mask&-3;let c=e.parent,l=n.cameras;N_(n,c);for(let u=0;u<l.length;u++)N_(l[u],c);l.length===2?DF(n,r,a):n.projectionMatrix.copy(r.projectionMatrix),LF(e,n,c)}_getController(e){let t=this._controllers[e];return t===void 0&&(t=new yl,this._controllers[e]=t),t}};function DF(o,e,t){M_.setFromMatrixPosition(e.matrixWorld),A_.setFromMatrixPosition(t.matrixWorld);let s=M_.distanceTo(A_),i=e.projectionMatrix.elements,n=t.projectionMatrix.elements,r=i[14]/(i[10]-1),a=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],h=(n[8]+1)/n[0],d=r*u,p=r*h,m=s/(-u+h),g=m*-u;if(e.matrixWorld.decompose(o.position,o.quaternion,o.scale),o.translateX(g),o.translateZ(m),o.matrixWorld.compose(o.position,o.quaternion,o.scale),o.matrixWorldInverse.copy(o.matrixWorld).invert(),i[10]===-1)o.projectionMatrix.copy(e.projectionMatrix),o.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{let y=r+m,x=a+m,_=d-g,w=p+(s-g),S=c*a/x*y,E=l*a/x*y;o.projectionMatrix.makePerspective(_,w,S,E,y,x),o.projectionMatrixInverse.copy(o.projectionMatrix).invert()}}function N_(o,e){e===null?o.matrixWorld.copy(o.matrix):o.matrixWorld.multiplyMatrices(e.matrixWorld,o.matrix),o.matrixWorldInverse.copy(o.matrixWorld).invert()}function LF(o,e,t){t===null?o.matrix.copy(e.matrixWorld):(o.matrix.copy(t.matrixWorld),o.matrix.invert(),o.matrix.multiply(e.matrixWorld)),o.matrix.decompose(o.position,o.quaternion,o.scale),o.updateMatrixWorld(!0),o.projectionMatrix.copy(e.projectionMatrix),o.projectionMatrixInverse.copy(e.projectionMatrixInverse),o.isPerspectiveCamera&&(o.fov=Un*2*Math.atan(1/o.projectionMatrix.elements[5]),o.zoom=1)}function UF(o){let e=this._controllerInputSources.indexOf(o.inputSource);if(e===-1)return;let t=this._controllers[e];if(t!==void 0){let s=this.getReferenceSpace();t.update(o.inputSource,o.frame,s),t.dispatchEvent({type:o.type,data:o.inputSource})}}function OF(){let o=this._session,e=this._renderer;o.removeEventListener("select",this._onSessionEvent),o.removeEventListener("selectstart",this._onSessionEvent),o.removeEventListener("selectend",this._onSessionEvent),o.removeEventListener("squeeze",this._onSessionEvent),o.removeEventListener("squeezestart",this._onSessionEvent),o.removeEventListener("squeezeend",this._onSessionEvent),o.removeEventListener("end",this._onSessionEnd),o.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let t=0;t<this._controllers.length;t++){let s=this._controllerInputSources[t];s!==null&&(this._controllerInputSources[t]=null,this._controllers[t].disconnect(s))}if(this._currentDepthNear=null,this._currentDepthFar=null,e._resetXRState(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._glBaseLayer=null,this._glProjLayer=null,this._sessionUsesLayers===!0)for(let t of this._layers)t.renderTarget=new rr(t.pixelwidth,t.pixelheight,{format:Lt,type:lt,depthTexture:new Rt(t.pixelwidth,t.pixelheight,t.stencilBuffer?Ei:Oe,void 0,void 0,void 0,void 0,void 0,void 0,t.stencilBuffer?Hs:ns),stencilBuffer:t.stencilBuffer,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),t.renderTarget.isXRRenderTarget=!1,t.plane.material=t.material,t.material.map=t.renderTarget.texture,t.material.map.offset.y=1,t.material.map.repeat.y=-1,delete t.xrlayer;this.isPresenting=!1,this._useMultiview=!1,e._animation.stop(),e._animation.setAnimationLoop(this._currentAnimationLoop),e._animation.setContext(this._currentAnimationContext),e._animation.start(),e.setPixelRatio(this._currentPixelRatio),e.setSize(this._currentSize.width,this._currentSize.height,!1),this.dispatchEvent({type:"sessionend"})}function VF(o){let e=this._controllers,t=this._controllerInputSources;for(let s=0;s<o.removed.length;s++){let i=o.removed[s],n=t.indexOf(i);n>=0&&(t[n]=null,e[n].disconnect(i))}for(let s=0;s<o.added.length;s++){let i=o.added[s],n=t.indexOf(i);if(n===-1){for(let a=0;a<e.length;a++)if(a>=t.length){t.push(i),n=a;break}else if(t[a]===null){t[a]=i,n=a;break}if(n===-1)break}let r=e[n];r&&r.connect(i)}}function kF(o){return o.type==="quad"?this._glBinding.createQuadLayer({transform:new XRRigidTransform(o.translation,o.quaternion),width:o.width/2,height:o.height/2,space:this._referenceSpace,viewPixelWidth:o.pixelwidth,viewPixelHeight:o.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(o.translation,o.quaternion),radius:o.radius,centralAngle:o.centralAngle,aspectRatio:o.aspectRatio,space:this._referenceSpace,viewPixelWidth:o.pixelwidth,viewPixelHeight:o.pixelheight,clearOnAccess:!1})}function zF(o,e){if(e===void 0)return;let t=this._cameraXR,s=this._renderer,i=s.backend,n=this._glBaseLayer,r=this.getReferenceSpace(),a=e.getViewerPose(r);if(this._xrFrame=e,a!==null){let c=a.views;this._glBaseLayer!==null&&i.setXRTarget(n.framebuffer);let l=!1;c.length!==t.cameras.length&&(t.cameras.length=0,l=!0);for(let u=0;u<c.length;u++){let h=c[u],d;if(this._supportsLayers===!0){let m=this._glBinding.getViewSubImage(this._glProjLayer,h);d=m.viewport,u===0&&i.setXRRenderTargetTextures(this._xrRenderTarget,m.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:m.depthStencilTexture)}else d=n.getViewport(h);let p=this._cameras[u];p===void 0&&(p=new it,p.layers.enable(u),p.viewport=new Te,this._cameras[u]=p),p.matrix.fromArray(h.transform.matrix),p.matrix.decompose(p.position,p.quaternion,p.scale),p.projectionMatrix.fromArray(h.projectionMatrix),p.projectionMatrixInverse.copy(p.projectionMatrix).invert(),p.viewport.set(d.x,d.y,d.width,d.height),u===0&&(t.matrix.copy(p.matrix),t.matrix.decompose(t.position,t.quaternion,t.scale)),l===!0&&t.cameras.push(p)}s.setOutputRenderTarget(this._xrRenderTarget)}for(let c=0;c<this._controllers.length;c++){let l=this._controllerInputSources[c],u=this._controllers[c];l!==null&&u!==void 0&&u.update(l,e,r)}this._currentAnimationLoop&&this._currentAnimationLoop(o,e),e.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:e}),this._xrFrame=null}var py=class extends Ts{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new Te(0,0,this._width,this._height),this._scissor=new Te(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new Or,this.depthTexture=new Rt}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._dispatchResize())}setSize(e,t,s=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),s===!0&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){let t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,i){let n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,i,n=0,r=1){let a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,s,i),a.minDepth=n,a.maxDepth=r}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}},R_=new On,ao=new re,rf=new Te,of=new Ur,af=new Tl,Vu=new de,Fi=new Te,GF={[_s]:rt,[rt]:_s,[$s]:$s},fy=class{constructor(e,t={}){this.isRenderer=!0;let{logarithmicDepthBuffer:s=!1,reversedDepthBuffer:i=!1,alpha:n=!0,depth:r=!0,stencil:a=!1,antialias:c=!1,samples:l=0,getFallback:u=null,outputBufferType:h=$e,multiview:d=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=n,this.logarithmicDepthBuffer=s,this.reversedDepthBuffer=i,this.outputColorSpace=Pt,this.toneMapping=Ri,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=a,this.info=new qm,this.contextNode=$i(),this.library=new zh,this.lighting=new hy,this._samples=l||c===!0?4:0,this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new py(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new uh,this._inspector.setRenderer(this),this._getFallback=u,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 Gi(new Ne),this._quad.name="Output Color Transform",this._quad.material.name="outputColorTransform",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;let p=this.alpha===!0?0:1;this._clearColor=new Tc(0,0,0,p),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this._outputBufferType=h,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:ap},this.xr=new dy(this,d),this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(m,g,y)=>{await this.compileAsync(m,g);let x=this._renderLists.get(m,g),_=this._renderContexts.get(this._renderTarget,this._mrt),w=m.overrideMaterial||y.material,S=this._objects.get(y,w,m,g,x.lightsNode,_,_.clippingContext),{fragmentShader:E,vertexShader:B}=S.getNodeBuilderState();return{fragmentShader:E,vertexShader:B}}}}async init(){return this._initPromise!==null?this._initPromise:(this._initPromise=new Promise(async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(i){if(this._getFallback!==null)try{this.backend=s=this._getFallback(i),await s.init(this)}catch(n){t(n);return}else{t(i);return}}this._nodes=new cy(this,s),this._animation=new km(this,this._nodes,this.info),this._attributes=new Wm(s),this._background=new Bg(this,this._nodes),this._geometries=new $m(this._attributes,this.info),this._textures=new eg(this,s,this.info),this._pipelines=new Ym(s,this._nodes),this._bindings=new jm(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Gm(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new Jm(this.lighting),this._bundles=new uy,this._renderContexts=new Km(this),this._animation.start(),this._initialized=!0,this._inspector.init(),e(this)}),this._initPromise)}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(this._isDeviceLost===!0)return;this._initialized===!1&&await this.init();let i=this._nodes.nodeFrame,n=i.renderId,r=this._currentRenderContext,a=this._currentRenderObjectFunction,c=this._handleObjectFunction,l=this._compilationPromises,u=e.isScene===!0?e:R_;s===null&&(s=e);let h=this._renderTarget,d=this._renderContexts.get(h,this._mrt),p=this._activeMipmapLevel,m=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=m,i.renderId++,i.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new kh),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h);let g=this._renderLists.get(e,t);if(g.begin(),this._projectObject(e,t,0,g,d.clippingContext),s!==e&&s.traverseVisible(function(S){S.isLight&&S.layers.test(t.layers)&&g.pushLight(S)}),g.finish(),h!==null){this._textures.updateRenderTarget(h,p);let S=this._textures.get(h);d.textures=S.textures,d.depthTexture=S.depthTexture}else d.textures=null,d.depthTexture=null;s!==e?this._background.update(s,g,d):this._background.update(u,g,d);let y=g.opaque,x=g.transparent,_=g.transparentDoublePass,w=g.lightsNode;this.opaque===!0&&y.length>0&&this._renderObjects(y,t,u,w),this.transparent===!0&&x.length>0&&this._renderTransparents(x,_,t,u,w),i.renderId=n,this._currentRenderContext=r,this._currentRenderObjectFunction=a,this._handleObjectFunction=c,this._compilationPromises=l,await Promise.all(m)}async renderAsync(e,t){_e('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){O("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){this._inspector!==null&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){let t=this.contextNode.value;e===!0?(t.modelViewMatrix=Xf,t.modelNormalViewMatrix=Yf):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){let e=this.contextNode.value;return e.modelViewMatrix===Xf&&e.modelNormalViewMatrix===Yf}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return _e('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:
|
|
|
|
Message: ${e.message}`;e.reason&&(t+=`
|
|
Reason: ${e.reason}`),O(t),this._isDeviceLost=!0}_renderBundle(e,t,s){let{bundleGroup:i,camera:n,renderList:r}=e,a=this._currentRenderContext,c=this._bundles.get(i,n),l=this.backend.get(c);l.renderContexts===void 0&&(l.renderContexts=new Set);let u=i.version!==l.version,h=l.renderContexts.has(a)===!1||u;if(l.renderContexts.add(a),h){this.backend.beginBundle(a),(l.renderObjects===void 0||u)&&(l.renderObjects=[]),this._currentRenderBundle=c;let{transparentDoublePass:d,transparent:p,opaque:m}=r;this.opaque===!0&&m.length>0&&this._renderObjects(m,n,t,s),this.transparent===!0&&p.length>0&&this._renderTransparents(p,d,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(a,c),l.version=i.version}else{let{renderObjects:d}=l;for(let p=0,m=d.length;p<m;p++){let g=d[p];this._nodes.needsRefresh(g)&&(this._nodes.updateBefore(g),this._nodes.updateForRender(g),this._bindings.updateForRender(g),this._nodes.updateAfter(g))}}this.backend.addBundle(a,c)}render(e,t){if(this._initialized===!1)throw new Error('Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.');this._renderScene(e,t)}get initialized(){return this._initialized}_getFrameBufferTarget(){let{currentToneMapping:e,currentColorSpace:t}=this,s=e!==Ri,i=t!==me.workingColorSpace;if(s===!1&&i===!1)return null;let{width:n,height:r}=this.getDrawingBufferSize(ao),{depth:a,stencil:c}=this,l=this._frameBufferTarget;l===null&&(l=new bt(n,r,{depthBuffer:a,stencilBuffer:c,type:this._outputBufferType,format:Lt,colorSpace:me.workingColorSpace,generateMipmaps:!1,minFilter:ct,magFilter:ct,samples:this.samples}),l.isPostProcessingRenderTarget=!0,this._frameBufferTarget=l);let u=this.getOutputRenderTarget();l.depthBuffer=a,l.stencilBuffer=c,u!==null?l.setSize(u.width,u.height,u.depth):l.setSize(n,r,1);let h=this._canvasTarget;return l.viewport.copy(h._viewport),l.scissor.copy(h._scissor),l.viewport.multiplyScalar(h._pixelRatio),l.scissor.multiplyScalar(h._pixelRatio),l.scissorTest=h._scissorTest,l.multiview=u!==null?u.multiview:!1,l.resolveDepthBuffer=u!==null?u.resolveDepthBuffer:!0,l._autoAllocateDepthBuffer=u!==null?u._autoAllocateDepthBuffer:!1,l}_renderScene(e,t,s=!0){if(this._isDeviceLost===!0)return;let i=s?this._getFrameBufferTarget():null,n=this._nodes.nodeFrame,r=n.renderId,a=this._currentRenderContext,c=this._currentRenderObjectFunction,l=this._handleObjectFunction;this._callDepth++;let u=e.isScene===!0?e:R_,h=this._renderTarget||this._outputRenderTarget,d=this._activeCubeFace,p=this._activeMipmapLevel,m;i!==null?(m=i,this.setRenderTarget(m)):m=h;let g=this._renderContexts.get(m,this._mrt,this._callDepth);this._currentRenderContext=g,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,n.renderId=this.info.calls,this.backend.updateTimeStampUID(g),this.inspector.beginRender(this.backend.getTimestampUID(g),e,t,m);let y=this.xr;if(y.isPresenting===!1){let ee=!1;if(this.reversedDepthBuffer===!0&&t.reversedDepth!==!0){if(t._reversedDepth=!0,t.isArrayCamera)for(let ie of t.cameras)ie._reversedDepth=!0;ee=!0}let Q=this.coordinateSystem;if(t.coordinateSystem!==Q){if(t.coordinateSystem=Q,t.isArrayCamera)for(let ie of t.cameras)ie.coordinateSystem=Q;ee=!0}if(ee===!0&&(t.updateProjectionMatrix(),t.isArrayCamera))for(let ie of t.cameras)ie.updateProjectionMatrix()}e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),y.enabled===!0&&y.isPresenting===!0&&(y.cameraAutoUpdate===!0&&y.updateCamera(t),t=y.getCamera());let x=this._canvasTarget,_=x._viewport,w=x._scissor,S=x._pixelRatio;m!==null&&(_=m.viewport,w=m.scissor,S=1),this.getDrawingBufferSize(ao),rf.set(0,0,ao.width,ao.height);let E=_.minDepth===void 0?0:_.minDepth,B=_.maxDepth===void 0?1:_.maxDepth;g.viewportValue.copy(_).multiplyScalar(S).floor(),g.viewportValue.width>>=p,g.viewportValue.height>>=p,g.viewportValue.minDepth=E,g.viewportValue.maxDepth=B,g.viewport=g.viewportValue.equals(rf)===!1,g.scissorValue.copy(w).multiplyScalar(S).floor(),g.scissor=x._scissorTest&&g.scissorValue.equals(rf)===!1,g.scissorValue.width>>=p,g.scissorValue.height>>=p,g.clippingContext||(g.clippingContext=new kh),g.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,m);let N=t.isArrayCamera?af:of;t.isArrayCamera||(Vu.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),N.setFromProjectionMatrix(Vu,t.coordinateSystem,t.reversedDepth));let C=this._renderLists.get(e,t);if(C.begin(),this._projectObject(e,t,0,C,g.clippingContext),C.finish(),this.sortObjects===!0&&C.sort(this._opaqueSort,this._transparentSort),m!==null){this._textures.updateRenderTarget(m,p);let ee=this._textures.get(m);g.textures=ee.textures,g.depthTexture=ee.depthTexture,g.width=ee.width,g.height=ee.height,g.renderTarget=m,g.depth=m.depthBuffer,g.stencil=m.stencilBuffer}else g.textures=null,g.depthTexture=null,g.width=ao.width,g.height=ao.height,g.depth=this.depth,g.stencil=this.stencil;g.width>>=p,g.height>>=p,g.activeCubeFace=d,g.activeMipmapLevel=p,g.occlusionQueryCount=C.occlusionQueryCount,g.scissorValue.max(Fi.set(0,0,0,0)),g.scissorValue.x+g.scissorValue.width>g.width&&(g.scissorValue.width=Math.max(g.width-g.scissorValue.x,0)),g.scissorValue.y+g.scissorValue.height>g.height&&(g.scissorValue.height=Math.max(g.height-g.scissorValue.y,0)),this._background.update(u,C,g),g.camera=t,this.backend.beginRender(g);let{bundles:I,lightsNode:k,transparentDoublePass:W,transparent:X,opaque:Y}=C;return I.length>0&&this._renderBundles(I,u,k),this.opaque===!0&&Y.length>0&&this._renderObjects(Y,t,u,k),this.transparent===!0&&X.length>0&&this._renderTransparents(X,W,t,u,k),this.backend.finishRender(g),n.renderId=r,this._currentRenderContext=a,this._currentRenderObjectFunction=c,this._handleObjectFunction=l,this._callDepth--,i!==null&&(this.setRenderTarget(h,d,p),this._renderOutput(m)),u.onAfterRender(this,e,t,m),this.inspector.finishRender(this.backend.getTimestampUID(g)),g}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){let t=this._quad;this._nodes.hasOutputChange(e.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(e.texture),t.material.needsUpdate=!0);let s=this.autoClear,i=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderScene(t,t.camera,!1),this.autoClear=s,this.xr.enabled=i}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){this._initialized===!1&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._canvasTarget.getPixelRatio()}getDrawingBufferSize(e){return this._canvasTarget.getDrawingBufferSize(e)}getSize(e){return this._canvasTarget.getSize(e)}setPixelRatio(e=1){this._canvasTarget.setPixelRatio(e)}setDrawingBufferSize(e,t,s){this.xr&&this.xr.isPresenting||this._canvasTarget.setDrawingBufferSize(e,t,s)}setSize(e,t,s=!0){this.xr&&this.xr.isPresenting||this._canvasTarget.setSize(e,t,s)}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){return this._canvasTarget.getScissor(e)}setScissor(e,t,s,i){this._canvasTarget.setScissor(e,t,s,i)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,s,i,n=0,r=1){this._canvasTarget.setViewport(e,t,s,i,n,r)}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this.reversedDepthBuffer===!0?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){let t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(this._initialized===!1)throw new Error('Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before before using this method.');let i=this._renderTarget||this._getFrameBufferTarget(),n=null;if(i!==null){this._textures.updateRenderTarget(i);let r=this._textures.get(i);n=this._renderContexts.get(i),n.textures=r.textures,n.depthTexture=r.depthTexture,n.width=r.width,n.height=r.height,n.renderTarget=i,n.depth=i.depthBuffer,n.stencil=i.stencilBuffer;let a=this.backend.getClearColor();n.clearColorValue.r=a.r,n.clearColorValue.g=a.g,n.clearColorValue.b=a.b,n.clearColorValue.a=a.a,n.clearDepthValue=this.getClearDepth(),n.clearStencilValue=this.getClearStencil(),n.activeCubeFace=this.getActiveCubeFace(),n.activeMipmapLevel=this.getActiveMipmapLevel()}this.backend.clear(e,t,s,n),i!==null&&this._renderTarget===null&&this._renderOutput(i)}clearColor(){this.clear(!0,!1,!1)}clearDepth(){this.clear(!1,!0,!1)}clearStencil(){this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){_e('Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.clear(e,t,s)}async clearColorAsync(){_e('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){_e('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){_e('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){let e=this.currentToneMapping!==Ri,t=this.currentColorSpace!==me.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return this._renderTarget!==null?e=this._renderTarget.samples:this.needsFrameBufferTarget&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:Ri}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:me.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||this._renderTarget===null}dispose(){this._initialized===!0&&(this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._geometries.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this._frameBufferTarget!==null&&this._frameBufferTarget.dispose(),Object.values(this.backend.timestampQueryPool).forEach(e=>{e!==null&&e.dispose()})),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setCanvasTarget(e){this._canvasTarget.removeEventListener("resize",this._onCanvasTargetResize),this._canvasTarget=e,this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize)}getCanvasTarget(){return this._canvasTarget}_resetXRState(){this.backend.setXRTarget(null),this.setOutputRenderTarget(null),this.setRenderTarget(null),this._frameBufferTarget.dispose(),this._frameBufferTarget=null}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(this._isDeviceLost===!0)return;if(this._initialized===!1)return z("Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e,t);let s=this._nodes.nodeFrame,i=s.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,s.renderId=this.info.calls,this.backend.updateTimeStampUID(e),this.inspector.beginCompute(this.backend.getTimestampUID(e),e);let n=this.backend,r=this._pipelines,a=this._bindings,c=this._nodes,l=Array.isArray(e)?e:[e];if(l[0]===void 0||l[0].isComputeNode!==!0)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");n.beginCompute(e);for(let u of l){if(r.has(u)===!1){let p=()=>{u.removeEventListener("dispose",p),r.delete(u),a.deleteForCompute(u),c.delete(u)};u.addEventListener("dispose",p);let m=u.onInitFunction;m!==null&&m.call(u,{renderer:this})}c.updateForCompute(u),a.updateForCompute(u);let h=a.getForCompute(u),d=r.getForCompute(u,h);n.compute(e,u,h,d,t)}n.finishCompute(e),s.renderId=i,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){this._initialized===!1&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return _e('Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.hasFeature(e)}async resolveTimestampsAsync(e="render"){return this._initialized===!1&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(this._initialized===!1)throw new Error('Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){_e('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(this._initialized===!1)throw new Error('Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(this._initialized===!1)throw new Error('Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before before using this method.');this._textures.updateRenderTarget(e);let t=this._textures.get(e),s=this._renderContexts.get(e);s.textures=t.textures,s.depthTexture=t.depthTexture,s.width=t.width,s.height=t.height,s.renderTarget=e,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,this.backend.initRenderTarget(s)}copyFramebufferToTexture(e,t=null){if(t!==null)if(t.isVector2)t=Fi.set(t.x,t.y,e.image.width,e.image.height).floor();else if(t.isVector4)t=Fi.copy(t).floor();else{O("Renderer.copyFramebufferToTexture: Invalid rectangle.");return}else t=Fi.set(0,0,e.image.width,e.image.height);let s=this._currentRenderContext,i;s!==null?i=s.renderTarget:(i=this._renderTarget||this._getFrameBufferTarget(),i!==null&&(this._textures.updateRenderTarget(i),s=this._textures.get(i))),this._textures.updateTexture(e,{renderTarget:i}),this.backend.copyFramebufferToTexture(e,s,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,s=null,i=null,n=0,r=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,i,n,r),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,s,i,n,r=0,a=0){return this.backend.copyTextureToBuffer(e.textures[r],t,s,i,n,a)}_projectObject(e,t,s,i,n){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){let c=t.isArrayCamera?af:of;if(!e.frustumCulled||c.intersectsSprite(e,t)){this.sortObjects===!0&&Fi.setFromMatrixPosition(e.matrixWorld).applyMatrix4(Vu);let{geometry:l,material:u}=e;u.visible&&i.push(e,l,u,s,Fi.z,null,n)}}else if(e.isLineLoop)O("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){let c=t.isArrayCamera?af:of;if(!e.frustumCulled||c.intersectsObject(e,t)){let{geometry:l,material:u}=e;if(this.sortObjects===!0&&(l.boundingSphere===null&&l.computeBoundingSphere(),Fi.copy(l.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(Vu)),Array.isArray(u)){let h=l.groups;for(let d=0,p=h.length;d<p;d++){let m=h[d],g=u[m.materialIndex];g&&g.visible&&i.push(e,l,g,s,Fi.z,m,n)}}else u.visible&&i.push(e,l,u,s,Fi.z,null,n)}}}if(e.isBundleGroup===!0&&this.backend.beginBundle!==void 0){let c=i;i=this._renderLists.get(e,t),i.begin(),c.pushBundle({bundleGroup:e,camera:t,renderList:i}),i.finish()}let a=e.children;for(let c=0,l=a.length;c<l;c++)this._projectObject(a[c],t,s,i,n)}_renderBundles(e,t,s){for(let i of e)this._renderBundle(i,t,s)}_renderTransparents(e,t,s,i,n){if(t.length>0){for(let{material:r}of t)r.side=rt;this._renderObjects(t,s,i,n,"backSide");for(let{material:r}of t)r.side=_s;this._renderObjects(e,s,i,n);for(let{material:r}of t)r.side=$s}else this._renderObjects(e,s,i,n)}_renderObjects(e,t,s,i,n=null){for(let r=0,a=e.length;r<a;r++){let{object:c,geometry:l,material:u,group:h,clippingContext:d}=e[r];this._currentRenderObjectFunction(c,s,t,l,u,h,i,d,n)}}_getShadowNodes(e){let t=e.version,s=this._cacheShadowNodes.get(e);if(s===void 0||s.version!==t){let i=e.map!==null,n=e.colorNode&&e.colorNode.isNode,r=e.castShadowNode&&e.castShadowNode.isNode,a=e.maskShadowNode&&e.maskShadowNode.isNode||e.maskNode&&e.maskNode.isNode,c=null,l=null,u=null;if(i||n||r||a){let h,d;if(r?(h=e.castShadowNode.rgb,d=e.castShadowNode.a,this.shadowMap.transmitted!==!0&&_e("Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.")):(h=v(0),d=b(1)),i&&(d=d.mul(Ie("map","texture",e).a)),n&&(d=d.mul(e.colorNode.a)),l=Z(h,d),a){let p=e.maskShadowNode||e.maskNode;l=A(([m])=>(p.not().discard(),m))(l)}}e.depthNode&&e.depthNode.isNode&&(u=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?c=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(c=e.positionNode),s={version:t,colorNode:l,depthNode:u,positionNode:c},this._cacheShadowNodes.set(e,s)}return s}renderObject(e,t,s,i,n,r,a,c=null,l=null){let u=!1,h,d,p,m;if(e.onBeforeRender(this,t,s,i,n,r),n.allowOverride===!0&&t.overrideMaterial!==null){let g=t.overrideMaterial;if(u=!0,h=g.isNodeMaterial?g.colorNode:null,d=g.isNodeMaterial?g.depthNode:null,p=g.isNodeMaterial?g.positionNode:null,m=t.overrideMaterial.side,n.positionNode&&n.positionNode.isNode&&(g.positionNode=n.positionNode),g.alphaTest=n.alphaTest,g.alphaMap=n.alphaMap,g.transparent=n.transparent||n.transmission>0||n.transmissionNode&&n.transmissionNode.isNode||n.backdropNode&&n.backdropNode.isNode,g.isShadowPassMaterial){let{colorNode:y,depthNode:x,positionNode:_}=this._getShadowNodes(n);this.shadowMap.type===Wr?g.side=n.shadowSide!==null?n.shadowSide:n.side:g.side=n.shadowSide!==null?n.shadowSide:GF[n.side],y!==null&&(g.colorNode=y),x!==null&&(g.depthNode=x),_!==null&&(g.positionNode=_)}n=g}n.transparent===!0&&n.side===$s&&n.forceSinglePass===!1?(n.side=rt,this._handleObjectFunction(e,n,t,s,a,r,c,"backSide"),n.side=_s,this._handleObjectFunction(e,n,t,s,a,r,c,l),n.side=$s):this._handleObjectFunction(e,n,t,s,a,r,c,l),u&&(t.overrideMaterial.colorNode=h,t.overrideMaterial.depthNode=d,t.overrideMaterial.positionNode=p,t.overrideMaterial.side=m),e.onAfterRender(this,t,s,i,n,r)}hasCompatibility(e){return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,s,i,n,r,a,c){let l=this._objects.get(e,t,s,i,n,this._currentRenderContext,a,c);l.drawRange=e.geometry.drawRange,l.group=r,this._currentRenderBundle!==null&&(this.backend.get(this._currentRenderBundle).renderObjects.push(l),l.bundle=this._currentRenderBundle.bundleGroup);let u=this._nodes.needsRefresh(l);u&&(this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l)),this._pipelines.updateForRender(l),this.backend.draw(l,this.info),u&&this._nodes.updateAfter(l)}_createObjectPipeline(e,t,s,i,n,r,a,c){let l=this._objects.get(e,t,s,i,n,this._currentRenderContext,a,c);l.drawRange=e.geometry.drawRange,l.group=r,this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l),this._pipelines.getForRender(l,this._compilationPromises),this._nodes.updateAfter(l)}_onCanvasTargetResize(){this._initialized&&this.backend.updateSize()}get compile(){return this.compileAsync}},Gh=class{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}getVisibility(){return this.visibility}clone(){return Object.assign(new this.constructor,this)}};function WF(o){return o+(pn-o%pn)%pn}var Wh=class extends Gh{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t,this._updateRanges=[]}get updateRanges(){return this._updateRanges}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}get byteLength(){return WF(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}},$h=class extends Wh{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}},$F=0,qh=class extends $h{constructor(e,t){super("UniformBuffer_"+$F++,e?e.value:null),this.nodeUniform=e,this.groupNode=t,this.isNodeUniformBuffer=!0}set updateRanges(e){this.nodeUniform.updateRanges=e}get updateRanges(){return this.nodeUniform.updateRanges}addUpdateRange(e,t){this.nodeUniform.addUpdateRange(e,t)}clearUpdateRanges(){this.nodeUniform.clearUpdateRanges()}get buffer(){return this.nodeUniform.value}},my=class extends $h{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map}addUniformUpdateRange(e){let t=e.index;if(this._updateRangeCache.has(t)!==!0){let s=this.updateRanges,i=e.offset,n=e.itemSize,r={start:i,count:n};s.push(r),this._updateRangeCache.set(t,r)}}clearUpdateRanges(){this._updateRangeCache.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){let t=this.uniforms.indexOf(e);return t!==-1&&this.uniforms.splice(t,1),this}get values(){return this._values===null&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;if(e===null){let t=this.byteLength;e=new Float32Array(new ArrayBuffer(t)),this._buffer=e}return e}get byteLength(){let e=this.bytesPerElement,t=0;for(let s=0,i=this.uniforms.length;s<i;s++){let n=this.uniforms[s],r=n.boundary,a=n.itemSize*e,c=t%pn,l=c%r,u=c+l;t+=l,u!==0&&pn-u<a&&(t+=pn-u),n.offset=t/e,n.index=s,t+=a}return Math.ceil(t/pn)*pn}update(){let e=!1;for(let t of this.uniforms)this.updateByType(t)===!0&&(e=!0);return e}updateByType(e){if(e.isNumberUniform)return this.updateNumber(e);if(e.isVector2Uniform)return this.updateVector2(e);if(e.isVector3Uniform)return this.updateVector3(e);if(e.isVector4Uniform)return this.updateVector4(e);if(e.isColorUniform)return this.updateColor(e);if(e.isMatrix3Uniform)return this.updateMatrix3(e);if(e.isMatrix4Uniform)return this.updateMatrix4(e);O("WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1,s=this.values,i=e.getValue(),n=e.offset,r=e.getType();if(s[n]!==i){let a=this._getBufferForType(r);a[n]=s[n]=i,t=!0,this.addUniformUpdateRange(e)}return t}updateVector2(e){let t=!1,s=this.values,i=e.getValue(),n=e.offset,r=e.getType();if(s[n+0]!==i.x||s[n+1]!==i.y){let a=this._getBufferForType(r);a[n+0]=s[n+0]=i.x,a[n+1]=s[n+1]=i.y,t=!0,this.addUniformUpdateRange(e)}return t}updateVector3(e){let t=!1,s=this.values,i=e.getValue(),n=e.offset,r=e.getType();if(s[n+0]!==i.x||s[n+1]!==i.y||s[n+2]!==i.z){let a=this._getBufferForType(r);a[n+0]=s[n+0]=i.x,a[n+1]=s[n+1]=i.y,a[n+2]=s[n+2]=i.z,t=!0,this.addUniformUpdateRange(e)}return t}updateVector4(e){let t=!1,s=this.values,i=e.getValue(),n=e.offset,r=e.getType();if(s[n+0]!==i.x||s[n+1]!==i.y||s[n+2]!==i.z||s[n+4]!==i.w){let a=this._getBufferForType(r);a[n+0]=s[n+0]=i.x,a[n+1]=s[n+1]=i.y,a[n+2]=s[n+2]=i.z,a[n+3]=s[n+3]=i.w,t=!0,this.addUniformUpdateRange(e)}return t}updateColor(e){let t=!1,s=this.values,i=e.getValue(),n=e.offset;if(s[n+0]!==i.r||s[n+1]!==i.g||s[n+2]!==i.b){let r=this.buffer;r[n+0]=s[n+0]=i.r,r[n+1]=s[n+1]=i.g,r[n+2]=s[n+2]=i.b,t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix3(e){let t=!1,s=this.values,i=e.getValue().elements,n=e.offset;if(s[n+0]!==i[0]||s[n+1]!==i[1]||s[n+2]!==i[2]||s[n+4]!==i[3]||s[n+5]!==i[4]||s[n+6]!==i[5]||s[n+8]!==i[6]||s[n+9]!==i[7]||s[n+10]!==i[8]){let r=this.buffer;r[n+0]=s[n+0]=i[0],r[n+1]=s[n+1]=i[1],r[n+2]=s[n+2]=i[2],r[n+4]=s[n+4]=i[3],r[n+5]=s[n+5]=i[4],r[n+6]=s[n+6]=i[5],r[n+8]=s[n+8]=i[6],r[n+9]=s[n+9]=i[7],r[n+10]=s[n+10]=i[8],t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix4(e){let t=!1,s=this.values,i=e.getValue().elements,n=e.offset;return HF(s,i,n)===!1&&(this.buffer.set(i,n),qF(s,i,n),t=!0,this.addUniformUpdateRange(e)),t}_getBufferForType(e){return e==="int"||e==="ivec2"||e==="ivec3"||e==="ivec4"?new Int32Array(this.buffer.buffer):e==="uint"||e==="uvec2"||e==="uvec3"||e==="uvec4"?new Uint32Array(this.buffer.buffer):this.buffer}};function qF(o,e,t){for(let s=0,i=e.length;s<i;s++)o[t+s]=e[s]}function HF(o,e,t){for(let s=0,i=e.length;s<i;s++)if(o[t+s]!==e[s])return!1;return!0}var XF=0,Hh=class extends my{constructor(e,t){super(e),this.id=XF++,this.groupNode=t,this.isNodeUniformsGroup=!0}},Xh=class extends Gh{constructor(e,t){super(e),this._texture=null,this._onTextureDispose=()=>{this.generation=null,this.version=-1},this.texture=t,this.version=t?t.version:-1,this.generation=null,this.samplerKey="",this.isSampler=!0}set texture(e){this._texture!==e&&(this._texture&&this._texture.removeEventListener("dispose",this._onTextureDispose),this._texture=e,this.generation=null,this.version=-1,this._texture&&this._texture.addEventListener("dispose",this._onTextureDispose))}get texture(){return this._texture}update(){let{texture:e,version:t}=this;return t!==e.version?(this.version=e.version,!0):!1}clone(){let e=super.clone();return e._texture=null,e._onTextureDispose=()=>{e.generation=null,e.version=-1},e.texture=this.texture,e}},YF=0,gy=class extends Xh{constructor(e,t){super(e,t),this.id=YF++,this.store=!1,this.mipLevel=0,this.isSampledTexture=!0}},No=class extends gy{constructor(e,t,s,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s,this.access=i}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}},Yh=class extends No{constructor(e,t,s,i=null){super(e,t,s,i),this.isSampledCubeTexture=!0}},Cc=class extends No{constructor(e,t,s,i=null){super(e,t,s,i),this.isSampledTexture3D=!0}},C_={bitcast_int_uint:new He("uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }"),bitcast_uint_int:new He("uint tsl_bitcast_uint_to_int ( uint x ) { return floatBitsToInt( uintBitsToFloat ( x ) ); }")},jF={textureDimensions:"textureSize",equals:"equal",bitcast_float_int:"floatBitsToInt",bitcast_int_float:"intBitsToFloat",bitcast_uint_float:"uintBitsToFloat",bitcast_float_uint:"floatBitsToUint",bitcast_uint_int:"tsl_bitcast_uint_to_int",bitcast_int_uint:"tsl_bitcast_int_to_uint",floatpack_snorm_2x16:"packSnorm2x16",floatpack_unorm_2x16:"packUnorm2x16",floatpack_float16_2x16:"packHalf2x16",floatunpack_snorm_2x16:"unpackSnorm2x16",floatunpack_unorm_2x16:"unpackUnorm2x16",floatunpack_float16_2x16:"unpackHalf2x16"},E_={low:"lowp",medium:"mediump",high:"highp"},B_={swizzleAssign:!0,storageBuffer:!1},F_={perspective:"smooth",linear:"noperspective"},I_={centroid:"centroid"},P_=`
|
|
precision highp float;
|
|
precision highp int;
|
|
precision highp sampler2D;
|
|
precision highp sampler3D;
|
|
precision highp samplerCube;
|
|
precision highp sampler2DArray;
|
|
|
|
precision highp usampler2D;
|
|
precision highp usampler3D;
|
|
precision highp usamplerCube;
|
|
precision highp usampler2DArray;
|
|
|
|
precision highp isampler2D;
|
|
precision highp isampler3D;
|
|
precision highp isamplerCube;
|
|
precision highp isampler2DArray;
|
|
|
|
precision highp sampler2DShadow;
|
|
precision highp sampler2DArrayShadow;
|
|
precision highp samplerCubeShadow;
|
|
`,yy=class extends Uh{constructor(e,t){super(e,t,new ay),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]}}needsToWorkingColorSpace(e){return e.isVideoTexture===!0&&e.colorSpace!==Bi}_include(e){let t=C_[e];return t.build(this),this.addInclude(t),t}getMethod(e){return C_[e]!==void 0&&this._include(e),jF[e]||e}getBitcastMethod(e,t){return this.getMethod(`bitcast_${t}_${e}`)}getFloatPackingMethod(e){return this.getMethod(`floatpack_${e}_2x16`)}getFloatUnpackingMethod(e){return this.getMethod(`floatunpack_${e}_2x16`)}getTernary(e,t,s){return`${e} ? ${t} : ${s}`}getOutputStructName(){return""}buildFunctionCode(e){let t=e.layout,s=this.flowShaderNode(e),i=[];for(let r of t.inputs)i.push(this.getType(r.type)+" "+r.name);return`${this.getType(t.type)} ${t.name}( ${i.join(", ")} ) {
|
|
|
|
${s.vars}
|
|
|
|
${s.code}
|
|
return ${s.result};
|
|
|
|
}`}setupPBO(e){let t=e.value;if(t.pbo===void 0){let s=t.array,i=t.count*t.itemSize,{itemSize:n}=t,r=t.array.constructor.name.toLowerCase().includes("int"),a=r?ha:ua;n===2?a=r?da:Ms:n===3?a=r?ob:la:n===4&&(a=r?pa:Lt);let c={Float32Array:Ct,Uint8Array:lt,Uint16Array:rn,Uint32Array:Oe,Int8Array:Hn,Int16Array:Xn,Int32Array:ut,Uint8ClampedArray:lt},l=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(i/n)))),u=Math.ceil(i/n/l);l*u*n<i&&u++;let h=l*u*n,d=new s.constructor(h);d.set(s,0),t.array=d;let p=new Qo(t.array,l,u,a,c[t.array.constructor.name]||Ct);p.needsUpdate=!0,p.isPBOTexture=!0;let m=new ps(p,null,null);m.setPrecision("high"),t.pboNode=m,t.pbo=m.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&e.node.isTextureNode!==!0&&e.node.isBufferNode!==!0?e.name:super.getPropertyName(e,t)}generatePBO(e){let{node:t,indexNode:s}=e,i=t.value;if(this.renderer.backend.has(i)){let u=this.renderer.backend.get(i);u.pbo=i.pbo}let n=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.nodeName),r=this.getPropertyName(n);this.increaseUsage(s);let a=s.build(this,"uint"),c=this.getDataFromNode(e),l=c.propertyName;if(l===void 0){let u=this.getVarFromNode(e);l=this.getPropertyName(u);let h=this.getDataFromNode(t),d=h.propertySizeName;d===void 0&&(d=l+"Size",this.getVarFromNode(t,d,"uint"),this.addLineFlowCode(`${d} = uint( textureSize( ${r}, 0 ).x )`,e),h.propertySizeName=d);let{itemSize:p}=i,m="."+fr.join("").slice(0,p),g=`ivec2(${a} % ${d}, ${a} / ${d})`,y=this.generateTextureLoad(null,r,g,"0",null,null),x="vec4";i.pbo.type===Oe?x="uvec4":i.pbo.type===ut&&(x="ivec4"),this.addLineFlowCode(`${l} = ${x}(${y})${m}`,e),c.propertyName=l}return l}generateTextureLoad(e,t,s,i,n,r){i===null&&(i="0");let a;return n?r?a=`texelFetchOffset( ${t}, ivec3( ${s}, ${n} ), ${i}, ${r} )`:a=`texelFetch( ${t}, ivec3( ${s}, ${n} ), ${i} )`:r?a=`texelFetchOffset( ${t}, ${s}, ${i}, ${r} )`:a=`texelFetch( ${t}, ${s}, ${i} )`,e!==null&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,s,i,n){return i&&(s=`vec3( ${s}, ${i} )`),e.isDepthTexture?n?`textureOffset( ${t}, ${s}, ${n} ).x`:`texture( ${t}, ${s} ).x`:n?`textureOffset( ${t}, ${s}, ${n} )`:`texture( ${t}, ${s} )`}generateTextureLevel(e,t,s,i,n,r){return n&&(s=`vec3( ${s}, ${n} )`),r?`textureLodOffset( ${t}, ${s}, ${i}, ${r} )`:`textureLod( ${t}, ${s}, ${i} )`}generateTextureBias(e,t,s,i,n,r){return n&&(s=`vec3( ${s}, ${n} )`),r?`textureOffset( ${t}, ${s}, ${r}, ${i} )`:`texture( ${t}, ${s}, ${i} )`}generateTextureGrad(e,t,s,i,n,r){return n&&(s=`vec3( ${s}, ${n} )`),r?`textureGradOffset( ${t}, ${s}, ${i[0]}, ${i[1]}, ${r} )`:`textureGrad( ${t}, ${s}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,s,i,n,r,a=this.shaderStage){if(a==="fragment")return e.isCubeTexture?`texture( ${t}, vec4( ${s}, ${i} ) )`:n?r?`textureOffset( ${t}, vec4( ${s}, ${n}, ${i} ), ${r} )`:`texture( ${t}, vec4( ${s}, ${n}, ${i} ) )`:r?`textureOffset( ${t}, vec3( ${s}, ${i} ), ${r} )`:`texture( ${t}, vec3( ${s}, ${i} ) )`;O(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}getVars(e){let t=[],s=this.vars[e];if(s!==void 0)for(let i of s)t.push(`${this.getVar(i.type,i.name,i.count)};`);return t.join(`
|
|
`)}getUniforms(e){let t=this.uniforms[e],s=[],i={};for(let r of t){let a=null,c=!1;if(r.type==="texture"||r.type==="texture3D"){let l=r.node.value,u="";(l.isDataTexture===!0||l.isData3DTexture===!0)&&(l.type===Oe?u="u":l.type===ut&&(u="i")),r.type==="texture3D"&&l.isArrayTexture===!1?a=`${u}sampler3D ${r.name};`:l.compareFunction?l.isArrayTexture===!0?a=`sampler2DArrayShadow ${r.name};`:a=`sampler2DShadow ${r.name};`:l.isArrayTexture===!0||l.isDataArrayTexture===!0||l.isCompressedArrayTexture===!0?a=`${u}sampler2DArray ${r.name};`:a=`${u}sampler2D ${r.name};`}else if(r.type==="cubeTexture")a=`samplerCube ${r.name};`;else if(r.type==="cubeDepthTexture")r.node.value.compareFunction?a=`samplerCubeShadow ${r.name};`:a=`samplerCube ${r.name};`;else if(r.type==="buffer"){let l=r.node,u=this.getType(l.bufferType),h=l.bufferCount,d=h>0?h:"";a=`${l.name} {
|
|
${u} ${r.name}[${d}];
|
|
};
|
|
`}else{let l=r.groupNode.name;if(i[l]===void 0){let u=this.uniformGroups[l];if(u!==void 0){let h=[];for(let d of u.uniforms){let p=d.getType(),m=this.getVectorType(p),g=d.nodeUniform.node.precision,y=`${m} ${d.name};`;g!==null&&(y=E_[g]+" "+y),h.push(" "+y)}i[l]=h}}c=!0}if(!c){let l=r.node.precision;l!==null&&(a=E_[l]+" "+a),a="uniform "+a,s.push(a)}}let n="";for(let r in i){let a=i[r];n+=this._getGLSLUniformStruct(r,a.join(`
|
|
`))+`
|
|
`}return n+=s.join(`
|
|
`),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==ut){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);let i=s.array;i instanceof Uint32Array||i instanceof Int32Array||(t=t.slice(1))}return t}getAttributes(e){let t="";if(e==="vertex"||e==="compute"){let s=this.getAttributesArray(),i=0;for(let n of s)t+=`layout( location = ${i++} ) in ${n.type} ${n.name};
|
|
`}return t}getStructMembers(e){let t=[];for(let s of e.members)t.push(` ${s.type} ${s.name};`);return t.join(`
|
|
`)}getStructs(e){let t=[],s=this.structs[e],i=[];for(let n of s)if(n.output)for(let r of n.members)i.push(`layout( location = ${r.index} ) out ${r.type} ${r.name};`);else{let r="struct "+n.name+` {
|
|
`;r+=this.getStructMembers(n),r+=`
|
|
};
|
|
`,t.push(r)}return i.length===0&&i.push("layout( location = 0 ) out vec4 fragColor;"),`
|
|
`+i.join(`
|
|
`)+`
|
|
|
|
`+t.join(`
|
|
`)}getVaryings(e){let t="",s=this.varyings;if(e==="vertex"||e==="compute")for(let i of s){e==="compute"&&(i.needsInterpolation=!0);let n=this.getType(i.type);if(i.needsInterpolation)if(i.interpolationType){let r=F_[i.interpolationType]||i.interpolationType,a=I_[i.interpolationSampling]||"";t+=`${r} ${a} out ${n} ${i.name};
|
|
`}else{let r=n.includes("int")||n.includes("uv")||n.includes("iv")?"flat ":"";t+=`${r}out ${n} ${i.name};
|
|
`}else t+=`${n} ${i.name};
|
|
`}else if(e==="fragment"){for(let i of s)if(i.needsInterpolation){let n=this.getType(i.type);if(i.interpolationType){let r=F_[i.interpolationType]||i.interpolationType,a=I_[i.interpolationSampling]||"";t+=`${r} ${a} in ${n} ${i.name};
|
|
`}else{let r=n.includes("int")||n.includes("uv")||n.includes("iv")?"flat ":"";t+=`${r}in ${n} ${i.name};
|
|
`}}}for(let i of this.builtins[e])t+=`${i};
|
|
`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce((s,i)=>s*i,1)}u`}getSubgroupSize(){O("GLSLNodeBuilder: WebGLBackend does not support the subgroupSize node")}getInvocationSubgroupIndex(){O("GLSLNodeBuilder: WebGLBackend does not support the invocationSubgroupIndex node")}getSubgroupIndex(){O("GLSLNodeBuilder: WebGLBackend does not support the subgroupIndex node")}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(e,t,s=this.shaderStage){let i=this.extensions[s]||(this.extensions[s]=new Map);i.has(e)===!1&&i.set(e,{name:e,behavior:t})}getExtensions(e){let t=[];if(e==="vertex"){let i=this.renderer.backend.extensions;this.object.isBatchedMesh&&i.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}let s=this.extensions[e];if(s!==void 0)for(let{name:i,behavior:n}of s.values())t.push(`#extension ${i} : ${n}`);return t.join(`
|
|
`)}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=B_[e];if(t===void 0){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance";break}if(s!==void 0){let i=this.renderer.backend.extensions;i.has(s)&&(i.get(s),t=!0)}B_[e]=t}return t}isFlipY(){return!0}getUniformBufferLimit(){let e=this.renderer.backend.gl;return e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE)}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}enableMultiview(){this.enableExtension("GL_OVR_multiview2","require","fragment"),this.enableExtension("GL_OVR_multiview2","require","vertex"),this.builtins.vertex.push("layout(num_views = 2) in")}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){let e=this.transforms,t="";for(let s=0;s<e.length;s++){let i=e[s],n=this.getPropertyName(i.attributeNode);n&&(t+=`${i.varyingName} = ${n};
|
|
`)}return t}_getGLSLUniformStruct(e,t){return`
|
|
layout( std140 ) uniform ${e} {
|
|
${t}
|
|
};`}_getGLSLVertexCode(e){return`#version 300 es
|
|
|
|
${this.getSignature()}
|
|
|
|
// extensions
|
|
${e.extensions}
|
|
|
|
// precision
|
|
${P_}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
|
|
// attributes
|
|
${e.attributes}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
void main() {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// transforms
|
|
${e.transforms}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
gl_PointSize = 1.0;
|
|
|
|
}
|
|
`}_getGLSLFragmentCode(e){return`#version 300 es
|
|
|
|
${this.getSignature()}
|
|
|
|
// extensions
|
|
${e.extensions}
|
|
|
|
// precision
|
|
${P_}
|
|
|
|
// structs
|
|
${e.structs}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
void main() {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}buildCode(){let e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(let t in e){let s=`// code
|
|
|
|
`;s+=this.flowCode[t];let i=this.flowNodes[t],n=i[i.length-1];for(let a of i){let c=this.getFlowData(a),l=a.name;l&&(s.length>0&&(s+=`
|
|
`),s+=` // flow -> ${l}
|
|
`),s+=`${c.code}
|
|
`,a===n&&t!=="compute"&&(s+=`// result
|
|
`,t==="vertex"?(s+="gl_Position = ",s+=`${c.result};`):t==="fragment"&&(a.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${c.result};`)))}let r=e[t];r.extensions=this.getExtensions(t),r.uniforms=this.getUniforms(t),r.attributes=this.getAttributes(t),r.varyings=this.getVaryings(t),r.vars=this.getVars(t),r.structs=this.getStructs(t),r.codes=this.getCodes(t),r.transforms=this.getTransforms(t),r.flow=s}this.material!==null?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,i=null){let n=super.getUniformFromNode(e,t,s,i),r=this.getDataFromNode(e,s,this.globalCache),a=r.uniformGPU;if(a===void 0){let c=e.groupNode,l=c.name,u=this.getBindGroupArray(l,s);if(t==="texture")a=new No(n.name,n.node,c),u.push(a);else if(t==="cubeTexture"||t==="cubeDepthTexture")a=new Yh(n.name,n.node,c),u.push(a);else if(t==="texture3D")a=new Cc(n.name,n.node,c),u.push(a);else if(t==="buffer"){n.name=`buffer${e.id}`;let h=this.getSharedDataFromNode(e),d=h.buffer;d===void 0&&(e.name=`NodeBuffer_${e.id}`,d=new qh(e,c),d.name=e.name,h.buffer=d),u.push(d),a=d}else{let h=this.uniformGroups[l];h===void 0?(h=new Hh(l,c),this.uniformGroups[l]=h,u.push(h)):u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(n,t);let d=a.name;h.uniforms.some(m=>m.name===d)||h.addUniform(a)}r.uniformGPU=a}return n}},cf=null,co=null,jh=class{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[As.RENDER]:null,[As.COMPUTE]:null},this.trackTimestamp=e.trackTimestamp===!0}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){let t=this.get(e),s=this.renderer.info.frame,i;e.isComputeNode===!0?i="c:"+this.renderer.info.compute.frameCalls:i="r:"+this.renderer.info.render.frameCalls,t.timestampUID=i+":"+e.id+":f"+s}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){let t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){let t=e.startsWith("c:")?As.COMPUTE:As.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}hasTimestamp(e){return this._getQueryPool(e).hasTimestamp(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp){_e("WebGPURenderer: Timestamp tracking is disabled.");return}let t=this.timestampQueryPool[e];if(!t)return;let s=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=s,s}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getMaxAnisotropy(){}getDrawingBufferSize(){return cf=cf||new re,this.renderer.getDrawingBufferSize(cf)}setScissorTest(){}getClearColor(){let e=this.renderer;return co=co||new Tc,e.getClearColor(co),co.getRGB(co),co}getDomElement(){let e=this.domElement;return e===null&&(e=this.parameters.canvas!==void 0?this.parameters.canvas:Mb(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${"183"} webgpu`),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}dispose(){}},ZF=0,xy=class{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[this.activeBufferIndex^1]}switchBuffers(){this.activeBufferIndex^=1}},by=class{constructor(e){this.backend=e}createAttribute(e,t){let s=this.backend,{gl:i}=s,n=e.array,r=e.usage||i.STATIC_DRAW,a=e.isInterleavedBufferAttribute?e.data:e,c=s.get(a),l=c.bufferGPU;l===void 0&&(l=this._createBuffer(i,t,n,r),c.bufferGPU=l,c.bufferType=t,c.version=a.version);let u;if(n instanceof Float32Array)u=i.FLOAT;else if(typeof Float16Array<"u"&&n instanceof Float16Array)u=i.HALF_FLOAT;else if(n instanceof Uint16Array)e.isFloat16BufferAttribute?u=i.HALF_FLOAT:u=i.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=i.SHORT;else if(n instanceof Uint32Array)u=i.UNSIGNED_INT;else if(n instanceof Int32Array)u=i.INT;else if(n instanceof Int8Array)u=i.BYTE;else if(n instanceof Uint8Array)u=i.UNSIGNED_BYTE;else if(n instanceof Uint8ClampedArray)u=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);let h={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===i.INT||u===i.UNSIGNED_INT||e.gpuType===ut,id:ZF++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){let d=this._createBuffer(i,t,n,r);h=new xy(h,d)}s.set(e,h)}updateAttribute(e){let t=this.backend,{gl:s}=t,i=e.array,n=e.isInterleavedBufferAttribute?e.data:e,r=t.get(n),a=r.bufferType,c=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(a,r.bufferGPU),c.length===0)s.bufferSubData(a,0,i);else{for(let l=0,u=c.length;l<u;l++){let h=c[l];s.bufferSubData(a,h.start*i.BYTES_PER_ELEMENT,i,h.start,h.count)}n.clearUpdateRanges()}s.bindBuffer(a,null),r.version=n.version}destroyAttribute(e){let t=this.backend,{gl:s}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);let i=t.get(e);s.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e){let t=this.backend,{gl:s}=t,i=e.isInterleavedBufferAttribute?e.data:e,{bufferGPU:n}=t.get(i),r=e.array,a=r.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,n);let c=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,c),s.bufferData(s.COPY_WRITE_BUFFER,a,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,a),await t.utils._clientWaitAsync();let l=new e.array.constructor(r.length);return s.bindBuffer(s.COPY_WRITE_BUFFER,c),s.getBufferSubData(s.COPY_WRITE_BUFFER,0,l),s.deleteBuffer(c),s.bindBuffer(s.COPY_READ_BUFFER,null),s.bindBuffer(s.COPY_WRITE_BUFFER,null),l.buffer}_createBuffer(e,t,s,i){let n=e.createBuffer();return e.bindBuffer(t,n),e.bufferData(t,s,i),e.bindBuffer(t,null),n}},Qa,Ii,_y=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){let e=this.gl;Qa={[Xt]:e.FUNC_ADD,[cp]:e.FUNC_SUBTRACT,[lp]:e.FUNC_REVERSE_SUBTRACT},Ii={[Ni]:e.ZERO,[up]:e.ONE,[hp]:e.SRC_COLOR,[Ir]:e.SRC_ALPHA,[yp]:e.SRC_ALPHA_SATURATE,[mp]:e.DST_COLOR,[pp]:e.DST_ALPHA,[dp]:e.ONE_MINUS_SRC_COLOR,[Pr]:e.ONE_MINUS_SRC_ALPHA,[gp]:e.ONE_MINUS_DST_COLOR,[fp]:e.ONE_MINUS_DST_ALPHA};let t=e.getParameter(e.SCISSOR_BOX),s=e.getParameter(e.VIEWPORT);this.currentScissor=new Te().fromArray(t),this.currentViewport=new Te().fromArray(s),this._tempVec4=new Te}enable(e){let{enabled:t}=this;t[e]!==!0&&(this.gl.enable(e),t[e]=!0)}disable(e){let{enabled:t}=this;t[e]!==!1&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){let{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){let{gl:t}=this;e!==$0?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===q0?t.cullFace(t.BACK):e===H0?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){let{currentLineWidth:t,gl:s}=this;e!==t&&(s.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,s){let i=this.gl,n=this.backend.drawBuffersIndexedExt;if(!n){_e("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");return}for(let r=0;r<e.length;r++){let a=e[r],c=null;if(t!==null){let l=t.getBlendMode(a.name);l.blending===eu?c=s:l.blending!==qs&&(c=l)}else c=s;c!==null?this._setMRTBlendingIndex(r,c):n.blendFuncSeparateiOES(r,i.ONE,i.ZERO,i.ONE,i.ZERO)}}_setMRTBlendingIndex(e,t){let{gl:s}=this,i=this.backend.drawBuffersIndexedExt,n=t.blending,r=t.blendSrc,a=t.blendDst,c=t.blendEquation,l=t.premultipliedAlpha;if(n===$n){let u=t.blendSrcAlpha!==null?t.blendSrcAlpha:r,h=t.blendDstAlpha!==null?t.blendDstAlpha:a,d=t.blendEquationAlpha!==null?t.blendEquationAlpha:c;i.blendEquationSeparateiOES(e,Qa[c],Qa[d]),i.blendFuncSeparateiOES(e,Ii[r],Ii[a],Ii[u],Ii[h])}else if(i.blendEquationSeparateiOES(e,s.FUNC_ADD,s.FUNC_ADD),l)switch(n){case Ht:i.blendFuncSeparateiOES(e,s.ONE,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);break;case zn:i.blendFuncSeparateiOES(e,s.ONE,s.ONE,s.ONE,s.ONE);break;case Gn:i.blendFuncSeparateiOES(e,s.ZERO,s.ONE_MINUS_SRC_COLOR,s.ZERO,s.ONE);break;case Wn:i.blendFuncSeparateiOES(e,s.DST_COLOR,s.ONE_MINUS_SRC_ALPHA,s.ZERO,s.ONE);break;default:i.blendFuncSeparateiOES(e,s.ONE,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);break}else switch(n){case Ht:i.blendFuncSeparateiOES(e,s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);break;case zn:i.blendFuncSeparateiOES(e,s.SRC_ALPHA,s.ONE,s.ONE,s.ONE);break;case Gn:i.blendFuncSeparateiOES(e,s.ZERO,s.ONE_MINUS_SRC_COLOR,s.ZERO,s.ONE);break;case Wn:i.blendFuncSeparateiOES(e,s.DST_COLOR,s.ONE_MINUS_SRC_ALPHA,s.ZERO,s.ONE);break;default:i.blendFuncSeparateiOES(e,s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);break}}setBlending(e,t,s,i,n,r,a,c){let{gl:l}=this;if(e===qs){this.currentBlendingEnabled===!0&&(this.disable(l.BLEND),this.currentBlendingEnabled=!1);return}if(this.currentBlendingEnabled===!1&&(this.enable(l.BLEND),this.currentBlendingEnabled=!0),e!==$n){if(e!==this.currentBlending||c!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==Xt||this.currentBlendEquationAlpha!==Xt)&&(l.blendEquation(l.FUNC_ADD),this.currentBlendEquation=Xt,this.currentBlendEquationAlpha=Xt),c)switch(e){case Ht:l.blendFuncSeparate(l.ONE,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case zn:l.blendFunc(l.ONE,l.ONE);break;case Gn:l.blendFuncSeparate(l.ZERO,l.ONE_MINUS_SRC_COLOR,l.ZERO,l.ONE);break;case Wn:l.blendFuncSeparate(l.DST_COLOR,l.ONE_MINUS_SRC_ALPHA,l.ZERO,l.ONE);break;default:O("WebGLState: Invalid blending: ",e);break}else switch(e){case Ht:l.blendFuncSeparate(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case zn:l.blendFuncSeparate(l.SRC_ALPHA,l.ONE,l.ONE,l.ONE);break;case Gn:O("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case Wn:O("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:O("WebGLState: Invalid blending: ",e);break}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=c}return}n=n||t,r=r||s,a=a||i,(t!==this.currentBlendEquation||n!==this.currentBlendEquationAlpha)&&(l.blendEquationSeparate(Qa[t],Qa[n]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=n),(s!==this.currentBlendSrc||i!==this.currentBlendDst||r!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(l.blendFuncSeparate(Ii[s],Ii[i],Ii[r],Ii[a]),this.currentBlendSrc=s,this.currentBlendDst=i,this.currentBlendSrcAlpha=r,this.currentBlendDstAlpha=a),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){let{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){let t=this.backend.extensions.get("EXT_clip_control");e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),this.currentDepthReversed=e}}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthReversed&&(e=Np[e]),this.currentDepthFunc!==e){let{gl:t}=this;switch(e){case Oo:t.depthFunc(t.NEVER);break;case Vo:t.depthFunc(t.ALWAYS);break;case ko:t.depthFunc(t.LESS);break;case In:t.depthFunc(t.LEQUAL);break;case zo:t.depthFunc(t.EQUAL);break;case Go:t.depthFunc(t.GEQUAL);break;case Wo:t.depthFunc(t.GREATER);break;case $o:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,s,i){let n=this._tempVec4.set(e,t,s,i);if(this.currentScissor.equals(n)===!1){let{gl:r}=this;r.scissor(n.x,n.y,n.z,n.w),this.currentScissor.copy(n)}}viewport(e,t,s,i){let n=this._tempVec4.set(e,t,s,i);if(this.currentViewport.equals(n)===!1){let{gl:r}=this;r.viewport(n.x,n.y,n.z,n.w),this.currentViewport.copy(n)}}setScissorTest(e){let t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){let{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,s){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==s)&&(this.gl.stencilFunc(e,t,s),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=s)}setStencilOp(e,t,s){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==s)&&(this.gl.stencilOp(e,t,s),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=s)}setMaterial(e,t,s){let{gl:i}=this;e.side===$s?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let n=e.side===rt;t&&(n=!n),this.setFlipSided(n),e.blending===Ht&&e.transparent===!1?this.setBlending(qs):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);let r=e.stencilWrite;if(this.setStencilTest(r),r&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),e.alphaToCoverage===!0&&this.backend.renderer.currentSamples>0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s)for(let c=0;c<8;c++)c<s?this.enable(12288+c):this.disable(12288+c)}setPolygonOffset(e,t,s){let{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==s)&&(i.polygonOffset(t,s),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=s)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e?(this.gl.useProgram(e),this.currentProgram=e,!0):!1}setVertexState(e,t=null){let s=this.gl;return this.currentVAO!==e||this.currentIndex!==t?(s.bindVertexArray(e),t!==null&&s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0):!1}resetVertexState(){let e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){let{gl:s,currentBoundFramebuffers:i}=this;return i[e]!==t?(s.bindFramebuffer(e,t),i[e]=t,e===s.DRAW_FRAMEBUFFER&&(i[s.FRAMEBUFFER]=t),e===s.FRAMEBUFFER&&(i[s.DRAW_FRAMEBUFFER]=t),!0):!1}drawBuffers(e,t){let{gl:s}=this,i=[],n=!1;if(e.textures!==null){i=this.currentDrawbuffers.get(t),i===void 0&&(i=[],this.currentDrawbuffers.set(t,i));let r=e.textures;if(i.length!==r.length||i[0]!==s.COLOR_ATTACHMENT0){for(let a=0,c=r.length;a<c;a++)i[a]=s.COLOR_ATTACHMENT0+a;i.length=r.length,n=!0}}else i[0]!==s.BACK&&(i[0]=s.BACK,n=!0);n&&s.drawBuffers(i)}activeTexture(e){let{gl:t,currentTextureSlot:s,maxTextures:i}=this;e===void 0&&(e=t.TEXTURE0+i-1),s!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,s){let{gl:i,currentTextureSlot:n,currentBoundTextures:r,maxTextures:a}=this;s===void 0&&(n===null?s=i.TEXTURE0+a-1:s=n);let c=r[s];c===void 0&&(c={type:void 0,texture:void 0},r[s]=c),(c.type!==e||c.texture!==t)&&(n!==s&&(i.activeTexture(s),this.currentTextureSlot=s),i.bindTexture(e,t),c.type=e,c.texture=t)}bindBufferBase(e,t,s){let{gl:i}=this,n=`${e}-${t}`;return this.currentBoundBufferBases[n]!==s?(i.bindBufferBase(e,t,s),this.currentBoundBufferBases[n]=s,!0):!1}unbindTexture(){let{gl:e,currentTextureSlot:t,currentBoundTextures:s}=this,i=s[t];i!==void 0&&i.type!==void 0&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}},Ty=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=Bi){let{gl:s,extensions:i}=this,n,r=me.getTransfer(t);if(e===lt)return s.UNSIGNED_BYTE;if(e===bp)return s.UNSIGNED_SHORT_4_4_4_4;if(e===_p)return s.UNSIGNED_SHORT_5_5_5_1;if(e===ou)return s.UNSIGNED_INT_5_9_9_9_REV;if(e===au)return s.UNSIGNED_INT_10F_11F_11F_REV;if(e===Hn)return s.BYTE;if(e===Xn)return s.SHORT;if(e===rn)return s.UNSIGNED_SHORT;if(e===ut)return s.INT;if(e===Oe)return s.UNSIGNED_INT;if(e===Ct)return s.FLOAT;if(e===$e)return s.HALF_FLOAT;if(e===Tp)return s.ALPHA;if(e===la)return s.RGB;if(e===Lt)return s.RGBA;if(e===ns)return s.DEPTH_COMPONENT;if(e===Hs)return s.DEPTH_STENCIL;if(e===ua)return s.RED;if(e===ha)return s.RED_INTEGER;if(e===Ms)return s.RG;if(e===da)return s.RG_INTEGER;if(e===pa)return s.RGBA_INTEGER;if(e===qr||e===Hr||e===Xr||e===Yr)if(r===ne)if(n=i.get("WEBGL_compressed_texture_s3tc_srgb"),n!==null){if(e===qr)return n.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===Hr)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===Xr)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===Yr)return n.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(n=i.get("WEBGL_compressed_texture_s3tc"),n!==null){if(e===qr)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Hr)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===Xr)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Yr)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(e===cu||e===lu||e===uu||e===hu)if(n=i.get("WEBGL_compressed_texture_pvrtc"),n!==null){if(e===cu)return n.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===lu)return n.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===uu)return n.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===hu)return n.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(e===fa||e===ma||e===ga||e===ya||e===xa||e===jr||e===ba)if(n=i.get("WEBGL_compressed_texture_etc"),n!==null){if(e===fa||e===ma)return r===ne?n.COMPRESSED_SRGB8_ETC2:n.COMPRESSED_RGB8_ETC2;if(e===ga)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:n.COMPRESSED_RGBA8_ETC2_EAC;if(e===ya)return n.COMPRESSED_R11_EAC;if(e===xa)return n.COMPRESSED_SIGNED_R11_EAC;if(e===jr)return n.COMPRESSED_RG11_EAC;if(e===ba)return n.COMPRESSED_SIGNED_RG11_EAC}else return null;if(e===_a||e===Ta||e===Sa||e===va||e===wa||e===Ma||e===Aa||e===Na||e===Ra||e===Ca||e===Ea||e===Ba||e===Fa||e===Ia)if(n=i.get("WEBGL_compressed_texture_astc"),n!==null){if(e===_a)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:n.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===Ta)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:n.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===Sa)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:n.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===va)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:n.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===wa)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:n.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===Ma)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:n.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===Aa)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:n.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===Na)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:n.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===Ra)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:n.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===Ca)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:n.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===Ea)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:n.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===Ba)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:n.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===Fa)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:n.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===Ia)return r===ne?n.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:n.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(e===Pa)if(n=i.get("EXT_texture_compression_bptc"),n!==null){if(e===Pa)return r===ne?n.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:n.COMPRESSED_RGBA_BPTC_UNORM_EXT}else return null;if(e===Da||e===La||e===Zr||e===Ua)if(n=i.get("EXT_texture_compression_rgtc"),n!==null){if(e===Da)return n.COMPRESSED_RED_RGTC1_EXT;if(e===La)return n.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===Zr)return n.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===Ua)return n.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return e===Ei?s.UNSIGNED_INT_24_8:s[e]!==void 0?s[e]:null}_clientWaitAsync(){let{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((s,i)=>{function n(){let r=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(r===e.WAIT_FAILED){e.deleteSync(t),i();return}if(r===e.TIMEOUT_EXPIRED){requestAnimationFrame(n);return}e.deleteSync(t),s()}n()})}},D_=!1,ku,lf,L_,Sy=class{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,D_===!1&&(this._init(),D_=!0)}_init(){let e=this.gl;ku={[Pn]:e.REPEAT,[bs]:e.CLAMP_TO_EDGE,[Dn]:e.MIRRORED_REPEAT},lf={[Ue]:e.NEAREST,[xp]:e.NEAREST_MIPMAP_NEAREST,[$r]:e.NEAREST_MIPMAP_LINEAR,[ct]:e.LINEAR,[ru]:e.LINEAR_MIPMAP_NEAREST,[Ci]:e.LINEAR_MIPMAP_LINEAR},L_={[vp]:e.NEVER,[Ap]:e.ALWAYS,[pu]:e.LESS,[Jr]:e.LEQUAL,[wp]:e.EQUAL,[Yn]:e.GEQUAL,[Oa]:e.GREATER,[Mp]:e.NOTEQUAL}}getGLTextureType(e){let{gl:t}=this,s;return e.isCubeTexture===!0?s=t.TEXTURE_CUBE_MAP:e.isArrayTexture===!0||e.isDataArrayTexture===!0||e.isCompressedArrayTexture===!0?s=t.TEXTURE_2D_ARRAY:e.isData3DTexture===!0?s=t.TEXTURE_3D:s=t.TEXTURE_2D,s}getInternalFormat(e,t,s,i,n=!1){let{gl:r,extensions:a}=this;if(e!==null){if(r[e]!==void 0)return r[e];z("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let c=t;if(t===r.RED&&(s===r.FLOAT&&(c=r.R32F),s===r.HALF_FLOAT&&(c=r.R16F),s===r.UNSIGNED_BYTE&&(c=r.R8),s===r.UNSIGNED_SHORT&&(c=r.R16),s===r.UNSIGNED_INT&&(c=r.R32UI),s===r.BYTE&&(c=r.R8I),s===r.SHORT&&(c=r.R16I),s===r.INT&&(c=r.R32I)),t===r.RED_INTEGER&&(s===r.UNSIGNED_BYTE&&(c=r.R8UI),s===r.UNSIGNED_SHORT&&(c=r.R16UI),s===r.UNSIGNED_INT&&(c=r.R32UI),s===r.BYTE&&(c=r.R8I),s===r.SHORT&&(c=r.R16I),s===r.INT&&(c=r.R32I)),t===r.RG&&(s===r.FLOAT&&(c=r.RG32F),s===r.HALF_FLOAT&&(c=r.RG16F),s===r.UNSIGNED_BYTE&&(c=r.RG8),s===r.UNSIGNED_SHORT&&(c=r.RG16),s===r.UNSIGNED_INT&&(c=r.RG32UI),s===r.BYTE&&(c=r.RG8I),s===r.SHORT&&(c=r.RG16I),s===r.INT&&(c=r.RG32I)),t===r.RG_INTEGER&&(s===r.UNSIGNED_BYTE&&(c=r.RG8UI),s===r.UNSIGNED_SHORT&&(c=r.RG16UI),s===r.UNSIGNED_INT&&(c=r.RG32UI),s===r.BYTE&&(c=r.RG8I),s===r.SHORT&&(c=r.RG16I),s===r.INT&&(c=r.RG32I)),t===r.RGB){let l=n?Xo:me.getTransfer(i);s===r.FLOAT&&(c=r.RGB32F),s===r.HALF_FLOAT&&(c=r.RGB16F),s===r.UNSIGNED_BYTE&&(c=r.RGB8),s===r.UNSIGNED_SHORT&&(c=r.RGB16),s===r.UNSIGNED_INT&&(c=r.RGB32UI),s===r.BYTE&&(c=r.RGB8I),s===r.SHORT&&(c=r.RGB16I),s===r.INT&&(c=r.RGB32I),s===r.UNSIGNED_BYTE&&(c=l===ne?r.SRGB8:r.RGB8),s===r.UNSIGNED_SHORT_5_6_5&&(c=r.RGB565),s===r.UNSIGNED_SHORT_5_5_5_1&&(c=r.RGB5_A1),s===r.UNSIGNED_SHORT_4_4_4_4&&(c=r.RGB4),s===r.UNSIGNED_INT_5_9_9_9_REV&&(c=r.RGB9_E5),s===r.UNSIGNED_INT_10F_11F_11F_REV&&(c=r.R11F_G11F_B10F)}if(t===r.RGB_INTEGER&&(s===r.UNSIGNED_BYTE&&(c=r.RGB8UI),s===r.UNSIGNED_SHORT&&(c=r.RGB16UI),s===r.UNSIGNED_INT&&(c=r.RGB32UI),s===r.BYTE&&(c=r.RGB8I),s===r.SHORT&&(c=r.RGB16I),s===r.INT&&(c=r.RGB32I)),t===r.RGBA){let l=n?Xo:me.getTransfer(i);s===r.FLOAT&&(c=r.RGBA32F),s===r.HALF_FLOAT&&(c=r.RGBA16F),s===r.UNSIGNED_BYTE&&(c=r.RGBA8),s===r.UNSIGNED_SHORT&&(c=r.RGBA16),s===r.UNSIGNED_INT&&(c=r.RGBA32UI),s===r.BYTE&&(c=r.RGBA8I),s===r.SHORT&&(c=r.RGBA16I),s===r.INT&&(c=r.RGBA32I),s===r.UNSIGNED_BYTE&&(c=l===ne?r.SRGB8_ALPHA8:r.RGBA8),s===r.UNSIGNED_SHORT_4_4_4_4&&(c=r.RGBA4),s===r.UNSIGNED_SHORT_5_5_5_1&&(c=r.RGB5_A1)}return t===r.RGBA_INTEGER&&(s===r.UNSIGNED_BYTE&&(c=r.RGBA8UI),s===r.UNSIGNED_SHORT&&(c=r.RGBA16UI),s===r.UNSIGNED_INT&&(c=r.RGBA32UI),s===r.BYTE&&(c=r.RGBA8I),s===r.SHORT&&(c=r.RGBA16I),s===r.INT&&(c=r.RGBA32I)),t===r.DEPTH_COMPONENT&&(s===r.UNSIGNED_SHORT&&(c=r.DEPTH_COMPONENT16),s===r.UNSIGNED_INT&&(c=r.DEPTH_COMPONENT24),s===r.FLOAT&&(c=r.DEPTH_COMPONENT32F)),t===r.DEPTH_STENCIL&&s===r.UNSIGNED_INT_24_8&&(c=r.DEPTH24_STENCIL8),(c===r.R16F||c===r.R32F||c===r.RG16F||c===r.RG32F||c===r.RGBA16F||c===r.RGBA32F)&&a.get("EXT_color_buffer_float"),c}setTextureParameters(e,t){let{gl:s,extensions:i,backend:n}=this,r=me.getPrimaries(me.workingColorSpace),a=t.colorSpace===Bi?null:me.getPrimaries(t.colorSpace),c=t.colorSpace===Bi||r===a?s.NONE:s.BROWSER_DEFAULT_WEBGL;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,c),s.texParameteri(e,s.TEXTURE_WRAP_S,ku[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,ku[t.wrapT]),(e===s.TEXTURE_3D||e===s.TEXTURE_2D_ARRAY)&&(t.isArrayTexture||s.texParameteri(e,s.TEXTURE_WRAP_R,ku[t.wrapR])),s.texParameteri(e,s.TEXTURE_MAG_FILTER,lf[t.magFilter]);let l=t.mipmaps!==void 0&&t.mipmaps.length>0,u=t.minFilter===ct&&l?Ci:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,lf[u]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,L_[t.compareFunction])),i.has("EXT_texture_filter_anisotropic")===!0){if(t.magFilter===Ue||t.minFilter!==$r&&t.minFilter!==Ci||t.type===Ct&&i.has("OES_texture_float_linear")===!1)return;if(t.anisotropy>1){let h=i.get("EXT_texture_filter_anisotropic");s.texParameterf(e,h.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){let{gl:t,backend:s,defaultTextures:i}=this,n=this.getGLTextureType(e),r=i[n];r===void 0&&(r=t.createTexture(),s.state.bindTexture(n,r),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),i[n]=r),s.set(e,{textureGPU:r,glTextureType:n})}createTexture(e,t){let{gl:s,backend:i}=this,{levels:n,width:r,height:a,depth:c}=t,l=i.utils.convert(e.format,e.colorSpace),u=i.utils.convert(e.type),h=this.getInternalFormat(e.internalFormat,l,u,e.colorSpace,e.isVideoTexture),d=s.createTexture(),p=this.getGLTextureType(e);i.state.bindTexture(p,d),this.setTextureParameters(p,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,h,r,a,c):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,h,r,a,c):e.isVideoTexture||s.texStorage2D(p,n,h,r,a),i.set(e,{textureGPU:d,glTextureType:p,glFormat:l,glType:u,glInternalFormat:h})}copyBufferToTexture(e,t){let{gl:s,backend:i}=this,{textureGPU:n,glTextureType:r,glFormat:a,glType:c}=i.get(t),{width:l,height:u}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(r,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(r,0,0,0,l,u,a,c,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){let{gl:s}=this,{width:i,height:n}=t,{textureGPU:r,glTextureType:a,glFormat:c,glType:l,glInternalFormat:u}=this.backend.get(e);if(!(e.isRenderTargetTexture||r===void 0))if(this.backend.state.bindTexture(a,r),this.setTextureParameters(a,e),e.isCompressedTexture){let h=e.mipmaps,d=t.image;for(let p=0;p<h.length;p++){let m=h[p];e.isCompressedArrayTexture?e.format!==s.RGBA?c!==null?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,p,0,0,0,m.width,m.height,d.depth,c,m.data):z("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,p,0,0,0,m.width,m.height,d.depth,c,l,m.data):c!==null?s.compressedTexSubImage2D(s.TEXTURE_2D,p,0,0,m.width,m.height,c,m.data):z("WebGLBackend: Unsupported compressed texture format")}}else if(e.isCubeTexture){let h=t.images,d=e.mipmaps;for(let p=0;p<6;p++){let m=zu(h[p]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,0,0,i,n,c,l,m);for(let g=0;g<d.length;g++){let y=d[g],x=zu(y.images[p]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+p,g+1,0,0,x.width,x.height,c,l,x)}}}else if(e.isDataArrayTexture||e.isArrayTexture){let h=t.image;if(e.layerUpdates.size>0){let d=Cb(h.width,h.height,e.format,e.type);for(let p of e.layerUpdates){let m=h.data.subarray(p*d/h.data.BYTES_PER_ELEMENT,(p+1)*d/h.data.BYTES_PER_ELEMENT);s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,p,h.width,h.height,1,c,l,m)}e.clearLayerUpdates()}else s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,h.width,h.height,h.depth,c,l,h.data)}else if(e.isData3DTexture){let h=t.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,h.width,h.height,h.depth,c,l,h.data)}else if(e.isVideoTexture)e.update(),s.texImage2D(a,0,u,c,l,t.image);else{let h=e.mipmaps;if(h.length>0)for(let d=0,p=h.length;d<p;d++){let m=h[d],g=zu(m);s.texSubImage2D(a,d,0,0,m.width,m.height,c,l,g)}else{let d=zu(t.image);s.texSubImage2D(a,0,0,0,i,n,c,l,d)}}}generateMipmaps(e){let{gl:t,backend:s}=this,{textureGPU:i,glTextureType:n}=s.get(e);s.state.bindTexture(n,i),t.generateMipmap(n)}deallocateRenderBuffers(e){let{gl:t,backend:s}=this;if(e){let i=s.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(let n in i.framebuffers)t.deleteFramebuffer(i.framebuffers[n]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let n=0;n<i.msaaRenderbuffers.length;n++)t.deleteRenderbuffer(i.msaaRenderbuffers[n]);delete i.msaaRenderbuffers}}}destroyTexture(e,t=!1){let{gl:s,backend:i}=this,{textureGPU:n,renderTarget:r}=i.get(e);this.deallocateRenderBuffers(r),t===!1&&s.deleteTexture(n),i.delete(e)}copyTextureToTexture(e,t,s=null,i=null,n=0,r=0){let{gl:a,backend:c}=this,{state:l}=this.backend,{textureGPU:u,glTextureType:h,glType:d,glFormat:p}=c.get(t);l.bindTexture(h,u);let m,g,y,x,_,w,S,E,B,N=e.isCompressedTexture?e.mipmaps[r]:e.image;if(s!==null)m=s.max.x-s.min.x,g=s.max.y-s.min.y,y=s.isBox3?s.max.z-s.min.z:1,x=s.min.x,_=s.min.y,w=s.isBox3?s.min.z:0;else{let Q=Math.pow(2,-n);m=Math.floor(N.width*Q),g=Math.floor(N.height*Q),e.isDataArrayTexture||e.isArrayTexture?y=N.depth:e.isData3DTexture?y=Math.floor(N.depth*Q):y=1,x=0,_=0,w=0}i!==null?(S=i.x,E=i.y,B=i.z):(S=0,E=0,B=0),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,t.flipY),a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),a.pixelStorei(a.UNPACK_ALIGNMENT,t.unpackAlignment);let C=a.getParameter(a.UNPACK_ROW_LENGTH),I=a.getParameter(a.UNPACK_IMAGE_HEIGHT),k=a.getParameter(a.UNPACK_SKIP_PIXELS),W=a.getParameter(a.UNPACK_SKIP_ROWS),X=a.getParameter(a.UNPACK_SKIP_IMAGES);a.pixelStorei(a.UNPACK_ROW_LENGTH,N.width),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,N.height),a.pixelStorei(a.UNPACK_SKIP_PIXELS,x),a.pixelStorei(a.UNPACK_SKIP_ROWS,_),a.pixelStorei(a.UNPACK_SKIP_IMAGES,w);let Y=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,ee=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){let Q=c.get(e),ie=c.get(t),Pe=c.get(Q.renderTarget),Se=c.get(ie.renderTarget),ae=Pe.framebuffers[Q.cacheKey],fe=Se.framebuffers[ie.cacheKey];l.bindFramebuffer(a.READ_FRAMEBUFFER,ae),l.bindFramebuffer(a.DRAW_FRAMEBUFFER,fe);for(let Fe=0;Fe<y;Fe++)Y&&(a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,Q.textureGPU,n,w+Fe),a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,r,B+Fe)),a.blitFramebuffer(x,_,m,g,S,E,m,g,a.DEPTH_BUFFER_BIT,a.NEAREST);l.bindFramebuffer(a.READ_FRAMEBUFFER,null),l.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else if(n!==0||e.isRenderTargetTexture||c.has(e)){let Q=c.get(e);this._srcFramebuffer===null&&(this._srcFramebuffer=a.createFramebuffer()),this._dstFramebuffer===null&&(this._dstFramebuffer=a.createFramebuffer()),l.bindFramebuffer(a.READ_FRAMEBUFFER,this._srcFramebuffer),l.bindFramebuffer(a.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let ie=0;ie<y;ie++)Y?a.framebufferTextureLayer(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,Q.textureGPU,n,w+ie):a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,Q.textureGPU,n),ee?a.framebufferTextureLayer(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,u,r,B+ie):a.framebufferTexture2D(a.DRAW_FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,u,r),n!==0?a.blitFramebuffer(x,_,m,g,S,E,m,g,a.COLOR_BUFFER_BIT,a.NEAREST):ee?a.copyTexSubImage3D(h,r,S,E,B+ie,x,_,m,g):a.copyTexSubImage2D(h,r,S,E,x,_,m,g);l.bindFramebuffer(a.READ_FRAMEBUFFER,null),l.bindFramebuffer(a.DRAW_FRAMEBUFFER,null)}else ee?e.isDataTexture||e.isData3DTexture?a.texSubImage3D(h,r,S,E,B,m,g,y,p,d,N.data):t.isCompressedArrayTexture?a.compressedTexSubImage3D(h,r,S,E,B,m,g,y,p,N.data):a.texSubImage3D(h,r,S,E,B,m,g,y,p,d,N):e.isDataTexture?a.texSubImage2D(a.TEXTURE_2D,r,S,E,m,g,p,d,N.data):e.isCompressedTexture?a.compressedTexSubImage2D(a.TEXTURE_2D,r,S,E,N.width,N.height,p,N.data):a.texSubImage2D(a.TEXTURE_2D,r,S,E,m,g,p,d,N);a.pixelStorei(a.UNPACK_ROW_LENGTH,C),a.pixelStorei(a.UNPACK_IMAGE_HEIGHT,I),a.pixelStorei(a.UNPACK_SKIP_PIXELS,k),a.pixelStorei(a.UNPACK_SKIP_ROWS,W),a.pixelStorei(a.UNPACK_SKIP_IMAGES,X),r===0&&t.generateMipmaps&&a.generateMipmap(h),l.unbindTexture()}copyFramebufferToTexture(e,t,s){let{gl:i}=this,{state:n}=this.backend,{textureGPU:r}=this.backend.get(e),{x:a,y:c,z:l,w:u}=s,h=e.isDepthTexture===!0||t.renderTarget&&t.renderTarget.samples>0,d=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(h){let p=a!==0||c!==0,m,g;if(e.isDepthTexture===!0?(m=i.DEPTH_BUFFER_BIT,g=i.DEPTH_ATTACHMENT,t.stencil&&(m|=i.STENCIL_BUFFER_BIT)):(m=i.COLOR_BUFFER_BIT,g=i.COLOR_ATTACHMENT0),p){let y=this.backend.get(t.renderTarget),x=y.framebuffers[t.getCacheKey()],_=y.msaaFrameBuffer;n.bindFramebuffer(i.DRAW_FRAMEBUFFER,x),n.bindFramebuffer(i.READ_FRAMEBUFFER,_);let w=d-c-u;i.blitFramebuffer(a,w,a+l,w+u,a,w,a+l,w+u,m,i.NEAREST),n.bindFramebuffer(i.READ_FRAMEBUFFER,x),n.bindTexture(i.TEXTURE_2D,r),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,w,l,u),n.unbindTexture()}else{let y=i.createFramebuffer();n.bindFramebuffer(i.DRAW_FRAMEBUFFER,y),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,g,i.TEXTURE_2D,r,0),i.blitFramebuffer(0,0,l,u,0,0,l,u,m,i.NEAREST),i.deleteFramebuffer(y)}}else n.bindTexture(i.TEXTURE_2D,r),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,d-u-c,l,u),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,s,i=!1){let{gl:n}=this,r=t.renderTarget,{depthTexture:a,depthBuffer:c,stencilBuffer:l,width:u,height:h}=r;if(n.bindRenderbuffer(n.RENDERBUFFER,e),c&&!l){let d=n.DEPTH_COMPONENT24;i===!0?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(n.RENDERBUFFER,r.samples,d,u,h):s>0?(a&&a.isDepthTexture&&a.type===n.FLOAT&&(d=n.DEPTH_COMPONENT32F),n.renderbufferStorageMultisample(n.RENDERBUFFER,s,d,u,h)):n.renderbufferStorage(n.RENDERBUFFER,d,u,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,e)}else c&&l&&(s>0?n.renderbufferStorageMultisample(n.RENDERBUFFER,s,n.DEPTH24_STENCIL8,u,h):n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_STENCIL,u,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_STENCIL_ATTACHMENT,n.RENDERBUFFER,e));n.bindRenderbuffer(n.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,s,i,n,r){let{backend:a,gl:c}=this,{textureGPU:l,glFormat:u,glType:h}=this.backend.get(e),d=c.createFramebuffer();a.state.bindFramebuffer(c.READ_FRAMEBUFFER,d);let p=e.isCubeTexture?c.TEXTURE_CUBE_MAP_POSITIVE_X+r:c.TEXTURE_2D;c.framebufferTexture2D(c.READ_FRAMEBUFFER,c.COLOR_ATTACHMENT0,p,l,0);let m=this._getTypedArrayType(h),g=this._getBytesPerTexel(h,u),x=i*n*g,_=c.createBuffer();c.bindBuffer(c.PIXEL_PACK_BUFFER,_),c.bufferData(c.PIXEL_PACK_BUFFER,x,c.STREAM_READ),c.readPixels(t,s,i,n,u,h,0),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();let w=new m(x/m.BYTES_PER_ELEMENT);return c.bindBuffer(c.PIXEL_PACK_BUFFER,_),c.getBufferSubData(c.PIXEL_PACK_BUFFER,0,w),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(c.READ_FRAMEBUFFER,null),c.deleteFramebuffer(d),w}_getTypedArrayType(e){let{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){let{gl:s}=this,i=0;if(e===s.UNSIGNED_BYTE&&(i=1),(e===s.UNSIGNED_SHORT_4_4_4_4||e===s.UNSIGNED_SHORT_5_5_5_1||e===s.UNSIGNED_SHORT_5_6_5||e===s.UNSIGNED_SHORT||e===s.HALF_FLOAT)&&(i=2),(e===s.UNSIGNED_INT||e===s.FLOAT)&&(i=4),t===s.RGBA)return i*4;if(t===s.RGB)return i*3;if(t===s.ALPHA)return i}dispose(){let{gl:e}=this;this._srcFramebuffer!==null&&e.deleteFramebuffer(this._srcFramebuffer),this._dstFramebuffer!==null&&e.deleteFramebuffer(this._dstFramebuffer)}};function zu(o){return o.isDataTexture?o.image.data:typeof HTMLImageElement<"u"&&o instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&o instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&o instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&o instanceof OffscreenCanvas?o:o.data}var vy=class{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return t===void 0&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}},wy=class{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(this.maxAnisotropy!==null)return this.maxAnisotropy;let e=this.backend.gl,t=this.backend.extensions;if(t.has("EXT_texture_filter_anisotropic")===!0){let s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}},U_={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"},My=class{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){let{gl:s,mode:i,object:n,type:r,info:a,index:c}=this;c!==0?s.drawElements(i,t,r,e):s.drawArrays(i,e,t),a.update(n,t,1)}renderInstances(e,t,s){let{gl:i,mode:n,type:r,index:a,object:c,info:l}=this;s!==0&&(a!==0?i.drawElementsInstanced(n,t,r,e,s):i.drawArraysInstanced(n,e,t,s),l.update(c,t,s))}renderMultiDraw(e,t,s){let{extensions:i,mode:n,object:r,info:a}=this;if(s===0)return;let c=i.get("WEBGL_multi_draw");if(c===null)for(let l=0;l<s;l++)this.render(e[l],t[l]);else{this.index!==0?c.multiDrawElementsWEBGL(n,t,0,this.type,e,0,s):c.multiDrawArraysWEBGL(n,e,0,t,0,s);let l=0;for(let u=0;u<s;u++)l+=t[u];a.update(r,l,1)}}renderMultiDrawInstances(e,t,s,i){let{extensions:n,mode:r,object:a,info:c}=this;if(s===0)return;let l=n.get("WEBGL_multi_draw");if(l===null)for(let u=0;u<s;u++)this.renderInstances(e[u],t[u],i[u]);else{this.index!==0?l.multiDrawElementsInstancedWEBGL(r,t,0,this.type,e,0,i,0,s):l.multiDrawArraysInstancedWEBGL(r,e,0,t,0,i,0,s);let u=0;for(let h=0;h<s;h++)u+=t[h]*i[h];c.update(a,u,1)}}},Zh=class{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.frames=[],this.pendingResolve=!1,this.timestamps=new Map}getTimestampFrames(){return this.frames}getTimestamp(e){let t=this.timestamps.get(e);return t===void 0&&(z(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestamp(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}},Ay=class extends Zh{constructor(e,t,s=2048){if(super(s),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext){z("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let i=0;i<this.maxQueries;i++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;if(this.currentQueryIndex+2>this.maxQueries)return _e(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(t==null||this.activeQuery!==null)return;let s=this.queries[t];if(s)try{this.queryStates.get(t)==="inactive"&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,s),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(i){O("Error in beginQuery:",i),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(t!=null&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(s){O("Error in endQuery:",s),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{let e=new Map;for(let[n,r]of this.queryOffsets)if(this.queryStates.get(r)==="ended"){let c=this.queries[r];e.set(n,this.resolveQuery(c))}if(e.size===0)return this.lastValue;let t={},s=[];for(let[n,r]of e){let a=n.match(/^(.*):f(\d+)$/),c=parseInt(a[2]);s.includes(c)===!1&&s.push(c),t[c]===void 0&&(t[c]=0);let l=await r;this.timestamps.set(n,l),t[c]+=l}let i=t[s[s.length-1]];return this.lastValue=i,this.frames=s,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return O("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{if(this.isDisposed){t(this.lastValue);return}let s,i=!1,n=()=>{s&&(clearTimeout(s),s=null)},r=c=>{i||(i=!0,n(),t(c))},a=()=>{if(this.isDisposed){r(this.lastValue);return}try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT)){r(this.lastValue);return}if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){s=setTimeout(a,1);return}let u=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(u)/1e6)}catch(c){O("Error checking query:",c),t(this.lastValue)}};a()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,!!this.trackTimestamp)){for(let e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.lastValue=0,this.activeQuery=null}}},Jh=class extends jh{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);let t=this.parameters,s={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=t.context!==void 0?t.context:e.domElement.getContext("webgl2",s);function n(r){r.preventDefault();let a={api:"WebGL",message:r.statusMessage||"Unknown reason",reason:null,originalEvent:r};e.onDeviceLost(a)}this._onContextLost=n,e.domElement.addEventListener("webglcontextlost",n,!1),this.gl=i,this.extensions=new vy(this),this.capabilities=new wy(this),this.attributeUtils=new by(this),this.textureUtils=new Sy(this),this.bufferRenderer=new My(this),this.state=new _y(this),this.utils=new Ty(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),t.reversedDepthBuffer===!0&&this.extensions.has("EXT_clip_control")&&this.state.setReversedDepth(!0)}get coordinateSystem(){return Dt}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}async makeXRCompatible(){this.gl.getContextAttributes().xrCompatible!==!0&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,s=null){let i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),s!==null){let n=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:s,glInternalFormat:n}),this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer===!0&&e.multiview===!1&&z("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new Ay(this.gl,e,2048));let s=this.timestampQueryPool[e];s.allocateQueriesForContext(t)!==null&&s.beginQuery(t)}prepareTimestampBuffer(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){let{state:t}=this,s=this.get(e);if(e.viewport)this.updateViewport(e);else{let{width:n,height:r}=this.getDrawingBufferSize();t.viewport(0,0,n,r)}if(e.scissor)this.updateScissor(e);else{let{width:n,height:r}=this.getDrawingBufferSize();t.scissor(0,0,n,r)}this.initTimestampQuery(As.RENDER,this.getTimestampUID(e)),s.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);let i=e.occlusionQueryCount;i>0&&(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(e){let{gl:t,state:s}=this,i=this.get(e),n=i.previousContext;s.resetVertexState();let r=e.occlusionQueryCount;r>0&&(r>i.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));let a=e.textures;if(a!==null)for(let c=0;c<a.length;c++){let l=a[c];l.generateMipmaps&&this.generateMipmaps(l)}if(this._currentContext=n,this._resolveRenderTarget(e),n!==null){if(this._setFramebuffer(n),n.viewport)this.updateViewport(n);else{let{width:c,height:l}=this.getDrawingBufferSize();s.viewport(0,0,c,l)}if(n.scissor)this.updateScissor(n);else{let{width:c,height:l}=this.getDrawingBufferSize();s.scissor(0,0,c,l)}}this.prepareTimestampBuffer(As.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=t;if(s&&i){let n=new WeakSet,{gl:r}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;let a=()=>{let c=0;for(let l=0;l<s.length;l++){let u=s[l];u!==null&&r.getQueryParameter(u,r.QUERY_RESULT_AVAILABLE)&&(r.getQueryParameter(u,r.QUERY_RESULT)===0&&n.add(i[l]),s[l]=null,r.deleteQuery(u),c++)}c<s.length?requestAnimationFrame(a):t.occluded=n};a()}}isOccluded(e,t){let s=this.get(e);return s.occluded&&s.occluded.has(t)}updateViewport(e){let{state:t}=this,{x:s,y:i,width:n,height:r}=e.viewportValue;t.viewport(s,e.height-r-i,n,r)}updateScissor(e){let{state:t}=this,{x:s,y:i,width:n,height:r}=e.scissorValue;t.scissor(s,e.height-r-i,n,r)}setScissorTest(e){this.state.setScissorTest(e)}getClearColor(){let e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,s,i=null,n=!0,r=!0){let{gl:a,renderer:c}=this;i===null&&(i={textures:null,clearColorValue:this.getClearColor()});let l=0;if(e&&(l|=a.COLOR_BUFFER_BIT),t&&(l|=a.DEPTH_BUFFER_BIT),s&&(l|=a.STENCIL_BUFFER_BIT),l!==0){let u;i.clearColorValue?u=i.clearColorValue:u=this.getClearColor();let h=c.getClearDepth(),d=c.getClearStencil();if(t&&this.state.setDepthMask(!0),i.textures===null)a.clearColor(u.r,u.g,u.b,u.a),a.clear(l);else{if(n&&this._setFramebuffer(i),e)for(let p=0;p<i.textures.length;p++)p===0?a.clearBufferfv(a.COLOR,p,[u.r,u.g,u.b,u.a]):a.clearBufferfv(a.COLOR,p,[0,0,0,1]);t&&s?a.clearBufferfi(a.DEPTH_STENCIL,0,h,d):t?a.clearBufferfv(a.DEPTH,0,[h]):s&&a.clearBufferiv(a.STENCIL,0,[d]),n&&r&&this._resolveRenderTarget(i)}}}beginCompute(e){let{state:t,gl:s}=this;t.bindFramebuffer(s.FRAMEBUFFER,null),this.initTimestampQuery(As.COMPUTE,this.getTimestampUID(e))}compute(e,t,s,i,n=null){let{state:r,gl:a}=this;this.discard===!1&&(r.enable(a.RASTERIZER_DISCARD),this.discard=!0);let{programGPU:c,transformBuffers:l,attributes:u}=this.get(i),h=this._getVaoKey(u),d=this.vaoCache[h];d===void 0?this.vaoCache[h]=this._createVao(u):r.setVertexState(d),r.useProgram(c),this._bindUniforms(s);let p=this._getTransformFeedback(l);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,p),a.beginTransformFeedback(a.POINTS),n=n!==null?n:t.count,Array.isArray(n)?(_e("WebGLBackend.compute(): The count parameter must be a single number, not an array."),n=n[0]):n&&typeof n=="object"&&n.isIndirectStorageBufferAttribute&&(_e("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),n=t.count),u[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,n):a.drawArrays(a.POINTS,0,n),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let m=0;m<l.length;m++){let g=l[m];g.pbo&&this.has(g.pbo)&&this.textureUtils.copyBufferToTexture(g.transformBuffer,g.pbo),g.switchBuffers()}}finishCompute(e){let{state:t,gl:s}=this;this.discard=!1,t.disable(s.RASTERIZER_DISCARD),this.prepareTimestampBuffer(As.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}draw(e){let{object:t,pipeline:s,material:i,context:n,hardwareClippingPlanes:r}=e,{programGPU:a}=this.get(s),{gl:c,state:l}=this,u=this.get(n),h=e.getDrawParameters();if(h===null)return;this._bindUniforms(e.getBindings());let d=t.isMesh&&t.matrixWorld.determinant()<0;l.setMaterial(i,d,r),n.mrt!==null&&n.textures!==null&&l.setMRTBlending(n.textures,n.mrt,i),l.useProgram(a);let p=e.getAttributes(),m=this.get(p),g=m.vaoGPU;if(g===void 0){let C=this._getVaoKey(p);g=this.vaoCache[C],g===void 0&&(g=this._createVao(p),this.vaoCache[C]=g,m.vaoGPU=g)}let y=e.getIndex(),x=y!==null?this.get(y).bufferGPU:null;l.setVertexState(g,x);let _=u.lastOcclusionObject;if(_!==t&&_!==void 0){if(_!==null&&_.occlusionTest===!0&&(c.endQuery(c.ANY_SAMPLES_PASSED),u.occlusionQueryIndex++),t.occlusionTest===!0){let C=c.createQuery();c.beginQuery(c.ANY_SAMPLES_PASSED,C),u.occlusionQueries[u.occlusionQueryIndex]=C,u.occlusionQueryObjects[u.occlusionQueryIndex]=t}u.lastOcclusionObject=t}let w=this.bufferRenderer;t.isPoints?w.mode=c.POINTS:t.isLineSegments?w.mode=c.LINES:t.isLine?w.mode=c.LINE_STRIP:t.isLineLoop?w.mode=c.LINE_LOOP:i.wireframe===!0?(l.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),w.mode=c.LINES):w.mode=c.TRIANGLES;let{vertexCount:S,instanceCount:E}=h,{firstVertex:B}=h;if(w.object=t,y!==null){B*=y.array.BYTES_PER_ELEMENT;let C=this.get(y);w.index=y.count,w.type=C.type}else w.index=0;let N=()=>{t.isBatchedMesh?t._multiDrawInstances!==null?(_e("WebGLBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),w.renderMultiDrawInstances(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount,t._multiDrawInstances)):this.hasFeature("WEBGL_multi_draw")?w.renderMultiDraw(t._multiDrawStarts,t._multiDrawCounts,t._multiDrawCount):_e("WebGLBackend: WEBGL_multi_draw not supported."):E>1?w.renderInstances(B,S,E):w.render(B,S)};if(e.camera.isArrayCamera===!0&&e.camera.cameras.length>0&&e.camera.isMultiViewCamera===!1){let C=this.get(e.camera),I=e.camera.cameras,k=e.getBindingGroup("cameraIndex").bindings[0];if(C.indexesGPU===void 0||C.indexesGPU.length!==I.length){let ie=new Uint32Array([0,0,0,0]),Pe=[];for(let Se=0,ae=I.length;Se<ae;Se++){let fe=c.createBuffer();ie[0]=Se,c.bindBuffer(c.UNIFORM_BUFFER,fe),c.bufferData(c.UNIFORM_BUFFER,ie,c.STATIC_DRAW),Pe.push(fe)}C.indexesGPU=Pe}let W=this.get(k),X=this.renderer.getPixelRatio(),Y=this._currentContext.renderTarget,ee=this._isRenderCameraDepthArray(this._currentContext),Q=this._currentContext.activeCubeFace;if(ee){let ie=this.get(Y.depthTexture);if(ie.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){ie.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;let{stencilBuffer:Pe}=Y;for(let Se=0,ae=I.length;Se<ae;Se++)this.renderer._activeCubeFace=Se,this._currentContext.activeCubeFace=Se,this._setFramebuffer(this._currentContext),this.clear(!1,!0,Pe,this._currentContext,!1,!1);this.renderer._activeCubeFace=Q,this._currentContext.activeCubeFace=Q}}for(let ie=0,Pe=I.length;ie<Pe;ie++){let Se=I[ie];if(t.layers.test(Se.layers)){ee&&(this.renderer._activeCubeFace=ie,this._currentContext.activeCubeFace=ie,this._setFramebuffer(this._currentContext));let ae=Se.viewport;if(ae!==void 0){let fe=ae.x*X,Fe=ae.y*X,Gt=ae.width*X,Vs=ae.height*X;l.viewport(Math.floor(fe),Math.floor(e.context.height-Vs-Fe),Math.floor(Gt),Math.floor(Vs))}l.bindBufferBase(c.UNIFORM_BUFFER,W.index,C.indexesGPU[ie]),N()}this._currentContext.activeCubeFace=Q,this.renderer._activeCubeFace=Q}}else N()}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,s,i,n,r){return this.textureUtils.copyTextureToBuffer(e,t,s,i,n,r)}updateSampler(){return""}createNodeBuilder(e,t){return new yy(e,t)}createProgram(e){let t=this.gl,{stage:s,code:i}=e,n=s==="fragment"?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,i),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){let s=this.gl,i=e.pipeline,{fragmentProgram:n,vertexProgram:r}=i,a=s.createProgram(),c=this.get(n).shaderGPU,l=this.get(r).shaderGPU;if(s.attachShader(a,c),s.attachShader(a,l),s.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:c,vertexShader:l}),t!==null&&this.parallel){let u=new Promise(h=>{let d=this.parallel,p=()=>{s.getProgramParameter(a,d.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),h()):requestAnimationFrame(p)};p()});t.push(u);return}this._completeCompile(e,i)}_handleSource(e,t){let s=e.split(`
|
|
`),i=[],n=Math.max(t-6,0),r=Math.min(t+6,s.length);for(let a=n;a<r;a++){let c=a+1;i.push(`${c===t?">":" "} ${c}: ${s[a]}`)}return i.join(`
|
|
`)}_getShaderErrors(e,t,s){let i=e.getShaderParameter(t,e.COMPILE_STATUS),r=(e.getShaderInfoLog(t)||"").trim();if(i&&r==="")return"";let a=/ERROR: 0:(\d+)/.exec(r);if(a){let c=parseInt(a[1]);return s.toUpperCase()+`
|
|
|
|
`+r+`
|
|
|
|
`+this._handleSource(e.getShaderSource(t),c)}else return r}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){let i=this.gl,r=(i.getProgramInfoLog(e)||"").trim();if(i.getProgramParameter(e,i.LINK_STATUS)===!1)if(typeof this.renderer.debug.onShaderError=="function")this.renderer.debug.onShaderError(i,e,s,t);else{let a=this._getShaderErrors(i,s,"vertex"),c=this._getShaderErrors(i,t,"fragment");O("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+`
|
|
|
|
Program Info Log: `+r+`
|
|
`+a+`
|
|
`+c)}else r!==""&&z("WebGLProgram: Program Info Log:",r)}}_completeCompile(e,t){let{state:s,gl:i}=this,n=this.get(t),{programGPU:r,fragmentShader:a,vertexShader:c}=n;i.getProgramParameter(r,i.LINK_STATUS)===!1&&this._logProgramError(r,a,c),s.useProgram(r);let l=e.getBindings();this._setupBindings(l,r),this.set(t,{programGPU:r})}createComputePipeline(e,t){let{state:s,gl:i}=this,n={stage:"fragment",code:`#version 300 es
|
|
precision highp float;
|
|
void main() {}`};this.createProgram(n);let{computeProgram:r}=e,a=i.createProgram(),c=this.get(n).shaderGPU,l=this.get(r).shaderGPU,u=r.transforms,h=[],d=[];for(let y=0;y<u.length;y++){let x=u[y];h.push(x.varyingName),d.push(x.attributeNode)}i.attachShader(a,c),i.attachShader(a,l),i.transformFeedbackVaryings(a,h,i.SEPARATE_ATTRIBS),i.linkProgram(a),i.getProgramParameter(a,i.LINK_STATUS)===!1&&this._logProgramError(a,c,l),s.useProgram(a),this._setupBindings(t,a);let p=r.attributes,m=[],g=[];for(let y=0;y<p.length;y++){let x=p[y].node.attribute;m.push(x),this.has(x)||this.attributeUtils.createAttribute(x,i.ARRAY_BUFFER)}for(let y=0;y<d.length;y++){let x=d[y].attribute;this.has(x)||this.attributeUtils.createAttribute(x,i.ARRAY_BUFFER);let _=this.get(x);g.push(_)}this.set(e,{programGPU:a,transformBuffers:g,attributes:m})}createBindings(e,t){if(this._knownBindings.has(t)===!1){this._knownBindings.add(t);let s=0,i=0;for(let n of t){this.set(n,{textures:i,uniformBuffers:s});for(let r of n.bindings)r.isUniformBuffer&&s++,r.isSampledTexture&&i++}}this.updateBindings(e,t)}updateBindings(e){let{gl:t}=this,s=this.get(e),i=s.uniformBuffers,n=s.textures;for(let r of e.bindings){let a=this.get(r);if(r.isUniformsGroup||r.isUniformBuffer){let c=r.buffer,{bufferGPU:l}=this.get(c);l===void 0?(l=t.createBuffer(),t.bindBuffer(t.UNIFORM_BUFFER,l),t.bufferData(t.UNIFORM_BUFFER,c.byteLength,t.DYNAMIC_DRAW),this.set(c,{bufferGPU:l})):t.bindBuffer(t.UNIFORM_BUFFER,l);let u=r.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,l),u.length===0)t.bufferData(t.UNIFORM_BUFFER,c,t.DYNAMIC_DRAW);else{let h=Kr(c),d=h?1:c.BYTES_PER_ELEMENT;for(let p=0,m=u.length;p<m;p++){let g=u[p],y=g.start*d,x=g.count*d,_=y*(h?c.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,_,c,y,x)}}a.index=i++,a.bufferGPU=l,this.set(r,a)}else if(r.isSampledTexture){let{textureGPU:c,glTextureType:l}=this.get(r.texture);a.index=n++,a.textureGPU=c,a.glTextureType=l,this.set(r,a)}}}updateBinding(e){let t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){let i=this.get(e).bufferGPU,n=e.buffer,r=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,i),r.length===0)t.bufferData(t.UNIFORM_BUFFER,n,t.DYNAMIC_DRAW);else{let a=Kr(n),c=a?1:n.BYTES_PER_ELEMENT;for(let l=0,u=r.length;l<u;l++){let h=r[l],d=h.start*c,p=h.count*c,m=d*(a?n.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,m,n,d,p)}}}}createIndexAttribute(e){let t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){let t=Object.keys(U_).filter(i=>U_[i]===e),s=this.extensions;for(let i=0;i<t.length;i++)if(s.has(t[i]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(e,t,s=null,i=null,n=0,r=0){this.textureUtils.copyTextureToTexture(e,t,s,i,n,r)}copyFramebufferToTexture(e,t,s){this.textureUtils.copyFramebufferToTexture(e,t,s)}hasCompatibility(e){return e===Ys.TEXTURE_COMPARE?!0:super.hasCompatibility(e)}initRenderTarget(e){let{gl:t,state:s}=this;this._setFramebuffer(e),s.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){let{gl:t,state:s}=this,i=null;if(e.textures!==null){let n=e.renderTarget,r=this.get(n),{samples:a,depthBuffer:c,stencilBuffer:l}=n,u=n.isCubeRenderTarget===!0,h=n.isRenderTarget3D===!0,d=n.depth>1,p=n.isXRRenderTarget===!0,m=p===!0&&n._hasExternalTextures===!0,g=r.msaaFrameBuffer,y=r.depthRenderbuffer,x=this.extensions.get("WEBGL_multisampled_render_to_texture"),_=this.extensions.get("OVR_multiview2"),w=this._useMultisampledExtension(n),S=sw(e),E;if(u?(r.cubeFramebuffers||(r.cubeFramebuffers={}),E=r.cubeFramebuffers[S]):p&&m===!1?E=this._xrFramebuffer:(r.framebuffers||(r.framebuffers={}),E=r.framebuffers[S]),E===void 0){E=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,E);let B=e.textures,N=[];if(u){r.cubeFramebuffers[S]=E;let{textureGPU:I}=this.get(B[0]),k=this.renderer._activeCubeFace,W=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+k,I,W)}else{r.framebuffers[S]=E;for(let I=0;I<B.length;I++){let k=B[I],W=this.get(k);W.renderTarget=e.renderTarget,W.cacheKey=S;let X=t.COLOR_ATTACHMENT0+I;if(n.multiview)_.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,X,W.textureGPU,0,a,0,2);else if(h||d){let Y=this.renderer._activeCubeFace,ee=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,X,W.textureGPU,ee,Y)}else if(w)x.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,X,t.TEXTURE_2D,W.textureGPU,0,a);else{let Y=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,X,t.TEXTURE_2D,W.textureGPU,Y)}}}let C=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(n._autoAllocateDepthBuffer===!0){let I=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(I,e,0,w),r.xrDepthRenderbuffer=I,N.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,I),t.framebufferRenderbuffer(t.FRAMEBUFFER,C,t.RENDERBUFFER,I)}else if(e.depthTexture!==null){N.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);let I=this.get(e.depthTexture);if(I.renderTarget=e.renderTarget,I.cacheKey=S,n.multiview)_.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,C,I.textureGPU,0,a,0,2);else if(m&&w)x.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,C,t.TEXTURE_2D,I.textureGPU,0,a);else if(e.depthTexture.isArrayTexture){let k=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,C,I.textureGPU,0,k)}else if(e.depthTexture.isCubeTexture){let k=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,C,t.TEXTURE_CUBE_MAP_POSITIVE_X+k,I.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,C,t.TEXTURE_2D,I.textureGPU,0)}r.depthInvalidationArray=N}else{if(this._isRenderCameraDepthArray(e)){s.bindFramebuffer(t.FRAMEBUFFER,E);let N=this.renderer._activeCubeFace,C=this.get(e.depthTexture),I=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,I,C.textureGPU,0,N)}if((p||w||n.multiview)&&n._isOpaqueFramebuffer!==!0){s.bindFramebuffer(t.FRAMEBUFFER,E);let N=this.get(e.textures[0]);n.multiview?_.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,N.textureGPU,0,a,0,2):w?x.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,N.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,N.textureGPU,0);let C=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(n._autoAllocateDepthBuffer===!0){let I=r.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,I),t.framebufferRenderbuffer(t.FRAMEBUFFER,C,t.RENDERBUFFER,I)}else{let I=this.get(e.depthTexture);n.multiview?_.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,C,I.textureGPU,0,a,0,2):w?x.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,C,t.TEXTURE_2D,I.textureGPU,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,C,t.TEXTURE_2D,I.textureGPU,0)}}}if(a>0&&w===!1&&!n.multiview){if(g===void 0){let B=[];g=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,g);let N=[],C=e.textures;for(let I=0;I<C.length;I++){N[I]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,N[I]),B.push(t.COLOR_ATTACHMENT0+I);let k=e.textures[I],W=this.get(k);t.renderbufferStorageMultisample(t.RENDERBUFFER,a,W.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+I,t.RENDERBUFFER,N[I])}if(t.bindRenderbuffer(t.RENDERBUFFER,null),r.msaaFrameBuffer=g,r.msaaRenderbuffers=N,c&&y===void 0){y=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(y,e,a),r.depthRenderbuffer=y;let I=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;B.push(I)}r.invalidationArray=B}i=r.msaaFrameBuffer}else i=E;s.drawBuffers(e,E)}s.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let s=0;s<e.length;s++){let i=this.get(e[s]);t+=":"+i.id}return t}_createVao(e){let{gl:t}=this,s=t.createVertexArray();t.bindVertexArray(s);for(let i=0;i<e.length;i++){let n=e[i],r=this.get(n);t.bindBuffer(t.ARRAY_BUFFER,r.bufferGPU),t.enableVertexAttribArray(i);let a,c;n.isInterleavedBufferAttribute===!0?(a=n.data.stride*r.bytesPerElement,c=n.offset*r.bytesPerElement):(a=0,c=0),r.isInteger?t.vertexAttribIPointer(i,n.itemSize,r.type,a,c):t.vertexAttribPointer(i,n.itemSize,r.type,n.normalized,a,c),n.isInstancedBufferAttribute&&!n.isInterleavedBufferAttribute?t.vertexAttribDivisor(i,n.meshPerAttribute):n.isInterleavedBufferAttribute&&n.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(i,n.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),s}_getTransformFeedback(e){let t="";for(let n=0;n<e.length;n++)t+=":"+e[n].id;let s=this.transformFeedbackCache[t];if(s!==void 0)return s;let{gl:i}=this;s=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,s);for(let n=0;n<e.length;n++){let r=e[n];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,n,r.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=s,s}_setupBindings(e,t){let s=this.gl;for(let i of e)for(let n of i.bindings){let a=this.get(n).index;if(n.isUniformsGroup||n.isUniformBuffer){let c=s.getUniformBlockIndex(t,n.name);s.uniformBlockBinding(t,c,a)}else if(n.isSampledTexture){let c=s.getUniformLocation(t,n.name);s.uniform1i(c,a)}}}_bindUniforms(e){let{gl:t,state:s}=this;for(let i of e)for(let n of i.bindings){let r=this.get(n),a=r.index;n.isUniformsGroup||n.isUniformBuffer?s.bindBufferBase(t.UNIFORM_BUFFER,a,r.bufferGPU):n.isSampledTexture&&s.bindTexture(r.glTextureType,r.textureGPU,t.TEXTURE0+a)}}_resolveRenderTarget(e){let{gl:t,state:s}=this,i=e.renderTarget;if(e.textures!==null&&i){let n=this.get(i);if(i.samples>0&&this._useMultisampledExtension(i)===!1){let r=n.framebuffers[e.getCacheKey()],a=t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));let c=n.msaaFrameBuffer,l=n.msaaRenderbuffers,u=e.textures,h=u.length>1;if(s.bindFramebuffer(t.READ_FRAMEBUFFER,c),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,r),h)for(let d=0;d<u.length;d++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,null,0);for(let d=0;d<u.length;d++){if(h){let{textureGPU:p}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,l[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,p,0)}if(e.scissor){let{x:p,y:m,width:g,height:y}=e.scissorValue,x=e.height-y-m;t.blitFramebuffer(p,x,p+g,x+y,p,x,p+g,x+y,a,t.NEAREST)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,a,t.NEAREST)}if(h)for(let d=0;d<u.length;d++){let{textureGPU:p}=this.get(u[d]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.RENDERBUFFER,l[d]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+d,t.TEXTURE_2D,p,0)}this._supportsInvalidateFramebuffer===!0&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,n.invalidationArray)}else if(i.resolveDepthBuffer===!1&&n.framebuffers){let r=n.framebuffers[e.getCacheKey()];s.bindFramebuffer(t.DRAW_FRAMEBUFFER,r),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,n.depthInvalidationArray)}}}_useMultisampledExtension(e){return e.multiview===!0?!0:e.samples>0&&this.extensions.has("WEBGL_multisampled_render_to_texture")===!0&&e._autoAllocateDepthBuffer!==!1}dispose(){this.textureUtils!==null&&this.textureUtils.dispose();let e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}},Gu={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list"},ni=typeof self<"u"&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},ht={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},Et={Store:"store"},ve={Load:"load",Clear:"clear"},O_={CCW:"ccw",CW:"cw"},V_={None:"none",Back:"back"},Qh={Uint16:"uint16",Uint32:"uint32"},M={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:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},uf={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},si={Linear:"linear",Nearest:"nearest"},pe={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},Qn={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},k_={None:0,All:15},an={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},hf={Storage:"storage",ReadOnlyStorage:"read-only-storage"},df={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},z_={NonFiltering:"non-filtering",Comparison:"comparison"},Kn={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},G_={TwoD:"2d",ThreeD:"3d"},Tt={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},JF={All:"all"},Wu={Vertex:"vertex",Instance:"instance"},Ny={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},W_={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"},Ry=class extends Xh{constructor(e,t,s){super(e,t?t.value:null),this.textureNode=t,this.groupNode=s}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}},Cy=class extends Wh{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}},QF=0,Ey=class extends Cy{constructor(e,t){super("StorageBuffer_"+QF++,e?e.value:null),this.nodeUniform=e,this.access=e?e.access:dt.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}},By=class extends fi{constructor(e){super(),this.device=e;let t=`
|
|
struct VarysStruct {
|
|
@builtin( position ) Position: vec4f,
|
|
@location( 0 ) vTex : vec2f,
|
|
@location( 1 ) @interpolate(flat, either) vBaseArrayLayer: u32,
|
|
};
|
|
|
|
@group( 0 ) @binding ( 2 )
|
|
var<uniform> flipY: u32;
|
|
|
|
@vertex
|
|
fn mainVS(
|
|
@builtin( vertex_index ) vertexIndex : u32,
|
|
@builtin( instance_index ) instanceIndex : u32 ) -> VarysStruct {
|
|
|
|
var Varys : VarysStruct;
|
|
|
|
var pos = array(
|
|
vec2f( -1, -1 ),
|
|
vec2f( -1, 3 ),
|
|
vec2f( 3, -1 ),
|
|
);
|
|
|
|
let p = pos[ vertexIndex ];
|
|
let mult = select( vec2f( 0.5, -0.5 ), vec2f( 0.5, 0.5 ), flipY != 0 );
|
|
Varys.vTex = p * mult + vec2f( 0.5 );
|
|
Varys.Position = vec4f( p, 0, 1 );
|
|
Varys.vBaseArrayLayer = instanceIndex;
|
|
|
|
return Varys;
|
|
|
|
}
|
|
|
|
@group( 0 ) @binding( 0 )
|
|
var imgSampler : sampler;
|
|
|
|
@group( 0 ) @binding( 1 )
|
|
var img2d : texture_2d<f32>;
|
|
|
|
@fragment
|
|
fn main_2d( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
|
|
return textureSample( img2d, imgSampler, Varys.vTex );
|
|
|
|
}
|
|
|
|
@group( 0 ) @binding( 1 )
|
|
var img2dArray : texture_2d_array<f32>;
|
|
|
|
@fragment
|
|
fn main_2d_array( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
|
|
return textureSample( img2dArray, imgSampler, Varys.vTex, Varys.vBaseArrayLayer );
|
|
|
|
}
|
|
|
|
const faceMat = array(
|
|
mat3x3f( 0, 0, -2, 0, -2, 0, 1, 1, 1 ), // pos-x
|
|
mat3x3f( 0, 0, 2, 0, -2, 0, -1, 1, -1 ), // neg-x
|
|
mat3x3f( 2, 0, 0, 0, 0, 2, -1, 1, -1 ), // pos-y
|
|
mat3x3f( 2, 0, 0, 0, 0, -2, -1, -1, 1 ), // neg-y
|
|
mat3x3f( 2, 0, 0, 0, -2, 0, -1, 1, 1 ), // pos-z
|
|
mat3x3f( -2, 0, 0, 0, -2, 0, 1, 1, -1 ), // neg-z
|
|
);
|
|
|
|
@group( 0 ) @binding( 1 )
|
|
var imgCube : texture_cube<f32>;
|
|
|
|
@fragment
|
|
fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
|
|
return textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) );
|
|
|
|
}
|
|
`;this.mipmapSampler=e.createSampler({minFilter:si.Linear}),this.flipYSampler=e.createSampler({minFilter:si.Nearest}),this.flipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),this.noFlipUniformBuffer=e.createBuffer({size:4,usage:GPUBufferUsage.UNIFORM}),this.transferPipelines={},this.mipmapShaderModule=e.createShaderModule({label:"mipmap",code:t})}getTransferPipeline(e,t){t=t||"2d-array";let s=`${e}-${t}`,i=this.transferPipelines[s];return i===void 0&&(i=this.device.createRenderPipeline({label:`mipmap-${e}-${t}`,vertex:{module:this.mipmapShaderModule},fragment:{module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},layout:"auto"}),this.transferPipelines[s]=i),i}flipY(e,t,s=0){let i=t.format,{width:n,height:r}=t.size,a=this.device.createTexture({size:{width:n,height:r},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),c=this.getTransferPipeline(i,e.textureBindingViewDimension),l=this.getTransferPipeline(i,a.textureBindingViewDimension),u=this.device.createCommandEncoder({}),h=(d,p,m,g,y,x)=>{let _=d.getBindGroupLayout(0),w=this.device.createBindGroup({layout:_,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:p.createView({dimension:p.textureBindingViewDimension||"2d-array",baseMipLevel:0,mipLevelCount:1})},{binding:2,resource:{buffer:x?this.flipUniformBuffer:this.noFlipUniformBuffer}}]}),S=u.beginRenderPass({colorAttachments:[{view:g.createView({dimension:"2d",baseMipLevel:0,mipLevelCount:1,baseArrayLayer:y,arrayLayerCount:1}),loadOp:ve.Clear,storeOp:Et.Store}]});S.setPipeline(d),S.setBindGroup(0,w),S.draw(3,1,0,m),S.end()};h(c,e,s,a,0,!1),h(l,a,0,e,s,!0),this.device.queue.submit([u.finish()]),a.destroy()}generateMipmaps(e,t=null){let s=this.get(e),i=s.layers||this._mipmapCreateBundles(e),n=t||this.device.createCommandEncoder({label:"mipmapEncoder"});this._mipmapRunBundles(n,i),t===null&&this.device.queue.submit([n.finish()]),s.layers=i}_mipmapCreateBundles(e){let t=e.textureBindingViewDimension||"2d-array",s=this.getTransferPipeline(e.format,t),i=s.getBindGroupLayout(0),n=[];for(let r=1;r<e.mipLevelCount;r++)for(let a=0;a<e.depthOrArrayLayers;a++){let c=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:e.createView({dimension:t,baseMipLevel:r-1,mipLevelCount:1})},{binding:2,resource:{buffer:this.noFlipUniformBuffer}}]}),l={colorAttachments:[{view:e.createView({dimension:"2d",baseMipLevel:r,mipLevelCount:1,baseArrayLayer:a,arrayLayerCount:1}),loadOp:ve.Clear,storeOp:Et.Store}]},u=this.device.createRenderBundleEncoder({colorFormats:[e.format]});u.setPipeline(s),u.setBindGroup(0,c),u.draw(3,1,0,a),n.push({renderBundles:[u.finish()],passDescriptor:l})}return n}_mipmapRunBundles(e,t){let s=t.length;for(let i=0;i<s;i++){let n=t[i],r=e.beginRenderPass(n.passDescriptor);r.executeBundles(n.renderBundles),r.end()}}},KF={[vp]:"never",[pu]:"less",[wp]:"equal",[Jr]:"less-equal",[Oa]:"greater",[Yn]:"greater-equal",[Ap]:"always",[Mp]:"not-equal"},eI=[0,1,3,2,4,5],Fy=class{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){let t=this.backend,s=e.minFilter+"-"+e.magFilter+"-"+e.wrapS+"-"+e.wrapT+"-"+(e.wrapR||"0")+"-"+e.anisotropy+"-"+(e.compareFunction||0),i=this._samplerCache.get(s);if(i===void 0){let r={addressModeU:this._convertAddressMode(e.wrapS),addressModeV:this._convertAddressMode(e.wrapT),addressModeW:this._convertAddressMode(e.wrapR),magFilter:this._convertFilterMode(e.magFilter),minFilter:this._convertFilterMode(e.minFilter),mipmapFilter:this._convertFilterMode(e.minFilter),maxAnisotropy:1};e.isDepthTexture&&e.compareFunction===null&&(r.magFilter=si.Nearest,r.minFilter=si.Nearest,r.mipmapFilter=si.Nearest),r.magFilter===si.Linear&&r.minFilter===si.Linear&&r.mipmapFilter===si.Linear&&(r.maxAnisotropy=e.anisotropy),e.isDepthTexture&&e.compareFunction!==null&&t.hasCompatibility(Ys.TEXTURE_COMPARE)&&(r.compare=KF[e.compareFunction]),i={sampler:t.device.createSampler(r),usedTimes:0},this._samplerCache.set(s,i)}let n=t.get(e);if(n.sampler!==i.sampler){if(n.sampler!==void 0){let r=this._samplerCache.get(n.samplerKey);r.usedTimes--,r.usedTimes===0&&this._samplerCache.delete(n.samplerKey)}n.samplerKey=s,n.sampler=i.sampler,i.usedTimes++}return s}createDefaultTexture(e){let t,s=Iy(e);e.isCubeTexture?t=this._getDefaultCubeTextureGPU(s):t=this._getDefaultTextureGPU(s),this.backend.get(e).texture=t}createTexture(e,t={}){let s=this.backend,i=s.get(e);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");if(e.isExternalTexture){i.texture=e.sourceTexture,i.initialized=!0;return}t.needsMipmaps===void 0&&(t.needsMipmaps=!1),t.levels===void 0&&(t.levels=1),t.depth===void 0&&(t.depth=1);let{width:n,height:r,depth:a,levels:c}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());let l=this._getDimension(e),u=e.internalFormat||t.format||Iy(e,s.device);i.format=u;let{samples:h,primarySamples:d,isMSAA:p}=s.utils.getTextureSampleData(e),m=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;e.isStorageTexture===!0&&(m|=GPUTextureUsage.STORAGE_BINDING),e.isCompressedTexture!==!0&&e.isCompressedArrayTexture!==!0&&u!==M.RGB9E5UFloat&&(m|=GPUTextureUsage.RENDER_ATTACHMENT);let g={label:e.name,size:{width:n,height:r,depthOrArrayLayers:a},mipLevelCount:c,sampleCount:d,dimension:l,format:u,usage:m};if(u===void 0){z("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(g.textureBindingViewDimension=Tt.Cube);try{i.texture=s.device.createTexture(g)}catch{z("WebGPURenderer: Failed to create texture with descriptor:",g),this.createDefaultTexture(e);return}if(p){let y=Object.assign({},g);y.label=y.label+"-msaa",y.sampleCount=h,y.mipLevelCount=1,i.msaaTexture=s.device.createTexture(y)}i.initialized=!0,i.textureDescriptorGPU=g}destroyTexture(e,t=!1){let s=this.backend,i=s.get(e);i.texture!==void 0&&t===!1&&i.texture.destroy(),i.msaaTexture!==void 0&&i.msaaTexture.destroy(),s.delete(e)}generateMipmaps(e,t=null){let s=this.backend.get(e);this._generateMipmaps(s.texture,t)}getColorBuffer(){let e=this.backend,t=e.renderer.getCanvasTarget(),{width:s,height:i}=e.getDrawingBufferSize(),n=e.renderer.currentSamples,r=t.colorTexture,a=e.get(r);if(r.width===s&&r.height===i&&r.samples===n)return a.texture;let c=a.texture;return c&&c.destroy(),c=e.device.createTexture({label:"colorBuffer",size:{width:s,height:i,depthOrArrayLayers:1},sampleCount:e.utils.getSampleCount(e.renderer.currentSamples),format:e.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),r.source.width=s,r.source.height=i,r.samples=n,a.texture=c,c}getDepthBuffer(e=!0,t=!1){let s=this.backend,i=s.renderer.getCanvasTarget(),{width:n,height:r}=s.getDrawingBufferSize(),a=s.renderer.currentSamples,c=i.depthTexture;if(c.width===n&&c.height===r&&c.samples===a&&c.depth===e&&c.stencil===t)return s.get(c).texture;let l=s.get(c).texture,u,h;if(t?(u=Hs,h=Ei):e&&(u=ns,h=Oe),l!==void 0){if(c.image.width===n&&c.image.height===r&&c.format===u&&c.type===h&&c.samples===a)return l;this.destroyTexture(c)}return c.name="depthBuffer",c.format=u,c.type=h,c.image.width=n,c.image.height=r,c.samples=a,this.createTexture(c,{width:n,height:r}),s.get(c).texture}updateTexture(e,t){let s=this.backend.get(e),i=e.mipmaps,{textureDescriptorGPU:n}=s;if(!(e.isRenderTargetTexture||n===void 0)){if(e.isDataTexture)if(i.length>0)for(let r=0,a=i.length;r<a;r++){let c=i[r];this._copyBufferToTexture(c,s.texture,n,0,e.flipY,0,r)}else this._copyBufferToTexture(t.image,s.texture,n,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)for(let r=0;r<t.image.depth;r++)this._copyBufferToTexture(t.image,s.texture,n,r,e.flipY,r);else if(e.isCompressedTexture||e.isCompressedArrayTexture)this._copyCompressedBufferToTexture(e.mipmaps,s.texture,n);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,s.texture,n);else if(i.length>0)for(let r=0,a=i.length;r<a;r++){let c=i[r];this._copyImageToTexture(c,s.texture,n,0,e.flipY,e.premultiplyAlpha,r)}else this._copyImageToTexture(t.image,s.texture,n,0,e.flipY,e.premultiplyAlpha);s.version=e.version}}async copyTextureToBuffer(e,t,s,i,n,r){let a=this.backend.device,c=this.backend.get(e),l=c.texture,u=c.textureDescriptorGPU.format,h=this._getBytesPerTexel(u),d=i*h;d=Math.ceil(d/256)*256;let p=a.createBuffer({size:(n-1)*d+i*h,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),m=a.createCommandEncoder();m.copyTextureToBuffer({texture:l,origin:{x:t,y:s,z:r}},{buffer:p,bytesPerRow:d},{width:i,height:n});let g=this._getTypedArrayType(u);a.queue.submit([m.finish()]),await p.mapAsync(GPUMapMode.READ);let y=p.getMappedRange();return new g(y)}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(t===void 0){let s=new xt;s.minFilter=Ue,s.magFilter=Ue,this.createTexture(s,{width:1,height:1,format:e}),this.defaultTexture[e]=t=s}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultCubeTexture[e];if(t===void 0){let s=new kn;s.minFilter=Ue,s.magFilter=Ue,this.createTexture(s,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=s}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,s){let i=e.images,n=e.mipmaps;for(let r=0;r<6;r++){let a=i[r],c=e.flipY===!0?eI[r]:r;a.isDataTexture?this._copyBufferToTexture(a.image,t,s,c,e.flipY):this._copyImageToTexture(a,t,s,c,e.flipY,e.premultiplyAlpha);for(let l=0;l<n.length;l++){let h=n[l].images[r];h.isDataTexture?this._copyBufferToTexture(h.image,t,s,c,e.flipY,0,l+1):this._copyImageToTexture(h,t,s,c,e.flipY,e.premultiplyAlpha,l+1)}}}_copyImageToTexture(e,t,s,i,n,r,a=0){let c=this.backend.device,l=a>0?e.width:s.size.width,u=a>0?e.height:s.size.height;try{c.queue.copyExternalImageToTexture({source:e,flipY:n},{texture:t,mipLevel:a,origin:{x:0,y:0,z:i},premultipliedAlpha:r},{width:l,height:u,depthOrArrayLayers:1})}catch{}}_getPassUtils(){let e=this._passUtils;return e===null&&(this._passUtils=e=new By(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,s=0){this._getPassUtils().flipY(e,t,s)}_copyBufferToTexture(e,t,s,i,n,r=0,a=0){let c=this.backend.device,l=e.data,u=this._getBytesPerTexel(s.format),h=e.width*u;c.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:i}},l,{offset:e.width*e.height*u*r,bytesPerRow:h},{width:e.width,height:e.height,depthOrArrayLayers:1}),n===!0&&this._flipY(t,s,i)}_copyCompressedBufferToTexture(e,t,s){let i=this.backend.device,n=this._getBlockData(s.format),r=s.size.depthOrArrayLayers>1;for(let a=0;a<e.length;a++){let c=e[a],l=c.width,u=c.height,h=r?s.size.depthOrArrayLayers:1,d=Math.ceil(l/n.width)*n.byteLength,p=d*Math.ceil(u/n.height);for(let m=0;m<h;m++)i.queue.writeTexture({texture:t,mipLevel:a,origin:{x:0,y:0,z:m}},c.data,{offset:m*p,bytesPerRow:d,rowsPerImage:Math.ceil(u/n.height)},{width:Math.ceil(l/n.width)*n.width,height:Math.ceil(u/n.height)*n.height,depthOrArrayLayers:1})}}_getBlockData(e){if(e===M.BC1RGBAUnorm||e===M.BC1RGBAUnormSRGB)return{byteLength:8,width:4,height:4};if(e===M.BC2RGBAUnorm||e===M.BC2RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===M.BC3RGBAUnorm||e===M.BC3RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===M.BC4RUnorm||e===M.BC4RSnorm)return{byteLength:8,width:4,height:4};if(e===M.BC5RGUnorm||e===M.BC5RGSnorm)return{byteLength:16,width:4,height:4};if(e===M.BC6HRGBUFloat||e===M.BC6HRGBFloat)return{byteLength:16,width:4,height:4};if(e===M.BC7RGBAUnorm||e===M.BC7RGBAUnormSRGB)return{byteLength:16,width:4,height:4};if(e===M.ETC2RGB8Unorm||e===M.ETC2RGB8UnormSRGB)return{byteLength:8,width:4,height:4};if(e===M.ETC2RGB8A1Unorm||e===M.ETC2RGB8A1UnormSRGB)return{byteLength:8,width:4,height:4};if(e===M.ETC2RGBA8Unorm||e===M.ETC2RGBA8UnormSRGB)return{byteLength:16,width:4,height:4};if(e===M.EACR11Unorm)return{byteLength:8,width:4,height:4};if(e===M.EACR11Snorm)return{byteLength:8,width:4,height:4};if(e===M.EACRG11Unorm)return{byteLength:16,width:4,height:4};if(e===M.EACRG11Snorm)return{byteLength:16,width:4,height:4};if(e===M.ASTC4x4Unorm||e===M.ASTC4x4UnormSRGB)return{byteLength:16,width:4,height:4};if(e===M.ASTC5x4Unorm||e===M.ASTC5x4UnormSRGB)return{byteLength:16,width:5,height:4};if(e===M.ASTC5x5Unorm||e===M.ASTC5x5UnormSRGB)return{byteLength:16,width:5,height:5};if(e===M.ASTC6x5Unorm||e===M.ASTC6x5UnormSRGB)return{byteLength:16,width:6,height:5};if(e===M.ASTC6x6Unorm||e===M.ASTC6x6UnormSRGB)return{byteLength:16,width:6,height:6};if(e===M.ASTC8x5Unorm||e===M.ASTC8x5UnormSRGB)return{byteLength:16,width:8,height:5};if(e===M.ASTC8x6Unorm||e===M.ASTC8x6UnormSRGB)return{byteLength:16,width:8,height:6};if(e===M.ASTC8x8Unorm||e===M.ASTC8x8UnormSRGB)return{byteLength:16,width:8,height:8};if(e===M.ASTC10x5Unorm||e===M.ASTC10x5UnormSRGB)return{byteLength:16,width:10,height:5};if(e===M.ASTC10x6Unorm||e===M.ASTC10x6UnormSRGB)return{byteLength:16,width:10,height:6};if(e===M.ASTC10x8Unorm||e===M.ASTC10x8UnormSRGB)return{byteLength:16,width:10,height:8};if(e===M.ASTC10x10Unorm||e===M.ASTC10x10UnormSRGB)return{byteLength:16,width:10,height:10};if(e===M.ASTC12x10Unorm||e===M.ASTC12x10UnormSRGB)return{byteLength:16,width:12,height:10};if(e===M.ASTC12x12Unorm||e===M.ASTC12x12UnormSRGB)return{byteLength:16,width:12,height:12}}_convertAddressMode(e){let t=uf.ClampToEdge;return e===Pn?t=uf.Repeat:e===Dn&&(t=uf.MirrorRepeat),t}_convertFilterMode(e){let t=si.Linear;return(e===Ue||e===xp||e===$r)&&(t=si.Nearest),t}_getBytesPerTexel(e){if(e===M.R8Unorm||e===M.R8Snorm||e===M.R8Uint||e===M.R8Sint)return 1;if(e===M.R16Uint||e===M.R16Sint||e===M.R16Float||e===M.RG8Unorm||e===M.RG8Snorm||e===M.RG8Uint||e===M.RG8Sint)return 2;if(e===M.R32Uint||e===M.R32Sint||e===M.R32Float||e===M.RG16Uint||e===M.RG16Sint||e===M.RG16Float||e===M.RGBA8Unorm||e===M.RGBA8UnormSRGB||e===M.RGBA8Snorm||e===M.RGBA8Uint||e===M.RGBA8Sint||e===M.BGRA8Unorm||e===M.BGRA8UnormSRGB||e===M.RGB9E5UFloat||e===M.RGB10A2Unorm||e===M.RG11B10UFloat||e===M.Depth32Float||e===M.Depth24Plus||e===M.Depth24PlusStencil8||e===M.Depth32FloatStencil8)return 4;if(e===M.RG32Uint||e===M.RG32Sint||e===M.RG32Float||e===M.RGBA16Uint||e===M.RGBA16Sint||e===M.RGBA16Float)return 8;if(e===M.RGBA32Uint||e===M.RGBA32Sint||e===M.RGBA32Float)return 16}_getTypedArrayType(e){if(e===M.R8Uint)return Uint8Array;if(e===M.R8Sint)return Int8Array;if(e===M.R8Unorm)return Uint8Array;if(e===M.R8Snorm)return Int8Array;if(e===M.RG8Uint)return Uint8Array;if(e===M.RG8Sint)return Int8Array;if(e===M.RG8Unorm)return Uint8Array;if(e===M.RG8Snorm)return Int8Array;if(e===M.RGBA8Uint)return Uint8Array;if(e===M.RGBA8Sint)return Int8Array;if(e===M.RGBA8Unorm||e===M.RGBA8UnormSRGB)return Uint8Array;if(e===M.RGBA8Snorm)return Int8Array;if(e===M.R16Uint)return Uint16Array;if(e===M.R16Sint)return Int16Array;if(e===M.RG16Uint)return Uint16Array;if(e===M.RG16Sint)return Int16Array;if(e===M.RGBA16Uint)return Uint16Array;if(e===M.RGBA16Sint)return Int16Array;if(e===M.R16Float||e===M.RG16Float||e===M.RGBA16Float)return Uint16Array;if(e===M.R32Uint)return Uint32Array;if(e===M.R32Sint)return Int32Array;if(e===M.R32Float)return Float32Array;if(e===M.RG32Uint)return Uint32Array;if(e===M.RG32Sint)return Int32Array;if(e===M.RG32Float)return Float32Array;if(e===M.RGBA32Uint)return Uint32Array;if(e===M.RGBA32Sint)return Int32Array;if(e===M.RGBA32Float)return Float32Array;if(e===M.BGRA8Unorm||e===M.BGRA8UnormSRGB)return Uint8Array;if(e===M.RGB10A2Unorm||e===M.RGB9E5UFloat||e===M.RG11B10UFloat)return Uint32Array;if(e===M.Depth32Float)return Float32Array;if(e===M.Depth24Plus||e===M.Depth24PlusStencil8)return Uint32Array;if(e===M.Depth32FloatStencil8)return Float32Array}_getDimension(e){let t;return e.is3DTexture||e.isData3DTexture?t=G_.ThreeD:t=G_.TwoD,t}};function Iy(o,e=null){let t=o.format,s=o.type,i=o.colorSpace,n=me.getTransfer(i),r;if(o.isCompressedTexture===!0||o.isCompressedArrayTexture===!0)switch(t){case qr:case Hr:r=n===ne?M.BC1RGBAUnormSRGB:M.BC1RGBAUnorm;break;case Xr:r=n===ne?M.BC2RGBAUnormSRGB:M.BC2RGBAUnorm;break;case Yr:r=n===ne?M.BC3RGBAUnormSRGB:M.BC3RGBAUnorm;break;case Da:r=M.BC4RUnorm;break;case La:r=M.BC4RSnorm;break;case Zr:r=M.BC5RGUnorm;break;case Ua:r=M.BC5RGSnorm;break;case Pa:r=n===ne?M.BC7RGBAUnormSRGB:M.BC7RGBAUnorm;break;case ma:case fa:r=n===ne?M.ETC2RGB8UnormSRGB:M.ETC2RGB8Unorm;break;case ga:r=n===ne?M.ETC2RGBA8UnormSRGB:M.ETC2RGBA8Unorm;break;case ya:r=M.EACR11Unorm;break;case xa:r=M.EACR11Snorm;break;case jr:r=M.EACRG11Unorm;break;case ba:r=M.EACRG11Snorm;break;case _a:r=n===ne?M.ASTC4x4UnormSRGB:M.ASTC4x4Unorm;break;case Ta:r=n===ne?M.ASTC5x4UnormSRGB:M.ASTC5x4Unorm;break;case Sa:r=n===ne?M.ASTC5x5UnormSRGB:M.ASTC5x5Unorm;break;case va:r=n===ne?M.ASTC6x5UnormSRGB:M.ASTC6x5Unorm;break;case wa:r=n===ne?M.ASTC6x6UnormSRGB:M.ASTC6x6Unorm;break;case Ma:r=n===ne?M.ASTC8x5UnormSRGB:M.ASTC8x5Unorm;break;case Aa:r=n===ne?M.ASTC8x6UnormSRGB:M.ASTC8x6Unorm;break;case Na:r=n===ne?M.ASTC8x8UnormSRGB:M.ASTC8x8Unorm;break;case Ra:r=n===ne?M.ASTC10x5UnormSRGB:M.ASTC10x5Unorm;break;case Ca:r=n===ne?M.ASTC10x6UnormSRGB:M.ASTC10x6Unorm;break;case Ea:r=n===ne?M.ASTC10x8UnormSRGB:M.ASTC10x8Unorm;break;case Ba:r=n===ne?M.ASTC10x10UnormSRGB:M.ASTC10x10Unorm;break;case Fa:r=n===ne?M.ASTC12x10UnormSRGB:M.ASTC12x10Unorm;break;case Ia:r=n===ne?M.ASTC12x12UnormSRGB:M.ASTC12x12Unorm;break;case Lt:r=n===ne?M.RGBA8UnormSRGB:M.RGBA8Unorm;break;default:O("WebGPURenderer: Unsupported texture format.",t)}else switch(t){case Lt:switch(s){case Hn:r=M.RGBA8Snorm;break;case Xn:r=M.RGBA16Sint;break;case rn:r=M.RGBA16Uint;break;case Oe:r=M.RGBA32Uint;break;case ut:r=M.RGBA32Sint;break;case lt:r=n===ne?M.RGBA8UnormSRGB:M.RGBA8Unorm;break;case $e:r=M.RGBA16Float;break;case Ct:r=M.RGBA32Float;break;default:O("WebGPURenderer: Unsupported texture type with RGBAFormat.",s)}break;case la:switch(s){case ou:r=M.RGB9E5UFloat;break;case au:r=M.RG11B10UFloat;break;default:O("WebGPURenderer: Unsupported texture type with RGBFormat.",s)}break;case ua:switch(s){case Hn:r=M.R8Snorm;break;case Xn:r=M.R16Sint;break;case rn:r=M.R16Uint;break;case Oe:r=M.R32Uint;break;case ut:r=M.R32Sint;break;case lt:r=M.R8Unorm;break;case $e:r=M.R16Float;break;case Ct:r=M.R32Float;break;default:O("WebGPURenderer: Unsupported texture type with RedFormat.",s)}break;case Ms:switch(s){case Hn:r=M.RG8Snorm;break;case Xn:r=M.RG16Sint;break;case rn:r=M.RG16Uint;break;case Oe:r=M.RG32Uint;break;case ut:r=M.RG32Sint;break;case lt:r=M.RG8Unorm;break;case $e:r=M.RG16Float;break;case Ct:r=M.RG32Float;break;default:O("WebGPURenderer: Unsupported texture type with RGFormat.",s)}break;case ns:switch(s){case rn:r=M.Depth16Unorm;break;case Oe:r=M.Depth24Plus;break;case Ct:r=M.Depth32Float;break;default:O("WebGPURenderer: Unsupported texture type with DepthFormat.",s)}break;case Hs:switch(s){case Ei:r=M.Depth24PlusStencil8;break;case Ct:e&&e.features.has(Ny.Depth32FloatStencil8)===!1&&O('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),r=M.Depth32FloatStencil8;break;default:O("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",s)}break;case ha:switch(s){case ut:r=M.R32Sint;break;case Oe:r=M.R32Uint;break;default:O("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",s)}break;case da:switch(s){case ut:r=M.RG32Sint;break;case Oe:r=M.RG32Uint;break;default:O("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",s)}break;case pa:switch(s){case ut:r=M.RGBA32Sint;break;case Oe:r=M.RGBA32Uint;break;default:O("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",s)}break;default:O("WebGPURenderer: Unsupported texture format.",t)}return r}var tI=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,sI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,$_={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"},iI=o=>{o=o.trim();let e=o.match(tI);if(e!==null&&e.length===4){let t=e[2],s=[],i=null;for(;(i=sI.exec(t))!==null;)s.push({name:i[1],type:i[2]});let n=[];for(let u=0;u<s.length;u++){let{name:h,type:d}=s[u],p=d;p.startsWith("ptr")?p="pointer":(p.startsWith("texture")&&(p=d.split("<")[0]),p=$_[p]),n.push(new Ac(p,h))}let r=o.substring(e[0].length),a=e[3]||"void",c=e[1]!==void 0?e[1]:"";return{type:$_[a]||a,inputs:n,name:c,inputsCode:t,blockCode:r,outputType:a}}else throw new Error("FunctionNode: Function is not a WGSL code.")},Py=class extends Rc{constructor(e){let{type:t,inputs:s,name:i,inputsCode:n,blockCode:r,outputType:a}=iI(e);super(t,s,i),this.inputsCode=n,this.blockCode=r,this.outputType=a}getCode(e=this.name){let t=this.outputType!=="void"?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}},Dy=class extends Vh{parseFunction(e){return new Py(e)}},nI={[dt.READ_ONLY]:"read",[dt.WRITE_ONLY]:"write",[dt.READ_WRITE]:"read_write"},q_={[Pn]:"repeat",[bs]:"clamp",[Dn]:"mirror"},pf={vertex:ni.VERTEX,fragment:ni.FRAGMENT,compute:ni.COMPUTE},H_={instance:!0,swizzleAssign:!1,storageBuffer:!0},rI={"^^":"tsl_xor"},oI={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},X_={},Ka={tsl_xor:new He("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new He("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new He("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new He("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new He("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new He("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new He("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new He("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new He("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new He("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new He("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new He("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new He(`
|
|
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
|
|
|
|
let res = vec2f( iRes );
|
|
|
|
let uvScaled = coord * res;
|
|
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
|
|
// https://www.shadertoy.com/view/WtyXRy
|
|
|
|
let uv = uvWrapping - 0.5;
|
|
let iuv = floor( uv );
|
|
let f = fract( uv );
|
|
|
|
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
|
|
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
|
|
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
|
|
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
|
|
|
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
|
|
}
|
|
`),biquadraticTextureArray:new He(`
|
|
fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f {
|
|
|
|
let res = vec2f( iRes );
|
|
|
|
let uvScaled = coord * res;
|
|
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
|
|
// https://www.shadertoy.com/view/WtyXRy
|
|
|
|
let uv = uvWrapping - 0.5;
|
|
let iuv = floor( uv );
|
|
let f = fract( uv );
|
|
|
|
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level );
|
|
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level );
|
|
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level );
|
|
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level );
|
|
|
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
|
|
}
|
|
`)},aI={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<f32>",floatpack_snorm_2x16:"pack2x16snorm",floatpack_unorm_2x16:"pack2x16unorm",floatpack_float16_2x16:"pack2x16float",floatunpack_snorm_2x16:"unpack2x16snorm",floatunpack_unorm_2x16:"unpack2x16unorm",floatunpack_float16_2x16:"unpack2x16float"},Qw="";(typeof navigator<"u"&&/Firefox|Deno/g.test(navigator.userAgent))!==!0&&(Qw+=`diagnostic( off, derivative_uniformity );
|
|
`);var Ly=class extends Uh{constructor(e,t){super(e,t,new Dy),this.uniformGroups={},this.uniformGroupsBindings={},this.builtins={},this.directives={},this.scopedArrays=new Map}_generateTextureSample(e,t,s,i,n,r=this.shaderStage){return r==="fragment"?i?n?`textureSample( ${t}, ${t}_sampler, ${s}, ${i}, ${n} )`:`textureSample( ${t}, ${t}_sampler, ${s}, ${i} )`:n?`textureSample( ${t}, ${t}_sampler, ${s}, ${n} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.generateTextureSampleLevel(e,t,s,"0",i)}generateTextureSampleLevel(e,t,s,i,n,r){return this.isUnfilterable(e)===!1?n?r?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${n}, ${i}, ${r} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${n}, ${i} )`:r?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${i}, ${r} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r,i,n):this.generateTextureLod(e,t,s,n,r,i)}generateWrapFunction(e){let t=`tsl_coord_${q_[e.wrapS]}S_${q_[e.wrapT]}_${e.is3DTexture||e.isData3DTexture?"3d":"2d"}T`,s=X_[t];if(s===void 0){let i=[],n=e.is3DTexture||e.isData3DTexture?"vec3f":"vec2f",r=`fn ${t}( coord : ${n} ) -> ${n} {
|
|
|
|
return ${n}(
|
|
`,a=(c,l)=>{c===Pn?(i.push(Ka.repeatWrapping_float),r+=` tsl_repeatWrapping_float( coord.${l} )`):c===bs?(i.push(Ka.clampWrapping_float),r+=` tsl_clampWrapping_float( coord.${l} )`):c===Dn?(i.push(Ka.mirrorWrapping_float),r+=` tsl_mirrorWrapping_float( coord.${l} )`):(r+=` coord.${l}`,z(`WebGPURenderer: Unsupported texture wrap type "${c}" for vertex shader.`))};a(e.wrapS,"x"),r+=`,
|
|
`,a(e.wrapT,"y"),(e.is3DTexture||e.isData3DTexture)&&(r+=`,
|
|
`,a(e.wrapR,"z")),r+=`
|
|
);
|
|
|
|
}
|
|
`,X_[t]=s=new He(r,i)}return s.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,s){let i=this.getDataFromNode(e,this.shaderStage,this.globalCache);i.dimensionsSnippet===void 0&&(i.dimensionsSnippet={});let n=i.dimensionsSnippet[s];if(i.dimensionsSnippet[s]===void 0){let r,a,{primarySamples:c}=this.renderer.backend.utils.getTextureSampleData(e),l=c>1;e.is3DTexture||e.isData3DTexture?a="vec3<u32>":a="vec2<u32>",l||e.isStorageTexture?r=t:r=`${t}${s?`, u32( ${s} )`:""}`,n=new mo(new yo(`textureDimensions( ${r} )`,a)),i.dimensionsSnippet[s]=n,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new mo(new yo(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new mo(new yo("6u","u32")))}return n.build(this)}generateFilteredTexture(e,t,s,i,n="0u",r){let a=this.generateWrapFunction(e),c=this.generateTextureDimension(e,t,n);return i&&(s=`${s} + vec2<f32>(${i}) / ${c}`),r?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${s} ), ${c}, u32( ${r} ), u32( ${n} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${s} ), ${c}, u32( ${n} ) )`)}generateTextureLod(e,t,s,i,n,r="0u"){if(e.isCubeTexture===!0){n&&(s=`${s} + vec3<f32>(${n})`);let p=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${p}( ${r} ) )`}let a=this.generateWrapFunction(e),c=this.generateTextureDimension(e,t,r),l=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",u=l==="vec3"?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )";n&&(s=`${s} + ${l}<f32>(${n}) / ${l}<f32>( ${c} )`);let h=`${l}<f32>( 0 )`,d=`${l}<f32>( ${c} - ${u} )`;return s=`${l}<u32>( clamp( floor( ${a}( ${s} ) * ${l}<f32>( ${c} ) ), ${h}, ${d} ) )`,this.generateTextureLoad(e,t,s,r,i,null)}generateStorageTextureLoad(e,t,s,i,n,r){r&&(s=`${s} + ${r}`);let a;return n?a=`textureLoad( ${t}, ${s}, ${n} )`:a=`textureLoad( ${t}, ${s} )`,a}generateTextureLoad(e,t,s,i,n,r){i===null&&(i="0u"),r&&(s=`${s} + ${r}`);let a;return n?a=`textureLoad( ${t}, ${s}, ${n}, u32( ${i} ) )`:(a=`textureLoad( ${t}, ${s}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,s,i,n){let r;return i?r=`textureStore( ${t}, ${s}, ${i}, ${n} )`:r=`textureStore( ${t}, ${s}, ${n} )`,r}isSampleCompare(e){return e.isDepthTexture===!0&&e.compareFunction!==null&&this.renderer.hasCompatibility(Ys.TEXTURE_COMPARE)}isUnfilterable(e){return this.getComponentTypeFromTexture(e)!=="float"||!this.isAvailable("float32Filterable")&&e.isDataTexture===!0&&e.type===Ct||this.isSampleCompare(e)===!1&&e.minFilter===Ue&&e.magFilter===Ue||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1}generateTexture(e,t,s,i,n,r=this.shaderStage){let a=null;return this.isUnfilterable(e)?a=this.generateTextureLod(e,t,s,i,n,"0",r):a=this._generateTextureSample(e,t,s,i,n,r),a}generateTextureGrad(e,t,s,i,n,r,a=this.shaderStage){if(a==="fragment")return n?r?`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${n}, ${i[0]}, ${i[1]}, ${r} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${n}, ${i[0]}, ${i[1]} )`:r?`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${i[0]}, ${i[1]}, ${r} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${i[0]}, ${i[1]} )`;O(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,s,i,n,r,a=this.shaderStage){if(a==="fragment")return e.isDepthTexture===!0&&e.isArrayTexture===!0?r?`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${n}, ${i}, ${r} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${n}, ${i} )`:r?`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${i}, ${r} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${i} )`;O(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureLevel(e,t,s,i,n,r){return this.isUnfilterable(e)===!1?n?r?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${n}, ${i}, ${r} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${n}, ${i} )`:r?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${i}, ${r} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${i} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r,i,n):this.generateTextureLod(e,t,s,n,r,i)}generateTextureBias(e,t,s,i,n,r,a=this.shaderStage){if(a==="fragment")return n?r?`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${n}, ${i}, ${r} )`:`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${n}, ${i} )`:r?`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${i}, ${r} )`:`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${i} )`;O(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(e.isNodeVarying===!0&&e.needsInterpolation===!0){if(t==="vertex")return`varyings.${e.name}`}else if(e.isNodeUniform===!0){let s=e.name,i=e.type;return i==="texture"||i==="cubeTexture"||i==="cubeDepthTexture"||i==="storageTexture"||i==="texture3D"?s:i==="buffer"||i==="storageBuffer"||i==="indirectStorageBuffer"?this.isCustomStruct(e)?s:s+".value":e.groupNode.name+"."+s}return super.getPropertyName(e)}getOutputStructName(){return"output"}getFunctionOperator(e){let t=rI[e];return t!==void 0?(this._include(t),t):null}getNodeAccess(e,t){return t!=="compute"?e.isAtomic===!0?(z("WebGPURenderer: Atomic operations are only supported in compute shaders."),dt.READ_WRITE):dt.READ_ONLY:e.access}getStorageAccess(e,t){return nI[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,s,i=null){let n=super.getUniformFromNode(e,t,s,i),r=this.getDataFromNode(e,s,this.globalCache);if(r.uniformGPU===void 0){let a,c=e.groupNode,l=c.name,u=this.getBindGroupArray(l,s);if(t==="texture"||t==="cubeTexture"||t==="cubeDepthTexture"||t==="storageTexture"||t==="texture3D"){let h=null,d=this.getNodeAccess(e,s);if(t==="texture"||t==="storageTexture"?e.value.is3DTexture===!0?h=new Cc(n.name,n.node,c,d):h=new No(n.name,n.node,c,d):t==="cubeTexture"||t==="cubeDepthTexture"?h=new Yh(n.name,n.node,c,d):t==="texture3D"&&(h=new Cc(n.name,n.node,c,d)),h.store=e.isStorageTextureNode===!0,h.mipLevel=h.store?e.mipLevel:0,h.setVisibility(pf[s]),e.value.isCubeTexture===!0||this.isUnfilterable(e.value)===!1&&h.store===!1){let m=new Ry(`${n.name}_sampler`,n.node,c);m.setVisibility(pf[s]),u.push(m,h),a=[m,h]}else u.push(h),a=[h]}else if(t==="buffer"||t==="storageBuffer"||t==="indirectStorageBuffer"){let h=this.getSharedDataFromNode(e),d=h.buffer;if(d===void 0){let p=t==="buffer"?qh:Ey;d=new p(e,c),h.buffer=d}d.setVisibility(d.getVisibility()|pf[s]),u.push(d),a=d,n.name=i||"NodeBuffer_"+n.id}else{let h=this.uniformGroups[l];h===void 0&&(h=new Hh(l,c),h.setVisibility(ni.VERTEX|ni.FRAGMENT|ni.COMPUTE),this.uniformGroups[l]=h),u.indexOf(h)===-1&&u.push(h),a=this.getNodeUniform(n,t);let d=a.name;h.uniforms.some(m=>m.name===d)||h.addUniform(a)}r.uniformGPU=a}return n}getBuiltin(e,t,s,i=this.shaderStage){let n=this.builtins[i]||(this.builtins[i]=new Map);return n.has(e)===!1&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return this.builtins[t]!==void 0&&this.builtins[t].has(e)}getVertexIndex(){return this.shaderStage==="vertex"?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){let t=e.layout,s=this.flowShaderNode(e),i=[];for(let r of t.inputs)i.push(r.name+" : "+this.getType(r.type));let n=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} {
|
|
${s.vars}
|
|
${s.code}
|
|
`;return s.result&&(n+=` return ${s.result};
|
|
`),n+=`
|
|
}
|
|
`,n}getInstanceIndex(){return this.shaderStage==="vertex"?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){let t=[],s=this.directives[e];if(s!==void 0)for(let i of s)t.push(`enable ${i};`);return t.join(`
|
|
`)}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array<f32, ${e} >`,"vertex")}getBuiltins(e){let t=[],s=this.builtins[e];if(s!==void 0)for(let{name:i,property:n,type:r}of s.values())t.push(`@builtin( ${i} ) ${n} : ${r}`);return t.join(`,
|
|
`)}getScopedArray(e,t,s,i){return this.scopedArrays.has(e)===!1&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:i}),e}getScopedArrays(e){if(e!=="compute")return;let t=[];for(let{name:s,scope:i,bufferType:n,bufferCount:r}of this.scopedArrays.values()){let a=this.getType(n);t.push(`var<${i}> ${s}: array< ${a}, ${r} >;`)}return t.join(`
|
|
`)}getAttributes(e){let t=[];if(e==="compute"&&(this.getBuiltin("global_invocation_id","globalId","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),e==="vertex"||e==="compute"){let s=this.getBuiltins("attribute");s&&t.push(s);let i=this.getAttributesArray();for(let n=0,r=i.length;n<r;n++){let a=i[n],c=a.name,l=this.getType(a.type);t.push(`@location( ${n} ) ${c} : ${l}`)}}return t.join(`,
|
|
`)}getStructMembers(e){let t=[];for(let s of e.members){let i=e.output?"@location( "+s.index+" ) ":"",n=this.getType(s.type);s.atomic&&(n="atomic< "+n+" >"),t.push(` ${i+s.name} : ${n}`)}return e.output&&t.push(` ${this.getBuiltins("output")}`),t.join(`,
|
|
`)}getStructs(e){let t="",s=this.structs[e];if(s.length>0){let i=[];for(let n of s){let r=`struct ${n.name} {
|
|
`;r+=this.getStructMembers(n),r+=`
|
|
};`,i.push(r)}t=`
|
|
`+i.join(`
|
|
|
|
`)+`
|
|
`}return t}getVar(e,t,s=null){let i=`var ${t} : `;return s!==null?i+=this.generateArrayDeclaration(e,s):i+=this.getType(e),i}getVars(e){let t=[],s=this.vars[e];if(s!==void 0)for(let i of s)t.push(` ${this.getVar(i.type,i.name,i.count)};`);return`
|
|
${t.join(`
|
|
`)}
|
|
`}getVaryings(e){let t=[];if(e==="vertex"&&this.getBuiltin("position","builtinClipSpace","vec4<f32>","vertex"),e==="vertex"||e==="fragment"){let n=this.varyings,r=this.vars[e];for(let a=0;a<n.length;a++){let c=n[a];if(c.needsInterpolation){let l=`@location( ${a} )`;if(c.interpolationType){let u=c.interpolationSampling!==null?`, ${c.interpolationSampling} )`:" )";l+=` @interpolate( ${c.interpolationType}${u}`}else/^(int|uint|ivec|uvec)/.test(c.type)&&(l+=" @interpolate(flat, either)");t.push(`${l} ${c.name} : ${this.getType(c.type)}`)}else e==="vertex"&&r.includes(c)===!1&&r.push(c)}}let s=this.getBuiltins(e);s&&t.push(s);let i=t.join(`,
|
|
`);return e==="vertex"?this._getWGSLStruct("VaryingsStruct"," "+i):i}isCustomStruct(e){let t=e.value,s=e.node,i=(t.isBufferAttribute||t.isInstancedBufferAttribute)&&s.structTypeNode!==null,n=s.value&&s.value.array&&typeof s.value.itemSize=="number"&&s.value.array.length>s.value.itemSize;return i&&!n}getUniforms(e){let t=this.uniforms[e],s=[],i=[],n=[],r={};for(let c of t){let l=c.groupNode.name,u=this.bindingsIndexes[l];if(c.type==="texture"||c.type==="cubeTexture"||c.type==="cubeDepthTexture"||c.type==="storageTexture"||c.type==="texture3D"){let h=c.node.value;(h.isCubeTexture===!0||this.isUnfilterable(h)===!1&&c.node.isStorageTextureNode!==!0)&&(this.isSampleCompare(h)?s.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${c.name}_sampler : sampler_comparison;`):s.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${c.name}_sampler : sampler;`));let p,m="",{primarySamples:g}=this.renderer.backend.utils.getTextureSampleData(h);if(g>1&&(m="_multisampled"),h.isCubeTexture===!0&&h.isDepthTexture===!0)p="texture_depth_cube";else if(h.isCubeTexture===!0)p="texture_cube<f32>";else if(h.isDepthTexture===!0)this.renderer.backend.compatibilityMode&&h.compareFunction===null?p=`texture${m}_2d<f32>`:p=`texture_depth${m}_2d${h.isArrayTexture===!0?"_array":""}`;else if(c.node.isStorageTextureNode===!0){let y=Iy(h),x=this.getStorageAccess(c.node,e),_=c.node.value.is3DTexture,w=c.node.value.isArrayTexture;p=`texture_storage_${_?"3d":`2d${w?"_array":""}`}<${y}, ${x}>`}else if(h.isArrayTexture===!0||h.isDataArrayTexture===!0||h.isCompressedArrayTexture===!0)p="texture_2d_array<f32>";else if(h.is3DTexture===!0||h.isData3DTexture===!0)p="texture_3d<f32>";else{let y=this.getComponentTypeFromTexture(h).charAt(0);p=`texture${m}_2d<${y}32>`}s.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var ${c.name} : ${p};`)}else if(c.type==="buffer"||c.type==="storageBuffer"||c.type==="indirectStorageBuffer"){let h=c.node,d=this.getType(h.getNodeType(this)),p=h.bufferCount,m=p>0&&c.type==="buffer"?", "+p:"",g=h.isStorageBufferNode?`storage, ${this.getStorageAccess(h,e)}`:"uniform";if(this.isCustomStruct(c))i.push(`@binding( ${u.binding++} ) @group( ${u.group} ) var<${g}> ${c.name} : ${d};`);else{let x=` value : array< ${h.isAtomic?`atomic<${d}>`:`${d}`}${m} >`;i.push(this._getWGSLStructBinding(c.name,x,g,u.binding++,u.group))}}else{let h=c.groupNode.name;if(r[h]===void 0){let d=this.uniformGroups[h];if(d!==void 0){let p=[];for(let g of d.uniforms){let y=g.getType(),x=this.getType(this.getVectorType(y));p.push(` ${g.name} : ${x}`)}let m=this.uniformGroupsBindings[h];m===void 0&&(m={index:u.binding++,id:u.group},this.uniformGroupsBindings[h]=m),r[h]={index:m.index,id:m.id,snippets:p}}}}}for(let c in r){let l=r[c];n.push(this._getWGSLStructBinding(c,l.snippets.join(`,
|
|
`),"uniform",l.index,l.id))}return[...s,...i,...n].join(`
|
|
`)}buildCode(){let e=this.material!==null?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(let t in e){this.shaderStage=t;let s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let i=`// code
|
|
|
|
`;i+=this.flowCode[t];let n=this.flowNodes[t],r=n[n.length-1],a=r.outputNode,c=a!==void 0&&a.isOutputStructNode===!0;for(let l of n){let u=this.getFlowData(l),h=l.name;if(h&&(i.length>0&&(i+=`
|
|
`),i+=` // flow -> ${h}
|
|
`),i+=`${u.code}
|
|
`,l===r&&t!=="compute"){if(i+=`// result
|
|
|
|
`,t==="vertex")i+=`varyings.builtinClipSpace = ${u.result};`;else if(t==="fragment")if(c)s.returnType=a.getNodeType(this),s.structs+="var<private> output : "+s.returnType+";",i+=`return ${u.result};`;else{let d=" @location(0) color: vec4<f32>",p=this.getBuiltins("output");p&&(d+=`,
|
|
`+p),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",d),s.structs+=`
|
|
var<private> output : OutputStruct;`,i+=`output.color = ${u.result};
|
|
|
|
return output;`}}}s.flow=i}if(this.shaderStage=null,this.material!==null)this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment);else{let t=this.object.workgroupSize;this.computeShader=this._getWGSLComputeCode(e.compute,t)}}getMethod(e,t=null){let s;return t!==null&&(s=this._getWGSLMethod(e+"_"+t)),s===void 0&&(s=this._getWGSLMethod(e)),s||e}getBitcastMethod(e){return`bitcast<${this.getType(e)}>`}getFloatPackingMethod(e){return this.getMethod(`floatpack_${e}_2x16`)}getFloatUnpackingMethod(e){return this.getMethod(`floatunpack_${e}_2x16`)}getTernary(e,t,s){return`select( ${s}, ${t}, ${e} )`}getType(e){return oI[e]||e}isAvailable(e){let t=H_[e];return t===void 0&&(e==="float32Filterable"?t=this.renderer.hasFeature("float32-filterable"):e==="clipDistance"&&(t=this.renderer.hasFeature("clip-distances")),H_[e]=t),t}getUniformBufferLimit(){return this.renderer.backend.device.limits.maxUniformBufferBindingSize}_getWGSLMethod(e){return Ka[e]!==void 0&&this._include(e),aI[e]}_include(e){let t=Ka[e];return t.build(this),this.addInclude(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}
|
|
// directives
|
|
${e.directives}
|
|
|
|
// structs
|
|
${e.structs}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// varyings
|
|
${e.varyings}
|
|
var<private> varyings : VaryingsStruct;
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@vertex
|
|
fn main( ${e.attributes} ) -> VaryingsStruct {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
return varyings;
|
|
|
|
}
|
|
`}_getWGSLFragmentCode(e){return`${this.getSignature()}
|
|
// global
|
|
${Qw}
|
|
|
|
// structs
|
|
${e.structs}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@fragment
|
|
fn main( ${e.varyings} ) -> ${e.returnType} {
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}_getWGSLComputeCode(e,t){let[s,i,n]=t;return`${this.getSignature()}
|
|
// directives
|
|
${e.directives}
|
|
|
|
// system
|
|
var<private> instanceIndex : u32;
|
|
|
|
// locals
|
|
${e.scopedArrays}
|
|
|
|
// structs
|
|
${e.structs}
|
|
|
|
// uniforms
|
|
${e.uniforms}
|
|
|
|
// codes
|
|
${e.codes}
|
|
|
|
@compute @workgroup_size( ${s}, ${i}, ${n} )
|
|
fn main( ${e.attributes} ) {
|
|
|
|
// system
|
|
instanceIndex = globalId.x
|
|
+ globalId.y * ( ${s} * numWorkgroups.x )
|
|
+ globalId.z * ( ${s} * numWorkgroups.x ) * ( ${i} * numWorkgroups.y );
|
|
|
|
// vars
|
|
${e.vars}
|
|
|
|
// flow
|
|
${e.flow}
|
|
|
|
}
|
|
`}_getWGSLStruct(e,t){return`
|
|
struct ${e} {
|
|
${t}
|
|
};`}_getWGSLStructBinding(e,t,s,i=0,n=0){let r=e+"Struct";return`${this._getWGSLStruct(r,t)}
|
|
@binding( ${i} ) @group( ${n} )
|
|
var<${s}> ${e} : ${r};`}},Uy=class{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return e.depth&&(e.depthTexture!==null?t=this.getTextureFormatGPU(e.depthTexture):e.stencil?t=M.Depth24PlusStencil8:t=M.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){let n=this.backend.renderer,r=n.getRenderTarget();t=r?r.samples:n.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);t=t||1;let s=t>1&&e.renderTarget!==null&&e.isDepthTexture!==!0&&e.isFramebufferTexture!==!0;return{samples:t,primarySamples:s?1:t,isMSAA:s}}getCurrentColorFormat(e){let t;return e.textures!==null?t=this.getTextureFormatGPU(e.textures[0]):t=this.getPreferredCanvasFormat(),t}getCurrentColorFormats(e){return e.textures!==null?e.textures.map(t=>this.getTextureFormatGPU(t)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return e.textures!==null?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){if(e.isPoints)return Gu.PointList;if(e.isLineSegments||e.isMesh&&t.wireframe===!0)return Gu.LineList;if(e.isLine)return Gu.LineStrip;if(e.isMesh)return Gu.TriangleList}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return e.textures!==null?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){let t=this.backend.parameters.outputType;if(t===void 0)return navigator.gpu.getPreferredCanvasFormat();if(t===lt)return M.BGRA8Unorm;if(t===$e)return M.RGBA16Float;throw new Error("Unsupported output buffer type.")}},Kw=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]);typeof Float16Array<"u"&&Kw.set(Float16Array,["float16"]);var cI=new Map([[Zo,["float16"]]]),lI=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]),Oy=class{constructor(e){this.backend=e}createAttribute(e,t){let s=this._getBufferAttribute(e),i=this.backend,n=i.get(s),r=n.buffer;if(r===void 0){let a=i.device,c=s.array;if(e.normalized===!1){if(c.constructor===Int16Array||c.constructor===Int8Array)c=new Int32Array(c);else if((c.constructor===Uint16Array||c.constructor===Uint8Array)&&(c=new Uint32Array(c),t&GPUBufferUsage.INDEX))for(let h=0;h<c.length;h++)c[h]===65535&&(c[h]=4294967295)}if(s.array=c,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&s.itemSize===3){c=new c.constructor(s.count*4);for(let h=0;h<s.count;h++)c.set(s.array.subarray(h*3,h*3+3),h*4);s.itemSize=4,s.array=c,n._force3to4BytesAlignment=!0}let l=c.byteLength,u=l+(4-l%4)%4;r=a.createBuffer({label:s.name,size:u,usage:t,mappedAtCreation:!0}),new c.constructor(r.getMappedRange()).set(c),r.unmap(),n.buffer=r}}updateAttribute(e){let t=this._getBufferAttribute(e),s=this.backend,i=s.device,n=s.get(t),r=s.get(t).buffer,a=t.array;if(n._force3to4BytesAlignment===!0){a=new a.constructor(t.count*4);for(let l=0;l<t.count;l++)a.set(t.array.subarray(l*3,l*3+3),l*4);t.array=a}let c=t.updateRanges;if(c.length===0)i.queue.writeBuffer(r,0,a,0);else{let l=Kr(a),u=l?1:a.BYTES_PER_ELEMENT;for(let h=0,d=c.length;h<d;h++){let p=c[h],m,g;if(n._force3to4BytesAlignment===!0){let x=Math.floor(p.start/3),_=Math.ceil(p.count/3);m=x*4*u,g=_*4*u}else m=p.start*u,g=p.count*u;let y=m*(l?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(r,y,a,m,g)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){let t=e.getAttributes(),s=new Map;for(let i=0;i<t.length;i++){let n=t[i],r=n.array.BYTES_PER_ELEMENT,a=this._getBufferAttribute(n),c=s.get(a);if(c===void 0){let h,d;n.isInterleavedBufferAttribute===!0?(h=n.data.stride*r,d=n.data.isInstancedInterleavedBuffer?Wu.Instance:Wu.Vertex):(h=n.itemSize*r,d=n.isInstancedBufferAttribute?Wu.Instance:Wu.Vertex),n.normalized===!1&&(n.array.constructor===Int16Array||n.array.constructor===Uint16Array)&&(h=4),c={arrayStride:h,attributes:[],stepMode:d},s.set(a,c)}let l=this._getVertexFormat(n),u=n.isInterleavedBufferAttribute===!0?n.offset*r:0;c.attributes.push({shaderLocation:i,offset:u,format:l})}return Array.from(s.values())}destroyAttribute(e){let t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e){let t=this.backend,s=t.device,n=t.get(this._getBufferAttribute(e)).buffer,r=n.size,a=s.createBuffer({label:`${e.name}_readback`,size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),c=s.createCommandEncoder({label:`readback_encoder_${e.name}`});c.copyBufferToBuffer(n,0,a,0,r);let l=c.finish();s.queue.submit([l]),await a.mapAsync(GPUMapMode.READ);let u=a.getMappedRange(),h=new e.array.constructor(u.slice(0));return a.unmap(),h.buffer}_getVertexFormat(e){let{itemSize:t,normalized:s}=e,i=e.array.constructor,n=e.constructor,r;if(t===1)r=lI.get(i);else{let c=(cI.get(n)||Kw.get(i))[s?1:0];if(c){let l=i.BYTES_PER_ELEMENT*t,h=Math.floor((l+3)/4)*4/i.BYTES_PER_ELEMENT;if(h%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");r=`${c}x${h}`}}return r||O("WebGPUAttributeUtils: Vertex format not supported yet."),r}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}},Vy=class{constructor(e){this.layoutGPU=e,this.usedTimes=0}},ky=class{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){let t=this.backend,s=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;let n=this._createLayoutEntries(e),r=Ro(JSON.stringify(n)),a=this._bindGroupLayoutCache.get(r);return a===void 0&&(a=new Vy(s.createBindGroupLayout({entries:n})),this._bindGroupLayoutCache.set(r,a)),a.usedTimes++,i.layout=a,i.layoutKey=r,a.layoutGPU}createBindings(e,t,s,i=0){let{backend:n}=this,r=n.get(e),a=this.createBindingsLayout(e),c;s>0&&(r.groups===void 0&&(r.groups=[],r.versions=[]),r.versions[s]===i&&(c=r.groups[s])),c===void 0&&(c=this.createBindGroup(e,a),s>0&&(r.groups[s]=c,r.versions[s]=i)),r.group=c}updateBinding(e){let t=this.backend,s=t.device,i=e.buffer,n=t.get(e).buffer,r=e.updateRanges;if(r.length===0)s.queue.writeBuffer(n,0,i,0);else{let a=Kr(i),c=a?1:i.BYTES_PER_ELEMENT;for(let l=0,u=r.length;l<u;l++){let h=r[l],d=h.start*c,p=h.count*c,m=d*(a?i.BYTES_PER_ELEMENT:1);s.queue.writeBuffer(n,m,i,d,p)}}}createBindGroupIndex(e,t){let i=this.backend.device,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,r=e[0],a=i.createBuffer({label:"bindingCameraIndex_"+r,size:16,usage:n});i.queue.writeBuffer(a,0,e,0);let c=[{binding:0,resource:{buffer:a}}];return i.createBindGroup({label:"bindGroupCameraIndex_"+r,layout:t,entries:c})}createBindGroup(e,t){let s=this.backend,i=s.device,n=0,r=[];for(let a of e.bindings){if(a.isUniformBuffer){let c=s.get(a);if(c.buffer===void 0){let l=a.byteLength,u=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,h=[];a.visibility&ni.VERTEX&&h.push("vertex"),a.visibility&ni.FRAGMENT&&h.push("fragment"),a.visibility&ni.COMPUTE&&h.push("compute");let d=`(${h.join(",")})`,p=i.createBuffer({label:`bindingBuffer${a.id}_${a.name}_${d}`,size:l,usage:u});c.buffer=p}r.push({binding:n,resource:{buffer:c.buffer}})}else if(a.isStorageBuffer){let c=s.get(a.attribute).buffer;r.push({binding:n,resource:{buffer:c}})}else if(a.isSampledTexture){let c=s.get(a.texture),l;if(c.externalTexture!==void 0)l=i.importExternalTexture({source:c.externalTexture});else{let u=a.store?1:c.texture.mipLevelCount,h=a.store?a.mipLevel:0,d=`view-${c.texture.width}-${c.texture.height}`;if(c.texture.depthOrArrayLayers>1&&(d+=`-${c.texture.depthOrArrayLayers}`),d+=`-${u}-${h}`,l=c[d],l===void 0){let p=JF.All,m;a.isSampledCubeTexture?m=Tt.Cube:a.isSampledTexture3D?m=Tt.ThreeD:a.texture.isArrayTexture||a.texture.isDataArrayTexture||a.texture.isCompressedArrayTexture?m=Tt.TwoDArray:m=Tt.TwoD,l=c[d]=c.texture.createView({aspect:p,dimension:m,mipLevelCount:u,baseMipLevel:h})}}r.push({binding:n,resource:l})}else if(a.isSampler){let c=s.get(a.texture);r.push({binding:n,resource:c.sampler})}n++}return i.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:r})}_createLayoutEntries(e){let t=[],s=0;for(let i of e.bindings){let n=this.backend,r={binding:s,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){let a={};i.isStorageBuffer&&(i.visibility&ni.COMPUTE&&(i.access===dt.READ_WRITE||i.access===dt.WRITE_ONLY)?a.type=hf.Storage:a.type=hf.ReadOnlyStorage),r.buffer=a}else if(i.isSampledTexture&&i.store){let a={};a.format=this.backend.get(i.texture).texture.format;let c=i.access;c===dt.READ_WRITE?a.access=df.ReadWrite:c===dt.WRITE_ONLY?a.access=df.WriteOnly:a.access=df.ReadOnly,i.texture.isArrayTexture?a.viewDimension=Tt.TwoDArray:i.texture.is3DTexture&&(a.viewDimension=Tt.ThreeD),r.storageTexture=a}else if(i.isSampledTexture){let a={},{primarySamples:c}=n.utils.getTextureSampleData(i.texture);if(c>1&&(a.multisampled=!0,i.texture.isDepthTexture||(a.sampleType=Kn.UnfilterableFloat)),i.texture.isDepthTexture)n.compatibilityMode&&i.texture.compareFunction===null?a.sampleType=Kn.UnfilterableFloat:a.sampleType=Kn.Depth;else if(i.texture.isDataTexture||i.texture.isDataArrayTexture||i.texture.isData3DTexture){let l=i.texture.type;l===ut?a.sampleType=Kn.SInt:l===Oe?a.sampleType=Kn.UInt:l===Ct&&(this.backend.hasFeature("float32-filterable")?a.sampleType=Kn.Float:a.sampleType=Kn.UnfilterableFloat)}i.isSampledCubeTexture?a.viewDimension=Tt.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?a.viewDimension=Tt.TwoDArray:i.isSampledTexture3D&&(a.viewDimension=Tt.ThreeD),r.texture=a}else if(i.isSampler){let a={};i.texture.isDepthTexture&&(i.texture.compareFunction!==null&&n.hasCompatibility(Ys.TEXTURE_COMPARE)?a.type=z_.Comparison:a.type=z_.NonFiltering),r.sampler=a}else O(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(r),s++}return t}deleteBindGroupData(e){let{backend:t}=this,s=t.get(e);s.layout&&(s.layout.usedTimes--,s.layout.usedTimes===0&&this._bindGroupLayoutCache.delete(s.layoutKey),s.layout=void 0,s.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}},zy=class{constructor(e){this.backend=e,this._activePipelines=new WeakMap}setPipeline(e,t){this._activePipelines.get(e)!==t&&(e.setPipeline(t),this._activePipelines.set(e,t))}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){let{object:s,material:i,geometry:n,pipeline:r}=e,{vertexProgram:a,fragmentProgram:c}=r,l=this.backend,u=l.device,h=l.utils,d=l.get(r),p=[];for(let Y of e.getBindings()){let ee=l.get(Y),{layoutGPU:Q}=ee.layout;p.push(Q)}let m=l.attributeUtils.createShaderVertexBuffers(e),g;i.blending!==qs&&(i.blending!==Ht||i.transparent!==!1)&&(g=this._getBlending(i));let y={};i.stencilWrite===!0&&(y={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});let x=this._getColorWriteMask(i),_=[];if(e.context.textures!==null){let Y=e.context.textures,ee=e.context.mrt;for(let Q=0;Q<Y.length;Q++){let ie=Y[Q],Pe=h.getTextureFormatGPU(ie),Se;if(ee!==null)if(this.backend.compatibilityMode!==!0){let ae=ee.getBlendMode(ie.name);ae.blending===eu?Se=g:ae.blending!==qs&&(Se=this._getBlending(ae))}else _e("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),Se=g;else Se=g;_.push({format:Pe,blend:Se,writeMask:x})}}else{let Y=h.getCurrentColorFormat(e.context);_.push({format:Y,blend:g,writeMask:x})}let w=l.get(a).module,S=l.get(c).module,E=this._getPrimitiveState(s,n,i),B=this._getDepthCompare(i),N=h.getCurrentDepthStencilFormat(e.context),C=this._getSampleCount(e.context),I={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},w,{buffers:m}),fragment:Object.assign({},S,{targets:_}),primitive:E,multisample:{count:C,alphaToCoverageEnabled:i.alphaToCoverage&&C>1},layout:u.createPipelineLayout({bindGroupLayouts:p})},k={},W=e.context.depth,X=e.context.stencil;if((W===!0||X===!0)&&(W===!0&&(k.format=N,k.depthWriteEnabled=i.depthWrite,k.depthCompare=B),X===!0&&(k.stencilFront=y,k.stencilBack=y,k.stencilReadMask=i.stencilFuncMask,k.stencilWriteMask=i.stencilWriteMask),i.polygonOffset===!0&&(k.depthBias=i.polygonOffsetUnits,k.depthBiasSlopeScale=i.polygonOffsetFactor,k.depthBiasClamp=0),I.depthStencil=k),u.pushErrorScope("validation"),t===null)d.pipeline=u.createRenderPipeline(I),u.popErrorScope().then(Y=>{Y!==null&&(d.error=!0,O(Y.message))});else{let Y=new Promise(async ee=>{try{d.pipeline=await u.createRenderPipelineAsync(I)}catch{}let Q=await u.popErrorScope();Q!==null&&(d.error=!0,O(Q.message)),ee()});t.push(Y)}}createBundleEncoder(e,t="renderBundleEncoder"){let s=this.backend,{utils:i,device:n}=s,r=i.getCurrentDepthStencilFormat(e),a=i.getCurrentColorFormats(e),c=this._getSampleCount(e),l={label:t,colorFormats:a,depthStencilFormat:r,sampleCount:c};return n.createRenderBundleEncoder(l)}createComputePipeline(e,t){let s=this.backend,i=s.device,n=s.get(e.computeProgram).module,r=s.get(e),a=[];for(let c of t){let l=s.get(c),{layoutGPU:u}=l.layout;a.push(u)}r.pipeline=i.createComputePipeline({compute:n,layout:i.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(e){let t,s,i=e.blending,n=e.blendSrc,r=e.blendDst,a=e.blendEquation;if(i===$n){let c=e.blendSrcAlpha!==null?e.blendSrcAlpha:n,l=e.blendDstAlpha!==null?e.blendDstAlpha:r,u=e.blendEquationAlpha!==null?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(r),operation:this._getBlendOperation(a)},s={srcFactor:this._getBlendFactor(c),dstFactor:this._getBlendFactor(l),operation:this._getBlendOperation(u)}}else{let c=e.premultipliedAlpha,l=(u,h,d,p)=>{t={srcFactor:u,dstFactor:h,operation:Qn.Add},s={srcFactor:d,dstFactor:p,operation:Qn.Add}};if(c)switch(i){case Ht:l(pe.One,pe.OneMinusSrcAlpha,pe.One,pe.OneMinusSrcAlpha);break;case zn:l(pe.One,pe.One,pe.One,pe.One);break;case Gn:l(pe.Zero,pe.OneMinusSrc,pe.Zero,pe.One);break;case Wn:l(pe.Dst,pe.OneMinusSrcAlpha,pe.Zero,pe.One);break}else switch(i){case Ht:l(pe.SrcAlpha,pe.OneMinusSrcAlpha,pe.One,pe.OneMinusSrcAlpha);break;case zn:l(pe.SrcAlpha,pe.One,pe.One,pe.One);break;case Gn:O(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case Wn:O(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break}}if(t!==void 0&&s!==void 0)return{color:t,alpha:s};O("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case Ni:t=pe.Zero;break;case up:t=pe.One;break;case hp:t=pe.Src;break;case dp:t=pe.OneMinusSrc;break;case Ir:t=pe.SrcAlpha;break;case Pr:t=pe.OneMinusSrcAlpha;break;case mp:t=pe.Dst;break;case gp:t=pe.OneMinusDst;break;case pp:t=pe.DstAlpha;break;case fp:t=pe.OneMinusDstAlpha;break;case yp:t=pe.SrcAlphaSaturated;break;case aR:t=pe.Constant;break;case cR:t=pe.OneMinusConstant;break;default:O("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t,s=e.stencilFunc;switch(s){case xb:t=ht.Never;break;case hl:t=ht.Always;break;case bb:t=ht.Less;break;case Tb:t=ht.LessEqual;break;case _b:t=ht.Equal;break;case wb:t=ht.GreaterEqual;break;case Sb:t=ht.Greater;break;case vb:t=ht.NotEqual;break;default:O("WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Qi:t=an.Keep;break;case hb:t=an.Zero;break;case db:t=an.Replace;break;case yb:t=an.Invert;break;case pb:t=an.IncrementClamp;break;case fb:t=an.DecrementClamp;break;case mb:t=an.IncrementWrap;break;case gb:t=an.DecrementWrap;break;default:O("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Xt:t=Qn.Add;break;case cp:t=Qn.Subtract;break;case lp:t=Qn.ReverseSubtract;break;case j0:t=Qn.Min;break;case Z0:t=Qn.Max;break;default:O("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){let i={},n=this.backend.utils;i.topology=n.getPrimitiveTopology(e,s),t.index!==null&&e.isLine===!0&&e.isLineSegments!==!0&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?Qh.Uint16:Qh.Uint32);let r=s.side===rt;return e.isMesh&&e.matrixWorld.determinant()<0&&(r=!r),i.frontFace=r===!0?O_.CW:O_.CCW,i.cullMode=s.side===$s?V_.None:V_.Back,i}_getColorWriteMask(e){return e.colorWrite===!0?k_.All:k_.None}_getDepthCompare(e){let t;if(e.depthTest===!1)t=ht.Always;else{let s=this.backend.parameters.reversedDepthBuffer?Np[e.depthFunc]:e.depthFunc;switch(s){case Oo:t=ht.Never;break;case Vo:t=ht.Always;break;case ko:t=ht.Less;break;case In:t=ht.LessEqual;break;case zo:t=ht.Equal;break;case Go:t=ht.GreaterEqual;break;case Wo:t=ht.Greater;break;case $o:t=ht.NotEqual;break;default:O("WebGPUPipelineUtils: Invalid depth function.",s)}}return t}},Gy=class extends Zh{constructor(e,t,s=2048){super(s),this.device=e,this.type=t,this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxQueries,label:`queryset_global_timestamp_${t}`});let i=this.maxQueries*8;this.resolveBuffer=this.device.createBuffer({label:`buffer_timestamp_resolve_${t}`,size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.resultBuffer=this.device.createBuffer({label:`buffer_timestamp_result_${t}`,size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;if(this.currentQueryIndex+2>this.maxQueries)return _e(`WebGPUTimestampQueryPool [${this.type}]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${this.type.toUpperCase()} ).`),null;let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||this.currentQueryIndex===0||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if(this.resultBuffer.mapState!=="unmapped")return this.lastValue;let e=new Map(this.queryOffsets),t=this.currentQueryIndex,s=t*8;this.currentQueryIndex=0,this.queryOffsets.clear();let i=this.device.createCommandEncoder();i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,s);let n=i.finish();if(this.device.queue.submit([n]),this.resultBuffer.mapState!=="unmapped")return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,s),this.isDisposed)return this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue;let r=new BigUint64Array(this.resultBuffer.getMappedRange(0,s)),a={},c=[];for(let[u,h]of e){let d=u.match(/^(.*):f(\d+)$/),p=parseInt(d[2]);c.includes(p)===!1&&c.push(p),a[p]===void 0&&(a[p]=0);let m=r[h],g=r[h+1],y=Number(g-m)/1e6;this.timestamps.set(u,y),a[p]+=y}let l=a[c[c.length-1]];return this.resultBuffer.unmap(),this.lastValue=l,this.frames=c,l}catch(e){return O("Error resolving queries:",e),this.resultBuffer.mapState==="mapped"&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){O("Error waiting for pending resolve:",e)}if(this.resultBuffer&&this.resultBuffer.mapState==="mapped")try{this.resultBuffer.unmap()}catch(e){O("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.pendingResolve=null}}},Wy=class extends jh{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=e.alpha===void 0?!0:e.alpha,this.parameters.requiredLimits=e.requiredLimits===void 0?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new Uy(this),this.attributeUtils=new Oy(this),this.bindingUtils=new ky(this),this.pipelineUtils=new zy(this),this.textureUtils=new Fy(this),this.occludedResolveCache=new Map;let t=typeof navigator>"u"?!0:/Android/.test(navigator.userAgent)===!1;this._compatibility={[Ys.TEXTURE_COMPARE]:t}}async init(e){await super.init(e);let t=this.parameters,s;if(t.device===void 0){let i={powerPreference:t.powerPreference,featureLevel:"compatibility"},n=typeof navigator<"u"?await navigator.gpu.requestAdapter(i):null;if(n===null)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");let r=Object.values(Ny),a=[];for(let l of r)n.features.has(l)&&a.push(l);let c={requiredFeatures:a,requiredLimits:t.requiredLimits};s=await n.requestDevice(c)}else s=t.device;this.compatibilityMode=!s.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),s.lost.then(i=>{if(i.reason==="destroyed")return;let n={api:"WebGPU",message:i.message||"Unknown reason",reason:i.reason||null,originalEvent:i};e.onDeviceLost(n)}),this.device=s,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(Ny.TimestampQuery),this.updateSize()}get context(){let e=this.renderer.getCanvasTarget(),t=this.get(e),s=t.context;if(s===void 0){let i=this.parameters;e.isDefaultCanvasTarget===!0&&i.context!==void 0?s=i.context:s=e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${"183"} webgpu`);let n=i.alpha?"premultiplied":"opaque",r=i.outputType===$e?"extended":"standard";s.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n,toneMapping:{mode:r}}),t.context=s}return s}get coordinateSystem(){return Yt}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.renderer,t=e.getCanvasTarget(),s=this.get(t),i=e.currentSamples,n=s.descriptor;if(n===void 0||s.samples!==i){n={colorAttachments:[{view:null}]},(e.depth===!0||e.stencil===!0)&&(n.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});let a=n.colorAttachments[0];i>0?a.view=this.textureUtils.getColorBuffer().createView():a.resolveTarget=void 0,s.descriptor=n,s.samples=i}let r=n.colorAttachments[0];return i>0?r.resolveTarget=this.context.getCurrentTexture().createView():r.view=this.context.getCurrentTexture().createView(),n}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.image.depth>1&&e.camera.isArrayCamera}_getRenderPassDescriptor(e,t={}){let s=e.renderTarget,i=this.get(s),n=i.descriptors;(n===void 0||i.width!==s.width||i.height!==s.height||i.samples!==s.samples)&&(n={},i.descriptors=n);let r=e.getCacheKey(),a=n[r];if(a===void 0){let l=e.textures,u=[],h,d=this._isRenderCameraDepthArray(e);for(let p=0;p<l.length;p++){let m=this.get(l[p]),g={label:`colorAttachment_${p}`,baseMipLevel:e.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:e.activeCubeFace,arrayLayerCount:1,dimension:Tt.TwoD};if(s.isRenderTarget3D)h=e.activeCubeFace,g.baseArrayLayer=0,g.dimension=Tt.ThreeD,g.depthOrArrayLayers=l[p].image.depth;else if(s.isRenderTarget&&l[p].image.depth>1)if(d===!0){let y=e.camera.cameras;for(let x=0;x<y.length;x++){let _={...g,baseArrayLayer:x,arrayLayerCount:1,dimension:Tt.TwoD},w=m.texture.createView(_);u.push({view:w,resolveTarget:void 0,depthSlice:void 0})}}else g.dimension=Tt.TwoDArray,g.depthOrArrayLayers=l[p].image.depth;if(d!==!0){let y=m.texture.createView(g),x,_;m.msaaTexture!==void 0?(x=m.msaaTexture.createView(),_=y):(x=y,_=void 0),u.push({view:x,resolveTarget:_,depthSlice:h})}}if(a={textureViews:u},e.depth){let p=this.get(e.depthTexture),m={};(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(m.dimension=Tt.TwoD,m.arrayLayerCount=1,m.baseArrayLayer=e.activeCubeFace),a.depthStencilView=p.texture.createView(m)}n[r]=a,i.width=s.width,i.height=s.height,i.samples=s.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace}let c={colorAttachments:[]};for(let l=0;l<a.textureViews.length;l++){let u=a.textureViews[l],h={r:0,g:0,b:0,a:1};l===0&&t.clearValue&&(h=t.clearValue),c.colorAttachments.push({view:u.view,depthSlice:u.depthSlice,resolveTarget:u.resolveTarget,loadOp:t.loadOp||ve.Load,storeOp:t.storeOp||Et.Store,clearValue:h})}return a.depthStencilView&&(c.depthStencilAttachment={view:a.depthStencilView}),c}beginRender(e){let t=this.get(e),s=this.device,i=e.occlusionQueryCount,n;i>0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:i,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(i),t.lastOcclusionObject=null);let r;e.textures===null?r=this._getDefaultRenderPassDescriptor():r=this._getRenderPassDescriptor(e,{loadOp:ve.Load}),this.initTimestampQuery(As.RENDER,this.getTimestampUID(e),r),r.occlusionQuerySet=n;let a=r.depthStencilAttachment;if(e.textures!==null){let l=r.colorAttachments;for(let u=0;u<l.length;u++){let h=l[u];e.clearColor?(h.clearValue=u===0?e.clearColorValue:{r:0,g:0,b:0,a:1},h.loadOp=ve.Clear):h.loadOp=ve.Load,h.storeOp=Et.Store}}else{let l=r.colorAttachments[0];e.clearColor?(l.clearValue=e.clearColorValue,l.loadOp=ve.Clear):l.loadOp=ve.Load,l.storeOp=Et.Store}e.depth&&(e.clearDepth?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=ve.Clear):a.depthLoadOp=ve.Load,a.depthStoreOp=Et.Store),e.stencil&&(e.clearStencil?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=ve.Clear):a.stencilLoadOp=ve.Load,a.stencilStoreOp=Et.Store);let c=s.createCommandEncoder({label:"renderContext_"+e.id});if(this._isRenderCameraDepthArray(e)===!0){let l=e.camera.cameras;!t.layerDescriptors||t.layerDescriptors.length!==l.length?this._createDepthLayerDescriptors(e,t,r,l):this._updateDepthLayerDescriptors(e,t,l),t.bundleEncoders=[],t.bundleSets=[];for(let u=0;u<l.length;u++){let h=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+u),d={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(h),t.bundleSets.push(d)}t.currentPass=null}else{let l=c.beginRenderPass(r);t.currentPass=l,e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e)}t.descriptor=r,t.encoder=c,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.renderBundles=[]}_createDepthLayerDescriptors(e,t,s,i){let n=s.depthStencilAttachment;t.layerDescriptors=[];let r=this.get(e.depthTexture);r.viewCache||(r.viewCache=[]);for(let a=0;a<i.length;a++){let c={...s,colorAttachments:[{...s.colorAttachments[0],view:s.colorAttachments[a].view}]};if(s.depthStencilAttachment){let l=a;r.viewCache[l]||(r.viewCache[l]=r.texture.createView({dimension:Tt.TwoD,baseArrayLayer:a,arrayLayerCount:1})),c.depthStencilAttachment={view:r.viewCache[l],depthLoadOp:n.depthLoadOp||ve.Clear,depthStoreOp:n.depthStoreOp||Et.Store,depthClearValue:n.depthClearValue||1},e.stencil&&(c.depthStencilAttachment.stencilLoadOp=n.stencilLoadOp,c.depthStencilAttachment.stencilStoreOp=n.stencilStoreOp,c.depthStencilAttachment.stencilClearValue=n.stencilClearValue)}else c.depthStencilAttachment={...n};t.layerDescriptors.push(c)}}_updateDepthLayerDescriptors(e,t,s){for(let i=0;i<s.length;i++){let n=t.layerDescriptors[i];if(n.depthStencilAttachment){let r=n.depthStencilAttachment;e.depth&&(e.clearDepth?(r.depthClearValue=e.clearDepthValue,r.depthLoadOp=ve.Clear):r.depthLoadOp=ve.Load),e.stencil&&(e.clearStencil?(r.stencilClearValue=e.clearStencilValue,r.stencilLoadOp=ve.Clear):r.stencilLoadOp=ve.Load)}}}finishRender(e){let t=this.get(e),s=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery();let i=t.encoder;if(this._isRenderCameraDepthArray(e)===!0){let n=[];for(let r=0;r<t.bundleEncoders.length;r++){let a=t.bundleEncoders[r];n.push(a.finish())}for(let r=0;r<t.layerDescriptors.length;r++)if(r<n.length){let a=t.layerDescriptors[r],c=i.beginRenderPass(a);if(e.viewport){let{x:l,y:u,width:h,height:d,minDepth:p,maxDepth:m}=e.viewportValue;c.setViewport(l,u,h,d,p,m)}if(e.scissor){let{x:l,y:u,width:h,height:d}=e.scissorValue;c.setScissorRect(l,u,h,d)}c.executeBundles([n[r]]),c.end()}}else t.currentPass&&t.currentPass.end();if(s>0){let n=s*8,r=this.occludedResolveCache.get(n);r===void 0&&(r=this.device.createBuffer({size:n,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(n,r));let a=this.device.createBuffer({size:n,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,r,0),t.encoder.copyBufferToBuffer(r,0,a,0,n),t.occlusionQueryBuffer=a,this.resolveOccludedAsync(e)}if(this.device.queue.submit([t.encoder.finish()]),e.textures!==null){let n=e.textures;for(let r=0;r<n.length;r++){let a=n[r];a.generateMipmaps===!0&&this.textureUtils.generateMipmaps(a)}}}isOccluded(e,t){let s=this.get(e);return s.occluded&&s.occluded.has(t)}async resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueryBuffer:s,currentOcclusionQueryObjects:i}=t;if(s&&i){let n=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);let r=s.getMappedRange(),a=new BigUint64Array(r);for(let c=0;c<i.length;c++)a[c]===BigInt(0)&&n.add(i[c]);s.destroy(),t.occluded=n}}updateViewport(e){let{currentPass:t}=this.get(e),{x:s,y:i,width:n,height:r,minDepth:a,maxDepth:c}=e.viewportValue;t.setViewport(s,i,n,r,a,c)}updateScissor(e){let{currentPass:t}=this.get(e),{x:s,y:i,width:n,height:r}=e.scissorValue;t.setScissorRect(s,i,n,r)}getClearColor(){let e=super.getClearColor();return this.renderer.alpha===!0&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,s,i=null){let n=this.device,r=this.renderer,a=[],c,l,u,h;if(e){let m=this.getClearColor();l={r:m.r,g:m.g,b:m.b,a:m.a}}if(i===null){u=r.depth,h=r.stencil;let m=this._getDefaultRenderPassDescriptor();if(e){a=m.colorAttachments;let g=a[0];g.clearValue=l,g.loadOp=ve.Clear,g.storeOp=Et.Store}(u||h)&&(c=m.depthStencilAttachment)}else{u=i.depth,h=i.stencil;let m={loadOp:e?ve.Clear:ve.Load,clearValue:e?l:void 0};u&&(m.depthLoadOp=t?ve.Clear:ve.Load,m.depthClearValue=t?r.getClearDepth():void 0,m.depthStoreOp=Et.Store),h&&(m.stencilLoadOp=s?ve.Clear:ve.Load,m.stencilClearValue=s?r.getClearStencil():void 0,m.stencilStoreOp=Et.Store);let g=this._getRenderPassDescriptor(i,m);a=g.colorAttachments,c=g.depthStencilAttachment}u&&c&&(t?(c.depthLoadOp=ve.Clear,c.depthClearValue=r.getClearDepth(),c.depthStoreOp=Et.Store):(c.depthLoadOp=ve.Load,c.depthStoreOp=Et.Store)),h&&c&&(s?(c.stencilLoadOp=ve.Clear,c.stencilClearValue=r.getClearStencil(),c.stencilStoreOp=Et.Store):(c.stencilLoadOp=ve.Load,c.stencilStoreOp=Et.Store));let d=n.createCommandEncoder({label:"clear"});d.beginRenderPass({colorAttachments:a,depthStencilAttachment:c}).end(),n.queue.submit([d.finish()])}beginCompute(e){let t=this.get(e),s={label:"computeGroup_"+e.id};this.initTimestampQuery(As.COMPUTE,this.getTimestampUID(e),s),t.cmdEncoderGPU=this.device.createCommandEncoder({label:"computeGroup_"+e.id}),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(s)}compute(e,t,s,i,n=null){let r=this.get(t),{passEncoderGPU:a}=this.get(e),c=this.get(i).pipeline;this.pipelineUtils.setPipeline(a,c);for(let l=0,u=s.length;l<u;l++){let h=s[l],d=this.get(h);a.setBindGroup(l,d.group)}if(n===null&&(n=t.count),n&&typeof n=="object"&&n.isIndirectStorageBufferAttribute){let l=this.get(n).buffer;a.dispatchWorkgroupsIndirect(l,0);return}if(typeof n=="number"){let l=n;if(r.dispatchSize===void 0||r.count!==l){r.dispatchSize=[0,1,1],r.count=l;let u=t.workgroupSize,h=u[0];for(let m=1;m<u.length;m++)h*=u[m];let d=Math.ceil(l/h),p=this.device.limits.maxComputeWorkgroupsPerDimension;n=[d,1,1],d>p&&(n[0]=Math.min(d,p),n[1]=Math.ceil(d/p)),r.dispatchSize=n}n=r.dispatchSize}a.dispatchWorkgroups(n[0],n[1]||1,n[2]||1)}finishCompute(e){let t=this.get(e);t.passEncoderGPU.end(),this.device.queue.submit([t.cmdEncoderGPU.finish()])}draw(e,t){let{object:s,material:i,context:n,pipeline:r}=e,a=e.getBindings(),c=this.get(n),l=this.get(r),u=l.pipeline;if(l.error===!0)return;let h=e.getIndex(),d=h!==null,p=e.getDrawParameters();if(p===null)return;let m=(y,x)=>{this.pipelineUtils.setPipeline(y,u),x.pipeline=u;let _=x.bindingGroups;for(let S=0,E=a.length;S<E;S++){let B=a[S],N=this.get(B);_[B.index]!==B.id&&(y.setBindGroup(B.index,N.group),_[B.index]=B.id)}if(d===!0&&x.index!==h){let S=this.get(h).buffer,E=h.array instanceof Uint16Array?Qh.Uint16:Qh.Uint32;y.setIndexBuffer(S,E),x.index=h}let w=e.getVertexBuffers();for(let S=0,E=w.length;S<E;S++){let B=w[S];if(x.attributes[S]!==B){let N=this.get(B).buffer;y.setVertexBuffer(S,N),x.attributes[S]=B}}n.stencil===!0&&i.stencilWrite===!0&&c.currentStencilRef!==i.stencilRef&&(y.setStencilReference(i.stencilRef),c.currentStencilRef=i.stencilRef)},g=(y,x)=>{if(m(y,x),s.isBatchedMesh===!0){let _=s._multiDrawStarts,w=s._multiDrawCounts,S=s._multiDrawCount,E=s._multiDrawInstances;E!==null&&_e("WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.");let B=d===!0?h.array.BYTES_PER_ELEMENT:1;i.wireframe&&(B=s.geometry.attributes.position.count>65535?4:2);for(let N=0;N<S;N++){let C=E?E[N]:1,I=C>1?0:N;d===!0?y.drawIndexed(w[N],C,_[N]/B,0,I):y.draw(w[N],C,_[N],I),t.update(s,w[N],C)}}else if(d===!0){let{vertexCount:_,instanceCount:w,firstVertex:S}=p,E=e.getIndirect();if(E!==null){let B=this.get(E).buffer,N=e.getIndirectOffset(),C=Array.isArray(N)?N:[N];for(let I=0;I<C.length;I++)y.drawIndexedIndirect(B,C[I])}else y.drawIndexed(_,w,S,0,0);t.update(s,_,w)}else{let{vertexCount:_,instanceCount:w,firstVertex:S}=p,E=e.getIndirect();if(E!==null){let B=this.get(E).buffer,N=e.getIndirectOffset(),C=Array.isArray(N)?N:[N];for(let I=0;I<C.length;I++)y.drawIndirect(B,C[I])}else y.draw(_,w,S,0);t.update(s,_,w)}};if(e.camera.isArrayCamera&&e.camera.cameras.length>0){let y=this.get(e.camera),x=e.camera.cameras,_=e.getBindingGroup("cameraIndex");if(y.indexesGPU===void 0||y.indexesGPU.length!==x.length){let S=this.get(_),E=[],B=new Uint32Array([0,0,0,0]);for(let N=0,C=x.length;N<C;N++){B[0]=N;let{layoutGPU:I}=S.layout,k=this.bindingUtils.createBindGroupIndex(B,I);E.push(k)}y.indexesGPU=E}let w=this.renderer.getPixelRatio();for(let S=0,E=x.length;S<E;S++){let B=x[S];if(s.layers.test(B.layers)){let N=B.viewport,C=c.currentPass,I=c.currentSets;if(c.bundleEncoders){let k=c.bundleEncoders[S],W=c.bundleSets[S];C=k,I=W}N&&C.setViewport(Math.floor(N.x*w),Math.floor(N.y*w),Math.floor(N.width*w),Math.floor(N.height*w),n.viewportValue.minDepth,n.viewportValue.maxDepth),_&&y.indexesGPU&&(C.setBindGroup(_.index,y.indexesGPU[S]),I.bindingGroups[_.index]=_.id),g(C,I)}}}else if(c.currentPass){if(c.occlusionQuerySet!==void 0){let y=c.lastOcclusionObject;y!==s&&(y!==null&&y.occlusionTest===!0&&(c.currentPass.endOcclusionQuery(),c.occlusionQueryIndex++),s.occlusionTest===!0&&(c.currentPass.beginOcclusionQuery(c.occlusionQueryIndex),c.occlusionQueryObjects[c.occlusionQueryIndex]=s),c.lastOcclusionObject=s)}g(c.currentPass,c.currentSets)}}needsRenderUpdate(e){let t=this.get(e),{object:s,material:i}=e,n=this.utils,r=n.getSampleCountRenderContext(e.context),a=n.getCurrentColorSpace(e.context),c=n.getCurrentColorFormat(e.context),l=n.getCurrentDepthStencilFormat(e.context),u=n.getPrimitiveTopology(s,i),h=!1;return(t.material!==i||t.materialVersion!==i.version||t.transparent!==i.transparent||t.blending!==i.blending||t.premultipliedAlpha!==i.premultipliedAlpha||t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendEquation!==i.blendEquation||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha||t.blendEquationAlpha!==i.blendEquationAlpha||t.colorWrite!==i.colorWrite||t.depthWrite!==i.depthWrite||t.depthTest!==i.depthTest||t.depthFunc!==i.depthFunc||t.stencilWrite!==i.stencilWrite||t.stencilFunc!==i.stencilFunc||t.stencilFail!==i.stencilFail||t.stencilZFail!==i.stencilZFail||t.stencilZPass!==i.stencilZPass||t.stencilFuncMask!==i.stencilFuncMask||t.stencilWriteMask!==i.stencilWriteMask||t.side!==i.side||t.alphaToCoverage!==i.alphaToCoverage||t.sampleCount!==r||t.colorSpace!==a||t.colorFormat!==c||t.depthStencilFormat!==l||t.primitiveTopology!==u||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=r,t.colorSpace=a,t.colorFormat=c,t.depthStencilFormat=l,t.primitiveTopology=u,t.clippingContextCacheKey=e.clippingContextCacheKey,h=!0),h}getRenderCacheKey(e){let{object:t,material:s}=e,i=this.utils,n=e.context,r=t.isMesh&&t.matrixWorld.determinant()<0;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,r,i.getSampleCountRenderContext(n),i.getCurrentColorSpace(n),i.getCurrentColorFormat(n),i.getCurrentDepthStencilFormat(n),i.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}createDefaultTexture(e){return this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,s,i,n,r){return this.textureUtils.copyTextureToBuffer(e,t,s,i,n,r)}initTimestampQuery(e,t,s){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new Gy(this.device,e,2048));let i=this.timestampQueryPool[e],n=i.allocateQueriesForContext(t);s.timestampWrites={querySet:i.querySet,beginningOfPassWriteIndex:n,endOfPassWriteIndex:n+1}}createNodeBuilder(e,t){return new Ly(e,t)}createProgram(e){let t=this.get(e);t.module={module:this.device.createShaderModule({code:e.code,label:e.stage+(e.name!==""?`_${e.name}`:"")}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){let t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){let s=this.get(e),n=s.currentPass.finish();this.get(t).bundleGPU=n,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,i){this.bindingUtils.createBindings(e,t,s,i)}updateBindings(e,t,s,i){this.bindingUtils.createBindings(e,t,s,i)}updateBinding(e){this.bindingUtils.updateBinding(e)}deleteBindGroupData(e){this.bindingUtils.deleteBindGroupData(e)}createIndexAttribute(e){let t=GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST;(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t|=GPUBufferUsage.STORAGE),this.attributeUtils.createAttribute(e,t)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.delete(this.renderer.getCanvasTarget())}getMaxAnisotropy(){return 16}hasFeature(e){return W_[e]!==void 0&&(e=W_[e]),this.device.features.has(e)}copyTextureToTexture(e,t,s=null,i=null,n=0,r=0){let a=0,c=0,l=0,u=0,h=0,d=0,p=e.image.width,m=e.image.height,g=1;s!==null&&(s.isBox3===!0?(u=s.min.x,h=s.min.y,d=s.min.z,p=s.max.x-s.min.x,m=s.max.y-s.min.y,g=s.max.z-s.min.z):(u=s.min.x,h=s.min.y,p=s.max.x-s.min.x,m=s.max.y-s.min.y,g=1)),i!==null&&(a=i.x,c=i.y,l=i.z||0);let y=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),x=this.get(e).texture,_=this.get(t).texture;y.copyTextureToTexture({texture:x,mipLevel:n,origin:{x:u,y:h,z:d}},{texture:_,mipLevel:r,origin:{x:a,y:c,z:l}},[p,m,g]),this.device.queue.submit([y.finish()]),r===0&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,s){let i=this.get(t),n=null;t.renderTarget?e.isDepthTexture?n=this.get(t.depthTexture).texture:n=this.get(t.textures[0]).texture:e.isDepthTexture?n=this.textureUtils.getDepthBuffer(t.depth,t.stencil):n=this.context.getCurrentTexture();let r=this.get(e).texture;if(n.format!==r.format){O("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,r.format);return}let a;if(i.currentPass?(i.currentPass.end(),a=i.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),a.copyTextureToTexture({texture:n,origin:[s.x,s.y,0]},{texture:r},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e,a),i.currentPass){let{descriptor:c}=i;for(let l=0;l<c.colorAttachments.length;l++)c.colorAttachments[l].loadOp=ve.Load;t.depth&&(c.depthStencilAttachment.depthLoadOp=ve.Load),t.stencil&&(c.depthStencilAttachment.stencilLoadOp=ve.Load),i.currentPass=a.beginRenderPass(c),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else this.device.queue.submit([a.finish()])}hasCompatibility(e){return this._compatibility[Ys.TEXTURE_COMPARE]!==void 0?this._compatibility[Ys.TEXTURE_COMPARE]:super.hasCompatibility(e)}dispose(){if(this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(let e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}if(this.timestampQueryPool)for(let e of Object.values(this.timestampQueryPool))e!==null&&e.dispose();this.parameters.device===void 0&&this.device!==null&&this.device.destroy()}},$y=class extends zr{constructor(e,t,s,i,n,r){super(e,t,s,i,n,r),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}},qy=class extends zr{constructor(e,t,s,i,n,r){super(e,t,s,i,n,r),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}},Hy=class extends zh{constructor(){super(),this.addMaterial(wm,"MeshPhongMaterial"),this.addMaterial(Th,"MeshStandardMaterial"),this.addMaterial(Fm,"MeshPhysicalMaterial"),this.addMaterial(Pm,"MeshToonMaterial"),this.addMaterial(xc,"MeshBasicMaterial"),this.addMaterial(vm,"MeshLambertMaterial"),this.addMaterial(_m,"MeshNormalMaterial"),this.addMaterial(Dm,"MeshMatcapMaterial"),this.addMaterial(xm,"LineBasicMaterial"),this.addMaterial(bm,"LineDashedMaterial"),this.addMaterial(Um,"PointsMaterial"),this.addMaterial(Sh,"SpriteMaterial"),this.addMaterial(Vm,"ShadowMaterial"),this.addLight(Eg,ql),this.addLight(ey,Hl),this.addLight(ry,Yl),this.addLight(Nc,zr),this.addLight(Kg,Xl),this.addLight(ty,$l),this.addLight(iy,Zl),this.addLight(sy,$y),this.addLight(ny,qy),this.addToneMapping(fw,K0),this.addToneMapping(mw,eb),this.addToneMapping(gw,tb),this.addToneMapping(yw,sb),this.addToneMapping(xw,ib),this.addToneMapping(bw,nb)}},Kh=class extends fy{constructor(e={}){let t;e.forceWebGL?t=Jh:(t=Wy,e.getFallback=()=>(z("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Jh(e)));let s=new t(e);super(s,e),this.library=new Hy,this.isWebGPURenderer=!0,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}};var Xy=class{constructor(e,t=Z(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0;let s=new Ne;s.name="RenderPipeline",this._quadMesh=new Gi(s),this._quadMesh.name="Render Pipeline",this._context=null}render(){let e=this.renderer;this._update(),this._context.onBeforeRenderPipeline!==null&&this._context.onBeforeRenderPipeline();let t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=Ri,e.outputColorSpace=me.workingColorSpace;let i=e.xr.enabled;e.xr.enabled=!1,this._quadMesh.render(e),e.xr.enabled=i,e.toneMapping=t,e.outputColorSpace=s,this._context.onAfterRenderPipeline!==null&&this._context.onAfterRenderPipeline()}get context(){return this._context}dispose(){this._quadMesh.material.dispose()}_update(){if(this.needsUpdate===!0){let e=this.renderer,t=e.toneMapping,s=e.outputColorSpace,i={renderPipeline:this,onBeforeRenderPipeline:null,onAfterRenderPipeline:null},n=this.outputNode;this.outputColorTransform===!0?(n=n.context(i),n=Ix(n,t,s)):(i.toneMapping=t,i.outputColorSpace=s,n=n.context(i)),this._context=i,this._quadMesh.material.fragmentNode=n,this._quadMesh.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){_e('RenderPipeline: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.renderer.init(),this.render()}},ed=class extends Xy{constructor(e,t){_e('PostProcessing: "PostProcessing" has been renamed to "RenderPipeline". Please update your code to use "THREE.RenderPipeline" instead.'),super(e,t)}};var bD=f.BRDF_GGX,_D=f.BRDF_Lambert,TD=f.BasicPointShadowFilter,SD=f.BasicShadowFilter,vD=f.Break,wD=f.Const,MD=f.Continue,AD=f.DFGLUT,ND=f.D_GGX,RD=f.Discard,CD=f.EPSILON,ED=f.F_Schlick,Oc=f.Fn,BD=f.INFINITY,FD=f.If,e1=f.Loop,ID=f.NodeAccess,PD=f.NodeShaderStage,DD=f.NodeType,LD=f.NodeUpdateType,UD=f.PCFShadowFilter,OD=f.PCFSoftShadowFilter,VD=f.PI,kD=f.PI2,zD=f.TWO_PI,GD=f.HALF_PI,WD=f.PointShadowFilter,$D=f.Return,qD=f.Schlick_to_F0,HD=f.ShaderNode,XD=f.Stack,YD=f.Switch,jD=f.TBNViewMatrix,ZD=f.VSMShadowFilter,JD=f.V_GGX_SmithCorrelated,QD=f.Var,KD=f.VarIntent,y0=f.abs,e3=f.acesFilmicToneMapping,t3=f.acos,Nd=f.add,s3=f.addMethodChaining,i3=f.addNodeElement,n3=f.agxToneMapping,r3=f.all,o3=f.alphaT,a3=f.and,c3=f.anisotropy,l3=f.anisotropyB,u3=f.anisotropyT,h3=f.any,d3=f.append,p3=f.array,f3=f.arrayBuffer,m3=f.asin,g3=f.assign,y3=f.atan,x3=f.atomicAdd,b3=f.atomicAnd,_3=f.atomicFunc,T3=f.atomicLoad,S3=f.atomicMax,v3=f.atomicMin,w3=f.atomicOr,M3=f.atomicStore,A3=f.atomicSub,N3=f.atomicXor,R3=f.attenuationColor,C3=f.attenuationDistance,E3=f.attribute,B3=f.attributeArray,F3=f.backgroundBlurriness,I3=f.backgroundIntensity,P3=f.backgroundRotation,D3=f.batch,L3=f.bentNormalView,U3=f.billboarding,O3=f.bitAnd,V3=f.bitNot,k3=f.bitOr,z3=f.bitXor,G3=f.bitangentGeometry,W3=f.bitangentLocal,$3=f.bitangentView,q3=f.bitangentWorld,H3=f.bitcast,X3=f.blendBurn,Y3=f.blendColor,j3=f.blendDodge,Z3=f.blendOverlay,t1=f.blendScreen,J3=f.blur,Q3=f.bool,K3=f.buffer,eL=f.bufferAttribute,tL=f.bumpMap,sL=f.builtin,iL=f.builtinAOContext,nL=f.builtinShadowContext,rL=f.bvec2,oL=f.bvec3,aL=f.bvec4,cL=f.bypass,lL=f.cache,uL=f.call,hL=f.cameraFar,dL=f.cameraIndex,pL=f.cameraNear,fL=f.cameraNormalMatrix,mL=f.cameraPosition,gL=f.cameraProjectionMatrix,yL=f.cameraProjectionMatrixInverse,xL=f.cameraViewMatrix,bL=f.cameraViewport,_L=f.cameraWorldMatrix,TL=f.cbrt,SL=f.cdl,vL=f.ceil,wL=f.checker,ML=f.cineonToneMapping,AL=f.clamp,NL=f.clearcoat,RL=f.clearcoatNormalView,CL=f.clearcoatRoughness,EL=f.clipSpace,BL=f.code,FL=f.color,IL=f.colorSpaceToWorking,PL=f.colorToDirection,DL=f.compute,LL=f.computeKernel,UL=f.computeSkinning,OL=f.context,VL=f.convert,kL=f.convertColorSpace,zL=f.convertToTexture,GL=f.countLeadingZeros,WL=f.countOneBits,$L=f.countTrailingZeros,qL=f.cos,HL=f.cross,XL=f.cubeTexture,YL=f.cubeTextureBase,jL=f.dFdx,ZL=f.dFdy,JL=f.dashSize,QL=f.debug,KL=f.decrement,eU=f.decrementBefore,tU=f.defaultBuildStages,sU=f.defaultShaderStages,iU=f.defined,nU=f.degrees,rU=f.deltaTime,oU=f.densityFog,aU=f.densityFogFactor,cU=f.depth,lU=f.depthPass,uU=f.determinant,hU=f.difference,dU=f.diffuseColor,pU=f.directPointLight,fU=f.directionToColor,mU=f.directionToFaceDirection,gU=f.dispersion,yU=f.distance,xU=f.div,bU=f.dot,_U=f.drawIndex,TU=f.dynamicBufferAttribute,SU=f.element,vU=f.emissive,wU=f.equal,MU=f.equirectUV,AU=f.exp,NU=f.exp2,RU=f.exponentialHeightFogFactor,CU=f.expression,EU=f.faceDirection,BU=f.faceForward,FU=f.faceforward,An=f.float,IU=f.floatBitsToInt,PU=f.floatBitsToUint,DU=f.floor,LU=f.fog,UU=f.fract,OU=f.frameGroup,VU=f.frameId,kU=f.frontFacing,zU=f.fwidth,GU=f.gain,WU=f.gapSize,$U=f.getConstNodeType,qU=f.getCurrentStack,HU=f.getDirection,XU=f.getDistanceAttenuation,YU=f.getGeometryRoughness,jU=f.getNormalFromDepth,ZU=f.interleavedGradientNoise,JU=f.vogelDiskSample,QU=f.getParallaxCorrectNormal,KU=f.getRoughness,eO=f.getScreenPosition,tO=f.getShIrradianceAt,sO=f.getShadowMaterial,iO=f.getShadowRenderObjectFunction,nO=f.getTextureIndex,rO=f.getViewPosition,oO=f.globalId,aO=f.glsl,cO=f.glslFn,lO=f.grayscale,uO=f.greaterThan,hO=f.greaterThanEqual,dO=f.hash,pO=f.highpModelNormalViewMatrix,fO=f.highpModelViewMatrix,mO=f.hue,gO=f.increment,yO=f.incrementBefore,xO=f.instance,bO=f.instanceIndex,_O=f.instancedArray,TO=f.instancedBufferAttribute,SO=f.instancedDynamicBufferAttribute,vO=f.instancedMesh,x0=f.int,wO=f.intBitsToFloat,MO=f.inverse,AO=f.inverseSqrt,NO=f.inversesqrt,RO=f.invocationLocalIndex,CO=f.invocationSubgroupIndex,EO=f.ior,BO=f.iridescence,FO=f.iridescenceIOR,IO=f.iridescenceThickness,PO=f.ivec2,DO=f.ivec3,LO=f.ivec4,UO=f.js,OO=f.label,VO=f.length,kO=f.lengthSq,zO=f.lessThan,GO=f.lessThanEqual,WO=f.lightPosition,$O=f.lightProjectionUV,qO=f.lightShadowMatrix,HO=f.lightTargetDirection,XO=f.lightTargetPosition,YO=f.lightViewPosition,jO=f.lightingContext,ZO=f.lights,JO=f.linearDepth,QO=f.linearToneMapping,KO=f.localId,eV=f.log,tV=f.log2,sV=f.logarithmicDepthToViewZ,s1=f.luminance,iV=f.mat2,nV=f.mat3,rV=f.mat4,oV=f.matcapUV,aV=f.materialAO,cV=f.materialAlphaTest,lV=f.materialAnisotropy,uV=f.materialAnisotropyVector,hV=f.materialAttenuationColor,dV=f.materialAttenuationDistance,pV=f.materialClearcoat,fV=f.materialClearcoatNormal,mV=f.materialClearcoatRoughness,gV=f.materialColor,yV=f.materialDispersion,xV=f.materialEmissive,bV=f.materialEnvIntensity,_V=f.materialEnvRotation,TV=f.materialIOR,SV=f.materialIridescence,vV=f.materialIridescenceIOR,wV=f.materialIridescenceThickness,MV=f.materialLightMap,AV=f.materialLineDashOffset,NV=f.materialLineDashSize,RV=f.materialLineGapSize,CV=f.materialLineScale,EV=f.materialLineWidth,BV=f.materialMetalness,FV=f.materialNormal,IV=f.materialOpacity,PV=f.materialPointSize,DV=f.materialReference,LV=f.materialReflectivity,UV=f.materialRefractionRatio,OV=f.materialRotation,VV=f.materialRoughness,kV=f.materialSheen,zV=f.materialSheenRoughness,GV=f.materialShininess,WV=f.materialSpecular,$V=f.materialSpecularColor,qV=f.materialSpecularIntensity,HV=f.materialSpecularStrength,XV=f.materialThickness,YV=f.materialTransmission,jV=f.max,ZV=f.maxMipLevel,JV=f.mediumpModelViewMatrix,QV=f.metalness,KV=f.min,Vc=f.mix,ek=f.mixElement,i1=f.mod,tk=f.modInt,sk=f.modelDirection,ik=f.modelNormalMatrix,nk=f.modelPosition,rk=f.modelRadius,ok=f.modelScale,ak=f.modelViewMatrix,ck=f.modelViewPosition,lk=f.modelViewProjection,uk=f.modelWorldMatrix,hk=f.modelWorldMatrixInverse,dk=f.morphReference,pk=f.mrt,fk=f.mul,mk=f.mx_aastep,gk=f.mx_add,yk=f.mx_atan2,n1=f.mx_cell_noise_float,xk=f.mx_contrast,bk=f.mx_divide,_k=f.mx_fractal_noise_float,Tk=f.mx_fractal_noise_vec2,Sk=f.mx_fractal_noise_vec3,vk=f.mx_fractal_noise_vec4,wk=f.mx_frame,Mk=f.mx_heighttonormal,Ak=f.mx_hsvtorgb,Nk=f.mx_ifequal,Rk=f.mx_ifgreater,Ck=f.mx_ifgreatereq,Ek=f.mx_invert,Bk=f.mx_modulo,Fk=f.mx_multiply,Ik=f.mx_noise_float,Pk=f.mx_noise_vec3,Dk=f.mx_noise_vec4,Lk=f.mx_place2d,Uk=f.mx_power,Ok=f.mx_ramp4,Vk=f.mx_ramplr,kk=f.mx_ramptb,zk=f.mx_rgbtohsv,Gk=f.mx_rotate2d,Wk=f.mx_rotate3d,$k=f.mx_safepower,qk=f.mx_separate,Hk=f.mx_splitlr,Xk=f.mx_splittb,Yk=f.mx_srgb_texture_to_lin_rec709,jk=f.mx_subtract,Zk=f.mx_timer,Jk=f.mx_transform_uv,Qk=f.mx_unifiednoise2d,Kk=f.mx_unifiednoise3d,ez=f.mx_worley_noise_float,tz=f.mx_worley_noise_vec2,sz=f.mx_worley_noise_vec3,iz=f.negate,nz=f.neutralToneMapping,rz=f.nodeArray,oz=f.nodeImmutable,r1=f.nodeObject,az=f.nodeObjectIntent,cz=f.nodeObjects,lz=f.nodeProxy,uz=f.nodeProxyIntent,hz=f.normalFlat,dz=f.normalGeometry,pz=f.normalLocal,fz=f.normalMap,mz=f.normalView,gz=f.normalViewGeometry,yz=f.normalWorld,xz=f.normalWorldGeometry,bz=f.normalize,_z=f.not,Tz=f.notEqual,Sz=f.numWorkgroups,vz=f.objectDirection,wz=f.objectGroup,Mz=f.objectPosition,Az=f.objectRadius,Nz=f.objectScale,Rz=f.objectViewPosition,Cz=f.objectWorldMatrix,Ez=f.OnBeforeObjectUpdate,Bz=f.OnBeforeMaterialUpdate,Fz=f.OnObjectUpdate,Iz=f.OnMaterialUpdate,Rd=f.oneMinus,Pz=f.or,Dz=f.orthographicDepthToViewZ,Lz=f.oscSawtooth,Uz=f.oscSine,Oz=f.oscSquare,Vz=f.oscTriangle,kz=f.output,zz=f.outputStruct,Gz=f.overloadingFn,Wz=f.packHalf2x16,$z=f.packSnorm2x16,qz=f.packUnorm2x16,Hz=f.parabola,Xz=f.parallaxDirection,Yz=f.parallaxUV,jz=f.parameter,o1=f.pass,a1=f.passTexture,Zz=f.pcurve,Jz=f.perspectiveDepthToViewZ,Qz=f.pmremTexture,Kz=f.pointShadow,eG=f.pointUV,tG=f.pointWidth,sG=f.positionGeometry,iG=f.positionLocal,nG=f.positionPrevious,rG=f.positionView,oG=f.positionViewDirection,aG=f.positionWorld,cG=f.positionWorldDirection,lG=f.posterize,uG=f.pow,hG=f.pow2,dG=f.pow3,pG=f.pow4,fG=f.premultiplyAlpha,mG=f.property,gG=f.radians,yG=f.rand,xG=f.range,bG=f.rangeFog,_G=f.rangeFogFactor,TG=f.reciprocal,SG=f.reference,vG=f.referenceBuffer,wG=f.reflect,MG=f.reflectVector,AG=f.reflectView,NG=f.reflector,RG=f.refract,CG=f.refractVector,EG=f.refractView,BG=f.reinhardToneMapping,FG=f.remap,IG=f.remapClamp,PG=f.renderGroup,DG=f.renderOutput,LG=f.rendererReference,UG=f.replaceDefaultUV,OG=f.rotate,VG=f.rotateUV,kG=f.roughness,zG=f.round,GG=f.rtt,WG=f.sRGBTransferEOTF,$G=f.sRGBTransferOETF,qG=f.sample,HG=f.sampler,XG=f.samplerComparison,YG=f.saturate,jG=f.saturation,ZG=f.screen,JG=f.screenCoordinate,QG=f.screenDPR,KG=f.screenSize,e4=f.screenUV,t4=f.select,s4=f.setCurrentStack,i4=f.setName,n4=f.shaderStages,r4=f.shadow,o4=f.shadowPositionWorld,a4=f.shapeCircle,c4=f.sharedUniformGroup,l4=f.sheen,u4=f.sheenRoughness,h4=f.shiftLeft,d4=f.shiftRight,p4=f.shininess,f4=f.sign,m4=f.sin,g4=f.sinc,y4=f.skinning,yr=f.smoothstep,x4=f.smoothstepElement,b4=f.specularColor,_4=f.specularF90,T4=f.spherizeUV,S4=f.split,v4=f.spritesheetUV,w4=f.sqrt,M4=f.stack,A4=f.step,N4=f.stepElement,R4=f.storage,C4=f.storageBarrier,E4=f.storageTexture,B4=f.string,F4=f.struct,I4=f.sub,P4=f.subgroupAdd,D4=f.subgroupAll,L4=f.subgroupAnd,U4=f.subgroupAny,O4=f.subgroupBallot,V4=f.subgroupBroadcast,k4=f.subgroupBroadcastFirst,z4=f.subBuild,G4=f.subgroupElect,W4=f.subgroupExclusiveAdd,$4=f.subgroupExclusiveMul,q4=f.subgroupInclusiveAdd,H4=f.subgroupInclusiveMul,X4=f.subgroupIndex,Y4=f.subgroupMax,j4=f.subgroupMin,Z4=f.subgroupMul,J4=f.subgroupOr,Q4=f.subgroupShuffle,K4=f.subgroupShuffleDown,e5=f.subgroupShuffleUp,t5=f.subgroupShuffleXor,s5=f.subgroupSize,i5=f.subgroupXor,n5=f.tan,r5=f.tangentGeometry,o5=f.tangentLocal,a5=f.tangentView,c5=f.tangentWorld,Ls=f.texture,l5=f.texture3D,u5=f.textureBarrier,h5=f.textureBicubic,d5=f.textureBicubicLevel,p5=f.textureCubeUV,f5=f.textureLoad,m5=f.textureSize,g5=f.textureLevel,y5=f.textureStore,x5=f.thickness,b5=f.time,_5=f.toneMapping,T5=f.toneMappingExposure,S5=f.toonOutlinePass,v5=f.transformDirection,w5=f.transformNormal,M5=f.transformNormalToView,A5=f.transformedClearcoatNormalView,N5=f.transformedNormalView,R5=f.transformedNormalWorld,C5=f.transmission,E5=f.transpose,B5=f.triNoise3D,F5=f.triplanarTexture,I5=f.triplanarTextures,P5=f.trunc,D5=f.uint,L5=f.uintBitsToFloat,Us=f.uniform,Cd=f.uniformArray,U5=f.uniformCubeTexture,O5=f.uniformGroup,V5=f.uniformFlow,k5=f.uniformTexture,z5=f.unpackHalf2x16,G5=f.unpackSnorm2x16,W5=f.unpackUnorm2x16,$5=f.unpremultiplyAlpha,q5=f.userData,xr=f.uv,H5=f.uvec2,X5=f.uvec3,Y5=f.uvec4,j5=f.varying,Z5=f.varyingProperty,b0=f.vec2,_0=f.vec3,Nn=f.vec4,J5=f.vectorComponents,Q5=f.velocity,K5=f.vertexColor,eW=f.vertexIndex,tW=f.vertexStage,sW=f.vibrance,iW=f.viewZToLogarithmicDepth,nW=f.viewZToOrthographicDepth,rW=f.viewZToPerspectiveDepth,oW=f.viewZToReversedOrthographicDepth,aW=f.viewZToReversedPerspectiveDepth,cW=f.viewport,lW=f.viewportCoordinate,uW=f.viewportDepthTexture,hW=f.viewportLinearDepth,dW=f.viewportMipTexture,pW=f.viewportOpaqueMipTexture,fW=f.viewportResolution,mW=f.viewportSafeUV,gW=f.viewportSharedTexture,yW=f.viewportSize,xW=f.viewportTexture,bW=f.viewportUV,_W=f.wgsl,TW=f.wgslFn,SW=f.workgroupArray,vW=f.workgroupBarrier,wW=f.workgroupId,MW=f.workingToColorSpace,AW=f.xor;var Os=new Gi,hI=new re,dI=new re(1,0),pI=new re(0,1),T0,S0=class extends Be{static get type(){return"BloomNode"}constructor(e,t=1,s=0,i=0){super("vec4"),this.inputNode=e,this.strength=Us(t),this.radius=Us(s),this.threshold=Us(i),this.smoothWidth=Us(.01),this._renderTargetsHorizontal=[],this._renderTargetsVertical=[],this._nMips=5,this._renderTargetBright=new bt(1,1,{depthBuffer:!1,type:$e}),this._renderTargetBright.texture.name="UnrealBloomPass.bright",this._renderTargetBright.texture.generateMipmaps=!1;for(let n=0;n<this._nMips;n++){let r=new bt(1,1,{depthBuffer:!1,type:$e});r.texture.name="UnrealBloomPass.h"+n,r.texture.generateMipmaps=!1,this._renderTargetsHorizontal.push(r);let a=new bt(1,1,{depthBuffer:!1,type:$e});a.texture.name="UnrealBloomPass.v"+n,a.texture.generateMipmaps=!1,this._renderTargetsVertical.push(a)}this._compositeMaterial=null,this._highPassFilterMaterial=null,this._separableBlurMaterials=[],this._textureNodeBright=Ls(this._renderTargetBright.texture),this._textureNodeBlur0=Ls(this._renderTargetsVertical[0].texture),this._textureNodeBlur1=Ls(this._renderTargetsVertical[1].texture),this._textureNodeBlur2=Ls(this._renderTargetsVertical[2].texture),this._textureNodeBlur3=Ls(this._renderTargetsVertical[3].texture),this._textureNodeBlur4=Ls(this._renderTargetsVertical[4].texture),this._textureOutput=a1(this,this._renderTargetsHorizontal[0].texture),this.updateBeforeType=te.FRAME}getTextureNode(){return this._textureOutput}setSize(e,t){let s=Math.round(e/2),i=Math.round(t/2);this._renderTargetBright.setSize(s,i);for(let n=0;n<this._nMips;n++)this._renderTargetsHorizontal[n].setSize(s,i),this._renderTargetsVertical[n].setSize(s,i),this._separableBlurMaterials[n].invSize.value.set(1/s,1/i),s=Math.round(s/2),i=Math.round(i/2)}updateBefore(e){let{renderer:t}=e;T0=p0.resetRendererState(t,T0);let s=t.getDrawingBufferSize(hI);this.setSize(s.width,s.height),t.setRenderTarget(this._renderTargetBright),Os.material=this._highPassFilterMaterial,Os.name="Bloom [ High Pass ]",Os.render(t);let i=this._renderTargetBright;for(let n=0;n<this._nMips;n++)Os.material=this._separableBlurMaterials[n],this._separableBlurMaterials[n].colorTexture.value=i.texture,this._separableBlurMaterials[n].direction.value=dI,t.setRenderTarget(this._renderTargetsHorizontal[n]),Os.name=`Bloom [ Blur Horizontal - ${n} ]`,Os.render(t),this._separableBlurMaterials[n].colorTexture.value=this._renderTargetsHorizontal[n].texture,this._separableBlurMaterials[n].direction.value=pI,t.setRenderTarget(this._renderTargetsVertical[n]),Os.name=`Bloom [ Blur Vertical - ${n} ]`,Os.render(t),i=this._renderTargetsVertical[n];t.setRenderTarget(this._renderTargetsHorizontal[0]),Os.material=this._compositeMaterial,Os.name="Bloom [ Composite ]",Os.render(t),p0.restoreRendererState(t,T0)}setup(e){let t=Oc(()=>{let c=this.inputNode,l=s1(c.rgb),u=yr(this.threshold,this.threshold.add(this.smoothWidth),l);return Vc(Nn(0),c,u)});this._highPassFilterMaterial=this._highPassFilterMaterial||new Ne,this._highPassFilterMaterial.fragmentNode=t().context(e.getSharedContext()),this._highPassFilterMaterial.name="Bloom_highPass",this._highPassFilterMaterial.needsUpdate=!0;let s=[6,10,14,18,22];for(let c=0;c<this._nMips;c++)this._separableBlurMaterials.push(this._getSeparableBlurMaterial(e,s[c]));let i=Cd([1,.8,.6,.4,.2]),n=Cd([new R(1,1,1),new R(1,1,1),new R(1,1,1),new R(1,1,1),new R(1,1,1)]),r=Oc(([c,l])=>{let u=An(1.2).sub(c);return Vc(c,u,l)}).setLayout({name:"lerpBloomFactor",type:"float",inputs:[{name:"factor",type:"float"},{name:"radius",type:"float"}]}),a=Oc(()=>{let c=r(i.element(0),this.radius).mul(Nn(n.element(0),1)).mul(this._textureNodeBlur0),l=r(i.element(1),this.radius).mul(Nn(n.element(1),1)).mul(this._textureNodeBlur1),u=r(i.element(2),this.radius).mul(Nn(n.element(2),1)).mul(this._textureNodeBlur2),h=r(i.element(3),this.radius).mul(Nn(n.element(3),1)).mul(this._textureNodeBlur3),d=r(i.element(4),this.radius).mul(Nn(n.element(4),1)).mul(this._textureNodeBlur4);return c.add(l).add(u).add(h).add(d).mul(this.strength)});return this._compositeMaterial=this._compositeMaterial||new Ne,this._compositeMaterial.fragmentNode=a().context(e.getSharedContext()),this._compositeMaterial.name="Bloom_comp",this._compositeMaterial.needsUpdate=!0,this._textureOutput}dispose(){for(let e=0;e<this._renderTargetsHorizontal.length;e++)this._renderTargetsHorizontal[e].dispose();for(let e=0;e<this._renderTargetsVertical.length;e++)this._renderTargetsVertical[e].dispose();this._renderTargetBright.dispose(),this._highPassFilterMaterial!==null&&this._highPassFilterMaterial.dispose(),this._compositeMaterial!==null&&this._compositeMaterial.dispose();for(let e=0;e<this._separableBlurMaterials.length;e++)this._separableBlurMaterials[e].dispose()}_getSeparableBlurMaterial(e,t){let s=[],i=t/3;for(let p=0;p<t;p++)s.push(.39894*Math.exp(-.5*p*p/(i*i))/i);let n=Ls(null),r=Cd(s),a=Us(new re),c=Us(new re(.5,.5)),l=xr(),u=p=>n.sample(p),h=Oc(()=>{let p=u(l).rgb.mul(r.element(0)).toVar();return e1({start:x0(1),end:x0(t),type:"int",condition:"<"},({i:m})=>{let g=An(m),y=r.element(m),x=c.mul(a).mul(g),_=u(l.add(x)).rgb,w=u(l.sub(x)).rgb;p.addAssign(Nd(_,w).mul(y))}),Nn(p,1)}),d=new Ne;return d.fragmentNode=h().context(e.getSharedContext()),d.name="Bloom_separable",d.needsUpdate=!0,d.colorTexture=n,d.direction=c,d.invSize=a,d}},c1=(o,e,t,s)=>new S0(r1(o),e,t,s);var fI="https://i.postimg.cc/XYwvXN8D/img-4.png",mI="https://i.postimg.cc/2SHKQh2q/raw-4.webp",l1=300,u1=300,h1=.4;async function gI(){let o=document.getElementById("m3d-hero-canvas");if(!o)return;let e=new Kh({canvas:o,antialias:!1});await e.init(),e.setSize(o.offsetWidth,o.offsetHeight),e.setPixelRatio(Math.min(window.devicePixelRatio,2));let t=new On,s=new it(75,o.offsetWidth/o.offsetHeight,.1,1e3);s.position.z=5;let i=new ia,[n,r]=await Promise.all([i.loadAsync(fI),i.loadAsync(mI)]),a=Us(new re(0)),c=Us(0),l=Us(0),u=Ls(r),h=Ls(n,xr().add(u.r.mul(a).mul(.01))),d=An(l1).div(u1),p=b0(xr().x.mul(d),xr().y),m=b0(120),g=i1(p.mul(m),2).sub(1),y=n1(p.mul(m).div(2)),x=An(yr(.5,.49,An(g.length()))).mul(y),_=Rd(yr(0,.02,y0(u.sub(c)))),w=x.mul(_).mul(_0(10,0,0)),S=new xc({colorNode:t1(h,w),transparent:!0,opacity:0});function E(){let ae=s.fov*Math.PI/180,fe=2*Math.tan(ae/2)*Math.abs(s.position.z),Fe=fe*s.aspect,Gt=l1/u1,Vs=Fe/fe,Ed=Gt>Vs?Fe:fe*Gt,kc=Gt>Vs?Fe/Gt:fe;return[Ed*h1,kc*h1,1]}let B=new Zt(new Vr,S);B.scale.set(...E()),t.add(B);let N=new ed(e),I=o1(t,s).getTextureNode("output"),k=c1(I,1,.5,1),W=yr(0,An(.05),y0(xr().y.sub(l))),X=_0(1,0,0).mul(Rd(W)).mul(.4),Y=Vc(I,Nd(I,X),yr(.9,1,Rd(W)));N.outputNode=Y.add(k);let ee=new re(0);window.addEventListener("mousemove",ae=>{ee.x=ae.clientX/window.innerWidth*2-1,ee.y=-(ae.clientY/window.innerHeight*2-1)});function Q(){let ae=o.offsetWidth,fe=o.offsetHeight;e.setSize(ae,fe),s.aspect=ae/fe,s.updateProjectionMatrix(),B.scale.set(...E())}window.addEventListener("resize",Q),document.querySelectorAll(".m3d-hw").forEach((ae,fe)=>{let Fe=parseInt(ae.dataset.delay)||fe*600;setTimeout(()=>ae.classList.add("m3d-hw-visible"),Fe)});let ie=null,Pe=0;function Se(ae){ie||(ie=ae);let fe=(ae-ie)/1e3;c.value=Math.sin(fe*.5)*.5+.5,l.value=Math.sin(fe*.5)*.5+.5,a.value=ee,Pe=Va.lerp(Pe,1,.04),S.opacity=Pe,N.renderAsync().then(()=>requestAnimationFrame(Se))}requestAnimationFrame(Se)}gI().catch(o=>console.warn("[m3d-hero] WebGPU init failed:",o));
|
|
/*! Bundled license information:
|
|
|
|
three/build/three.core.js:
|
|
three/build/three.webgpu.js:
|
|
three/build/three.tsl.js:
|
|
(**
|
|
* @license
|
|
* Copyright 2010-2026 Three.js Authors
|
|
* SPDX-License-Identifier: MIT
|
|
*)
|
|
*/
|