| 123456 |
- /**
- * @license
- * Copyright 2010-2024 Three.js Authors
- * SPDX-License-Identifier: MIT
- */
- const t="170dev",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},s={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,n=2,o=3,a=0,h=1,u=2,l=3,c=0,d=1,p=2,m=0,g=1,f=2,y=3,x=4,b=5,v=100,T=101,_=102,w=103,S=104,M=200,A=201,N=202,C=203,R=204,E=205,B=206,I=207,P=208,F=209,U=210,O=211,z=212,L=213,V=214,D=0,k=1,G=2,W=3,j=4,H=5,$=6,q=7,X=0,Y=1,Z=2,J=0,K=1,Q=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,ut=302,lt=303,ct=304,dt=306,pt=1e3,mt=1001,gt=1002,ft=1003,yt=1004,xt=1004,bt=1005,vt=1005,Tt=1006,_t=1007,wt=1007,St=1008,Mt=1008,At=1009,Nt=1010,Ct=1011,Rt=1012,Et=1013,Bt=1014,It=1015,Pt=1016,Ft=1017,Ut=1018,Ot=1020,zt=35902,Lt=1021,Vt=1022,Dt=1023,kt=1024,Gt=1025,Wt=1026,jt=1027,Ht=1028,$t=1029,qt=1030,Xt=1031,Yt=1032,Zt=1033,Jt=33776,Kt=33777,Qt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,ue=37809,le=37810,ce=37811,de=37812,pe=37813,me=37814,ge=37815,fe=37816,ye=37817,xe=37818,be=37819,ve=37820,Te=37821,_e=36492,we=36494,Se=36495,Me=36283,Ae=36284,Ne=36285,Ce=36286,Re=2200,Ee=2201,Be=2202,Ie=2300,Pe=2301,Fe=2302,Ue=2400,Oe=2401,ze=2402,Le=2500,Ve=2501,De=0,ke=1,Ge=2,We=3200,je=3201,He=3202,$e=3203,qe=0,Xe=1,Ye="",Ze="srgb",Je="srgb-linear",Ke="linear",Qe="srgb",ts=0,es=7680,ss=7681,is=7682,rs=7683,ns=34055,os=34056,as=5386,hs=512,us=513,ls=514,cs=515,ds=516,ps=517,ms=518,gs=519,fs=512,ys=513,xs=514,bs=515,vs=516,Ts=517,_s=518,ws=519,Ss=35044,Ms=35048,As=35040,Ns=35045,Cs=35049,Rs=35041,Es=35046,Bs=35050,Is=35042,Ps="100",Fs="300 es",Us=2e3,Os=2001;class zs{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[t]&&-1!==s[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const s=this._listeners[t];if(void 0!==s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const s=e.slice(0);for(let e=0,i=s.length;e<i;e++)s[e].call(this,t);t.target=null}}}const Ls=["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"];let Vs=1234567;const Ds=Math.PI/180,ks=180/Math.PI;function Gs(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,s=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(Ls[255&t]+Ls[t>>8&255]+Ls[t>>16&255]+Ls[t>>24&255]+"-"+Ls[255&e]+Ls[e>>8&255]+"-"+Ls[e>>16&15|64]+Ls[e>>24&255]+"-"+Ls[63&s|128]+Ls[s>>8&255]+"-"+Ls[s>>16&255]+Ls[s>>24&255]+Ls[255&i]+Ls[i>>8&255]+Ls[i>>16&255]+Ls[i>>24&255]).toLowerCase()}function Ws(t,e,s){return Math.max(e,Math.min(s,t))}function js(t,e){return(t%e+e)%e}function Hs(t,e,s){return(1-s)*t+s*e}function $s(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function qs(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Xs={DEG2RAD:Ds,RAD2DEG:ks,generateUUID:Gs,clamp:Ws,euclideanModulo:js,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:Hs,damp:function(t,e,s,i){return Hs(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(js(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Vs=t);let e=Vs+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*Ds},radToDeg:function(t){return t*ks},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((e+i)/2),l=o((e+i)/2),c=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*l,h*c,h*d,a*u);break;case"YZY":t.set(h*d,a*l,h*c,a*u);break;case"ZXZ":t.set(h*c,h*d,a*l,a*u);break;case"XZX":t.set(a*l,h*m,h*p,a*u);break;case"YXY":t.set(h*p,a*l,h*m,a*u);break;case"ZYZ":t.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:qs,denormalize:$s};class Ys{constructor(t=0,e=0){Ys.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(Ws(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Zs{constructor(t,e,s,i,r,n,o,a,h){Zs.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const u=this.elements;return u[0]=t,u[1]=i,u[2]=o,u[3]=e,u[4]=r,u[5]=a,u[6]=s,u[7]=n,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],u=s[4],l=s[7],c=s[2],d=s[5],p=s[8],m=i[0],g=i[3],f=i[6],y=i[1],x=i[4],b=i[7],v=i[2],T=i[5],_=i[8];return r[0]=n*m+o*y+a*v,r[3]=n*g+o*x+a*T,r[6]=n*f+o*b+a*_,r[1]=h*m+u*y+l*v,r[4]=h*g+u*x+l*T,r[7]=h*f+u*b+l*_,r[2]=c*m+d*y+p*v,r[5]=c*g+d*x+p*T,r[8]=c*f+d*b+p*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8];return e*n*u-e*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=e*l+s*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(i*h-u*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(u*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(Js.makeScale(t,e)),this}rotate(t){return this.premultiply(Js.makeRotation(-t)),this}translate(t,e){return this.premultiply(Js.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const Js=new Zs;const Ks={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function Qs(t,e){return new Ks[t](e)}function ti(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ei(){const t=ti("canvas");return t.style.display="block",t}const si={};const ii={enabled:!0,workingColorSpace:Je,spaces:{},convert:function(t,e,s){return!1!==this.enabled&&e!==s&&e&&s?(this.spaces[e].transfer===Qe&&(t.r=ri(t.r),t.g=ri(t.g),t.b=ri(t.b)),this.spaces[e].primaries!==this.spaces[s].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[s].fromXYZ)),this.spaces[s].transfer===Qe&&(t.r=ni(t.r),t.g=ni(t.g),t.b=ni(t.b)),t):t},fromWorkingColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return t===Ye?Ke:this.spaces[t].transfer},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,s){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[s].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}};function ri(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function ni(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}const oi=[.64,.33,.3,.6,.15,.06],ai=[.2126,.7152,.0722],hi=[.3127,.329],ui=(new Zs).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),li=(new Zs).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);let ci;ii.define({[Je]:{primaries:oi,whitePoint:hi,transfer:Ke,toXYZ:ui,fromXYZ:li,luminanceCoefficients:ai,workingColorSpaceConfig:{unpackColorSpace:Ze},outputColorSpaceConfig:{drawingBufferColorSpace:Ze}},[Ze]:{primaries:oi,whitePoint:hi,transfer:Qe,toXYZ:ui,fromXYZ:li,luminanceCoefficients:ai,outputColorSpaceConfig:{drawingBufferColorSpace:Ze}}});class di{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===ci&&(ci=ti("canvas")),ci.width=t.width,ci.height=t.height;const s=ci.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=ci}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ti("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*ri(r[t]/255);return s.putImageData(i,0,0),e}if(t.data){const e=t.data.slice(0);for(let t=0;t<e.length;t++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[t]=Math.floor(255*ri(e[t]/255)):e[t]=ri(e[t]);return{data:e,width:t.width,height:t.height}}return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let pi=0;class mi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:pi++}),this.uuid=Gs(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){!0===t&&this.version++}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.images[this.uuid])return t.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,s=i.length;e<s;e++)i[e].isDataTexture?t.push(gi(i[e].image)):t.push(gi(i[e]))}else t=gi(i);s.url=t}return e||(t.images[this.uuid]=s),s}}function gi(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?di.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let fi=0;class yi extends zs{constructor(t=yi.DEFAULT_IMAGE,e=yi.DEFAULT_MAPPING,s=1001,i=1001,r=1006,n=1008,o=1023,a=1009,h=yi.DEFAULT_ANISOTROPY,u=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:fi++}),this.uuid=Gs(),this.name="",this.source=new mi(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=r,this.minFilter=n,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new Ys(0,0),this.repeat=new Ys(1,1),this.center=new Ys(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Zs,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const s={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,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),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case gt:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case gt:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}yi.DEFAULT_IMAGE=null,yi.DEFAULT_MAPPING=at,yi.DEFAULT_ANISOTROPY=1;class xi{constructor(t=0,e=0,s=0,i=1){xi.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],u=a[4],l=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(u-c)<n&&Math.abs(l-m)<n&&Math.abs(p-g)<n){if(Math.abs(u+c)<o&&Math.abs(l+m)<o&&Math.abs(p+g)<o&&Math.abs(h+d+f-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,y=(f+1)/2,x=(u+c)/4,b=(l+m)/4,v=(p+g)/4;return t>a&&t>y?t<n?(s=0,i=.707106781,r=.707106781):(s=Math.sqrt(t),i=x/s,r=b/s):a>y?a<n?(s=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),s=x/i,r=v/i):y<n?(s=.707106781,i=.707106781,r=0):(r=Math.sqrt(y),s=b/r,i=v/r),this.set(s,i,r,e),this}let y=Math.sqrt((g-p)*(g-p)+(l-m)*(l-m)+(c-u)*(c-u));return Math.abs(y)<.001&&(y=1),this.x=(g-p)/y,this.y=(l-m)/y,this.z=(c-u)/y,this.w=Math.acos((h+d+f-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}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}}class bi extends zs{constructor(t=1,e=1,s={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new xi(0,0,t,e),this.scissorTest=!1,this.viewport=new xi(0,0,t,e);const i={width:t,height:e,depth:1};s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Tt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},s);const r=new yi(i,s.mapping,s.wrapS,s.wrapT,s.magFilter,s.minFilter,s.format,s.type,s.anisotropy,s.colorSpace);r.flipY=!1,r.generateMipmaps=s.generateMipmaps,r.internalFormat=s.internalFormat,this.textures=[];const n=s.count;for(let t=0;t<n;t++)this.textures[t]=r.clone(),this.textures[t].isRenderTargetTexture=!0;this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this.depthTexture=s.depthTexture,this.samples=s.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,s=1){if(this.width!==t||this.height!==e||this.depth!==s){this.width=t,this.height=e,this.depth=s;for(let i=0,r=this.textures.length;i<r;i++)this.textures[i].image.width=t,this.textures[i].image.height=e,this.textures[i].image.depth=s;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let e=0,s=t.textures.length;e<s;e++)this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new mi(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,null!==t.depthTexture&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class vi extends bi{constructor(t=1,e=1,s={}){super(t,e,s),this.isWebGLRenderTarget=!0}}class Ti extends yi{constructor(t=null,e=1,s=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:s,depth:i},this.magFilter=ft,this.minFilter=ft,this.wrapR=mt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class _i extends vi{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGLArrayRenderTarget=!0,this.depth=s,this.texture=new Ti(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class wi extends yi{constructor(t=null,e=1,s=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:s,depth:i},this.magFilter=ft,this.minFilter=ft,this.wrapR=mt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Si extends vi{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGL3DRenderTarget=!0,this.depth=s,this.texture=new wi(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class Mi{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let a=s[i+0],h=s[i+1],u=s[i+2],l=s[i+3];const c=r[n+0],d=r[n+1],p=r[n+2],m=r[n+3];if(0===o)return t[e+0]=a,t[e+1]=h,t[e+2]=u,void(t[e+3]=l);if(1===o)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=m);if(l!==m||a!==c||h!==d||u!==p){let t=1-o;const e=a*c+h*d+u*p+l*m,s=e>=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+c*r,h=h*t+d*r,u=u*t+p*r,l=l*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=t,h*=t,u*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=u,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],u=s[i+3],l=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+u*l+a*d-h*c,t[e+1]=a*p+u*c+h*l-o*d,t[e+2]=h*p+u*d+o*c-a*l,t[e+3]=u*p-o*l-a*c-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),u=o(i/2),l=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"YXZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"ZXY":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"ZYX":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"YZX":this._x=c*u*l+h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l-c*d*p;break;case"XZY":this._x=c*u*l-h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],u=e[6],l=e[10],c=s+o+l;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(u-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(u-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+u)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+u)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Ws(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,u=e._w;return this._x=s*u+n*o+i*h-r*a,this._y=i*u+n*a+r*o-s*h,this._z=r*u+n*h+s*a-i*o,this._w=n*u-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-e)*u)/h,c=Math.sin(e*u)/h;return this._w=n*l+this._w*c,this._x=s*l+this._x*c,this._y=i*l+this._y*c,this._z=r*l+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Ai{constructor(t=0,e=0,s=0){Ai.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ci.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ci.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),u=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*u,this.y=s+a*u+o*h-r*l,this.z=i+a*l+r*u-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Ni.copy(this).projectOnVector(t),this.sub(Ni)}reflect(t){return this.sub(Ni.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(Ws(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ni=new Ai,Ci=new Mi;class Ri{constructor(t=new Ai(1/0,1/0,1/0),e=new Ai(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e+=3)this.expandByPoint(Bi.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Bi.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Bi.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.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(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const s=t.geometry;if(void 0!==s){const i=s.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,s=i.count;e<s;e++)!0===t.isMesh?t.getVertexPosition(e,Bi):Bi.fromBufferAttribute(i,e),Bi.applyMatrix4(t.matrixWorld),this.expandByPoint(Bi);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),Ii.copy(t.boundingBox)):(null===s.boundingBox&&s.computeBoundingBox(),Ii.copy(s.boundingBox)),Ii.applyMatrix4(t.matrixWorld),this.union(Ii)}const i=t.children;for(let t=0,s=i.length;t<s;t++)this.expandByObject(i[t],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Bi),Bi.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Vi),Di.subVectors(this.max,Vi),Pi.subVectors(t.a,Vi),Fi.subVectors(t.b,Vi),Ui.subVectors(t.c,Vi),Oi.subVectors(Fi,Pi),zi.subVectors(Ui,Fi),Li.subVectors(Pi,Ui);let e=[0,-Oi.z,Oi.y,0,-zi.z,zi.y,0,-Li.z,Li.y,Oi.z,0,-Oi.x,zi.z,0,-zi.x,Li.z,0,-Li.x,-Oi.y,Oi.x,0,-zi.y,zi.x,0,-Li.y,Li.x,0];return!!Wi(e,Pi,Fi,Ui,Di)&&(e=[1,0,0,0,1,0,0,0,1],!!Wi(e,Pi,Fi,Ui,Di)&&(ki.crossVectors(Oi,zi),e=[ki.x,ki.y,ki.z],Wi(e,Pi,Fi,Ui,Di)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Bi).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Bi).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Ei[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ei[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ei[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ei[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ei[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ei[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ei[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ei[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ei)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Ei=[new Ai,new Ai,new Ai,new Ai,new Ai,new Ai,new Ai,new Ai],Bi=new Ai,Ii=new Ri,Pi=new Ai,Fi=new Ai,Ui=new Ai,Oi=new Ai,zi=new Ai,Li=new Ai,Vi=new Ai,Di=new Ai,ki=new Ai,Gi=new Ai;function Wi(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){Gi.fromArray(t,n);const o=r.x*Math.abs(Gi.x)+r.y*Math.abs(Gi.y)+r.z*Math.abs(Gi.z),a=e.dot(Gi),h=s.dot(Gi),u=i.dot(Gi);if(Math.max(-Math.max(a,h,u),Math.min(a,h,u))>o)return!1}return!0}const ji=new Ri,Hi=new Ai,$i=new Ai;class qi{constructor(t=new Ai,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;void 0!==e?s.copy(e):ji.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;e<r;e++)i=Math.max(i,s.distanceToSquared(t[e]));return this.radius=Math.sqrt(i),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const s=this.center.distanceToSquared(t);return e.copy(t),s>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Hi.subVectors(t,this.center);const e=Hi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Hi,s/t),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):($i.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Hi.copy(t.center).add($i)),this.expandByPoint(Hi.copy(t.center).sub($i))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Xi=new Ai,Yi=new Ai,Zi=new Ai,Ji=new Ai,Ki=new Ai,Qi=new Ai,tr=new Ai;class er{constructor(t=new Ai,e=new Ai(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,Xi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Xi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Xi.copy(this.origin).addScaledVector(this.direction,e),Xi.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Yi.copy(t).add(e).multiplyScalar(.5),Zi.copy(e).sub(t).normalize(),Ji.copy(this.origin).sub(Yi);const r=.5*t.distanceTo(e),n=-this.direction.dot(Zi),o=Ji.dot(this.direction),a=-Ji.dot(Zi),h=Ji.lengthSq(),u=Math.abs(1-n*n);let l,c,d,p;if(u>0)if(l=n*a-o,c=n*o-a,p=r*u,l>=0)if(c>=-p)if(c<=p){const t=1/u;l*=t,c*=t,d=l*(l+n*c+2*o)+c*(n*l+c+2*a)+h}else c=r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c=-r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c<=-p?(l=Math.max(0,-(-n*r+o)),c=l>0?-r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h):c<=p?(l=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(l=Math.max(0,-(n*r+o)),c=l>0?r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h);else c=n>0?-r:r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,l),i&&i.copy(Yi).addScaledVector(Zi,c),d}intersectSphere(t,e){Xi.subVectors(t.center,this.origin);const s=Xi.dot(this.direction),i=Xi.dot(Xi)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,o,a;const h=1/this.direction.x,u=1/this.direction.y,l=1/this.direction.z,c=this.origin;return h>=0?(s=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(s=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),u>=0?(r=(t.min.y-c.y)*u,n=(t.max.y-c.y)*u):(r=(t.max.y-c.y)*u,n=(t.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),l>=0?(o=(t.min.z-c.z)*l,a=(t.max.z-c.z)*l):(o=(t.max.z-c.z)*l,a=(t.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(s>=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,Xi)}intersectTriangle(t,e,s,i,r){Ki.subVectors(e,t),Qi.subVectors(s,t),tr.crossVectors(Ki,Qi);let n,o=this.direction.dot(tr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}Ji.subVectors(this.origin,t);const a=n*this.direction.dot(Qi.crossVectors(Ji,Qi));if(a<0)return null;const h=n*this.direction.dot(Ki.cross(Ji));if(h<0)return null;if(a+h>o)return null;const u=-n*Ji.dot(tr);return u<0?null:this.at(u/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class sr{constructor(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){sr.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=u,f[10]=l,f[14]=c,f[3]=d,f[7]=p,f[11]=m,f[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new sr).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/ir.setFromMatrixColumn(t,0).length(),r=1/ir.setFromMatrixColumn(t,1).length(),n=1/ir.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),u=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*u,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*u,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*u,e[9]=-o*u,e[2]=-h*u,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=-l,e[8]=h*u,e[1]=t*l+r,e[5]=n*u,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*u,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(nr,t,or)}lookAt(t,e,s){const i=this.elements;return ur.subVectors(t,e),0===ur.lengthSq()&&(ur.z=1),ur.normalize(),ar.crossVectors(s,ur),0===ar.lengthSq()&&(1===Math.abs(s.z)?ur.x+=1e-4:ur.z+=1e-4,ur.normalize(),ar.crossVectors(s,ur)),ar.normalize(),hr.crossVectors(ur,ar),i[0]=ar.x,i[4]=hr.x,i[8]=ur.x,i[1]=ar.y,i[5]=hr.y,i[9]=ur.y,i[2]=ar.z,i[6]=hr.z,i[10]=ur.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],u=s[1],l=s[5],c=s[9],d=s[13],p=s[2],m=s[6],g=s[10],f=s[14],y=s[3],x=s[7],b=s[11],v=s[15],T=i[0],_=i[4],w=i[8],S=i[12],M=i[1],A=i[5],N=i[9],C=i[13],R=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],U=i[11],O=i[15];return r[0]=n*T+o*M+a*R+h*P,r[4]=n*_+o*A+a*E+h*F,r[8]=n*w+o*N+a*B+h*U,r[12]=n*S+o*C+a*I+h*O,r[1]=u*T+l*M+c*R+d*P,r[5]=u*_+l*A+c*E+d*F,r[9]=u*w+l*N+c*B+d*U,r[13]=u*S+l*C+c*I+d*O,r[2]=p*T+m*M+g*R+f*P,r[6]=p*_+m*A+g*E+f*F,r[10]=p*w+m*N+g*B+f*U,r[14]=p*S+m*C+g*I+f*O,r[3]=y*T+x*M+b*R+v*P,r[7]=y*_+x*A+b*E+v*F,r[11]=y*w+x*N+b*B+v*U,r[15]=y*S+x*C+b*I+v*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],u=t[2],l=t[6],c=t[10],d=t[14];return t[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+t[11]*(+e*h*l-e*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+t[15]*(-i*o*u-e*a*l+e*o*c+i*n*l-s*n*c+s*a*u)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=l*g*h-m*c*h+m*a*d-o*g*d-l*a*f+o*c*f,x=p*c*h-u*g*h-p*a*d+n*g*d+u*a*f-n*c*f,b=u*m*h-p*l*h+p*o*d-n*m*d-u*o*f+n*l*f,v=p*l*a-u*m*a-p*o*c+n*m*c+u*o*g-n*l*g,T=e*y+s*x+i*b+r*v;if(0===T)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/T;return t[0]=y*_,t[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,t[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,t[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(u*g*r-p*c*r+p*i*d-e*g*d-u*i*f+e*c*f)*_,t[6]=(p*a*r-n*g*r-p*i*h+e*g*h+n*i*f-e*a*f)*_,t[7]=(n*c*r-u*a*r+u*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*l*r-u*m*r-p*s*d+e*m*d+u*s*f-e*l*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(u*o*r-n*l*r-u*s*h+e*l*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(u*m*i-p*l*i+p*s*c-e*m*c-u*s*g+e*l*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*l*i-u*o*i+u*s*a-e*l*a-n*s*c+e*o*c)*_,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,u=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,u*o+s,u*a-i*n,0,h*a-i*o,u*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,u=n+n,l=o+o,c=r*h,d=r*u,p=r*l,m=n*u,g=n*l,f=o*l,y=a*h,x=a*u,b=a*l,v=s.x,T=s.y,_=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*T,i[5]=(1-(c+f))*T,i[6]=(g+y)*T,i[7]=0,i[8]=(p+x)*_,i[9]=(g-y)*_,i[10]=(1-(c+m))*_,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=ir.set(i[0],i[1],i[2]).length();const n=ir.set(i[4],i[5],i[6]).length(),o=ir.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],rr.copy(this);const a=1/r,h=1/n,u=1/o;return rr.elements[0]*=a,rr.elements[1]*=a,rr.elements[2]*=a,rr.elements[4]*=h,rr.elements[5]*=h,rr.elements[6]*=h,rr.elements[8]*=u,rr.elements[9]*=u,rr.elements[10]*=u,e.setFromRotationMatrix(rr),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),u=2*r/(s-i),l=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===Us)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Os)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=l,a[12]=0,a[1]=0,a[5]=u,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),u=1/(s-i),l=1/(n-r),c=(e+t)*h,d=(s+i)*u;let p,m;if(o===Us)p=(n+r)*l,m=-2*l;else{if(o!==Os)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*l,m=-1*l}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*u,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const ir=new Ai,rr=new sr,nr=new Ai(0,0,0),or=new Ai(1,1,1),ar=new Ai,hr=new Ai,ur=new Ai,lr=new sr,cr=new Mi;class dr{constructor(t=0,e=0,s=0,i=dr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],u=i[9],l=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Ws(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-Ws(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(Ws(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-Ws(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(Ws(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-Ws(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return lr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(lr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return cr.setFromEuler(this),this.setFromQuaternion(cr,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}dr.DEFAULT_ORDER="XYZ";class pr{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return 0!=(this.mask&t.mask)}isEnabled(t){return 0!=(this.mask&(1<<t|0))}}let mr=0;const gr=new Ai,fr=new Mi,yr=new sr,xr=new Ai,br=new Ai,vr=new Ai,Tr=new Mi,_r=new Ai(1,0,0),wr=new Ai(0,1,0),Sr=new Ai(0,0,1),Mr={type:"added"},Ar={type:"removed"},Nr={type:"childadded",child:null},Cr={type:"childremoved",child:null};class Rr extends zs{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:mr++}),this.uuid=Gs(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Rr.DEFAULT_UP.clone();const t=new Ai,e=new dr,s=new Mi,i=new Ai(1,1,1);e._onChange((function(){s.setFromEuler(e,!1)})),s._onChange((function(){e.setFromQuaternion(s,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new sr},normalMatrix:{value:new Zs}}),this.matrix=new sr,this.matrixWorld=new sr,this.matrixAutoUpdate=Rr.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Rr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new pr,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return fr.setFromAxisAngle(t,e),this.quaternion.multiply(fr),this}rotateOnWorldAxis(t,e){return fr.setFromAxisAngle(t,e),this.quaternion.premultiply(fr),this}rotateX(t){return this.rotateOnAxis(_r,t)}rotateY(t){return this.rotateOnAxis(wr,t)}rotateZ(t){return this.rotateOnAxis(Sr,t)}translateOnAxis(t,e){return gr.copy(t).applyQuaternion(this.quaternion),this.position.add(gr.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(_r,t)}translateY(t){return this.translateOnAxis(wr,t)}translateZ(t){return this.translateOnAxis(Sr,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(yr.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?xr.copy(t):xr.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),br.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?yr.lookAt(br,xr,this.up):yr.lookAt(xr,br,this.up),this.quaternion.setFromRotationMatrix(yr),i&&(yr.extractRotation(i.matrixWorld),fr.setFromRotationMatrix(yr),this.quaternion.premultiply(fr.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Mr),Nr.child=t,this.dispatchEvent(Nr),Nr.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Ar),Cr.child=t,this.dispatchEvent(Cr),Cr.child=null),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),yr.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),yr.multiply(t.parent.matrixWorld)),t.applyMatrix4(yr),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Mr),Nr.child=t,this.dispatchEvent(Nr),Nr.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let s=0,i=this.children.length;s<i;s++){const i=this.children[s].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(br,t,vr),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(br,Tr,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,i=e.length;s<i;s++){e[s].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const s=this.parent;if(!0===t&&null!==s&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),!0===e){const t=this.children;for(let e=0,s=t.length;e<s;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,s){return void 0===e[s.uuid]&&(e[s.uuid]=s.toJSON(t)),s.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),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(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e<i;e++){const i=s[e];r(t.shapes,i)}else r(t.shapes,s)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(r(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let s=0,i=this.material.length;s<i;s++)e.push(r(t.materials,this.material[s]));i.material=e}else i.material=r(t.materials,this.material);if(this.children.length>0){i.children=[];for(let e=0;e<this.children.length;e++)i.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let e=0;e<this.animations.length;e++){const s=this.animations[e];i.animations.push(r(t.animations,s))}}if(e){const e=n(t.geometries),i=n(t.materials),r=n(t.textures),o=n(t.images),a=n(t.shapes),h=n(t.skeletons),u=n(t.animations),l=n(t.nodes);e.length>0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),u.length>0&&(s.animations=u),l.length>0&&(s.nodes=l)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e<t.children.length;e++){const s=t.children[e];this.add(s.clone())}return this}}Rr.DEFAULT_UP=new Ai(0,1,0),Rr.DEFAULT_MATRIX_AUTO_UPDATE=!0,Rr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Er=new Ai,Br=new Ai,Ir=new Ai,Pr=new Ai,Fr=new Ai,Ur=new Ai,Or=new Ai,zr=new Ai,Lr=new Ai,Vr=new Ai,Dr=new xi,kr=new xi,Gr=new xi;class Wr{constructor(t=new Ai,e=new Ai,s=new Ai){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),Er.subVectors(t,e),i.cross(Er);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Er.subVectors(i,e),Br.subVectors(s,e),Ir.subVectors(t,e);const n=Er.dot(Er),o=Er.dot(Br),a=Er.dot(Ir),h=Br.dot(Br),u=Br.dot(Ir),l=n*h-o*o;if(0===l)return r.set(0,0,0),null;const c=1/l,d=(h*a-o*u)*c,p=(n*u-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,Pr)&&(Pr.x>=0&&Pr.y>=0&&Pr.x+Pr.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Pr)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,Pr.x),a.addScaledVector(n,Pr.y),a.addScaledVector(o,Pr.z),a)}static getInterpolatedAttribute(t,e,s,i,r,n){return Dr.setScalar(0),kr.setScalar(0),Gr.setScalar(0),Dr.fromBufferAttribute(t,e),kr.fromBufferAttribute(t,s),Gr.fromBufferAttribute(t,i),n.setScalar(0),n.addScaledVector(Dr,r.x),n.addScaledVector(kr,r.y),n.addScaledVector(Gr,r.z),n}static isFrontFacing(t,e,s,i){return Er.subVectors(s,e),Br.subVectors(t,e),Er.cross(Br).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Er.subVectors(this.c,this.b),Br.subVectors(this.a,this.b),.5*Er.cross(Br).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Wr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Wr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return Wr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return Wr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Wr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;Fr.subVectors(i,s),Ur.subVectors(r,s),zr.subVectors(t,s);const a=Fr.dot(zr),h=Ur.dot(zr);if(a<=0&&h<=0)return e.copy(s);Lr.subVectors(t,i);const u=Fr.dot(Lr),l=Ur.dot(Lr);if(u>=0&&l<=u)return e.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),e.copy(s).addScaledVector(Fr,n);Vr.subVectors(t,r);const d=Fr.dot(Vr),p=Ur.dot(Vr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Ur,o);const g=u*p-d*l;if(g<=0&&l-u>=0&&d-p>=0)return Or.subVectors(r,i),o=(l-u)/(l-u+(d-p)),e.copy(i).addScaledVector(Or,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(Fr,n).addScaledVector(Ur,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const jr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Hr={h:0,s:0,l:0},$r={h:0,s:0,l:0};function qr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class Xr{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Ze){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,ii.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=ii.workingColorSpace){return this.r=t,this.g=e,this.b=s,ii.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=ii.workingColorSpace){if(t=js(t,1),e=Ws(e,0,1),s=Ws(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=qr(r,i,t+1/3),this.g=qr(r,i,t),this.b=qr(r,i,t-1/3)}return ii.toWorkingColorSpace(this,i),this}setStyle(t,e=Ze){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Ze){const s=jr[t.toLowerCase()];return void 0!==s?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=ri(t.r),this.g=ri(t.g),this.b=ri(t.b),this}copyLinearToSRGB(t){return this.r=ni(t.r),this.g=ni(t.g),this.b=ni(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Ze){return ii.fromWorkingColorSpace(Yr.copy(this),t),65536*Math.round(Ws(255*Yr.r,0,255))+256*Math.round(Ws(255*Yr.g,0,255))+Math.round(Ws(255*Yr.b,0,255))}getHexString(t=Ze){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ii.workingColorSpace){ii.fromWorkingColorSpace(Yr.copy(this),e);const s=Yr.r,i=Yr.g,r=Yr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const u=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=u<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i<r?6:0);break;case i:a=(r-s)/t+2;break;case r:a=(s-i)/t+4}a/=6}return t.h=a,t.s=h,t.l=u,t}getRGB(t,e=ii.workingColorSpace){return ii.fromWorkingColorSpace(Yr.copy(this),e),t.r=Yr.r,t.g=Yr.g,t.b=Yr.b,t}getStyle(t=Ze){ii.fromWorkingColorSpace(Yr.copy(this),t);const e=Yr.r,s=Yr.g,i=Yr.b;return t!==Ze?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*s)},${Math.round(255*i)})`}offsetHSL(t,e,s){return this.getHSL(Hr),this.setHSL(Hr.h+t,Hr.s+e,Hr.l+s)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(Hr),t.getHSL($r);const s=Hs(Hr.h,$r.h,e),i=Hs(Hr.s,$r.s,e),r=Hs(Hr.l,$r.l,e);return this.setHSL(s,i,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,s=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*s+r[6]*i,this.g=r[1]*e+r[4]*s+r[7]*i,this.b=r[2]*e+r[5]*s+r[8]*i,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Yr=new Xr;Xr.NAMES=jr;let Zr=0;class Jr extends zs{static get type(){return"Material"}get type(){return this.constructor.type}set type(t){}constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Zr++}),this.uuid=Gs(),this.name="",this.blending=1,this.side=c,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=R,this.blendDst=E,this.blendEquation=v,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Xr(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=gs,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=es,this.stencilZFail=es,this.stencilZPass=es,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.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==c&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),this.blendSrc!==R&&(s.blendSrc=this.blendSrc),this.blendDst!==E&&(s.blendDst=this.blendDst),this.blendEquation!==v&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==gs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==es&&(s.stencilFail=this.stencilFail),this.stencilZFail!==es&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==es&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class Kr extends Jr{static get type(){return"MeshBasicMaterial"}constructor(t){super(),this.isMeshBasicMaterial=!0,this.color=new Xr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Qr=tn();function tn(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function en(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=Ws(t,-65504,65504),Qr.floatView[0]=t;const e=Qr.uint32View[0],s=e>>23&511;return Qr.baseTable[s]+((8388607&e)>>Qr.shiftTable[s])}function sn(t){const e=t>>10;return Qr.uint32View[0]=Qr.mantissaTable[Qr.offsetTable[e]+(1023&t)]+Qr.exponentTable[e],Qr.floatView[0]}const rn={toHalfFloat:en,fromHalfFloat:sn},nn=new Ai,on=new Ys;class an{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=s,this.usage=Ss,this.updateRanges=[],this.gpuType=It,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[s+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,s=this.count;e<s;e++)on.fromBufferAttribute(this,e),on.applyMatrix3(t),this.setXY(e,on.x,on.y);else if(3===this.itemSize)for(let e=0,s=this.count;e<s;e++)nn.fromBufferAttribute(this,e),nn.applyMatrix3(t),this.setXYZ(e,nn.x,nn.y,nn.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)nn.fromBufferAttribute(this,e),nn.applyMatrix4(t),this.setXYZ(e,nn.x,nn.y,nn.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)nn.fromBufferAttribute(this,e),nn.applyNormalMatrix(t),this.setXYZ(e,nn.x,nn.y,nn.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)nn.fromBufferAttribute(this,e),nn.transformDirection(t),this.setXYZ(e,nn.x,nn.y,nn.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=$s(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=qs(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=$s(e,this.array)),e}setX(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=$s(e,this.array)),e}setY(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=$s(e,this.array)),e}setZ(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=$s(e,this.array)),e}setW(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array),r=qs(r,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),this.usage!==Ss&&(t.usage=this.usage),t}}class hn extends an{constructor(t,e,s){super(new Int8Array(t),e,s)}}class un extends an{constructor(t,e,s){super(new Uint8Array(t),e,s)}}class ln extends an{constructor(t,e,s){super(new Uint8ClampedArray(t),e,s)}}class cn extends an{constructor(t,e,s){super(new Int16Array(t),e,s)}}class dn extends an{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class pn extends an{constructor(t,e,s){super(new Int32Array(t),e,s)}}class mn extends an{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class gn extends an{constructor(t,e,s){super(new Uint16Array(t),e,s),this.isFloat16BufferAttribute=!0}getX(t){let e=sn(this.array[t*this.itemSize]);return this.normalized&&(e=$s(e,this.array)),e}setX(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize]=en(e),this}getY(t){let e=sn(this.array[t*this.itemSize+1]);return this.normalized&&(e=$s(e,this.array)),e}setY(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+1]=en(e),this}getZ(t){let e=sn(this.array[t*this.itemSize+2]);return this.normalized&&(e=$s(e,this.array)),e}setZ(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+2]=en(e),this}getW(t){let e=sn(this.array[t*this.itemSize+3]);return this.normalized&&(e=$s(e,this.array)),e}setW(t,e){return this.normalized&&(e=qs(e,this.array)),this.array[t*this.itemSize+3]=en(e),this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array)),this.array[t+0]=en(e),this.array[t+1]=en(s),this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array)),this.array[t+0]=en(e),this.array[t+1]=en(s),this.array[t+2]=en(i),this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array),r=qs(r,this.array)),this.array[t+0]=en(e),this.array[t+1]=en(s),this.array[t+2]=en(i),this.array[t+3]=en(r),this}}class fn extends an{constructor(t,e,s){super(new Float32Array(t),e,s)}}let yn=0;const xn=new sr,bn=new Rr,vn=new Ai,Tn=new Ri,_n=new Ri,wn=new Ai;class Sn extends zs{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:yn++}),this.uuid=Gs(),this.name="",this.type="BufferGeometry",this.index=null,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(t){return Array.isArray(t)?this.index=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(t)?mn:dn)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const e=(new Zs).getNormalMatrix(t);s.applyNormalMatrix(e),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return xn.makeRotationFromQuaternion(t),this.applyMatrix4(xn),this}rotateX(t){return xn.makeRotationX(t),this.applyMatrix4(xn),this}rotateY(t){return xn.makeRotationY(t),this.applyMatrix4(xn),this}rotateZ(t){return xn.makeRotationZ(t),this.applyMatrix4(xn),this}translate(t,e,s){return xn.makeTranslation(t,e,s),this.applyMatrix4(xn),this}scale(t,e,s){return xn.makeScale(t,e,s),this.applyMatrix4(xn),this}lookAt(t){return bn.lookAt(t),bn.updateMatrix(),this.applyMatrix4(bn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(vn).negate(),this.translate(vn.x,vn.y,vn.z),this}setFromPoints(t){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s];e.push(i.x,i.y,i.z||0)}return this.setAttribute("position",new fn(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Ri);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Ai(-1/0,-1/0,-1/0),new Ai(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];Tn.setFromBufferAttribute(s),this.morphTargetsRelative?(wn.addVectors(this.boundingBox.min,Tn.min),this.boundingBox.expandByPoint(wn),wn.addVectors(this.boundingBox.max,Tn.max),this.boundingBox.expandByPoint(wn)):(this.boundingBox.expandByPoint(Tn.min),this.boundingBox.expandByPoint(Tn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new qi);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new Ai,1/0);if(t){const s=this.boundingSphere.center;if(Tn.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];_n.setFromBufferAttribute(s),this.morphTargetsRelative?(wn.addVectors(Tn.min,_n.min),Tn.expandByPoint(wn),wn.addVectors(Tn.max,_n.max),Tn.expandByPoint(wn)):(Tn.expandByPoint(_n.min),Tn.expandByPoint(_n.max))}Tn.getCenter(s);let i=0;for(let e=0,r=t.count;e<r;e++)wn.fromBufferAttribute(t,e),i=Math.max(i,s.distanceToSquared(wn));if(e)for(let r=0,n=e.length;r<n;r++){const n=e[r],o=this.morphTargetsRelative;for(let e=0,r=n.count;e<r;e++)wn.fromBufferAttribute(n,e),o&&(vn.fromBufferAttribute(t,e),wn.add(vn)),i=Math.max(i,s.distanceToSquared(wn))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return void console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const s=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new an(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),o=[],a=[];for(let t=0;t<s.count;t++)o[t]=new Ai,a[t]=new Ai;const h=new Ai,u=new Ai,l=new Ai,c=new Ys,d=new Ys,p=new Ys,m=new Ai,g=new Ai;function f(t,e,i){h.fromBufferAttribute(s,t),u.fromBufferAttribute(s,e),l.fromBufferAttribute(s,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),u.sub(h),l.sub(h),d.sub(c),p.sub(c);const n=1/(d.x*p.y-p.x*d.y);isFinite(n)&&(m.copy(u).multiplyScalar(p.y).addScaledVector(l,-d.y).multiplyScalar(n),g.copy(l).multiplyScalar(d.x).addScaledVector(u,-p.x).multiplyScalar(n),o[t].add(m),o[e].add(m),o[i].add(m),a[t].add(g),a[e].add(g),a[i].add(g))}let y=this.groups;0===y.length&&(y=[{start:0,count:t.count}]);for(let e=0,s=y.length;e<s;++e){const s=y[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)f(t.getX(e+0),t.getX(e+1),t.getX(e+2))}const x=new Ai,b=new Ai,v=new Ai,T=new Ai;function _(t){v.fromBufferAttribute(i,t),T.copy(v);const e=o[t];x.copy(e),x.sub(v.multiplyScalar(v.dot(e))).normalize(),b.crossVectors(T,e);const s=b.dot(a[t])<0?-1:1;n.setXYZW(t,x.x,x.y,x.z,s)}for(let e=0,s=y.length;e<s;++e){const s=y[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)_(t.getX(e+0)),_(t.getX(e+1)),_(t.getX(e+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let s=this.getAttribute("normal");if(void 0===s)s=new an(new Float32Array(3*e.count),3),this.setAttribute("normal",s);else for(let t=0,e=s.count;t<e;t++)s.setXYZ(t,0,0,0);const i=new Ai,r=new Ai,n=new Ai,o=new Ai,a=new Ai,h=new Ai,u=new Ai,l=new Ai;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),m=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),n.fromBufferAttribute(e,m),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),o.fromBufferAttribute(s,d),a.fromBufferAttribute(s,p),h.fromBufferAttribute(s,m),o.add(u),a.add(u),h.add(u),s.setXYZ(d,o.x,o.y,o.z),s.setXYZ(p,a.x,a.y,a.z),s.setXYZ(m,h.x,h.y,h.z)}else for(let t=0,o=e.count;t<o;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),n.fromBufferAttribute(e,t+2),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),s.setXYZ(t+0,u.x,u.y,u.z),s.setXYZ(t+1,u.x,u.y,u.z),s.setXYZ(t+2,u.x,u.y,u.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)wn.fromBufferAttribute(t,e),wn.normalize(),t.setXYZ(e,wn.x,wn.y,wn.z)}toNonIndexed(){function t(t,e){const s=t.array,i=t.itemSize,r=t.normalized,n=new s.constructor(e.length*i);let o=0,a=0;for(let r=0,h=e.length;r<h;r++){o=t.isInterleavedBufferAttribute?e[r]*t.data.stride+t.offset:e[r]*i;for(let t=0;t<i;t++)n[a++]=s[o++]}return new an(n,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Sn,s=this.index.array,i=this.attributes;for(const r in i){const n=t(i[r],s);e.setAttribute(r,n)}const r=this.morphAttributes;for(const i in r){const n=[],o=r[i];for(let e=0,i=o.length;e<i;e++){const i=t(o[e],s);n.push(i)}e.morphAttributes[i]=n}e.morphTargetsRelative=this.morphTargetsRelative;const n=this.groups;for(let t=0,s=n.length;t<s;t++){const s=n[t];e.addGroup(s.start,s.count,s.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,""!==this.name&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e<i;e++){const i=s[e];n.push(i.toJSON(t.data))}n.length>0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t<r;t++)s.push(i[t].clone(e));this.morphAttributes[t]=s}this.morphTargetsRelative=t.morphTargetsRelative;const n=t.groups;for(let t=0,e=n.length;t<e;t++){const e=n[t];this.addGroup(e.start,e.count,e.materialIndex)}const o=t.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=t.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Mn=new sr,An=new er,Nn=new qi,Cn=new Ai,Rn=new Ai,En=new Ai,Bn=new Ai,In=new Ai,Pn=new Ai,Fn=new Ai,Un=new Ai;class On extends Rr{constructor(t=new Sn,e=new Kr){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const s=this.geometry,i=s.attributes.position,r=s.morphAttributes.position,n=s.morphTargetsRelative;e.fromBufferAttribute(i,t);const o=this.morphTargetInfluences;if(r&&o){Pn.set(0,0,0);for(let s=0,i=r.length;s<i;s++){const i=o[s],a=r[s];0!==i&&(In.fromBufferAttribute(a,t),n?Pn.addScaledVector(In,i):Pn.addScaledVector(In.sub(e),i))}e.add(Pn)}return e}raycast(t,e){const s=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===s.boundingSphere&&s.computeBoundingSphere(),Nn.copy(s.boundingSphere),Nn.applyMatrix4(r),An.copy(t.ray).recast(t.near),!1===Nn.containsPoint(An.origin)){if(null===An.intersectSphere(Nn,Cn))return;if(An.origin.distanceToSquared(Cn)>(t.far-t.near)**2)return}Mn.copy(r).invert(),An.copy(t.ray).applyMatrix4(Mn),null!==s.boundingBox&&!1===An.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,An)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,u=r.attributes.uv1,l=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=c.length;r<a;r++){const a=c[r],p=n[a.materialIndex];for(let r=Math.max(a.start,d.start),n=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<n;r+=3){i=zn(this,p,t,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=a.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),a=Math.min(o.count,d.start+d.count);r<a;r+=3){i=zn(this,n,t,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==a)if(Array.isArray(n))for(let r=0,o=c.length;r<o;r++){const o=c[r],p=n[o.materialIndex];for(let r=Math.max(o.start,d.start),n=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<n;r+=3){i=zn(this,p,t,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=o.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),o=Math.min(a.count,d.start+d.count);r<o;r+=3){i=zn(this,n,t,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function zn(t,e,s,i,r,n,o,a,h,u){t.getVertexPosition(a,Rn),t.getVertexPosition(h,En),t.getVertexPosition(u,Bn);const l=function(t,e,s,i,r,n,o,a){let h;if(h=e.side===d?i.intersectTriangle(o,n,r,!0,a):i.intersectTriangle(r,n,o,e.side===c,a),null===h)return null;Un.copy(a),Un.applyMatrix4(t.matrixWorld);const u=s.ray.origin.distanceTo(Un);return u<s.near||u>s.far?null:{distance:u,point:Un.clone(),object:t}}(t,e,s,i,Rn,En,Bn,Fn);if(l){const t=new Ai;Wr.getBarycoord(Fn,Rn,En,Bn,t),r&&(l.uv=Wr.getInterpolatedAttribute(r,a,h,u,t,new Ys)),n&&(l.uv1=Wr.getInterpolatedAttribute(n,a,h,u,t,new Ys)),o&&(l.normal=Wr.getInterpolatedAttribute(o,a,h,u,t,new Ai),l.normal.dot(i.direction)>0&&l.normal.multiplyScalar(-1));const e={a:a,b:h,c:u,normal:new Ai,materialIndex:0};Wr.getNormal(Rn,En,Bn,e.normal),l.face=e,l.barycoord=t}return l}class Ln extends Sn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],u=[],l=[];let c=0,d=0;function p(t,e,s,i,r,n,p,m,g,f,y){const x=n/g,b=p/f,v=n/2,T=p/2,_=m/2,w=g+1,S=f+1;let M=0,A=0;const N=new Ai;for(let n=0;n<S;n++){const o=n*b-T;for(let a=0;a<w;a++){const c=a*x-v;N[t]=c*i,N[e]=o*r,N[s]=_,h.push(N.x,N.y,N.z),N[t]=0,N[e]=0,N[s]=m>0?1:-1,u.push(N.x,N.y,N.z),l.push(a/g),l.push(1-n/f),M+=1}}for(let t=0;t<f;t++)for(let e=0;e<g;e++){const s=c+e+w*t,i=c+e+w*(t+1),r=c+(e+1)+w*(t+1),n=c+(e+1)+w*t;a.push(s,i,n),a.push(i,r,n),A+=6}o.addGroup(d,A,y),d+=A,c+=M}p("z","y","x",-1,-1,s,e,t,n,r,0),p("z","y","x",1,-1,s,e,-t,n,r,1),p("x","z","y",1,1,t,s,e,i,n,2),p("x","z","y",1,-1,t,s,-e,i,n,3),p("x","y","z",1,-1,t,e,s,i,r,4),p("x","y","z",-1,-1,t,e,-s,i,r,5),this.setIndex(a),this.setAttribute("position",new fn(h,3)),this.setAttribute("normal",new fn(u,3)),this.setAttribute("uv",new fn(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ln(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function Vn(t){const e={};for(const s in t){e[s]={};for(const i in t[s]){const r=t[s][i];r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)?r.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[s][i]=null):e[s][i]=r.clone():Array.isArray(r)?e[s][i]=r.slice():e[s][i]=r}}return e}class Dn extends Jr{static get type(){return"ShaderMaterial"}constructor(t){super(),this.isShaderMaterial=!0,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader="\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n",this.fragmentShader="\nvoid main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}\n",this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,void 0!==t&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=Vn(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let s=0;s<t.length;s++)e.push(t[s].clone());return e}(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const s in this.uniforms){const i=this.uniforms[s].value;i&&i.isTexture?e.uniforms[s]={type:"t",value:i.toJSON(t).uuid}:i&&i.isColor?e.uniforms[s]={type:"c",value:i.getHex()}:i&&i.isVector2?e.uniforms[s]={type:"v2",value:i.toArray()}:i&&i.isVector3?e.uniforms[s]={type:"v3",value:i.toArray()}:i&&i.isVector4?e.uniforms[s]={type:"v4",value:i.toArray()}:i&&i.isMatrix3?e.uniforms[s]={type:"m3",value:i.toArray()}:i&&i.isMatrix4?e.uniforms[s]={type:"m4",value:i.toArray()}:e.uniforms[s]={value:i}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class kn extends Rr{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new sr,this.projectionMatrix=new sr,this.projectionMatrixInverse=new sr,this.coordinateSystem=Us}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const Gn=new Ai,Wn=new Ys,jn=new Ys;class Hn extends kn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*ks*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Ds*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*ks*Math.atan(Math.tan(.5*Ds*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,s){Gn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Gn.x,Gn.y).multiplyScalar(-t/Gn.z),Gn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Gn.x,Gn.y).multiplyScalar(-t/Gn.z)}getViewSize(t,e){return this.getViewBounds(t,Wn,jn),e.subVectors(jn,Wn)}setViewOffset(t,e,s,i,r,n){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*Ds*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const $n=-90;class qn extends Rr{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Hn($n,1,t,e);i.layers=this.layers,this.add(i);const r=new Hn($n,1,t,e);r.layers=this.layers,this.add(r);const n=new Hn($n,1,t,e);n.layers=this.layers,this.add(n);const o=new Hn($n,1,t,e);o.layers=this.layers,this.add(o);const a=new Hn($n,1,t,e);a.layers=this.layers,this.add(a);const h=new Hn($n,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Us)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Os)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,u),t.setRenderTarget(l,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class Xn extends yi{constructor(t,e,s,i,r,n,o,a,h,u){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Yn extends vi{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new Xn(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Tt}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const s={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Ln(5,5,5),r=new Dn({name:"CubemapFromEquirect",uniforms:Vn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new On(i,r),o=e.minFilter;e.minFilter===St&&(e.minFilter=Tt);return new qn(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class Zn{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new Xr(t),this.density=e}clone(){return new Zn(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class Jn{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new Xr(t),this.near=e,this.far=s}clone(){return new Jn(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Kn extends Rr{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new dr,this.environmentIntensity=1,this.environmentRotation=new dr,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class Qn{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Ss,this.updateRanges=[],this.version=0,this.uuid=Gs()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;i<r;i++)this.array[t+i]=e.array[s+i];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=Gs()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(e,this.stride);return s.setUsage(this.usage),s}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=Gs()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.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}}}const to=new Ai;class eo{constructor(t,e,s,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=s,this.normalized=i}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,s=this.data.count;e<s;e++)to.fromBufferAttribute(this,e),to.applyMatrix4(t),this.setXYZ(e,to.x,to.y,to.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)to.fromBufferAttribute(this,e),to.applyNormalMatrix(t),this.setXYZ(e,to.x,to.y,to.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)to.fromBufferAttribute(this,e),to.transformDirection(t),this.setXYZ(e,to.x,to.y,to.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=$s(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=qs(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=qs(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=qs(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=qs(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=qs(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=$s(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=$s(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=$s(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=$s(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this}setXYZ(t,e,s,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t=t*this.data.stride+this.offset,this.normalized&&(e=qs(e,this.array),s=qs(s,this.array),i=qs(i,this.array),r=qs(r,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=i,this.data.array[t+3]=r,this}clone(t){if(void 0===t){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let e=0;e<this.count;e++){const s=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[s+e])}return new an(new this.array.constructor(t),this.itemSize,this.normalized)}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new eo(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(void 0===t){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let e=0;e<this.count;e++){const s=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[s+e])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}class so extends Jr{static get type(){return"SpriteMaterial"}constructor(t){super(),this.isSpriteMaterial=!0,this.color=new Xr(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let io;const ro=new Ai,no=new Ai,oo=new Ai,ao=new Ys,ho=new Ys,uo=new sr,lo=new Ai,co=new Ai,po=new Ai,mo=new Ys,go=new Ys,fo=new Ys;class yo extends Rr{constructor(t=new so){if(super(),this.isSprite=!0,this.type="Sprite",void 0===io){io=new Sn;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),e=new Qn(t,5);io.setIndex([0,1,2,0,2,3]),io.setAttribute("position",new eo(e,3,0,!1)),io.setAttribute("uv",new eo(e,2,3,!1))}this.geometry=io,this.material=t,this.center=new Ys(.5,.5)}raycast(t,e){null===t.camera&&console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),no.setFromMatrixScale(this.matrixWorld),uo.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),oo.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&no.multiplyScalar(-oo.z);const s=this.material.rotation;let i,r;0!==s&&(r=Math.cos(s),i=Math.sin(s));const n=this.center;xo(lo.set(-.5,-.5,0),oo,n,no,i,r),xo(co.set(.5,-.5,0),oo,n,no,i,r),xo(po.set(.5,.5,0),oo,n,no,i,r),mo.set(0,0),go.set(1,0),fo.set(1,1);let o=t.ray.intersectTriangle(lo,co,po,!1,ro);if(null===o&&(xo(co.set(-.5,.5,0),oo,n,no,i,r),go.set(0,1),o=t.ray.intersectTriangle(lo,po,co,!1,ro),null===o))return;const a=t.ray.origin.distanceTo(ro);a<t.near||a>t.far||e.push({distance:a,point:ro.clone(),uv:Wr.getInterpolation(ro,lo,co,po,mo,go,fo,new Ys),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function xo(t,e,s,i,r,n){ao.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(ho.x=n*ao.x-r*ao.y,ho.y=r*ao.x+n*ao.y):ho.copy(ao),t.copy(e),t.x+=ho.x,t.y+=ho.y,t.applyMatrix4(uo)}const bo=new Ai,vo=new Ai;class To extends Rr{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let t=0,s=e.length;t<s;t++){const s=e[t];this.addLevel(s.object.clone(),s.distance,s.hysteresis)}return this.autoUpdate=t.autoUpdate,this}addLevel(t,e=0,s=0){e=Math.abs(e);const i=this.levels;let r;for(r=0;r<i.length&&!(e<i[r].distance);r++);return i.splice(r,0,{distance:e,hysteresis:s,object:t}),this.add(t),this}removeLevel(t){const e=this.levels;for(let s=0;s<e.length;s++)if(e[s].distance===t){const t=e.splice(s,1);return this.remove(t[0].object),!0}return!1}getCurrentLevel(){return this._currentLevel}getObjectForDistance(t){const e=this.levels;if(e.length>0){let s,i;for(s=1,i=e.length;s<i;s++){let i=e[s].distance;if(e[s].object.visible&&(i-=i*e[s].hysteresis),t<i)break}return e[s-1].object}return null}raycast(t,e){if(this.levels.length>0){bo.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(bo);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){bo.setFromMatrixPosition(t.matrixWorld),vo.setFromMatrixPosition(this.matrixWorld);const s=bo.distanceTo(vo)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i<r;i++){let t=e[i].distance;if(e[i].object.visible&&(t-=t*e[i].hysteresis),!(s>=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i<r;i++)e[i].object.visible=!1}}toJSON(t){const e=super.toJSON(t);!1===this.autoUpdate&&(e.object.autoUpdate=!1),e.object.levels=[];const s=this.levels;for(let t=0,i=s.length;t<i;t++){const i=s[t];e.object.levels.push({object:i.object.uuid,distance:i.distance,hysteresis:i.hysteresis})}return e}}const _o=new Ai,wo=new xi,So=new xi,Mo=new Ai,Ao=new sr,No=new Ai,Co=new qi,Ro=new sr,Eo=new er;class Bo extends On{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=nt,this.bindMatrix=new sr,this.bindMatrixInverse=new sr,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;null===this.boundingBox&&(this.boundingBox=new Ri),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,No),this.boundingBox.expandByPoint(No)}computeBoundingSphere(){const t=this.geometry;null===this.boundingSphere&&(this.boundingSphere=new qi),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,No),this.boundingSphere.expandByPoint(No)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const s=this.material,i=this.matrixWorld;void 0!==s&&(null===this.boundingSphere&&this.computeBoundingSphere(),Co.copy(this.boundingSphere),Co.applyMatrix4(i),!1!==t.ray.intersectsSphere(Co)&&(Ro.copy(i).invert(),Eo.copy(t.ray).applyMatrix4(Ro),null!==this.boundingBox&&!1===Eo.intersectsBox(this.boundingBox)||this._computeIntersections(t,e,Eo)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,void 0===e&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new xi,e=this.geometry.attributes.skinWeight;for(let s=0,i=e.count;s<i;s++){t.fromBufferAttribute(e,s);const i=1/t.manhattanLength();i!==1/0?t.multiplyScalar(i):t.set(1,0,0,0),e.setXYZW(s,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===nt?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===ot?this.bindMatrixInverse.copy(this.bindMatrix).invert():console.warn("THREE.SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const s=this.skeleton,i=this.geometry;wo.fromBufferAttribute(i.attributes.skinIndex,t),So.fromBufferAttribute(i.attributes.skinWeight,t),_o.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const i=So.getComponent(t);if(0!==i){const r=wo.getComponent(t);Ao.multiplyMatrices(s.bones[r].matrixWorld,s.boneInverses[r]),e.addScaledVector(Mo.copy(_o).applyMatrix4(Ao),i)}}return e.applyMatrix4(this.bindMatrixInverse)}}class Io extends Rr{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Po extends yi{constructor(t=null,e=1,s=1,i,r,n,o,a,h=1003,u=1003,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isDataTexture=!0,this.image={data:t,width:e,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Fo=new sr,Uo=new sr;class Oo{constructor(t=[],e=[]){this.uuid=Gs(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(16*t.length),0===e.length)this.calculateInverses();else if(t.length!==e.length){console.warn("THREE.Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let t=0,e=this.bones.length;t<e;t++)this.boneInverses.push(new sr)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const e=new sr;this.bones[t]&&e.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(e)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const e=this.bones[t];e&&e.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const e=this.bones[t];e&&(e.parent&&e.parent.isBone?(e.matrix.copy(e.parent.matrixWorld).invert(),e.matrix.multiply(e.matrixWorld)):e.matrix.copy(e.matrixWorld),e.matrix.decompose(e.position,e.quaternion,e.scale))}}update(){const t=this.bones,e=this.boneInverses,s=this.boneMatrices,i=this.boneTexture;for(let i=0,r=t.length;i<r;i++){const r=t[i]?t[i].matrixWorld:Uo;Fo.multiplyMatrices(r,e[i]),Fo.toArray(s,16*i)}null!==i&&(i.needsUpdate=!0)}clone(){return new Oo(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(4*this.bones.length);t=4*Math.ceil(t/4),t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const s=new Po(e,t,t,Dt,It);return s.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=s,this}getBoneByName(t){for(let e=0,s=this.bones.length;e<s;e++){const s=this.bones[e];if(s.name===t)return s}}dispose(){null!==this.boneTexture&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let s=0,i=t.bones.length;s<i;s++){const i=t.bones[s];let r=e[i];void 0===r&&(console.warn("THREE.Skeleton: No bone found with UUID:",i),r=new Io),this.bones.push(r),this.boneInverses.push((new sr).fromArray(t.boneInverses[s]))}return this.init(),this}toJSON(){const t={metadata:{version:4.6,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,s=this.boneInverses;for(let i=0,r=e.length;i<r;i++){const r=e[i];t.bones.push(r.uuid);const n=s[i];t.boneInverses.push(n.toArray())}return t}}class zo extends an{constructor(t,e,s,i=1){super(t,e,s),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const Lo=new sr,Vo=new sr,Do=[],ko=new Ri,Go=new sr,Wo=new On,jo=new qi;class Ho extends On{constructor(t,e,s){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new zo(new Float32Array(16*s),16),this.instanceColor=null,this.morphTexture=null,this.count=s,this.boundingBox=null,this.boundingSphere=null;for(let t=0;t<s;t++)this.setMatrixAt(t,Go)}computeBoundingBox(){const t=this.geometry,e=this.count;null===this.boundingBox&&(this.boundingBox=new Ri),null===t.boundingBox&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Lo),ko.copy(t.boundingBox).applyMatrix4(Lo),this.boundingBox.union(ko)}computeBoundingSphere(){const t=this.geometry,e=this.count;null===this.boundingSphere&&(this.boundingSphere=new qi),null===t.boundingSphere&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Lo),jo.copy(t.boundingSphere).applyMatrix4(Lo),this.boundingSphere.union(jo)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),null!==t.morphTexture&&(this.morphTexture=t.morphTexture.clone()),null!==t.instanceColor&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){e.fromArray(this.instanceColor.array,3*t)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,16*t)}getMorphAt(t,e){const s=e.morphTargetInfluences,i=this.morphTexture.source.data.data,r=t*(s.length+1)+1;for(let t=0;t<s.length;t++)s[t]=i[r+t]}raycast(t,e){const s=this.matrixWorld,i=this.count;if(Wo.geometry=this.geometry,Wo.material=this.material,void 0!==Wo.material&&(null===this.boundingSphere&&this.computeBoundingSphere(),jo.copy(this.boundingSphere),jo.applyMatrix4(s),!1!==t.ray.intersectsSphere(jo)))for(let r=0;r<i;r++){this.getMatrixAt(r,Lo),Vo.multiplyMatrices(s,Lo),Wo.matrixWorld=Vo,Wo.raycast(t,Do);for(let t=0,s=Do.length;t<s;t++){const s=Do[t];s.instanceId=r,s.object=this,e.push(s)}Do.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new zo(new Float32Array(3*this.instanceMatrix.count).fill(1),3)),e.toArray(this.instanceColor.array,3*t)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,16*t)}setMorphAt(t,e){const s=e.morphTargetInfluences,i=s.length+1;null===this.morphTexture&&(this.morphTexture=new Po(new Float32Array(i*this.count),i,this.count,Ht,It));const r=this.morphTexture.source.data.data;let n=0;for(let t=0;t<s.length;t++)n+=s[t];const o=this.geometry.morphTargetsRelative?1:1-n,a=i*t;r[a]=o,r.set(s,a+1)}updateMorphTargets(){}dispose(){return this.dispatchEvent({type:"dispose"}),null!==this.morphTexture&&(this.morphTexture.dispose(),this.morphTexture=null),this}}const $o=new Ai,qo=new Ai,Xo=new Zs;class Yo{constructor(t=new Ai(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,s,i){return this.normal.set(t,e,s),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,s){const i=$o.subVectors(s,e).cross(qo.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const s=t.delta($o),i=this.normal.dot(s);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||Xo.getNormalMatrix(t),i=this.coplanarPoint($o).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const Zo=new qi,Jo=new Ai;class Ko{constructor(t=new Yo,e=new Yo,s=new Yo,i=new Yo,r=new Yo,n=new Yo){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],u=i[5],l=i[6],c=i[7],d=i[8],p=i[9],m=i[10],g=i[11],f=i[12],y=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,c-h,g-d,b-f).normalize(),s[1].setComponents(a+r,c+h,g+d,b+f).normalize(),s[2].setComponents(a+n,c+u,g+p,b+y).normalize(),s[3].setComponents(a-n,c-u,g-p,b-y).normalize(),s[4].setComponents(a-o,c-l,g-m,b-x).normalize(),e===Us)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(e!==Os)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),Zo.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),Zo.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(Zo)}intersectsSprite(t){return Zo.center.set(0,0,0),Zo.radius=.7071067811865476,Zo.applyMatrix4(t.matrixWorld),this.intersectsSphere(Zo)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)<i)return!1}return!0}intersectsBox(t){const e=this.planes;for(let s=0;s<6;s++){const i=e[s];if(Jo.x=i.normal.x>0?t.max.x:t.min.x,Jo.y=i.normal.y>0?t.max.y:t.min.y,Jo.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(Jo)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function Qo(t,e){return t.z-e.z}function ta(t,e){return e.z-t.z}class ea{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s){const i=this.pool,r=this.list;this.index>=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const n=i[this.index];r.push(n),this.index++,n.start=t.start,n.count=t.count,n.z=e,n.index=s}reset(){this.list.length=0,this.index=0}}const sa=new sr,ia=new sr,ra=new sr,na=new Xr(1,1,1),oa=new sr,aa=new Ko,ha=new Ri,ua=new qi,la=new Ai,ca=new Ai,da=new Ai,pa=new ea,ma=new On,ga=[];function fa(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n<r;n++)for(let r=0;r<i;r++)e.setComponent(n+s,r,t.getComponent(n,r))}else e.array.set(t.array,s*i);e.needsUpdate=!0}class ya extends On{get maxInstanceCount(){return this._maxInstanceCount}constructor(t,e,s=2*e,i){super(new Sn,i),this.isBatchedMesh=!0,this.perObjectFrustumCulled=!0,this.sortObjects=!0,this.boundingBox=null,this.boundingSphere=null,this.customSort=null,this._drawInfo=[],this._availableInstanceIds=[],this._availableGeometryIds=[],this._drawRanges=[],this._reservedRanges=[],this._bounds=[],this._maxInstanceCount=t,this._maxVertexCount=e,this._maxIndexCount=s,this._geometryInitialized=!1,this._geometryCount=0,this._multiDrawCounts=new Int32Array(t),this._multiDrawStarts=new Int32Array(t),this._multiDrawCount=0,this._multiDrawInstances=null,this._visibilityChanged=!0,this._matricesTexture=null,this._indirectTexture=null,this._colorsTexture=null,this._initMatricesTexture(),this._initIndirectTexture()}_initMatricesTexture(){let t=Math.sqrt(4*this._maxInstanceCount);t=4*Math.ceil(t/4),t=Math.max(t,4);const e=new Float32Array(t*t*4),s=new Po(e,t,t,Dt,It);this._matricesTexture=s}_initIndirectTexture(){let t=Math.sqrt(this._maxInstanceCount);t=Math.ceil(t);const e=new Uint32Array(t*t),s=new Po(e,t,t,$t,Bt);this._indirectTexture=s}_initColorsTexture(){let t=Math.sqrt(this._maxInstanceCount);t=Math.ceil(t);const e=new Float32Array(t*t*4).fill(1),s=new Po(e,t,t,Dt,It);s.colorSpace=ii.workingColorSpace,this._colorsTexture=s}_initializeGeometry(t){const e=this.geometry,s=this._maxVertexCount,i=this._maxIndexCount;if(!1===this._geometryInitialized){for(const i in t.attributes){const r=t.getAttribute(i),{array:n,itemSize:o,normalized:a}=r,h=new n.constructor(s*o),u=new an(h,o,a);e.setAttribute(i,u)}if(null!==t.getIndex()){const t=s>65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new an(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const s in e.attributes){if(!t.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Ri);const t=this.boundingBox,e=this._drawInfo;t.makeEmpty();for(let s=0,i=e.length;s<i;s++){if(!1===e[s].active)continue;const i=e[s].geometryIndex;this.getMatrixAt(s,sa),this.getBoundingBoxAt(i,ha).applyMatrix4(sa),t.union(ha)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new qi);const t=this.boundingSphere,e=this._drawInfo;t.makeEmpty();for(let s=0,i=e.length;s<i;s++){if(!1===e[s].active)continue;const i=e[s].geometryIndex;this.getMatrixAt(s,sa),this.getBoundingSphereAt(i,ua).applyMatrix4(sa),t.union(ua)}}addInstance(t){if(this._drawInfo.length>=this.maxInstanceCount&&0===this._availableInstanceIds.length)throw new Error("BatchedMesh: Maximum item count reached.");const e={visible:!0,active:!0,geometryIndex:t};let s=null;this._availableInstanceIds.length>0?(s=this._availableInstanceIds.pop(),this._drawInfo[s]=e):(s=this._drawInfo.length,this._drawInfo.push(e));const i=this._matricesTexture,r=i.image.data;ra.toArray(r,16*s),i.needsUpdate=!0;const n=this._colorsTexture;return n&&(na.toArray(n.image.data,4*s),n.needsUpdate=!0),s}addGeometry(t,e=-1,s=-1){this._initializeGeometry(t),this._validateGeometry(t);const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let r=null;const n=this._reservedRanges,o=this._drawRanges,a=this._bounds;0!==this._geometryCount&&(r=n[n.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=t.getIndex(),u=null!==h;if(u&&(i.indexCount=-1===s?h.count:s,i.indexStart=null===r?0:r.indexStart+r.indexCount),-1!==i.indexStart&&i.indexStart+i.indexCount>this._maxIndexCount||i.vertexStart+i.vertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");const l={start:u?i.indexStart:i.vertexStart,count:-1,active:!0},c={boxInitialized:!1,box:new Ri,sphereInitialized:!1,sphere:new qi};let d;return this._availableGeometryIds.length>0?(d=this._availableGeometryIds.pop(),n[d]=i,o[d]=l,a[d]=c):(d=this._geometryCount,this._geometryCount++,n.push(i),o.push(l),a.push(c)),this.setGeometryAt(d,t),d}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._reservedRanges[t];if(i&&n.count>o.indexCount||e.attributes.position.count>o.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.vertexCount;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);fa(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t<e;t++){const e=a+t;for(let t=0;t<n;t++)r.setComponent(e,t,0)}r.needsUpdate=!0,r.addUpdateRange(a*n,h*n)}if(i){const t=o.indexStart;for(let e=0;e<n.count;e++)r.setX(t+e,a+n.getX(e));for(let e=n.count,s=o.indexCount;e<s;e++)r.setX(t+e,a);r.needsUpdate=!0,r.addUpdateRange(t,o.indexCount)}const u=this._bounds[t];null!==e.boundingBox?(u.box.copy(e.boundingBox),u.boxInitialized=!0):u.boxInitialized=!1,null!==e.boundingSphere?(u.sphere.copy(e.boundingSphere),u.sphereInitialized=!0):u.sphereInitialized=!1;const l=this._drawRanges[t],c=e.getAttribute("position");return l.count=i?n.count:c.count,this._visibilityChanged=!0,t}deleteGeometry(t){const e=this._drawRanges;if(t>=e.length||!1===e[t].active)return this;const s=this._drawInfo;for(let e=0,i=s.length;e<i;e++)s[e].geometryIndex===t&&this.deleteInstance(e);return e[t].active=!1,this._availableGeometryIds.push(t),this._visibilityChanged=!0,this}deleteInstance(t){const e=this._drawInfo;return t>=e.length||!1===e[t].active||(e[t].active=!1,this._availableInstanceIds.push(t),this._visibilityChanged=!0),this}optimize(){let t=0,e=0;const s=this._drawRanges,i=this._reservedRanges,r=this.geometry;for(let n=0,o=s.length;n<o;n++){const o=s[n],a=i[n];if(!1!==o.active){if(null!==r.index&&a.indexStart!==e){const{indexStart:s,indexCount:i}=a,n=r.index,o=n.array,h=t-a.vertexStart;for(let t=s;t<s+i;t++)o[t]=o[t]+h;n.array.copyWithin(e,s,s+i),n.addUpdateRange(e,i),a.indexStart=e,e+=a.indexCount}if(a.vertexStart!==t){const{vertexStart:e,vertexCount:s}=a,i=r.attributes;for(const r in i){const n=i[r],{array:o,itemSize:a}=n;o.copyWithin(t*a,e*a,(e+s)*a),n.addUpdateRange(t*a,s*a)}a.vertexStart=t,t+=a.vertexCount}o.start=r.index?a.indexStart:a.vertexStart}}return this}getBoundingBoxAt(t,e){if(t>=this._geometryCount)return null;const s=this._bounds[t],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const e=r.index,n=r.attributes.position,o=this._drawRanges[t];for(let t=o.start,s=o.start+o.count;t<s;t++){let s=t;e&&(s=e.getX(s)),i.expandByPoint(la.fromBufferAttribute(n,s))}s.boxInitialized=!0}return e.copy(i),e}getBoundingSphereAt(t,e){if(t>=this._geometryCount)return null;const s=this._bounds[t],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,ha),ha.getCenter(i.center);const e=r.index,n=r.attributes.position,o=this._drawRanges[t];let a=0;for(let t=o.start,s=o.start+o.count;t<s;t++){let s=t;e&&(s=e.getX(s)),la.fromBufferAttribute(n,s),a=Math.max(a,i.center.distanceToSquared(la))}i.radius=Math.sqrt(a),s.sphereInitialized=!0}return e.copy(i),e}setMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture,r=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active||(e.toArray(r,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return t>=r.length||!1===r[t].active||(e.toArray(i,4*t),s.needsUpdate=!0),this}getColorAt(t,e){const s=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(s,4*t)}setVisibleAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||s[t].visible===e||(s[t].visible=e,this._visibilityChanged=!0),this}getVisibleAt(t){const e=this._drawInfo;return!(t>=e.length||!1===e[t].active)&&e[t].visible}setGeometryIdAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||e<0||e>=this._geometryCount?null:(s[t].geometryIndex=e,this)}getGeometryIdAt(t){const e=this._drawInfo;return t>=e.length||!1===e[t].active?-1:e[t].geometryIndex}getGeometryRangeAt(t,e={}){if(t<0||t>=this._geometryCount)return null;const s=this._drawRanges[t];return e.start=s.start,e.count=s.count,e}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;ma.material=this.material,ma.geometry.index=n.index,ma.geometry.attributes=n.attributes,null===ma.geometry.boundingBox&&(ma.geometry.boundingBox=new Ri),null===ma.geometry.boundingSphere&&(ma.geometry.boundingSphere=new qi);for(let n=0,o=s.length;n<o;n++){if(!s[n].visible||!s[n].active)continue;const o=s[n].geometryIndex,a=i[o];ma.geometry.setDrawRange(a.start,a.count),this.getMatrixAt(n,ma.matrixWorld).premultiply(r),this.getBoundingBoxAt(o,ma.geometry.boundingBox),this.getBoundingSphereAt(o,ma.geometry.boundingSphere),ma.raycast(t,ga);for(let t=0,s=ga.length;t<s;t++){const s=ga[t];s.object=this,s.batchId=n,e.push(s)}ga.length=0}ma.material=null,ma.geometry.index=null,ma.geometry.attributes={},ma.geometry.setDrawRange(0,1/0)}copy(t){return super.copy(t),this.geometry=t.geometry.clone(),this.perObjectFrustumCulled=t.perObjectFrustumCulled,this.sortObjects=t.sortObjects,this.boundingBox=null!==t.boundingBox?t.boundingBox.clone():null,this.boundingSphere=null!==t.boundingSphere?t.boundingSphere.clone():null,this._drawRanges=t._drawRanges.map((t=>({...t}))),this._reservedRanges=t._reservedRanges.map((t=>({...t}))),this._drawInfo=t._drawInfo.map((t=>({...t}))),this._bounds=t._bounds.map((t=>({boxInitialized:t.boxInitialized,box:t.box.clone(),sphereInitialized:t.sphereInitialized,sphere:t.sphere.clone()}))),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._drawInfo,h=this._multiDrawStarts,u=this._multiDrawCounts,l=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(oa.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),aa.setFromProjectionMatrix(oa,t.coordinateSystem));let m=0;if(this.sortObjects){ia.copy(this.matrixWorld).invert(),la.setFromMatrixPosition(s.matrixWorld).applyMatrix4(ia),ca.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(ia);for(let t=0,e=a.length;t<e;t++)if(a[t].visible&&a[t].active){const e=a[t].geometryIndex;this.getMatrixAt(t,sa),this.getBoundingSphereAt(e,ua).applyMatrix4(sa);let s=!1;if(c&&(s=!aa.intersectsSphere(ua)),!s){const s=da.subVectors(ua.center,la).dot(ca);pa.push(l[e],s,t)}}const t=pa.list,e=this.customSort;null===e?t.sort(r.transparent?ta:Qo):e.call(this,t,s);for(let e=0,s=t.length;e<s;e++){const s=t[e];h[m]=s.start*o,u[m]=s.count,p[m]=s.index,m++}pa.reset()}else for(let t=0,e=a.length;t<e;t++)if(a[t].visible&&a[t].active){const e=a[t].geometryIndex;let s=!1;if(c&&(this.getMatrixAt(t,sa),this.getBoundingSphereAt(e,ua).applyMatrix4(sa),s=!aa.intersectsSphere(ua)),!s){const s=l[e];h[m]=s.start*o,u[m]=s.count,p[m]=t,m++}}d.needsUpdate=!0,this._multiDrawCount=m,this._visibilityChanged=!1}onBeforeShadow(t,e,s,i,r,n){this.onBeforeRender(t,null,i,r,n)}}class xa extends Jr{static get type(){return"LineBasicMaterial"}constructor(t){super(),this.isLineBasicMaterial=!0,this.color=new Xr(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const ba=new Ai,va=new Ai,Ta=new sr,_a=new er,wa=new qi,Sa=new Ai,Ma=new Ai;class Aa extends Rr{constructor(t=new Sn,e=new xa){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[0];for(let t=1,i=e.count;t<i;t++)ba.fromBufferAttribute(e,t-1),va.fromBufferAttribute(e,t),s[t]=s[t-1],s[t]+=ba.distanceTo(va);t.setAttribute("lineDistance",new fn(s,1))}else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const s=this.geometry,i=this.matrixWorld,r=t.params.Line.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),wa.copy(s.boundingSphere),wa.applyMatrix4(i),wa.radius+=r,!1===t.ray.intersectsSphere(wa))return;Ta.copy(i).invert(),_a.copy(t.ray).applyMatrix4(Ta);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=this.isLineSegments?2:1,u=s.index,l=s.attributes.position;if(null!==u){const s=Math.max(0,n.start),i=Math.min(u.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=u.getX(r),i=u.getX(r+1),n=Na(this,t,_a,a,s,i);n&&e.push(n)}if(this.isLineLoop){const r=u.getX(i-1),n=u.getX(s),o=Na(this,t,_a,a,r,n);o&&e.push(o)}}else{const s=Math.max(0,n.start),i=Math.min(l.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=Na(this,t,_a,a,r,r+1);s&&e.push(s)}if(this.isLineLoop){const r=Na(this,t,_a,a,i-1,s);r&&e.push(r)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}}function Na(t,e,s,i,r,n){const o=t.geometry.attributes.position;ba.fromBufferAttribute(o,r),va.fromBufferAttribute(o,n);if(s.distanceSqToSegment(ba,va,Sa,Ma)>i)return;Sa.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Sa);return a<e.near||a>e.far?void 0:{distance:a,point:Ma.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:t}}const Ca=new Ai,Ra=new Ai;class Ea extends Aa{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[];for(let t=0,i=e.count;t<i;t+=2)Ca.fromBufferAttribute(e,t),Ra.fromBufferAttribute(e,t+1),s[t]=0===t?0:s[t-1],s[t+1]=s[t]+Ca.distanceTo(Ra);t.setAttribute("lineDistance",new fn(s,1))}else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class Ba extends Aa{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class Ia extends Jr{static get type(){return"PointsMaterial"}constructor(t){super(),this.isPointsMaterial=!0,this.color=new Xr(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Pa=new sr,Fa=new er,Ua=new qi,Oa=new Ai;class za extends Rr{constructor(t=new Sn,e=new Ia){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const s=this.geometry,i=this.matrixWorld,r=t.params.Points.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),Ua.copy(s.boundingSphere),Ua.applyMatrix4(i),Ua.radius+=r,!1===t.ray.intersectsSphere(Ua))return;Pa.copy(i).invert(),Fa.copy(t.ray).applyMatrix4(Pa);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=s.index,u=s.attributes.position;if(null!==h){for(let s=Math.max(0,n.start),r=Math.min(h.count,n.start+n.count);s<r;s++){const r=h.getX(s);Oa.fromBufferAttribute(u,r),La(Oa,r,a,i,t,e,this)}}else{for(let s=Math.max(0,n.start),r=Math.min(u.count,n.start+n.count);s<r;s++)Oa.fromBufferAttribute(u,s),La(Oa,s,a,i,t,e,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}}function La(t,e,s,i,r,n,o){const a=Fa.distanceSqToPoint(t);if(a<s){const s=new Ai;Fa.closestPointToPoint(t,s),s.applyMatrix4(i);const h=r.ray.origin.distanceTo(s);if(h<r.near||h>r.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,faceIndex:null,barycoord:null,object:o})}}class Va extends Rr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class Da extends yi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Tt,this.magFilter=void 0!==r?r:Tt,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){u.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class ka extends yi{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ga extends yi{constructor(t,e,s,i,r,n,o,a,h,u,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Wa extends Ga{constructor(t,e,s,i,r,n){super(t,e,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class ja extends Ga{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Ha extends yi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class $a extends yi{constructor(t,e,s,i,r,n,o,a,h,u=1026){if(u!==Wt&&u!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===Wt&&(s=Bt),void 0===s&&u===jt&&(s=Ot),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class qa{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const u=s[i];return(i+(n-u)/(s[i+1]-u))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Ys:new Ai);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ai,i=[],r=[],n=[],o=new Ai,a=new sr;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ai)}r[0]=new Ai,n[0]=new Ai;let h=Number.MAX_VALUE;const u=Math.abs(i[0].x),l=Math.abs(i[0].y),c=Math.abs(i[0].z);u<=h&&(h=u,s.set(1,0,0)),l<=h&&(h=l,s.set(0,1,0)),c<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos(Ws(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos(Ws(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class Xa extends qa{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Ys){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=n?0:i),!0!==this.aClockwise||n||(r===i?r=-i:r-=i);const o=this.aStartAngle+t*r;let a=this.aX+this.xRadius*Math.cos(o),h=this.aY+this.yRadius*Math.sin(o);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),s=a-this.aX,i=h-this.aY;a=s*t-i*e+this.aX,h=s*e+i*t+this.aY}return s.set(a,h)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class Ya extends Xa{constructor(t,e,s,i,r,n){super(t,e,s,s,i,r,n),this.isArcCurve=!0,this.type="ArcCurve"}}function Za(){let t=0,e=0,s=0,i=0;function r(r,n,o,a){t=r,e=o,s=-3*r+3*n-2*o-a,i=2*r-2*n+o+a}return{initCatmullRom:function(t,e,s,i,n){r(e,s,n*(s-t),n*(i-e))},initNonuniformCatmullRom:function(t,e,s,i,n,o,a){let h=(e-t)/n-(s-t)/(n+o)+(s-e)/o,u=(s-e)/o-(i-e)/(o+a)+(i-s)/a;h*=o,u*=o,r(e,s,h,u)},calc:function(r){const n=r*r;return t+e*r+s*n+i*(n*r)}}}const Ja=new Ai,Ka=new Za,Qa=new Za,th=new Za;class eh extends qa{constructor(t=[],e=!1,s="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=s,this.tension=i}getPoint(t,e=new Ai){const s=e,i=this.points,r=i.length,n=(r-(this.closed?0:1))*t;let o,a,h=Math.floor(n),u=n-h;this.closed?h+=h>0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===u&&h===r-1&&(h=r-2,u=1),this.closed||h>0?o=i[(h-1)%r]:(Ja.subVectors(i[0],i[1]).add(i[0]),o=Ja);const l=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(Ja.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=Ja),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(o.distanceToSquared(l),t),s=Math.pow(l.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(a),t);s<1e-4&&(s=1),e<1e-4&&(e=s),i<1e-4&&(i=s),Ka.initNonuniformCatmullRom(o.x,l.x,c.x,a.x,e,s,i),Qa.initNonuniformCatmullRom(o.y,l.y,c.y,a.y,e,s,i),th.initNonuniformCatmullRom(o.z,l.z,c.z,a.z,e,s,i)}else"catmullrom"===this.curveType&&(Ka.initCatmullRom(o.x,l.x,c.x,a.x,this.tension),Qa.initCatmullRom(o.y,l.y,c.y,a.y,this.tension),th.initCatmullRom(o.z,l.z,c.z,a.z,this.tension));return s.set(Ka.calc(u),Qa.calc(u),th.calc(u)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push(s.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,s=this.points.length;e<s;e++){const s=this.points[e];t.points.push(s.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push((new Ai).fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function sh(t,e,s,i,r){const n=.5*(i-e),o=.5*(r-s),a=t*t;return(2*s-2*i+n+o)*(t*a)+(-3*s+3*i-2*n-o)*a+n*t+s}function ih(t,e,s,i){return function(t,e){const s=1-t;return s*s*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,s)+function(t,e){return t*t*e}(t,i)}function rh(t,e,s,i,r){return function(t,e){const s=1-t;return s*s*s*e}(t,e)+function(t,e){const s=1-t;return 3*s*s*t*e}(t,s)+function(t,e){return 3*(1-t)*t*t*e}(t,i)+function(t,e){return t*t*t*e}(t,r)}class nh extends qa{constructor(t=new Ys,e=new Ys,s=new Ys,i=new Ys){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Ys){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(rh(t,i.x,r.x,n.x,o.x),rh(t,i.y,r.y,n.y,o.y)),s}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class oh extends qa{constructor(t=new Ai,e=new Ai,s=new Ai,i=new Ai){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Ai){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(rh(t,i.x,r.x,n.x,o.x),rh(t,i.y,r.y,n.y,o.y),rh(t,i.z,r.z,n.z,o.z)),s}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class ah extends qa{constructor(t=new Ys,e=new Ys){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Ys){const s=e;return 1===t?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(t).add(this.v1)),s}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Ys){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class hh extends qa{constructor(t=new Ai,e=new Ai){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new Ai){const s=e;return 1===t?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(t).add(this.v1)),s}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Ai){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class uh extends qa{constructor(t=new Ys,e=new Ys,s=new Ys){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Ys){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(ih(t,i.x,r.x,n.x),ih(t,i.y,r.y,n.y)),s}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class lh extends qa{constructor(t=new Ai,e=new Ai,s=new Ai){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Ai){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(ih(t,i.x,r.x,n.x),ih(t,i.y,r.y,n.y),ih(t,i.z,r.z,n.z)),s}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class ch extends qa{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new Ys){const s=e,i=this.points,r=(i.length-1)*t,n=Math.floor(r),o=r-n,a=i[0===n?n:n-1],h=i[n],u=i[n>i.length-2?i.length-1:n+1],l=i[n>i.length-3?i.length-1:n+2];return s.set(sh(o,a.x,h.x,u.x,l.x),sh(o,a.y,h.y,u.y,l.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,s=this.points.length;e<s;e++){const s=this.points[e];t.points.push(s.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push((new Ys).fromArray(s))}return this}}var dh=Object.freeze({__proto__:null,ArcCurve:Ya,CatmullRomCurve3:eh,CubicBezierCurve:nh,CubicBezierCurve3:oh,EllipseCurve:Xa,LineCurve:ah,LineCurve3:hh,QuadraticBezierCurve:uh,QuadraticBezierCurve3:lh,SplineCurve:ch});class ph extends qa{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const s=!0===t.isVector2?"LineCurve":"LineCurve3";this.curves.push(new dh[s](e,t))}return this}getPoint(t,e){const s=t*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let s=0,i=this.curves.length;s<i;s++)e+=this.curves[s].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let s;for(let i=0,r=this.curves;i<r.length;i++){const n=r[i],o=n.isEllipseCurve?2*t:n.isLineCurve||n.isLineCurve3?1:n.isSplineCurve?t*n.points.length:t,a=n.getPoints(o);for(let t=0;t<a.length;t++){const i=a[t];s&&s.equals(i)||(e.push(i),s=i)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,s=t.curves.length;e<s;e++){const s=t.curves[e];this.curves.push(s.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,s=this.curves.length;e<s;e++){const s=this.curves[e];t.curves.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,s=t.curves.length;e<s;e++){const s=t.curves[e];this.curves.push((new dh[s.type]).fromJSON(s))}return this}}class mh extends ph{constructor(t){super(),this.type="Path",this.currentPoint=new Ys,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,s=t.length;e<s;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const s=new ah(this.currentPoint.clone(),new Ys(t,e));return this.curves.push(s),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,s,i){const r=new uh(this.currentPoint.clone(),new Ys(t,e),new Ys(s,i));return this.curves.push(r),this.currentPoint.set(s,i),this}bezierCurveTo(t,e,s,i,r,n){const o=new nh(this.currentPoint.clone(),new Ys(t,e),new Ys(s,i),new Ys(r,n));return this.curves.push(o),this.currentPoint.set(r,n),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),s=new ch(e);return this.curves.push(s),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,s,i,r,n){const o=this.currentPoint.x,a=this.currentPoint.y;return this.absarc(t+o,e+a,s,i,r,n),this}absarc(t,e,s,i,r,n){return this.absellipse(t,e,s,s,i,r,n),this}ellipse(t,e,s,i,r,n,o,a){const h=this.currentPoint.x,u=this.currentPoint.y;return this.absellipse(t+h,e+u,s,i,r,n,o,a),this}absellipse(t,e,s,i,r,n,o,a){const h=new Xa(t,e,s,i,r,n,o,a);if(this.curves.length>0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class gh extends Sn{constructor(t=[new Ys(0,-.5),new Ys(.5,0),new Ys(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=Ws(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/e,l=new Ai,c=new Ys,d=new Ai,p=new Ai,m=new Ai;let g=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){l.x=t[s].x*p,l.y=t[s].y,l.z=t[s].x*m,n.push(l.x,l.y,l.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,u=a[3*s+1],d=a[3*s+0]*m;h.push(i,u,d)}}for(let s=0;s<e;s++)for(let e=0;e<t.length-1;e++){const i=e+s*t.length,n=i,o=i+t.length,a=i+t.length+1,h=i+1;r.push(n,o,h),r.push(a,h,o)}this.setIndex(r),this.setAttribute("position",new fn(n,3)),this.setAttribute("uv",new fn(o,2)),this.setAttribute("normal",new fn(h,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new gh(t.points,t.segments,t.phiStart,t.phiLength)}}class fh extends gh{constructor(t=1,e=1,s=4,i=8){const r=new mh;r.absarc(0,-e/2,t,1.5*Math.PI,0),r.absarc(0,e/2,t,0,.5*Math.PI),super(r.getPoints(s),i),this.type="CapsuleGeometry",this.parameters={radius:t,length:e,capSegments:s,radialSegments:i}}static fromJSON(t){return new fh(t.radius,t.length,t.capSegments,t.radialSegments)}}class yh extends Sn{constructor(t=1,e=32,s=0,i=2*Math.PI){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:s,thetaLength:i},e=Math.max(3,e);const r=[],n=[],o=[],a=[],h=new Ai,u=new Ys;n.push(0,0,0),o.push(0,0,1),a.push(.5,.5);for(let r=0,l=3;r<=e;r++,l+=3){const c=s+r/e*i;h.x=t*Math.cos(c),h.y=t*Math.sin(c),n.push(h.x,h.y,h.z),o.push(0,0,1),u.x=(n[l]/t+1)/2,u.y=(n[l+1]/t+1)/2,a.push(u.x,u.y)}for(let t=1;t<=e;t++)r.push(t,t+1,0);this.setIndex(r),this.setAttribute("position",new fn(n,3)),this.setAttribute("normal",new fn(o,3)),this.setAttribute("uv",new fn(a,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new yh(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class xh extends Sn{constructor(t=1,e=1,s=1,i=32,r=1,n=!1,o=0,a=2*Math.PI){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:s,radialSegments:i,heightSegments:r,openEnded:n,thetaStart:o,thetaLength:a};const h=this;i=Math.floor(i),r=Math.floor(r);const u=[],l=[],c=[],d=[];let p=0;const m=[],g=s/2;let f=0;function y(s){const r=p,n=new Ys,m=new Ai;let y=0;const x=!0===s?t:e,b=!0===s?1:-1;for(let t=1;t<=i;t++)l.push(0,g*b,0),c.push(0,b,0),d.push(.5,.5),p++;const v=p;for(let t=0;t<=i;t++){const e=t/i*a+o,s=Math.cos(e),r=Math.sin(e);m.x=x*r,m.y=g*b,m.z=x*s,l.push(m.x,m.y,m.z),c.push(0,b,0),n.x=.5*s+.5,n.y=.5*r*b+.5,d.push(n.x,n.y),p++}for(let t=0;t<i;t++){const e=r+t,i=v+t;!0===s?u.push(i,i+1,e):u.push(i+1,i,e),y+=3}h.addGroup(f,y,!0===s?1:2),f+=y}!function(){const n=new Ai,y=new Ai;let x=0;const b=(e-t)/s;for(let h=0;h<=r;h++){const u=[],f=h/r,x=f*(e-t)+t;for(let t=0;t<=i;t++){const e=t/i,r=e*a+o,h=Math.sin(r),m=Math.cos(r);y.x=x*h,y.y=-f*s+g,y.z=x*m,l.push(y.x,y.y,y.z),n.set(h,b,m).normalize(),c.push(n.x,n.y,n.z),d.push(e,1-f),u.push(p++)}m.push(u)}for(let s=0;s<i;s++)for(let i=0;i<r;i++){const r=m[i][s],n=m[i+1][s],o=m[i+1][s+1],a=m[i][s+1];t>0&&(u.push(r,n,a),x+=3),e>0&&(u.push(n,o,a),x+=3)}h.addGroup(f,x,0),f+=x}(),!1===n&&(t>0&&y(!0),e>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new fn(l,3)),this.setAttribute("normal",new fn(c,3)),this.setAttribute("uv",new fn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new xh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class bh extends xh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new bh(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class vh extends Sn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t<r;t++)for(let e=0;e<2*(r-t)-1;e++){const s=Math.floor(e/2);e%2==0?(a(n[t][s+1]),a(n[t+1][s]),a(n[t][s])):(a(n[t][s+1]),a(n[t+1][s+1]),a(n[t+1][s]))}}function a(t){r.push(t.x,t.y,t.z)}function h(e,s){const i=3*e;s.x=t[i+0],s.y=t[i+1],s.z=t[i+2]}function u(t,e,s,i){i<0&&1===t.x&&(n[e]=t.x-1),0===s.x&&0===s.z&&(n[e]=i/2/Math.PI+.5)}function l(t){return Math.atan2(t.z,-t.x)}!function(t){const s=new Ai,i=new Ai,r=new Ai;for(let n=0;n<e.length;n+=3)h(e[n+0],s),h(e[n+1],i),h(e[n+2],r),o(s,i,r,t)}(i),function(t){const e=new Ai;for(let s=0;s<r.length;s+=3)e.x=r[s+0],e.y=r[s+1],e.z=r[s+2],e.normalize().multiplyScalar(t),r[s+0]=e.x,r[s+1]=e.y,r[s+2]=e.z}(s),function(){const t=new Ai;for(let s=0;s<r.length;s+=3){t.x=r[s+0],t.y=r[s+1],t.z=r[s+2];const i=l(t)/2/Math.PI+.5,o=(e=t,Math.atan2(-e.y,Math.sqrt(e.x*e.x+e.z*e.z))/Math.PI+.5);n.push(i,1-o)}var e;(function(){const t=new Ai,e=new Ai,s=new Ai,i=new Ai,o=new Ys,a=new Ys,h=new Ys;for(let c=0,d=0;c<r.length;c+=9,d+=6){t.set(r[c+0],r[c+1],r[c+2]),e.set(r[c+3],r[c+4],r[c+5]),s.set(r[c+6],r[c+7],r[c+8]),o.set(n[d+0],n[d+1]),a.set(n[d+2],n[d+3]),h.set(n[d+4],n[d+5]),i.copy(t).add(e).add(s).divideScalar(3);const p=l(i);u(o,d+0,t,p),u(a,d+2,e,p),u(h,d+4,s,p)}})(),function(){for(let t=0;t<n.length;t+=6){const e=n[t+0],s=n[t+2],i=n[t+4],r=Math.max(e,s,i),o=Math.min(e,s,i);r>.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new fn(r,3)),this.setAttribute("normal",new fn(r.slice(),3)),this.setAttribute("uv",new fn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new vh(t.vertices,t.indices,t.radius,t.details)}}class Th extends vh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Th(t.radius,t.detail)}}const _h=new Ai,wh=new Ai,Sh=new Ai,Mh=new Wr;class Ah extends Sn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(Ds*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let t=0;t<a;t+=3){n?(h[0]=n.getX(t),h[1]=n.getX(t+1),h[2]=n.getX(t+2)):(h[0]=t,h[1]=t+1,h[2]=t+2);const{a:e,b:s,c:a}=Mh;if(e.fromBufferAttribute(o,h[0]),s.fromBufferAttribute(o,h[1]),a.fromBufferAttribute(o,h[2]),Mh.getNormal(Sh),l[0]=`${Math.round(e.x*i)},${Math.round(e.y*i)},${Math.round(e.z*i)}`,l[1]=`${Math.round(s.x*i)},${Math.round(s.y*i)},${Math.round(s.z*i)}`,l[2]=`${Math.round(a.x*i)},${Math.round(a.y*i)},${Math.round(a.z*i)}`,l[0]!==l[1]&&l[1]!==l[2]&&l[2]!==l[0])for(let t=0;t<3;t++){const e=(t+1)%3,s=l[t],i=l[e],n=Mh[u[t]],o=Mh[u[e]],a=`${s}_${i}`,p=`${i}_${s}`;p in c&&c[p]?(Sh.dot(c[p].normal)<=r&&(d.push(n.x,n.y,n.z),d.push(o.x,o.y,o.z)),c[p]=null):a in c||(c[a]={index0:h[t],index1:h[e],normal:Sh.clone()})}}for(const t in c)if(c[t]){const{index0:e,index1:s}=c[t];_h.fromBufferAttribute(o,e),wh.fromBufferAttribute(o,s),d.push(_h.x,_h.y,_h.z),d.push(wh.x,wh.y,wh.z)}this.setAttribute("position",new fn(d,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}class Nh extends mh{constructor(t){super(t),this.uuid=Gs(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let s=0,i=this.holes.length;s<i;s++)e[s]=this.holes[s].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,s=t.holes.length;e<s;e++){const s=t.holes[e];this.holes.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,s=this.holes.length;e<s;e++){const s=this.holes[e];t.holes.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,s=t.holes.length;e<s;e++){const s=t.holes[e];this.holes.push((new mh).fromJSON(s))}return this}}const Ch=function(t,e,s=2){const i=e&&e.length,r=i?e[0]*s:t.length;let n=Rh(t,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,u,l,c,d,p;if(i&&(n=function(t,e,s,i){const r=[];let n,o,a,h,u;for(n=0,o=e.length;n<o;n++)a=e[n]*i,h=n<o-1?e[n+1]*i:t.length,u=Rh(t,a,h,i,!1),u===u.next&&(u.steiner=!0),r.push(Dh(u));for(r.sort(Oh),n=0;n<r.length;n++)s=zh(r[n],s);return s}(t,e,n,s)),t.length>80*s){a=u=t[0],h=l=t[1];for(let e=s;e<r;e+=s)c=t[e],d=t[e+1],c<a&&(a=c),d<h&&(h=d),c>u&&(u=c),d>l&&(l=d);p=Math.max(u-a,l-h),p=0!==p?32767/p:0}return Bh(n,o,s,a,h,p,0),o};function Rh(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n<s;n+=i)r+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return r}(t,e,s,i)>0)for(n=e;n<s;n+=i)o=Zh(n,t[n],t[n+1],o);else for(n=s-i;n>=e;n-=i)o=Zh(n,t[n],t[n+1],o);return o&&jh(o,o.next)&&(Jh(o),o=o.next),o}function Eh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!jh(i,i.next)&&0!==Wh(i.prev,i,i.next))i=i.next;else{if(Jh(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Bh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=Vh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,u=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e<u&&(a++,i=i.nextZ,i);e++);for(h=u;a>0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(t,i,r,n);let a,h,u=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Ph(t,i,r,n):Ih(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),Jh(t),t=h.next,u=h.next;else if((t=h)===u){o?1===o?Bh(t=Fh(Eh(t),e,s),e,s,i,r,n,2):2===o&&Uh(t,e,s,i,r,n):Bh(Eh(t),e,s,i,r,n,1);break}}function Ih(t){const e=t.prev,s=t,i=t.next;if(Wh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,u=i.y,l=r<n?r<o?r:o:n<o?n:o,c=a<h?a<u?a:u:h<u?h:u,d=r>n?r>o?r:o:n>o?n:o,p=a>h?a>u?a:u:h>u?h:u;let m=i.next;for(;m!==e;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&kh(r,a,n,h,o,u,m.x,m.y)&&Wh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Ph(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Wh(r,n,o)>=0)return!1;const a=r.x,h=n.x,u=o.x,l=r.y,c=n.y,d=o.y,p=a<h?a<u?a:u:h<u?h:u,m=l<c?l<d?l:d:c<d?c:d,g=a>h?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=Vh(p,m,e,s,i),x=Vh(g,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=y&&v&&v.z<=x;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&kh(a,l,h,c,u,d,b.x,b.y)&&Wh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&kh(a,l,h,c,u,d,v.x,v.y)&&Wh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=y;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&kh(a,l,h,c,u,d,b.x,b.y)&&Wh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&kh(a,l,h,c,u,d,v.x,v.y)&&Wh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Fh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!jh(r,n)&&Hh(r,i,i.next,n)&&Xh(r,n)&&Xh(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),Jh(i),Jh(i.next),i=t=n),i=i.next}while(i!==t);return Eh(i)}function Uh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Gh(o,t)){let a=Yh(o,t);return o=Eh(o,o.next),a=Eh(a,a.next),Bh(o,e,s,i,r,n,0),void Bh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Oh(t,e){return t.x-e.x}function zh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x<i.next.x?i:i.next,t===n))return s}i=i.next}while(i!==e);if(!s)return null;const a=s,h=s.x,u=s.y;let l,c=1/0;i=s;do{n>=i.x&&i.x>=h&&n!==i.x&&kh(o<u?n:r,o,h,u,o<u?r:n,o,i.x,i.y)&&(l=Math.abs(o-i.y)/(n-i.x),Xh(i,t)&&(l<c||l===c&&(i.x>s.x||i.x===s.x&&Lh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=Yh(s,t);return Eh(i,i.next),Eh(s,s.next)}function Lh(t,e){return Wh(t.prev,t,e.prev)<0&&Wh(e.next,t,t.next)<0}function Vh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Dh(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function kh(t,e,s,i,r,n,o,a){return(r-o)*(e-a)>=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Gh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Hh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(Xh(t,e)&&Xh(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Wh(t.prev,t,e.prev)||Wh(t,e.prev,e))||jh(t,e)&&Wh(t.prev,t,t.next)>0&&Wh(e.prev,e,e.next)>0)}function Wh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function jh(t,e){return t.x===e.x&&t.y===e.y}function Hh(t,e,s,i){const r=qh(Wh(t,e,s)),n=qh(Wh(t,e,i)),o=qh(Wh(s,i,t)),a=qh(Wh(s,i,e));return r!==n&&o!==a||(!(0!==r||!$h(t,s,e))||(!(0!==n||!$h(t,i,e))||(!(0!==o||!$h(s,t,i))||!(0!==a||!$h(s,e,i)))))}function $h(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function qh(t){return t>0?1:t<0?-1:0}function Xh(t,e){return Wh(t.prev,t,t.next)<0?Wh(t,e,t.next)>=0&&Wh(t,t.prev,e)>=0:Wh(t,e,t.prev)<0||Wh(t,t.next,e)<0}function Yh(t,e){const s=new Kh(t.i,t.x,t.y),i=new Kh(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function Zh(t,e,s,i){const r=new Kh(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Jh(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Kh(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class Qh{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r<e;i=r++)s+=t[i].x*t[r].y-t[r].x*t[i].y;return.5*s}static isClockWise(t){return Qh.area(t)<0}static triangulateShape(t,e){const s=[],i=[],r=[];tu(t),eu(s,t);let n=t.length;e.forEach(tu);for(let t=0;t<e.length;t++)i.push(n),n+=e[t].length,eu(s,e[t]);const o=Ch(s,i);for(let t=0;t<o.length;t+=3)r.push(o.slice(t,t+3));return r}}function tu(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function eu(t,e){for(let s=0;s<e.length;s++)t.push(e[s].x),t.push(e[s].y)}class su extends Sn{constructor(t=new Nh([new Ys(.5,.5),new Ys(-.5,.5),new Ys(-.5,-.5),new Ys(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],r=[];for(let e=0,s=t.length;e<s;e++){n(t[e])}function n(t){const n=[],o=void 0!==e.curveSegments?e.curveSegments:12,a=void 0!==e.steps?e.steps:1,h=void 0!==e.depth?e.depth:1;let u=void 0===e.bevelEnabled||e.bevelEnabled,l=void 0!==e.bevelThickness?e.bevelThickness:.2,c=void 0!==e.bevelSize?e.bevelSize:l-.1,d=void 0!==e.bevelOffset?e.bevelOffset:0,p=void 0!==e.bevelSegments?e.bevelSegments:3;const m=e.extrudePath,g=void 0!==e.UVGenerator?e.UVGenerator:iu;let f,y,x,b,v,T=!1;m&&(f=m.getSpacedPoints(a),T=!0,u=!1,y=m.computeFrenetFrames(a,!1),x=new Ai,b=new Ai,v=new Ai),u||(p=0,l=0,c=0,d=0);const _=t.extractPoints(o);let w=_.shape;const S=_.holes;if(!Qh.isClockWise(w)){w=w.reverse();for(let t=0,e=S.length;t<e;t++){const e=S[t];Qh.isClockWise(e)&&(S[t]=e.reverse())}}const M=Qh.triangulateShape(w,S),A=w;for(let t=0,e=S.length;t<e;t++){const e=S[t];w=w.concat(e)}function N(t,e,s){return e||console.error("THREE.ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,s)}const C=w.length,R=M.length;function E(t,e,s){let i,r,n;const o=t.x-e.x,a=t.y-e.y,h=s.x-t.x,u=s.y-t.y,l=o*o+a*a,c=o*u-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=e.x-a/c,m=e.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-t.x,r=m+a*g-t.y;const f=i*i+r*r;if(f<=2)return new Ys(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(u)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new Ys(i/n,r/n)}const B=[];for(let t=0,e=A.length,s=e-1,i=t+1;t<e;t++,s++,i++)s===e&&(s=0),i===e&&(i=0),B[t]=E(A[t],A[s],A[i]);const I=[];let P,F=B.concat();for(let t=0,e=S.length;t<e;t++){const e=S[t];P=[];for(let t=0,s=e.length,i=s-1,r=t+1;t<s;t++,i++,r++)i===s&&(i=0),r===s&&(r=0),P[t]=E(e[t],e[i],e[r]);I.push(P),F=F.concat(P)}for(let t=0;t<p;t++){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=N(A[t],B[t],i);z(e.x,e.y,-s)}for(let t=0,e=S.length;t<e;t++){const e=S[t];P=I[t];for(let t=0,r=e.length;t<r;t++){const r=N(e[t],P[t],i);z(r.x,r.y,-s)}}}const U=c+d;for(let t=0;t<C;t++){const e=u?N(w[t],F[t],U):w[t];T?(b.copy(y.normals[0]).multiplyScalar(e.x),x.copy(y.binormals[0]).multiplyScalar(e.y),v.copy(f[0]).add(b).add(x),z(v.x,v.y,v.z)):z(e.x,e.y,0)}for(let t=1;t<=a;t++)for(let e=0;e<C;e++){const s=u?N(w[e],F[e],U):w[e];T?(b.copy(y.normals[t]).multiplyScalar(s.x),x.copy(y.binormals[t]).multiplyScalar(s.y),v.copy(f[t]).add(b).add(x),z(v.x,v.y,v.z)):z(s.x,s.y,h/a*t)}for(let t=p-1;t>=0;t--){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=N(A[t],B[t],i);z(e.x,e.y,h+s)}for(let t=0,e=S.length;t<e;t++){const e=S[t];P=I[t];for(let t=0,r=e.length;t<r;t++){const r=N(e[t],P[t],i);T?z(r.x,r.y+f[a-1].y,f[a-1].x+s):z(r.x,r.y,h+s)}}}function O(t,e){let s=t.length;for(;--s>=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t<s;t++){const s=C*t,n=C*(t+1);V(e+i+s,e+r+s,e+r+n,e+i+n)}}}function z(t,e,s){n.push(t),n.push(e),n.push(s)}function L(t,e,r){D(t),D(e),D(r);const n=i.length/3,o=g.generateTopUV(s,i,n-3,n-2,n-1);k(o[0]),k(o[1]),k(o[2])}function V(t,e,r,n){D(t),D(e),D(n),D(e),D(r),D(n);const o=i.length/3,a=g.generateSideWallUV(s,i,o-6,o-3,o-2,o-1);k(a[0]),k(a[1]),k(a[3]),k(a[1]),k(a[2]),k(a[3])}function D(t){i.push(n[3*t+0]),i.push(n[3*t+1]),i.push(n[3*t+2])}function k(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(u){let t=0,e=C*t;for(let t=0;t<R;t++){const s=M[t];L(s[2]+e,s[1]+e,s[0]+e)}t=a+2*p,e=C*t;for(let t=0;t<R;t++){const s=M[t];L(s[0]+e,s[1]+e,s[2]+e)}}else{for(let t=0;t<R;t++){const e=M[t];L(e[2],e[1],e[0])}for(let t=0;t<R;t++){const e=M[t];L(e[0]+C*a,e[1]+C*a,e[2]+C*a)}}s.addGroup(t,i.length/3-t,0)}(),function(){const t=i.length/3;let e=0;O(A,e),e+=A.length;for(let t=0,s=S.length;t<s;t++){const s=S[t];O(s,e),e+=s.length}s.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new fn(i,3)),this.setAttribute("uv",new fn(r,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,s){if(s.shapes=[],Array.isArray(t))for(let e=0,i=t.length;e<i;e++){const i=t[e];s.shapes.push(i.uuid)}else s.shapes.push(t.uuid);s.options=Object.assign({},e),void 0!==e.extrudePath&&(s.options.extrudePath=e.extrudePath.toJSON());return s}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const s=[];for(let i=0,r=t.shapes.length;i<r;i++){const r=e[t.shapes[i]];s.push(r)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new dh[i.type]).fromJSON(i)),new su(s,t.options)}}const iu={generateTopUV:function(t,e,s,i,r){const n=e[3*s],o=e[3*s+1],a=e[3*i],h=e[3*i+1],u=e[3*r],l=e[3*r+1];return[new Ys(n,o),new Ys(a,h),new Ys(u,l)]},generateSideWallUV:function(t,e,s,i,r,n){const o=e[3*s],a=e[3*s+1],h=e[3*s+2],u=e[3*i],l=e[3*i+1],c=e[3*i+2],d=e[3*r],p=e[3*r+1],m=e[3*r+2],g=e[3*n],f=e[3*n+1],y=e[3*n+2];return Math.abs(a-l)<Math.abs(o-u)?[new Ys(o,1-h),new Ys(u,1-c),new Ys(d,1-m),new Ys(g,1-y)]:[new Ys(a,1-h),new Ys(l,1-c),new Ys(p,1-m),new Ys(f,1-y)]}};class ru extends vh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2;super([-1,s,0,1,s,0,-1,-s,0,1,-s,0,0,-1,s,0,1,s,0,-1,-s,0,1,-s,s,0,-1,s,0,1,-s,0,-1,-s,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],t,e),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new ru(t.radius,t.detail)}}class nu extends vh{constructor(t=1,e=0){super([1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],t,e),this.type="OctahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new nu(t.radius,t.detail)}}class ou extends Sn{constructor(t=1,e=1,s=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:s,heightSegments:i};const r=t/2,n=e/2,o=Math.floor(s),a=Math.floor(i),h=o+1,u=a+1,l=t/o,c=e/a,d=[],p=[],m=[],g=[];for(let t=0;t<u;t++){const e=t*c-n;for(let s=0;s<h;s++){const i=s*l-r;p.push(i,-e,0),m.push(0,0,1),g.push(s/o),g.push(1-t/a)}}for(let t=0;t<a;t++)for(let e=0;e<o;e++){const s=e+h*t,i=e+h*(t+1),r=e+1+h*(t+1),n=e+1+h*t;d.push(s,i,n),d.push(i,r,n)}this.setIndex(d),this.setAttribute("position",new fn(p,3)),this.setAttribute("normal",new fn(m,3)),this.setAttribute("uv",new fn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ou(t.width,t.height,t.widthSegments,t.heightSegments)}}class au extends Sn{constructor(t=.5,e=1,s=32,i=1,r=0,n=2*Math.PI){super(),this.type="RingGeometry",this.parameters={innerRadius:t,outerRadius:e,thetaSegments:s,phiSegments:i,thetaStart:r,thetaLength:n},s=Math.max(3,s);const o=[],a=[],h=[],u=[];let l=t;const c=(e-t)/(i=Math.max(1,i)),d=new Ai,p=new Ys;for(let t=0;t<=i;t++){for(let t=0;t<=s;t++){const i=r+t/s*n;d.x=l*Math.cos(i),d.y=l*Math.sin(i),a.push(d.x,d.y,d.z),h.push(0,0,1),p.x=(d.x/e+1)/2,p.y=(d.y/e+1)/2,u.push(p.x,p.y)}l+=c}for(let t=0;t<i;t++){const e=t*(s+1);for(let t=0;t<s;t++){const i=t+e,r=i,n=i+s+1,a=i+s+2,h=i+1;o.push(r,n,h),o.push(n,a,h)}}this.setIndex(o),this.setAttribute("position",new fn(a,3)),this.setAttribute("normal",new fn(h,3)),this.setAttribute("uv",new fn(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new au(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class hu extends Sn{constructor(t=new Nh([new Ys(0,.5),new Ys(-.5,-.5),new Ys(.5,-.5)]),e=12){super(),this.type="ShapeGeometry",this.parameters={shapes:t,curveSegments:e};const s=[],i=[],r=[],n=[];let o=0,a=0;if(!1===Array.isArray(t))h(t);else for(let e=0;e<t.length;e++)h(t[e]),this.addGroup(o,a,e),o+=a,a=0;function h(t){const o=i.length/3,h=t.extractPoints(e);let u=h.shape;const l=h.holes;!1===Qh.isClockWise(u)&&(u=u.reverse());for(let t=0,e=l.length;t<e;t++){const e=l[t];!0===Qh.isClockWise(e)&&(l[t]=e.reverse())}const c=Qh.triangulateShape(u,l);for(let t=0,e=l.length;t<e;t++){const e=l[t];u=u.concat(e)}for(let t=0,e=u.length;t<e;t++){const e=u[t];i.push(e.x,e.y,0),r.push(0,0,1),n.push(e.x,e.y)}for(let t=0,e=c.length;t<e;t++){const e=c[t],i=e[0]+o,r=e[1]+o,n=e[2]+o;s.push(i,r,n),a+=3}}this.setIndex(s),this.setAttribute("position",new fn(i,3)),this.setAttribute("normal",new fn(r,3)),this.setAttribute("uv",new fn(n,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e){if(e.shapes=[],Array.isArray(t))for(let s=0,i=t.length;s<i;s++){const i=t[s];e.shapes.push(i.uuid)}else e.shapes.push(t.uuid);return e}(this.parameters.shapes,t)}static fromJSON(t,e){const s=[];for(let i=0,r=t.shapes.length;i<r;i++){const r=e[t.shapes[i]];s.push(r)}return new hu(s,t.curveSegments)}}class uu extends Sn{constructor(t=1,e=32,s=16,i=0,r=2*Math.PI,n=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:s,phiStart:i,phiLength:r,thetaStart:n,thetaLength:o},e=Math.max(3,Math.floor(e)),s=Math.max(2,Math.floor(s));const a=Math.min(n+o,Math.PI);let h=0;const u=[],l=new Ai,c=new Ai,d=[],p=[],m=[],g=[];for(let d=0;d<=s;d++){const f=[],y=d/s;let x=0;0===d&&0===n?x=.5/e:d===s&&a===Math.PI&&(x=-.5/e);for(let s=0;s<=e;s++){const a=s/e;l.x=-t*Math.cos(i+a*r)*Math.sin(n+y*o),l.y=t*Math.cos(n+y*o),l.z=t*Math.sin(i+a*r)*Math.sin(n+y*o),p.push(l.x,l.y,l.z),c.copy(l).normalize(),m.push(c.x,c.y,c.z),g.push(a+x,1-y),f.push(h++)}u.push(f)}for(let t=0;t<s;t++)for(let i=0;i<e;i++){const e=u[t][i+1],r=u[t][i],o=u[t+1][i],h=u[t+1][i+1];(0!==t||n>0)&&d.push(e,r,h),(t!==s-1||a<Math.PI)&&d.push(r,o,h)}this.setIndex(d),this.setAttribute("position",new fn(p,3)),this.setAttribute("normal",new fn(m,3)),this.setAttribute("uv",new fn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new uu(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class lu extends vh{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e),this.type="TetrahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new lu(t.radius,t.detail)}}class cu extends Sn{constructor(t=1,e=.4,s=12,i=48,r=2*Math.PI){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:s,tubularSegments:i,arc:r},s=Math.floor(s),i=Math.floor(i);const n=[],o=[],a=[],h=[],u=new Ai,l=new Ai,c=new Ai;for(let n=0;n<=s;n++)for(let d=0;d<=i;d++){const p=d/i*r,m=n/s*Math.PI*2;l.x=(t+e*Math.cos(m))*Math.cos(p),l.y=(t+e*Math.cos(m))*Math.sin(p),l.z=e*Math.sin(m),o.push(l.x,l.y,l.z),u.x=t*Math.cos(p),u.y=t*Math.sin(p),c.subVectors(l,u).normalize(),a.push(c.x,c.y,c.z),h.push(d/i),h.push(n/s)}for(let t=1;t<=s;t++)for(let e=1;e<=i;e++){const s=(i+1)*t+e-1,r=(i+1)*(t-1)+e-1,o=(i+1)*(t-1)+e,a=(i+1)*t+e;n.push(s,r,a),n.push(r,o,a)}this.setIndex(n),this.setAttribute("position",new fn(o,3)),this.setAttribute("normal",new fn(a,3)),this.setAttribute("uv",new fn(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new cu(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class du extends Sn{constructor(t=1,e=.4,s=64,i=8,r=2,n=3){super(),this.type="TorusKnotGeometry",this.parameters={radius:t,tube:e,tubularSegments:s,radialSegments:i,p:r,q:n},s=Math.floor(s),i=Math.floor(i);const o=[],a=[],h=[],u=[],l=new Ai,c=new Ai,d=new Ai,p=new Ai,m=new Ai,g=new Ai,f=new Ai;for(let o=0;o<=s;++o){const x=o/s*r*Math.PI*2;y(x,r,n,t,d),y(x+.01,r,n,t,p),g.subVectors(p,d),f.addVectors(p,d),m.crossVectors(g,f),f.crossVectors(m,g),m.normalize(),f.normalize();for(let t=0;t<=i;++t){const r=t/i*Math.PI*2,n=-e*Math.cos(r),p=e*Math.sin(r);l.x=d.x+(n*f.x+p*m.x),l.y=d.y+(n*f.y+p*m.y),l.z=d.z+(n*f.z+p*m.z),a.push(l.x,l.y,l.z),c.subVectors(l,d).normalize(),h.push(c.x,c.y,c.z),u.push(o/s),u.push(t/i)}}for(let t=1;t<=s;t++)for(let e=1;e<=i;e++){const s=(i+1)*(t-1)+(e-1),r=(i+1)*t+(e-1),n=(i+1)*t+e,a=(i+1)*(t-1)+e;o.push(s,r,a),o.push(r,n,a)}function y(t,e,s,i,r){const n=Math.cos(t),o=Math.sin(t),a=s/e*t,h=Math.cos(a);r.x=i*(2+h)*.5*n,r.y=i*(2+h)*o*.5,r.z=i*Math.sin(a)*.5}this.setIndex(o),this.setAttribute("position",new fn(a,3)),this.setAttribute("normal",new fn(h,3)),this.setAttribute("uv",new fn(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new du(t.radius,t.tube,t.tubularSegments,t.radialSegments,t.p,t.q)}}class pu extends Sn{constructor(t=new lh(new Ai(-1,-1,0),new Ai(-1,1,0),new Ai(1,1,0)),e=64,s=1,i=8,r=!1){super(),this.type="TubeGeometry",this.parameters={path:t,tubularSegments:e,radius:s,radialSegments:i,closed:r};const n=t.computeFrenetFrames(e,r);this.tangents=n.tangents,this.normals=n.normals,this.binormals=n.binormals;const o=new Ai,a=new Ai,h=new Ys;let u=new Ai;const l=[],c=[],d=[],p=[];function m(r){u=t.getPointAt(r/e,u);const h=n.normals[r],d=n.binormals[r];for(let t=0;t<=i;t++){const e=t/i*Math.PI*2,r=Math.sin(e),n=-Math.cos(e);a.x=n*h.x+r*d.x,a.y=n*h.y+r*d.y,a.z=n*h.z+r*d.z,a.normalize(),c.push(a.x,a.y,a.z),o.x=u.x+s*a.x,o.y=u.y+s*a.y,o.z=u.z+s*a.z,l.push(o.x,o.y,o.z)}}!function(){for(let t=0;t<e;t++)m(t);m(!1===r?e:0),function(){for(let t=0;t<=e;t++)for(let s=0;s<=i;s++)h.x=t/e,h.y=s/i,d.push(h.x,h.y)}(),function(){for(let t=1;t<=e;t++)for(let e=1;e<=i;e++){const s=(i+1)*(t-1)+(e-1),r=(i+1)*t+(e-1),n=(i+1)*t+e,o=(i+1)*(t-1)+e;p.push(s,r,o),p.push(r,n,o)}}()}(),this.setIndex(p),this.setAttribute("position",new fn(l,3)),this.setAttribute("normal",new fn(c,3)),this.setAttribute("uv",new fn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return t.path=this.parameters.path.toJSON(),t}static fromJSON(t){return new pu((new dh[t.path.type]).fromJSON(t.path),t.tubularSegments,t.radius,t.radialSegments,t.closed)}}class mu extends Sn{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},null!==t){const e=[],s=new Set,i=new Ai,r=new Ai;if(null!==t.index){const n=t.attributes.position,o=t.index;let a=t.groups;0===a.length&&(a=[{start:0,count:o.count,materialIndex:0}]);for(let t=0,h=a.length;t<h;++t){const h=a[t],u=h.start;for(let t=u,a=u+h.count;t<a;t+=3)for(let a=0;a<3;a++){const h=o.getX(t+a),u=o.getX(t+(a+1)%3);i.fromBufferAttribute(n,h),r.fromBufferAttribute(n,u),!0===gu(i,r,s)&&(e.push(i.x,i.y,i.z),e.push(r.x,r.y,r.z))}}}else{const n=t.attributes.position;for(let t=0,o=n.count/3;t<o;t++)for(let o=0;o<3;o++){const a=3*t+o,h=3*t+(o+1)%3;i.fromBufferAttribute(n,a),r.fromBufferAttribute(n,h),!0===gu(i,r,s)&&(e.push(i.x,i.y,i.z),e.push(r.x,r.y,r.z))}}this.setAttribute("position",new fn(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function gu(t,e,s){const i=`${t.x},${t.y},${t.z}-${e.x},${e.y},${e.z}`,r=`${e.x},${e.y},${e.z}-${t.x},${t.y},${t.z}`;return!0!==s.has(i)&&!0!==s.has(r)&&(s.add(i),s.add(r),!0)}var fu=Object.freeze({__proto__:null,BoxGeometry:Ln,CapsuleGeometry:fh,CircleGeometry:yh,ConeGeometry:bh,CylinderGeometry:xh,DodecahedronGeometry:Th,EdgesGeometry:Ah,ExtrudeGeometry:su,IcosahedronGeometry:ru,LatheGeometry:gh,OctahedronGeometry:nu,PlaneGeometry:ou,PolyhedronGeometry:vh,RingGeometry:au,ShapeGeometry:hu,SphereGeometry:uu,TetrahedronGeometry:lu,TorusGeometry:cu,TorusKnotGeometry:du,TubeGeometry:pu,WireframeGeometry:mu});class yu extends Jr{static get type(){return"ShadowMaterial"}constructor(t){super(),this.isShadowMaterial=!0,this.color=new Xr(0),this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.fog=t.fog,this}}class xu extends Dn{static get type(){return"RawShaderMaterial"}constructor(t){super(t),this.isRawShaderMaterial=!0}}class bu extends Jr{static get type(){return"MeshStandardMaterial"}constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.color=new Xr(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 Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class vu extends bu{static get type(){return"MeshPhysicalMaterial"}constructor(t){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new Ys(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Ws(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 Xr(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 Xr(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new Xr(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(t)}get anisotropy(){return this._anisotropy}set anisotropy(t){this._anisotropy>0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class Tu extends Jr{static get type(){return"MeshPhongMaterial"}constructor(t){super(),this.isMeshPhongMaterial=!0,this.color=new Xr(16777215),this.specular=new Xr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class _u extends Jr{static get type(){return"MeshToonMaterial"}constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.color=new Xr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class wu extends Jr{static get type(){return"MeshNormalMaterial"}constructor(t){super(),this.isMeshNormalMaterial=!0,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class Su extends Jr{static get type(){return"MeshLambertMaterial"}constructor(t){super(),this.isMeshLambertMaterial=!0,this.color=new Xr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Xr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new dr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Mu extends Jr{static get type(){return"MeshDepthMaterial"}constructor(t){super(),this.isMeshDepthMaterial=!0,this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Au extends Jr{static get type(){return"MeshDistanceMaterial"}constructor(t){super(),this.isMeshDistanceMaterial=!0,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class Nu extends Jr{static get type(){return"MeshMatcapMaterial"}constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.color=new Xr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ys(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Cu extends xa{static get type(){return"LineDashedMaterial"}constructor(t){super(),this.isLineDashedMaterial=!0,this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function Ru(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Eu(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Bu(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Iu(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Pu(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const Fu={convertArray:Ru,isTypedArray:Eu,getKeyframeOrder:Bu,sortedArray:Iu,flattenJSON:Pu,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t<n.tracks.length;++t){const e=n.tracks[t],a=e.getValueSize(),h=[],u=[];for(let t=0;t<e.times.length;++t){const n=e.times[t]*r;if(!(n<s||n>=i)){h.push(e.times[t]);for(let s=0;s<a;++s)u.push(e.values[t*a+s])}}0!==h.length&&(e.times=Ru(h,e.times.constructor),e.values=Ru(u,e.values.constructor),o.push(e))}n.tracks=o;let a=1/0;for(let t=0;t<n.tracks.length;++t)a>n.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t<n.tracks.length;++t)n.tracks[t].shift(-1*a);return n.resetDuration(),n},makeClipAdditive:function(t,e=0,s=t,i=30){i<=0&&(i=30);const r=s.tracks.length,n=e/i;for(let e=0;e<r;++e){const i=s.tracks[e],r=i.ValueTypeName;if("bool"===r||"string"===r)continue;const o=t.tracks.find((function(t){return t.name===i.name&&t.ValueTypeName===r}));if(void 0===o)continue;let a=0;const h=i.getValueSize();i.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(a=h/3);let u=0;const l=o.getValueSize();o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(u=l/3);const c=i.times.length-1;let d;if(n<=i.times[0]){const t=a,e=h-a;d=i.values.slice(t,e)}else if(n>=i.times[c]){const t=c*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Mi).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t<p;++t){const e=t*l+u;if("quaternion"===r)Mi.multiplyQuaternionsFlat(o.values,e,d,0,o.values,e);else{const t=l-2*u;for(let s=0;s<t;++s)o.values[e+s]-=d[s]}}}return t.blendMode=Ve,t}};class Uu{constructor(t,e,s,i){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=void 0!==i?i:new e.constructor(s),this.sampleValues=e,this.valueSize=s,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let s=this._cachedIndex,i=e[s],r=e[s-1];t:{e:{let n;s:{i:if(!(t<i)){for(let n=s+2;;){if(void 0===i){if(t<r)break i;return s=e.length,this._cachedIndex=s,this.copySampleValue_(s-1)}if(s===n)break;if(r=i,i=e[++s],t<i)break e}n=e.length;break s}if(t>=r)break t;{const o=e[1];t<o&&(s=2,r=o);for(let n=s-2;;){if(void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(s===n)break;if(i=r,r=e[--s-1],t>=r)break e}n=s,s=0}}for(;s<n;){const i=s+n>>>1;t<e[i]?n=i:s=i+1}if(i=e[s],r=e[s-1],void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(void 0===i)return s=e.length,this._cachedIndex=s,this.copySampleValue_(s-1)}this._cachedIndex=s,this.intervalChanged_(s,r,i)}return this.interpolate_(s,r,t,i)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,s=this.sampleValues,i=this.valueSize,r=t*i;for(let t=0;t!==i;++t)e[t]=s[r+t];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}class Ou extends Uu{constructor(t,e,s,i){super(t,e,s,i),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Ue,endingEnd:Ue}}intervalChanged_(t,e,s){const i=this.parameterPositions;let r=t-2,n=t+1,o=i[r],a=i[n];if(void 0===o)switch(this.getSettings_().endingStart){case Oe:r=t,o=2*e-s;break;case ze:r=i.length-2,o=e+i[r]-i[r+1];break;default:r=t,o=s}if(void 0===a)switch(this.getSettings_().endingEnd){case Oe:n=t,a=2*s-e;break;case ze:n=1,a=s+i[1]-i[0];break;default:n=t-1,a=e}const h=.5*(s-e),u=this.valueSize;this._weightPrev=h/(e-o),this._weightNext=h/(a-s),this._offsetPrev=r*u,this._offsetNext=n*u}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=t*o,h=a-o,u=this._offsetPrev,l=this._offsetNext,c=this._weightPrev,d=this._weightNext,p=(s-e)/(i-e),m=p*p,g=m*p,f=-c*g+2*c*m-c*p,y=(1+c)*g+(-1.5-2*c)*m+(-.5+c)*p+1,x=(-1-d)*g+(1.5+d)*m+.5*p,b=d*g-d*m;for(let t=0;t!==o;++t)r[t]=f*n[u+t]+y*n[h+t]+x*n[a+t]+b*n[l+t];return r}}class zu extends Uu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=t*o,h=a-o,u=(s-e)/(i-e),l=1-u;for(let t=0;t!==o;++t)r[t]=n[h+t]*l+n[a+t]*u;return r}}class Lu extends Uu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t){return this.copySampleValue_(t-1)}}class Vu{constructor(t,e,s,i){if(void 0===t)throw new Error("THREE.KeyframeTrack: track name is undefined");if(void 0===e||0===e.length)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=Ru(e,this.TimeBufferType),this.values=Ru(s,this.ValueBufferType),this.setInterpolation(i||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let s;if(e.toJSON!==this.toJSON)s=e.toJSON(t);else{s={name:t.name,times:Ru(t.times,Array),values:Ru(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(s.interpolation=e)}return s.type=t.ValueTypeName,s}InterpolantFactoryMethodDiscrete(t){return new Lu(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new zu(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Ou(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case Ie:e=this.InterpolantFactoryMethodDiscrete;break;case Pe:e=this.InterpolantFactoryMethodLinear;break;case Fe:e=this.InterpolantFactoryMethodSmooth}if(void 0===e){const e="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(void 0===this.createInterpolant){if(t===this.DefaultInterpolation)throw new Error(e);this.setInterpolation(this.DefaultInterpolation)}return console.warn("THREE.KeyframeTrack:",e),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Ie;case this.InterpolantFactoryMethodLinear:return Pe;case this.InterpolantFactoryMethodSmooth:return Fe}}getValueSize(){return this.values.length/this.times.length}shift(t){if(0!==t){const e=this.times;for(let s=0,i=e.length;s!==i;++s)e[s]+=t}return this}scale(t){if(1!==t){const e=this.times;for(let s=0,i=e.length;s!==i;++s)e[s]*=t}return this}trim(t,e){const s=this.times,i=s.length;let r=0,n=i-1;for(;r!==i&&s[r]<t;)++r;for(;-1!==n&&s[n]>e;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&Eu(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Fe,r=t.length-1;let n=1;for(let o=1;o<r;++o){let r=!1;const a=t[o];if(a!==t[o+1]&&(1!==o||a!==t[0]))if(i)r=!0;else{const t=o*s,i=t-s,n=t+s;for(let o=0;o!==s;++o){const s=e[t+o];if(s!==e[i+o]||s!==e[n+o]){r=!0;break}}}if(r){if(o!==n){t[n]=t[o];const i=o*s,r=n*s;for(let t=0;t!==s;++t)e[r+t]=e[i+t]}++n}}if(r>0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}Vu.prototype.TimeBufferType=Float32Array,Vu.prototype.ValueBufferType=Float32Array,Vu.prototype.DefaultInterpolation=Pe;class Du extends Vu{constructor(t,e,s){super(t,e,s)}}Du.prototype.ValueTypeName="bool",Du.prototype.ValueBufferType=Array,Du.prototype.DefaultInterpolation=Ie,Du.prototype.InterpolantFactoryMethodLinear=void 0,Du.prototype.InterpolantFactoryMethodSmooth=void 0;class ku extends Vu{}ku.prototype.ValueTypeName="color";class Gu extends Vu{}Gu.prototype.ValueTypeName="number";class Wu extends Uu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Mi.slerpFlat(r,0,n,h-o,n,h,a);return r}}class ju extends Vu{InterpolantFactoryMethodLinear(t){return new Wu(this.times,this.values,this.getValueSize(),t)}}ju.prototype.ValueTypeName="quaternion",ju.prototype.InterpolantFactoryMethodSmooth=void 0;class Hu extends Vu{constructor(t,e,s){super(t,e,s)}}Hu.prototype.ValueTypeName="string",Hu.prototype.ValueBufferType=Array,Hu.prototype.DefaultInterpolation=Ie,Hu.prototype.InterpolantFactoryMethodLinear=void 0,Hu.prototype.InterpolantFactoryMethodSmooth=void 0;class $u extends Vu{}$u.prototype.ValueTypeName="vector";class qu{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=Gs(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(Xu(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(Vu.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t<r;t++){let o=[],a=[];o.push((t+r-1)%r,t,(t+1)%r),a.push(0,1,0);const h=Bu(o);o=Iu(o,1,h),a=Iu(a,1,h),i||0!==o[0]||(o.push(r),a.push(a[0])),n.push(new Gu(".morphTargetInfluences["+e[t].name+"]",o,a).scale(1/s))}return new this(t,-1,n)}static findByName(t,e){let s=t;if(!Array.isArray(t)){const e=t;s=e.geometry&&e.geometry.animations||e.animations}for(let t=0;t<s.length;t++)if(s[t].name===e)return s[t];return null}static CreateClipsFromMorphTargetSequences(t,e,s){const i={},r=/^([\w-]*?)([\d]+)$/;for(let e=0,s=t.length;e<s;e++){const s=t[e],n=s.name.match(r);if(n&&n.length>1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Pu(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t<h.length;t++){const r=h[t].keys;if(r&&0!==r.length)if(r[0].morphTargets){const t={};let e;for(e=0;e<r.length;e++)if(r[e].morphTargets)for(let s=0;s<r[e].morphTargets.length;s++)t[r[e].morphTargets[s]]=-1;for(const s in t){const t=[],n=[];for(let i=0;i!==r[e].morphTargets.length;++i){const i=r[e];t.push(i.time),n.push(i.morphTarget===s?1:0)}i.push(new Gu(".morphTargetInfluence["+s+"]",t,n))}a=t.length*n}else{const n=".bones["+e[t].name+"]";s($u,n+".position",r,"pos",i),s(ju,n+".quaternion",r,"rot",i),s($u,n+".scale",r,"scl",i)}}if(0===i.length)return null;return new this(r,a,i,o)}resetDuration(){let t=0;for(let e=0,s=this.tracks.length;e!==s;++e){const s=this.tracks[e];t=Math.max(t,s.times[s.times.length-1])}return this.duration=t,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let e=0;e<this.tracks.length;e++)t.push(this.tracks[e].clone());return new this.constructor(this.name,this.duration,t,this.blendMode)}toJSON(){return this.constructor.toJSON(this)}}function Xu(t){if(void 0===t.type)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=function(t){switch(t.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Gu;case"vector":case"vector2":case"vector3":case"vector4":return $u;case"color":return ku;case"quaternion":return ju;case"bool":case"boolean":return Du;case"string":return Hu}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],s=[];Pu(t.keys,e,s,"value"),t.times=e,t.values=s}return void 0!==e.parse?e.parse(t):new e(t.name,t.times,t.values,t.interpolation)}const Yu={enabled:!1,files:{},add:function(t,e){!1!==this.enabled&&(this.files[t]=e)},get:function(t){if(!1!==this.enabled)return this.files[t]},remove:function(t){delete this.files[t]},clear:function(){this.files={}}};class Zu{constructor(t,e,s){const i=this;let r,n=!1,o=0,a=0;const h=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=s,this.itemStart=function(t){a++,!1===n&&void 0!==i.onStart&&i.onStart(t,o,a),n=!0},this.itemEnd=function(t){o++,void 0!==i.onProgress&&i.onProgress(t,o,a),o===a&&(n=!1,void 0!==i.onLoad&&i.onLoad())},this.itemError=function(t){void 0!==i.onError&&i.onError(t)},this.resolveURL=function(t){return r?r(t):t},this.setURLModifier=function(t){return r=t,this},this.addHandler=function(t,e){return h.push(t,e),this},this.removeHandler=function(t){const e=h.indexOf(t);return-1!==e&&h.splice(e,2),this},this.getHandler=function(t){for(let e=0,s=h.length;e<s;e+=2){const s=h[e],i=h[e+1];if(s.global&&(s.lastIndex=0),s.test(t))return i}return null}}}const Ju=new Zu;class Ku{constructor(t){this.manager=void 0!==t?t:Ju,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const s=this;return new Promise((function(i,r){s.load(t,i,e,r)}))}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}}Ku.DEFAULT_MATERIAL_NAME="__DEFAULT";const Qu={};class tl extends Error{constructor(t,e){super(t),this.response=e}}class el extends Ku{constructor(t){super(t)}load(t,e,s,i){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=Yu.get(t);if(void 0!==r)return this.manager.itemStart(t),setTimeout((()=>{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==Qu[t])return void Qu[t].push({onLoad:e,onProgress:s,onError:i});Qu[t]=[],Qu[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const s=Qu[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t<e;t++){const e=s[t];e.onProgress&&e.onProgress(i)}t.enqueue(r),e()}}),(e=>{t.error(e)}))}()}});return new Response(h)}throw new tl(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{Yu.add(t,e);const s=Qu[t];delete Qu[t];for(let t=0,i=s.length;t<i;t++){const i=s[t];i.onLoad&&i.onLoad(e)}})).catch((e=>{const s=Qu[t];if(void 0===s)throw this.manager.itemError(t),e;delete Qu[t];for(let t=0,i=s.length;t<i;t++){const i=s[t];i.onError&&i.onError(e)}this.manager.itemError(t)})).finally((()=>{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class sl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new el(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s<t.length;s++){const i=qu.parse(t[s]);e.push(i)}return e}}class il extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=[],o=new Ga,a=new el(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(r.withCredentials);let h=0;function u(u){a.load(t[u],(function(t){const s=r.parse(t,!0);n[u]={width:s.width,height:s.height,format:s.format,mipmaps:s.mipmaps},h+=1,6===h&&(1===s.mipmapCount&&(o.minFilter=Tt),o.image=n,o.format=s.format,o.needsUpdate=!0,e&&e(o))}),s,i)}if(Array.isArray(t))for(let e=0,s=t.length;e<s;++e)u(e);else a.load(t,(function(t){const s=r.parse(t,!0);if(s.isCubemap){const t=s.mipmaps.length/s.mipmapCount;for(let e=0;e<t;e++){n[e]={mipmaps:[]};for(let t=0;t<s.mipmapCount;t++)n[e].mipmaps.push(s.mipmaps[e*s.mipmapCount+t]),n[e].format=s.format,n[e].width=s.width,n[e].height=s.height}o.image=n}else o.image.width=s.width,o.image.height=s.height,o.mipmaps=s.mipmaps;1===s.mipmapCount&&(o.minFilter=Tt),o.format=s.format,o.needsUpdate=!0,e&&e(o)}),s,i);return o}}class rl extends Ku{constructor(t){super(t)}load(t,e,s,i){void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,n=Yu.get(t);if(void 0!==n)return r.manager.itemStart(t),setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n;const o=ti("img");function a(){u(),Yu.add(t,this),e&&e(this),r.manager.itemEnd(t)}function h(e){u(),i&&i(e),r.manager.itemError(t),r.manager.itemEnd(t)}function u(){o.removeEventListener("load",a,!1),o.removeEventListener("error",h,!1)}return o.addEventListener("load",a,!1),o.addEventListener("error",h,!1),"data:"!==t.slice(0,5)&&void 0!==this.crossOrigin&&(o.crossOrigin=this.crossOrigin),r.manager.itemStart(t),o.src=t,o}}class nl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=new Xn;r.colorSpace=Ze;const n=new rl(this.manager);n.setCrossOrigin(this.crossOrigin),n.setPath(this.path);let o=0;function a(s){n.load(t[s],(function(t){r.images[s]=t,o++,6===o&&(r.needsUpdate=!0,e&&e(r))}),void 0,i)}for(let e=0;e<t.length;++e)a(e);return r}}class ol extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new Po,o=new el(this.manager);return o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(r.withCredentials),o.load(t,(function(t){let s;try{s=r.parse(t)}catch(t){if(void 0===i)return void console.error(t);i(t)}void 0!==s.image?n.image=s.image:void 0!==s.data&&(n.image.width=s.width,n.image.height=s.height,n.image.data=s.data),n.wrapS=void 0!==s.wrapS?s.wrapS:mt,n.wrapT=void 0!==s.wrapT?s.wrapT:mt,n.magFilter=void 0!==s.magFilter?s.magFilter:Tt,n.minFilter=void 0!==s.minFilter?s.minFilter:Tt,n.anisotropy=void 0!==s.anisotropy?s.anisotropy:1,void 0!==s.colorSpace&&(n.colorSpace=s.colorSpace),void 0!==s.flipY&&(n.flipY=s.flipY),void 0!==s.format&&(n.format=s.format),void 0!==s.type&&(n.type=s.type),void 0!==s.mipmaps&&(n.mipmaps=s.mipmaps,n.minFilter=St),1===s.mipmapCount&&(n.minFilter=Tt),void 0!==s.generateMipmaps&&(n.generateMipmaps=s.generateMipmaps),n.needsUpdate=!0,e&&e(n,s)}),s,i),n}}class al extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=new yi,n=new rl(this.manager);return n.setCrossOrigin(this.crossOrigin),n.setPath(this.path),n.load(t,(function(t){r.image=t,r.needsUpdate=!0,void 0!==e&&e(r)}),s,i),r}}class hl extends Rr{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Xr(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),void 0!==this.target&&(e.object.target=this.target.uuid),e}}class ul extends hl{constructor(t,e,s){super(t,s),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Rr.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Xr(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const ll=new sr,cl=new Ai,dl=new Ai;class pl{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Ys(512,512),this.map=null,this.mapPass=null,this.matrix=new sr,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ko,this._frameExtents=new Ys(1,1),this._viewportCount=1,this._viewports=[new xi(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,s=this.matrix;cl.setFromMatrixPosition(t.matrixWorld),e.position.copy(cl),dl.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(dl),e.updateMatrixWorld(),ll.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(ll),s.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),s.multiply(ll)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 1!==this.intensity&&(t.intensity=this.intensity),0!==this.bias&&(t.bias=this.bias),0!==this.normalBias&&(t.normalBias=this.normalBias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class ml extends pl{constructor(){super(new Hn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,s=2*ks*t.angle*this.focus,i=this.mapSize.width/this.mapSize.height,r=t.distance||e.far;s===e.fov&&i===e.aspect&&r===e.far||(e.fov=s,e.aspect=i,e.far=r,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class gl extends hl{constructor(t,e,s=0,i=Math.PI/3,r=0,n=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Rr.DEFAULT_UP),this.updateMatrix(),this.target=new Rr,this.distance=s,this.angle=i,this.penumbra=r,this.decay=n,this.map=null,this.shadow=new ml}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}const fl=new sr,yl=new Ai,xl=new Ai;class bl extends pl{constructor(){super(new Hn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new Ys(4,2),this._viewportCount=6,this._viewports=[new xi(2,1,1,1),new xi(0,1,1,1),new xi(3,1,1,1),new xi(1,1,1,1),new xi(3,0,1,1),new xi(1,0,1,1)],this._cubeDirections=[new Ai(1,0,0),new Ai(-1,0,0),new Ai(0,0,1),new Ai(0,0,-1),new Ai(0,1,0),new Ai(0,-1,0)],this._cubeUps=[new Ai(0,1,0),new Ai(0,1,0),new Ai(0,1,0),new Ai(0,1,0),new Ai(0,0,1),new Ai(0,0,-1)]}updateMatrices(t,e=0){const s=this.camera,i=this.matrix,r=t.distance||s.far;r!==s.far&&(s.far=r,s.updateProjectionMatrix()),yl.setFromMatrixPosition(t.matrixWorld),s.position.copy(yl),xl.copy(s.position),xl.add(this._cubeDirections[e]),s.up.copy(this._cubeUps[e]),s.lookAt(xl),s.updateMatrixWorld(),i.makeTranslation(-yl.x,-yl.y,-yl.z),fl.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),this._frustum.setFromProjectionMatrix(fl)}}class vl extends hl{constructor(t,e,s=0,i=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=s,this.decay=i,this.shadow=new bl}get power(){return 4*this.intensity*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}class Tl extends kn{constructor(t=-1,e=1,s=1,i=-1,r=.1,n=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=s,this.bottom=i,this.near=r,this.far=n,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,s,i,r,n){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),s=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=s-t,n=s+t,o=i+e,a=i-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=t*this.view.offsetX,n=r+t*this.view.width,o-=e*this.view.offsetY,a=o-e*this.view.height}this.projectionMatrix.makeOrthographic(r,n,o,a,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}class _l extends pl{constructor(){super(new Tl(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class wl extends hl{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Rr.DEFAULT_UP),this.updateMatrix(),this.target=new Rr,this.shadow=new _l}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Sl extends hl{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class Ml extends hl{constructor(t,e,s=10,i=10){super(t,e),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(t){this.intensity=t/(this.width*this.height*Math.PI)}copy(t){return super.copy(t),this.width=t.width,this.height=t.height,this}toJSON(t){const e=super.toJSON(t);return e.object.width=this.width,e.object.height=this.height,e}}class Al{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Ai)}set(t){for(let e=0;e<9;e++)this.coefficients[e].copy(t[e]);return this}zero(){for(let t=0;t<9;t++)this.coefficients[t].set(0,0,0);return this}getAt(t,e){const s=t.x,i=t.y,r=t.z,n=this.coefficients;return e.copy(n[0]).multiplyScalar(.282095),e.addScaledVector(n[1],.488603*i),e.addScaledVector(n[2],.488603*r),e.addScaledVector(n[3],.488603*s),e.addScaledVector(n[4],s*i*1.092548),e.addScaledVector(n[5],i*r*1.092548),e.addScaledVector(n[6],.315392*(3*r*r-1)),e.addScaledVector(n[7],s*r*1.092548),e.addScaledVector(n[8],.546274*(s*s-i*i)),e}getIrradianceAt(t,e){const s=t.x,i=t.y,r=t.z,n=this.coefficients;return e.copy(n[0]).multiplyScalar(.886227),e.addScaledVector(n[1],1.023328*i),e.addScaledVector(n[2],1.023328*r),e.addScaledVector(n[3],1.023328*s),e.addScaledVector(n[4],.858086*s*i),e.addScaledVector(n[5],.858086*i*r),e.addScaledVector(n[6],.743125*r*r-.247708),e.addScaledVector(n[7],.858086*s*r),e.addScaledVector(n[8],.429043*(s*s-i*i)),e}add(t){for(let e=0;e<9;e++)this.coefficients[e].add(t.coefficients[e]);return this}addScaledSH(t,e){for(let s=0;s<9;s++)this.coefficients[s].addScaledVector(t.coefficients[s],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let s=0;s<9;s++)this.coefficients[s].lerp(t.coefficients[s],e);return this}equals(t){for(let e=0;e<9;e++)if(!this.coefficients[e].equals(t.coefficients[e]))return!1;return!0}copy(t){return this.set(t.coefficients)}clone(){return(new this.constructor).copy(this)}fromArray(t,e=0){const s=this.coefficients;for(let i=0;i<9;i++)s[i].fromArray(t,e+3*i);return this}toArray(t=[],e=0){const s=this.coefficients;for(let i=0;i<9;i++)s[i].toArray(t,e+3*i);return t}static getBasisAt(t,e){const s=t.x,i=t.y,r=t.z;e[0]=.282095,e[1]=.488603*i,e[2]=.488603*r,e[3]=.488603*s,e[4]=1.092548*s*i,e[5]=1.092548*i*r,e[6]=.315392*(3*r*r-1),e[7]=1.092548*s*r,e[8]=.546274*(s*s-i*i)}}class Nl extends hl{constructor(t=new Al,e=1){super(void 0,e),this.isLightProbe=!0,this.sh=t}copy(t){return super.copy(t),this.sh.copy(t.sh),this}fromJSON(t){return this.intensity=t.intensity,this.sh.fromArray(t.sh),this}toJSON(t){const e=super.toJSON(t);return e.object.sh=this.sh.toArray(),e}}class Cl extends Ku{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=this,n=new el(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=this.textures;function s(t){return void 0===e[t]&&console.warn("THREE.MaterialLoader: Undefined texture",t),e[t]}const i=this.createMaterialFromType(t.type);if(void 0!==t.uuid&&(i.uuid=t.uuid),void 0!==t.name&&(i.name=t.name),void 0!==t.color&&void 0!==i.color&&i.color.setHex(t.color),void 0!==t.roughness&&(i.roughness=t.roughness),void 0!==t.metalness&&(i.metalness=t.metalness),void 0!==t.sheen&&(i.sheen=t.sheen),void 0!==t.sheenColor&&(i.sheenColor=(new Xr).setHex(t.sheenColor)),void 0!==t.sheenRoughness&&(i.sheenRoughness=t.sheenRoughness),void 0!==t.emissive&&void 0!==i.emissive&&i.emissive.setHex(t.emissive),void 0!==t.specular&&void 0!==i.specular&&i.specular.setHex(t.specular),void 0!==t.specularIntensity&&(i.specularIntensity=t.specularIntensity),void 0!==t.specularColor&&void 0!==i.specularColor&&i.specularColor.setHex(t.specularColor),void 0!==t.shininess&&(i.shininess=t.shininess),void 0!==t.clearcoat&&(i.clearcoat=t.clearcoat),void 0!==t.clearcoatRoughness&&(i.clearcoatRoughness=t.clearcoatRoughness),void 0!==t.dispersion&&(i.dispersion=t.dispersion),void 0!==t.iridescence&&(i.iridescence=t.iridescence),void 0!==t.iridescenceIOR&&(i.iridescenceIOR=t.iridescenceIOR),void 0!==t.iridescenceThicknessRange&&(i.iridescenceThicknessRange=t.iridescenceThicknessRange),void 0!==t.transmission&&(i.transmission=t.transmission),void 0!==t.thickness&&(i.thickness=t.thickness),void 0!==t.attenuationDistance&&(i.attenuationDistance=t.attenuationDistance),void 0!==t.attenuationColor&&void 0!==i.attenuationColor&&i.attenuationColor.setHex(t.attenuationColor),void 0!==t.anisotropy&&(i.anisotropy=t.anisotropy),void 0!==t.anisotropyRotation&&(i.anisotropyRotation=t.anisotropyRotation),void 0!==t.fog&&(i.fog=t.fog),void 0!==t.flatShading&&(i.flatShading=t.flatShading),void 0!==t.blending&&(i.blending=t.blending),void 0!==t.combine&&(i.combine=t.combine),void 0!==t.side&&(i.side=t.side),void 0!==t.shadowSide&&(i.shadowSide=t.shadowSide),void 0!==t.opacity&&(i.opacity=t.opacity),void 0!==t.transparent&&(i.transparent=t.transparent),void 0!==t.alphaTest&&(i.alphaTest=t.alphaTest),void 0!==t.alphaHash&&(i.alphaHash=t.alphaHash),void 0!==t.depthFunc&&(i.depthFunc=t.depthFunc),void 0!==t.depthTest&&(i.depthTest=t.depthTest),void 0!==t.depthWrite&&(i.depthWrite=t.depthWrite),void 0!==t.colorWrite&&(i.colorWrite=t.colorWrite),void 0!==t.blendSrc&&(i.blendSrc=t.blendSrc),void 0!==t.blendDst&&(i.blendDst=t.blendDst),void 0!==t.blendEquation&&(i.blendEquation=t.blendEquation),void 0!==t.blendSrcAlpha&&(i.blendSrcAlpha=t.blendSrcAlpha),void 0!==t.blendDstAlpha&&(i.blendDstAlpha=t.blendDstAlpha),void 0!==t.blendEquationAlpha&&(i.blendEquationAlpha=t.blendEquationAlpha),void 0!==t.blendColor&&void 0!==i.blendColor&&i.blendColor.setHex(t.blendColor),void 0!==t.blendAlpha&&(i.blendAlpha=t.blendAlpha),void 0!==t.stencilWriteMask&&(i.stencilWriteMask=t.stencilWriteMask),void 0!==t.stencilFunc&&(i.stencilFunc=t.stencilFunc),void 0!==t.stencilRef&&(i.stencilRef=t.stencilRef),void 0!==t.stencilFuncMask&&(i.stencilFuncMask=t.stencilFuncMask),void 0!==t.stencilFail&&(i.stencilFail=t.stencilFail),void 0!==t.stencilZFail&&(i.stencilZFail=t.stencilZFail),void 0!==t.stencilZPass&&(i.stencilZPass=t.stencilZPass),void 0!==t.stencilWrite&&(i.stencilWrite=t.stencilWrite),void 0!==t.wireframe&&(i.wireframe=t.wireframe),void 0!==t.wireframeLinewidth&&(i.wireframeLinewidth=t.wireframeLinewidth),void 0!==t.wireframeLinecap&&(i.wireframeLinecap=t.wireframeLinecap),void 0!==t.wireframeLinejoin&&(i.wireframeLinejoin=t.wireframeLinejoin),void 0!==t.rotation&&(i.rotation=t.rotation),void 0!==t.linewidth&&(i.linewidth=t.linewidth),void 0!==t.dashSize&&(i.dashSize=t.dashSize),void 0!==t.gapSize&&(i.gapSize=t.gapSize),void 0!==t.scale&&(i.scale=t.scale),void 0!==t.polygonOffset&&(i.polygonOffset=t.polygonOffset),void 0!==t.polygonOffsetFactor&&(i.polygonOffsetFactor=t.polygonOffsetFactor),void 0!==t.polygonOffsetUnits&&(i.polygonOffsetUnits=t.polygonOffsetUnits),void 0!==t.dithering&&(i.dithering=t.dithering),void 0!==t.alphaToCoverage&&(i.alphaToCoverage=t.alphaToCoverage),void 0!==t.premultipliedAlpha&&(i.premultipliedAlpha=t.premultipliedAlpha),void 0!==t.forceSinglePass&&(i.forceSinglePass=t.forceSinglePass),void 0!==t.visible&&(i.visible=t.visible),void 0!==t.toneMapped&&(i.toneMapped=t.toneMapped),void 0!==t.userData&&(i.userData=t.userData),void 0!==t.vertexColors&&("number"==typeof t.vertexColors?i.vertexColors=t.vertexColors>0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new Xr).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Ys).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ai).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new xi).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new Zs).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new sr).fromArray(r.value);break;default:i.uniforms[e].value=r.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new Ys).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Ys).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return Cl.createMaterialFromType(t)}static createMaterialFromType(t){return new{ShadowMaterial:yu,SpriteMaterial:so,RawShaderMaterial:xu,ShaderMaterial:Dn,PointsMaterial:Ia,MeshPhysicalMaterial:vu,MeshStandardMaterial:bu,MeshPhongMaterial:Tu,MeshToonMaterial:_u,MeshNormalMaterial:wu,MeshLambertMaterial:Su,MeshDepthMaterial:Mu,MeshDistanceMaterial:Au,MeshBasicMaterial:Kr,MeshMatcapMaterial:Nu,LineDashedMaterial:Cu,LineBasicMaterial:xa,Material:Jr}[t]}}class Rl{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let s=0,i=t.length;s<i;s++)e+=String.fromCharCode(t[s]);try{return decodeURIComponent(escape(e))}catch(t){return e}}static extractUrlBase(t){const e=t.lastIndexOf("/");return-1===e?"./":t.slice(0,e+1)}static resolveURL(t,e){return"string"!=typeof t||""===t?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class El extends Sn{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}toJSON(){const t=super.toJSON();return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}class Bl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new el(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e={},s={};function i(t,i){if(void 0!==e[i])return e[i];const r=t.interleavedBuffers[i],n=function(t,e){if(void 0!==s[e])return s[e];const i=t.arrayBuffers,r=i[e],n=new Uint32Array(r).buffer;return s[e]=n,n}(t,r.buffer),o=Qs(r.type,n),a=new Qn(o,r.stride);return a.uuid=r.uuid,e[i]=a,a}const r=t.isInstancedBufferGeometry?new El:new Sn,n=t.data.index;if(void 0!==n){const t=Qs(n.type,n.array);r.setIndex(new an(t,1))}const o=t.data.attributes;for(const e in o){const s=o[e];let n;if(s.isInterleavedBufferAttribute){const e=i(t.data,s.data);n=new eo(e,s.itemSize,s.offset,s.normalized)}else{const t=Qs(s.type,s.array);n=new(s.isInstancedBufferAttribute?zo:an)(t,s.itemSize,s.normalized)}void 0!==s.name&&(n.name=s.name),void 0!==s.usage&&n.setUsage(s.usage),r.setAttribute(e,n)}const a=t.data.morphAttributes;if(a)for(const e in a){const s=a[e],n=[];for(let e=0,r=s.length;e<r;e++){const r=s[e];let o;if(r.isInterleavedBufferAttribute){const e=i(t.data,r.data);o=new eo(e,r.itemSize,r.offset,r.normalized)}else{const t=Qs(r.type,r.array);o=new an(t,r.itemSize,r.normalized)}void 0!==r.name&&(o.name=r.name),n.push(o)}r.morphAttributes[e]=n}t.data.morphTargetsRelative&&(r.morphTargetsRelative=!0);const h=t.data.groups||t.data.drawcalls||t.data.offsets;if(void 0!==h)for(let t=0,e=h.length;t!==e;++t){const e=h[t];r.addGroup(e.start,e.count,e.materialIndex)}const u=t.data.boundingSphere;if(void 0!==u){const t=new Ai;void 0!==u.center&&t.fromArray(u.center),r.boundingSphere=new qi(t,u.radius)}return t.name&&(r.name=t.name),t.userData&&(r.userData=t.userData),r}}class Il extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=""===this.path?Rl.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||n;const o=new el(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,(function(s){let n=null;try{n=JSON.parse(s)}catch(e){return void 0!==i&&i(e),void console.error("THREE:ObjectLoader: Can't parse "+t+".",e.message)}const o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())return void 0!==i&&i(new Error("THREE.ObjectLoader: Can't load "+t)),void console.error("THREE.ObjectLoader: Can't load "+t);r.parse(n,e)}),s,i)}async loadAsync(t,e){const s=""===this.path?Rl.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||s;const i=new el(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials);const r=await i.loadAsync(t,e),n=JSON.parse(r),o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())throw new Error("THREE.ObjectLoader: Can't load "+t);return await this.parseAsync(n)}parse(t,e){const s=this.parseAnimations(t.animations),i=this.parseShapes(t.shapes),r=this.parseGeometries(t.geometries,i),n=this.parseImages(t.images,(function(){void 0!==e&&e(h)})),o=this.parseTextures(t.textures,n),a=this.parseMaterials(t.materials,o),h=this.parseObject(t.object,r,a,o,s),u=this.parseSkeletons(t.skeletons,h);if(this.bindSkeletons(h,u),this.bindLightTargets(h),void 0!==e){let t=!1;for(const e in n)if(n[e].data instanceof HTMLImageElement){t=!0;break}!1===t&&e(h)}return h}async parseAsync(t){const e=this.parseAnimations(t.animations),s=this.parseShapes(t.shapes),i=this.parseGeometries(t.geometries,s),r=await this.parseImagesAsync(t.images),n=this.parseTextures(t.textures,r),o=this.parseMaterials(t.materials,n),a=this.parseObject(t.object,i,o,n,e),h=this.parseSkeletons(t.skeletons,a);return this.bindSkeletons(a,h),this.bindLightTargets(a),a}parseShapes(t){const e={};if(void 0!==t)for(let s=0,i=t.length;s<i;s++){const i=(new Nh).fromJSON(t[s]);e[i.uuid]=i}return e}parseSkeletons(t,e){const s={},i={};if(e.traverse((function(t){t.isBone&&(i[t.uuid]=t)})),void 0!==t)for(let e=0,r=t.length;e<r;e++){const r=(new Oo).fromJSON(t[e],i);s[r.uuid]=r}return s}parseGeometries(t,e){const s={};if(void 0!==t){const i=new Bl;for(let r=0,n=t.length;r<n;r++){let n;const o=t[r];switch(o.type){case"BufferGeometry":case"InstancedBufferGeometry":n=i.parse(o);break;default:o.type in fu?n=fu[o.type].fromJSON(o,e):console.warn(`THREE.ObjectLoader: Unsupported geometry type "${o.type}"`)}n.uuid=o.uuid,void 0!==o.name&&(n.name=o.name),void 0!==o.userData&&(n.userData=o.userData),s[o.uuid]=n}}return s}parseMaterials(t,e){const s={},i={};if(void 0!==t){const r=new Cl;r.setTextures(e);for(let e=0,n=t.length;e<n;e++){const n=t[e];void 0===s[n.uuid]&&(s[n.uuid]=r.parse(n)),i[n.uuid]=s[n.uuid]}}return i}parseAnimations(t){const e={};if(void 0!==t)for(let s=0;s<t.length;s++){const i=t[s],r=qu.parse(i);e[r.uuid]=r}return e}parseImages(t,e){const s=this,i={};let r;function n(t){if("string"==typeof t){const e=t;return function(t){return s.manager.itemStart(t),r.load(t,(function(){s.manager.itemEnd(t)}),void 0,(function(){s.manager.itemError(t),s.manager.itemEnd(t)}))}(/^(\/\/)|([a-z]+:(\/\/)?)/i.test(e)?e:s.resourcePath+e)}return t.data?{data:Qs(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){const s=new Zu(e);r=new rl(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e<s;e++){const s=t[e],r=s.url;if(Array.isArray(r)){const t=[];for(let e=0,s=r.length;e<s;e++){const s=n(r[e]);null!==s&&(s instanceof HTMLImageElement?t.push(s):t.push(new Po(s.data,s.width,s.height)))}i[s.uuid]=new mi(t)}else{const t=n(s.url);i[s.uuid]=new mi(t)}}}return i}async parseImagesAsync(t){const e=this,s={};let i;async function r(t){if("string"==typeof t){const s=t,r=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(s)?s:e.resourcePath+s;return await i.loadAsync(r)}return t.data?{data:Qs(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){i=new rl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e<i;e++){const i=t[e],n=i.url;if(Array.isArray(n)){const t=[];for(let e=0,s=n.length;e<s;e++){const s=n[e],i=await r(s);null!==i&&(i instanceof HTMLImageElement?t.push(i):t.push(new Po(i.data,i.width,i.height)))}s[i.uuid]=new mi(t)}else{const t=await r(i.url);s[i.uuid]=new mi(t)}}}return s}parseTextures(t,e){function s(t,e){return"number"==typeof t?t:(console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.",t),e[t])}const i={};if(void 0!==t)for(let r=0,n=t.length;r<n;r++){const n=t[r];void 0===n.image&&console.warn('THREE.ObjectLoader: No "image" specified for',n.uuid),void 0===e[n.image]&&console.warn("THREE.ObjectLoader: Undefined image",n.image);const o=e[n.image],a=o.data;let h;Array.isArray(a)?(h=new Xn,6===a.length&&(h.needsUpdate=!0)):(h=a&&a.data?new Po:new yi,a&&(h.needsUpdate=!0)),h.source=o,h.uuid=n.uuid,void 0!==n.name&&(h.name=n.name),void 0!==n.mapping&&(h.mapping=s(n.mapping,Pl)),void 0!==n.channel&&(h.channel=n.channel),void 0!==n.offset&&h.offset.fromArray(n.offset),void 0!==n.repeat&&h.repeat.fromArray(n.repeat),void 0!==n.center&&h.center.fromArray(n.center),void 0!==n.rotation&&(h.rotation=n.rotation),void 0!==n.wrap&&(h.wrapS=s(n.wrap[0],Fl),h.wrapT=s(n.wrap[1],Fl)),void 0!==n.format&&(h.format=n.format),void 0!==n.internalFormat&&(h.internalFormat=n.internalFormat),void 0!==n.type&&(h.type=n.type),void 0!==n.colorSpace&&(h.colorSpace=n.colorSpace),void 0!==n.minFilter&&(h.minFilter=s(n.minFilter,Ul)),void 0!==n.magFilter&&(h.magFilter=s(n.magFilter,Ul)),void 0!==n.anisotropy&&(h.anisotropy=n.anisotropy),void 0!==n.flipY&&(h.flipY=n.flipY),void 0!==n.generateMipmaps&&(h.generateMipmaps=n.generateMipmaps),void 0!==n.premultiplyAlpha&&(h.premultiplyAlpha=n.premultiplyAlpha),void 0!==n.unpackAlignment&&(h.unpackAlignment=n.unpackAlignment),void 0!==n.compareFunction&&(h.compareFunction=n.compareFunction),void 0!==n.userData&&(h.userData=n.userData),i[n.uuid]=h}return i}parseObject(t,e,s,i,r){let n,o,a;function h(t){return void 0===e[t]&&console.warn("THREE.ObjectLoader: Undefined geometry",t),e[t]}function u(t){if(void 0!==t){if(Array.isArray(t)){const e=[];for(let i=0,r=t.length;i<r;i++){const r=t[i];void 0===s[r]&&console.warn("THREE.ObjectLoader: Undefined material",r),e.push(s[r])}return e}return void 0===s[t]&&console.warn("THREE.ObjectLoader: Undefined material",t),s[t]}}function l(t){return void 0===i[t]&&console.warn("THREE.ObjectLoader: Undefined texture",t),i[t]}switch(t.type){case"Scene":n=new Kn,void 0!==t.background&&(Number.isInteger(t.background)?n.background=new Xr(t.background):n.background=l(t.background)),void 0!==t.environment&&(n.environment=l(t.environment)),void 0!==t.fog&&("Fog"===t.fog.type?n.fog=new Jn(t.fog.color,t.fog.near,t.fog.far):"FogExp2"===t.fog.type&&(n.fog=new Zn(t.fog.color,t.fog.density)),""!==t.fog.name&&(n.fog.name=t.fog.name)),void 0!==t.backgroundBlurriness&&(n.backgroundBlurriness=t.backgroundBlurriness),void 0!==t.backgroundIntensity&&(n.backgroundIntensity=t.backgroundIntensity),void 0!==t.backgroundRotation&&n.backgroundRotation.fromArray(t.backgroundRotation),void 0!==t.environmentIntensity&&(n.environmentIntensity=t.environmentIntensity),void 0!==t.environmentRotation&&n.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":n=new Hn(t.fov,t.aspect,t.near,t.far),void 0!==t.focus&&(n.focus=t.focus),void 0!==t.zoom&&(n.zoom=t.zoom),void 0!==t.filmGauge&&(n.filmGauge=t.filmGauge),void 0!==t.filmOffset&&(n.filmOffset=t.filmOffset),void 0!==t.view&&(n.view=Object.assign({},t.view));break;case"OrthographicCamera":n=new Tl(t.left,t.right,t.top,t.bottom,t.near,t.far),void 0!==t.zoom&&(n.zoom=t.zoom),void 0!==t.view&&(n.view=Object.assign({},t.view));break;case"AmbientLight":n=new Sl(t.color,t.intensity);break;case"DirectionalLight":n=new wl(t.color,t.intensity),n.target=t.target||"";break;case"PointLight":n=new vl(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":n=new Ml(t.color,t.intensity,t.width,t.height);break;case"SpotLight":n=new gl(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),n.target=t.target||"";break;case"HemisphereLight":n=new ul(t.color,t.groundColor,t.intensity);break;case"LightProbe":n=(new Nl).fromJSON(t);break;case"SkinnedMesh":o=h(t.geometry),a=u(t.material),n=new Bo(o,a),void 0!==t.bindMode&&(n.bindMode=t.bindMode),void 0!==t.bindMatrix&&n.bindMatrix.fromArray(t.bindMatrix),void 0!==t.skeleton&&(n.skeleton=t.skeleton);break;case"Mesh":o=h(t.geometry),a=u(t.material),n=new On(o,a);break;case"InstancedMesh":o=h(t.geometry),a=u(t.material);const e=t.count,s=t.instanceMatrix,i=t.instanceColor;n=new Ho(o,a,e),n.instanceMatrix=new zo(new Float32Array(s.array),16),void 0!==i&&(n.instanceColor=new zo(new Float32Array(i.array),i.itemSize));break;case"BatchedMesh":o=h(t.geometry),a=u(t.material),n=new ya(t.maxInstanceCount,t.maxVertexCount,t.maxIndexCount,a),n.geometry=o,n.perObjectFrustumCulled=t.perObjectFrustumCulled,n.sortObjects=t.sortObjects,n._drawRanges=t.drawRanges,n._reservedRanges=t.reservedRanges,n._visibility=t.visibility,n._active=t.active,n._bounds=t.bounds.map((t=>{const e=new Ri;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new qi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=l(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=l(t.colorsTexture.uuid));break;case"LOD":n=new To;break;case"Line":n=new Aa(h(t.geometry),u(t.material));break;case"LineLoop":n=new Ba(h(t.geometry),u(t.material));break;case"LineSegments":n=new Ea(h(t.geometry),u(t.material));break;case"PointCloud":case"Points":n=new za(h(t.geometry),u(t.material));break;case"Sprite":n=new yo(u(t.material));break;case"Group":n=new Va;break;case"Bone":n=new Io;break;default:n=new Rr}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t<o.length;t++)n.add(this.parseObject(o[t],e,s,i,r))}if(void 0!==t.animations){const e=t.animations;for(let t=0;t<e.length;t++){const s=e[t];n.animations.push(r[s])}}if("LOD"===t.type){void 0!==t.autoUpdate&&(n.autoUpdate=t.autoUpdate);const e=t.levels;for(let t=0;t<e.length;t++){const s=e[t],i=n.getObjectByProperty("uuid",s.object);void 0!==i&&n.addLevel(i,s.distance,s.hysteresis)}}return n}bindSkeletons(t,e){0!==Object.keys(e).length&&t.traverse((function(t){if(!0===t.isSkinnedMesh&&void 0!==t.skeleton){const s=e[t.skeleton];void 0===s?console.warn("THREE.ObjectLoader: No skeleton found with UUID:",t.skeleton):t.bind(s,t.bindMatrix)}}))}bindLightTargets(t){t.traverse((function(e){if(e.isDirectionalLight||e.isSpotLight){const s=e.target,i=t.getObjectByProperty("uuid",s);e.target=void 0!==i?i:new Rr}}))}}const Pl={UVMapping:at,CubeReflectionMapping:ht,CubeRefractionMapping:ut,EquirectangularReflectionMapping:lt,EquirectangularRefractionMapping:ct,CubeUVReflectionMapping:dt},Fl={RepeatWrapping:pt,ClampToEdgeWrapping:mt,MirroredRepeatWrapping:gt},Ul={NearestFilter:ft,NearestMipmapNearestFilter:yt,NearestMipmapLinearFilter:bt,LinearFilter:Tt,LinearMipmapNearestFilter:_t,LinearMipmapLinearFilter:St};class Ol extends Ku{constructor(t){super(t),this.isImageBitmapLoader=!0,"undefined"==typeof createImageBitmap&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),"undefined"==typeof fetch&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,s,i){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,n=Yu.get(t);if(void 0!==n)return r.manager.itemStart(t),n.then?void n.then((s=>{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return Yu.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),Yu.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));Yu.add(t,a),r.manager.itemStart(t)}}let zl;class Ll{static getContext(){return void 0===zl&&(zl=new(window.AudioContext||window.webkitAudioContext)),zl}static setContext(t){zl=t}}class Vl extends Ku{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new el(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Ll.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const Dl=new sr,kl=new sr,Gl=new sr;class Wl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Hn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Hn,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,Gl.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(Ds*e.fov*.5)/e.zoom;let n,o;kl.elements[12]=-s,Dl.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Gl.elements[0]=2*e.near/(o-n),Gl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Gl),n=-r*e.aspect-i,o=r*e.aspect-i,Gl.elements[0]=2*e.near/(o-n),Gl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Gl)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(kl),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Dl)}}class jl extends Hn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Hl{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=$l(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=$l();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function $l(){return performance.now()}const ql=new Ai,Xl=new Mi,Yl=new Ai,Zl=new Ai;class Jl extends Rr{constructor(){super(),this.type="AudioListener",this.context=Ll.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Hl}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(ql,Xl,Yl),Zl.set(0,0,-1).applyQuaternion(Xl),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(ql.x,t),e.positionY.linearRampToValueAtTime(ql.y,t),e.positionZ.linearRampToValueAtTime(ql.z,t),e.forwardX.linearRampToValueAtTime(Zl.x,t),e.forwardY.linearRampToValueAtTime(Zl.y,t),e.forwardZ.linearRampToValueAtTime(Zl.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(ql.x,ql.y,ql.z),e.setOrientation(Zl.x,Zl.y,Zl.z,s.x,s.y,s.z)}}class Kl extends Rr{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(t=0){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(this.context.currentTime+t),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].connect(this.filters[t]);this.filters[this.filters.length-1].connect(this.getOutput())}else this.source.connect(this.getOutput());return this._connected=!0,this}disconnect(){if(!1!==this._connected){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].disconnect(this.filters[t]);this.filters[this.filters.length-1].disconnect(this.getOutput())}else this.source.disconnect(this.getOutput());return this._connected=!1,this}}getFilters(){return this.filters}setFilters(t){return t||(t=[]),!0===this._connected?(this.disconnect(),this.filters=t.slice(),this.connect()):this.filters=t.slice(),this}setDetune(t){return this.detune=t,!0===this.isPlaying&&void 0!==this.source.detune&&this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,.01),this}getDetune(){return this.detune}getFilter(){return this.getFilters()[0]}setFilter(t){return this.setFilters(t?[t]:[])}setPlaybackRate(t){if(!1!==this.hasPlaybackControl)return this.playbackRate=t,!0===this.isPlaying&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this;console.warn("THREE.Audio: this Audio has no playback control.")}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1}getLoop(){return!1===this.hasPlaybackControl?(console.warn("THREE.Audio: this Audio has no playback control."),!1):this.loop}setLoop(t){if(!1!==this.hasPlaybackControl)return this.loop=t,!0===this.isPlaying&&(this.source.loop=this.loop),this;console.warn("THREE.Audio: this Audio has no playback control.")}setLoopStart(t){return this.loopStart=t,this}setLoopEnd(t){return this.loopEnd=t,this}getVolume(){return this.gain.gain.value}setVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}}const Ql=new Ai,tc=new Mi,ec=new Ai,sc=new Ai;class ic extends Kl{constructor(t){super(t),this.panner=this.context.createPanner(),this.panner.panningModel="HRTF",this.panner.connect(this.gain)}connect(){super.connect(),this.panner.connect(this.gain)}disconnect(){super.disconnect(),this.panner.disconnect(this.gain)}getOutput(){return this.panner}getRefDistance(){return this.panner.refDistance}setRefDistance(t){return this.panner.refDistance=t,this}getRolloffFactor(){return this.panner.rolloffFactor}setRolloffFactor(t){return this.panner.rolloffFactor=t,this}getDistanceModel(){return this.panner.distanceModel}setDistanceModel(t){return this.panner.distanceModel=t,this}getMaxDistance(){return this.panner.maxDistance}setMaxDistance(t){return this.panner.maxDistance=t,this}setDirectionalCone(t,e,s){return this.panner.coneInnerAngle=t,this.panner.coneOuterAngle=e,this.panner.coneOuterGain=s,this}updateMatrixWorld(t){if(super.updateMatrixWorld(t),!0===this.hasPlaybackControl&&!1===this.isPlaying)return;this.matrixWorld.decompose(Ql,tc,ec),sc.set(0,0,1).applyQuaternion(tc);const e=this.panner;if(e.positionX){const t=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime(Ql.x,t),e.positionY.linearRampToValueAtTime(Ql.y,t),e.positionZ.linearRampToValueAtTime(Ql.z,t),e.orientationX.linearRampToValueAtTime(sc.x,t),e.orientationY.linearRampToValueAtTime(sc.y,t),e.orientationZ.linearRampToValueAtTime(sc.z,t)}else e.setPosition(Ql.x,Ql.y,Ql.z),e.setOrientation(sc.x,sc.y,sc.z)}}class rc{constructor(t,e=2048){this.analyser=t.context.createAnalyser(),this.analyser.fftSize=e,this.data=new Uint8Array(this.analyser.frequencyBinCount),t.getOutput().connect(this.analyser)}getFrequencyData(){return this.analyser.getByteFrequencyData(this.data),this.data}getAverageFrequency(){let t=0;const e=this.getFrequencyData();for(let s=0;s<e.length;s++)t+=e[s];return t/e.length}}class nc{constructor(t,e,s){let i,r,n;switch(this.binding=t,this.valueSize=s,e){case"quaternion":i=this._slerp,r=this._slerpAdditive,n=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(6*s),this._workIndex=5;break;case"string":case"bool":i=this._select,r=this._select,n=this._setAdditiveIdentityOther,this.buffer=new Array(5*s);break;default:i=this._lerp,r=this._lerpAdditive,n=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(5*s)}this._mixBufferRegion=i,this._mixBufferRegionAdditive=r,this._setIdentity=n,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const s=this.buffer,i=this.valueSize,r=t*i+i;let n=this.cumulativeWeight;if(0===n){for(let t=0;t!==i;++t)s[r+t]=s[t];n=e}else{n+=e;const t=e/n;this._mixBufferRegion(s,r,0,t,i)}this.cumulativeWeight=n}accumulateAdditive(t){const e=this.buffer,s=this.valueSize,i=s*this._addIndex;0===this.cumulativeWeightAdditive&&this._setIdentity(),this._mixBufferRegionAdditive(e,i,0,t,s),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,s=this.buffer,i=t*e+e,r=this.cumulativeWeight,n=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,r<1){const t=e*this._origIndex;this._mixBufferRegion(s,i,t,1-r,e)}n>0&&this._mixBufferRegionAdditive(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let s=t;s<e;s++)this.buffer[s]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let s=0;s<this.valueSize;s++)this.buffer[e+s]=this.buffer[t+s]}_select(t,e,s,i,r){if(i>=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Mi.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Mi.multiplyQuaternionsFlat(t,n,t,e,t,s),Mi.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const oc="\\[\\]\\.:\\/",ac=new RegExp("["+oc+"]","g"),hc="[^"+oc+"]",uc="[^"+oc.replace("\\.","")+"]",lc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",hc)+/(WCOD+)?/.source.replace("WCOD",uc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",hc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",hc)+"$"),cc=["material","materials","bones","map"];class dc{constructor(t,e,s){this.path=e,this.parsedPath=s||dc.parseTrackName(e),this.node=dc.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new dc.Composite(t,e,s):new dc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(ac,"")}static parseTrackName(t){const e=lc.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==cc.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i<t.length;i++){const r=t[i];if(r.name===e||r.uuid===e)return r;const n=s(r.children);if(n)return n}return null},i=s(t.children);if(i)return i}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)t[e++]=s[i]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,s=e.objectName,i=e.propertyName;let r=e.propertyIndex;if(t||(t=dc.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t)return void console.warn("THREE.PropertyBinding: No target node found for track: "+this.path+".");if(s){let i=e.objectIndex;switch(s){case"materials":if(!t.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!t.material.materials)return void console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);t=t.material.materials;break;case"bones":if(!t.skeleton)return void console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);t=t.skeleton.bones;for(let e=0;e<t.length;e++)if(t[e].name===i){i=e;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!t.material.map)return void console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);t=t.material.map;break;default:if(void 0===t[s])return void console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.",this);t=t[s]}if(void 0!==i){if(void 0===t[i])return void console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);t=t[i]}}const n=t[i];if(void 0===n){const s=e.nodeName;return void console.error("THREE.PropertyBinding: Trying to update property for track: "+s+"."+i+" but it wasn't found.",t)}let o=this.Versioning.None;this.targetObject=t,void 0!==t.needsUpdate?o=this.Versioning.NeedsUpdate:void 0!==t.matrixWorldNeedsUpdate&&(o=this.Versioning.MatrixWorldNeedsUpdate);let a=this.BindingType.Direct;if(void 0!==r){if("morphTargetInfluences"===i){if(!t.geometry)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);if(!t.geometry.morphAttributes)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);void 0!==t.morphTargetDictionary[r]&&(r=t.morphTargetDictionary[r])}a=this.BindingType.ArrayElement,this.resolvedProperty=n,this.propertyIndex=r}else void 0!==n.fromArray&&void 0!==n.toArray?(a=this.BindingType.HasFromToArray,this.resolvedProperty=n):Array.isArray(n)?(a=this.BindingType.EntireArray,this.resolvedProperty=n):this.propertyName=i;this.getValue=this.GetterByBindingType[a],this.setValue=this.SetterByBindingTypeAndVersioning[a][o]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}dc.Composite=class{constructor(t,e,s){const i=s||dc.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}getValue(t,e){this.bind();const s=this._targetGroup.nCachedObjects_,i=this._bindings[s];void 0!==i&&i.getValue(t,e)}setValue(t,e){const s=this._bindings;for(let i=this._targetGroup.nCachedObjects_,r=s.length;i!==r;++i)s[i].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,s=t.length;e!==s;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,s=t.length;e!==s;++e)t[e].unbind()}},dc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},dc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},dc.prototype.GetterByBindingType=[dc.prototype._getValue_direct,dc.prototype._getValue_array,dc.prototype._getValue_arrayElement,dc.prototype._getValue_toArray],dc.prototype.SetterByBindingTypeAndVersioning=[[dc.prototype._setValue_direct,dc.prototype._setValue_direct_setNeedsUpdate,dc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[dc.prototype._setValue_array,dc.prototype._setValue_array_setNeedsUpdate,dc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[dc.prototype._setValue_arrayElement,dc.prototype._setValue_arrayElement_setNeedsUpdate,dc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[dc.prototype._setValue_fromArray,dc.prototype._setValue_fromArray_setNeedsUpdate,dc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class pc{constructor(){this.isAnimationObjectGroup=!0,this.uuid=Gs(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const t={};this._indicesByUUID=t;for(let e=0,s=arguments.length;e!==s;++e)t[arguments[e].uuid]=e;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};const e=this;this.stats={objects:{get total(){return e._objects.length},get inUse(){return this.total-e.nCachedObjects_}},get bindingsPerObject(){return e._bindings.length}}}add(){const t=this._objects,e=this._indicesByUUID,s=this._paths,i=this._parsedPaths,r=this._bindings,n=r.length;let o,a=t.length,h=this.nCachedObjects_;for(let u=0,l=arguments.length;u!==l;++u){const l=arguments[u],c=l.uuid;let d=e[c];if(void 0===d){d=a++,e[c]=d,t.push(l);for(let t=0,e=n;t!==e;++t)r[t].push(new dc(l,s[t],i[t]))}else if(d<h){o=t[d];const a=--h,u=t[a];e[u.uuid]=d,t[d]=u,e[c]=a,t[a]=l;for(let t=0,e=n;t!==e;++t){const e=r[t],n=e[a];let o=e[d];e[d]=n,void 0===o&&(o=new dc(l,s[t],i[t])),e[a]=o}}else t[d]!==o&&console.error("THREE.AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.")}this.nCachedObjects_=h}remove(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_;for(let n=0,o=arguments.length;n!==o;++n){const o=arguments[n],a=o.uuid,h=e[a];if(void 0!==h&&h>=r){const n=r++,u=t[n];e[u.uuid]=h,t[h]=u,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h<r){const o=--r,a=t[o],u=--n,l=t[u];e[a.uuid]=h,t[h]=a,e[l.uuid]=o,t[o]=l,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[o],r=e[u];e[h]=i,e[o]=r,e.pop()}}else{const r=--n,o=t[r];r>0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,u=this.nCachedObjects_,l=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new dc(i,t,e)}return l}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class mc{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Ue,endingEnd:Ue};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=Oe,i.endingEnd=Oe):(i.endingStart=t?this.zeroSlopeAtStart?Oe:Ue:ze,i.endingEnd=e?this.zeroSlopeAtEnd?Oe:Ue:ze)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const gc=new Float32Array(1);class fc extends zs{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[t]=l;else{if(l=n[t],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;l=new nc(dc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[t]=l}o[t].resultBuffer=l.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e<this._nActiveActions}_addInactiveAction(t,e,s){const i=this._actions,r=this._actionsByClip;let n=r[e];if(void 0===n)n={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,r[e]=n;else{const e=n.knownActions;t._byClipCacheIndex=e.length,e.push(t)}t._cacheIndex=i.length,i.push(t),n.actionByRoot[s]=t}_removeInactiveAction(t){const e=this._actions,s=e[e.length-1],i=t._cacheIndex;s._cacheIndex=i,e[i]=s,e.pop(),t._cacheIndex=null;const r=t._clip.uuid,n=this._actionsByClip,o=n[r],a=o.knownActions,h=a[a.length-1],u=t._byClipCacheIndex;h._byClipCacheIndex=u,a[u]=h,a.pop(),t._byClipCacheIndex=null;delete o.actionByRoot[(t._localRoot||this._root).uuid],0===a.length&&delete n[r],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.referenceCount&&this._removeInactiveBinding(s)}}_lendAction(t){const e=this._actions,s=t._cacheIndex,i=this._nActiveActions++,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_takeBackAction(t){const e=this._actions,s=t._cacheIndex,i=--this._nActiveActions,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_addInactiveBinding(t,e,s){const i=this._bindingsByRootAndName,r=this._bindings;let n=i[e];void 0===n&&(n={},i[e]=n),n[s]=t,t._cacheIndex=r.length,r.push(t)}_removeInactiveBinding(t){const e=this._bindings,s=t.binding,i=s.rootNode.uuid,r=s.path,n=this._bindingsByRootAndName,o=n[i],a=e[e.length-1],h=t._cacheIndex;a._cacheIndex=h,e[h]=a,e.pop(),delete o[r],0===Object.keys(o).length&&delete n[i]}_lendBinding(t){const e=this._bindings,s=t._cacheIndex,i=this._nActiveBindings++,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_takeBackBinding(t){const e=this._bindings,s=t._cacheIndex,i=--this._nActiveBindings,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let s=t[e];return void 0===s&&(s=new zu(new Float32Array(2),new Float32Array(2),1,gc),s.__cacheIndex=e,t[e]=s),s}_takeBackControlInterpolant(t){const e=this._controlInterpolants,s=t.__cacheIndex,i=--this._nActiveControlInterpolants,r=e[i];t.__cacheIndex=i,e[i]=t,r.__cacheIndex=s,e[s]=r}clipAction(t,e,s){const i=e||this._root,r=i.uuid;let n="string"==typeof t?qu.findByName(i,t):t;const o=null!==n?n.uuid:t,a=this._actionsByClip[o];let h=null;if(void 0===s&&(s=null!==n?n.blendMode:Le),void 0!==a){const t=a.actionByRoot[r];if(void 0!==t&&t.blendMode===s)return t;h=a.knownActions[0],null===n&&(n=h._clip)}if(null===n)return null;const u=new mc(this,n,e,s);return this._bindAction(u,h),this._addInactiveAction(u,o,r),u}existingAction(t,e){const s=e||this._root,i=s.uuid,r="string"==typeof t?qu.findByName(s,t):t,n=r?r.uuid:t,o=this._actionsByClip[n];return void 0!==o&&o.actionByRoot[i]||null}stopAllAction(){const t=this._actions;for(let e=this._nActiveActions-1;e>=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);return this}setTime(t){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,s=t.uuid,i=this._actionsByClip,r=i[s];if(void 0!==r){const t=r.knownActions;for(let s=0,i=t.length;s!==i;++s){const i=t[s];this._deactivateAction(i);const r=i._cacheIndex,n=e[e.length-1];i._cacheIndex=null,i._byClipCacheIndex=null,n._cacheIndex=r,e[r]=n,e.pop(),this._removeInactiveBindingsForAction(i)}delete i[s]}}uncacheRoot(t){const e=t.uuid,s=this._actionsByClip;for(const t in s){const i=s[t].actionByRoot[e];void 0!==i&&(this._deactivateAction(i),this._removeInactiveAction(i))}const i=this._bindingsByRootAndName[e];if(void 0!==i)for(const t in i){const e=i[t];e.restoreOriginalState(),this._removeInactiveBinding(e)}}uncacheAction(t,e){const s=this.existingAction(t,e);null!==s&&(this._deactivateAction(s),this._removeInactiveAction(s))}}let yc=class t{constructor(t){this.value=t}clone(){return new t(void 0===this.value.clone?this.value:this.value.clone())}},xc=0,bc=class extends zs{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:xc++}),this.name="",this.usage=Ss,this.uniforms=[]}add(t){return this.uniforms.push(t),this}remove(t){const e=this.uniforms.indexOf(t);return-1!==e&&this.uniforms.splice(e,1),this}setName(t){return this.name=t,this}setUsage(t){return this.usage=t,this}dispose(){return this.dispatchEvent({type:"dispose"}),this}copy(t){this.name=t.name,this.usage=t.usage;const e=t.uniforms;this.uniforms.length=0;for(let t=0,s=e.length;t<s;t++){const s=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0;t<s.length;t++)this.uniforms.push(s[t].clone())}return this}clone(){return(new this.constructor).copy(this)}};class vc extends Qn{constructor(t,e,s=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=s}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}class Tc{constructor(t,e,s,i,r){this.isGLBufferAttribute=!0,this.name="",this.buffer=t,this.type=e,this.itemSize=s,this.elementSize=i,this.count=r,this.version=0}set needsUpdate(t){!0===t&&this.version++}setBuffer(t){return this.buffer=t,this}setType(t,e){return this.type=t,this.elementSize=e,this}setItemSize(t){return this.itemSize=t,this}setCount(t){return this.count=t,this}}const _c=new sr;class wc{constructor(t,e,s=0,i=1/0){this.ray=new er(t,e),this.near=s,this.far=i,this.camera=null,this.layers=new pr,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):console.error("THREE.Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return _c.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(_c),this}intersectObject(t,e=!0,s=[]){return Mc(t,this,s,e),s.sort(Sc),s}intersectObjects(t,e=!0,s=[]){for(let i=0,r=t.length;i<r;i++)Mc(t[i],this,s,e);return s.sort(Sc),s}}function Sc(t,e){return t.distance-e.distance}function Mc(t,e,s,i){let r=!0;if(t.layers.test(e.layers)){!1===t.raycast(e,s)&&(r=!1)}if(!0===r&&!0===i){const i=t.children;for(let t=0,r=i.length;t<r;t++)Mc(i[t],e,s,!0)}}class Ac{constructor(t=1,e=0,s=0){return this.radius=t,this.phi=e,this.theta=s,this}set(t,e,s){return this.radius=t,this.phi=e,this.theta=s,this}copy(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}makeSafe(){const t=1e-6;return this.phi=Math.max(t,Math.min(Math.PI-t,this.phi)),this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,s){return this.radius=Math.sqrt(t*t+e*e+s*s),0===this.radius?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,s),this.phi=Math.acos(Ws(e/this.radius,-1,1))),this}clone(){return(new this.constructor).copy(this)}}class Nc{constructor(t=1,e=0,s=0){return this.radius=t,this.theta=e,this.y=s,this}set(t,e,s){return this.radius=t,this.theta=e,this.y=s,this}copy(t){return this.radius=t.radius,this.theta=t.theta,this.y=t.y,this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,s){return this.radius=Math.sqrt(t*t+s*s),this.theta=Math.atan2(t,s),this.y=e,this}clone(){return(new this.constructor).copy(this)}}class Cc{constructor(t,e,s,i){Cc.prototype.isMatrix2=!0,this.elements=[1,0,0,1],void 0!==t&&this.set(t,e,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let s=0;s<4;s++)this.elements[s]=t[s+e];return this}set(t,e,s,i){const r=this.elements;return r[0]=t,r[2]=e,r[1]=s,r[3]=i,this}}const Rc=new Ys;class Ec{constructor(t=new Ys(1/0,1/0),e=new Ys(-1/0,-1/0)){this.isBox2=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Rc.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y}getCenter(t){return this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Rc).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Bc=new Ai,Ic=new Ai;class Pc{constructor(t=new Ai,e=new Ai){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Bc.subVectors(t,this.start),Ic.subVectors(this.end,this.start);const s=Ic.dot(Ic);let i=Ic.dot(Bc)/s;return e&&(i=Ws(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const Fc=new Ai;class Uc extends Rr{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new Sn,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,s=32;t<s;t++,e++){const r=t/s*Math.PI*2,n=e/s*Math.PI*2;i.push(Math.cos(r),Math.sin(r),1,Math.cos(n),Math.sin(n),1)}s.setAttribute("position",new fn(i,3));const r=new xa({fog:!1,toneMapped:!1});this.cone=new Ea(s,r),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);const t=this.light.distance?this.light.distance:1e3,e=t*Math.tan(this.light.angle);this.cone.scale.set(e,e,t),Fc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(Fc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}}const Oc=new Ai,zc=new sr,Lc=new sr;class Vc extends Ea{constructor(t){const e=Dc(t),s=new Sn,i=[],r=[],n=new Xr(0,0,1),o=new Xr(0,1,0);for(let t=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(i.push(0,0,0),i.push(0,0,0),r.push(n.r,n.g,n.b),r.push(o.r,o.g,o.b))}s.setAttribute("position",new fn(i,3)),s.setAttribute("color",new fn(r,3));super(s,new xa({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.isSkeletonHelper=!0,this.type="SkeletonHelper",this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1}updateMatrixWorld(t){const e=this.bones,s=this.geometry,i=s.getAttribute("position");Lc.copy(this.root.matrixWorld).invert();for(let t=0,s=0;t<e.length;t++){const r=e[t];r.parent&&r.parent.isBone&&(zc.multiplyMatrices(Lc,r.matrixWorld),Oc.setFromMatrixPosition(zc),i.setXYZ(s,Oc.x,Oc.y,Oc.z),zc.multiplyMatrices(Lc,r.parent.matrixWorld),Oc.setFromMatrixPosition(zc),i.setXYZ(s+1,Oc.x,Oc.y,Oc.z),s+=2)}s.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose()}}function Dc(t){const e=[];!0===t.isBone&&e.push(t);for(let s=0;s<t.children.length;s++)e.push.apply(e,Dc(t.children[s]));return e}class kc extends On{constructor(t,e,s){super(new uu(e,4,2),new Kr({wireframe:!0,fog:!1,toneMapped:!1})),this.light=t,this.color=s,this.type="PointLightHelper",this.matrix=this.light.matrixWorld,this.matrixAutoUpdate=!1,this.update()}dispose(){this.geometry.dispose(),this.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),void 0!==this.color?this.material.color.set(this.color):this.material.color.copy(this.light.color)}}const Gc=new Ai,Wc=new Xr,jc=new Xr;class Hc extends Rr{constructor(t,e,s){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="HemisphereLightHelper";const i=new nu(e);i.rotateY(.5*Math.PI),this.material=new Kr({wireframe:!0,fog:!1,toneMapped:!1}),void 0===this.color&&(this.material.vertexColors=!0);const r=i.getAttribute("position"),n=new Float32Array(3*r.count);i.setAttribute("color",new an(n,3)),this.add(new On(i,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const t=this.children[0];if(void 0!==this.color)this.material.color.set(this.color);else{const e=t.geometry.getAttribute("color");Wc.copy(this.light.color),jc.copy(this.light.groundColor);for(let t=0,s=e.count;t<s;t++){const i=t<s/2?Wc:jc;e.setXYZ(t,i.r,i.g,i.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(Gc.setFromMatrixPosition(this.light.matrixWorld).negate())}}class $c extends Ea{constructor(t=10,e=10,s=4473924,i=8947848){s=new Xr(s),i=new Xr(i);const r=e/2,n=t/e,o=t/2,a=[],h=[];for(let t=0,u=0,l=-o;t<=e;t++,l+=n){a.push(-o,0,l,o,0,l),a.push(l,0,-o,l,0,o);const e=t===r?s:i;e.toArray(h,u),u+=3,e.toArray(h,u),u+=3,e.toArray(h,u),u+=3,e.toArray(h,u),u+=3}const u=new Sn;u.setAttribute("position",new fn(a,3)),u.setAttribute("color",new fn(h,3));super(u,new xa({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}class qc extends Ea{constructor(t=10,e=16,s=8,i=64,r=4473924,n=8947848){r=new Xr(r),n=new Xr(n);const o=[],a=[];if(e>1)for(let s=0;s<e;s++){const i=s/e*(2*Math.PI),h=Math.sin(i)*t,u=Math.cos(i)*t;o.push(0,0,0),o.push(h,0,u);const l=1&s?r:n;a.push(l.r,l.g,l.b),a.push(l.r,l.g,l.b)}for(let e=0;e<s;e++){const h=1&e?r:n,u=t-t/s*e;for(let t=0;t<i;t++){let e=t/i*(2*Math.PI),s=Math.sin(e)*u,r=Math.cos(e)*u;o.push(s,0,r),a.push(h.r,h.g,h.b),e=(t+1)/i*(2*Math.PI),s=Math.sin(e)*u,r=Math.cos(e)*u,o.push(s,0,r),a.push(h.r,h.g,h.b)}}const h=new Sn;h.setAttribute("position",new fn(o,3)),h.setAttribute("color",new fn(a,3));super(h,new xa({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}const Xc=new Ai,Yc=new Ai,Zc=new Ai;class Jc extends Rr{constructor(t,e,s){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="DirectionalLightHelper",void 0===e&&(e=1);let i=new Sn;i.setAttribute("position",new fn([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const r=new xa({fog:!1,toneMapped:!1});this.lightPlane=new Aa(i,r),this.add(this.lightPlane),i=new Sn,i.setAttribute("position",new fn([0,0,0,0,0,1],3)),this.targetLine=new Aa(i,r),this.add(this.targetLine),this.update()}dispose(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),Xc.setFromMatrixPosition(this.light.matrixWorld),Yc.setFromMatrixPosition(this.light.target.matrixWorld),Zc.subVectors(Yc,Xc),this.lightPlane.lookAt(Yc),void 0!==this.color?(this.lightPlane.material.color.set(this.color),this.targetLine.material.color.set(this.color)):(this.lightPlane.material.color.copy(this.light.color),this.targetLine.material.color.copy(this.light.color)),this.targetLine.lookAt(Yc),this.targetLine.scale.z=Zc.length()}}const Kc=new Ai,Qc=new kn;class td extends Ea{constructor(t){const e=new Sn,s=new xa({color:16777215,vertexColors:!0,toneMapped:!1}),i=[],r=[],n={};function o(t,e){a(t),a(e)}function a(t){i.push(0,0,0),r.push(0,0,0),void 0===n[t]&&(n[t]=[]),n[t].push(i.length/3-1)}o("n1","n2"),o("n2","n4"),o("n4","n3"),o("n3","n1"),o("f1","f2"),o("f2","f4"),o("f4","f3"),o("f3","f1"),o("n1","f1"),o("n2","f2"),o("n3","f3"),o("n4","f4"),o("p","n1"),o("p","n2"),o("p","n3"),o("p","n4"),o("u1","u2"),o("u2","u3"),o("u3","u1"),o("c","t"),o("p","c"),o("cn1","cn2"),o("cn3","cn4"),o("cf1","cf2"),o("cf3","cf4"),e.setAttribute("position",new fn(i,3)),e.setAttribute("color",new fn(r,3)),super(e,s),this.type="CameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=n,this.update();const h=new Xr(16755200),u=new Xr(16711680),l=new Xr(43775),c=new Xr(16777215),d=new Xr(3355443);this.setColors(h,u,l,c,d)}setColors(t,e,s,i,r){const n=this.geometry.getAttribute("color");n.setXYZ(0,t.r,t.g,t.b),n.setXYZ(1,t.r,t.g,t.b),n.setXYZ(2,t.r,t.g,t.b),n.setXYZ(3,t.r,t.g,t.b),n.setXYZ(4,t.r,t.g,t.b),n.setXYZ(5,t.r,t.g,t.b),n.setXYZ(6,t.r,t.g,t.b),n.setXYZ(7,t.r,t.g,t.b),n.setXYZ(8,t.r,t.g,t.b),n.setXYZ(9,t.r,t.g,t.b),n.setXYZ(10,t.r,t.g,t.b),n.setXYZ(11,t.r,t.g,t.b),n.setXYZ(12,t.r,t.g,t.b),n.setXYZ(13,t.r,t.g,t.b),n.setXYZ(14,t.r,t.g,t.b),n.setXYZ(15,t.r,t.g,t.b),n.setXYZ(16,t.r,t.g,t.b),n.setXYZ(17,t.r,t.g,t.b),n.setXYZ(18,t.r,t.g,t.b),n.setXYZ(19,t.r,t.g,t.b),n.setXYZ(20,t.r,t.g,t.b),n.setXYZ(21,t.r,t.g,t.b),n.setXYZ(22,t.r,t.g,t.b),n.setXYZ(23,t.r,t.g,t.b),n.setXYZ(24,e.r,e.g,e.b),n.setXYZ(25,e.r,e.g,e.b),n.setXYZ(26,e.r,e.g,e.b),n.setXYZ(27,e.r,e.g,e.b),n.setXYZ(28,e.r,e.g,e.b),n.setXYZ(29,e.r,e.g,e.b),n.setXYZ(30,e.r,e.g,e.b),n.setXYZ(31,e.r,e.g,e.b),n.setXYZ(32,s.r,s.g,s.b),n.setXYZ(33,s.r,s.g,s.b),n.setXYZ(34,s.r,s.g,s.b),n.setXYZ(35,s.r,s.g,s.b),n.setXYZ(36,s.r,s.g,s.b),n.setXYZ(37,s.r,s.g,s.b),n.setXYZ(38,i.r,i.g,i.b),n.setXYZ(39,i.r,i.g,i.b),n.setXYZ(40,r.r,r.g,r.b),n.setXYZ(41,r.r,r.g,r.b),n.setXYZ(42,r.r,r.g,r.b),n.setXYZ(43,r.r,r.g,r.b),n.setXYZ(44,r.r,r.g,r.b),n.setXYZ(45,r.r,r.g,r.b),n.setXYZ(46,r.r,r.g,r.b),n.setXYZ(47,r.r,r.g,r.b),n.setXYZ(48,r.r,r.g,r.b),n.setXYZ(49,r.r,r.g,r.b),n.needsUpdate=!0}update(){const t=this.geometry,e=this.pointMap;Qc.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),ed("c",e,t,Qc,0,0,-1),ed("t",e,t,Qc,0,0,1),ed("n1",e,t,Qc,-1,-1,-1),ed("n2",e,t,Qc,1,-1,-1),ed("n3",e,t,Qc,-1,1,-1),ed("n4",e,t,Qc,1,1,-1),ed("f1",e,t,Qc,-1,-1,1),ed("f2",e,t,Qc,1,-1,1),ed("f3",e,t,Qc,-1,1,1),ed("f4",e,t,Qc,1,1,1),ed("u1",e,t,Qc,.7,1.1,-1),ed("u2",e,t,Qc,-.7,1.1,-1),ed("u3",e,t,Qc,0,2,-1),ed("cf1",e,t,Qc,-1,0,1),ed("cf2",e,t,Qc,1,0,1),ed("cf3",e,t,Qc,0,-1,1),ed("cf4",e,t,Qc,0,1,1),ed("cn1",e,t,Qc,-1,0,-1),ed("cn2",e,t,Qc,1,0,-1),ed("cn3",e,t,Qc,0,-1,-1),ed("cn4",e,t,Qc,0,1,-1),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}function ed(t,e,s,i,r,n,o){Kc.set(r,n,o).unproject(i);const a=e[t];if(void 0!==a){const t=s.getAttribute("position");for(let e=0,s=a.length;e<s;e++)t.setXYZ(a[e],Kc.x,Kc.y,Kc.z)}}const sd=new Ri;class id extends Ea{constructor(t,e=16776960){const s=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),i=new Float32Array(24),r=new Sn;r.setIndex(new an(s,1)),r.setAttribute("position",new an(i,3)),super(r,new xa({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(t){if(void 0!==t&&console.warn("THREE.BoxHelper: .update() has no longer arguments."),void 0!==this.object&&sd.setFromObject(this.object),sd.isEmpty())return;const e=sd.min,s=sd.max,i=this.geometry.attributes.position,r=i.array;r[0]=s.x,r[1]=s.y,r[2]=s.z,r[3]=e.x,r[4]=s.y,r[5]=s.z,r[6]=e.x,r[7]=e.y,r[8]=s.z,r[9]=s.x,r[10]=e.y,r[11]=s.z,r[12]=s.x,r[13]=s.y,r[14]=e.z,r[15]=e.x,r[16]=s.y,r[17]=e.z,r[18]=e.x,r[19]=e.y,r[20]=e.z,r[21]=s.x,r[22]=e.y,r[23]=e.z,i.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}copy(t,e){return super.copy(t,e),this.object=t.object,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class rd extends Ea{constructor(t,e=16776960){const s=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),i=new Sn;i.setIndex(new an(s,1)),i.setAttribute("position",new fn([1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],3)),super(i,new xa({color:e,toneMapped:!1})),this.box=t,this.type="Box3Helper",this.geometry.computeBoundingSphere()}updateMatrixWorld(t){const e=this.box;e.isEmpty()||(e.getCenter(this.position),e.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(t))}dispose(){this.geometry.dispose(),this.material.dispose()}}class nd extends Aa{constructor(t,e=1,s=16776960){const i=s,r=new Sn;r.setAttribute("position",new fn([1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],3)),r.computeBoundingSphere(),super(r,new xa({color:i,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const n=new Sn;n.setAttribute("position",new fn([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),n.computeBoundingSphere(),this.add(new On(n,new Kr({color:i,opacity:.2,transparent:!0,depthWrite:!1,toneMapped:!1})))}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),this.lookAt(this.plane.normal),this.translateZ(-this.plane.constant),super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}}const od=new Ai;let ad,hd;class ud extends Rr{constructor(t=new Ai(0,0,1),e=new Ai(0,0,0),s=1,i=16776960,r=.2*s,n=.2*r){super(),this.type="ArrowHelper",void 0===ad&&(ad=new Sn,ad.setAttribute("position",new fn([0,0,0,0,1,0],3)),hd=new xh(0,.5,1,5,1),hd.translate(0,-.5,0)),this.position.copy(e),this.line=new Aa(ad,new xa({color:i,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new On(hd,new Kr({color:i,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(t),this.setLength(s,r,n)}setDirection(t){if(t.y>.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{od.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(od,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class ld extends Ea{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new Sn;s.setAttribute("position",new fn(e,3)),s.setAttribute("color",new fn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new xa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new Xr,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class cd{constructor(){this.type="ShapePath",this.color=new Xr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new mh,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;n<s;r=n++){let s=e[r],o=e[n],a=o.x-s.x,h=o.y-s.y;if(Math.abs(h)>Number.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.y<s.y||t.y>o.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=Qh.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Nh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let e=0,o=i.length;e<o;e++)n=i[e],c=n.getPoints(),r=s(c),r=t?!r:r,r?(!h&&l[m]&&m++,l[m]={s:new Nh,p:c},l[m].s.curves=n.curves,h&&m++,p[m]=[]):p[m].push({h:n,p:c[0]});if(!l[0])return function(t){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s],r=new Nh;r.curves=i.curves,e.push(r)}return e}(i);if(l.length>1){let t=!1,s=0;for(let t=0,e=l.length;t<e;t++)u[t]=[];for(let i=0,r=l.length;i<r;i++){const r=p[i];for(let n=0;n<r.length;n++){const o=r[n];let a=!0;for(let r=0;r<l.length;r++)e(o.p,l[r].p)&&(i!==r&&s++,a?(a=!1,u[r].push(o)):t=!0);a&&u[i].push(o)}}s>0&&!1===t&&(p=u)}for(let t=0,e=l.length;t<e;t++){o=l[t].s,a.push(o),d=p[t];for(let t=0,e=d.length;t<e;t++)o.holes.push(d[t].h)}return a}}class dd extends zs{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}class pd extends vi{constructor(t=1,e=1,s=1,i={}){console.warn('THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.'),super(t,e,{...i,count:s}),this.isWebGLMultipleRenderTargets=!0}get texture(){return this.textures}}const md=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class gd{constructor(t){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(t),this.hasAnimation=!0===t.object.isSkinnedMesh,this.refreshUniforms=md,this.renderId=0}firstInitialization(t){return!1===this.renderObjects.has(t)&&(this.getRenderObjectData(t),!0)}getRenderObjectData(t){let e=this.renderObjects.get(t);return void 0===e&&(e={material:this.getMaterialData(t.material),worldMatrix:t.object.matrixWorld.clone()},t.object.center&&(e.center=t.object.center.clone()),t.object.morphTargetInfluences&&(e.morphTargetInfluences=t.object.morphTargetInfluences.slice()),null!==t.bundle&&(e.version=t.bundle.version),this.renderObjects.set(t,e)),e}containsNode(t){const e=t.material;for(const t in e)if(e[t]&&e[t].isNode)return!0;return null!==t.renderer.nodes.modelViewMatrix||null!==t.renderer.nodes.modelNormalViewMatrix}getMaterialData(t){const e={};for(const s of this.refreshUniforms){const i=t[s];null!=i&&("object"==typeof i&&void 0!==i.clone?!0===i.isTexture?e[s]={id:i.id,version:i.version}:e[s]=i.clone():e[s]=i)}return e}equals(t){const{object:e,material:s}=t,i=this.getRenderObjectData(t);if(!0!==i.worldMatrix.equals(e.matrixWorld))return i.worldMatrix.copy(e.matrixWorld),!1;const r=i.material;for(const t in r){const e=r[t],i=s[t];if(void 0!==e.equals){if(!1===e.equals(i))return e.copy(i),!1}else if(!0===i.isTexture){if(e.id!==i.id||e.version!==i.version)return e.id=i.id,e.version=i.version,!1}else if(e!==i)return r[t]=i,!1}if(i.morphTargetInfluences){let t=!1;for(let s=0;s<i.morphTargetInfluences.length;s++)i.morphTargetInfluences[s]!==e.morphTargetInfluences[s]&&(t=!0);if(t)return!0}return i.center&&!1===i.center.equals(e.center)?(i.center.copy(e.center),!0):(null!==t.bundle&&(i.version=t.bundle.version),!0)}needsRefresh(t,e){if(this.hasNode||this.hasAnimation||this.firstInitialization(t))return!0;const{renderId:s}=e;if(this.renderId!==s)return this.renderId=s,!0;const i=!0===t.object.static,r=null!==t.bundle&&!0===t.bundle.static&&this.getRenderObjectData(t).version===t.bundle.version;if(i||r)return!1;return!0!==this.equals(t)}}function fd(t,e=0){let s=3735928559^e,i=1103547991^e;if(t instanceof Array)for(let e,r=0;r<t.length;r++)e=t[r],s=Math.imul(s^e,2654435761),i=Math.imul(i^e,1597334677);else for(let e,r=0;r<t.length;r++)e=t.charCodeAt(r),s=Math.imul(s^e,2654435761),i=Math.imul(i^e,1597334677);return s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&i)+(s>>>0)}const yd=t=>fd(t),xd=t=>fd(t),bd=(...t)=>fd(t);function vd(t,e=!1){const s=[];!0===t.isNode&&(s.push(t.id),t=t.getSelf());for(const{property:i,childNode:r}of Td(t))s.push(s,fd(i.slice(0,-4)),r.getCacheKey(e));return fd(s)}function*Td(t,e=!1){for(const s in t){if(!0===s.startsWith("_"))continue;const i=t[s];if(!0===Array.isArray(i))for(let t=0;t<i.length;t++){const r=i[t];r&&(!0===r.isNode||e&&"function"==typeof r.toJSON)&&(yield{property:s,index:t,childNode:r})}else if(i&&!0===i.isNode)yield{property:s,childNode:i};else if("object"==typeof i)for(const t in i){const r=i[t];r&&(!0===r.isNode||e&&"function"==typeof r.toJSON)&&(yield{property:s,index:t,childNode:r})}}}function _d(t){if(null==t)return null;const e=typeof t;return!0===t.isNode?"node":"number"===e?"float":"boolean"===e?"bool":"string"===e?"string":"function"===e?"shader":!0===t.isVector2?"vec2":!0===t.isVector3?"vec3":!0===t.isVector4?"vec4":!0===t.isMatrix3?"mat3":!0===t.isMatrix4?"mat4":!0===t.isColor?"color":t instanceof ArrayBuffer?"ArrayBuffer":null}function wd(t,...e){const s=t?t.slice(-4):void 0;return 1===e.length&&("vec2"===s?e=[e[0],e[0]]:"vec3"===s?e=[e[0],e[0],e[0]]:"vec4"===s&&(e=[e[0],e[0],e[0],e[0]])),"color"===t?new Xr(...e):"vec2"===s?new Ys(...e):"vec3"===s?new Ai(...e):"vec4"===s?new xi(...e):"mat3"===s?new Zs(...e):"mat4"===s?new sr(...e):"bool"===t?e[0]||!1:"float"===t||"int"===t||"uint"===t?e[0]||0:"string"===t?e[0]||"":"ArrayBuffer"===t?Md(e[0]):null}function Sd(t){let e="";const s=new Uint8Array(t);for(let t=0;t<s.length;t++)e+=String.fromCharCode(s[t]);return btoa(e)}function Md(t){return Uint8Array.from(atob(t),(t=>t.charCodeAt(0))).buffer}var Ad=Object.freeze({__proto__:null,arrayBufferToBase64:Sd,base64ToArrayBuffer:Md,getCacheKey:vd,getNodeChildren:Td,getValueFromType:wd,getValueType:_d,hash:bd,hashArray:xd,hashString:yd});const Nd={VERTEX:"vertex",FRAGMENT:"fragment"},Cd={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Rd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Ed=["fragment","vertex"],Bd=["setup","analyze","generate"],Id=[...Ed,"compute"],Pd=["x","y","z","w"];let Fd=0;class Ud extends zs{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=Cd.NONE,this.updateBeforeType=Cd.NONE,this.updateAfterType=Cd.NONE,this.uuid=Xs.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Fd++})}set needsUpdate(t){!0===t&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,Cd.FRAME)}onRenderUpdate(t){return this.onUpdate(t,Cd.RENDER)}onObjectUpdate(t){return this.onUpdate(t,Cd.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of Td(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return!0!==(t=t||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=vd(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const t of this.getChildren())e["node"+s++]=t;return null}analyze(t){if(1===t.increaseUsage(this)){const e=t.getNodeProperties(this);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let i=null;const r=t.getBuildStage();if("setup"===r){this.updateReference(t);const e=t.getNodeProperties(this);if(!0!==e.initialized){t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length;for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i?(i=this.generate(t)||"",r.snippet=i):void 0!==r.flowCodes&&void 0!==t.context.nodeBlock&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return Td(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of e)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(t.meta).uuid):s[i]=n.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const r of t.inputNodes[s])i.push(e[r]);this[s]=i}else if("object"==typeof t.inputNodes[s]){const i={};for(const r in t.inputNodes[s]){const n=t.inputNodes[s][r];i[r]=e[n]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const e=n(t.textures),s=n(t.images),i=n(t.nodes);e.length>0&&(r.textures=e),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}class Od extends Ud{static get type(){return"ArrayElementNode"}constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){return`${this.node.build(t)}[ ${this.indexNode.build(t,"uint")} ]`}}class zd extends Ud{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))null!==s&&t.getTypeLength(e)!==t.getTypeLength(i)||(s=i);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,i=this.getNodeType(t),r=s.build(t,i);return t.format(r,i,e)}}class Ld extends Ud{static get type(){return"TempNode"}constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const s=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,s,e);if("void"!==s&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,s),n=t.getVarFromNode(this,null,s),o=t.getPropertyName(n);return t.addLineFlowCode(`${o} = ${r}`,this),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}class Vd extends Ld{static get type(){return"JoinNode"}constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return null!==this.nodeType?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce(((e,s)=>e+t.getTypeLength(s.getNodeType(t))),0))}generate(t,e){const s=this.getNodeType(t),i=this.nodes,r=t.getComponentType(s),n=[];for(const e of i){let s=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(s=t.format(s,i,r)),n.push(s)}const o=`${t.getType(s)}( ${n.join(", ")} )`;return t.format(o,s,e)}}const Dd=Pd.join("");class kd extends Ud{static get type(){return"SplitNode"}constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Pd.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,i=t.getTypeLength(s.getNodeType(t));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const o=s.build(t,n);r=this.components.length===i&&this.components===Dd.slice(0,this.components.length)?t.format(o,n,e):t.format(`${o}.${this.components}`,this.getNodeType(t),e)}else r=s.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class Gd extends Ld{static get type(){return"SetNode"}constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,r=this.getNodeType(t),n=t.getTypeFromLength(s.length,i.getNodeType(t)),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),u=[];for(let t=0;t<h;t++){const e=Pd[t];e===s[0]?(u.push(o),t+=s.length-1):u.push(a+"."+e)}return`${t.getType(r)}( ${u.join(", ")} )`}}class Wd extends Ld{static get type(){return"FlipNode"}constructor(t,e){super(),this.sourceNode=t,this.components=e}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{components:e,sourceNode:s}=this,i=this.getNodeType(t),r=s.build(t),n=t.getVarFromNode(this),o=t.getPropertyName(n);t.addLineFlowCode(o+" = "+r,this);const a=t.getTypeLength(i),h=[];let u=0;for(let t=0;t<a;t++){const s=Pd[t];s===e[u]?(h.push("1.0 - "+o+"."+s),u++):h.push(o+"."+s)}return`${t.getType(i)}( ${h.join(", ")} )`}}class jd extends Ud{static get type(){return"InputNode"}constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return null===this.nodeType?_d(this.value):this.nodeType}getInputType(t){return this.getNodeType(t)}setPrecision(t){return this.precision=t,this}serialize(t){super.serialize(t),t.value=this.value,this.value&&this.value.toArray&&(t.value=this.value.toArray()),t.valueType=_d(this.value),t.nodeType=this.nodeType,"ArrayBuffer"===t.valueType&&(t.value=Sd(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?wd(t.valueType,...t.value):t.value,this.precision=t.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(t.value))}generate(){console.warn("Abstract function.")}}class Hd extends jd{static get type(){return"ConstNode"}constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const s=this.getNodeType(t);return t.format(this.generateConst(t),s,e)}}let $d=null;const qd=new Map;function Xd(t,e){if(qd.has(t))console.warn(`Redefinition of method chaining ${t}`);else{if("function"!=typeof e)throw new Error(`Node element ${t} is not a function`);qd.set(t,e)}}const Yd=t=>t.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Zd=t=>Yd(t).split("").sort().join(""),Jd={setup(t,e){const s=e.shift();return t(_p(s),...e)},get(t,e,s){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>($d.assign(s,...t),s);if(qd.has(e)){const i=qd.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&qd.has(e.slice(0,e.length-6))){const i=qd.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>s.assign(t[0],i(...t)):(...t)=>s.assign(i(s,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=Yd(e),Tp(new kd(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Zd(e.slice(3).toLowerCase()),s=>Tp(new Gd(t,e,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Zd(e.slice(4).toLowerCase()),()=>Tp(new Wd(Tp(t),e));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),Tp(new kd(t,e));if(!0===/^\d+$/.test(e))return Tp(new Od(s,new Hd(Number(e),"uint")))}return Reflect.get(t,e,s)},set:(t,e,s,i)=>"string"!=typeof e||void 0!==t[e]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(e)&&"width"!==e&&"height"!==e&&"depth"!==e&&!0!==/^\d+$/.test(e)?Reflect.set(t,e,s,i):(i[e].assign(s),!0)},Kd=new WeakMap,Qd=new WeakMap,tp=function(t,e=null){for(const s in t)t[s]=Tp(t[s],e);return t},ep=function(t,e=null){const s=t.length;for(let i=0;i<s;i++)t[i]=Tp(t[i],e);return t},sp=function(t,e=null,s=null,i=null){const r=t=>Tp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...wp(e))):null!==s?(s=Tp(s),(...i)=>r(new t(e,...wp(i),s))):(...s)=>r(new t(e,...wp(s)))},ip=function(t,...e){return Tp(new t(...wp(e)))};class rp extends Ud{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this,i=t.getNodeProperties(e);if(i.onceOutput)return i.onceOutput;let r=null;if(e.layout){let i=Qd.get(t.constructor);void 0===i&&(i=new WeakMap,Qd.set(t.constructor,i));let n=i.get(e);void 0===n&&(n=Tp(t.buildFunctionNode(e)),i.set(e,n)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(n),r=Tp(n.call(s))}else{const i=e.jsFunc,n=null!==s?i(s,t):i(t);r=Tp(n)}return e.once&&(i.onceOutput=r),r}getOutputNode(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode}setup(t){return this.getOutputNode(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){return this.getOutputNode(t).build(t,e)}}class np extends Ud{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}call(t=null){return _p(t),Tp(new rp(this,t))}setup(){return this.call()}}const op=[!1,!0],ap=[0,1,2,3],hp=[-1,-2],up=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],lp=new Map;for(const t of op)lp.set(t,new Hd(t));const cp=new Map;for(const t of ap)cp.set(t,new Hd(t,"uint"));const dp=new Map([...cp].map((t=>new Hd(t.value,"int"))));for(const t of hp)dp.set(t,new Hd(t,"int"));const pp=new Map([...dp].map((t=>new Hd(t.value))));for(const t of up)pp.set(t,new Hd(t));for(const t of up)pp.set(-t,new Hd(-t));const mp={bool:lp,uint:cp,ints:dp,float:pp},gp=new Map([...lp,...pp]),fp=(t,e)=>gp.has(t)?gp.get(t):!0===t.isNode?t:new Hd(t,e),yp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[wd(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return Tp(e.get(s[0]));if(1===s.length){const e=fp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?Tp(e):Tp(new zd(e,t))}const i=s.map((t=>fp(t)));return Tp(new Vd(i,t))}},xp=t=>"object"==typeof t&&null!==t?t.value:t,bp=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function vp(t,e){return new Proxy(new np(t,e),Jd)}const Tp=(t,e=null)=>function(t,e=null){const s=_d(t);if("node"===s){let e=Kd.get(t);return void 0===e&&(e=new Proxy(t,Jd),Kd.set(t,e),Kd.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Tp(fp(t,e)):"shader"===s?Ap(t):t}(t,e),_p=(t,e=null)=>new tp(t,e),wp=(t,e=null)=>new ep(t,e),Sp=(...t)=>new sp(...t),Mp=(...t)=>new ip(...t),Ap=(t,e)=>{const s=new vp(t,e),i=(...t)=>{let e;return _p(t),e=t[0]&&t[0].isNode?[...t]:t[0],s.call(e)};return i.shaderNode=s,i.setLayout=t=>(s.setLayout(t),i),i.once=()=>(s.once=!0,i),i},Np=(...t)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),Ap(...t));Xd("toGlobal",(t=>(t.global=!0,t)));const Cp=t=>{$d=t},Rp=()=>$d,Ep=(...t)=>$d.If(...t);function Bp(t){return $d&&$d.add(t),t}Xd("append",Bp);const Ip=new yp("color"),Pp=new yp("float",mp.float),Fp=new yp("int",mp.ints),Up=new yp("uint",mp.uint),Op=new yp("bool",mp.bool),zp=new yp("vec2"),Lp=new yp("ivec2"),Vp=new yp("uvec2"),Dp=new yp("bvec2"),kp=new yp("vec3"),Gp=new yp("ivec3"),Wp=new yp("uvec3"),jp=new yp("bvec3"),Hp=new yp("vec4"),$p=new yp("ivec4"),qp=new yp("uvec4"),Xp=new yp("bvec4"),Yp=new yp("mat2"),Zp=new yp("mat3"),Jp=new yp("mat4"),Kp=(t="")=>Tp(new Hd(t,"string")),Qp=t=>Tp(new Hd(t,"ArrayBuffer"));Xd("toColor",Ip),Xd("toFloat",Pp),Xd("toInt",Fp),Xd("toUint",Up),Xd("toBool",Op),Xd("toVec2",zp),Xd("toIVec2",Lp),Xd("toUVec2",Vp),Xd("toBVec2",Dp),Xd("toVec3",kp),Xd("toIVec3",Gp),Xd("toUVec3",Wp),Xd("toBVec3",jp),Xd("toVec4",Hp),Xd("toIVec4",$p),Xd("toUVec4",qp),Xd("toBVec4",Xp),Xd("toMat2",Yp),Xd("toMat3",Zp),Xd("toMat4",Jp);const tm=Sp(Od),em=(t,e)=>Tp(new zd(Tp(t),e)),sm=(t,e)=>Tp(new kd(Tp(t),e));Xd("element",tm),Xd("convert",em);class im extends Ud{static get type(){return"UniformGroupNode"}constructor(t,e=!1,s=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=s,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const rm=t=>new im(t),nm=(t,e=0)=>new im(t,!0,e),om=nm("frame"),am=nm("render"),hm=rm("object");class um extends jd{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=hm}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate((e=>{const i=t(e,s);void 0!==i&&(this.value=i)}),e)}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const n=r.getInputType(t),o=t.getUniformFromNode(r,n,t.shaderStage,this.name||t.context.label),a=t.getPropertyName(o);return void 0!==t.context.label&&delete t.context.label,t.format(a,s,e)}}const lm=(t,e)=>{const s=bp(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return Tp(new um(i,s))};class cm extends Ud{static get type(){return"PropertyNode"}constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return!0===this.varying?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const dm=(t,e)=>Tp(new cm(t,e)),pm=(t,e)=>Tp(new cm(t,e,!0)),mm=Mp(cm,"vec4","DiffuseColor"),gm=Mp(cm,"vec3","EmissiveColor"),fm=Mp(cm,"float","Roughness"),ym=Mp(cm,"float","Metalness"),xm=Mp(cm,"float","Clearcoat"),bm=Mp(cm,"float","ClearcoatRoughness"),vm=Mp(cm,"vec3","Sheen"),Tm=Mp(cm,"float","SheenRoughness"),_m=Mp(cm,"float","Iridescence"),wm=Mp(cm,"float","IridescenceIOR"),Sm=Mp(cm,"float","IridescenceThickness"),Mm=Mp(cm,"float","AlphaT"),Am=Mp(cm,"float","Anisotropy"),Nm=Mp(cm,"vec3","AnisotropyT"),Cm=Mp(cm,"vec3","AnisotropyB"),Rm=Mp(cm,"color","SpecularColor"),Em=Mp(cm,"float","SpecularF90"),Bm=Mp(cm,"float","Shininess"),Im=Mp(cm,"vec4","Output"),Pm=Mp(cm,"float","dashSize"),Fm=Mp(cm,"float","gapSize"),Um=Mp(cm,"float","pointWidth"),Om=Mp(cm,"float","IOR"),zm=Mp(cm,"float","Transmission"),Lm=Mp(cm,"float","Thickness"),Vm=Mp(cm,"float","AttenuationDistance"),Dm=Mp(cm,"color","AttenuationColor"),km=Mp(cm,"float","Dispersion");class Gm extends Ld{static get type(){return"AssignNode"}constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return"void"!==e?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(!1===t.isAvailable("swizzleAssign")&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return Pd.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(t),n=s.getNodeType(t),o=s.context({assign:!0}).build(t),a=i.build(t,n),h=i.getNodeType(t),u=t.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==e&&(l=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`,this);const h=s.node.context({assign:!0}).build(t);for(let e=0;e<s.components.length;e++){const i=s.components[e];t.addLineFlowCode(`${h}.${i} = ${r}[ ${e} ]`,this)}"void"!==e&&(l=o)}else l=`${o} = ${a}`,"void"!==e&&"void"!==h||(t.addLineFlowCode(l,this),"void"!==e&&(l=o));return u.initialized=!0,t.format(l,n,e)}}const Wm=Sp(Gm);Xd("assign",Wm);class jm extends Ld{static get type(){return"FunctionCallNode"}constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,i=s.getInputs(t),r=this.parameters,n=(e,s)=>{const i=s.type;let r;return r="pointer"===i?"&"+e.build(t):e.build(t,i),r};if(Array.isArray(r))for(let t=0;t<r.length;t++)e.push(n(r[t],i[t]));else for(const t of i){const s=r[t.name];if(void 0===s)throw new Error(`FunctionCallNode: Input '${t.name}' not found in FunctionNode.`);e.push(n(s,t))}return`${s.build(t,"property")}( ${e.join(", ")} )`}}const Hm=(t,...e)=>(e=e.length>1||e[0]&&!0===e[0].isNode?wp(e):_p(e[0]),Tp(new jm(Tp(t),e)));Xd("call",Hm);class $m extends Ld{static get type(){return"OperatorNode"}constructor(t,e,s,...i){if(super(),i.length>0){let r=new $m(t,e,s);for(let e=0;e<i.length-1;e++)r=new $m(t,r,i[e]);e=r,s=i[i.length-1]}this.op=t,this.aNode=e,this.bNode=s}getNodeType(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=i.getNodeType(t),o=void 0!==r?r.getNodeType(t):null;if("void"===n||"void"===o)return"void";if("%"===s)return n;if("~"===s||"&"===s||"|"===s||"^"===s||">>"===s||"<<"===s)return t.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=e?t.getTypeLength(e):Math.max(t.getTypeLength(n),t.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&t.isMatrix(o)?o:t.isMatrix(n)&&t.isVector(o)?t.getVectorFromMatrix(n):t.isVector(n)&&t.isMatrix(o)?t.getVectorFromMatrix(o):t.getTypeLength(o)>t.getTypeLength(n)?o:n}generate(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(t,e);let o=null,a=null;"void"!==n?(o=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?t.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=t.changeComponentType(a,"uint")):t.isMatrix(o)&&t.isVector(a)?a=t.getVectorFromMatrix(o):o=t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(t,o),u=void 0!==r?r.build(t,a):null,l=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} < ${u} )`,n,e):"<="===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} <= ${u} )`,n,e):">"===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} > ${u} )`,n,e):">="===s&&l>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${h}, ${u} )`,n,e):t.format(`( ${h} >= ${u} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`( ${h} ${s} ${u} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`${h} ${s} ${u}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const qm=Sp($m,"+"),Xm=Sp($m,"-"),Ym=Sp($m,"*"),Zm=Sp($m,"/"),Jm=Sp($m,"%"),Km=Sp($m,"=="),Qm=Sp($m,"!="),tg=Sp($m,"<"),eg=Sp($m,">"),sg=Sp($m,"<="),ig=Sp($m,">="),rg=Sp($m,"&&"),ng=Sp($m,"||"),og=Sp($m,"!"),ag=Sp($m,"^^"),hg=Sp($m,"&"),ug=Sp($m,"~"),lg=Sp($m,"|"),cg=Sp($m,"^"),dg=Sp($m,"<<"),pg=Sp($m,">>");Xd("add",qm),Xd("sub",Xm),Xd("mul",Ym),Xd("div",Zm),Xd("modInt",Jm),Xd("equal",Km),Xd("notEqual",Qm),Xd("lessThan",tg),Xd("greaterThan",eg),Xd("lessThanEqual",sg),Xd("greaterThanEqual",ig),Xd("and",rg),Xd("or",ng),Xd("not",og),Xd("xor",ag),Xd("bitAnd",hg),Xd("bitNot",ug),Xd("bitOr",lg),Xd("bitXor",cg),Xd("shiftLeft",dg),Xd("shiftRight",pg);const mg=(...t)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),Jm(...t));Xd("remainder",mg);class gg extends Ld{static get type(){return"MathNode"}constructor(t,e,s=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s),o=t.isMatrix(i)?0:t.getTypeLength(i);return r>n&&r>o?e:n>o?s:o>r?i:e}getNodeType(t){const e=this.method;return e===gg.LENGTH||e===gg.DISTANCE||e===gg.DOT?"float":e===gg.CROSS?"vec3":e===gg.ALL?"bool":e===gg.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===gg.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),r=this.getInputType(t),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===t.renderer.isWebGLRenderer;if(s===gg.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=Hp(kp(i),0):s=Hp(kp(s),0);const r=Ym(s,i).xyz;return Pg(r).build(t,e)}if(s===gg.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===gg.ONE_MINUS)return Xm(1,n).build(t,e);if(s===gg.RECIPROCAL)return Zm(1,n).build(t,e);if(s===gg.DIFFERENCE)return kg(Xm(n,o)).build(t,e);{const u=[];return s===gg.CROSS||s===gg.MOD?u.push(n.build(t,i),o.build(t,i)):h&&s===gg.STEP?u.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===gg.MIN||s===gg.MAX)||s===gg.MOD?u.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===gg.REFRACT?u.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===gg.MIX?u.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(u.push(n.build(t,r)),null!==o&&u.push(o.build(t,r)),null!==a&&u.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${u.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}gg.ALL="all",gg.ANY="any",gg.EQUALS="equals",gg.RADIANS="radians",gg.DEGREES="degrees",gg.EXP="exp",gg.EXP2="exp2",gg.LOG="log",gg.LOG2="log2",gg.SQRT="sqrt",gg.INVERSE_SQRT="inversesqrt",gg.FLOOR="floor",gg.CEIL="ceil",gg.NORMALIZE="normalize",gg.FRACT="fract",gg.SIN="sin",gg.COS="cos",gg.TAN="tan",gg.ASIN="asin",gg.ACOS="acos",gg.ATAN="atan",gg.ABS="abs",gg.SIGN="sign",gg.LENGTH="length",gg.NEGATE="negate",gg.ONE_MINUS="oneMinus",gg.DFDX="dFdx",gg.DFDY="dFdy",gg.ROUND="round",gg.RECIPROCAL="reciprocal",gg.TRUNC="trunc",gg.FWIDTH="fwidth",gg.BITCAST="bitcast",gg.TRANSPOSE="transpose",gg.ATAN2="atan2",gg.MIN="min",gg.MAX="max",gg.MOD="mod",gg.STEP="step",gg.REFLECT="reflect",gg.DISTANCE="distance",gg.DIFFERENCE="difference",gg.DOT="dot",gg.CROSS="cross",gg.POW="pow",gg.TRANSFORM_DIRECTION="transformDirection",gg.MIX="mix",gg.CLAMP="clamp",gg.REFRACT="refract",gg.SMOOTHSTEP="smoothstep",gg.FACEFORWARD="faceforward";const fg=Pp(1e-6),yg=Pp(1e6),xg=Pp(Math.PI),bg=Pp(2*Math.PI),vg=Sp(gg,gg.ALL),Tg=Sp(gg,gg.ANY),_g=Sp(gg,gg.EQUALS),wg=Sp(gg,gg.RADIANS),Sg=Sp(gg,gg.DEGREES),Mg=Sp(gg,gg.EXP),Ag=Sp(gg,gg.EXP2),Ng=Sp(gg,gg.LOG),Cg=Sp(gg,gg.LOG2),Rg=Sp(gg,gg.SQRT),Eg=Sp(gg,gg.INVERSE_SQRT),Bg=Sp(gg,gg.FLOOR),Ig=Sp(gg,gg.CEIL),Pg=Sp(gg,gg.NORMALIZE),Fg=Sp(gg,gg.FRACT),Ug=Sp(gg,gg.SIN),Og=Sp(gg,gg.COS),zg=Sp(gg,gg.TAN),Lg=Sp(gg,gg.ASIN),Vg=Sp(gg,gg.ACOS),Dg=Sp(gg,gg.ATAN),kg=Sp(gg,gg.ABS),Gg=Sp(gg,gg.SIGN),Wg=Sp(gg,gg.LENGTH),jg=Sp(gg,gg.NEGATE),Hg=Sp(gg,gg.ONE_MINUS),$g=Sp(gg,gg.DFDX),qg=Sp(gg,gg.DFDY),Xg=Sp(gg,gg.ROUND),Yg=Sp(gg,gg.RECIPROCAL),Zg=Sp(gg,gg.TRUNC),Jg=Sp(gg,gg.FWIDTH),Kg=Sp(gg,gg.BITCAST),Qg=Sp(gg,gg.TRANSPOSE),tf=Sp(gg,gg.ATAN2),ef=Sp(gg,gg.MIN),sf=Sp(gg,gg.MAX),rf=Sp(gg,gg.MOD),nf=Sp(gg,gg.STEP),of=Sp(gg,gg.REFLECT),af=Sp(gg,gg.DISTANCE),hf=Sp(gg,gg.DIFFERENCE),uf=Sp(gg,gg.DOT),lf=Sp(gg,gg.CROSS),cf=Sp(gg,gg.POW),df=Sp(gg,gg.POW,2),pf=Sp(gg,gg.POW,3),mf=Sp(gg,gg.POW,4),gf=Sp(gg,gg.TRANSFORM_DIRECTION),ff=t=>Ym(Gg(t),cf(kg(t),1/3)),yf=t=>uf(t,t),xf=Sp(gg,gg.MIX),bf=(t,e=0,s=1)=>Tp(new gg(gg.CLAMP,Tp(t),Tp(e),Tp(s))),vf=t=>bf(t),Tf=Sp(gg,gg.REFRACT),_f=Sp(gg,gg.SMOOTHSTEP),wf=Sp(gg,gg.FACEFORWARD),Sf=Ap((([t])=>{const e=uf(t.xy,zp(12.9898,78.233)),s=rf(e,xg);return Fg(Ug(s).mul(43758.5453))})),Mf=(t,e,s)=>xf(e,s,t),Af=(t,e,s)=>_f(e,s,t);Xd("all",vg),Xd("any",Tg),Xd("equals",_g),Xd("radians",wg),Xd("degrees",Sg),Xd("exp",Mg),Xd("exp2",Ag),Xd("log",Ng),Xd("log2",Cg),Xd("sqrt",Rg),Xd("inverseSqrt",Eg),Xd("floor",Bg),Xd("ceil",Ig),Xd("normalize",Pg),Xd("fract",Fg),Xd("sin",Ug),Xd("cos",Og),Xd("tan",zg),Xd("asin",Lg),Xd("acos",Vg),Xd("atan",Dg),Xd("abs",kg),Xd("sign",Gg),Xd("length",Wg),Xd("lengthSq",yf),Xd("negate",jg),Xd("oneMinus",Hg),Xd("dFdx",$g),Xd("dFdy",qg),Xd("round",Xg),Xd("reciprocal",Yg),Xd("trunc",Zg),Xd("fwidth",Jg),Xd("atan2",tf),Xd("min",ef),Xd("max",sf),Xd("mod",rf),Xd("step",nf),Xd("reflect",of),Xd("distance",af),Xd("dot",uf),Xd("cross",lf),Xd("pow",cf),Xd("pow2",df),Xd("pow3",pf),Xd("pow4",mf),Xd("transformDirection",gf),Xd("mix",Mf),Xd("clamp",bf),Xd("refract",Tf),Xd("smoothstep",Af),Xd("faceForward",wf),Xd("difference",hf),Xd("saturate",vf),Xd("cbrt",ff),Xd("transpose",Qg),Xd("rand",Sf);class Nf extends Ud{static get type(){return"ConditionalNode"}constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=this.condNode.cache(),s=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,r=t.context.nodeBlock;t.getDataFromNode(s).parentNodeBlock=r,null!==i&&(t.getDataFromNode(i).parentNodeBlock=r);const n=t.getNodeProperties(this);n.condNode=e,n.ifNode=s.context({nodeBlock:s}),n.elseNode=i?i.context({nodeBlock:i}):null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=t.getNodeProperties(this),a="void"!==e,h=a?dm(s).build(t):"";i.nodeProperty=h;const u=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(t,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+l+"\n\n"+t.tab+"}"),null!==o){t.addFlowCode(" else {\n\n").addFlowTab();let e=o.build(t,s);e&&(e=a?h+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(h,s,e)}}const Cf=Sp(Nf);Xd("select",Cf);const Rf=(...t)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Cf(...t));Xd("cond",Rf);class Ef extends Ud{static get type(){return"ContextNode"}constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.value});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.value});const i=this.node.build(t,e);return t.setContext(s),i}}const Bf=Sp(Ef),If=(t,e)=>Bf(t,{label:e});Xd("context",Bf),Xd("label",If);class Pf extends Ud{static get type(){return"VarNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,i=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),n=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${n}`,this),r}}const Ff=Sp(Pf);Xd("toVar",((...t)=>Ff(...t).append()));const Uf=t=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Ff(t));Xd("temp",Uf);class Of extends Ud{static get type(){return"VaryingNode"}constructor(t,e=null){super(),this.node=t,this.name=e,this.isVaryingNode=!0}isGlobal(){return!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}setupVarying(t){const e=t.getNodeProperties(this);let s=e.varying;if(void 0===s){const i=this.name,r=this.getNodeType(t);e.varying=s=t.getVaryingFromNode(this,i,r),e.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===t.shaderStage),s}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),s=this.setupVarying(t);if(void 0===e.propertyName){const i=this.getNodeType(t),r=t.getPropertyName(s,Nd.VERTEX);t.flowNodeFromShaderStage(Nd.VERTEX,this.node,i,r),e.propertyName=r}return t.getPropertyName(s)}}const zf=Sp(Of);Xd("varying",zf);const Lf="WorkingColorSpace",Vf="OutputColorSpace";function Df(t){let e=null;return t===Je?e="Linear":t===Ze&&(e="sRGB"),e}function kf(t,e){return Df(t)+"To"+Df(e)}class Gf extends Ld{static get type(){return"ColorSpaceNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.source=e,this.target=s}getColorSpace(t,e){return e===Lf?ii.workingColorSpace:e===Vf?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{renderer:e}=t,{colorNode:s}=this,i=this.getColorSpace(t,this.source),r=this.getColorSpace(t,this.target);if(i===r)return s;const n=kf(i,r);let o=null;const a=e.nodes.library.getColorSpaceFunction(n);return null!==a?o=Hp(a(s.rgb),s.a):(console.error("ColorSpaceNode: Unsupported Color Space configuration.",n),o=s),o}}const Wf=t=>Tp(new Gf(Tp(t),Lf,Vf)),jf=t=>Tp(new Gf(Tp(t),Vf,Lf)),Hf=(t,e)=>Tp(new Gf(Tp(t),Lf,e)),$f=(t,e)=>Tp(new Gf(Tp(t),e,Lf));Xd("toOutputColorSpace",Wf),Xd("toWorkingColorSpace",jf),Xd("workingToColorSpace",Hf),Xd("colorSpaceToWorking",$f);let qf=class extends Od{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}};class Xf extends Ud{static get type(){return"ReferenceBaseNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=Cd.OBJECT}setGroup(t){return this.group=t,this}element(t){return Tp(new qf(this,Tp(t)))}setNodeType(t){const e=lm(null,t).getSelf();null!==this.group&&e.setGroup(this.group),this.node=e}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let t=1;t<e.length;t++)s=s[e[t]];return s}updateReference(t){return this.reference=null!==this.object?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}class Yf extends Xf{static get type(){return"RendererReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.renderer=s,this.setGroup(am)}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const Zf=(t,e,s)=>Tp(new Yf(t,e,s));class Jf extends Ld{static get type(){return"ToneMappingNode"}constructor(t,e=Qf,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){return bd(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;let i=null;const r=t.renderer.nodes.library.getToneMappingFunction(s);return null!==r?i=Hp(r(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),i=e),i}}const Kf=(t,e,s)=>Tp(new Jf(t,Tp(e),Tp(s))),Qf=Zf("toneMappingExposure","float");Xd("toneMapping",((t,e,s)=>Kf(e,s,t)));class ty extends jd{static get type(){return"BufferAttributeNode"}constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=Ss,this.instanced=!1,this.attribute=null,this.global=!0,t&&!0===t.isBufferAttribute&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(0===this.bufferStride&&0===this.bufferOffset){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return null===this.bufferType&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(null!==this.attribute)return;const e=this.getNodeType(t),s=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new Qn(s,r),a=new eo(o,i,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=zf(this).build(t,e)}return r}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const ey=(t,e,s,i)=>Tp(new ty(t,e,s,i)),sy=(t,e,s,i)=>ey(t,e,s,i).setUsage(Ms),iy=(t,e,s,i)=>ey(t,e,s,i).setInstanced(!0),ry=(t,e,s,i)=>sy(t,e,s,i).setInstanced(!0);Xd("toAttribute",(t=>ey(t.value)));class ny extends Ud{static get type(){return"ComputeNode"}constructor(t,e,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=Cd.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let s=e[0];for(let t=1;t<e.length;t++)s*=e[t];this.dispatchCount=Math.ceil(t/s)}onInit(t){return this.onInitFunction=t,this}updateBefore({renderer:t}){t.compute(this)}generate(t){const{shaderStage:e}=t;if("compute"===e){const e=this.computeNode.build(t,"void");""!==e&&t.addLineFlowCode(e,this)}}}const oy=(t,e,s)=>Tp(new ny(Tp(t),e,s));Xd("compute",oy);class ay extends Ud{static get type(){return"CacheNode"}constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),i=t.getCacheFromNode(this,this.parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const hy=(t,...e)=>Tp(new ay(Tp(t),...e));Xd("cache",hy);class uy extends Ud{static get type(){return"BypassNode"}constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return""!==e&&t.addLineFlowCode(e,this),this.outputNode.build(t)}}const ly=Sp(uy);Xd("bypass",ly);class cy extends Ud{static get type(){return"RemapNode"}constructor(t,e,s,i=Pp(0),r=Pp(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=t.sub(e).div(s.sub(e));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const dy=Sp(cy,null,null,{doClamp:!1}),py=Sp(cy);Xd("remap",dy),Xd("remapClamp",py);class my extends Ud{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if("void"!==s)return t.format(`( ${i} )`,s,e);t.addLineFlowCode(i,this)}}const gy=Sp(my),fy=t=>(t?Cf(t,gy("discard")):gy("discard")).append(),yy=()=>gy("return").append();Xd("discard",fy);class xy extends Ld{static get type(){return"RenderOutputNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=(null!==this.toneMapping?this.toneMapping:t.toneMapping)||0,i=(null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace)||Ye;return 0!==s&&(e=e.toneMapping(s)),i!==Ye&&i!==ii.workingColorSpace&&(e=e.workingToColorSpace(i)),e}}const by=(t,e=null,s=null)=>Tp(new xy(Tp(t),e,s));function vy(t){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",t)}Xd("renderOutput",by);class Ty extends Ud{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(null===e){const s=this.getAttributeName(t);if(t.hasGeometryAttribute(s)){const i=t.geometry.getAttribute(s);e=t.getTypeFromAttribute(i)}else e="float"}return e}setAttributeName(t){return this._attributeName=t,this}getAttributeName(){return this._attributeName}generate(t){const e=this.getAttributeName(t),s=this.getNodeType(t);if(!0===t.hasGeometryAttribute(e)){const i=t.geometry.getAttribute(e),r=t.getTypeFromAttribute(i),n=t.getAttribute(e,r);if("vertex"===t.shaderStage)return t.format(n.name,r,s);return zf(this).build(t,s)}return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(s)}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const _y=(t,e)=>Tp(new Ty(t,e)),wy=t=>_y("uv"+(t>0?t:""),"vec2");class Sy extends Ud{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=null===this.levelNode?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const My=Sp(Sy);class Ay extends um{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=Cd.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&void 0!==s.width){const{width:t,height:e}=s;this.value=Math.log2(Math.max(t,e))}}}const Ny=Sp(Ay);class Cy extends um{static get type(){return"TextureNode"}constructor(t,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Cd.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(null===e)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===Bt?"uvec4":this.value.type===Et?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return wy(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=lm(this.value.matrix)),this._matrixUniform.mul(kp(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?Cd.FRAME:Cd.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=this.sampler?e.flipY():e.setY(Fp(My(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==t.context.forceUVContext||!t.context.getUV||(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=i,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,!0===this.sampler?"vec2":"ivec2")}generateSnippet(t,e,s,i,r,n,o,a){const h=this.value;let u;return u=i?t.generateTextureLevel(h,e,s,i,n):r?t.generateTextureBias(h,e,s,r,n):a?t.generateTextureGrad(h,e,s,a,n):o?t.generateTextureCompare(h,e,s,o,n):!1===this.sampler?t.generateTextureLoad(h,e,s,n):t.generateTexture(h,e,s,n),u}generate(t,e){const s=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(t,"property");if("sampler"===e)return r+"_sampler";if(t.isReference(e))return r;{const n=t.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:e,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=a?a.build(t,"float"):null,m=u?u.build(t,"int"):null,g=h?h.build(t,"float"):null,f=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,y=t.getVarFromNode(this);o=t.getPropertyName(y);const x=this.generateSnippet(t,r,c,d,p,m,g,f);t.addLineFlowCode(`${o} = ${x}`,this),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsToWorkingColorSpace(i)&&(a=$f(gy(a,h),i.colorSpace).setup(t).build(t,h)),t.format(a,h,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}blur(t){const e=this.clone();return e.biasNode=Tp(t).mul(Ny(e)),e.referenceNode=this.getSelf(),Tp(e)}level(t){const e=this.clone();return e.levelNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}size(t){return My(this,t)}bias(t){const e=this.clone();return e.biasNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}compare(t){const e=this.clone();return e.compareNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}grad(t,e){const s=this.clone();return s.gradNode=[Tp(t),Tp(e)],s.referenceNode=this.getSelf(),Tp(s)}depth(t){const e=this.clone();return e.depthNode=Tp(t),e.referenceNode=this.getSelf(),Tp(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;null!==e&&(e.value=t.matrix),!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const Ry=Sp(Cy),Ey=(...t)=>Ry(...t).setSampler(!1),By=t=>(!0===t.isNode?t:Ry(t)).convert("sampler"),Iy=lm("float").label("cameraNear").setGroup(am).onRenderUpdate((({camera:t})=>t.near)),Py=lm("float").label("cameraFar").setGroup(am).onRenderUpdate((({camera:t})=>t.far)),Fy=lm("mat4").label("cameraProjectionMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.projectionMatrix)),Uy=lm("mat4").label("cameraProjectionMatrixInverse").setGroup(am).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Oy=lm("mat4").label("cameraViewMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),zy=lm("mat4").label("cameraWorldMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.matrixWorld)),Ly=lm("mat3").label("cameraNormalMatrix").setGroup(am).onRenderUpdate((({camera:t})=>t.normalMatrix)),Vy=lm(new Ai).label("cameraPosition").setGroup(am).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Dy extends Ud{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=Cd.OBJECT,this._uniformNode=new um(null)}getNodeType(){const t=this.scope;return t===Dy.WORLD_MATRIX?"mat4":t===Dy.POSITION||t===Dy.VIEW_POSITION||t===Dy.DIRECTION||t===Dy.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Dy.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Dy.POSITION)s.value=s.value||new Ai,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Dy.SCALE)s.value=s.value||new Ai,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Dy.DIRECTION)s.value=s.value||new Ai,e.getWorldDirection(s.value);else if(i===Dy.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ai,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Dy.WORLD_MATRIX?this._uniformNode.nodeType="mat4":e!==Dy.POSITION&&e!==Dy.VIEW_POSITION&&e!==Dy.DIRECTION&&e!==Dy.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}Dy.WORLD_MATRIX="worldMatrix",Dy.POSITION="position",Dy.SCALE="scale",Dy.VIEW_POSITION="viewPosition",Dy.DIRECTION="direction";const ky=Sp(Dy,Dy.DIRECTION),Gy=Sp(Dy,Dy.WORLD_MATRIX),Wy=Sp(Dy,Dy.POSITION),jy=Sp(Dy,Dy.SCALE),Hy=Sp(Dy,Dy.VIEW_POSITION);class $y extends Dy{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}const qy=Mp($y,$y.DIRECTION),Xy=Mp($y,$y.WORLD_MATRIX),Yy=Mp($y,$y.POSITION),Zy=Mp($y,$y.SCALE),Jy=Mp($y,$y.VIEW_POSITION),Ky=lm(new Zs).onObjectUpdate((({object:t},e)=>e.value.getNormalMatrix(t.matrixWorld))),Qy=lm(new sr).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert())),tx=Oy.mul(Xy).toVar("modelViewMatrix"),ex=Ap((t=>(t.context.isHighPrecisionModelViewMatrix=!0,lm("mat4").onObjectUpdate((({object:t,camera:e})=>t.modelViewMatrix.multiplyMatrices(e.matrixWorldInverse,t.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),sx=Ap((t=>{const e=t.context.isHighPrecisionModelViewMatrix;return lm("mat3").onObjectUpdate((({object:t,camera:s})=>(!0!==e&&t.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),ix=_y("position","vec3"),rx=ix.varying("positionLocal"),nx=ix.varying("positionPrevious"),ox=Xy.mul(rx).xyz.varying("v_positionWorld"),ax=rx.transformDirection(Xy).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),hx=tx.mul(rx).xyz.varying("v_positionView"),ux=hx.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class lx extends Ud{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===Us&&s.side===d?"false":t.getFrontFacing()}}const cx=Mp(lx),dx=Pp(cx).mul(2).sub(1),px=_y("normal","vec3"),mx=Ap((t=>!1===t.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),kp(0,1,0)):px),"vec3").once()().toVar("normalLocal"),gx=hx.dFdx().cross(hx.dFdy()).normalize().toVar("normalFlat"),fx=Ap((t=>{let e;return e=!0===t.material.flatShading?gx:zf(_x(mx),"v_normalView").normalize(),e}),"vec3").once()().toVar("normalView"),yx=zf(fx.transformDirection(Oy),"v_normalWorld").normalize().toVar("normalWorld"),xx=Ap((t=>t.context.setupNormal()),"vec3").once()().mul(dx).toVar("transformedNormalView"),bx=xx.transformDirection(Oy).toVar("transformedNormalWorld"),vx=Ap((t=>t.context.setupClearcoatNormal()),"vec3").once()().mul(dx).toVar("transformedClearcoatNormalView"),Tx=Ap((([t,e=Xy])=>{const s=Zp(e),i=t.div(kp(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(i).xyz})),_x=Ap((([t],e)=>{const s=e.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(t);const i=Ky.mul(t);return Oy.transformDirection(i)})),wx=lm(0).onReference((({material:t})=>t)).onRenderUpdate((({material:t})=>t.refractionRatio)),Sx=ux.negate().reflect(xx),Mx=ux.negate().refract(xx,wx),Ax=Sx.transformDirection(Oy).toVar("reflectVector"),Nx=Mx.transformDirection(Oy).toVar("reflectVector");class Cx extends Cy{static get type(){return"CubeTextureNode"}constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===ht?Ax:t.mapping===ut?Nx:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),kp(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Os&&s.isRenderTargetTexture?e:kp(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const Rx=Sp(Cx);class Ex extends um{static get type(){return"BufferNode"}constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const Bx=(t,e,s)=>Tp(new Ex(t,e,s));class Ix extends Od{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class Px extends Ex{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=Cd.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;s<t.length;s++){e[4*s]=t[s]}else if("color"===i)for(let s=0;s<t.length;s++){const i=4*s,r=t[s];e[i]=r.r,e[i+1]=r.g,e[i+2]=r.b||0}else for(let s=0;s<t.length;s++){const i=4*s,r=t[s];e[i]=r.x,e[i+1]=r.y,e[i+2]=r.z||0,e[i+3]=r.w||0}}setup(t){const e=this.array.length;this._elementType=null===this.elementType?_d(this.array[0]):this.elementType,this._elementLength=t.getTypeLength(this._elementType);let s=Float32Array;return"i"===this._elementType.charAt(0)?s=Int32Array:"u"===this._elementType.charAt(0)&&(s=Uint32Array),this.value=new s(4*e),this.bufferCount=e,this.bufferType=t.changeComponentType("vec4",t.getComponentType(this._elementType)),super.setup(t)}element(t){return Tp(new Ix(this,Tp(t)))}}const Fx=(t,e)=>Tp(new Px(t,e)),Ux=(t,e)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),Tp(new Px(t,e)));class Ox extends Od{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class zx extends Ud{static get type(){return"ReferenceNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=Cd.OBJECT}element(t){return Tp(new Ox(this,Tp(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;e=null!==this.count?Bx(null,t,this.count):Array.isArray(this.getValueFromReference())?Fx(null,t):"texture"===t?Ry(null):"cubeTexture"===t?Rx(null):lm(null,t),null!==this.group&&e.setGroup(this.group),null!==this.name&&e.label(this.name),this.node=e.getSelf()}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let t=1;t<e.length;t++)s=s[e[t]];return s}updateReference(t){return this.reference=null!==this.object?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}const Lx=(t,e,s)=>Tp(new zx(t,e,s)),Vx=(t,e,s,i)=>Tp(new zx(t,e,i,s));class Dx extends zx{static get type(){return"MaterialReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const kx=(t,e,s)=>Tp(new Dx(t,e,s)),Gx=Ap((t=>(!1===t.geometry.hasAttribute("tangent")&&t.geometry.computeTangents(),_y("tangent","vec4"))))(),Wx=Gx.xyz.toVar("tangentLocal"),jx=tx.mul(Hp(Wx,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Hx=jx.transformDirection(Oy).varying("v_tangentWorld").normalize().toVar("tangentWorld"),$x=jx.toVar("transformedTangentView"),qx=$x.transformDirection(Oy).normalize().toVar("transformedTangentWorld"),Xx=t=>t.mul(Gx.w).xyz,Yx=zf(Xx(px.cross(Gx)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),Zx=zf(Xx(mx.cross(Wx)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),Jx=zf(Xx(fx.cross(jx)),"v_bitangentView").normalize().toVar("bitangentView"),Kx=zf(Xx(yx.cross(Hx)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Qx=Xx(xx.cross($x)).normalize().toVar("transformedBitangentView"),tb=Qx.transformDirection(Oy).normalize().toVar("transformedBitangentWorld"),eb=Zp(jx,Jx,fx),sb=ux.mul(eb),ib=(t,e)=>t.sub(sb.mul(e)),rb=(()=>{let t=Cm.cross(ux);return t=t.cross(Cm).normalize(),t=xf(t,xx,Am.mul(fm.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})(),nb=Ap((t=>{const{eye_pos:e,surf_norm:s,mapN:i,uv:r}=t,n=e.dFdx(),o=e.dFdy(),a=r.dFdx(),h=r.dFdy(),u=s,l=o.cross(u),c=u.cross(n),d=l.mul(a.x).add(c.mul(h.x)),p=l.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=dx.mul(m.inverseSqrt());return qm(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()}));class ob extends Ld{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=kp(i.xy.mul(s),i.z));let r=null;if(1===e)r=_x(i);else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?eb.mul(i).normalize():nb({eye_pos:hx,surf_norm:fx,mapN:i,uv:wy()})}return r}}const ab=Sp(ob),hb=Ap((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||wy()),forceUVContext:!0}),i=Pp(s((t=>t)));return zp(Pp(s((t=>t.add(t.dFdx())))).sub(i),Pp(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),ub=Ap((t=>{const{surf_pos:e,surf_norm:s,dHdxy:i}=t,r=e.dFdx().normalize(),n=s,o=e.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(dx),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()}));class lb extends Ld{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=hb({textureNode:this.textureNode,bumpScale:t});return ub({surf_pos:hx,surf_norm:fx,dHdxy:e})}}const cb=Sp(lb),db=new Map;class pb extends Ud{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let s=db.get(t);return void 0===s&&(s=kx(t,e),db.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache("map"===t?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let i=null;if(s===pb.COLOR){const t=void 0!==e.color?this.getColor(s):kp();i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===pb.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===pb.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:Pp(1);else if(s===pb.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===pb.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===pb.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===pb.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===pb.EMISSIVE){const t=this.getFloat("emissiveIntensity"),r=this.getColor(s).mul(t);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?r.mul(this.getTexture(s)):r}else if(s===pb.NORMAL)e.normalMap?(i=ab(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=e.normalMapType):i=e.bumpMap?cb(this.getTexture("bump").r,this.getFloat("bumpScale")):fx;else if(s===pb.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===pb.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===pb.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?ab(this.getTexture(s),this.getCache(s+"Scale","vec2")):fx;else if(s===pb.SHEEN){const t=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=e.sheenColorMap&&!0===e.sheenColorMap.isTexture?t.mul(this.getTexture("sheenColor").rgb):t}else if(s===pb.SHEEN_ROUGHNESS){const t=this.getFloat(s);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(s).a):t,i=i.clamp(.07,1)}else if(s===pb.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=Yp(Jb.x,Jb.y,Jb.y.negate(),Jb.x).mul(t.rg.mul(2).sub(zp(1)).normalize().mul(t.b))}else i=Jb;else if(s===pb.IRIDESCENCE_THICKNESS){const t=Lx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=Lx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===pb.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===pb.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===pb.IOR)i=this.getFloat(s);else if(s===pb.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===pb.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}pb.ALPHA_TEST="alphaTest",pb.COLOR="color",pb.OPACITY="opacity",pb.SHININESS="shininess",pb.SPECULAR="specular",pb.SPECULAR_STRENGTH="specularStrength",pb.SPECULAR_INTENSITY="specularIntensity",pb.SPECULAR_COLOR="specularColor",pb.REFLECTIVITY="reflectivity",pb.ROUGHNESS="roughness",pb.METALNESS="metalness",pb.NORMAL="normal",pb.CLEARCOAT="clearcoat",pb.CLEARCOAT_ROUGHNESS="clearcoatRoughness",pb.CLEARCOAT_NORMAL="clearcoatNormal",pb.EMISSIVE="emissive",pb.ROTATION="rotation",pb.SHEEN="sheen",pb.SHEEN_ROUGHNESS="sheenRoughness",pb.ANISOTROPY="anisotropy",pb.IRIDESCENCE="iridescence",pb.IRIDESCENCE_IOR="iridescenceIOR",pb.IRIDESCENCE_THICKNESS="iridescenceThickness",pb.IOR="ior",pb.TRANSMISSION="transmission",pb.THICKNESS="thickness",pb.ATTENUATION_DISTANCE="attenuationDistance",pb.ATTENUATION_COLOR="attenuationColor",pb.LINE_SCALE="scale",pb.LINE_DASH_SIZE="dashSize",pb.LINE_GAP_SIZE="gapSize",pb.LINE_WIDTH="linewidth",pb.LINE_DASH_OFFSET="dashOffset",pb.POINT_WIDTH="pointWidth",pb.DISPERSION="dispersion",pb.LIGHT_MAP="light",pb.AO_MAP="ao";const mb=Mp(pb,pb.ALPHA_TEST),gb=Mp(pb,pb.COLOR),fb=Mp(pb,pb.SHININESS),yb=Mp(pb,pb.EMISSIVE),xb=Mp(pb,pb.OPACITY),bb=Mp(pb,pb.SPECULAR),vb=Mp(pb,pb.SPECULAR_INTENSITY),Tb=Mp(pb,pb.SPECULAR_COLOR),_b=Mp(pb,pb.SPECULAR_STRENGTH),wb=Mp(pb,pb.REFLECTIVITY),Sb=Mp(pb,pb.ROUGHNESS),Mb=Mp(pb,pb.METALNESS),Ab=Mp(pb,pb.NORMAL).context({getUV:null}),Nb=Mp(pb,pb.CLEARCOAT),Cb=Mp(pb,pb.CLEARCOAT_ROUGHNESS),Rb=Mp(pb,pb.CLEARCOAT_NORMAL).context({getUV:null}),Eb=Mp(pb,pb.ROTATION),Bb=Mp(pb,pb.SHEEN),Ib=Mp(pb,pb.SHEEN_ROUGHNESS),Pb=Mp(pb,pb.ANISOTROPY),Fb=Mp(pb,pb.IRIDESCENCE),Ub=Mp(pb,pb.IRIDESCENCE_IOR),Ob=Mp(pb,pb.IRIDESCENCE_THICKNESS),zb=Mp(pb,pb.TRANSMISSION),Lb=Mp(pb,pb.THICKNESS),Vb=Mp(pb,pb.IOR),Db=Mp(pb,pb.ATTENUATION_DISTANCE),kb=Mp(pb,pb.ATTENUATION_COLOR),Gb=Mp(pb,pb.LINE_SCALE),Wb=Mp(pb,pb.LINE_DASH_SIZE),jb=Mp(pb,pb.LINE_GAP_SIZE),Hb=Mp(pb,pb.LINE_WIDTH),$b=Mp(pb,pb.LINE_DASH_OFFSET),qb=Mp(pb,pb.POINT_WIDTH),Xb=Mp(pb,pb.DISPERSION),Yb=Mp(pb,pb.LIGHT_MAP),Zb=Mp(pb,pb.AO_MAP),Jb=lm(new Ys).onReference((function(t){return t.material})).onRenderUpdate((function({material:t}){this.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation))}));class Kb extends Ld{static get type(){return"ModelViewProjectionNode"}constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return zf(t.context.mvp);const e=this.positionNode||rx,s=t.renderer.nodes.modelViewMatrix||tx;return Fy.mul(s).mul(e)}}const Qb=Sp(Kb);class tv extends Ud{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i,r;if(s===tv.VERTEX)i=t.getVertexIndex();else if(s===tv.INSTANCE)i=t.getInstanceIndex();else if(s===tv.DRAW)i=t.getDrawIndex();else if(s===tv.INVOCATION_LOCAL)i=t.getInvocationLocalIndex();else if(s===tv.INVOCATION_SUBGROUP)i=t.getInvocationSubgroupIndex();else{if(s!==tv.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getSubgroupIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=zf(this).build(t,e)}return r}}tv.VERTEX="vertex",tv.INSTANCE="instance",tv.SUBGROUP="subgroup",tv.INVOCATION_LOCAL="invocationLocal",tv.INVOCATION_SUBGROUP="invocationSubgroup",tv.DRAW="draw";const ev=Mp(tv,tv.VERTEX),sv=Mp(tv,tv.INSTANCE),iv=Mp(tv,tv.SUBGROUP),rv=Mp(tv,tv.INVOCATION_SUBGROUP),nv=Mp(tv,tv.INVOCATION_LOCAL),ov=Mp(tv,tv.DRAW);class av extends Ud{static get type(){return"InstanceNode"}constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Cd.FRAME,this.buffer=null,this.bufferColor=null}setup(t){let e=this.instanceMatrixNode,s=this.instanceColorNode;const i=this.instanceMesh;if(null===e){const t=i.instanceMatrix;if(i.count<=1e3)e=Bx(t.array,"mat4",Math.max(i.count,1)).element(sv);else{const s=new vc(t.array,16,1);this.buffer=s;const i=t.usage===Ms?ry:iy,r=[i(s,"vec4",16,0),i(s,"vec4",16,4),i(s,"vec4",16,8),i(s,"vec4",16,12)];e=Jp(...r)}this.instanceMatrixNode=e}const r=i.instanceColor;if(r&&null===s){const t=new zo(r.array,3),e=r.usage===Ms?ry:iy;this.bufferColor=t,s=kp(e(t,"vec3",3,0)),this.instanceColorNode=s}const n=e.mul(rx).xyz;if(rx.assign(n),t.hasGeometryAttribute("normal")){const t=Tx(mx,e);mx.assign(t)}null!==this.instanceColorNode&&pm("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Ms&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Ms&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const hv=Sp(av);class uv extends Ud{static get type(){return"BatchNode"}constructor(t){super("void"),this.batchMesh=t,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=sv:this.batchingIdNode=ov);const e=Ap((([t])=>{const e=My(Ey(this.batchMesh._indirectTexture),0),s=Fp(t).modInt(Fp(e)),i=Fp(t).div(Fp(e));return Ey(this.batchMesh._indirectTexture,Lp(s,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=e(Fp(this.batchingIdNode)),i=this.batchMesh._matricesTexture,r=My(Ey(i),0),n=Pp(s).mul(4).toInt().toVar(),o=n.modInt(r),a=n.div(Fp(r)),h=Jp(Ey(i,Lp(o,a)),Ey(i,Lp(o.add(1),a)),Ey(i,Lp(o.add(2),a)),Ey(i,Lp(o.add(3),a))),u=this.batchMesh._colorsTexture;if(null!==u){const t=Ap((([t])=>{const e=My(Ey(u),0).x,s=t,i=s.modInt(e),r=s.div(e);return Ey(u,Lp(i,r)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),e=t(s);pm("vec3","vBatchColor").assign(e)}const l=Zp(h);rx.assign(h.mul(rx));const c=mx.div(kp(l[0].dot(l[0]),l[1].dot(l[1]),l[2].dot(l[2]))),d=l.mul(c).xyz;mx.assign(d),t.hasGeometryAttribute("tangent")&&Wx.mulAssign(l)}}const lv=Sp(uv),cv=new WeakMap;class dv extends Ud{static get type(){return"SkinningNode"}constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=Cd.OBJECT,this.skinIndexNode=_y("skinIndex","uvec4"),this.skinWeightNode=_y("skinWeight","vec4"),e?(s=Lx("bindMatrix","mat4"),i=Lx("bindMatrixInverse","mat4"),r=Vx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=lm(t.bindMatrix,"mat4"),i=lm(t.bindMatrixInverse,"mat4"),r=Bx(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r,this.previousBoneMatricesNode=null}getSkinnedPosition(t=this.boneMatricesNode,e=rx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=t.element(s.x),a=t.element(s.y),h=t.element(s.z),u=t.element(s.w),l=r.mul(e),c=qm(o.mul(i.x).mul(l),a.mul(i.y).mul(l),h.mul(i.z).mul(l),u.mul(i.w).mul(l));return n.mul(c).xyz}getSkinnedNormal(t=this.boneMatricesNode,e=mx){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:n}=this,o=t.element(s.x),a=t.element(s.y),h=t.element(s.z),u=t.element(s.w);let l=qm(i.x.mul(o),i.y.mul(a),i.z.mul(h),i.w.mul(u));return l=n.mul(l).mul(r),l.transformDirection(e).xyz}getPreviousSkinnedPosition(t){const e=t.object;return null===this.previousBoneMatricesNode&&(e.skeleton.previousBoneMatrices=new Float32Array(e.skeleton.boneMatrices),this.previousBoneMatricesNode=Vx("skeleton.previousBoneMatrices","mat4",e.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,nx)}needsPreviousBoneMatrices(t){const e=t.renderer.getMRT();return e&&e.has("velocity")}setup(t){this.needsPreviousBoneMatrices(t)&&nx.assign(this.getPreviousSkinnedPosition(t));const e=this.getSkinnedPosition();if(rx.assign(e),t.hasGeometryAttribute("normal")){const e=this.getSkinnedNormal();mx.assign(e),t.hasGeometryAttribute("tangent")&&Wx.assign(e)}}generate(t,e){if("void"!==e)return rx.build(t,e)}update(t){const e=(this.useReference?t.object:this.skinnedMesh).skeleton;cv.get(e)!==t.frameId&&(cv.set(e,t.frameId),null!==this.previousBoneMatricesNode&&e.previousBoneMatrices.set(e.boneMatrices),e.update())}}const pv=t=>Tp(new dv(t)),mv=t=>Tp(new dv(t,!0));class gv extends Ud{static get type(){return"LoopNode"}constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode("i".charCodeAt()+t)}getProperties(t){const e=t.getNodeProperties(this);if(void 0!==e.stackNode)return e;const s={};for(let t=0,e=this.params.length-1;t<e;t++){const e=this.params[t],i=!0!==e.isNode&&e.name||this.getVarName(t),r=!0!==e.isNode&&e.type||"int";s[i]=gy(i,r)}const i=t.addStack();return e.returnsNode=this.params[this.params.length-1](s,i,t),e.stackNode=i,t.removeStack(),e}getNodeType(t){const{returnsNode:e}=this.getProperties(t);return e?e.getNodeType(t):"void"}setup(t){this.getProperties(t)}generate(t){const e=this.getProperties(t),s=this.params,i=e.stackNode;for(let e=0,i=s.length-1;e<i;e++){const i=s[e];let r=null,n=null,o=null,a=null,h=null,u=null;i.isNode?(a="int",o=this.getVarName(e),r="0",n=i.build(t,a),h="<"):(a=i.type||"int",o=i.name||this.getVarName(e),r=i.start,n=i.end,h=i.condition,u=i.update,"number"==typeof r?r=r.toString():r&&r.isNode&&(r=r.build(t,a)),"number"==typeof n?n=n.toString():n&&n.isNode&&(n=n.build(t,a)),void 0!==r&&void 0===n?(r+=" - 1",n="0",h=">="):void 0!==n&&void 0===r&&(r="0",h="<"),void 0===h&&(h=Number(r)>Number(n)?">=":"<"));const l={start:r,end:n,condition:h},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;t.addFlowCode((0===e?"\n":"")+t.tab+f+" {\n\n").addFlowTab()}const r=i.build(t,"void"),n=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,s=this.params.length-1;e<s;e++)t.addFlowCode((0===e?"":t.tab)+"}\n\n").removeFlowTab();return t.addFlowTab(),n}}const fv=(...t)=>Tp(new gv(wp(t,"int"))).append(),yv=()=>gy("continue").append(),xv=()=>gy("break").append(),bv=(...t)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),fv(...t)),vv=new WeakMap,Tv=new xi,_v=Ap((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=Fp(ev).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return Ey(t,Lp(h,a)).depth(r).mul(e)}));class wv extends Ud{static get type(){return"MorphNode"}constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=lm(1),this.updateType=Cd.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=e.hasAttribute("normal")&&void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(t){const e=void 0!==t.morphAttributes.position,s=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0;let o=vv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],u=t.morphAttributes.color||[];let l=0;!0===e&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=t.attributes.position.count*l,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new Ti(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*l;for(let x=0;x<n;x++){const b=a[x],v=h[x],T=u[x],_=c*d*4*x;for(let w=0;w<b.count;w++){const S=w*f;!0===e&&(Tv.fromBufferAttribute(b,w),m[_+S+0]=Tv.x,m[_+S+1]=Tv.y,m[_+S+2]=Tv.z,m[_+S+3]=0),!0===s&&(Tv.fromBufferAttribute(v,w),m[_+S+4]=Tv.x,m[_+S+5]=Tv.y,m[_+S+6]=Tv.z,m[_+S+7]=0),!0===i&&(Tv.fromBufferAttribute(T,w),m[_+S+8]=Tv.x,m[_+S+9]=Tv.y,m[_+S+10]=Tv.z,m[_+S+11]=4===T.itemSize?Tv.w:1)}}function y(){g.dispose(),vv.delete(t),t.removeEventListener("dispose",y)}o={count:n,texture:g,stride:l,size:new Ys(c,d)},vv.set(t,o),t.addEventListener("dispose",y)}return o}(e);!0===s&&rx.mulAssign(this.morphBaseInfluence),!0===i&&mx.mulAssign(this.morphBaseInfluence);const u=Fp(h.width);fv(n,(({i:t})=>{const e=Pp(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(Ey(this.mesh.morphTexture,Lp(Fp(t).add(1),Fp(sv))).r):e.assign(Lx("morphTargetInfluences","float").element(t).toVar()),!0===s&&rx.addAssign(_v({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:Fp(0)})),!0===i&&mx.addAssign(_v({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:Fp(1)}))}))}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce(((t,e)=>t+e),0)}}const Sv=Sp(wv),Mv=(t,e)=>{for(const s of e)if(s.isAnalyticLightNode&&s.light.id===t)return s;return null},Av=new WeakMap;class Nv extends Ud{static get type(){return"LightsNode"}constructor(t=[]){super("vec3"),this.totalDiffuseNode=kp().toVar("totalDiffuse"),this.totalSpecularNode=kp().toVar("totalSpecular"),this.outgoingLightNode=kp().toVar("outgoingLight"),this._lights=t,this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(t){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(t);const e=[];for(const t of this._lightNodes)e.push(t.getHash());this._lightNodesHash="lights-"+e.join(",")}return this._lightNodesHash}analyze(t){const e=t.getDataFromNode(this);for(const s of e.nodes)s.build(t)}setupLightsNode(t){const e=[],s=this._lightNodes,i=(t=>t.sort(((t,e)=>t.id-e.id)))(this._lights),r=t.renderer.nodes.library;for(const t of i)if(t.isNode)e.push(Tp(t));else{let i=null;if(null!==s&&(i=Mv(t.id,s)),null===i){const s=r.getLightNodeClass(t.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${t.constructor.name}`);continue}let i=null;Av.has(t)?i=Av.get(t):(i=new s(t),Av.set(t,i)),e.push(i)}}this._lightNodes=e}setup(t){null===this._lightNodes&&this.setupLightsNode(t);const e=t.context,s=e.lightingModel;let i=this.outgoingLightNode;if(s){const{_lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;e.outgoingLight=i;const a=t.addStack();t.getDataFromNode(this).nodes=a.nodes,s.start(e,a,t);for(const e of r)e.build(t);s.indirect(e,a,t);const{backdrop:h,backdropAlpha:u}=e,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=l.add(d);null!==h&&(m=kp(null!==u?u.mix(m,h):h),e.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(e,a,t),i=i.bypass(t.removeStack())}return i}setLights(t){return this._lights=t,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}}const Cv=Sp(Nv);class Rv extends Ud{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class Ev extends Rv{static get type(){return"AONode"}constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}class Bv extends Ef{static get type(){return"LightingContextNode"}constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:kp().toVar("directDiffuse"),directSpecular:kp().toVar("directSpecular"),indirectDiffuse:kp().toVar("indirectDiffuse"),indirectSpecular:kp().toVar("indirectSpecular")};return{radiance:kp().toVar("radiance"),irradiance:kp().toVar("irradiance"),iblIrradiance:kp().toVar("iblIrradiance"),ambientOcclusion:Pp(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:t,backdropAlpha:e}}setup(t){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const Iv=Sp(Bv);class Pv extends Rv{static get type(){return"IrradianceNode"}constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let Fv,Uv;class Ov extends Ud{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===Ov.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=Cd.NONE;return this.scope!==Ov.SIZE&&this.scope!==Ov.VIEWPORT||(t=Cd.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===Ov.VIEWPORT?null!==e?Uv.copy(e.viewport):(t.getViewport(Uv),Uv.multiplyScalar(t.getPixelRatio())):null!==e?(Fv.width=e.width,Fv.height=e.height):t.getDrawingBufferSize(Fv)}setup(){const t=this.scope;let e=null;return e=t===Ov.SIZE?lm(Fv||(Fv=new Ys)):t===Ov.VIEWPORT?lm(Uv||(Uv=new xi)):zp(Vv.div(Lv)),e}generate(t){if(this.scope===Ov.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(Lv).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}Ov.COORDINATE="coordinate",Ov.VIEWPORT="viewport",Ov.SIZE="size",Ov.UV="uv";const zv=Mp(Ov,Ov.UV),Lv=Mp(Ov,Ov.SIZE),Vv=Mp(Ov,Ov.COORDINATE),Dv=Mp(Ov,Ov.VIEWPORT),kv=Dv.zw,Gv=Vv.sub(Dv.xy),Wv=Gv.div(kv),jv=Ap((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Lv)),"vec2").once()(),Hv=Ap((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),zv)),"vec2").once()(),$v=Ap((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),zv.flipY())),"vec2").once()(),qv=new Ys;class Xv extends Cy{static get type(){return"ViewportTextureNode"}constructor(t=zv,e=null,s=null){null===s&&((s=new ka).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Cd.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(qv);const s=this.value;s.image.width===qv.width&&s.image.height===qv.height||(s.image.width=qv.width,s.image.height=qv.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const Yv=Sp(Xv),Zv=Sp(Xv,null,null,{generateMipmaps:!0});let Jv=null;class Kv extends Xv{static get type(){return"ViewportDepthTextureNode"}constructor(t=zv,e=null){null===Jv&&(Jv=new $a),super(t,e,Jv)}}const Qv=Sp(Kv);class tT extends Ud{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===tT.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===tT.DEPTH_BASE)null!==s&&(i=oT().assign(s));else if(e===tT.DEPTH)i=t.isPerspectiveCamera?iT(hx.z,Iy,Py):eT(hx.z,Iy,Py);else if(e===tT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=rT(s,Iy,Py);i=eT(t,Iy,Py)}else i=s;else i=eT(hx.z,Iy,Py);return i}}tT.DEPTH_BASE="depthBase",tT.DEPTH="depth",tT.LINEAR_DEPTH="linearDepth";const eT=(t,e,s)=>t.add(e).div(e.sub(s)),sT=(t,e,s)=>e.sub(s).mul(t).sub(e),iT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),rT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s)),nT=(t,e,s)=>{e=e.max(1e-6).toVar();const i=Cg(t.div(e).add(1)),r=Cg(s.div(e).add(1));return i.div(r)},oT=Sp(tT,tT.DEPTH_BASE),aT=Mp(tT,tT.DEPTH),hT=Sp(tT,tT.LINEAR_DEPTH),uT=hT(Qv());aT.assign=t=>oT(t);class lT extends Ud{static get type(){return"ClippingNode"}constructor(t=lT.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=e,n=r+i,o=s?n-i:n;return this.scope===lT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return Ap((()=>{const i=Fx(t),r=dm("float","distanceToPlane"),n=dm("float","distanceToGradient"),o=dm("float","clipOpacity");let a;if(o.assign(1),fv(s,(({i:t})=>{a=i.element(t),r.assign(hx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(_f(n.negate(),n,r)),o.equal(0).discard()})),s<e){const t=dm("float","unionclipOpacity");t.assign(1),fv({start:s,end:e},(({i:e})=>{a=i.element(e),r.assign(hx.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(_f(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}mm.a.mulAssign(o),mm.a.equal(0).discard()}))()}setupDefault(t,e,s){return Ap((()=>{const i=Fx(t);let r;if(fv(s,(({i:t})=>{r=i.element(t),hx.dot(r.xyz).greaterThan(r.w).discard()})),s<e){const t=dm("bool","clipped");t.assign(!0),fv({start:s,end:e},(({i:e})=>{r=i.element(e),t.assign(hx.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}lT.ALPHA_TO_COVERAGE="alphaToCoverage",lT.DEFAULT="default";class cT extends Jr{static get type(){return"NodeMaterial"}constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+vd(this)}build(t){this.setup(t)}setupObserver(t){return new gd(t)}setup(t){let e;t.context.setupNormal=()=>this.setupNormal(t),t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),null!==this.geometryNode&&(t.stack.outputNode=t.stack.outputNode.bypass(this.geometryNode)),t.addFlow("vertex",t.removeStack()),t.addStack();const s=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==s&&t.stack.add(s);const r=Hp(i,mm.a).max(0);e=this.setupOutput(t,r),Im.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const s=t.renderer.getMRT(),i=this.mrtNode;null!==s?(e=s,null!==i&&(e=s.merge(i))):null!==i&&(e=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=Hp(s)),e=this.setupOutput(t,s)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack()),t.monitor=this.setupObserver(t)}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:s}=t.clippingContext;let i=null;if(e||s){const e=t.renderer.samples;this.alphaToCoverage&&e>1?i=Tp(new lT(lT.ALPHA_TO_COVERAGE)):t.stack.add(Tp(new lT))}return i}setupDepth(t){const{renderer:e,camera:s}=t;let i=this.depthNode;if(null===i){const t=e.getMRT();t&&t.has("depth")?i=t.get("depth"):!0===e.logarithmicDepthBuffer&&(i=s.isPerspectiveCamera?nT(Qb().w,Iy,Py):eT(hx.z,Iy,Py))}null!==i&&aT.assign(i).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&Sv(e).append(),!0===e.isSkinnedMesh&&mv(e).append(),this.displacementMap){const t=kx("displacementMap","texture"),e=kx("displacementScale","float"),s=kx("displacementBias","float");rx.addAssign(mx.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&lv(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&hv(e).append(),null!==this.positionNode&&rx.assign(this.positionNode);const i=Qb();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?Hp(this.colorNode):gb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=Hp(s.xyz.mul(_y("color","vec3")),s.a)),t.instanceColor){s=pm("vec3","vInstanceColor").mul(s)}if(t.isBatchedMesh&&t._colorsTexture){s=pm("vec3","vBatchColor").mul(s)}mm.assign(s);const i=this.opacityNode?Pp(this.opacityNode):xb;if(mm.a.assign(mm.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?Pp(this.alphaTestNode):mb;mm.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&mm.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?kp(0):mm.rgb}setupNormal(){return this.normalNode?kp(this.normalNode):Ab}setupEnvironment(){let t=null;return this.envNode?t=this.envNode:this.envMap&&(t=this.envMap.isCubeTexture?kx("envMap","cubeTexture"):kx("envMap","texture")),t}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new Pv(Yb)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);const i=this.setupLightMap(t);if(i&&i.isLightingNode&&e.push(i),null!==this.aoNode||t.material.aoMap){const t=null!==this.aoNode?this.aoNode:Zb;e.push(new Ev(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=Cv([...r.getLights(),...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let o=this.setupOutgoingLight(t);if(n&&n.getScope().getLights().length>0){const e=this.setupLightingModel(t);o=Iv(n,e,s,i)}else null!==s&&(o=kp(null!==i?xf(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(gm.assign(kp(r||yb)),o=o.add(gm)),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=Hp(s.mix(e.rgb,s.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const s=t[e];void 0===this[e]&&(this[e]=s,s&&s.clone&&(this[e]=s.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const t in e)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,t)&&void 0!==e[t].get&&Object.defineProperty(this.constructor.prototype,t,e[t])}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{},nodes:{}});const s=Jr.prototype.toJSON.call(this,t),i=Td(this);s.inputNodes={};for(const{property:e,childNode:r}of i)s.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),n=r(t.nodes);e.length>0&&(s.textures=e),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.colorNode=t.colorNode,this.normalNode=t.normalNode,this.opacityNode=t.opacityNode,this.backdropNode=t.backdropNode,this.backdropAlphaNode=t.backdropAlphaNode,this.alphaTestNode=t.alphaTestNode,this.positionNode=t.positionNode,this.geometryNode=t.geometryNode,this.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}}const dT=new Ia;class pT extends cT{static get type(){return"InstancedPointsNodeMaterial"}constructor(t={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(dT),this.setValues(t)}setup(t){this.setupShaders(t),super.setup(t)}setupShaders({renderer:t}){const e=this.alphaToCoverage,s=this.useColor;this.vertexNode=Ap((()=>{const t=_y("instancePosition").xyz,e=Hp(tx.mul(Hp(t,1))),s=Dv.z.div(Dv.w),i=Fy.mul(e),r=ix.xy.toVar();return r.mulAssign(this.pointWidthNode?this.pointWidthNode:qb),r.assign(r.div(Dv.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.addAssign(Hp(r,0,0)),i}))(),this.fragmentNode=Ap((()=>{const i=Pp(1).toVar(),r=yf(wy().mul(2).sub(1));if(e&&t.samples>1){const t=Pp(r.fwidth()).toVar();i.assign(_f(t.oneMinus(),t.add(1),r).oneMinus())}else r.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=_y("instanceColor").mul(gb)}else n=gb;return i.mulAssign(xb),Hp(n,i)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}const mT=new xa;class gT extends cT{static get type(){return"LineBasicNodeMaterial"}constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(mT),this.setValues(t)}}const fT=new Cu;class yT extends cT{static get type(){return"LineDashedNodeMaterial"}constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(fT),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?Pp(this.dashScaleNode):Gb,s=this.dashSizeNode?Pp(this.dashSizeNode):Wb,i=this.dashSizeNode?Pp(this.dashGapNode):jb;Pm.assign(s),Fm.assign(i);const r=zf(_y("lineDistance").mul(e));(t?r.add(t):r).mod(Pm.add(Fm)).greaterThan(Pm).discard()}}const xT=new Cu;class bT extends cT{static get type(){return"Line2NodeMaterial"}constructor(t={}){super(),this.lights=!1,this.setDefaultValues(xT),this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.useDash=t.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setup(t){this.setupShaders(t),super.setup(t)}setupShaders({renderer:t}){const e=this.alphaToCoverage,s=this.useColor,i=this.dashed,r=this.worldUnits,n=Ap((({start:t,end:e})=>{const s=Fy.element(2).element(2),i=Fy.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return Hp(xf(t.xyz,e.xyz,i),e.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=Ap((()=>{const t=_y("instanceStart"),e=_y("instanceEnd"),s=Hp(tx.mul(Hp(t,1))).toVar("start"),o=Hp(tx.mul(Hp(e,1))).toVar("end");r&&(pm("vec3","worldStart").assign(s.xyz),pm("vec3","worldEnd").assign(o.xyz));const a=Dv.z.div(Dv.w),h=Fy.element(2).element(3).equal(-1);Ep(h,(()=>{Ep(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(n({start:o,end:s}))}))}));const u=Fy.mul(s),l=Fy.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=Hp().toVar();if(r){const t=o.xyz.sub(s.xyz).normalize(),e=xf(s.xyz,o.xyz,.5).normalize(),r=t.cross(e).normalize(),n=t.cross(r),a=pm("vec4","worldPos");a.assign(ix.y.lessThan(.5).select(s,o));const h=Hb.mul(.5);a.addAssign(Hp(ix.x.lessThan(0).select(r.mul(h),r.mul(h).negate()),0)),i||(a.addAssign(Hp(ix.y.lessThan(.5).select(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(Hp(n.mul(h),0)),Ep(ix.y.greaterThan(1).or(ix.y.lessThan(0)),(()=>{a.subAssign(Hp(n.mul(2).mul(h),0))}))),m.assign(Fy.mul(a));const u=kp().toVar();u.assign(ix.y.lessThan(.5).select(c,d)),m.z.assign(u.z.mul(m.w))}else{const t=zp(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(ix.x.lessThan(0).select(t.negate(),t)),Ep(ix.y.lessThan(0),(()=>{t.assign(t.sub(p))})).ElseIf(ix.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Hb)),t.assign(t.div(Dv.w)),m.assign(ix.y.lessThan(.5).select(u,l)),t.assign(t.mul(m.w)),m.assign(m.add(Hp(t,0,0)))}return m}))();const o=Ap((({p1:t,p2:e,p3:s,p4:i})=>{const r=t.sub(s),n=i.sub(s),o=e.sub(t),a=r.dot(n),h=n.dot(o),u=r.dot(o),l=n.dot(n),c=o.dot(o).mul(l).sub(h.mul(h)),d=a.mul(h).sub(u.mul(l)).div(c).clamp(),p=a.add(h.mul(d)).div(l).clamp();return zp(d,p)}));this.fragmentNode=Ap((()=>{const n=wy();if(i){const t=this.offsetNode?Pp(this.offsetNodeNode):$b,e=this.dashScaleNode?Pp(this.dashScaleNode):Gb,s=this.dashSizeNode?Pp(this.dashSizeNode):Wb,i=this.dashSizeNode?Pp(this.dashGapNode):jb;Pm.assign(s),Fm.assign(i);const r=_y("instanceDistanceStart"),o=_y("instanceDistanceEnd"),a=ix.y.lessThan(.5).select(e.mul(r),Gb.mul(o)),h=zf(a.add($b)),u=t?h.add(t):h;n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),u.mod(Pm.add(Fm)).greaterThan(Pm).discard()}const a=Pp(1).toVar("alpha");if(r){const s=pm("vec3","worldStart"),r=pm("vec3","worldEnd"),n=pm("vec4","worldPos").xyz.normalize().mul(1e5),h=r.sub(s),u=o({p1:s,p2:r,p3:kp(0,0,0),p4:n}),l=s.add(h.mul(u.x)),c=n.mul(u.y),d=l.sub(c).length().div(Hb);if(!i)if(e&&t.samples>1){const t=d.fwidth();a.assign(_f(t.negate().add(.5),t.add(.5),d).oneMinus())}else d.greaterThan(.5).discard()}else if(e&&t.samples>1){const t=n.x,e=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=t.mul(t).add(e.mul(e)),i=Pp(s.fwidth()).toVar("dlen");Ep(n.y.abs().greaterThan(1),(()=>{a.assign(_f(i.oneMinus(),i.add(1),s).oneMinus())}))}else Ep(n.y.abs().greaterThan(1),(()=>{const t=n.x,e=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let h;if(this.lineColorNode)h=this.lineColorNode;else if(s){const t=_y("instanceColorStart"),e=_y("instanceColorEnd");h=ix.y.lessThan(.5).select(t,e).mul(gb)}else h=gb;return Hp(h,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}const vT=t=>Tp(t).mul(.5).add(.5),TT=t=>Tp(t).mul(2).sub(1),_T=new wu;class wT extends cT{static get type(){return"MeshNormalNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(_T),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?Pp(this.opacityNode):xb;mm.assign(Hp(vT(xx),t))}}class ST extends Ld{static get type(){return"EquirectUVNode"}constructor(t=ax){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),s=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return zp(e,s)}}const MT=Sp(ST);class AT extends Yn{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const s=e.minFilter,i=e.generateMipmaps;e.generateMipmaps=!0,this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const r=new Ln(5,5,5),n=MT(ax),o=new cT;o.colorNode=Ry(e,n,0),o.side=d,o.blending=m;const a=new On(r,o),h=new Kn;h.add(a),e.minFilter===St&&(e.minFilter=Tt);const u=new qn(1,10,this),l=t.getMRT();return t.setMRT(null),u.update(t,h),t.setMRT(l),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const NT=new WeakMap;class CT extends Ld{static get type(){return"CubeMapNode"}constructor(t){super("vec3"),this.envNode=t,this._cubeTexture=null,this._cubeTextureNode=Rx();const e=new Xn;e.isRenderTargetTexture=!0,this._defaultTexture=e,this.updateBeforeType=Cd.RENDER}updateBefore(t){const{renderer:e,material:s}=t,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const t=i.isTextureNode?i.value:s[i.property];if(t&&t.isTexture){const s=t.mapping;if(s===lt||s===ct){if(NT.has(t)){const e=NT.get(t);ET(e,t.mapping),this._cubeTexture=e}else{const s=t.image;if(function(t){return null!=t&&t.height>0}(s)){const i=new AT(s.height);i.fromEquirectangularTexture(e,t),ET(i.texture,t.mapping),this._cubeTexture=i.texture,NT.set(t,i.texture),t.addEventListener("dispose",RT)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(t){return this.updateBefore(t),this._cubeTextureNode}}function RT(t){const e=t.target;e.removeEventListener("dispose",RT);const s=NT.get(e);void 0!==s&&(NT.delete(e),s.dispose())}function ET(t,e){e===lt?t.mapping=ht:e===ct&&(t.mapping=ut)}const BT=Sp(CT);class IT extends Rv{static get type(){return"BasicEnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=BT(this.envNode)}}class PT extends Rv{static get type(){return"BasicLightMapNode"}constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=Pp(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}class FT{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class UT extends FT{constructor(){super()}indirect(t,e,s){const i=t.ambientOcclusion,r=t.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(Hp(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(Hp(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(mm.rgb)}finish(t,e,s){const i=s.material,r=t.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(xf(r.rgb,r.rgb.mul(n.rgb),_b.mul(wb)));break;case 1:r.rgb.assign(xf(r.rgb,n.rgb,_b.mul(wb)));break;case 2:r.rgb.addAssign(n.rgb.mul(_b.mul(wb)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const OT=new Kr;class zT extends cT{static get type(){return"MeshBasicNodeMaterial"}constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(OT),this.setValues(t)}setupNormal(){return fx}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new PT(Yb)),e}setupOutgoingLight(){return mm.rgb}setupLightingModel(){return new UT}}const LT=Ap((({f0:t,f90:e,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),VT=Ap((t=>t.diffuseColor.mul(1/Math.PI))),DT=Ap((({dotNH:t})=>Bm.mul(Pp(.5)).add(1).mul(Pp(1/Math.PI)).mul(t.pow(Bm)))),kT=Ap((({lightDirection:t})=>{const e=t.add(ux).normalize(),s=xx.dot(e).clamp(),i=ux.dot(e).clamp(),r=LT({f0:Rm,f90:1,dotVH:i}),n=Pp(.25),o=DT({dotNH:s});return r.mul(n).mul(o)}));class GT extends UT{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=xx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(VT({diffuseColor:mm.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(kT({lightDirection:t})).mul(_b))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(VT({diffuseColor:mm}))),s.indirectDiffuse.mulAssign(t)}}const WT=new Su;class jT extends cT{static get type(){return"MeshLambertNodeMaterial"}constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(WT),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightingModel(){return new GT(!1)}}const HT=new Tu;class $T extends cT{static get type(){return"MeshPhongNodeMaterial"}constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(HT),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new IT(e):null}setupLightingModel(){return new GT}setupVariants(){const t=(this.shininessNode?Pp(this.shininessNode):fb).max(1e-4);Bm.assign(t);const e=this.specularNode||bb;Rm.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}const qT=Ap((()=>{const t=fx.dFdx().abs().max(fx.dFdy().abs());return t.x.max(t.y).max(t.z)})),XT=Ap((t=>{const{roughness:e}=t,s=qT();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),YT=Ap((({alpha:t,dotNL:e,dotNV:s})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return Zm(.5,r.add(n).max(fg))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),ZT=Ap((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(kp(t.mul(s),e.mul(i),o).length()),u=o.mul(kp(t.mul(r),e.mul(n),a).length());return Zm(.5,h.add(u)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),JT=Ap((({alpha:t,dotNH:e})=>{const s=t.pow2(),i=e.pow2().mul(s.oneMinus()).oneMinus();return s.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),KT=Pp(1/Math.PI),QT=Ap((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=kp(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return KT.mul(n.mul(h.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),t_=Ap((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||xx,u=r.pow2(),l=e.add(ux).normalize(),c=h.dot(e).clamp(),d=h.dot(ux).clamp(),p=h.dot(l).clamp(),m=ux.dot(l).clamp();let g,f,y=LT({f0:s,f90:i,dotVH:m});if(xp(o)&&(y=_m.mix(y,n)),xp(a)){const t=Nm.dot(e),s=Nm.dot(ux),i=Nm.dot(l),r=Cm.dot(e),n=Cm.dot(ux),o=Cm.dot(l);g=ZT({alphaT:Mm,alphaB:u,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=QT({alphaT:Mm,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=YT({alpha:u,dotNL:c,dotNV:d}),f=JT({alpha:u,dotNH:p});return y.mul(g).mul(f)})),e_=Ap((({roughness:t,dotNV:e})=>{const s=Hp(-1,-.0275,-.572,.022),i=Hp(1,.0425,1.04,-.04),r=t.mul(s).add(i),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return zp(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),s_=Ap((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=e_({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),i_=Ap((({f:t,f90:e,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return t.sub(kp(e).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),r_=Ap((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=Pp(1).div(s),r=e.pow2().oneMinus().max(.0078125);return Pp(2).add(i).mul(r.pow(i.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),n_=Ap((({dotNV:t,dotNL:e})=>Pp(1).div(Pp(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),o_=Ap((({lightDirection:t})=>{const e=t.add(ux).normalize(),s=xx.dot(t).clamp(),i=xx.dot(ux).clamp(),r=xx.dot(e).clamp(),n=r_({roughness:Tm,dotNH:r}),o=n_({dotNV:i,dotNL:s});return vm.mul(n).mul(o)})),a_=Ap((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=zp(s,i.oneMinus().sqrt());return r.assign(r.mul(.984375).add(.0078125)),r})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),h_=Ap((({f:t})=>{const e=t.length();return sf(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),u_=Ap((({v1:t,v2:e})=>{const s=t.dot(e),i=s.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),o=r.div(n),a=s.greaterThan(0).select(o,sf(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return t.cross(e).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),l_=Ap((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),u=a.sub(r).toVar(),l=h.cross(u),c=kp().toVar();return Ep(l.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),u=t.cross(h).negate(),l=i.mul(Zp(h,u,t).transpose()).toVar(),d=l.mul(r.sub(s)).normalize().toVar(),p=l.mul(n.sub(s)).normalize().toVar(),m=l.mul(o.sub(s)).normalize().toVar(),g=l.mul(a.sub(s)).normalize().toVar(),f=kp(0).toVar();f.addAssign(u_({v1:d,v2:p})),f.addAssign(u_({v1:p,v2:m})),f.addAssign(u_({v1:m,v2:g})),f.addAssign(u_({v1:g,v2:d})),c.assign(kp(h_({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),c_=1/6,d_=t=>Ym(c_,Ym(t,Ym(t,t.negate().add(3)).sub(3)).add(1)),p_=t=>Ym(c_,Ym(t,Ym(t,Ym(3,t).sub(6))).add(4)),m_=t=>Ym(c_,Ym(t,Ym(t,Ym(-3,t).add(3)).add(3)).add(1)),g_=t=>Ym(c_,cf(t,3)),f_=t=>d_(t).add(p_(t)),y_=t=>m_(t).add(g_(t)),x_=t=>qm(-1,p_(t).div(d_(t).add(p_(t)))),b_=t=>qm(1,g_(t).div(m_(t).add(g_(t)))),v_=(t,e,s)=>{const i=t.uvNode,r=Ym(i,e.zw).add(.5),n=Bg(r),o=Fg(r),a=f_(o.x),h=y_(o.x),u=x_(o.x),l=b_(o.x),c=x_(o.y),d=b_(o.y),p=zp(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),m=zp(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),g=zp(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),f=zp(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=f_(o.y).mul(qm(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=y_(o.y).mul(qm(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)},T_=Ap((([t,e=Pp(3)])=>{const s=zp(t.size(Fp(e))),i=zp(t.size(Fp(e.add(1)))),r=Zm(1,s),n=Zm(1,i),o=v_(t,Hp(r,s),Bg(e)),a=v_(t,Hp(n,i),Ig(e));return Fg(e).mix(o,a)})),__=Ap((([t,e,s,i,r])=>{const n=kp(Tf(e.negate(),Pg(t),Zm(1,i))),o=kp(Wg(r[0].xyz),Wg(r[1].xyz),Wg(r[2].xyz));return Pg(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),w_=Ap((([t,e])=>t.mul(bf(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),S_=Zv(),M_=Ap((([t,e,s])=>{const i=S_.uv(t),r=Cg(Pp(Lv.x)).mul(w_(e,s));return T_(i,r)})),A_=Ap((([t,e,s])=>(Ep(s.notEqual(0),(()=>{const i=Ng(e).negate().div(s);return Mg(i.negate().mul(t))})),kp(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),N_=Ap((([t,e,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=Hp().toVar(),f=kp().toVar();const r=l.sub(1).mul(m.mul(.025)),n=kp(l.sub(r),l,l.add(r));fv({start:0,end:3},(({i:r})=>{const l=n.element(r),m=__(t,e,c,l,a),y=o.add(m),x=u.mul(h.mul(Hp(y,1))),b=zp(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(zp(b.x,b.y.oneMinus()));const v=M_(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(A_(Wg(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=__(t,e,c,l,a),n=o.add(r),m=u.mul(h.mul(Hp(n,1))),y=zp(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(zp(y.x,y.y.oneMinus())),g=M_(y,s,l),f=i.mul(A_(Wg(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=kp(s_({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return Hp(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),C_=Zp(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),R_=(t,e)=>t.sub(e).div(t.add(e)).pow2(),E_=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=kp(54856e-17,44201e-17,52481e-17),r=kp(1681e3,1795300,2208400),n=kp(43278e5,93046e5,66121e5),o=Pp(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(e.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(e).cos()).mul(s.pow2().negate().mul(n).exp());a=kp(a.x.add(o),a.y,a.z).div(1.0685e-7);return C_.mul(a)},B_=Ap((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=xf(t,e,_f(0,.03,i)),o=t.div(n).pow2().mul(Pp(1).sub(s.pow2())),a=Pp(1).sub(o).sqrt(),h=R_(n,t),u=LT({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(t).select(Math.PI,0),d=Pp(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return kp(1).add(e).div(kp(1).sub(e))})(r.clamp(0,.9999)),m=R_(p,n.toVec3()),g=LT({f0:m,f90:1,dotVH:a}),f=kp(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(i,a,2),x=kp(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(kp(1).sub(b));let _=u.add(T),w=T.sub(l);for(let t=1;t<=2;++t){w=w.mul(v);const e=E_(Pp(t).mul(y),Pp(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(kp(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),I_=Ap((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=Cf(s.lessThan(.25),Pp(-339.2).mul(r).add(Pp(161.4).mul(s)).sub(25.9),Pp(-8.48).mul(r).add(Pp(14.3).mul(s)).sub(9.95)),o=Cf(s.lessThan(.25),Pp(44).mul(r).sub(Pp(23.7).mul(s)).add(3.26),Pp(1.97).mul(r).sub(Pp(3.27).mul(s)).add(.72));return Cf(s.lessThan(.25),0,Pp(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),P_=kp(.04),F_=Pp(1);class U_ extends FT{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=s,this.anisotropy=i,this.transmission=r,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(t){if(!0===this.clearcoat&&(this.clearcoatRadiance=kp().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=kp().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=kp().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=kp().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=kp().toVar("sheenSpecularIndirect")),!0===this.iridescence){const t=xx.dot(ux).clamp();this.iridescenceFresnel=B_({outsideIOR:Pp(1),eta2:wm,cosTheta1:t,thinFilmThickness:Sm,baseF0:Rm}),this.iridescenceF0=i_({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=ox,s=Vy.sub(ox).normalize(),i=bx;t.backdrop=N_(i,s,fm,mm,Rm,Em,e,Xy,Oy,Fy,Om,Lm,Dm,Vm,this.dispersion?km:null),t.backdropAlpha=zm,mm.a.mulAssign(xf(1,t.backdrop.a,zm))}}computeMultiscattering(t,e,s){const i=xx.dot(ux).clamp(),r=e_({roughness:fm,dotNV:i}),n=(this.iridescenceF0?_m.mix(Rm,this.iridescenceF0):Rm).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Rm.add(Rm.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());t.addAssign(n),e.addAssign(h.mul(o))}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=xx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(o_({lightDirection:t}))),!0===this.clearcoat){const s=vx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(t_({lightDirection:t,f0:P_,f90:F_,roughness:bm,normalView:vx})))}s.directDiffuse.addAssign(i.mul(VT({diffuseColor:mm.rgb}))),s.directSpecular.addAssign(i.mul(t_({lightDirection:t,f0:Rm,f90:1,roughness:fm,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=e.add(s).sub(i),h=e.sub(s).sub(i),u=e.sub(s).add(i),l=e.add(s).add(i),c=xx,d=ux,p=hx.toVar(),m=a_({N:c,V:d,roughness:fm}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=Zp(kp(g.x,0,g.y),kp(0,1,0),kp(g.z,0,g.w)).toVar(),x=Rm.mul(f.x).add(Rm.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(l_({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(t.mul(mm).mul(l_({N:c,V:d,P:p,mInv:Zp(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(t,e,s){this.indirectDiffuse(t,e,s),this.indirectSpecular(t,e,s),this.ambientOcclusion(t,e,s)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(VT({diffuseColor:mm})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(vm,I_({normal:xx,viewDir:ux,roughness:Tm}))),!0===this.clearcoat){const t=vx.dot(ux).clamp(),e=s_({dotNV:t,specularColor:P_,specularF90:F_,roughness:bm});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=kp().toVar("singleScattering"),r=kp().toVar("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Em);const o=i.add(r),a=mm.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(t.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const s=xx.dot(ux).clamp().add(t),i=fm.mul(-16).oneMinus().negate().exp2(),r=t.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),e.indirectDiffuse.mulAssign(t),e.indirectSpecular.mulAssign(r)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=vx.dot(ux).clamp(),s=LT({dotVH:t,f0:P_,f90:F_}),i=e.mul(xm.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(xm));e.assign(i)}if(!0===this.sheen){const t=vm.r.max(vm.g).max(vm.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const O_=Pp(1),z_=Pp(-2),L_=Pp(.8),V_=Pp(-1),D_=Pp(.4),k_=Pp(2),G_=Pp(.305),W_=Pp(3),j_=Pp(.21),H_=Pp(4),$_=Pp(4),q_=Pp(16),X_=Ap((([t])=>{const e=kp(kg(t)).toVar(),s=Pp(-1).toVar();return Ep(e.x.greaterThan(e.z),(()=>{Ep(e.x.greaterThan(e.y),(()=>{s.assign(Cf(t.x.greaterThan(0),0,3))})).Else((()=>{s.assign(Cf(t.y.greaterThan(0),1,4))}))})).Else((()=>{Ep(e.z.greaterThan(e.y),(()=>{s.assign(Cf(t.z.greaterThan(0),2,5))})).Else((()=>{s.assign(Cf(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),Y_=Ap((([t,e])=>{const s=zp().toVar();return Ep(e.equal(0),(()=>{s.assign(zp(t.z,t.y).div(kg(t.x)))})).ElseIf(e.equal(1),(()=>{s.assign(zp(t.x.negate(),t.z.negate()).div(kg(t.y)))})).ElseIf(e.equal(2),(()=>{s.assign(zp(t.x.negate(),t.y).div(kg(t.z)))})).ElseIf(e.equal(3),(()=>{s.assign(zp(t.z.negate(),t.y).div(kg(t.x)))})).ElseIf(e.equal(4),(()=>{s.assign(zp(t.x.negate(),t.z).div(kg(t.y)))})).Else((()=>{s.assign(zp(t.x,t.y).div(kg(t.z)))})),Ym(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),Z_=Ap((([t])=>{const e=Pp(0).toVar();return Ep(t.greaterThanEqual(L_),(()=>{e.assign(O_.sub(t).mul(V_.sub(z_)).div(O_.sub(L_)).add(z_))})).ElseIf(t.greaterThanEqual(D_),(()=>{e.assign(L_.sub(t).mul(k_.sub(V_)).div(L_.sub(D_)).add(V_))})).ElseIf(t.greaterThanEqual(G_),(()=>{e.assign(D_.sub(t).mul(W_.sub(k_)).div(D_.sub(G_)).add(k_))})).ElseIf(t.greaterThanEqual(j_),(()=>{e.assign(G_.sub(t).mul(H_.sub(W_)).div(G_.sub(j_)).add(W_))})).Else((()=>{e.assign(Pp(-2).mul(Cg(Ym(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),J_=Ap((([t,e])=>{const s=t.toVar();s.assign(Ym(2,s).sub(1));const i=kp(s,1).toVar();return Ep(e.equal(0),(()=>{i.assign(i.zyx)})).ElseIf(e.equal(1),(()=>{i.assign(i.xzy),i.xz.mulAssign(-1)})).ElseIf(e.equal(2),(()=>{i.x.mulAssign(-1)})).ElseIf(e.equal(3),(()=>{i.assign(i.zyx),i.xz.mulAssign(-1)})).ElseIf(e.equal(4),(()=>{i.assign(i.xzy),i.xy.mulAssign(-1)})).ElseIf(e.equal(5),(()=>{i.z.mulAssign(-1)})),i})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),K_=Ap((([t,e,s,i,r,n])=>{const o=Pp(s),a=kp(e),h=bf(Z_(o),z_,n),u=Fg(h),l=Bg(h),c=kp(Q_(t,a,l,i,r,n)).toVar();return Ep(u.notEqual(0),(()=>{const e=kp(Q_(t,a,l.add(1),i,r,n)).toVar();c.assign(xf(c,e,u))})),c})),Q_=Ap((([t,e,s,i,r,n])=>{const o=Pp(s).toVar(),a=kp(e),h=Pp(X_(a)).toVar(),u=Pp(sf($_.sub(o),0)).toVar();o.assign(sf(o,$_));const l=Pp(Ag(o)).toVar(),c=zp(Y_(a,h).mul(l.sub(2)).add(1)).toVar();return Ep(h.greaterThan(2),(()=>{c.y.addAssign(l),h.subAssign(3)})),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(Ym(3,q_))),c.y.addAssign(Ym(4,Ag(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(zp(),zp())})),tw=Ap((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=Og(i),u=s.mul(h).add(r.cross(s).mul(Ug(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return Q_(t,u,e,n,o,a)})),ew=Ap((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})=>{const d=kp(Cf(e,s,lf(s,i))).toVar();Ep(vg(d.equals(kp(0))),(()=>{d.assign(kp(i.z,0,i.x.negate()))})),d.assign(Pg(d));const p=kp().toVar();return p.addAssign(r.element(Fp(0)).mul(tw({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),fv({start:Fp(1),end:t},(({i:t})=>{Ep(t.greaterThanEqual(n),(()=>{xv()}));const e=Pp(o.mul(Pp(t))).toVar();p.addAssign(r.element(t).mul(tw({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(tw({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))})),Hp(p,1)}));let sw=null;const iw=new WeakMap;function rw(t){let e=iw.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){const s=t.image;if(t.isCubeTexture){if(!function(t){if(null==t)return!1;let e=0;const s=6;for(let i=0;i<s;i++)void 0!==t[i]&&e++;return e===s}(s))return null;e=sw.fromCubemap(t,e)}else{if(!function(t){return null!=t&&t.height>0}(s))return null;e=sw.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,iw.set(t,e)}return e.texture}class nw extends Ld{static get type(){return"PMREMNode"}constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null;const i=new yi;i.isRenderTargetTexture=!0,this._texture=Ry(i),this._width=lm(0),this._height=lm(0),this._maxMip=lm(0),this.updateBeforeType=Cd.RENDER}set value(t){this._value=t,this._pmrem=null}get value(){return this._value}updateFromTexture(t){const e=function(t){const e=Math.log2(t)-2,s=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:s,maxMip:e}}(t.image.height);this._texture.value=t,this._width.value=e.texelWidth,this._height.value=e.texelHeight,this._maxMip.value=e.maxMip}updateBefore(){let t=this._pmrem;const e=t?t.pmremVersion:-1,s=this._value;e!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:rw(s),null!==t&&(this._pmrem=t,this.updateFromTexture(t)))}setup(t){null===sw&&(sw=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const s=this.value;t.renderer.coordinateSystem===Us&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=kp(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),K_(this._texture,e,i,this._width,this._height,this._maxMip)}}const ow=Sp(nw),aw=new WeakMap;class hw extends Rv{static get type(){return"EnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){const{material:e}=t;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const t=s.isTextureNode?s.value:e[s.property];let i=aw.get(t);void 0===i&&(i=ow(t),aw.set(t,i)),s=i}const i=e.envMap?Lx("envMapIntensity","float",t.material):Lx("environmentIntensity","float",t.scene),r=!0===e.useAnisotropy||e.anisotropy>0?rb:xx,n=s.context(uw(fm,r)).mul(i),o=s.context(lw(bx)).mul(Math.PI).mul(i),a=hy(n),h=hy(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const u=t.context.lightingModel.clearcoatRadiance;if(u){const t=s.context(uw(bm,vx)).mul(i),e=hy(t);u.addAssign(e)}}}const uw=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=ux.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Oy)),s),getTextureLevel:()=>t}},lw=t=>({getUV:()=>t,getTextureLevel:()=>Pp(1)}),cw=new bu;class dw extends cT{static get type(){return"MeshStandardNodeMaterial"}constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(cw),this.setValues(t)}setupEnvironment(t){let e=super.setupEnvironment(t);return null===e&&t.environmentNode&&(e=t.environmentNode),e?new hw(e):null}setupLightingModel(){return new U_}setupSpecular(){const t=xf(kp(.04),mm.rgb,ym);Rm.assign(t),Em.assign(1)}setupVariants(){const t=this.metalnessNode?Pp(this.metalnessNode):Mb;ym.assign(t);let e=this.roughnessNode?Pp(this.roughnessNode):Sb;e=XT({roughness:e}),fm.assign(e),this.setupSpecular(),mm.assign(Hp(mm.rgb.mul(t.oneMinus()),mm.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}const pw=new vu;class mw extends dw{static get type(){return"MeshPhysicalNodeMaterial"}constructor(t){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(pw),this.setValues(t)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const t=this.iorNode?Pp(this.iorNode):Vb;Om.assign(t),Rm.assign(xf(ef(df(Om.sub(1).div(Om.add(1))).mul(Tb),kp(1)).mul(vb),mm.rgb,ym)),Em.assign(xf(vb,1,ym))}setupLightingModel(){return new U_(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?Pp(this.clearcoatNode):Nb,e=this.clearcoatRoughnessNode?Pp(this.clearcoatRoughnessNode):Cb;xm.assign(t),bm.assign(XT({roughness:e}))}if(this.useSheen){const t=this.sheenNode?kp(this.sheenNode):Bb,e=this.sheenRoughnessNode?Pp(this.sheenRoughnessNode):Ib;vm.assign(t),Tm.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?Pp(this.iridescenceNode):Fb,e=this.iridescenceIORNode?Pp(this.iridescenceIORNode):Ub,s=this.iridescenceThicknessNode?Pp(this.iridescenceThicknessNode):Ob;_m.assign(t),wm.assign(e),Sm.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?zp(this.anisotropyNode):Pb).toVar();Am.assign(t.length()),Ep(Am.equal(0),(()=>{t.assign(zp(1,0))})).Else((()=>{t.divAssign(zp(Am)),Am.assign(Am.saturate())})),Mm.assign(Am.pow2().mix(fm.pow2(),1)),Nm.assign(eb[0].mul(t.x).add(eb[1].mul(t.y))),Cm.assign(eb[1].mul(t.x).sub(eb[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?Pp(this.transmissionNode):zb,e=this.thicknessNode?Pp(this.thicknessNode):Lb,s=this.attenuationDistanceNode?Pp(this.attenuationDistanceNode):Db,i=this.attenuationColorNode?kp(this.attenuationColorNode):kb;if(zm.assign(t),Lm.assign(e),Vm.assign(s),Dm.assign(i),this.useDispersion){const t=this.dispersionNode?Pp(this.dispersionNode):Xb;km.assign(t)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?kp(this.clearcoatNormalNode):Rb}setup(t){t.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(t),super.setup(t)}copy(t){return this.clearcoatNode=t.clearcoatNode,this.clearcoatRoughnessNode=t.clearcoatRoughnessNode,this.clearcoatNormalNode=t.clearcoatNormalNode,this.sheenNode=t.sheenNode,this.sheenRoughnessNode=t.sheenRoughnessNode,this.iridescenceNode=t.iridescenceNode,this.iridescenceIORNode=t.iridescenceIORNode,this.iridescenceThicknessNode=t.iridescenceThicknessNode,this.specularIntensityNode=t.specularIntensityNode,this.specularColorNode=t.specularColorNode,this.transmissionNode=t.transmissionNode,this.thicknessNode=t.thicknessNode,this.attenuationDistanceNode=t.attenuationDistanceNode,this.attenuationColorNode=t.attenuationColorNode,this.dispersionNode=t.dispersionNode,this.anisotropyNode=t.anisotropyNode,super.copy(t)}}class gw extends U_{constructor(t,e,s,i){super(t,e,s),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){if(!0===this.useSSS){const i=r.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:h,thicknessPowerNode:u,thicknessScaleNode:l}=i,c=t.add(xx.mul(o)).normalize(),d=Pp(ux.dot(c.negate()).saturate().pow(u).mul(l)),p=kp(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class fw extends mw{static get type(){return"MeshSSSNodeMaterial"}constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=Pp(.1),this.thicknessAmbientNode=Pp(0),this.thicknessAttenuationNode=Pp(.1),this.thicknessPowerNode=Pp(2),this.thicknessScaleNode=Pp(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new gw(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(t){return this.thicknessColorNode=t.thicknessColorNode,this.thicknessDistortionNode=t.thicknessDistortionNode,this.thicknessAmbientNode=t.thicknessAmbientNode,this.thicknessAttenuationNode=t.thicknessAttenuationNode,this.thicknessPowerNode=t.thicknessPowerNode,this.thicknessScaleNode=t.thicknessScaleNode,super.copy(t)}}const yw=Ap((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=zp(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=kx("gradientMap","texture").context({getUV:()=>r});return kp(t.r)}{const t=r.fwidth().mul(.5);return xf(kp(.7),kp(1),_f(Pp(.7).sub(t.x),Pp(.7).add(t.x),r.x))}}));class xw extends FT{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=yw({normal:px,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(VT({diffuseColor:mm.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(VT({diffuseColor:mm}))),s.indirectDiffuse.mulAssign(t)}}const bw=new _u;class vw extends cT{static get type(){return"MeshToonNodeMaterial"}constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(bw),this.setValues(t)}setupLightingModel(){return new xw}}class Tw extends Ld{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const t=kp(ux.z,0,ux.x.negate()).normalize(),e=ux.cross(t);return zp(t.dot(xx),e.dot(xx)).mul(.495).add(.5)}}const _w=Mp(Tw),ww=new Nu;class Sw extends cT{static get type(){return"MeshMatcapNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(ww),this.setValues(t)}setupVariants(t){const e=_w;let s;s=t.material.matcap?kx("matcap","texture").context({getUV:()=>e}):kp(xf(.2,.8,e.y)),mm.rgb.mulAssign(s.rgb)}}const Mw=new Ia;class Aw extends cT{static get type(){return"PointsNodeMaterial"}constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(Mw),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}class Nw extends Ld{static get type(){return"RotateNode"}constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:s}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Yp(t,i,i.negate(),t).mul(s)}{const t=e,i=Jp(Hp(1,0,0,0),Hp(0,Og(t.x),Ug(t.x).negate(),0),Hp(0,Ug(t.x),Og(t.x),0),Hp(0,0,0,1)),r=Jp(Hp(Og(t.y),0,Ug(t.y),0),Hp(0,1,0,0),Hp(Ug(t.y).negate(),0,Og(t.y),0),Hp(0,0,0,1)),n=Jp(Hp(Og(t.z),Ug(t.z).negate(),0,0),Hp(Ug(t.z),Og(t.z),0,0),Hp(0,0,1,0),Hp(0,0,0,1));return i.mul(r).mul(n).mul(Hp(s,1)).xyz}}}const Cw=Sp(Nw),Rw=new so;class Ew extends cT{static get type(){return"SpriteNodeMaterial"}constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Rw),this.setValues(t)}setupPosition({object:t,camera:e,context:s}){const i=this.sizeAttenuation,{positionNode:r,rotationNode:n,scaleNode:o}=this,a=rx;let h=tx.mul(kp(r||0)),u=zp(Xy[0].xyz.length(),Xy[1].xyz.length());if(null!==o&&(u=u.mul(o)),!i)if(e.isPerspectiveCamera)u=u.mul(h.z.negate());else{const t=Pp(2).div(Fy.element(1).element(1));u=u.mul(t.mul(2))}let l=a.xy;if(t.center&&!0===t.center.isVector2){const t=((t,e,s)=>Tp(new Xf(t,e,s)))("center","vec2");l=l.sub(t.sub(.5))}l=l.mul(u);const c=Pp(n||Eb),d=Cw(l,c);h=Hp(h.xy.add(d),h.zw);const p=Fy.mul(h);return s.vertex=a,p}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(t){this._useSizeAttenuation!==t&&(this._useSizeAttenuation=t,this.needsUpdate=!0)}}class Bw extends FT{constructor(){super(),this.shadowNode=Pp(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){mm.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(mm.rgb)}}const Iw=new yu;class Pw extends cT{static get type(){return"ShadowNodeMaterial"}constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Iw),this.setValues(t)}setupLightingModel(){return new Bw}}const Fw=Ap((({texture:t,uv:e})=>{const s=1e-4,i=kp().toVar();return Ep(e.x.lessThan(s),(()=>{i.assign(kp(1,0,0))})).ElseIf(e.y.lessThan(s),(()=>{i.assign(kp(0,1,0))})).ElseIf(e.z.lessThan(s),(()=>{i.assign(kp(0,0,1))})).ElseIf(e.x.greaterThan(.9999),(()=>{i.assign(kp(-1,0,0))})).ElseIf(e.y.greaterThan(.9999),(()=>{i.assign(kp(0,-1,0))})).ElseIf(e.z.greaterThan(.9999),(()=>{i.assign(kp(0,0,-1))})).Else((()=>{const s=.01,r=t.uv(e.add(kp(-.01,0,0))).r.sub(t.uv(e.add(kp(s,0,0))).r),n=t.uv(e.add(kp(0,-.01,0))).r.sub(t.uv(e.add(kp(0,s,0))).r),o=t.uv(e.add(kp(0,0,-.01))).r.sub(t.uv(e.add(kp(0,0,s))).r);i.assign(kp(r,n,o))})),i.normalize()}));class Uw extends Cy{static get type(){return"Texture3DNode"}constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return kp(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return Fw({texture:this,uv:t})}}const Ow=Sp(Uw);class zw extends cT{static get type(){return"VolumeNodeMaterial"}constructor(t={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=Ow(this.map,null,0),s=Ap((({orig:t,dir:e})=>{const s=kp(-.5),i=kp(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=ef(n,o),h=sf(n,o),u=sf(a.x,sf(a.y,a.z)),l=ef(h.x,ef(h.y,h.z));return zp(u,l)}));this.fragmentNode=Ap((()=>{const t=zf(kp(Qy.mul(Hp(Vy,1)))),i=zf(ix.sub(t)).normalize(),r=zp(s({orig:t,dir:i})).toVar();r.x.greaterThan(r.y).discard(),r.assign(zp(sf(r.x,0),r.y));const n=kp(t.add(r.x.mul(i))).toVar(),o=kp(i.abs().reciprocal()).toVar(),a=Pp(ef(o.x,ef(o.y,o.z))).toVar("delta");a.divAssign(kx("steps","float"));const h=Hp(kx("base","color"),0).toVar();return fv({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=dm("float","d").assign(e.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:n,finalColor:h}).append():(h.a.assign(1),xv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),Hp(h)}))(),super.setup(t)}}class Lw{constructor(t,e){this.nodes=t,this.info=e,this.animationLoop=null,this.requestId=null,this._init()}_init(){const t=(e,s)=>{this.requestId=self.requestAnimationFrame(t),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(e,s)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class Vw{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let s=0;s<t.length;s++)if(e=e.get(t[s]),void 0===e)return;return e.get(t[t.length-1])}set(t,e){let s=this.weakMap;for(let e=0;e<t.length;e++){const i=t[e];!1===s.has(i)&&s.set(i,new WeakMap),s=s.get(i)}return s.set(t[t.length-1],e)}delete(t){let e=this.weakMap;for(let s=0;s<t.length;s++)if(e=e.get(t[s]),void 0===e)return!1;return e.delete(t[t.length-1])}}const Dw=new Yo;class kw{constructor(){this.version=0,this.globalClippingCount=0,this.localClippingCount=0,this.localClippingEnabled=!1,this.localClipIntersection=!1,this.planes=[],this.parentVersion=0,this.viewNormalMatrix=new Zs,this.cacheKey=0}projectPlanes(t,e){const s=t.length,i=this.planes;for(let r=0;r<s;r++){Dw.copy(t[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const s=i[e+r],n=Dw.normal;s.x=-n.x,s.y=-n.y,s.z=-n.z,s.w=Dw.constant}}updateGlobal(t,e){const s=t.clippingPlanes;this.viewMatrix=e.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix);let i=!1;if(Array.isArray(s)&&0!==s.length){const t=s.length;if(t!==this.globalClippingCount){const e=[];for(let s=0;s<t;s++)e.push(new xi);this.globalClippingCount=t,this.planes=e,i=!0}this.projectPlanes(s,0)}else 0!==this.globalClippingCount&&(this.globalClippingCount=0,this.planes=[],i=!0);t.localClippingEnabled!==this.localClippingEnabled&&(this.localClippingEnabled=t.localClippingEnabled,i=!0),i&&(this.version++,this.cacheKey=bd(this.globalClippingCount,!0===this.localClippingEnabled?1:0))}update(t,e){let s=!1;if(this!==t&&t.version!==this.parentVersion&&(this.globalClippingCount=e.isShadowNodeMaterial?0:t.globalClippingCount,this.localClippingEnabled=t.localClippingEnabled,this.planes=Array.from(t.planes),this.parentVersion=t.version,this.viewMatrix=t.viewMatrix,this.viewNormalMatrix=t.viewNormalMatrix,s=!0),this.localClippingEnabled){const t=e.clippingPlanes;if(Array.isArray(t)&&0!==t.length){const e=t.length,i=this.planes,r=this.globalClippingCount;if(s||e!==this.localClippingCount){i.length=r+e;for(let t=0;t<e;t++)i[r+t]=new xi;this.localClippingCount=e,s=!0}this.projectPlanes(t,r)}else 0!==this.localClippingCount&&(this.localClippingCount=0,s=!0);this.localClipIntersection!==e.clipIntersection&&(this.localClipIntersection=e.clipIntersection,s=!0)}s&&(this.version+=t.version,this.cacheKey=bd(t.cacheKey,this.localClippingCount,!0===this.localClipIntersection?1:0))}}let Gw=0;class Ww{constructor(t,e,s,i,r,n,o,a,h){this._nodes=t,this._geometries=e,this.id=Gw++,this.renderer=s,this.object=i,this.material=r,this.scene=n,this.camera=o,this.lightsNode=a,this.context=h,this.geometry=i.geometry,this.version=r.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.updateClipping(h.clippingContext),this.clippingContextVersion=this.clippingContext.version,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.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let s=this.clippingContext;Array.isArray(e.clippingPlanes)?(s!==t&&s||(s=new kw,this.clippingContext=s),s.update(t,e)):this.clippingContext!==t&&(this.clippingContext=t)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}getAttributes(){if(null!==this.attributes)return this.attributes;const t=this.getNodeBuilderState().nodeAttributes,e=this.geometry,s=[],i=new Set;for(const r of t){const t=r.node&&r.node.attribute?r.node.attribute:e.getAttribute(r.name);if(void 0===t)continue;s.push(t);const n=t.isInterleavedBufferAttribute?t.data:t;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:t,material:e,geometry:s,group:i,drawRange:r}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,h=s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1;if(0===h)return null;if(n.instanceCount=h,!0===t.isBatchedMesh)return n;let u=1;!0!==e.wireframe||t.isPoints||t.isLineSegments||t.isLine||t.isLineLoop||(u=2);let l=r.start*u,c=(r.start+r.count)*u;null!==i&&(l=Math.max(l,i.start*u),c=Math.min(c,(i.start+i.count)*u));const d=!0===a?o.count:s.attributes.position.count;l=Math.max(l,0),c=Math.min(c,d);const p=c-l;return p<0||p===1/0?null:(n.vertexCount=p,n.firstVertex=l,n)}getGeometryCacheKey(){const{geometry:t}=this;let e="";for(const s of Object.keys(t.attributes).sort()){const i=t.attributes[s];e+=s+",",i.data&&(e+=i.data.stride+","),i.offset&&(e+=i.offset+","),i.itemSize&&(e+=i.itemSize+","),i.normalized&&(e+="n,")}return t.index&&(e+="index,"),e}getMaterialCacheKey(){const{object:t,material:e}=this;let s=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let s=Object.getPrototypeOf(t);for(;s;){const t=Object.getOwnPropertyDescriptors(s);for(const s in t)if(void 0!==t[s]){const i=t[s];i&&"function"==typeof i.get&&e.push(s)}s=Object.getPrototypeOf(s)}return e}(e)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(t))continue;const i=e[t];let r;if(null!==i){const t=typeof i;"number"===t?r=0!==i?"1":"0":"object"===t?(r="{",i.isTexture&&(r+=i.mapping),r+="}"):r=String(i)}else r=String(i);s+=r+","}return s+=this.clippingContext.cacheKey+",",t.geometry&&(s+=this.getGeometryCacheKey()),t.skeleton&&(s+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(s+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(s+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(s+=t._colorsTexture.uuid+",")),t.count>1&&(s+=t.uuid+","),yd(s)}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let t=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(t+=1),t}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const jw=[];class Hw{constructor(t,e,s,i,r,n){this.renderer=t,this.nodes=e,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(t,e,s,i,r,n,o){const a=this.getChainMap(o);jw[0]=t,jw[1]=e,jw[2]=n,jw[3]=r;let h=a.get(jw);return void 0===h?(h=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(jw,h)):(h.updateClipping(n.clippingContext),(h.version!==e.version||h.needsUpdate)&&(h.initialCacheKey!==h.getCacheKey()?(h.dispose(),h=this.get(t,e,s,i,r,n,o)):h.version=e.version)),h}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new Vw)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Ww(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),l.delete(c.getChainArray())},c}}class $w{constructor(){this.data=new WeakMap}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}delete(t){let e;return this.data.has(t)&&(e=this.data.get(t),this.data.delete(t)),e}has(t){return this.data.has(t)}dispose(){this.data=new WeakMap}}const qw=1,Xw=2,Yw=4,Zw=16;class Jw extends $w{constructor(t){super(),this.backend=t}delete(t){const e=super.delete(t);return void 0!==e&&this.backend.destroyAttribute(t),e}update(t,e){const s=this.get(t);if(void 0===s.version)e===qw?this.backend.createAttribute(t):e===Xw?this.backend.createIndexAttribute(t):e===Yw&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version<e.version||e.usage===Ms)&&(this.backend.updateAttribute(t),s.version=e.version)}}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}function Kw(t){return null!==t.index?t.index.version:t.attributes.position.version}function Qw(t){const e=[],s=t.index,i=t.attributes.position;if(null!==s){const t=s.array;for(let s=0,i=t.length;s<i;s+=3){const i=t[s+0],r=t[s+1],n=t[s+2];e.push(i,r,r,n,n,i)}}else{for(let t=0,s=i.array.length/3-1;t<s;t+=3){const s=t+0,i=t+1,r=t+2;e.push(s,i,i,r,r,s)}}const r=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(e)?mn:dn)(e,1);return r.version=Kw(t),r}class tS extends $w{constructor(t,e){super(),this.attributes=t,this.info=e,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(t){const e=t.geometry;return super.has(e)&&!0===this.get(e).initialized}updateForRender(t){!1===this.has(t)&&this.initGeometry(t),this.updateAttributes(t)}initGeometry(t){const e=t.geometry;this.get(e).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=e.index,r=t.getAttributes();null!==i&&this.attributes.delete(i);for(const t of r)this.attributes.delete(t);const n=this.wireframes.get(e);void 0!==n&&this.attributes.delete(n),e.removeEventListener("dispose",s)};e.addEventListener("dispose",s)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,Yw):this.updateAttribute(t,qw);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Xw)}updateAttribute(t,e){const s=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,s)):this.attributeCall.get(t.data)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t.data,s),this.attributeCall.set(t,s)):this.attributeCall.get(t)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t,s))}getIndex(t){const{geometry:e,material:s}=t;let i=e.index;if(!0===s.wireframe){const t=this.wireframes;let s=t.get(e);void 0===s?(s=Qw(e),t.set(e,s)):s.version!==Kw(e)&&(this.attributes.delete(s),s=Qw(e),t.set(e,s)),i=s}return i}}class eS{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(t,e,s){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=s*(e/3):t.isPoints?this.render.points+=s*e:t.isLineSegments?this.render.lines+=s*(e/2):t.isLine?this.render.lines+=s*(e-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(t,e){0===this[t].timestampCalls&&(this[t].timestamp=0),this[t].timestamp+=e,this[t].timestampCalls++,this[t].timestampCalls>=this[t].previousFrameCalls&&(this[t].timestampCalls=0)}reset(){const t=this.render.frameCalls;this.render.previousFrameCalls=t;const e=this.compute.frameCalls;this.compute.previousFrameCalls=e,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class sS{constructor(t){this.cacheKey=t,this.usedTimes=0}}class iS extends sS{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class rS extends sS{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let nS=0;class oS{constructor(t,e,s=null,i=null){this.id=nS++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class aS extends $w{constructor(t,e){super(),this.backend=t,this.nodes=e,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(t,e){const{backend:s}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(t);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new oS(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(t,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(t,o,a,e)),h.usedTimes++,o.usedTimes++,i.version=t.version,i.pipeline=h}return i.pipeline}getForRender(t,e=null){const{backend:s}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=t.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new oS(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),a=new oS(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(t){const e=this.get(t).pipeline;return e&&(e.usedTimes--,0===e.usedTimes&&this._releasePipeline(e),e.isComputePipeline?(e.computeProgram.usedTimes--,0===e.computeProgram.usedTimes&&this._releaseProgram(e.computeProgram)):(e.fragmentProgram.usedTimes--,e.vertexProgram.usedTimes--,0===e.vertexProgram.usedTimes&&this._releaseProgram(e.vertexProgram),0===e.fragmentProgram.usedTimes&&this._releaseProgram(e.fragmentProgram))),super.delete(t)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(t){this.getForRender(t)}_getComputePipeline(t,e,s,i){s=s||this._getComputeCacheKey(t,e);let r=this.caches.get(s);return void 0===r&&(r=new rS(s,e),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,s,i,r){i=i||this._getRenderCacheKey(t,e,s);let n=this.caches.get(i);return void 0===n&&(n=new iS(i,e,s),this.caches.set(i,n),t.pipeline=n,this.backend.createRenderPipeline(t,r)),n}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,s){return e.id+","+s.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,s=t.stage;this.programs[s].delete(e)}_needsComputeUpdate(t){const e=this.get(t);return void 0===e.pipeline||e.version!==t.version}_needsRenderUpdate(t){return void 0===this.get(t).pipeline||this.backend.needsRenderUpdate(t)}}class hS extends $w{constructor(t,e,s,i,r,n){super(),this.backend=t,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=n,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(this.getForCompute(t))}updateForRender(t){this._updateBindings(this.getForRender(t))}_updateBindings(t){for(const e of t)this._update(e,t)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute;this.attributes.update(t,Yw)}}_update(t,e){const{backend:s}=this;let i=!1;for(const e of t.bindings){if(e.isNodeUniformsGroup){if(!this.nodes.updateGroup(e))continue}if(e.isUniformBuffer){e.update()&&s.updateBinding(e)}else if(e.isSampler)e.update();else if(e.isSampledTexture){e.needsBindingsUpdate(this.textures.get(e.texture).generation)&&(i=!0);const t=e.update(),r=e.texture;t&&this.textures.updateTexture(r);const n=s.get(r);if(!0===s.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",e,t,r,e.textureNode.value,i),this.textures.updateTexture(r),i=!0),!0===r.isStorageTexture){const t=this.get(r);!0===e.store?t.needsMipmap=!0:!0===r.generateMipmaps&&this.textures.needsMipmaps(r)&&!0===t.needsMipmap&&(this.backend.generateMipmaps(r),t.needsMipmap=!1)}}}!0===i&&this.backend.updateBindings(t,e)}}class uS{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class lS{constructor(t,e,s){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=s.getSelf()}get value(){return this.node.value}set value(t){this.node.value=t}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class cS{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class dS extends cS{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class pS{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let mS=0;class gS{constructor(t=null){this.id=mS++,this.nodesData=new WeakMap,this.parent=t}getData(t){let e=this.nodesData.get(t);return void 0===e&&null!==this.parent&&(e=this.parent.getData(t)),e}setData(t,e){this.nodesData.set(t,e)}}class fS extends cm{static get type(){return"ParameterNode"}constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const yS=(t,e)=>Tp(new fS(t,e));class xS extends Ud{static get type(){return"CodeNode"}constructor(t="",e=[],s=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=s,this.includes=e}isGlobal(){return!0}setIncludes(t){return this.includes=t,this}getIncludes(){return this.includes}generate(t){const e=this.getIncludes(t);for(const s of e)s.build(t);const s=t.getCodeFromNode(this,this.getNodeType(t));return s.code=this.code,s.code}serialize(t){super.serialize(t),t.code=this.code,t.language=this.language}deserialize(t){super.deserialize(t),this.code=t.code,this.language=t.language}}const bS=Sp(xS),vS=(t,e)=>bS(t,e,"js"),TS=(t,e)=>bS(t,e,"wgsl"),_S=(t,e)=>bS(t,e,"glsl");class wS extends xS{static get type(){return"FunctionNode"}constructor(t="",e=[],s=""){super(t,e,s)}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let s=e.nodeFunction;return void 0===s&&(s=t.parser.parseFunction(this.code),e.nodeFunction=s),s}generate(t,e){super.generate(t);const s=this.getNodeFunction(t),i=s.name,r=s.type,n=t.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=t.getPropertyName(n),a=this.getNodeFunction(t).getCode(o);return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const SS=(t,e=[],s="")=>{for(let t=0;t<e.length;t++){const s=e[t];"function"==typeof s&&(e[t]=s.functionNode)}const i=Tp(new wS(t,e,s)),r=(...t)=>i.call(...t);return r.functionNode=i,r},MS=(t,e)=>SS(t,e,"glsl"),AS=(t,e)=>SS(t,e,"wgsl");class NS{constructor(t,e){this.name=t,this.value=e,this.boundary=0,this.itemSize=0,this.offset=0}setValue(t){this.value=t}getValue(){return this.value}}class CS extends NS{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class RS extends NS{constructor(t,e=new Ys){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class ES extends NS{constructor(t,e=new Ai){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class BS extends NS{constructor(t,e=new xi){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class IS extends NS{constructor(t,e=new Xr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class PS extends NS{constructor(t,e=new Zs){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class FS extends NS{constructor(t,e=new sr){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class US extends CS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class OS extends RS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class zS extends ES{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class LS extends BS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class VS extends IS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class DS extends PS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class kS extends FS{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class GS extends Ud{static get type(){return"StackNode"}constructor(t=null){super(),this.nodes=[],this.outputNode=null,this.parent=t,this._currentCond=null,this.isStackNode=!0}getNodeType(t){return this.outputNode?this.outputNode.getNodeType(t):"void"}add(t){return this.nodes.push(t),this}If(t,e){const s=new vp(e);return this._currentCond=Cf(t,s),this.add(this._currentCond)}ElseIf(t,e){const s=new vp(e),i=Cf(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(t){return this._currentCond.elseNode=new vp(t),this}build(t,...e){const s=Rp();Cp(this);for(const e of this.nodes)e.build(t,"void");return Cp(s),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}else(...t){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...t)}elseif(...t){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...t)}}const WS=Sp(GS),jS=[.125,.215,.35,.446,.526,.582],HS=20,$S=new Tl(-1,1,1,-1,0,1),qS=new Hn(90,1),XS=new Xr;let YS=null,ZS=0,JS=0;const KS=(1+Math.sqrt(5))/2,QS=1/KS,tM=[new Ai(-KS,QS,0),new Ai(KS,QS,0),new Ai(-QS,0,KS),new Ai(QS,0,KS),new Ai(0,KS,-QS),new Ai(0,KS,QS),new Ai(-1,1,-1),new Ai(1,1,-1),new Ai(-1,1,1),new Ai(1,1,1)],eM=[3,1,5,0,4,2],sM=J_(wy(),_y("faceIndex")).normalize(),iM=kp(sM.x,sM.y.negate(),sM.z);class rM{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(t,e=0,s=.1,i=100){YS=this._renderer.getRenderTarget(),ZS=this._renderer.getActiveCubeFace(),JS=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,s,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=hM(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=uM(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodPlanes.length;t++)this._lodPlanes[t].dispose()}_cleanup(t){this._renderer.setRenderTarget(YS,ZS,JS),t.scissorTest=!1,oM(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===ht||t.mapping===ut?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),YS=this._renderer.getRenderTarget(),ZS=this._renderer.getActiveCubeFace(),JS=this._renderer.getActiveMipmapLevel();const s=e||this._allocateTargets();return this._textureToCubeUV(t,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,s={magFilter:Tt,minFilter:Tt,generateMipmaps:!1,type:Pt,format:Dt,colorSpace:Je},i=nM(t,e,s);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=nM(t,e,s);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=function(t){const e=[],s=[],i=[],r=[];let n=t;const o=t-4+1+jS.length;for(let a=0;a<o;a++){const o=Math.pow(2,n);s.push(o);let h=1/o;a>t-4?h=jS[a-t+4-1]:0===a&&(h=0),i.push(h);const u=1/(o-2),l=-u,c=1+u,d=[l,l,c,l,c,c,l,l,c,c,l,c],p=6,m=6,g=3,f=2,y=1,x=new Float32Array(g*m*p),b=new Float32Array(f*m*p),v=new Float32Array(y*m*p);for(let t=0;t<p;t++){const e=t%3*2/3-1,s=t>2?0:-1,i=[e,s,0,e+2/3,s,0,e+2/3,s+1,0,e,s,0,e+2/3,s+1,0,e,s+1,0],r=eM[t];x.set(i,g*m*r),b.set(d,f*m*r);const n=[r,r,r,r,r,r];v.set(n,y*m*r)}const T=new Sn;T.setAttribute("position",new an(x,g)),T.setAttribute("uv",new an(b,f)),T.setAttribute("faceIndex",new an(v,y)),e.push(T),r.push(new On(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=Fx(new Array(HS).fill(0)),r=lm(new Ai(0,1,0)),n=lm(0),o=Pp(HS),a=lm(0),h=lm(1),u=Ry(null),l=lm(0),c=Pp(1/e),d=Pp(1/s),p=Pp(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:iM,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=aM("blur");return g.uniforms=m,g.fragmentNode=ew({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}async _compileMaterial(t){const e=new On(this._lodPlanes[0],t);await this._renderer.compile(e,$S)}_sceneToCubeUV(t,e,s,i){const r=qS;r.near=e,r.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,h=a.autoClear;a.getClearColor(XS),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const t=new Kr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});u=new On(new Ln,t)}let l=!1;const c=t.background;c?c.isColor&&(u.material.color.copy(c),t.background=null,l=!0):(u.material.color.copy(XS),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let e=0;e<6;e++){const s=e%3;0===s?(r.up.set(0,n[e],0),r.lookAt(o[e],0,0)):1===s?(r.up.set(0,0,n[e]),r.lookAt(0,o[e],0)):(r.up.set(0,n[e],0),r.lookAt(0,0,o[e]));const h=this._cubeSize;oM(i,s*h,e>2?h:0,h,h),a.render(t,r)}a.autoClear=h,t.background=c}_textureToCubeUV(t,e){const s=this._renderer,i=t.mapping===ht||t.mapping===ut;i?null===this._cubemapMaterial&&(this._cubemapMaterial=hM(t)):null===this._equirectMaterial&&(this._equirectMaterial=uM(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;oM(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,$S)}_applyPMREM(t){const e=this._renderer,s=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;e<i;e++){const s=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),r=tM[(i-e-1)%tM.length];this._blur(t,e-1,e,s,r)}e.autoClear=s}_blur(t,e,s,i,r){const n=this._pingPongRenderTarget;this._halfBlur(t,n,e,s,i,"latitudinal",r),this._halfBlur(n,t,s,s,i,"longitudinal",r)}_halfBlur(t,e,s,i,r,n,o){const a=this._renderer,h=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&console.error("blur direction must be either latitudinal or longitudinal!");const u=this._lodMeshes[i];u.material=h;const l=h.uniforms,c=this._sizeLods[s]-1,d=isFinite(r)?Math.PI/(2*c):2*Math.PI/39,p=r/d,m=isFinite(r)?1+Math.floor(3*p):HS;m>HS&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const g=[];let f=0;for(let t=0;t<HS;++t){const e=t/p,s=Math.exp(-e*e/2);g.push(s),0===t?f+=s:t<m&&(f+=2*s)}for(let t=0;t<g.length;t++)g[t]=g[t]/f;t.texture.frame=(t.texture.frame||0)+1,l.envMap.value=t.texture,l.samples.value=m,l.weights.array=g,l.latitudinal.value="latitudinal"===n?1:0,o&&(l.poleAxis.value=o);const{_lodMax:y}=this;l.dTheta.value=d,l.mipInt.value=y-s;const x=this._sizeLods[i];oM(e,3*x*(i>y-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(u,$S)}}function nM(t,e,s){const i=new bi(t,e,s);return i.texture.mapping=dt,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function oM(t,e,s,i,r){t.viewport.set(e,s,i,r),t.scissor.set(e,s,i,r)}function aM(t){const e=new cT;return e.depthTest=!1,e.depthWrite=!1,e.blending=m,e.name=`PMREM_${t}`,e}function hM(t){const e=aM("cubemap");return e.fragmentNode=Rx(t,iM),e}function uM(t){const e=aM("equirect");return e.fragmentNode=Ry(t,MT(iM),0),e}let lM=0;class cM{constructor(t="",e=[],s=0,i=[]){this.name=t,this.bindings=e,this.index=s,this.bindingsReference=i,this.id=lM++}}const dM=new WeakMap,pM=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),mM=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),gM=t=>/e/g.test(t)?String(t).replace(/\+/g,""):(t=Number(t))+(t%1?"":".0");class fM{constructor(t,e,s){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=WS(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new gS,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let t=dM.get(this.renderer);return void 0===t&&(t=new Vw,dM.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new bi(t,e,s)}createCubeRenderTarget(t,e){return new AT(t,e)}createPMREMGenerator(){return new rM(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBindGroupsCache(),i=[];let r,n=!0;for(const t of e)i.push(t),n=n&&!0!==t.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new cM(t,i,this.bindingsIndexes[t].group,i),s.set(i,r))):r=new cM(t,i,this.bindingsIndexes[t].group,i),r}getBindGroupArray(t,e){const s=this.bindings[e];let i=s[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},s=this.bindings;for(const t of Id)for(const i in s[t]){const r=s[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const s in e){const i=e[s],r=this._getBindGroup(s,i);t.push(r)}this.bindGroups=t}return t}sortBindingGroups(){const t=this.getBindings();t.sort(((t,e)=>t.bindings[0].groupNode.order-e.bindings[0].groupNode.order));for(let e=0;e<t.length;e++){const s=t[e];this.bindingsIndexes[s.name].group=e,s.index=e}}setHashNode(t,e){this.hashNodes[e]=t}addNode(t){!1===this.nodes.includes(t)&&(this.nodes.push(t),this.setHashNode(t,t.getHash(this)))}buildUpdateNodes(){for(const t of this.nodes){const e=t.getUpdateType(),s=t.getUpdateBeforeType(),i=t.getUpdateAfterType();e!==Cd.NONE&&this.updateNodes.push(t.getSelf()),s!==Cd.NONE&&this.updateBeforeNodes.push(t.getSelf()),i!==Cd.NONE&&this.updateAfterNodes.push(t.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(t){return t.magFilter===Tt||t.magFilter===_t||t.magFilter===bt||t.magFilter===St||t.minFilter===Tt||t.minFilter===_t||t.minFilter===bt||t.minFilter===St}addChain(t){this.chaining.push(t)}removeChain(t){if(this.chaining.pop()!==t)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(t){return t}getNodeFromHash(t){return this.hashNodes[t]}addFlow(t,e){return this.flowNodes[t].push(e),e}setContext(t){this.context=t}getContext(){return this.context}getSharedContext(){return this.context,this.context}setCache(t){this.cache=t}getCache(){return this.cache}getCacheFromNode(t,e=!0){const s=this.getDataFromNode(t);return void 0===s.cache&&(s.cache=new gS(e?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}increaseUsage(t){const e=this.getDataFromNode(t);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(t,e=null){if(null===e&&("float"===t||"int"===t||"uint"===t?e=0:"bool"===t?e=!1:"color"===t?e=new Xr:"vec2"===t?e=new Ys:"vec3"===t?e=new Ai:"vec4"===t&&(e=new xi)),"float"===t)return gM(e);if("int"===t)return`${Math.round(e)}`;if("uint"===t)return e>=0?`${Math.round(e)}u`:"0u";if("bool"===t)return e?"true":"false";if("color"===t)return`${this.getType("vec3")}( ${gM(e.r)}, ${gM(e.g)}, ${gM(e.b)} )`;const s=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(s>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(t)}()`;throw new Error(`NodeBuilder: Type '${t}' not found in generate constant attempt.`)}getType(t){return"color"===t?"vec3":t}hasGeometryAttribute(t){return this.geometry&&void 0!==this.geometry.getAttribute(t)}getAttribute(t,e){const s=this.attributes;for(const e of s)if(e.name===t)return e;const i=new uS(t,e);return s.push(i),i}getPropertyName(t){return t.name}isVector(t){return/vec\d/.test(t)}isMatrix(t){return/mat\d/.test(t)}isReference(t){return"void"===t||"property"===t||"sampler"===t||"texture"===t||"cubeTexture"===t||"storageTexture"===t||"depthTexture"===t||"texture3D"===t}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===Et)return"int";if(e===Bt)return"uint"}return"float"}getElementType(t){return"mat2"===t?"vec2":"mat3"===t?"vec3":"mat4"===t?"vec4":this.getComponentType(t)}getComponentType(t){if("float"===(t=this.getVectorType(t))||"bool"===t||"int"===t||"uint"===t)return t;const e=/(b|i|u|)(vec|mat)([2-4])/.exec(t);return null===e?null:"b"===e[1]?"bool":"i"===e[1]?"int":"u"===e[1]?"uint":"float"}getVectorType(t){return"color"===t?"vec3":"texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t?"vec4":t}getTypeFromLength(t,e="float"){if(1===t)return e;const s=pM.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return mM.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const s=e.array,i=t.itemSize,r=t.normalized;let n;return t instanceof gn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(t){const e=this.getVectorType(t),s=/vec([2-4])/.exec(e);return null!==s?Number(s[1]):"float"===e||"bool"===e||"int"===e||"uint"===e?1:!0===/mat2/.test(t)?4:!0===/mat3/.test(t)?9:!0===/mat4/.test(t)?16:0}getVectorFromMatrix(t){return t.replace("mat","vec")}changeComponentType(t,e){return this.getTypeFromLength(this.getTypeLength(t),e)}getIntegerType(t){const e=this.getComponentType(t);return"int"===e||"uint"===e?t:this.changeComponentType(t,"int")}addStack(){return this.stack=WS(this.stack),this.stacks.push(Rp()||this.stack),Cp(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,Cp(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,s=null){let i=(s=null===s?t.isGlobal(this)?this.globalCache:this.cache:s).getData(t);return void 0===i&&(i={},s.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const s=this.getDataFromNode(t,e);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const s=this.getDataFromNode(t);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new uS("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const s=this.getDataFromNode(t,e);if(void 0===s.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),s.structType=t}return t}getUniformFromNode(t,e,s=this.shaderStage,i=null){const r=this.getDataFromNode(t,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new lS(i||"nodeUniform"+o,e,t),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(t,e=null,s=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let n=r.variable;if(void 0===n){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),n=new cS(e,s),t.push(n),r.variable=n}return n}getVaryingFromNode(t,e=null,s=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,n=t.length;null===e&&(e="nodeVarying"+n),r=new dS(e,s),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,s=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[s]||(this.codes[s]=[]),n=t.length;r=new pS("nodeCode"+n,e),t.push(r),i.code=r}return r}addFlowCodeHierarchy(t,e){const{flowCodes:s,flowCodeBlock:i}=this.getDataFromNode(t);let r=!0,n=e;for(;n;){if(!0===i.get(n)){r=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(r)for(const t of s)this.addLineFlowCode(t)}addLineFlowCodeBlock(t,e,s){const i=this.getDataFromNode(t),r=i.flowCodes||(i.flowCodes=[]),n=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);r.push(e),n.set(s,!0)}addLineFlowCode(t,e=null){return""===t||(null!==e&&this.context.nodeBlock&&this.addLineFlowCodeBlock(e,t,this.context.nodeBlock),t=this.tab+t,/;\s*$/.test(t)||(t+=";\n"),this.flow.code+=t),this}addFlowCode(t){return this.flow.code+=t,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(t){return this.flowsData.get(t)}flowNode(t){const e=t.getNodeType(this),s=this.flowChildNode(t,e);return this.flowsData.set(t,s),s}buildFunctionNode(t){const e=new wS,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout,s={[Symbol.iterator](){let t=0;const e=Object.values(this);return{next:()=>({value:e[t],done:t++>=e.length})}}};for(const t of e.inputs)s[t.name]=new fS(t.type,t.name);t.layout=null;const i=t.call(s),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const s=this.flow,i=this.vars,r=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new gS,this.stack=WS();for(const s of Bd)this.setBuildStage(s),a.result=t.build(this,e);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.cache=r,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(t,e=null){const s=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=s,i}flowNodeFromShaderStage(t,e,s=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const n=this.flowChildNode(e,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[t]=this.flowCode[t]+n.code,this.setShaderStage(r),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(t,e){return`${this.getType(t)} ${e}`}getVars(t){let e="";const s=this.vars[t];if(void 0!==s)for(const t of s)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let s="";if(void 0!==e)for(const t of e)s+=t.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(t){this.shaderStage=t}getShaderStage(){return this.shaderStage}setBuildStage(t){this.buildStage=t}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:t,material:e,renderer:s}=this;if(null!==e){let t=s.nodes.library.fromMaterial(e);null===t&&(console.error(`NodeMaterial: Material "${e.type}" is not compatible.`),t=new cT),t.build(this)}else this.addFlow("compute",t);for(const t of Bd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Id){this.setShaderStage(e);const s=this.flowNodes[e];for(const e of s)"generate"===t?this.flowNode(e):e.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(t,e){if("float"===e||"int"===e||"uint"===e)return new US(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new OS(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new zS(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new LS(t);if("color"===e)return new VS(t);if("mat3"===e)return new DS(t);if("mat4"===e)return new kS(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${t}() instead.`)}format(t,e,s){if((e=this.getVectorType(e))===(s=this.getVectorType(s))||null===s||this.isReference(s))return t;const i=this.getTypeLength(e),r=this.getTypeLength(s);return 16===i&&9===r?`${this.getType(s)}(${t}[0].xyz, ${t}[1].xyz, ${t}[2].xyz)`:9===i&&4===r?`${this.getType(s)}(${t}[0].xy, ${t}[1].xy)`:i>4||r>4||0===r?t:i===r?`${this.getType(s)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(s)&&(t=`${this.getType(this.getComponentType(s))}( ${t} )`),`${this.getType(s)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class yM{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(t,e){let s=t.get(e);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,s)),s}updateBeforeNode(t){const e=t.getUpdateBeforeType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(s,this.renderId)}else e===Cd.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(s,this.renderId)}else e===Cd.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===Cd.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.frameId&&!1!==t.update(this)&&e.set(s,this.frameId)}else if(e===Cd.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.renderId&&!1!==t.update(this)&&e.set(s,this.renderId)}else e===Cd.OBJECT&&t.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class xM{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}xM.isNodeFunctionInput=!0;class bM extends Ud{static get type(){return"StructTypeNode"}constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class vM extends Ud{static get type(){return"OutputStructNode"}constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,s=[];for(let i=0;i<e.length;i++)s.push(e[i].getNodeType(t));this.nodeType=t.getStructTypeFromNode(new bM(s)).name}generate(t,e){const s=t.getOutputStructName(),i=this.members,r=""!==s?s+".":"";for(let s=0;s<i.length;s++){const n=i[s].build(t,e);t.addLineFlowCode(`${r}m${s} = ${n}`,this)}return s}}const TM=Sp(vM);function _M(t,e){for(let s=0;s<t.length;s++)if(t[s].name===e)return s;return-1}class wM extends vM{static get type(){return"MRTNode"}constructor(t){super(),this.outputNodes=t,this.isMRTNode=!0}has(t){return void 0!==this.outputNodes[t]}get(t){return this.outputNodes[t]}merge(t){const e={...this.outputNodes,...t.outputNodes};return SM(e)}setup(t){const e=this.outputNodes,s=[],i=t.renderer.getRenderTarget().textures;for(const t in e){s[_M(i,t)]=Hp(e[t])}return this.members=s,super.setup(t)}}const SM=Sp(wM);class MM extends Ud{static get type(){return"FunctionOverloadingNode"}constructor(t=[],...e){super(),this.functionNodes=t,this.parametersNodes=e,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(t){const e=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let i=null,r=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(e.length===o.length){let n=0;for(let s=0;s<e.length;s++){const i=e[s],r=o[s];i.getNodeType(t)===r.type?n++:n=0}n>r&&(i=s,r=n)}}this._candidateFnCall=s=i(...e)}return s}}const AM=Sp(MM),NM=t=>(...e)=>AM(t,...e);class CM extends Ud{static get type(){return"SpriteSheetUVNode"}constructor(t,e=wy(),s=Pp(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=s}setup(){const{frameNode:t,uvNode:e,countNode:s}=this,{width:i,height:r}=s,n=t.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=zp(o,a);return e.add(u).mul(h)}}const RM=Sp(CM);class EM extends Od{static get type(){return"StorageArrayElementNode"}constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}setup(t){return!1===t.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&t.setupPBO(this.node),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(s=!1===t.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==i?t.generatePBO(this):this.node.build(t):super.generate(t),!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}const BM=Sp(EM);class IM extends Ud{static get type(){return"TriplanarTexturesNode"}constructor(t,e=null,s=null,i=Pp(1),r=rx,n=mx){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:t,textureYNode:e,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(kp(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=t.value,c=null!==e?e.value:l,d=null!==s?s.value:l,p=Ry(l,a).mul(o.x),m=Ry(c,h).mul(o.y),g=Ry(d,u).mul(o.z);return qm(p,m,g)}}const PM=Sp(IM),FM=(...t)=>PM(...t),UM=new Yo,OM=new Ai,zM=new Ai,LM=new Ai,VM=new sr,DM=new Ai(0,0,-1),kM=new xi,GM=new Ai,WM=new Ai,jM=new xi,HM=new Ys,$M=new bi,qM=zv.flipX();let XM=!1;class YM extends Cy{static get type(){return"ReflectorNode"}constructor(t={}){super($M.texture,qM);const{target:e=new Rr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=t;this.target=e,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?Cd.RENDER:Cd.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(HM),t.setSize(Math.round(HM.width*s),Math.round(HM.height*s))}setup(t){return this._updateResolution($M,t.renderer),super.setup(t)}getTextureNode(){return this.textureNode}getVirtualCamera(t){let e=this.virtualCameras.get(t);return void 0===e&&(e=t.clone(),this.virtualCameras.set(t,e)),e}getRenderTarget(t){let e=this.renderTargets.get(t);return void 0===e&&(e=new bi(0,0,{type:Pt}),!0===this.generateMipmaps&&(e.texture.minFilter=1008,e.texture.generateMipmaps=!0),this.renderTargets.set(t,e)),e}updateBefore(t){if(!1===this.bounces&&XM)return!1;XM=!0;const{scene:e,camera:s,renderer:i,material:r}=t,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(HM),this._updateResolution(a,i),zM.setFromMatrixPosition(n.matrixWorld),LM.setFromMatrixPosition(s.matrixWorld),VM.extractRotation(n.matrixWorld),OM.set(0,0,1),OM.applyMatrix4(VM),GM.subVectors(zM,LM),GM.dot(OM)>0)return;GM.reflect(OM).negate(),GM.add(zM),VM.extractRotation(s.matrixWorld),DM.set(0,0,-1),DM.applyMatrix4(VM),DM.add(LM),WM.subVectors(zM,DM),WM.reflect(OM).negate(),WM.add(zM),o.coordinateSystem=s.coordinateSystem,o.position.copy(GM),o.up.set(0,1,0),o.up.applyMatrix4(VM),o.up.reflect(OM),o.lookAt(WM),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),UM.setFromNormalAndCoplanarPoint(OM,zM),UM.applyMatrix4(o.matrixWorldInverse),kM.set(UM.normal.x,UM.normal.y,UM.normal.z,UM.constant);const h=o.projectionMatrix;jM.x=(Math.sign(kM.x)+h.elements[8])/h.elements[0],jM.y=(Math.sign(kM.y)+h.elements[9])/h.elements[5],jM.z=-1,jM.w=(1+h.elements[10])/h.elements[14],kM.multiplyScalar(1/kM.dot(jM));h.elements[2]=kM.x,h.elements[6]=kM.y,h.elements[10]=kM.z-0,h.elements[14]=kM.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget(),l=i.getMRT();i.setMRT(null),i.setRenderTarget(a),i.render(e,o),i.setMRT(l),i.setRenderTarget(u),r.visible=!0,XM=!1}}const ZM=t=>Tp(new YM(t)),JM=new Tl(-1,1,1,-1,0,1);class KM extends Sn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new fn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new fn(e,2))}}const QM=new KM;class tA extends On{constructor(t=null){super(QM,t),this.camera=JM,this.isQuadMesh=!0}renderAsync(t){return t.renderAsync(this,JM)}render(t){t.render(this,JM)}}const eA=new Ys;class sA extends Cy{static get type(){return"RTTNode"}constructor(t,e=null,s=null,i={type:Pt}){const r=new bi(e,s,i);super(r.texture,wy()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new tA(new cT),this.updateBeforeType=Cd.RENDER}get autoSize(){return null===this.width}setup(t){return this._rttNode=this.node.context(t.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(t)}setSize(t,e){this.width=t,this.height=e;const s=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(t){this.pixelRatio=t,this.setSize(this.width,this.height)}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=t.getPixelRatio();const e=t.getSize(eA);this.setSize(e.width,e.height)}this._quadMesh.material.fragmentNode=this._rttNode;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),this._quadMesh.render(t),t.setRenderTarget(e)}clone(){const t=new Cy(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const iA=(t,...e)=>Tp(new sA(Tp(t),...e)),rA=(t,...e)=>t.isTextureNode?t:iA(t,...e);class nA extends Ty{static get type(){return"VertexColorNode"}constructor(t=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=t}getAttributeName(){const t=this.index;return"color"+(t>0?t:"")}generate(t){const e=this.getAttributeName(t);let s;return s=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new xi(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const oA=(...t)=>Tp(new nA(...t));class aA extends Ud{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const hA=Mp(aA);class uA extends Ud{static get type(){return"SceneNode"}constructor(t=uA.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=null!==this.scene?this.scene:t.scene;let i;return e===uA.BACKGROUND_BLURRINESS?i=Lx("backgroundBlurriness","float",s):e===uA.BACKGROUND_INTENSITY?i=Lx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}uA.BACKGROUND_BLURRINESS="backgroundBlurriness",uA.BACKGROUND_INTENSITY="backgroundIntensity";const lA=Mp(uA,uA.BACKGROUND_BLURRINESS),cA=Mp(uA,uA.BACKGROUND_INTENSITY),dA="point-list",pA="line-list",mA="line-strip",gA="triangle-list",fA="triangle-strip",yA="never",xA="less",bA="equal",vA="less-equal",TA="greater",_A="not-equal",wA="greater-equal",SA="always",MA="store",AA="load",NA="clear",CA="ccw",RA="none",EA="front",BA="back",IA="uint16",PA="uint32",FA={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},UA="clamp-to-edge",OA="repeat",zA="mirror-repeat",LA="linear",VA="nearest",DA="zero",kA="one",GA="src",WA="one-minus-src",jA="src-alpha",HA="one-minus-src-alpha",$A="dst",qA="one-minus-dst",XA="dst-alpha",YA="one-minus-dst-alpha",ZA="src-alpha-saturated",JA="constant",KA="one-minus-constant",QA="add",tN="subtract",eN="reverse-subtract",sN="min",iN="max",rN=0,nN=15,oN="keep",aN="zero",hN="replace",uN="invert",lN="increment-clamp",cN="decrement-clamp",dN="increment-wrap",pN="decrement-wrap",mN="storage",gN="read-only-storage",fN="write-only",yN="read-only",xN="float",bN="unfilterable-float",vN="depth",TN="sint",_N="uint",wN="2d",SN="3d",MN="2d",AN="2d-array",NN="cube",CN="3d",RN="all",EN="vertex",BN="instance",IN={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class PN extends Ex{static get type(){return"StorageBufferNode"}constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=mN,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==t.isStorageBufferAttribute&&!0!==t.isStorageInstancedBufferAttribute&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(0===this.bufferCount){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(t){return BM(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(gN)}setAtomic(t){return this.isAtomic=t,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=ey(this.value),this._varying=zf(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(t){if(t.isAvailable("storageBuffer"))return super.getNodeType(t);const{attribute:e}=this.getAttributeData();return e.getNodeType(t)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const{attribute:e,varying:s}=this.getAttributeData(),i=s.build(t);return t.registerTransform(i,e),i}}const FN=(t,e,s)=>Tp(new PN(t,e,s)),UN=(t,e,s)=>Tp(new PN(t,e,s).setBufferObject(!0));class ON extends Cy{static get type(){return"StorageTextureNode"}constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=fN}getInputType(){return"storageTexture"}setup(t){super.setup(t);t.getNodeProperties(this).storeNode=this.storeNode}setAccess(t){return this.access=t,this}generate(t,e){let s;return s=null!==this.storeNode?this.generateStore(t):super.generate(t,e),s}toReadOnly(){return this.setAccess(yN)}toWriteOnly(){return this.setAccess(fN)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:s,storeNode:i}=e,r=super.generate(t,"property"),n=s.build(t,"uvec2"),o=i.build(t,"vec4"),a=t.generateTextureStore(t,r,n,o);t.addLineFlowCode(a,this)}}const zN=Sp(ON),LN=(t,e,s)=>{const i=zN(t,e,s);return null!==s&&i.append(),i};class VN extends zx{static get type(){return"UserDataNode"}constructor(t,e,s=null){super(t,e,s),this.userData=s}updateReference(t){return this.reference=null!==this.userData?this.userData:t.object.userData,this.reference}}const DN=(t,e,s)=>Tp(new VN(t,e,s));class kN extends Ld{static get type(){return"PosterizeNode"}constructor(t,e){super(),this.sourceNode=t,this.stepsNode=e}setup(){const{sourceNode:t,stepsNode:e}=this;return t.mul(e).floor().div(e)}}const GN=Sp(kN);let WN=null;class jN extends Xv{static get type(){return"ViewportSharedTextureNode"}constructor(t=zv,e=null){null===WN&&(WN=new ka),super(t,e,WN)}updateReference(){return this}}const HN=Sp(jN),$N=new Ys;class qN extends Cy{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class XN extends qN{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class YN extends Ld{static get type(){return"PassNode"}constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new $a;r.isRenderTargetTexture=!0,r.name="depth";const n=new bi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=Cd.FRAME,this._textures={output:n.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=lm(0),this._cameraFar=lm(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];if(void 0===e){e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)}return e}getPreviousTexture(t){let e=this._previousTextures[t];return void 0===e&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(void 0!==e){const s=this._textures[t],i=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[i]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return void 0===e&&(this._textureNodes[t]=e=Tp(new XN(this,t)),this._textureNodes[t].updateTexture()),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return void 0===e&&(void 0===this._textureNodes[t]&&this.getTextureNode(t),this._previousTextureNodes[t]=e=Tp(new XN(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=rT(this.getTextureNode(t),s,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar,r=this.getViewZNode(t);this._linearDepthNodes[t]=e=eT(r,s,i)}return e}setup({renderer:t}){return this.renderTarget.samples=void 0===this.options.samples?t.samples:this.options.samples,!0===t.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===YN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize($N);this.setSize(r.width,r.height);const n=e.getRenderTarget(),o=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const t in this._previousTextures)this.toggleTexture(t);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,i),e.setRenderTarget(n),e.setMRT(o)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}YN.COLOR="color",YN.DEPTH="depth";const ZN=(t,e,s)=>Tp(new YN(YN.COLOR,t,e,s)),JN=(t,e)=>Tp(new qN(t,e)),KN=(t,e)=>Tp(new YN(YN.DEPTH,t,e));class QN extends YN{static get type(){return"ToonOutlinePassNode"}constructor(t,e,s,i,r){super(YN.COLOR,t,e),this.colorNode=s,this.thicknessNode=i,this.alphaNode=r,this._materialCache=new WeakMap}updateBefore(t){const{renderer:e}=t,s=e.getRenderObjectFunction();e.setRenderObjectFunction(((t,s,i,r,n,o,a)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const h=this._getOutlineMaterial(n);e.renderObject(t,s,i,r,h,o,a)}e.renderObject(t,s,i,r,n,o,a)})),super.updateBefore(t),e.setRenderObjectFunction(s)}_createMaterial(){const t=new cT;t.isMeshToonOutlineMaterial=!0,t.name="Toon_Outline",t.side=d;const e=mx.negate(),s=Fy.mul(tx),i=Pp(1),r=s.mul(Hp(rx,1)),n=s.mul(Hp(rx.add(e),1)),o=Pg(r.sub(n));return t.vertexNode=r.add(o.mul(this.thicknessNode).mul(r.w).mul(i)),t.colorNode=Hp(this.colorNode,this.alphaNode),t}_getOutlineMaterial(t){let e=this._materialCache.get(t);return void 0===e&&(e=this._createMaterial(),this._materialCache.set(t,e)),e}}const tC=(t,e,s=new Xr(0,0,0),i=.003,r=1)=>Tp(new QN(t,e,Tp(s),Tp(i),Tp(r)));class eC extends Ud{static get type(){return"ScriptableValueNode"}constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new zs,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(t){this._value!==t&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=t,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const t=this.value;if(t&&null===this._cache&&"URL"===this.inputType&&t.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([t.value]));else if(t&&null!==t.value&&void 0!==t.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof t.value||"Number"===this.inputType&&"number"==typeof t.value||"Vector2"===this.inputType&&t.value.isVector2||"Vector3"===this.inputType&&t.value.isVector3||"Vector4"===this.inputType&&t.value.isVector4||"Color"===this.inputType&&t.value.isColor||"Matrix3"===this.inputType&&t.value.isMatrix3||"Matrix4"===this.inputType&&t.value.isMatrix4))return t.value;return this._cache||t}getNodeType(t){return this.value&&this.value.isNode?this.value.getNodeType(t):"float"}setup(){return this.value&&this.value.isNode?this.value:Pp()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=Sd(this.value):t.value=this.value?this.value.toJSON(t.meta).uuid:null:t.value=null,t.inputType=this.inputType,t.outputType=this.outputType}deserialize(t){super.deserialize(t);let e=null;null!==t.value&&(e="ArrayBuffer"===t.inputType?Md(t.value):"Texture"===t.inputType?t.meta.textures[t.value]:t.meta.nodes[t.value]||null),this.value=e,this.inputType=t.inputType,this.outputType=t.outputType}}const sC=Sp(eC);class iC extends Map{get(t,e=null,...s){if(this.has(t))return super.get(t);if(null!==e){const i=e(...s);return this.set(t,i),i}}}class rC{constructor(t){this.scriptableNode=t}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(t){return this.scriptableNode.getInputLayout(t)}get(t){const e=this.parameters[t];return e?e.getValue():null}}const nC=new iC;class oC extends Ud{static get type(){return"ScriptableNode"}constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new iC,this._output=sC(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(t,e){return this._local.set(t,e)}getLocal(t){return this._local.get(t)}onRefresh(){this._refresh()}getInputLayout(t){for(const e of this.getLayout())if(e.inputType&&(e.id===t||e.name===t))return e}getOutputLayout(t){for(const e of this.getLayout())if(e.outputType&&(e.id===t||e.name===t))return e}setOutput(t,e){const s=this._outputs;return void 0===s[t]?s[t]=sC(e):s[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const s=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),s[t]=e,s[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),s[t]=e,s[t].events.addEventListener("refresh",this.onRefresh)):void 0===s[t]?(s[t]=sC(e),s[t].events.addEventListener("refresh",this.onRefresh)):s[t].value=e,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(t){let e=this.parameters[t];return e&&(e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const t of Object.keys(this.parameters))this.deleteParameter(t);return this.needsUpdate=!0,this}call(t,...e){const s=this.getObject()[t];if("function"==typeof s)return s(...e)}async callAsync(t,...e){const s=this.getObject()[t];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...e):s(...e)}getNodeType(t){return this.getDefaultOutputNode().getNodeType(t)}refresh(t=null){null!==t?this.getOutput(t).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const t=new rC(this),e=nC.get("THREE"),s=nC.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,nC,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,s];this._object=i(...r);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const t of n.elements){const e=t.id||t.name;t.inputType&&(void 0===this.getParameter(e)&&this.setParameter(e,null),this.getParameter(e).inputType=t.inputType),t.outputType&&(void 0===this.getOutput(e)&&this.setOutput(e,null),this.getOutput(e).outputType=t.outputType)}return this._object}deserialize(t){super.deserialize(t);for(const t in this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const t=this.getDefaultOutput().value;return t&&t.isNode?t:Pp()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const t=["layout","init","main","dispose"].join(", "),e="\nreturn { ...output, "+t+" };",s="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(t){const e=[yd(this.source),this.getDefaultOutputNode().getCacheKey(t)];for(const s in this.parameters)e.push(this.parameters[s].getCacheKey(t));return xd(e)}set needsUpdate(t){!0===t&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const aC=Sp(oC);class hC extends Ud{static get type(){return"FogNode"}constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const s=t.context.getViewZ;return void 0!==s&&(e=s(this)),(e||hx.z).negate()}setup(){return this.factorNode}}const uC=Sp(hC);class lC extends hC{static get type(){return"FogRangeNode"}constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return _f(this.nearNode,this.farNode,e)}}const cC=Sp(lC);class dC extends hC{static get type(){return"FogExp2Node"}constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),s=this.densityNode;return s.mul(s,e,e).negate().exp().oneMinus()}}const pC=Sp(dC);let mC=null,gC=null;class fC extends Ud{static get type(){return"RangeNode"}constructor(t=Pp(),e=Pp()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(_d(this.minNode.value)),s=t.getTypeLength(_d(this.maxNode.value));return e>s?e:s}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let s=null;if(e.count>1){const i=this.minNode.value,r=this.maxNode.value,n=t.getTypeLength(_d(i)),o=t.getTypeLength(_d(r));mC=mC||new xi,gC=gC||new xi,mC.setScalar(0),gC.setScalar(0),1===n?mC.setScalar(i):i.isColor?mC.set(i.r,i.g,i.b):mC.set(i.x,i.y,i.z||0,i.w||0),1===o?gC.setScalar(r):r.isColor?gC.set(r.r,r.g,r.b):gC.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,u=new Float32Array(h);for(let t=0;t<h;t++){const e=t%a,s=mC.getComponent(e),i=gC.getComponent(e);u[t]=Xs.lerp(s,i,Math.random())}const l=this.getNodeType(t);if(e.count<=4096)s=Bx(u,"vec4",e.count).element(sv).convert(l);else{const e=new zo(u,4);t.geometry.setAttribute("__range"+this.id,e),s=iy(e).convert(l)}}else s=Pp(0);return s}}const yC=Sp(fC),xC=Ap((({depthTexture:t,shadowCoord:e})=>Ry(t,e.xy).compare(e.z))),bC=Ap((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>Ry(t,e).compare(s),r=Lx("mapSize","vec2",s).setGroup(am),n=Lx("radius","float",s).setGroup(am),o=zp(1).div(r),a=o.x.negate().mul(n),h=o.y.negate().mul(n),u=o.x.mul(n),l=o.y.mul(n),c=a.div(2),d=h.div(2),p=u.div(2),m=l.div(2);return qm(i(e.xy.add(zp(a,h)),e.z),i(e.xy.add(zp(0,h)),e.z),i(e.xy.add(zp(u,h)),e.z),i(e.xy.add(zp(c,d)),e.z),i(e.xy.add(zp(0,d)),e.z),i(e.xy.add(zp(p,d)),e.z),i(e.xy.add(zp(a,0)),e.z),i(e.xy.add(zp(c,0)),e.z),i(e.xy,e.z),i(e.xy.add(zp(p,0)),e.z),i(e.xy.add(zp(u,0)),e.z),i(e.xy.add(zp(c,m)),e.z),i(e.xy.add(zp(0,m)),e.z),i(e.xy.add(zp(p,m)),e.z),i(e.xy.add(zp(a,l)),e.z),i(e.xy.add(zp(0,l)),e.z),i(e.xy.add(zp(u,l)),e.z)).mul(1/17)})),vC=Ap((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>Ry(t,e).compare(s),r=Lx("mapSize","vec2",s).setGroup(am),n=zp(1).div(r),o=n.x,a=n.y,h=e.xy,u=Fg(h.mul(r).add(.5));return h.subAssign(u.mul(n)),qm(i(h,e.z),i(h.add(zp(o,0)),e.z),i(h.add(zp(0,a)),e.z),i(h.add(n),e.z),xf(i(h.add(zp(o.negate(),0)),e.z),i(h.add(zp(o.mul(2),0)),e.z),u.x),xf(i(h.add(zp(o.negate(),a)),e.z),i(h.add(zp(o.mul(2),a)),e.z),u.x),xf(i(h.add(zp(0,a.negate())),e.z),i(h.add(zp(0,a.mul(2))),e.z),u.y),xf(i(h.add(zp(o,a.negate())),e.z),i(h.add(zp(o,a.mul(2))),e.z),u.y),xf(xf(i(h.add(zp(o.negate(),a.negate())),e.z),i(h.add(zp(o.mul(2),a.negate())),e.z),u.x),xf(i(h.add(zp(o.negate(),a.mul(2))),e.z),i(h.add(zp(o.mul(2),a.mul(2))),e.z),u.x),u.y)).mul(1/9)})),TC=Ap((({depthTexture:t,shadowCoord:e})=>{const s=Pp(1).toVar(),i=Ry(t).uv(e.xy).rg,r=nf(e.z,i.x);return Ep(r.notEqual(Pp(1)),(()=>{const t=e.z.sub(i.x),n=sf(0,i.y.mul(i.y));let o=n.div(n.add(t.mul(t)));o=bf(Xm(o,.3).div(.95-.3)),s.assign(bf(sf(r,o)))})),s})),_C=Ap((({samples:t,radius:e,size:s,shadowPass:i})=>{const r=Pp(0).toVar(),n=Pp(0).toVar(),o=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(2).div(t.sub(1))),a=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(-1));fv({start:Fp(0),end:Fp(t),type:"int",condition:"<"},(({i:t})=>{const h=a.add(Pp(t).mul(o)),u=i.uv(qm(Vv.xy,zp(0,h).mul(e)).div(s)).x;r.addAssign(u),n.addAssign(u.mul(u))})),r.divAssign(t),n.divAssign(t);const h=Rg(n.sub(r.mul(r)));return zp(r,h)})),wC=Ap((({samples:t,radius:e,size:s,shadowPass:i})=>{const r=Pp(0).toVar(),n=Pp(0).toVar(),o=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(2).div(t.sub(1))),a=t.lessThanEqual(Pp(1)).select(Pp(0),Pp(-1));fv({start:Fp(0),end:Fp(t),type:"int",condition:"<"},(({i:t})=>{const h=a.add(Pp(t).mul(o)),u=i.uv(qm(Vv.xy,zp(h,0).mul(e)).div(s));r.addAssign(u.x),n.addAssign(qm(u.y.mul(u.y),u.x.mul(u.x)))})),r.divAssign(t),n.divAssign(t);const h=Rg(n.sub(r.mul(r)));return zp(r,h)})),SC=[xC,bC,vC,TC];let MC=null;const AC=new tA;class NC extends Rv{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=Cd.FRAME,this.light=t,this.color=new Xr,this.colorNode=lm(this.color).setGroup(am),this.baseColorNode=null,this.shadowMap=null,this.shadowNode=null,this.shadowColorNode=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.isAnalyticLightNode=!0}getCacheKey(){return bd(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(t){const{object:e,renderer:s}=t;if(!1===s.shadowMap.enabled)return;let i=this.shadowColorNode;if(null===i){null===MC&&(MC=new cT,MC.fragmentNode=Hp(0,0,0,1),MC.isShadowNodeMaterial=!0,MC.name="ShadowMaterial");const r=s.shadowMap.type,n=this.light.shadow,o=new $a;o.compareFunction=ys;const a=t.createRenderTarget(n.mapSize.width,n.mapSize.height);if(a.depthTexture=o,n.camera.updateProjectionMatrix(),3===r){o.compareFunction=null,this.vsmShadowMapVertical=t.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:qt,type:Pt}),this.vsmShadowMapHorizontal=t.createRenderTarget(n.mapSize.width,n.mapSize.height,{format:qt,type:Pt});const e=Ry(o),s=Ry(this.vsmShadowMapVertical.texture),i=Lx("blurSamples","float",n).setGroup(am),r=Lx("radius","float",n).setGroup(am),a=Lx("mapSize","vec2",n).setGroup(am);let h=this.vsmMaterialVertical||(this.vsmMaterialVertical=new cT);h.fragmentNode=_C({samples:i,radius:r,size:a,shadowPass:e}).context(t.getSharedContext()),h.name="VSMVertical",h=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new cT),h.fragmentNode=wC({samples:i,radius:r,size:a,shadowPass:s}).context(t.getSharedContext()),h.name="VSMHorizontal"}const h=Lx("intensity","float",n).setGroup(am),u=Lx("bias","float",n).setGroup(am),l=Lx("normalBias","float",n).setGroup(am),c=e.material.shadowPositionNode||ox;let d,p=lm(n.matrix).setGroup(am).mul(c.add(yx.mul(l)));if(n.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)p=p.xyz.div(p.w),d=p.z,s.coordinateSystem===Os&&(d=d.mul(2).sub(1));else{const t=p.w;p=p.xy.div(t);const e=lm("float").onRenderUpdate((()=>n.camera.near)),s=lm("float").onRenderUpdate((()=>n.camera.far));d=nT(t,e,s)}p=kp(p.x,p.y.oneMinus(),d.add(u));const m=p.x.greaterThanEqual(0).and(p.x.lessThanEqual(1)).and(p.y.greaterThanEqual(0)).and(p.y.lessThanEqual(1)).and(p.z.lessThanEqual(1)),g=n.filterNode||SC[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const f=Ry(a.texture,p),y=m.select(g({depthTexture:3===r?this.vsmShadowMapHorizontal.texture:o,shadowCoord:p,shadow:n}),Pp(1));this.shadowMap=a,this.light.shadow.map=a,this.shadowNode=y,this.shadowColorNode=i=this.colorNode.mul(xf(1,y.rgb.mix(f,1),h.mul(f.a))),this.baseColorNode=this.colorNode}this.colorNode=i,this.updateBeforeType=Cd.RENDER}setup(t){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?t.object.receiveShadow&&this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{shadowMap:e,light:s}=this,{renderer:i,scene:r,camera:n}=t,o=i.shadowMap.type,a=e.depthTexture.version;this._depthVersionCached=a;const h=r.overrideMaterial;r.overrideMaterial=MC,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const u=i.getRenderTarget(),l=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{(!0===t.castShadow||t.receiveShadow&&3===o)&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.render(r,s.shadow.camera),i.setRenderObjectFunction(l),!0!==s.isPointLight&&3===o&&this.vsmPass(t,s),i.setRenderTarget(u),r.overrideMaterial=h}vsmPass(t,e){const{renderer:s}=t;this.vsmShadowMapVertical.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),this.vsmShadowMapHorizontal.setSize(e.shadow.mapSize.width,e.shadow.mapSize.height),s.setRenderTarget(this.vsmShadowMapVertical),AC.material=this.vsmMaterialVertical,AC.render(s),s.setRenderTarget(this.vsmShadowMapHorizontal),AC.material=this.vsmMaterialHorizontal,AC.render(s)}disposeShadow(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.shadowNode=null,this.shadowColorNode=null,this.baseColorNode=null,this.updateBeforeType=Cd.NONE}updateBefore(t){const e=this.light.shadow;(e.needsUpdate||e.autoUpdate)&&(this.updateShadow(t),this.shadowMap.depthTexture.version===this._depthVersionCached&&(e.needsUpdate=!1))}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}const CC=Ap((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).select(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));let RC;function EC(t){RC=RC||new WeakMap;let e=RC.get(t);return void 0===e&&RC.set(t,e={}),e}function BC(t){const e=EC(t);return e.position||(e.position=lm(new Ai).setGroup(am).onRenderUpdate(((e,s)=>s.value.setFromMatrixPosition(t.matrixWorld))))}function IC(t){const e=EC(t);return e.targetPosition||(e.targetPosition=lm(new Ai).setGroup(am).onRenderUpdate(((e,s)=>s.value.setFromMatrixPosition(t.target.matrixWorld))))}function PC(t){const e=EC(t);return e.viewPosition||(e.viewPosition=lm(new Ai).setGroup(am).onRenderUpdate((({camera:e},s)=>{s.value=s.value||new Ai,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(e.matrixWorldInverse)})))}const FC=t=>Oy.transformDirection(BC(t).sub(IC(t))),UC=Ap((([t])=>{const e=t.toUint().mul(747796405).add(2891336453),s=e.shiftRight(e.shiftRight(28).add(4)).bitXor(e).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),OC=(t,e)=>cf(Ym(4,t.mul(Xm(1,t))),e),zC=(t,e)=>t.lessThan(.5)?OC(t.mul(2),e).div(2):Xm(1,OC(Ym(Xm(1,t),2),e).div(2)),LC=(t,e,s)=>cf(Zm(cf(t,e),qm(cf(t,e),cf(Xm(1,t),s))),1/e),VC=(t,e)=>Ug(xg.mul(e.mul(t).sub(1))).div(xg.mul(e.mul(t).sub(1))),DC=Ap((([t])=>t.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),kC=Ap((([t])=>kp(DC(t.z.add(DC(t.y.mul(1)))),DC(t.z.add(DC(t.x.mul(1)))),DC(t.y.add(DC(t.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),GC=Ap((([t,e,s])=>{const i=kp(t).toVar(),r=Pp(1.4).toVar(),n=Pp(0).toVar(),o=kp(i).toVar();return fv({start:Pp(0),end:Pp(3),type:"float",condition:"<="},(()=>{const t=kp(kC(o.mul(2))).toVar();i.addAssign(t.add(s.mul(Pp(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=Pp(DC(i.z.add(DC(i.x.add(DC(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]}),WC=lm(0).setGroup(am).onRenderUpdate((t=>t.time)),jC=lm(0).setGroup(am).onRenderUpdate((t=>t.deltaTime)),HC=lm(0,"uint").setGroup(am).onRenderUpdate((t=>t.frameId)),$C=(t=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),WC.mul(t)),qC=(t=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),WC.mul(t)),XC=(t=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),jC.mul(t)),YC=(t=WC)=>t.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),ZC=(t=WC)=>t.fract().round(),JC=(t=WC)=>t.add(.5).fract().mul(2).sub(1).abs(),KC=(t=WC)=>t.fract(),QC=Ap((([t,e,s=zp(.5)])=>Cw(t.sub(s),e).add(s))),tR=Ap((([t,e,s=zp(.5)])=>{const i=t.sub(s),r=i.dot(i),n=r.mul(r).mul(e);return t.add(i.mul(n))})),eR=Ap((({position:t=null,horizontal:e=!0,vertical:s=!1})=>{let i;null!==t?(i=Xy.toVar(),i[3][0]=t.x,i[3][1]=t.y,i[3][2]=t.z):i=Xy;const r=Oy.mul(i);return xp(e)&&(r[0][0]=Xy[0].length(),r[0][1]=0,r[0][2]=0),xp(s)&&(r[1][0]=0,r[1][1]=Xy[1].length(),r[1][2]=0),r[2][0]=0,r[2][1]=0,r[2][2]=1,Fy.mul(r).mul(rx)})),sR=Ap((([t=null])=>{const e=hT();return hT(Qv(t)).sub(e).lessThan(0).select(zv,t)})),iR=new WeakMap;class rR extends Ld{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.updateType=Cd.OBJECT,this.updateAfterType=Cd.OBJECT,this.previousModelWorldMatrix=lm(new sr),this.previousProjectionMatrix=lm(new sr).setGroup(am),this.previousCameraViewMatrix=lm(new sr)}update({frameId:t,camera:e,object:s}){const i=oR(s);this.previousModelWorldMatrix.value.copy(i);const r=nR(e);r.frameId!==t&&(r.frameId=t,void 0===r.previousProjectionMatrix?(r.previousProjectionMatrix=new sr,r.previousCameraViewMatrix=new sr,r.currentProjectionMatrix=new sr,r.currentCameraViewMatrix=new sr,r.previousProjectionMatrix.copy(e.projectionMatrix),r.previousCameraViewMatrix.copy(e.matrixWorldInverse)):(r.previousProjectionMatrix.copy(r.currentProjectionMatrix),r.previousCameraViewMatrix.copy(r.currentCameraViewMatrix)),r.currentProjectionMatrix.copy(e.projectionMatrix),r.currentCameraViewMatrix.copy(e.matrixWorldInverse),this.previousProjectionMatrix.value.copy(r.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(r.previousCameraViewMatrix))}updateAfter({object:t}){oR(t).copy(t.matrixWorld)}setup(){const t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),e=Fy.mul(tx).mul(rx),s=this.previousProjectionMatrix.mul(t).mul(nx),i=e.xy.div(e.w),r=s.xy.div(s.w);return Xm(i,r)}}function nR(t){let e=iR.get(t);return void 0===e&&(e={},iR.set(t,e)),e}function oR(t,e=0){const s=nR(t);let i=s[e];return void 0===i&&(s[e]=i=new sr),i}const aR=Mp(rR),hR=Ap((([t,e])=>ef(1,t.oneMinus().div(e)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),uR=Ap((([t,e])=>ef(t.div(e.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),lR=Ap((([t,e])=>t.oneMinus().mul(e.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cR=Ap((([t,e])=>xf(t.mul(2).mul(e),t.oneMinus().mul(2).mul(e.oneMinus()).oneMinus(),nf(.5,t)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),dR=Ap((([t])=>fR(t.rgb))),pR=Ap((([t,e=Pp(1)])=>e.mix(fR(t.rgb),t.rgb))),mR=Ap((([t,e=Pp(1)])=>{const s=qm(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),r=i.sub(s).mul(e).mul(-3);return xf(t.rgb,i,r)})),gR=Ap((([t,e=Pp(1)])=>{const s=kp(.57735,.57735,.57735),i=e.cos();return kp(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(uf(s,t.rgb).mul(i.oneMinus())))))})),fR=(t,e=kp(ii.getLuminanceCoefficients(new Ai)))=>uf(t,e),yR=(t,e)=>xf(kp(0),t,fR(t).sub(e).max(0)),xR=Ap((([t,e=kp(1),s=kp(0),i=kp(1),r=Pp(1),n=kp(ii.getLuminanceCoefficients(new Ai,Je))])=>{const o=t.rgb.dot(kp(n)),a=sf(t.rgb.mul(e).add(s),0).toVar(),h=a.pow(i).toVar();return Ep(a.r.greaterThan(0),(()=>{a.r.assign(h.r)})),Ep(a.g.greaterThan(0),(()=>{a.g.assign(h.g)})),Ep(a.b.greaterThan(0),(()=>{a.b.assign(h.b)})),a.assign(o.add(a.sub(o).mul(r))),Hp(a.rgb,t.a)})),bR=Ap((([t])=>{const e=t.mul(.9478672986).add(.0521327014).pow(2.4),s=t.mul(.0773993808),i=t.lessThanEqual(.04045);return xf(e,s,i)})).setLayout({name:"sRGBToLinearSRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),vR=Ap((([t])=>{const e=t.pow(.41666).mul(1.055).sub(.055),s=t.mul(12.92),i=t.lessThanEqual(.0031308);return xf(e,s,i)})).setLayout({name:"linearSRGBTosRGB",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),TR=Ap((([t,e])=>t.mul(e).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),_R=Ap((([t,e])=>(t=t.mul(e)).div(t.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),wR=Ap((([t,e])=>{const s=(t=(t=t.mul(e)).sub(.004).max(0)).mul(t.mul(6.2).add(.5)),i=t.mul(t.mul(6.2).add(1.7)).add(.06);return s.div(i).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),SR=Ap((([t])=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),s=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(s)})),MR=Ap((([t,e])=>{const s=Zp(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Zp(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=SR(t),(t=i.mul(t)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),AR=Zp(kp(1.6605,-.1246,-.0182),kp(-.5876,1.1329,-.1006),kp(-.0728,-.0083,1.1187)),NR=Zp(kp(.6274,.0691,.0164),kp(.3293,.9195,.088),kp(.0433,.0113,.8956)),CR=Ap((([t])=>{const e=kp(t).toVar(),s=kp(e.mul(e)).toVar(),i=kp(s.mul(s)).toVar();return Pp(15.5).mul(i.mul(s)).sub(Ym(40.14,i.mul(e))).add(Ym(31.96,i).sub(Ym(6.868,s.mul(e))).add(Ym(.4298,s).add(Ym(.1191,e).sub(.00232))))})),RR=Ap((([t,e])=>{const s=kp(t).toVar(),i=Zp(kp(.856627153315983,.137318972929847,.11189821299995),kp(.0951212405381588,.761241990602591,.0767994186031903),kp(.0482516061458583,.101439036467562,.811302368396859)),r=Zp(kp(1.1271005818144368,-.1413297634984383,-.14132976349843826),kp(-.11060664309660323,1.157823702216272,-.11060664309660294),kp(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=Pp(-12.47393),o=Pp(4.026069);return s.mulAssign(e),s.assign(NR.mul(s)),s.assign(i.mul(s)),s.assign(sf(s,1e-10)),s.assign(Cg(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(bf(s,0,1)),s.assign(CR(s)),s.assign(r.mul(s)),s.assign(cf(sf(kp(0),s),kp(2.2))),s.assign(AR.mul(s)),s.assign(bf(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),ER=Ap((([t,e])=>{const s=Pp(.76),i=Pp(.15);t=t.mul(e);const r=ef(t.r,ef(t.g,t.b)),n=Cf(r.lessThan(.08),r.sub(Ym(6.25,r.mul(r))),.04);t.subAssign(n);const o=sf(t.r,sf(t.g,t.b));Ep(o.lessThan(s),(()=>t));const a=Xm(1,s),h=Xm(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const u=Xm(1,Zm(1,i.mul(o.sub(h)).add(1)));return xf(t,kp(h),u)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class BR extends Ud{static get type(){return"ComputeBuiltinNode"}constructor(t,e){super(e),this._builtinName=t}getHash(t){return this.getBuiltinName(t)}getNodeType(){return this.nodeType}setBuiltinName(t){return this._builtinName=t,this}getBuiltinName(){return this._builtinName}hasBuiltin(t){t.hasBuiltin(this._builtinName)}generate(t,e){const s=this.getBuiltinName(t),i=this.getNodeType(t);return"compute"===t.shaderStage?t.format(s,i,e):(console.warn(`ComputeBuiltinNode: Compute built-in value ${s} can not be accessed in the ${t.shaderStage} stage`),t.generateConst(i))}serialize(t){super.serialize(t),t.global=this.global,t._builtinName=this._builtinName}deserialize(t){super.deserialize(t),this.global=t.global,this._builtinName=t._builtinName}}const IR=(t,e)=>Tp(new BR(t,e)),PR=IR("numWorkgroups","uvec3"),FR=IR("workgroupId","uvec3"),UR=IR("localId","uvec3"),OR=IR("subgroupSize","uint");const zR=Sp(class extends Ud{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;!0===s.backend.isWebGLBackend?t.addFlowCode(`\t// ${e}Barrier \n`):t.addLineFlowCode(`${e}Barrier()`,this)}}),LR=()=>zR("workgroup").append(),VR=()=>zR("storage").append(),DR=()=>zR("texture").append();class kR extends Od{constructor(t,e){super(t,e),this.isWorkgroupInfoElementNode=!0}generate(t,e){let s;const i=t.context.assign;if(s=super.generate(t),!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}class GR extends Ud{constructor(t,e,s=0){super(e),this.bufferType=e,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=t}label(t){return this.name=t,this}getHash(){return this.uuid}setScope(t){return this.scope=t,this}getInputType(){return`${this.scope}Array`}element(t){return Tp(new kR(this,t))}generate(t){return t.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const WR=(t,e)=>Tp(new GR("Workgroup",t,e));class jR extends Ld{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,i=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=i}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),i=this.getInputType(t),r=this.pointerNode,n=this.valueNode,o=[];o.push(`&${r.build(t,i)}`),o.push(n.build(t,i));const a=`${t.getMethod(e,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const e=this.storeNode.build(t,i);t.addLineFlowCode(`${e} = ${a}`,this)}else t.addLineFlowCode(a,this)}}jR.ATOMIC_LOAD="atomicLoad",jR.ATOMIC_STORE="atomicStore",jR.ATOMIC_ADD="atomicAdd",jR.ATOMIC_SUB="atomicSub",jR.ATOMIC_MAX="atomicMax",jR.ATOMIC_MIN="atomicMin",jR.ATOMIC_AND="atomicAnd",jR.ATOMIC_OR="atomicOr",jR.ATOMIC_XOR="atomicXor";const HR=Sp(jR),$R=(t,e,s,i)=>{const r=HR(t,e,s,i);return r.append(),r},qR=(t,e,s=null)=>$R(jR.ATOMIC_STORE,t,e,s),XR=(t,e,s=null)=>$R(jR.ATOMIC_ADD,t,e,s),YR=(t,e,s=null)=>$R(jR.ATOMIC_SUB,t,e,s),ZR=(t,e,s=null)=>$R(jR.ATOMIC_MAX,t,e,s),JR=(t,e,s=null)=>$R(jR.ATOMIC_MIN,t,e,s),KR=(t,e,s=null)=>$R(jR.ATOMIC_AND,t,e,s),QR=(t,e,s=null)=>$R(jR.ATOMIC_OR,t,e,s),tE=(t,e,s=null)=>$R(jR.ATOMIC_XOR,t,e,s),eE=Ap((([t=e()])=>{const e=t.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()})),sE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Op(t).toVar();return Cf(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),iE=Ap((([t,e])=>{const s=Op(e).toVar(),i=Pp(t).toVar();return Cf(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),rE=Ap((([t])=>{const e=Pp(t).toVar();return Fp(Bg(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),nE=Ap((([t,e])=>{const s=Pp(t).toVar();return e.assign(rE(s)),s.sub(Pp(e))})),oE=NM([Ap((([t,e,s,i,r,n])=>{const o=Pp(n).toVar(),a=Pp(r).toVar(),h=Pp(i).toVar(),u=Pp(s).toVar(),l=Pp(e).toVar(),c=Pp(t).toVar(),d=Pp(Xm(1,a)).toVar();return Xm(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),Ap((([t,e,s,i,r,n])=>{const o=Pp(n).toVar(),a=Pp(r).toVar(),h=kp(i).toVar(),u=kp(s).toVar(),l=kp(e).toVar(),c=kp(t).toVar(),d=Pp(Xm(1,a)).toVar();return Xm(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),aE=NM([Ap((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=Pp(l).toVar(),d=Pp(u).toVar(),p=Pp(h).toVar(),m=Pp(a).toVar(),g=Pp(o).toVar(),f=Pp(n).toVar(),y=Pp(r).toVar(),x=Pp(i).toVar(),b=Pp(s).toVar(),v=Pp(e).toVar(),T=Pp(t).toVar(),_=Pp(Xm(1,p)).toVar(),w=Pp(Xm(1,d)).toVar();return Pp(Xm(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),Ap((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=Pp(l).toVar(),d=Pp(u).toVar(),p=Pp(h).toVar(),m=kp(a).toVar(),g=kp(o).toVar(),f=kp(n).toVar(),y=kp(r).toVar(),x=kp(i).toVar(),b=kp(s).toVar(),v=kp(e).toVar(),T=kp(t).toVar(),_=Pp(Xm(1,p)).toVar(),w=Pp(Xm(1,d)).toVar();return Pp(Xm(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),hE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Up(t).toVar(),o=Up(n.bitAnd(Up(7))).toVar(),a=Pp(sE(o.lessThan(Up(4)),r,i)).toVar(),h=Pp(Ym(2,sE(o.lessThan(Up(4)),i,r))).toVar();return iE(a,Op(o.bitAnd(Up(1)))).add(iE(h,Op(o.bitAnd(Up(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),uE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Pp(e).toVar(),a=Up(t).toVar(),h=Up(a.bitAnd(Up(15))).toVar(),u=Pp(sE(h.lessThan(Up(8)),o,n)).toVar(),l=Pp(sE(h.lessThan(Up(4)),n,sE(h.equal(Up(12)).or(h.equal(Up(14))),o,r))).toVar();return iE(u,Op(h.bitAnd(Up(1)))).add(iE(l,Op(h.bitAnd(Up(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),lE=NM([hE,uE]),cE=Ap((([t,e,s])=>{const i=Pp(s).toVar(),r=Pp(e).toVar(),n=Wp(t).toVar();return kp(lE(n.x,r,i),lE(n.y,r,i),lE(n.z,r,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),dE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Pp(e).toVar(),a=Wp(t).toVar();return kp(lE(a.x,o,n,r),lE(a.y,o,n,r),lE(a.z,o,n,r))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),pE=NM([cE,dE]),mE=Ap((([t])=>{const e=Pp(t).toVar();return Ym(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),gE=Ap((([t])=>{const e=Pp(t).toVar();return Ym(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),fE=NM([mE,Ap((([t])=>{const e=kp(t).toVar();return Ym(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),yE=NM([gE,Ap((([t])=>{const e=kp(t).toVar();return Ym(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),xE=Ap((([t,e])=>{const s=Fp(e).toVar(),i=Up(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(Fp(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),bE=Ap((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(xE(s,Fp(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(xE(t,Fp(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(xE(e,Fp(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(xE(s,Fp(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(xE(t,Fp(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(xE(e,Fp(4))),e.addAssign(t)})),vE=Ap((([t,e,s])=>{const i=Up(s).toVar(),r=Up(e).toVar(),n=Up(t).toVar();return i.bitXorAssign(r),i.subAssign(xE(r,Fp(14))),n.bitXorAssign(i),n.subAssign(xE(i,Fp(11))),r.bitXorAssign(n),r.subAssign(xE(n,Fp(25))),i.bitXorAssign(r),i.subAssign(xE(r,Fp(16))),n.bitXorAssign(i),n.subAssign(xE(i,Fp(4))),r.bitXorAssign(n),r.subAssign(xE(n,Fp(14))),i.bitXorAssign(r),i.subAssign(xE(r,Fp(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),TE=Ap((([t])=>{const e=Up(t).toVar();return Pp(e).div(Pp(Up(Fp(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),_E=Ap((([t])=>{const e=Pp(t).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),wE=NM([Ap((([t])=>{const e=Fp(t).toVar(),s=Up(Up(1)).toVar(),i=Up(Up(Fp(3735928559)).add(s.shiftLeft(Up(2))).add(Up(13))).toVar();return vE(i.add(Up(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Ap((([t,e])=>{const s=Fp(e).toVar(),i=Fp(t).toVar(),r=Up(Up(2)).toVar(),n=Up().toVar(),o=Up().toVar(),a=Up().toVar();return n.assign(o.assign(a.assign(Up(Fp(3735928559)).add(r.shiftLeft(Up(2))).add(Up(13))))),n.addAssign(Up(i)),o.addAssign(Up(s)),vE(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Fp(e).toVar(),n=Fp(t).toVar(),o=Up(Up(3)).toVar(),a=Up().toVar(),h=Up().toVar(),u=Up().toVar();return a.assign(h.assign(u.assign(Up(Fp(3735928559)).add(o.shiftLeft(Up(2))).add(Up(13))))),a.addAssign(Up(n)),h.addAssign(Up(r)),u.addAssign(Up(i)),vE(a,h,u)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Ap((([t,e,s,i])=>{const r=Fp(i).toVar(),n=Fp(s).toVar(),o=Fp(e).toVar(),a=Fp(t).toVar(),h=Up(Up(4)).toVar(),u=Up().toVar(),l=Up().toVar(),c=Up().toVar();return u.assign(l.assign(c.assign(Up(Fp(3735928559)).add(h.shiftLeft(Up(2))).add(Up(13))))),u.addAssign(Up(a)),l.addAssign(Up(o)),c.addAssign(Up(n)),bE(u,l,c),u.addAssign(Up(r)),vE(u,l,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),Ap((([t,e,s,i,r])=>{const n=Fp(r).toVar(),o=Fp(i).toVar(),a=Fp(s).toVar(),h=Fp(e).toVar(),u=Fp(t).toVar(),l=Up(Up(5)).toVar(),c=Up().toVar(),d=Up().toVar(),p=Up().toVar();return c.assign(d.assign(p.assign(Up(Fp(3735928559)).add(l.shiftLeft(Up(2))).add(Up(13))))),c.addAssign(Up(u)),d.addAssign(Up(h)),p.addAssign(Up(a)),bE(c,d,p),c.addAssign(Up(o)),d.addAssign(Up(n)),vE(c,d,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),SE=NM([Ap((([t,e])=>{const s=Fp(e).toVar(),i=Fp(t).toVar(),r=Up(wE(i,s)).toVar(),n=Wp().toVar();return n.x.assign(r.bitAnd(Fp(255))),n.y.assign(r.shiftRight(Fp(8)).bitAnd(Fp(255))),n.z.assign(r.shiftRight(Fp(16)).bitAnd(Fp(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Fp(e).toVar(),n=Fp(t).toVar(),o=Up(wE(n,r,i)).toVar(),a=Wp().toVar();return a.x.assign(o.bitAnd(Fp(255))),a.y.assign(o.shiftRight(Fp(8)).bitAnd(Fp(255))),a.z.assign(o.shiftRight(Fp(16)).bitAnd(Fp(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),ME=NM([Ap((([t])=>{const e=zp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Pp(nE(e.x,s)).toVar(),n=Pp(nE(e.y,i)).toVar(),o=Pp(_E(r)).toVar(),a=Pp(_E(n)).toVar(),h=Pp(oE(lE(wE(s,i),r,n),lE(wE(s.add(Fp(1)),i),r.sub(1),n),lE(wE(s,i.add(Fp(1))),r,n.sub(1)),lE(wE(s.add(Fp(1)),i.add(Fp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return fE(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Fp().toVar(),n=Pp(nE(e.x,s)).toVar(),o=Pp(nE(e.y,i)).toVar(),a=Pp(nE(e.z,r)).toVar(),h=Pp(_E(n)).toVar(),u=Pp(_E(o)).toVar(),l=Pp(_E(a)).toVar(),c=Pp(aE(lE(wE(s,i,r),n,o,a),lE(wE(s.add(Fp(1)),i,r),n.sub(1),o,a),lE(wE(s,i.add(Fp(1)),r),n,o.sub(1),a),lE(wE(s.add(Fp(1)),i.add(Fp(1)),r),n.sub(1),o.sub(1),a),lE(wE(s,i,r.add(Fp(1))),n,o,a.sub(1)),lE(wE(s.add(Fp(1)),i,r.add(Fp(1))),n.sub(1),o,a.sub(1)),lE(wE(s,i.add(Fp(1)),r.add(Fp(1))),n,o.sub(1),a.sub(1)),lE(wE(s.add(Fp(1)),i.add(Fp(1)),r.add(Fp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return yE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),AE=NM([Ap((([t])=>{const e=zp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Pp(nE(e.x,s)).toVar(),n=Pp(nE(e.y,i)).toVar(),o=Pp(_E(r)).toVar(),a=Pp(_E(n)).toVar(),h=kp(oE(pE(SE(s,i),r,n),pE(SE(s.add(Fp(1)),i),r.sub(1),n),pE(SE(s,i.add(Fp(1))),r,n.sub(1)),pE(SE(s.add(Fp(1)),i.add(Fp(1))),r.sub(1),n.sub(1)),o,a)).toVar();return fE(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp().toVar(),i=Fp().toVar(),r=Fp().toVar(),n=Pp(nE(e.x,s)).toVar(),o=Pp(nE(e.y,i)).toVar(),a=Pp(nE(e.z,r)).toVar(),h=Pp(_E(n)).toVar(),u=Pp(_E(o)).toVar(),l=Pp(_E(a)).toVar(),c=kp(aE(pE(SE(s,i,r),n,o,a),pE(SE(s.add(Fp(1)),i,r),n.sub(1),o,a),pE(SE(s,i.add(Fp(1)),r),n,o.sub(1),a),pE(SE(s.add(Fp(1)),i.add(Fp(1)),r),n.sub(1),o.sub(1),a),pE(SE(s,i,r.add(Fp(1))),n,o,a.sub(1)),pE(SE(s.add(Fp(1)),i,r.add(Fp(1))),n.sub(1),o,a.sub(1)),pE(SE(s,i.add(Fp(1)),r.add(Fp(1))),n,o.sub(1),a.sub(1)),pE(SE(s.add(Fp(1)),i.add(Fp(1)),r.add(Fp(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return yE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),NE=NM([Ap((([t])=>{const e=Pp(t).toVar(),s=Fp(rE(e)).toVar();return TE(wE(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Ap((([t])=>{const e=zp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar();return TE(wE(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar();return TE(wE(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Ap((([t])=>{const e=Hp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar(),n=Fp(rE(e.w)).toVar();return TE(wE(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),CE=NM([Ap((([t])=>{const e=Pp(t).toVar(),s=Fp(rE(e)).toVar();return kp(TE(wE(s,Fp(0))),TE(wE(s,Fp(1))),TE(wE(s,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Ap((([t])=>{const e=zp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar();return kp(TE(wE(s,i,Fp(0))),TE(wE(s,i,Fp(1))),TE(wE(s,i,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Ap((([t])=>{const e=kp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar();return kp(TE(wE(s,i,r,Fp(0))),TE(wE(s,i,r,Fp(1))),TE(wE(s,i,r,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Ap((([t])=>{const e=Hp(t).toVar(),s=Fp(rE(e.x)).toVar(),i=Fp(rE(e.y)).toVar(),r=Fp(rE(e.z)).toVar(),n=Fp(rE(e.w)).toVar();return kp(TE(wE(s,i,r,n,Fp(0))),TE(wE(s,i,r,n,Fp(1))),TE(wE(s,i,r,n,Fp(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),RE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=Pp(0).toVar(),u=Pp(1).toVar();return fv(o,(()=>{h.addAssign(u.mul(ME(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),EE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=kp(0).toVar(),u=Pp(1).toVar();return fv(o,(()=>{h.addAssign(u.mul(AE(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),BE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar();return zp(RE(a,o,n,r),RE(a.add(kp(Fp(19),Fp(193),Fp(17))),o,n,r))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),IE=Ap((([t,e,s,i])=>{const r=Pp(i).toVar(),n=Pp(s).toVar(),o=Fp(e).toVar(),a=kp(t).toVar(),h=kp(EE(a,o,n,r)).toVar(),u=Pp(RE(a.add(kp(Fp(19),Fp(193),Fp(17))),o,n,r)).toVar();return Hp(h,u)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),PE=Ap((([t,e,s,i,r,n,o])=>{const a=Fp(o).toVar(),h=Pp(n).toVar(),u=Fp(r).toVar(),l=Fp(i).toVar(),c=Fp(s).toVar(),d=Fp(e).toVar(),p=zp(t).toVar(),m=kp(CE(zp(d.add(l),c.add(u)))).toVar(),g=zp(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=zp(zp(Pp(d),Pp(c)).add(g)).toVar(),y=zp(f.sub(p)).toVar();return Ep(a.equal(Fp(2)),(()=>kg(y.x).add(kg(y.y)))),Ep(a.equal(Fp(3)),(()=>sf(kg(y.x),kg(y.y)))),uf(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),FE=NM([PE,Ap((([t,e,s,i,r,n,o,a,h])=>{const u=Fp(h).toVar(),l=Pp(a).toVar(),c=Fp(o).toVar(),d=Fp(n).toVar(),p=Fp(r).toVar(),m=Fp(i).toVar(),g=Fp(s).toVar(),f=Fp(e).toVar(),y=kp(t).toVar(),x=kp(CE(kp(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=kp(kp(Pp(f),Pp(g),Pp(m)).add(x)).toVar(),v=kp(b.sub(y)).toVar();return Ep(u.equal(Fp(2)),(()=>kg(v.x).add(kg(v.y)).add(kg(v.z)))),Ep(u.equal(Fp(3)),(()=>sf(sf(kg(v.x),kg(v.y)),kg(v.z)))),uf(v,v)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),UE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=Pp(1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();u.assign(ef(u,s))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),OE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=zp(1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();Ep(s.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(s)})).ElseIf(s.lessThan(u.y),(()=>{u.y.assign(s)}))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),zE=Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=zp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=zp(nE(n.x,o),nE(n.y,a)).toVar(),u=kp(1e6,1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{const s=Pp(FE(h,t,e,o,a,r,i)).toVar();Ep(s.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(s)})).ElseIf(s.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(s)})).ElseIf(s.lessThan(u.z),(()=>{u.z.assign(s)}))}))})),Ep(i.equal(Fp(0)),(()=>{u.assign(Rg(u))})),u})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),LE=NM([UE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=Pp(1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();l.assign(ef(l,n))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),VE=NM([OE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=zp(1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();Ep(n.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(n)})).ElseIf(n.lessThan(l.y),(()=>{l.y.assign(n)}))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),DE=NM([zE,Ap((([t,e,s])=>{const i=Fp(s).toVar(),r=Pp(e).toVar(),n=kp(t).toVar(),o=Fp().toVar(),a=Fp().toVar(),h=Fp().toVar(),u=kp(nE(n.x,o),nE(n.y,a),nE(n.z,h)).toVar(),l=kp(1e6,1e6,1e6).toVar();return fv({start:-1,end:Fp(1),name:"x",condition:"<="},(({x:t})=>{fv({start:-1,end:Fp(1),name:"y",condition:"<="},(({y:e})=>{fv({start:-1,end:Fp(1),name:"z",condition:"<="},(({z:s})=>{const n=Pp(FE(u,t,e,s,o,a,h,r,i)).toVar();Ep(n.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(n)})).ElseIf(n.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(n)})).ElseIf(n.lessThan(l.z),(()=>{l.z.assign(n)}))}))}))})),Ep(i.equal(Fp(0)),(()=>{l.assign(Rg(l))})),l})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),kE=Ap((([t])=>{const e=t.y,s=t.z,i=kp().toVar();return Ep(e.lessThan(1e-4),(()=>{i.assign(kp(s,s,s))})).Else((()=>{let r=t.x;r=r.sub(Bg(r)).mul(6).toVar();const n=Fp(Zg(r)),o=r.sub(Pp(n)),a=s.mul(e.oneMinus()),h=s.mul(e.mul(o).oneMinus()),u=s.mul(e.mul(o.oneMinus()).oneMinus());Ep(n.equal(Fp(0)),(()=>{i.assign(kp(s,u,a))})).ElseIf(n.equal(Fp(1)),(()=>{i.assign(kp(h,s,a))})).ElseIf(n.equal(Fp(2)),(()=>{i.assign(kp(a,s,u))})).ElseIf(n.equal(Fp(3)),(()=>{i.assign(kp(a,h,s))})).ElseIf(n.equal(Fp(4)),(()=>{i.assign(kp(u,a,s))})).Else((()=>{i.assign(kp(s,a,h))}))})),i})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),GE=Ap((([t])=>{const e=kp(t).toVar(),s=Pp(e.x).toVar(),i=Pp(e.y).toVar(),r=Pp(e.z).toVar(),n=Pp(ef(s,ef(i,r))).toVar(),o=Pp(sf(s,sf(i,r))).toVar(),a=Pp(o.sub(n)).toVar(),h=Pp().toVar(),u=Pp().toVar(),l=Pp().toVar();return l.assign(o),Ep(o.greaterThan(0),(()=>{u.assign(a.div(o))})).Else((()=>{u.assign(0)})),Ep(u.lessThanEqual(0),(()=>{h.assign(0)})).Else((()=>{Ep(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).ElseIf(i.greaterThanEqual(o),(()=>{h.assign(qm(2,r.sub(s).div(a)))})).Else((()=>{h.assign(qm(4,s.sub(i).div(a)))})),h.mulAssign(1/6),Ep(h.lessThan(0),(()=>{h.addAssign(1)}))})),kp(h,u,l)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),WE=Ap((([t])=>{const e=kp(t).toVar(),s=jp(eg(e,kp(.04045))).toVar(),i=kp(e.div(12.92)).toVar(),r=kp(cf(sf(e.add(kp(.055)),kp(0)).div(1.055),kp(2.4))).toVar();return xf(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),jE=(t,e)=>{t=Pp(t),e=Pp(e);const s=zp(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return _f(t.sub(s),t.add(s),e)},HE=(t,e,s,i)=>xf(t,e,s[i].clamp()),$E=(t,e,s=wy())=>HE(t,e,s,"x"),qE=(t,e,s=wy())=>HE(t,e,s,"y"),XE=(t,e,s,i,r)=>xf(t,e,jE(s,i[r])),YE=(t,e,s,i=wy())=>XE(t,e,s,i,"x"),ZE=(t,e,s,i=wy())=>XE(t,e,s,i,"y"),JE=(t=1,e=0,s=wy())=>s.mul(t).add(e),KE=(t,e=1)=>(t=Pp(t)).abs().pow(e).mul(t.sign()),QE=(t,e=1,s=.5)=>Pp(t).sub(s).mul(e).add(s),tB=(t=wy(),e=1,s=0)=>ME(t.convert("vec2|vec3")).mul(e).add(s),eB=(t=wy(),e=1,s=0)=>AE(t.convert("vec2|vec3")).mul(e).add(s),sB=(t=wy(),e=1,s=0)=>{t=t.convert("vec2|vec3");return Hp(AE(t),ME(t.add(zp(19,73)))).mul(e).add(s)},iB=(t=wy(),e=1)=>LE(t.convert("vec2|vec3"),e,Fp(1)),rB=(t=wy(),e=1)=>VE(t.convert("vec2|vec3"),e,Fp(1)),nB=(t=wy(),e=1)=>DE(t.convert("vec2|vec3"),e,Fp(1)),oB=(t=wy())=>NE(t.convert("vec2|vec3")),aB=(t=wy(),e=3,s=2,i=.5,r=1)=>RE(t,Fp(e),s,i).mul(r),hB=(t=wy(),e=3,s=2,i=.5,r=1)=>BE(t,Fp(e),s,i).mul(r),uB=(t=wy(),e=3,s=2,i=.5,r=1)=>EE(t,Fp(e),s,i).mul(r),lB=(t=wy(),e=3,s=2,i=.5,r=1)=>IE(t,Fp(e),s,i).mul(r),cB=Ap((([t,e])=>{const s=t.x,i=t.y,r=t.z;let n=e.element(0).mul(.886227);return n=n.add(e.element(1).mul(1.023328).mul(i)),n=n.add(e.element(2).mul(1.023328).mul(r)),n=n.add(e.element(3).mul(1.023328).mul(s)),n=n.add(e.element(4).mul(.858086).mul(s).mul(i)),n=n.add(e.element(5).mul(.858086).mul(i).mul(r)),n=n.add(e.element(6).mul(r.mul(r).mul(.743125).sub(.247708))),n=n.add(e.element(7).mul(.858086).mul(s).mul(r)),n=n.add(e.element(8).mul(.429043).mul(Ym(s,s).sub(Ym(i,i)))),n}));class dB extends NC{static get type(){return"PointLightNode"}constructor(t=null){super(t),this.cutoffDistanceNode=lm(0).setGroup(am),this.decayExponentNode=lm(0).setGroup(am)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(t){const{colorNode:e,cutoffDistanceNode:s,decayExponentNode:i,light:r}=this,n=t.context.lightingModel,o=PC(r).sub(hx),a=o.normalize(),h=o.length(),u=CC({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=e.mul(u),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c},t.stack,t)}}class pB extends NC{static get type(){return"DirectionalLightNode"}constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=FC(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r},t.stack,t)}}const mB=new sr,gB=new sr;let fB=null;class yB extends NC{static get type(){return"RectAreaLightNode"}constructor(t=null){super(t),this.halfHeight=lm(new Ai).setGroup(am),this.halfWidth=lm(new Ai).setGroup(am)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;gB.identity(),mB.copy(e.matrixWorld),mB.premultiply(s),gB.extractRotation(mB),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(gB),this.halfHeight.value.applyMatrix4(gB)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=Ry(fB.LTC_FLOAT_1),s=Ry(fB.LTC_FLOAT_2)):(e=Ry(fB.LTC_HALF_1),s=Ry(fB.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=PC(r),a=t.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:e,ltc_2:s},t.stack,t)}static setLTC(t){fB=t}}class xB extends NC{static get type(){return"SpotLightNode"}constructor(t=null){super(t),this.coneCosNode=lm(0).setGroup(am),this.penumbraCosNode=lm(0).setGroup(am),this.cutoffDistanceNode=lm(0).setGroup(am),this.decayExponentNode=lm(0).setGroup(am)}update(t){super.update(t);const{light:e}=this;this.coneCosNode.value=Math.cos(e.angle),this.penumbraCosNode.value=Math.cos(e.angle*(1-e.penumbra)),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}getSpotAttenuation(t){const{coneCosNode:e,penumbraCosNode:s}=this;return _f(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=PC(n).sub(hx),a=o.normalize(),h=a.dot(FC(n)),u=this.getSpotAttenuation(h),l=o.length(),c=CC({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p},t.stack,t)}}class bB extends xB{static get type(){return"IESSpotLightNode"}getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=Ry(e,zp(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}class vB extends NC{static get type(){return"AmbientLightNode"}constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}class TB extends NC{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=BC(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=lm(new Xr).setGroup(am)}update(t){const{light:e}=this;super.update(t),this.lightPositionNode.object3d=e,this.groundColorNode.value.copy(e.groundColor).multiplyScalar(e.intensity)}setup(t){const{colorNode:e,groundColorNode:s,lightDirectionNode:i}=this,r=fx.dot(i).mul(.5).add(.5),n=xf(s,e,r);t.context.irradiance.addAssign(n)}}class _B extends NC{static get type(){return"LightProbeNode"}constructor(t=null){super(t);const e=[];for(let t=0;t<9;t++)e.push(new Ai);this.lightProbe=Fx(e)}update(t){const{light:e}=this;super.update(t);for(let t=0;t<9;t++)this.lightProbe.array[t].copy(e.sh.coefficients[t]).multiplyScalar(e.intensity)}setup(t){const e=cB(yx,this.lightProbe);t.context.irradiance.addAssign(e)}}class wB{parseFunction(){console.warn("Abstract function.")}}class SB{constructor(t,e,s="",i=""){this.type=t,this.inputs=e,this.name=s,this.precision=i}getCode(){console.warn("Abstract function.")}}SB.isNodeFunction=!0;const MB=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,AB=/[a-z_0-9]+/gi,NB="#pragma main";class CB extends SB{constructor(t){const{type:e,inputs:s,name:i,precision:r,inputsCode:n,blockCode:o,headerCode:a}=(t=>{const e=(t=t.trim()).indexOf(NB),s=-1!==e?t.slice(e+12):t,i=s.match(MB);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=AB.exec(r));)n.push(o);const a=[];let h=0;for(;h<n.length;){const t="const"===n[h][0];!0===t&&h++;let e=n[h][0];"in"===e||"out"===e||"inout"===e?h++:e="";const s=n[h++][0];let i=Number.parseInt(n[h][0]);!1===Number.isNaN(i)?h++:i=null;const r=n[h++][0];a.push(new xM(s,r,i,e,t))}const u=s.substring(i[0].length),l=void 0!==i[3]?i[3]:"";return{type:i[2],inputs:a,name:l,precision:void 0!==i[1]?i[1]:"",inputsCode:r,blockCode:u,headerCode:-1!==e?t.slice(0,e):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(t);super(e,s,i,r),this.inputsCode=n,this.blockCode=o,this.headerCode=a}getCode(t=this.name){let e;const s=this.blockCode;if(""!==s){const{type:i,inputsCode:r,headerCode:n,precision:o}=this;let a=`${i} ${t} ( ${r.trim()} )`;""!==o&&(a=`${o} ${a}`),e=n+a+s}else e="";return e}}class RB extends wB{parseFunction(t){return new CB(t)}}function EB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function BB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}class IB{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new Nv([]),this.lightsArray=[],this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(t,e,s,i,r,n){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:t.id,object:t,geometry:e,material:s,groupOrder:i,renderOrder:t.renderOrder,z:r,group:n},this.renderItems[this.renderItemsIndex]=o):(o.id=t.id,o.object=t,o.geometry=e,o.material=s,o.groupOrder=i,o.renderOrder=t.renderOrder,o.z=r,o.group=n),this.renderItemsIndex++,o}push(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);!0===t.occlusionTest&&this.occlusionQueryCount++,(!0===s.transparent||s.transmission>0?this.transparent:this.opaque).push(o)}unshift(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||EB),this.transparent.length>1&&this.transparent.sort(e||BB)}finish(){this.lightsNode.setLights(this.lightsArray);for(let t=this.renderItemsIndex,e=this.renderItems.length;t<e;t++){const e=this.renderItems[t];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.groupOrder=null,e.renderOrder=null,e.z=null,e.group=null}}}class PB{constructor(){this.lists=new Vw}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new IB,s.set(i,r)),r}dispose(){this.lists=new Vw}}let FB=0;class UB{constructor(){this.id=FB++,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 xi,this.scissor=!1,this.scissorValue=new xi,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}getCacheKey(){return OB(this)}}function OB(t){const{textures:e,activeCubeFace:s}=t,i=[s];for(const t of e)i.push(t.id);return xd(i)}class zB{constructor(){this.chainMaps={}}get(t,e,s=null){const i=[t,e];let r;if(null===s)r="default";else{const t=s.texture.format;r=`${s.textures.length}:${t}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this.getChainMap(r);let o=n.get(i);return void 0===o&&(o=new UB,n.set(i,o)),null!==s&&(o.sampleCount=0===s.samples?1:s.samples),o}getChainMap(t){return this.chainMaps[t]||(this.chainMaps[t]=new Vw)}dispose(){this.chainMaps={}}}const LB=new Ai;class VB extends $w{constructor(t,e,s){super(),this.renderer=t,this.backend=e,this.info=s}updateRenderTarget(t,e=0){const s=this.get(t),i=0===t.samples?1:t.samples,r=s.depthTextureMips||(s.depthTextureMips={}),n=t.textures,o=this.getSize(n[0]),a=o.width>>e,h=o.height>>e;let u=t.depthTexture||r[e];const l=!0===t.depthBuffer||!0===t.stencilBuffer;let c=!1;void 0===u&&l&&(u=new $a,u.format=t.stencilBuffer?jt:Wt,u.type=t.stencilBuffer?Ot:Bt,u.image.width=a,u.image.height=h,r[e]=u),s.width===o.width&&o.height===s.height||(c=!0,u&&(u.needsUpdate=!0,u.image.width=a,u.image.height=h)),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=u||null,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,u&&(u.needsUpdate=!0),s.sampleCount=i);const d={sampleCount:i};for(let t=0;t<n.length;t++){const e=n[t];c&&(e.needsUpdate=!0),this.updateTexture(e,d)}if(u&&this.updateTexture(u,d),!0!==s.initialized){s.initialized=!0;const e=()=>{t.removeEventListener("dispose",e);for(let t=0;t<n.length;t++)this._destroyTexture(n[t]);u&&this._destroyTexture(u),this.delete(t)};t.addEventListener("dispose",e)}}updateTexture(t,e={}){const s=this.get(t);if(!0===s.initialized&&s.version===t.version)return;const i=t.isRenderTargetTexture||t.isDepthTexture||t.isFramebufferTexture,r=this.backend;if(i&&!0===s.initialized&&(r.destroySampler(t),r.destroyTexture(t)),t.isFramebufferTexture){const e=this.renderer.getRenderTarget();t.type=e?e.texture.type:At}const{width:n,height:o,depth:a}=this.getSize(t);if(e.width=n,e.height=o,e.depth=a,e.needsMipmaps=this.needsMipmaps(t),e.levels=e.needsMipmaps?this.getMipLevels(t,n,o):1,i||!0===t.isStorageTexture)r.createSampler(t),r.createTexture(t,e),s.generation=t.version;else{if(!0!==s.initialized&&r.createSampler(t),t.version>0){const i=t.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(t.images){const s=[];for(const e of t.images)s.push(e);e.images=s}else e.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(t,e),s.isDefaultTexture=!1,s.generation=t.version),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0,s.generation=t.version}if(!0!==s.initialized){s.initialized=!0,s.generation=t.version,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}s.version=t.version}getSize(t,e=LB){let s=t.images?t.images[0]:t.image;return s?(void 0!==s.image&&(s=s.image),e.width=s.width,e.height=s.height,e.depth=t.isCubeTexture?6:s.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,s){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,s)))+1,i}needsMipmaps(t){return!!this.isEnvironmentTexture(t)||(!0===t.isCompressedTexture||t.minFilter!==ft&&t.minFilter!==Tt)}isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class DB extends Xr{constructor(t,e,s,i=1){super(t,e,s),this.a=i}set(t,e,s,i=1){return this.a=i,super.set(t,e,s)}copy(t){return void 0!==t.a&&(this.a=t.a),super.copy(t)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const kB=new DB;class GB extends $w{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,s){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let n=!1;if(null===r)i._clearColor.getRGB(kB,Je),kB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(kB,Je),kB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;kB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=Bf(Hp(n).mul(cA),{getUV:()=>yx,getTextureLevel:()=>lA});let e=Qb();e=e.setZ(e.w);const i=new cT;i.name="Background.material",i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new On(new uu(1,32,32),i),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Hp(n).mul(cA),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),e.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){const t=s.clearColorValue;t.r=kB.r,t.g=kB.g,t.b=kB.b,t.a=kB.a,!0!==i.backend.isWebGLBackend&&!0!==i.alpha||(t.r*=t.a,t.g*=t.a,t.b*=t.a),s.depthClearValue=i._clearDepth,s.stencilClearValue=i._clearStencil,s.clearColor=!0===i.autoClearColor,s.clearDepth=!0===i.autoClearDepth,s.clearStencil=!0===i.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}class WB{constructor(t,e,s,i,r,n,o,a,h,u=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==e.bindings[0].groupNode.shared){const s=new cM(e.name,[],e.index,e);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}const jB=new WeakMap;class HB extends $w{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new yM,this.nodeBuilderCache=new Map,this.callHashCache=new Vw,this.groupsData=new Vw}updateGroup(t){const e=t.groupNode,s=e.name;if(s===hm.name)return!0;if(s===am.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===om.name){const e=this.get(t),s=this.nodeFrame.frameId;return e.frameId!==s&&(e.frameId=s,!0)}const i=[e,t];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==e.version&&(r.version=e.version,!0)}getForRenderCacheKey(t){return t.initialCacheKey}getForRender(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(s=i.get(r),void 0===s){const e=this.backend.createNodeBuilder(t.object,this.renderer);e.scene=t.scene,e.material=t.material,e.camera=t.camera,e.context.material=t.material,e.lightsNode=t.lightsNode,e.environmentNode=this.getEnvironmentNode(t.scene),e.fogNode=this.getFogNode(t.scene),e.clippingContext=t.clippingContext,e.build(),s=this._createNodeBuilderState(e),i.set(r,s)}s.usedTimes++,e.nodeBuilderState=s}return s}delete(t){if(t.isRenderObject){const e=this.get(t).nodeBuilderState;e.usedTimes--,0===e.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(t))}return super.delete(t)}getForCompute(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),s=this._createNodeBuilderState(i),e.nodeBuilderState=s}return s}_createNodeBuilderState(t){return new WB(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.monitor,t.transforms)}getEnvironmentNode(t){return t.environmentNode||this.get(t).environmentNode||null}getBackgroundNode(t){return t.backgroundNode||this.get(t).backgroundNode||null}getFogNode(t){return t.fogNode||this.get(t).fogNode||null}getCacheKey(t,e){const s=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(t),o=this.getFogNode(t),a=[];e&&a.push(e.getCacheKey(!0)),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),a.push(this.renderer.shadowMap.enabled?1:0),r={callId:i,cacheKey:xd(a)},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(t){this.updateEnvironment(t),this.updateFog(t),this.updateBackground(t)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(t){const e=this.get(t),s=t.background;if(s){const i=0===t.backgroundBlurriness&&e.backgroundBlurriness>0||t.backgroundBlurriness>0&&0===e.backgroundBlurriness;if(e.background!==s||i){let i=null;if(!0===s.isCubeTexture||s.mapping===lt||s.mapping===ct||s.mapping===dt)if(t.backgroundBlurriness>0||s.mapping===dt)i=ow(s,yx);else{let t;t=!0===s.isCubeTexture?Rx(s):Ry(s),i=BT(t)}else!0===s.isTexture?i=Ry(s,zv.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);e.backgroundNode=i,e.background=s,e.backgroundBlurriness=t.backgroundBlurriness}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),s=t.fog;if(s){if(e.fog!==s){let t=null;if(s.isFogExp2){const e=Lx("color","color",s).setGroup(am),i=Lx("density","float",s).setGroup(am);t=pC(e,i)}else if(s.isFog){const e=Lx("color","color",s).setGroup(am),i=Lx("near","float",s).setGroup(am),r=Lx("far","float",s).setGroup(am);t=cC(e,i,r)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);e.fogNode=t,e.fog=s}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),s=t.environment;if(s){if(e.environment!==s){let t=null;!0===s.isCubeTexture?t=Rx(s):!0===s.isTexture?t=Ry(s):console.error("Nodes: Unsupported environment configuration.",s),e.environmentNode=t,e.environment=s}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=t,n.scene=e,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(t){return this.getNodeFrame(t.renderer,t.scene,t.object,t.camera,t.material)}getOutputCacheKey(){const t=this.renderer;return t.toneMapping+","+t.currentColorSpace}hasOutputChange(t){return jB.get(t)!==this.getOutputCacheKey()}getOutputNode(t){const e=this.renderer,s=this.getOutputCacheKey(),i=Ry(t,zv).renderOutput(e.toneMapping,e.currentColorSpace);return jB.set(t,s),i}updateBefore(t){const e=t.getNodeBuilderState();for(const s of e.updateBeforeNodes)this.getNodeFrameForRender(t).updateBeforeNode(s)}updateAfter(t){const e=t.getNodeBuilderState();for(const s of e.updateAfterNodes)this.getNodeFrameForRender(t).updateAfterNode(s)}updateForCompute(t){const e=this.getNodeFrame(),s=this.getForCompute(t);for(const t of s.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateNodes)e.updateNode(t)}needsRefresh(t){const e=this.getNodeFrameForRender(t);return t.getMonitor().needsRefresh(t,e)}dispose(){super.dispose(),this.nodeFrame=new yM,this.nodeBuilderCache=new Map}}class $B{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class qB{constructor(){this.lists=new Vw}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new $B(t,e),s.set(i,r)),r}dispose(){this.lists=new Vw}}class XB{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map,this.colorSpaceNodes=new Map}fromMaterial(t){if(t.isNodeMaterial)return t;let e=null;const s=this.getMaterialNodeClass(t.type);if(null!==s){e=new s;for(const s in t)e[s]=t[s]}return e}addColorSpace(t,e){this.addType(t,e,this.colorSpaceNodes)}getColorSpaceFunction(t){return this.colorSpaceNodes.get(t)||null}addToneMapping(t,e){this.addType(t,e,this.toneMappingNodes)}getToneMappingFunction(t){return this.toneMappingNodes.get(t)||null}getMaterialNodeClass(t){return this.materialNodes.get(t)||null}addMaterial(t,e){this.addType(t,e.type,this.materialNodes)}getLightNodeClass(t){return this.lightNodes.get(t)||null}addLight(t,e){this.addClass(t,e,this.lightNodes)}addType(t,e,s){if(s.has(e))console.warn(`Redefinition of node ${e}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"==typeof e||"object"==typeof e)throw new Error(`Base class ${e} is not a class.`);s.set(e,t)}}addClass(t,e,s){if(s.has(e))console.warn(`Redefinition of node ${e.name}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"!=typeof e)throw new Error(`Base class ${e.name} is not a class.`);s.set(e,t)}}}const YB=new Kn,ZB=new Ys,JB=new xi,KB=new Ko,QB=new sr,tI=new xi;class eI{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,depth:r=!0,stencil:n=!1,antialias:o=!1,samples:a=0,getFallback:h=null}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=a||!0===o?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Ze,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=n,this.clippingPlanes=[],this.info=new eS,this.nodes={library:new XB,modelViewMatrix:null,modelNormalViewMatrix:null},this._getFallback=h,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new xi(0,0,this._width,this._height),this._scissor=new xi(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new tA(new cT),this._quad.material.type="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const u=!0===this.alpha?0:1;this._clearColor=new DB(0,0,0,u),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:1},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null,getShaderAsync:async(t,e,s)=>{await this.compileAsync(t,e);const i=this._renderLists.get(t,e),r=this._renderContexts.get(t,e,this._renderTarget),n=t.overrideMaterial||s.material,o=this._objects.get(s,n,t,e,i.lightsNode,r),{fragmentShader:a,vertexShader:h}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:h}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(t,e)=>{let s=this.backend;try{await s.init(this)}catch(t){if(null===this._getFallback)return void e(t);try{this.backend=s=this._getFallback(t),await s.init(this)}catch(t){return void e(t)}}this._nodes=new HB(this,s),this._animation=new Lw(this._nodes,this.info),this._attributes=new Jw(s),this._background=new GB(this,this._nodes),this._geometries=new tS(this._attributes,this.info),this._textures=new VB(this,s,this.info),this._pipelines=new aS(s,this._nodes),this._bindings=new hS(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Hw(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new PB,this._bundles=new qB,this._renderContexts=new zB,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,s=null){!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,h=!0===t.isScene?t:YB;null===s&&(s=t);const u=this._renderTarget,l=this._renderContexts.get(s,e,u),c=this._activeMipmapLevel,d=[];this._currentRenderContext=l,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),l.depth=this.depth,l.stencil=this.stencil,l.clippingContext||(l.clippingContext=new kw),l.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,u);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),s!==t&&s.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const t=this._textures.get(u);l.textures=t.textures,l.depthTexture=t.depthTexture}else l.textures=null,l.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,l);const m=p.opaque,g=p.transparent,f=p.lightsNode;!0===this.opaque&&m.length>0&&this._renderObjects(m,e,h,f),!0===this.transparent&&g.length>0&&this._renderObjects(g,e,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const s=this._renderScene(t,e);await this.backend.resolveTimestampAsync(s,"render")}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_renderBundle(t,e,s){const{bundleGroup:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this._bundles.get(i,r),h=this.backend.get(a);void 0===h.renderContexts&&(h.renderContexts=new Set);const u=i.version!==h.version,l=!1===h.renderContexts.has(o)||u;if(h.renderContexts.add(o),l){this.backend.beginBundle(o),(void 0===h.renderObjects||u)&&(h.renderObjects=[]),this._currentRenderBundle=a;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),h.version=i.version}else{const{renderObjects:t}=h;for(let e=0,s=t.length;e<s;e++){const s=t[e];this._nodes.needsRefresh(s)&&(this._nodes.updateBefore(s),this._nodes.updateForRender(s),this._bindings.updateForRender(s),this._nodes.updateAfter(s))}}this.backend.addBundle(o,a)}render(t,e){if(!1===this._initialized)return console.warn("THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead."),this.renderAsync(t,e);this._renderScene(t,e)}_getFrameBufferTarget(){const{currentToneMapping:t,currentColorSpace:e}=this;if(!1===(0!==t)&&!1===(e!==Je))return null;const{width:s,height:i}=this.getDrawingBufferSize(ZB),{depth:r,stencil:n}=this;let o=this._frameBufferTarget;return null===o&&(o=new bi(s,i,{depthBuffer:r,stencilBuffer:n,type:Pt,format:Dt,colorSpace:Je,generateMipmaps:!1,minFilter:Tt,magFilter:Tt,samples:this.samples}),o.isPostProcessingRenderTarget=!0,this._frameBufferTarget=o),o.depthBuffer=r,o.stencilBuffer=n,o.setSize(s,i),o.viewport.copy(this._viewport),o.scissor.copy(this._scissor),o.viewport.multiplyScalar(this._pixelRatio),o.scissor.multiplyScalar(this._pixelRatio),o.scissorTest=this._scissorTest,o}_renderScene(t,e,s=!0){const i=s?this._getFrameBufferTarget():null,r=this._nodes.nodeFrame,n=r.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,h=!0===t.isScene?t:YB,u=this._renderTarget,l=this._activeCubeFace,c=this._activeMipmapLevel;let d;null!==i?(d=i,this.setRenderTarget(d)):d=u;const p=this._renderContexts.get(t,e,d);this._currentRenderContext=p,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,r.renderId=this.info.calls;const m=this.coordinateSystem;e.coordinateSystem!==m&&(e.coordinateSystem=m,e.updateProjectionMatrix()),!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld();let g=this._viewport,f=this._scissor,y=this._pixelRatio;null!==d&&(g=d.viewport,f=d.scissor,y=1),this.getDrawingBufferSize(ZB),JB.set(0,0,ZB.width,ZB.height);const x=void 0===g.minDepth?0:g.minDepth,b=void 0===g.maxDepth?1:g.maxDepth;p.viewportValue.copy(g).multiplyScalar(y).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(JB),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(JB),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new kw),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),QB.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),KB.setFromProjectionMatrix(QB,m);const v=this._renderLists.get(t,e);if(v.begin(),this._projectObject(t,e,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const t=this._textures.get(d);p.textures=t.textures,p.depthTexture=t.depthTexture,p.width=t.width,p.height=t.height,p.renderTarget=d,p.depth=d.depthBuffer,p.stencil=d.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=l,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const{bundles:T,lightsNode:_,transparent:w,opaque:S}=v;if(T.length>0&&this._renderBundles(T,h,_),!0===this.opaque&&S.length>0&&this._renderObjects(S,e,h,_),!0===this.transparent&&w.length>0&&this._renderObjects(w,e,h,_),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const t=this._quad;this._nodes.hasOutputChange(d.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(d.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}return h.onAfterRender(this,t,e,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(t){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(t)}async getArrayBufferAsync(t){return await this.backend.getArrayBufferAsync(t)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(t){return t.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(t){return t.set(this._width,this._height)}setPixelRatio(t=1){this._pixelRatio=t,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(t,e,s){this._width=t,this._height=e,this._pixelRatio=s,this.domElement.width=Math.floor(t*s),this.domElement.height=Math.floor(e*s),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,s=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===s&&(this.domElement.style.width=t+"px",this.domElement.style.height=e+"px"),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setOpaqueSort(t){this._opaqueSort=t}setTransparentSort(t){this._transparentSort=t}getScissor(t){const e=this._scissor;return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t}setScissor(t,e,s,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,s,i,r=0,n=1){const o=this._viewport;t.isVector4?o.copy(t):o.set(t,e,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(t){return t.copy(this._clearColor)}setClearColor(t,e=1){this._clearColor.set(t),this._clearColor.a=e}getClearAlpha(){return this._clearColor.a}setClearAlpha(t){this._clearColor.a=t}getClearDepth(){return this._clearDepth}setClearDepth(t){this._clearDepth=t}getClearStencil(){return this._clearStencil}setClearStencil(t){this._clearStencil=t}isOccluded(t){const e=this._currentRenderContext;return e&&this.backend.isOccluded(e,t)}clear(t=!0,e=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(t,e,s);const i=this._renderTarget||this._getFrameBufferTarget();let r=null;if(null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget){const t=this._quad;this._nodes.hasOutputChange(i.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(i.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(t=!0,e=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(t,e,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?0:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Je:this.outputColorSpace}dispose(){this.info.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(t,e=0,s=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}compute(t){if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(t);const e=this._nodes.nodeFrame,s=e.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,e.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(t)?t:[t];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of a){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),n.delete(e),o.delete(e)};e.addEventListener("dispose",t);const s=e.onInitFunction;null!==s&&s.call(e,{renderer:this})}o.updateForCompute(e),n.updateForCompute(e);const s=n.getForCompute(e),a=r.getForCompute(e,s);i.compute(t,e,s,a)}i.finishCompute(t),e.renderId=s}async computeAsync(t){!1===this._initialized&&await this.init(),this.compute(t),await this.backend.resolveTimestampAsync(t,"compute")}async hasFeatureAsync(t){return!1===this._initialized&&await this.init(),this.backend.hasFeature(t)}hasFeature(t){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(t)}copyFramebufferToTexture(t,e=null){const s=this._currentRenderContext;this._textures.updateTexture(t),e=null===e?tI.set(0,0,t.image.width,t.image.height):e,this.backend.copyFramebufferToTexture(t,s,e)}copyTextureToTexture(t,e,s=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,s,i,r)}readRenderTargetPixelsAsync(t,e,s,i,r,n=0,o=0){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r,o)}_projectObject(t,e,s,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)s=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)i.pushLight(t);else if(t.isSprite){if(!t.frustumCulled||KB.intersectsSprite(t)){!0===this.sortObjects&&tI.setFromMatrixPosition(t.matrixWorld).applyMatrix4(QB);const{geometry:e,material:r}=t;r.visible&&i.push(t,e,r,s,tI.z,null)}}else if(t.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||KB.intersectsObject(t))){const{geometry:e,material:r}=t;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),tI.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(QB)),Array.isArray(r)){const n=e.groups;for(let o=0,a=n.length;o<a;o++){const a=n[o],h=r[a.materialIndex];h&&h.visible&&i.push(t,e,h,s,tI.z,a)}}else r.visible&&i.push(t,e,r,s,tI.z,null)}if(!0===t.isBundleGroup&&void 0!==this.backend.beginBundle){const s=i;(i=this._renderLists.get(t,e)).begin(),s.pushBundle({bundleGroup:t,camera:e,renderList:i}),i.finish()}const r=t.children;for(let t=0,n=r.length;t<n;t++)this._projectObject(r[t],e,s,i)}_renderBundles(t,e,s){for(const i of t)this._renderBundle(i,e,s)}_renderObjects(t,e,s,i){for(let r=0,n=t.length;r<n;r++){const n=t[r],{object:o,geometry:a,material:h,group:u}=n;if(e.isArrayCamera){const t=e.cameras;for(let e=0,r=t.length;e<r;e++){const r=t[e];if(o.layers.test(r.layers)){const t=r.viewport,e=void 0===t.minDepth?0:t.minDepth,n=void 0===t.maxDepth?1:t.maxDepth,l=this._currentRenderContext.viewportValue;l.copy(t).multiplyScalar(this._pixelRatio).floor(),l.minDepth=e,l.maxDepth=n,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(o,s,r,a,h,u,i)}}}else this._currentRenderObjectFunction(o,s,e,a,h,u,i)}}renderObject(t,e,s,i,r,n,o){let a,h,u;if(t.onBeforeRender(this,e,s,i,r,n),null!==e.overrideMaterial){const t=e.overrideMaterial;r.positionNode&&r.positionNode.isNode&&(a=t.positionNode,t.positionNode=r.positionNode),t.isShadowNodeMaterial&&(t.side=null===r.shadowSide?r.side:r.shadowSide,r.depthNode&&r.depthNode.isNode&&(u=t.depthNode,t.depthNode=r.depthNode),r.shadowNode&&r.shadowNode.isNode&&(h=t.fragmentNode,t.fragmentNode=r.shadowNode),this.localClippingEnabled&&(r.clipShadows?(t.clippingPlanes!==r.clippingPlanes&&(t.clippingPlanes=r.clippingPlanes,t.needsUpdate=!0),t.clipIntersection!==r.clipIntersection&&(t.clipIntersection=r.clipIntersection)):Array.isArray(t.clippingPlanes)&&(t.clippingPlanes=null,t.needsUpdate=!0))),r=t}!0===r.transparent&&2===r.side&&!1===r.forceSinglePass?(r.side=d,this._handleObjectFunction(t,r,e,s,o,n,"backSide"),r.side=c,this._handleObjectFunction(t,r,e,s,o,n),r.side=2):this._handleObjectFunction(t,r,e,s,o,n),void 0!==a&&(e.overrideMaterial.positionNode=a),void 0!==u&&(e.overrideMaterial.depthNode=u),void 0!==h&&(e.overrideMaterial.fragmentNode=h),t.onAfterRender(this,e,s,i,r,n)}_renderObjectDirect(t,e,s,i,r,n,o){const a=this._objects.get(t,e,s,i,r,this._currentRenderContext,o);a.drawRange=t.geometry.drawRange,a.group=n;const h=this._nodes.needsRefresh(a);if(h&&(this._nodes.updateBefore(a),this._geometries.updateForRender(a),this._nodes.updateForRender(a),this._bindings.updateForRender(a)),this._pipelines.updateForRender(a),null!==this._currentRenderBundle){this.backend.get(this._currentRenderBundle).renderObjects.push(a),a.bundle=this._currentRenderBundle.scene}this.backend.draw(a,this.info),h&&this._nodes.updateAfter(a)}_createObjectPipeline(t,e,s,i,r,n){const o=this._objects.get(t,e,s,i,r,this._currentRenderContext,n);this._nodes.updateBefore(o),this._geometries.updateForRender(o),this._nodes.updateForRender(o),this._bindings.updateForRender(o),this._pipelines.getForRender(o,this._compilationPromises),this._nodes.updateAfter(o)}get compile(){return this.compileAsync}}class sI{constructor(t=""){this.name=t,this.visibility=0}setVisibility(t){this.visibility|=t}clone(){return Object.assign(new this.constructor,this)}}class iI extends sI{constructor(t,e=null){super(t),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=e}get byteLength(){return(t=this._buffer.byteLength)+(Zw-t%Zw)%Zw;var t}get buffer(){return this._buffer}update(){return!0}}class rI extends iI{constructor(t,e=null){super(t,e),this.isUniformBuffer=!0}}let nI=0;class oI extends rI{constructor(t,e){super("UniformBuffer_"+nI++,t?t.value:null),this.nodeUniform=t,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class aI extends rI{constructor(t){super(t),this.isUniformsGroup=!0,this._values=null,this.uniforms=[]}addUniform(t){return this.uniforms.push(t),this}removeUniform(t){const e=this.uniforms.indexOf(t);return-1!==e&&this.uniforms.splice(e,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let t=this._buffer;if(null===t){const e=this.byteLength;t=new Float32Array(new ArrayBuffer(e)),this._buffer=t}return t}get byteLength(){let t=0;for(let e=0,s=this.uniforms.length;e<s;e++){const s=this.uniforms[e],{boundary:i,itemSize:r}=s,n=t%Zw;0!==n&&Zw-n-i<0?t+=Zw-n:n%i!=0&&(t+=n%i),s.offset=t/this.bytesPerElement,t+=r*this.bytesPerElement}return Math.ceil(t/Zw)*Zw}update(){let t=!1;for(const e of this.uniforms)!0===this.updateByType(e)&&(t=!0);return t}updateByType(t){return t.isNumberUniform?this.updateNumber(t):t.isVector2Uniform?this.updateVector2(t):t.isVector3Uniform?this.updateVector3(t):t.isVector4Uniform?this.updateVector4(t):t.isColorUniform?this.updateColor(t):t.isMatrix3Uniform?this.updateMatrix3(t):t.isMatrix4Uniform?this.updateMatrix4(t):void console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",t)}updateNumber(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r]!==i){this.buffer[r]=s[r]=i,e=!0}return e}updateVector2(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,e=!0}return e}updateVector3(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,t[r+2]=s[r+2]=i.z,e=!0}return e}updateVector4(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z||s[r+4]!==i.w){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,t[r+2]=s[r+2]=i.z,t[r+3]=s[r+3]=i.w,e=!0}return e}updateColor(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.r||s[r+1]!==i.g||s[r+2]!==i.b){const t=this.buffer;t[r+0]=s[r+0]=i.r,t[r+1]=s[r+1]=i.g,t[r+2]=s[r+2]=i.b,e=!0}return e}updateMatrix3(t){let e=!1;const s=this.values,i=t.getValue().elements,r=t.offset;if(s[r+0]!==i[0]||s[r+1]!==i[1]||s[r+2]!==i[2]||s[r+4]!==i[3]||s[r+5]!==i[4]||s[r+6]!==i[5]||s[r+8]!==i[6]||s[r+9]!==i[7]||s[r+10]!==i[8]){const t=this.buffer;t[r+0]=s[r+0]=i[0],t[r+1]=s[r+1]=i[1],t[r+2]=s[r+2]=i[2],t[r+4]=s[r+4]=i[3],t[r+5]=s[r+5]=i[4],t[r+6]=s[r+6]=i[5],t[r+8]=s[r+8]=i[6],t[r+9]=s[r+9]=i[7],t[r+10]=s[r+10]=i[8],e=!0}return e}updateMatrix4(t){let e=!1;const s=this.values,i=t.getValue().elements,r=t.offset;if(!1===function(t,e,s){for(let i=0,r=e.length;i<r;i++)if(t[s+i]!==e[i])return!1;return!0}(s,i,r)){this.buffer.set(i,r),function(t,e,s){for(let i=0,r=e.length;i<r;i++)t[s+i]=e[i]}(s,i,r),e=!0}return e}}let hI=0;class uI extends aI{constructor(t,e){super(t),this.id=hI++,this.groupNode=e,this.isNodeUniformsGroup=!0}getNodes(){const t=[];for(const e of this.uniforms){const s=e.nodeUniform.node;if(!s)throw new Error("NodeUniformsGroup: Uniform has no node.");t.push(s)}return t}}let lI=0;class cI extends sI{constructor(t,e){super(t),this.id=lI++,this.texture=e,this.version=e?e.version:0,this.store=!1,this.generation=null,this.isSampledTexture=!0}needsBindingsUpdate(t){const{texture:e}=this;return t!==this.generation?(this.generation=t,!0):e.isVideoTexture}update(){const{texture:t,version:e}=this;return e!==t.version&&(this.version=t.version,!0)}}class dI extends cI{constructor(t,e,s,i=null){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s,this.access=i}needsBindingsUpdate(t){return this.textureNode.value!==this.texture||super.needsBindingsUpdate(t)}update(){const{textureNode:t}=this;return this.texture!==t.value?(this.texture=t.value,!0):super.update()}}class pI extends dI{constructor(t,e,s,i){super(t,e,s,i),this.isSampledCubeTexture=!0}}class mI extends dI{constructor(t,e,s,i){super(t,e,s,i),this.isSampledTexture3D=!0}}const gI={atan2:"atan",textureDimensions:"textureSize",equals:"equal"},fI={low:"lowp",medium:"mediump",high:"highp"},yI={swizzleAssign:!0,storageBuffer:!1},xI="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp sampler3D;\nprecision highp samplerCube;\nprecision highp sampler2DArray;\n\nprecision highp usampler2D;\nprecision highp usampler3D;\nprecision highp usamplerCube;\nprecision highp usampler2DArray;\n\nprecision highp isampler2D;\nprecision highp isampler3D;\nprecision highp isamplerCube;\nprecision highp isampler2DArray;\n\nprecision lowp sampler2DShadow;\n";class bI extends fM{constructor(t,e){super(t,e,new RB),this.uniformGroups={},this.transforms=[],this.extensions={},this.useComparisonMethod=!0}needsColorSpaceToLinearSRGB(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}getMethod(t){return gI[t]||t}getOutputStructName(){return""}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(this.getType(t.type)+" "+t.name);return`${this.getType(e.type)} ${e.name}( ${i.join(", ")} ) {\n\n\t${s.vars}\n\n${s.code}\n\treturn ${s.result};\n\n}`}setupPBO(t){const e=t.value;if(void 0===e.pbo){const t=e.array,s=e.count*e.itemSize,{itemSize:i}=e,r=e.array.constructor.name.toLowerCase().includes("int");let n=r?$t:Ht;2===i?n=r?Xt:qt:3===i?n=r?1032:Vt:4===i&&(n=r?Zt:Dt);const o={Float32Array:It,Uint8Array:At,Uint16Array:Rt,Uint32Array:Bt,Int8Array:Nt,Int16Array:Ct,Int32Array:Et,Uint8ClampedArray:At},a=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(s/i))));let h=Math.ceil(s/i/a);a*h*i<s&&h++;const u=a*h*i,l=new t.constructor(u);l.set(t,0),e.array=l;const c=new Po(e.array,a,h,n,o[e.array.constructor.name]||It);c.needsUpdate=!0,c.isPBOTexture=!0;const d=new Cy(c,null,null);d.setPrecision("high"),e.pboNode=d,e.pbo=d.value,this.getUniformFromNode(e.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(t,e=this.shaderStage){return t.isNodeUniform&&!0!==t.node.isTextureNode&&!0!==t.node.isBufferNode?e.charAt(0)+"_"+t.name:super.getPropertyName(t,e)}generatePBO(t){const{node:e,indexNode:s}=t,i=e.value;if(this.renderer.backend.has(i)){this.renderer.backend.get(i).pbo=i.pbo}const r=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.label),n=this.getPropertyName(r);this.increaseUsage(s);const o=s.build(this,"uint"),a=this.getDataFromNode(t);let h=a.propertyName;if(void 0===h){const s=this.getVarFromNode(t);h=this.getPropertyName(s);const r=this.getDataFromNode(e);let u=r.propertySizeName;void 0===u&&(u=h+"Size",this.getVarFromNode(e,u,"uint"),this.addLineFlowCode(`${u} = uint( textureSize( ${n}, 0 ).x )`,t),r.propertySizeName=u);const{itemSize:l}=i,c="."+Pd.join("").slice(0,l),d=`ivec2(${o} % ${u}, ${o} / ${u})`,p=this.generateTextureLoad(null,n,d,null,"0");let m="vec4";i.pbo.type===Bt?m="uvec4":i.pbo.type===Et&&(m="ivec4"),this.addLineFlowCode(`${h} = ${m}(${p})${c}`,t),a.propertyName=h}return h}generateTextureLoad(t,e,s,i,r="0"){return i?`texelFetch( ${e}, ivec3( ${s}, ${i} ), ${r} )`:`texelFetch( ${e}, ${s}, ${r} )`}generateTexture(t,e,s,i){return t.isDepthTexture?`texture( ${e}, ${s} ).x`:(i&&(s=`vec3( ${s}, ${i} )`),`texture( ${e}, ${s} )`)}generateTextureLevel(t,e,s,i){return`textureLod( ${e}, ${s}, ${i} )`}generateTextureBias(t,e,s,i){return`texture( ${e}, ${s}, ${i} )`}generateTextureGrad(t,e,s,i){return`textureGrad( ${e}, ${s}, ${i[0]}, ${i[1]} )`}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`texture( ${e}, vec3( ${s}, ${i} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`${this.getVar(t.type,t.name)};`);return e.join("\n\t")}getUniforms(t){const e=this.uniforms[t],s=[],i={};for(const r of e){let e=null,n=!1;if("texture"===r.type){const t=r.node.value;let s="";!0===t.isDataTexture&&(t.type===Bt?s="u":t.type===Et&&(s="i")),e=t.compareFunction?`sampler2DShadow ${r.name};`:!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture?`${s}sampler2DArray ${r.name};`:`${s}sampler2D ${r.name};`}else if("cubeTexture"===r.type)e=`samplerCube ${r.name};`;else if("texture3D"===r.type)e=`sampler3D ${r.name};`;else if("buffer"===r.type){const t=r.node,s=this.getType(t.bufferType),i=t.bufferCount,n=i>0?i:"";e=`${t.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,n=!0}const o=r.node.precision;if(null!==o&&(e=fI[o]+" "+e),n){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,s.push(e)}let r="";for(const e in i){const s=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==Et){let s=t;t.isInterleavedBufferAttribute&&(s=t.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(e=e.slice(1))}return e}getAttributes(t){let e="";if("vertex"===t||"compute"===t){const t=this.getAttributesArray();let s=0;for(const i of t)e+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t<s.length;t++){const i=s[t];e.push(`layout( location = ${t} ) out ${i} m${t};`)}return e.join("\n")}getStructs(t){const e=[],s=this.structs[t];if(0===s.length)return"layout( location = 0 ) out vec4 fragColor;\n";for(let t=0,i=s.length;t<i;t++){const i=s[t];let r="\n";r+=this.getStructMembers(i),r+="\n",e.push(r)}return e.join("\n\n")}getVaryings(t){let e="";const s=this.varyings;if("vertex"===t||"compute"===t)for(const i of s){"compute"===t&&(i.needsInterpolation=!0);const s=i.type;e+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}${i.needsInterpolation?"out":"/*out*/"} ${s} ${i.name};\n`}else if("fragment"===t)for(const t of s)if(t.needsInterpolation){const s=t.type;e+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}in ${s} ${t.name};\n`}return e}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce(((t,e)=>t*e),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(t,e,s=this.shaderStage){const i=this.extensions[s]||(this.extensions[s]=new Map);!1===i.has(t)&&i.set(t,{name:t,behavior:e})}getExtensions(t){const e=[];if("vertex"===t){const e=this.renderer.backend.extensions;this.object.isBatchedMesh&&e.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",t)}const s=this.extensions[t];if(void 0!==s)for(const{name:t,behavior:i}of s.values())e.push(`#extension ${t} : ${i}`);return e.join("\n")}isAvailable(t){let e=yI[t];if(void 0===e){if("float32Filterable"===t){const t=this.renderer.backend.extensions;t.has("OES_texture_float_linear")?(t.get("OES_texture_float_linear"),e=!0):e=!1}yI[t]=e}return e}isFlipY(){return!0}registerTransform(t,e){this.transforms.push({varyingName:t,attributeNode:e})}getTransforms(){const t=this.transforms;let e="";for(let s=0;s<t.length;s++){const i=t[s],r=this.getPropertyName(i.attributeNode);e+=`${i.varyingName} = ${r};\n\t`}return e}_getGLSLUniformStruct(t,e){return`\nlayout( std140 ) uniform ${t} {\n${e}\n};`}_getGLSLVertexCode(t){return`#version 300 es\n\n${this.getSignature()}\n\n// extensions \n${t.extensions}\n\n// precision\n${xI}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\n\n// attributes\n${t.attributes}\n\n// codes\n${t.codes}\n\nvoid main() {\n\n\t// vars\n\t${t.vars}\n\n\t// transforms\n\t${t.transforms}\n\n\t// flow\n\t${t.flow}\n\n\tgl_PointSize = 1.0;\n\n}\n`}_getGLSLFragmentCode(t){return`#version 300 es\n\n${this.getSignature()}\n\n// precision\n${xI}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\n\n// codes\n${t.codes}\n\n${t.structs}\n\nvoid main() {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const e in t){let s="// code\n\n";s+=this.flowCode[e];const i=this.flowNodes[e],r=i[i.length-1];for(const t of i){const i=this.getFlowData(t),n=t.name;n&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,t===r&&"compute"!==e&&(s+="// result\n\t","vertex"===e?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=t[e];n.extensions=this.getExtensions(e),n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.vars=this.getVars(e),n.structs=this.getStructs(e),n.codes=this.getCodes(e),n.transforms=this.getTransforms(e),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=t.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===e)o=new dI(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new pI(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new mI(r.name,r.node,i),h.push(o);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new oI(t,i);e.name=t.name,h.push(e),o=e}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new uI(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let vI=null,TI=null,_I=null;class wI{constructor(t={}){this.parameters=Object.assign({},t),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(t){this.renderer=t}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(t){const{object:e,geometry:s}=t;return s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return vI=vI||new Ys,this.renderer.getDrawingBufferSize(vI)}getScissor(){return TI=TI||new xi,this.renderer.getScissor(TI)}setScissorTest(){}getClearColor(){const t=this.renderer;return _I=_I||new DB,t.getClearColor(_I),_I.getRGB(_I,this.renderer.currentColorSpace),_I}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ei(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${t} webgpu`),this.domElement=e),e}set(t,e){this.data.set(t,e)}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}has(t){return this.data.has(t)}delete(t){this.data.delete(t)}}let SI=0;class MI{constructor(t,e){this.buffers=[t.bufferGPU,e],this.type=t.type,this.bufferType=t.bufferType,this.pbo=t.pbo,this.byteLength=t.byteLength,this.bytesPerElement=t.BYTES_PER_ELEMENT,this.version=t.version,this.isInteger=t.isInteger,this.activeBufferIndex=0,this.baseId=t.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class AI{constructor(t){this.backend=t}createAttribute(t,e){const s=this.backend,{gl:i}=s,r=t.array,n=t.usage||i.STATIC_DRAW,o=t.isInterleavedBufferAttribute?t.data:t,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,e,r,n),a.bufferGPU=u,a.bufferType=e,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)h=i.SHORT;else if(r instanceof Uint32Array)h=i.UNSIGNED_INT;else if(r instanceof Int32Array)h=i.INT;else if(r instanceof Int8Array)h=i.BYTE;else if(r instanceof Uint8Array)h=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);h=i.UNSIGNED_BYTE}let l={bufferGPU:u,bufferType:e,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||t.gpuType===Et,id:SI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);l=new MI(l,t)}s.set(t,l)}updateAttribute(t){const e=this.backend,{gl:s}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,n=e.get(r),o=n.bufferType,a=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let t=0,e=a.length;t<e;t++){const e=a[t];s.bufferSubData(o,e.start*i.BYTES_PER_ELEMENT,i,e.start,e.count)}r.clearUpdateRanges()}s.bindBuffer(o,null),n.version=r.version}destroyAttribute(t){const e=this.backend,{gl:s}=e;t.isInterleavedBufferAttribute&&e.delete(t.data);const i=e.get(t);s.deleteBuffer(i.bufferGPU),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,{gl:s}=e,i=t.isInterleavedBufferAttribute?t.data:t,{bufferGPU:r}=e.get(i),n=t.array,o=n.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,r);const a=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.bufferData(s.COPY_WRITE_BUFFER,o,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,o),await e.utils._clientWaitAsync();const h=new t.array.constructor(n.length);return s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.getBufferSubData(s.COPY_WRITE_BUFFER,0,h),s.deleteBuffer(a),s.bindBuffer(s.COPY_READ_BUFFER,null),s.bindBuffer(s.COPY_WRITE_BUFFER,null),h.buffer}_createBuffer(t,e,s,i){const r=t.createBuffer();return t.bindBuffer(e,r),t.bufferData(e,s,i),t.bindBuffer(e,null),r}}let NI,CI,RI=!1;class EI{constructor(t){this.backend=t,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.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.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},!1===RI&&(this._init(this.gl),RI=!0)}_init(t){NI={[v]:t.FUNC_ADD,101:t.FUNC_SUBTRACT,102:t.FUNC_REVERSE_SUBTRACT},CI={200:t.ZERO,201:t.ONE,202:t.SRC_COLOR,[R]:t.SRC_ALPHA,210:t.SRC_ALPHA_SATURATE,208:t.DST_COLOR,206:t.DST_ALPHA,203:t.ONE_MINUS_SRC_COLOR,[E]:t.ONE_MINUS_SRC_ALPHA,209:t.ONE_MINUS_DST_COLOR,207:t.ONE_MINUS_DST_ALPHA}}enable(t){const{enabled:e}=this;!0!==e[t]&&(this.gl.enable(t),e[t]=!0)}disable(t){const{enabled:e}=this;!1!==e[t]&&(this.gl.disable(t),e[t]=!1)}setFlipSided(t){if(this.currentFlipSided!==t){const{gl:e}=this;t?e.frontFace(e.CW):e.frontFace(e.CCW),this.currentFlipSided=t}}setCullFace(t){const{gl:e}=this;0!==t?(this.enable(e.CULL_FACE),t!==this.currentCullFace&&(1===t?e.cullFace(e.BACK):2===t?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK))):this.disable(e.CULL_FACE),this.currentCullFace=t}setLineWidth(t){const{currentLineWidth:e,gl:s}=this;t!==e&&(s.lineWidth(t),this.currentLineWidth=t)}setBlending(t,e,s,i,r,n,o,a){const{gl:h}=this;if(t!==m){if(!1===this.currentBlendingEnabled&&(this.enable(h.BLEND),this.currentBlendingEnabled=!0),5===t)r=r||e,n=n||s,o=o||i,e===this.currentBlendEquation&&r===this.currentBlendEquationAlpha||(h.blendEquationSeparate(NI[e],NI[r]),this.currentBlendEquation=e,this.currentBlendEquationAlpha=r),s===this.currentBlendSrc&&i===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&o===this.currentBlendDstAlpha||(h.blendFuncSeparate(CI[s],CI[i],CI[n],CI[o]),this.currentBlendSrc=s,this.currentBlendDst=i,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=o),this.currentBlending=t,this.currentPremultipledAlpha=!1;else if(t!==this.currentBlending||a!==this.currentPremultipledAlpha){if(this.currentBlendEquation===v&&this.currentBlendEquationAlpha===v||(h.blendEquation(h.FUNC_ADD),this.currentBlendEquation=v,this.currentBlendEquationAlpha=v),a)switch(t){case 1:h.blendFuncSeparate(h.ONE,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.ONE,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFuncSeparate(h.ZERO,h.SRC_COLOR,h.ZERO,h.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",t)}else switch(t){case 1:h.blendFuncSeparate(h.SRC_ALPHA,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.SRC_ALPHA,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFunc(h.ZERO,h.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",t)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=t,this.currentPremultipledAlpha=a}}else!0===this.currentBlendingEnabled&&(this.disable(h.BLEND),this.currentBlendingEnabled=!1)}setColorMask(t){this.currentColorMask!==t&&(this.gl.colorMask(t,t,t,t),this.currentColorMask=t)}setDepthTest(t){const{gl:e}=this;t?this.enable(e.DEPTH_TEST):this.disable(e.DEPTH_TEST)}setDepthMask(t){this.currentDepthMask!==t&&(this.gl.depthMask(t),this.currentDepthMask=t)}setDepthFunc(t){if(this.currentDepthFunc!==t){const{gl:e}=this;switch(t){case 0:e.depthFunc(e.NEVER);break;case 1:e.depthFunc(e.ALWAYS);break;case 2:e.depthFunc(e.LESS);break;case 3:default:e.depthFunc(e.LEQUAL);break;case 4:e.depthFunc(e.EQUAL);break;case 5:e.depthFunc(e.GEQUAL);break;case 6:e.depthFunc(e.GREATER);break;case 7:e.depthFunc(e.NOTEQUAL)}this.currentDepthFunc=t}}setStencilTest(t){const{gl:e}=this;t?this.enable(e.STENCIL_TEST):this.disable(e.STENCIL_TEST)}setStencilMask(t){this.currentStencilMask!==t&&(this.gl.stencilMask(t),this.currentStencilMask=t)}setStencilFunc(t,e,s){this.currentStencilFunc===t&&this.currentStencilRef===e&&this.currentStencilFuncMask===s||(this.gl.stencilFunc(t,e,s),this.currentStencilFunc=t,this.currentStencilRef=e,this.currentStencilFuncMask=s)}setStencilOp(t,e,s){this.currentStencilFail===t&&this.currentStencilZFail===e&&this.currentStencilZPass===s||(this.gl.stencilOp(t,e,s),this.currentStencilFail=t,this.currentStencilZFail=e,this.currentStencilZPass=s)}setMaterial(t,e){const{gl:s}=this;2===t.side?this.disable(s.CULL_FACE):this.enable(s.CULL_FACE);let i=t.side===d;e&&(i=!i),this.setFlipSided(i),1===t.blending&&!1===t.transparent?this.setBlending(m):this.setBlending(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.premultipliedAlpha),this.setDepthFunc(t.depthFunc),this.setDepthTest(t.depthTest),this.setDepthMask(t.depthWrite),this.setColorMask(t.colorWrite);const r=t.stencilWrite;this.setStencilTest(r),r&&(this.setStencilMask(t.stencilWriteMask),this.setStencilFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),this.setStencilOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),this.setPolygonOffset(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),!0===t.alphaToCoverage&&this.backend.renderer.samples>1?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE)}setPolygonOffset(t,e,s){const{gl:i}=this;t?(this.enable(i.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===e&&this.currentPolygonOffsetUnits===s||(i.polygonOffset(e,s),this.currentPolygonOffsetFactor=e,this.currentPolygonOffsetUnits=s)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(t){return this.currentProgram!==t&&(this.gl.useProgram(t),this.currentProgram=t,!0)}bindFramebuffer(t,e){const{gl:s,currentBoundFramebuffers:i}=this;return i[t]!==e&&(s.bindFramebuffer(t,e),i[t]=e,t===s.DRAW_FRAMEBUFFER&&(i[s.FRAMEBUFFER]=e),t===s.FRAMEBUFFER&&(i[s.DRAW_FRAMEBUFFER]=e),!0)}drawBuffers(t,e){const{gl:s}=this;let i=[],r=!1;if(null!==t.textures){i=this.currentDrawbuffers.get(e),void 0===i&&(i=[],this.currentDrawbuffers.set(e,i));const n=t.textures;if(i.length!==n.length||i[0]!==s.COLOR_ATTACHMENT0){for(let t=0,e=n.length;t<e;t++)i[t]=s.COLOR_ATTACHMENT0+t;i.length=n.length,r=!0}}else i[0]!==s.BACK&&(i[0]=s.BACK,r=!0);r&&s.drawBuffers(i)}activeTexture(t){const{gl:e,currentTextureSlot:s,maxTextures:i}=this;void 0===t&&(t=e.TEXTURE0+i-1),s!==t&&(e.activeTexture(t),this.currentTextureSlot=t)}bindTexture(t,e,s){const{gl:i,currentTextureSlot:r,currentBoundTextures:n,maxTextures:o}=this;void 0===s&&(s=null===r?i.TEXTURE0+o-1:r);let a=n[s];void 0===a&&(a={type:void 0,texture:void 0},n[s]=a),a.type===t&&a.texture===e||(r!==s&&(i.activeTexture(s),this.currentTextureSlot=s),i.bindTexture(t,e),a.type=t,a.texture=e)}bindBufferBase(t,e,s){const{gl:i}=this,r=`${t}-${e}`;return this.currentBoundBufferBases[r]!==s&&(i.bindBufferBase(t,e,s),this.currentBoundBufferBases[r]=s,!0)}unbindTexture(){const{gl:t,currentTextureSlot:e,currentBoundTextures:s}=this,i=s[e];void 0!==i&&void 0!==i.type&&(t.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}}class BI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.extensions=t.extensions}convert(t,e=""){const{gl:s,extensions:i}=this;let r;if(t===At)return s.UNSIGNED_BYTE;if(1017===t)return s.UNSIGNED_SHORT_4_4_4_4;if(1018===t)return s.UNSIGNED_SHORT_5_5_5_1;if(t===zt)return s.UNSIGNED_INT_5_9_9_9_REV;if(t===Nt)return s.BYTE;if(t===Ct)return s.SHORT;if(t===Rt)return s.UNSIGNED_SHORT;if(t===Et)return s.INT;if(t===Bt)return s.UNSIGNED_INT;if(t===It)return s.FLOAT;if(t===Pt)return s.HALF_FLOAT;if(1021===t)return s.ALPHA;if(t===Vt)return s.RGB;if(t===Dt)return s.RGBA;if(1024===t)return s.LUMINANCE;if(1025===t)return s.LUMINANCE_ALPHA;if(t===Wt)return s.DEPTH_COMPONENT;if(t===jt)return s.DEPTH_STENCIL;if(t===Ht)return s.RED;if(t===$t)return s.RED_INTEGER;if(t===qt)return s.RG;if(t===Xt)return s.RG_INTEGER;if(t===Zt)return s.RGBA_INTEGER;if(t===Jt||t===Kt||t===Qt||t===te)if(e===Ze){if(r=i.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(t===Jt)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(t===Kt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(t===te)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=i.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(t===Jt)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Kt)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===te)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(t===ee||t===se||t===ie||t===re){if(r=i.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(t===ee)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===se)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===ie)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===re)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===ne||t===oe||t===ae){if(r=i.get("WEBGL_compressed_texture_etc"),null===r)return null;if(t===ne||t===oe)return e===Ze?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(t===ae)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(t===he||t===ue||t===le||t===ce||t===de||t===pe||t===me||t===ge||t===fe||t===ye||t===xe||t===be||t===ve||t===Te){if(r=i.get("WEBGL_compressed_texture_astc"),null===r)return null;if(t===he)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(t===ue)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(t===le)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(t===ce)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(t===de)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(t===pe)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(t===me)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(t===ge)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(t===fe)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(t===ye)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(t===xe)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(t===be)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(t===ve)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(t===Te)return e===Ze?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(t===_e){if(r=i.get("EXT_texture_compression_bptc"),null===r)return null;if(t===_e)return e===Ze?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(36283===t||t===Ae||t===Ne||t===Ce){if(r=i.get("EXT_texture_compression_rgtc"),null===r)return null;if(t===_e)return r.COMPRESSED_RED_RGTC1_EXT;if(t===Ae)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(t===Ne)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(t===Ce)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return t===Ot?s.UNSIGNED_INT_24_8:void 0!==s[t]?s[t]:null}_clientWaitAsync(){const{gl:t}=this,e=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return t.flush(),new Promise(((s,i)=>{!function r(){const n=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(n===t.WAIT_FAILED)return t.deleteSync(e),void i();n!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),s()):requestAnimationFrame(r)}()}))}}let II,PI,FI,UI=!1;class OI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===UI&&(this._init(this.gl),UI=!0)}_init(t){II={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},PI={[ft]:t.NEAREST,[yt]:t.NEAREST_MIPMAP_NEAREST,[bt]:t.NEAREST_MIPMAP_LINEAR,[Tt]:t.LINEAR,[_t]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},FI={512:t.NEVER,519:t.ALWAYS,[ys]:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===ft||t===yt||t===bt?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let s;return s=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,s}getInternalFormat(t,e,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==t){if(void 0!==n[t])return n[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let a=e;return e===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=i===Ze&&!1===r?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),e===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),e===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=i===Ze&&!1===r?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),e===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),e===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),e===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(t,e){const{gl:s,extensions:i,backend:r}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,e.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,e.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(t,s.TEXTURE_WRAP_S,II[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,II[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,II[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,PI[e.magFilter]);const n=void 0!==e.mipmaps&&e.mipmaps.length>0,o=e.minFilter===Tt&&n?St:e.minFilter;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,PI[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,FI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===ft)return;if(e.minFilter!==bt&&e.minFilter!==St)return;if(e.type===It&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy()))}}}createDefaultTexture(t){const{gl:e,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(t);let n=i[r];void 0===n&&(n=e.createTexture(),s.state.bindTexture(r,n),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=n),s.set(t,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=e,h=i.utils.convert(t.format,t.colorSpace),u=i.utils.convert(t.type),l=this.getInternalFormat(t.internalFormat,h,u,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),this.setTextureParameters(d,t),t.isDataArrayTexture||t.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:u}=e.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(n,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,h,u,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:s}=this,{width:i,height:r}=e,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const l=t=>t.isDataTexture?t.image.data:t instanceof ImageBitmap||t instanceof OffscreenCanvas||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement?t:t.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,t),t.isCompressedTexture){const i=t.mipmaps,r=e.image;for(let e=0;e<i.length;e++){const n=i[e];t.isCompressedArrayTexture?t.format!==s.RGBA?null!==a?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,e,0,0,0,n.width,n.height,r.depth,a,n.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,e,0,0,0,n.width,n.height,r.depth,a,h,n.data):null!==a?s.compressedTexSubImage2D(s.TEXTURE_2D,e,0,0,n.width,n.height,a,n.data):console.warn("Unsupported compressed texture format")}}else if(t.isCubeTexture){const t=e.images;for(let e=0;e<6;e++){const n=l(t[e]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,i,r,a,h,n)}}else if(t.isDataArrayTexture){const t=e.image;s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,t.width,t.height,t.depth,a,h,t.data)}else if(t.isData3DTexture){const t=e.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,t.width,t.height,t.depth,a,h,t.data)}else if(t.isVideoTexture)t.update(),s.texImage2D(o,0,u,a,h,e.image);else{const t=l(e.image);s.texSubImage2D(o,0,0,0,i,r,a,h,t)}}generateMipmaps(t){const{gl:e,backend:s}=this,{textureGPU:i,glTextureType:r}=s.get(t);s.state.bindTexture(r,i),e.generateMipmap(r)}deallocateRenderBuffers(t){const{gl:e,backend:s}=this;if(t){const i=s.get(t);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(const t in i.framebuffers)e.deleteFramebuffer(i.framebuffers[t]);delete i.framebuffers}if(i.depthRenderbuffer&&(e.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(e.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(e.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let t=0;t<i.msaaRenderbuffers.length;t++)e.deleteRenderbuffer(i.msaaRenderbuffers[t]);delete i.msaaRenderbuffers}}}destroyTexture(t){const{gl:e,backend:s}=this,{textureGPU:i,renderTarget:r}=s.get(t);this.deallocateRenderBuffers(r),e.deleteTexture(i),s.delete(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){const{gl:n,backend:o}=this,{state:a}=this.backend,{textureGPU:h,glTextureType:u,glType:l,glFormat:c}=o.get(e);let d,p,m,g,f,y;null!==s?(d=s.max.x-s.min.x,p=s.max.y-s.min.y,m=s.min.x,g=s.min.y):(d=t.image.width,p=t.image.height,m=0,g=0),null!==i?(f=i.x,y=i.y):(f=0,y=0),a.bindTexture(u,h),n.pixelStorei(n.UNPACK_ALIGNMENT,e.unpackAlignment),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,e.flipY),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),n.pixelStorei(n.UNPACK_ALIGNMENT,e.unpackAlignment);const x=n.getParameter(n.UNPACK_ROW_LENGTH),b=n.getParameter(n.UNPACK_IMAGE_HEIGHT),v=n.getParameter(n.UNPACK_SKIP_PIXELS),T=n.getParameter(n.UNPACK_SKIP_ROWS),_=n.getParameter(n.UNPACK_SKIP_IMAGES),w=t.isCompressedTexture?t.mipmaps[r]:t.image;n.pixelStorei(n.UNPACK_ROW_LENGTH,w.width),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,w.height),n.pixelStorei(n.UNPACK_SKIP_PIXELS,m),n.pixelStorei(n.UNPACK_SKIP_ROWS,g),t.isDataTexture?n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w.data):t.isCompressedTexture?n.compressedTexSubImage2D(n.TEXTURE_2D,r,f,y,w.width,w.height,c,w.data):n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w),n.pixelStorei(n.UNPACK_ROW_LENGTH,x),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,b),n.pixelStorei(n.UNPACK_SKIP_PIXELS,v),n.pixelStorei(n.UNPACK_SKIP_ROWS,T),n.pixelStorei(n.UNPACK_SKIP_IMAGES,_),0===r&&e.generateMipmaps&&n.generateMipmap(n.TEXTURE_2D),a.unbindTexture()}copyFramebufferToTexture(t,e,s){const{gl:i}=this,{state:r}=this.backend,{textureGPU:n}=this.backend.get(t),{x:o,y:a,z:h,w:u}=s,l=!0===t.isDepthTexture||e.renderTarget&&e.renderTarget.samples>0,c=e.renderTarget?e.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(l){const s=0!==o||0!==a;let l,d;if(!0===t.isDepthTexture?(l=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,e.stencil&&(l|=i.STENCIL_BUFFER_BIT)):(l=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),s){const t=this.backend.get(e.renderTarget),s=t.framebuffers[e.getCacheKey()],d=t.msaaFrameBuffer;r.bindFramebuffer(i.DRAW_FRAMEBUFFER,s),r.bindFramebuffer(i.READ_FRAMEBUFFER,d);const p=c-a-u;i.blitFramebuffer(o,p,o+h,p+u,o,p,o+h,p+u,l,i.NEAREST),r.bindFramebuffer(i.READ_FRAMEBUFFER,s),r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,p,h,u),r.unbindTexture()}else{const t=i.createFramebuffer();r.bindFramebuffer(i.DRAW_FRAMEBUFFER,t),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,n,0),i.blitFramebuffer(0,0,h,u,0,0,h,u,l,i.NEAREST),i.deleteFramebuffer(t)}}else r.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,o,c-u-a,h,u),r.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:s}=this,i=e.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,t),o&&!a){let e=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(e=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,e,h,u)):s.renderbufferStorage(s.RENDERBUFFER,e,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,u):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r,n){const{backend:o,gl:a}=this,{textureGPU:h,glFormat:u,glType:l}=this.backend.get(t),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const d=t.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,d,h,0);const p=this._getTypedArrayType(l),m=i*r*this._getBytesPerTexel(l,u),g=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.bufferData(a.PIXEL_PACK_BUFFER,m,a.STREAM_READ),a.readPixels(e,s,i,r,u,l,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(m/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,g),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(t){const{gl:e}=this;if(t===e.UNSIGNED_BYTE)return Uint8Array;if(t===e.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(t===e.UNSIGNED_SHORT)return Uint16Array;if(t===e.UNSIGNED_INT)return Uint32Array;if(t===e.HALF_FLOAT)return Uint16Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t,e){const{gl:s}=this;let i=0;return t===s.UNSIGNED_BYTE&&(i=1),t!==s.UNSIGNED_SHORT_4_4_4_4&&t!==s.UNSIGNED_SHORT_5_5_5_1&&t!==s.UNSIGNED_SHORT_5_6_5&&t!==s.UNSIGNED_SHORT&&t!==s.HALF_FLOAT||(i=2),t!==s.UNSIGNED_INT&&t!==s.FLOAT||(i=4),e===s.RGBA?4*i:e===s.RGB?3*i:e===s.ALPHA?i:void 0}}class zI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(t){let e=this.extensions[t];return void 0===e&&(e=this.gl.getExtension(t),this.extensions[t]=e),e}has(t){return this.availableExtensions.includes(t)}}class LI{constructor(t){this.backend=t,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const t=this.backend.gl,e=this.backend.extensions;if(!0===e.has("EXT_texture_filter_anisotropic")){const s=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const VI={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class DI{constructor(t){this.gl=t.gl,this.extensions=t.extensions,this.info=t.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(t,e){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,e,n,t):s.drawArrays(i,t,e),o.update(r,e,i,1)}renderInstances(t,e,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,e,n,t,s):i.drawArraysInstanced(r,t,e,s),h.update(a,e,r,s))}renderMultiDraw(t,e,s){const{extensions:i,mode:r,object:n,info:o}=this;if(0===s)return;const a=i.get("WEBGL_multi_draw");if(null===a)for(let i=0;i<s;i++)this.render(t[i],e[i]);else{0!==this.index?a.multiDrawElementsWEBGL(r,e,0,this.type,t,0,s):a.multiDrawArraysWEBGL(r,t,0,e,0,s);let i=0;for(let t=0;t<s;t++)i+=e[t];o.update(n,i,r,1)}}renderMultiDrawInstances(t,e,s,i){const{extensions:r,mode:n,object:o,info:a}=this;if(0===s)return;const h=r.get("WEBGL_multi_draw");if(null===h)for(let r=0;r<s;r++)this.renderInstances(t[r],e[r],i[r]);else{0!==this.index?h.multiDrawElementsInstancedWEBGL(n,e,0,this.type,t,0,i,0,s):h.multiDrawArraysInstancedWEBGL(n,t,0,e,0,i,0,s);let r=0;for(let t=0;t<s;t++)r+=e[t]*i[t];a.update(o,r,n,1)}}}class kI extends wI{constructor(t={}){super(t),this.isWebGLBackend=!0}init(t){super.init(t);const e=this.parameters,s=void 0!==e.context?e.context:t.domElement.getContext("webgl2");this.gl=s,this.extensions=new zI(this),this.capabilities=new LI(this),this.attributeUtils=new AI(this),this.textureUtils=new OI(this),this.bufferRenderer=new DI(this),this.state=new EI(this),this.utils=new BI(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===e.trackTimestamp,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.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this._currentContext=null}get coordinateSystem(){return Us}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}initTimestampQuery(t){if(!this.disjoint||!this.trackTimestamp)return;const e=this.get(t);if(this.queryRunning)return e.queryQueue||(e.queryQueue=[]),void e.queryQueue.push(t);e.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),e.activeQuery=null),e.activeQuery=this.gl.createQuery(),null!==e.activeQuery&&(this.gl.beginQuery(this.disjoint.TIME_ELAPSED_EXT,e.activeQuery),this.queryRunning=!0)}prepareTimestampBuffer(t){if(!this.disjoint||!this.trackTimestamp)return;const e=this.get(t);if(e.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),e.gpuQueries||(e.gpuQueries=[]),e.gpuQueries.push({query:e.activeQuery}),e.activeQuery=null,this.queryRunning=!1,e.queryQueue&&e.queryQueue.length>0)){const t=e.queryQueue.shift();this.initTimestampQuery(t)}}async resolveTimestampAsync(t,e="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(t);s.gpuQueries||(s.gpuQueries=[]);for(let t=0;t<s.gpuQueries.length;t++){const i=s.gpuQueries[t],r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT_AVAILABLE),n=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(r&&!n){const r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT),n=Number(r)/1e6;this.gl.deleteQuery(i.query),s.gpuQueries.splice(t,1),t--,this.renderer.info.updateTimestamp(e,n)}}}getContext(){return this.gl}beginRender(t){const{gl:e}=this,s=this.get(t);if(this.initTimestampQuery(t),s.previousContext=this._currentContext,this._currentContext=t,this._setFramebuffer(t),this.clear(t.clearColor,t.clearDepth,t.clearStencil,t,!1),t.viewport?this.updateViewport(t):e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.scissor){const{x:s,y:i,width:r,height:n}=t.scissorValue;e.scissor(s,t.height-n-i,r,n)}const i=t.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(t){const{gl:e,state:s}=this,i=this.get(t),r=i.previousContext,n=t.occlusionQueryCount;n>0&&(n>i.occlusionQueryIndex&&e.endQuery(e.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(t));const o=t.textures;if(null!==o)for(let t=0;t<o.length;t++){const e=o[t];e.generateMipmaps&&this.generateMipmaps(e)}if(this._currentContext=r,null!==t.textures&&t.renderTarget){const i=this.get(t.renderTarget),{samples:r}=t.renderTarget;if(r>0){const r=i.framebuffers[t.getCacheKey()],n=e.COLOR_BUFFER_BIT,o=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,o),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,r);for(let s=0;s<a.length;s++)if(t.scissor){const{x:s,y:r,width:o,height:a}=t.scissorValue,h=t.height-a-r;e.blitFramebuffer(s,h,s+o,h+a,s,h,s+o,h+a,n,e.NEAREST),e.invalidateSubFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray,s,h,o,a)}else e.blitFramebuffer(0,0,t.width,t.height,0,0,t.width,t.height,n,e.NEAREST),e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray)}}null!==r&&(this._setFramebuffer(r),r.viewport?this.updateViewport(r):e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight)),this.prepareTimestampBuffer(t)}resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet,{gl:r}=this;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueries=null;const n=()=>{let o=0;for(let e=0;e<s.length;e++){const n=s[e];null!==n&&(r.getQueryParameter(n,r.QUERY_RESULT_AVAILABLE)&&(r.getQueryParameter(n,r.QUERY_RESULT)>0&&t.add(i[e]),s[e]=null,r.deleteQuery(n),o++))}o<s.length?requestAnimationFrame(n):e.occluded=t};n()}}isOccluded(t,e){const s=this.get(t);return s.occluded&&s.occluded.has(e)}updateViewport(t){const e=this.gl,{x:s,y:i,width:r,height:n}=t.viewportValue;e.viewport(s,t.height-n-i,r,n)}setScissorTest(t){const e=this.gl;t?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)}clear(t,e,s,i=null,r=!0){const{gl:n}=this;if(null===i){const t=this.getClearColor();t.r*=t.a,t.g*=t.a,t.b*=t.a,i={textures:null,clearColorValue:t}}let o=0;if(t&&(o|=n.COLOR_BUFFER_BIT),e&&(o|=n.DEPTH_BUFFER_BIT),s&&(o|=n.STENCIL_BUFFER_BIT),0!==o){let a;if(i.clearColorValue?a=i.clearColorValue:(a=this.getClearColor(),a.r*=a.a,a.g*=a.a,a.b*=a.a),e&&this.state.setDepthMask(!0),null===i.textures)n.clearColor(a.r,a.g,a.b,a.a),n.clear(o);else{if(r&&this._setFramebuffer(i),t)for(let t=0;t<i.textures.length;t++)n.clearBufferfv(n.COLOR,t,[a.r,a.g,a.b,a.a]);e&&s?n.clearBufferfi(n.DEPTH_STENCIL,0,1,0):e?n.clearBufferfv(n.DEPTH,0,[1]):s&&n.clearBufferiv(n.STENCIL,0,[0])}}}beginCompute(t){const{state:e,gl:s}=this;e.bindFramebuffer(s.FRAMEBUFFER,null),this.initTimestampQuery(t)}compute(t,e,s,i){const{state:r,gl:n}=this;this.discard||(n.enable(n.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:o,transformBuffers:a,attributes:h}=this.get(i),u=this._getVaoKey(null,h),l=this.vaoCache[u];void 0===l?this._createVao(null,h):n.bindVertexArray(l),r.useProgram(o),this._bindUniforms(s);const c=this._getTransformFeedback(a);n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,c),n.beginTransformFeedback(n.POINTS),h[0].isStorageInstancedBufferAttribute?n.drawArraysInstanced(n.POINTS,0,1,e.count):n.drawArrays(n.POINTS,0,e.count),n.endTransformFeedback(),n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,null);for(let t=0;t<a.length;t++){const e=a[t];e.pbo&&this.textureUtils.copyBufferToTexture(e.transformBuffer,e.pbo),e.switchBuffers()}}finishCompute(t){const e=this.gl;this.discard=!1,e.disable(e.RASTERIZER_DISCARD),this.prepareTimestampBuffer(t),this._currentContext&&this._setFramebuffer(this._currentContext)}draw(t){const{object:e,pipeline:s,material:i,context:r}=t,{programGPU:n}=this.get(s),{gl:o,state:a}=this,h=this.get(r),u=t.getDrawParameters();if(null===u)return;this._bindUniforms(t.getBindings());const l=e.isMesh&&e.matrixWorld.determinant()<0;a.setMaterial(i,l),a.useProgram(n);let c=t.staticVao;if(void 0===c){const e=this._getVaoKey(t.getIndex(),t.getAttributes());if(c=this.vaoCache[e],void 0===c){let e;({vaoGPU:c,staticVao:e}=this._createVao(t.getIndex(),t.getAttributes())),e&&(t.staticVao=c)}}o.bindVertexArray(c);const d=t.getIndex(),p=h.lastOcclusionObject;if(p!==e&&void 0!==p){if(null!==p&&!0===p.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),h.occlusionQueryIndex++),!0===e.occlusionTest){const t=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,t),h.occlusionQueries[h.occlusionQueryIndex]=t,h.occlusionQueryObjects[h.occlusionQueryIndex]=e}h.lastOcclusionObject=e}const m=this.bufferRenderer;e.isPoints?m.mode=o.POINTS:e.isLineSegments?m.mode=o.LINES:e.isLine?m.mode=o.LINE_STRIP:e.isLineLoop?m.mode=o.LINE_LOOP:!0===i.wireframe?(a.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),m.mode=o.LINES):m.mode=o.TRIANGLES;const{vertexCount:g,instanceCount:f}=u;let{firstVertex:y}=u;if(m.object=e,null!==d){y*=d.array.BYTES_PER_ELEMENT;const t=this.get(d);m.index=d.count,m.type=t.type}else m.index=0;var x;e.isBatchedMesh?null!==e._multiDrawInstances?m.renderMultiDrawInstances(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount,e._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?m.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount):(x="THREE.WebGLRenderer: WEBGL_multi_draw not supported.")in si||(si[x]=!0,console.warn(x)):f>1?m.renderInstances(y,g,f):m.render(y,g),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r,n){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r,n)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new bI(t,e)}createProgram(t){const e=this.gl,{stage:s,code:i}=t,r="fragment"===s?e.createShader(e.FRAGMENT_SHADER):e.createShader(e.VERTEX_SHADER);e.shaderSource(r,i),e.compileShader(r),this.set(t,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(t,e){const s=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:n}=i,o=s.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,h),s.linkProgram(o),this.set(i,{programGPU:o,fragmentShader:a,vertexShader:h}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(n)};n()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const s=t.split("\n"),i=[],r=Math.max(e-6,0),n=Math.min(e+6,s.length);for(let t=r;t<n;t++){const r=t+1;i.push(`${r===e?">":" "} ${r}: ${s[t]}`)}return i.join("\n")}_getShaderErrors(t,e,s){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const n=/ERROR: 0:(\d+)/.exec(r);if(n){const i=parseInt(n[1]);return s.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(t).trim();if(!1===i.getProgramParameter(t,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,t,s,e);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,e,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(t,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const{state:s,gl:i}=this,r=this.get(e),{programGPU:n,fragmentShader:o,vertexShader:a}=r;!1===i.getProgramParameter(n,i.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const h=t.getBindings();this._setupBindings(h,n),this.set(e,{programGPU:n})}createComputePipeline(t,e){const{state:s,gl:i}=this,r={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(r);const{computeProgram:n}=t,o=i.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU,u=n.transforms,l=[],c=[];for(let t=0;t<u.length;t++){const e=u[t];l.push(e.varyingName),c.push(e.attributeNode)}i.attachShader(o,a),i.attachShader(o,h),i.transformFeedbackVaryings(o,l,i.SEPARATE_ATTRIBS),i.linkProgram(o),!1===i.getProgramParameter(o,i.LINK_STATUS)&&this._logProgramError(o,a,h),s.useProgram(o),this.createBindings(null,e),this._setupBindings(e,o);const d=n.attributes,p=[],m=[];for(let t=0;t<d.length;t++){const e=d[t].node.attribute;p.push(e),this.has(e)||this.attributeUtils.createAttribute(e,i.ARRAY_BUFFER)}for(let t=0;t<c.length;t++){const e=c[t].attribute;this.has(e)||this.attributeUtils.createAttribute(e,i.ARRAY_BUFFER);const s=this.get(e);m.push(s)}this.set(t,{programGPU:o,transformBuffers:m,attributes:p})}createBindings(t,e){this.updateBindings(t,e)}updateBindings(t,e){if(!t)return;const{gl:s}=this,i=this.get(e),r=this.get(t);void 0===i.textureIndex&&(i.textureIndex=0),void 0===r.textureIndex?r.textureIndex=i.textureIndex:i.textureIndex=r.textureIndex;let n=0;for(const e of t.bindings)if(e.isUniformsGroup||e.isUniformBuffer){const i=e.buffer,r=s.createBuffer();s.bindBuffer(s.UNIFORM_BUFFER,r),s.bufferData(s.UNIFORM_BUFFER,i,s.DYNAMIC_DRAW),this.set(e,{index:2*t.index+n++,bufferGPU:r})}else if(e.isSampledTexture){const{textureGPU:t,glTextureType:s}=this.get(e.texture);this.set(e,{index:i.textureIndex++,textureGPU:t,glTextureType:s})}}updateBinding(t){const e=this.gl;if(t.isUniformsGroup||t.isUniformBuffer){const s=this.get(t).bufferGPU,i=t.buffer;e.bindBuffer(e.UNIFORM_BUFFER,s),e.bufferData(e.UNIFORM_BUFFER,i,e.DYNAMIC_DRAW)}}createIndexAttribute(t){const e=this.gl;this.attributeUtils.createAttribute(t,e.ELEMENT_ARRAY_BUFFER)}createAttribute(t){if(this.has(t))return;const e=this.gl;this.attributeUtils.createAttribute(t,e.ARRAY_BUFFER)}createStorageAttribute(t){if(this.has(t))return;const e=this.gl;this.attributeUtils.createAttribute(t,e.ARRAY_BUFFER)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){}hasFeature(t){const e=Object.keys(VI).filter((e=>VI[e]===t)),s=this.extensions;for(let t=0;t<e.length;t++)if(s.has(e[t]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(t,e,s,i){this.textureUtils.copyTextureToTexture(t,e,s,i)}copyFramebufferToTexture(t,e,s){this.textureUtils.copyFramebufferToTexture(t,e,s)}_setFramebuffer(t){const{gl:e,state:s}=this;let i=null;if(null!==t.textures){const r=t.renderTarget,n=this.get(r),{samples:o,depthBuffer:a,stencilBuffer:h}=r,u=!0===r.isWebGLCubeRenderTarget;let l=n.msaaFrameBuffer,c=n.depthRenderbuffer;const d=OB(t);let p;if(u?(n.cubeFramebuffers||(n.cubeFramebuffers={}),p=n.cubeFramebuffers[d]):(n.framebuffers||(n.framebuffers={}),p=n.framebuffers[d]),void 0===p){p=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,p);const i=t.textures;if(u){n.cubeFramebuffers[d]=p;const{textureGPU:t}=this.get(i[0]),s=this.renderer._activeCubeFace;e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+s,t,0)}else{n.framebuffers[d]=p;for(let s=0;s<i.length;s++){const r=i[s],n=this.get(r);n.renderTarget=t.renderTarget;const o=e.COLOR_ATTACHMENT0+s;e.framebufferTexture2D(e.FRAMEBUFFER,o,e.TEXTURE_2D,n.textureGPU,0)}s.drawBuffers(t,p)}if(null!==t.depthTexture){const s=this.get(t.depthTexture),i=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;e.framebufferTexture2D(e.FRAMEBUFFER,i,e.TEXTURE_2D,s.textureGPU,0)}}if(o>0){if(void 0===l){const i=[];l=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,l);const r=[],u=t.textures;for(let s=0;s<u.length;s++){if(r[s]=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,r[s]),i.push(e.COLOR_ATTACHMENT0+s),a){const t=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(t)}const n=t.textures[s],u=this.get(n);e.renderbufferStorageMultisample(e.RENDERBUFFER,o,u.glInternalFormat,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+s,e.RENDERBUFFER,r[s])}if(n.msaaFrameBuffer=l,n.msaaRenderbuffers=r,void 0===c){c=e.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(c,t),n.depthRenderbuffer=c;const s=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(s)}n.invalidationArray=i}i=n.msaaFrameBuffer}else i=p}s.bindFramebuffer(e.FRAMEBUFFER,i)}_getVaoKey(t,e){let s=[];if(null!==t){s+=":"+this.get(t).id}for(let t=0;t<e.length;t++){s+=":"+this.get(e[t]).id}return s}_createVao(t,e){const{gl:s}=this,i=s.createVertexArray();let r="",n=!0;if(s.bindVertexArray(i),null!==t){const e=this.get(t);s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,e.bufferGPU),r+=":"+e.id}for(let t=0;t<e.length;t++){const i=e[t],o=this.get(i);let a,h;r+=":"+o.id,s.bindBuffer(s.ARRAY_BUFFER,o.bufferGPU),s.enableVertexAttribArray(t),(i.isStorageBufferAttribute||i.isStorageInstancedBufferAttribute)&&(n=!1),!0===i.isInterleavedBufferAttribute?(a=i.data.stride*o.bytesPerElement,h=i.offset*o.bytesPerElement):(a=0,h=0),o.isInteger?s.vertexAttribIPointer(t,i.itemSize,o.type,a,h):s.vertexAttribPointer(t,i.itemSize,o.type,i.normalized,a,h),i.isInstancedBufferAttribute&&!i.isInterleavedBufferAttribute?s.vertexAttribDivisor(t,i.meshPerAttribute):i.isInterleavedBufferAttribute&&i.data.isInstancedInterleavedBuffer&&s.vertexAttribDivisor(t,i.data.meshPerAttribute)}return s.bindBuffer(s.ARRAY_BUFFER,null),this.vaoCache[r]=i,{vaoGPU:i,staticVao:n}}_getTransformFeedback(t){let e="";for(let s=0;s<t.length;s++)e+=":"+t[s].id;let s=this.transformFeedbackCache[e];if(void 0!==s)return s;const{gl:i}=this;s=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,s);for(let e=0;e<t.length;e++){const s=t[e];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,e,s.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[e]=s,s}_setupBindings(t,e){const s=this.gl;for(const i of t)for(const t of i.bindings){const i=this.get(t).index;if(t.isUniformsGroup||t.isUniformBuffer){const r=s.getUniformBlockIndex(e,t.name);s.uniformBlockBinding(e,r,i)}else if(t.isSampledTexture){const r=s.getUniformLocation(e,t.name);s.uniform1i(r,i)}}}_bindUniforms(t){const{gl:e,state:s}=this;for(const i of t)for(const t of i.bindings){const i=this.get(t),r=i.index;t.isUniformsGroup||t.isUniformBuffer?s.bindBufferBase(e.UNIFORM_BUFFER,r,i.bufferGPU):t.isSampledTexture&&s.bindTexture(i.glTextureType,i.textureGPU,e.TEXTURE0+r)}}}class GI extends sI{constructor(t,e){super(t),this.texture=e,this.version=e?e.version:0,this.isSampler=!0}}class WI extends GI{constructor(t,e,s){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s}update(){this.texture=this.textureNode.value}}class jI extends iI{constructor(t,e){super(t,e?e.array:null),this.attribute=e,this.isStorageBuffer=!0}}let HI=0;class $I extends jI{constructor(t,e){super("StorageBuffer_"+HI++,t?t.value:null),this.nodeUniform=t,this.access=t?t.access:mN,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class qI extends $w{constructor(t){super(),this.device=t;this.mipmapSampler=t.createSampler({minFilter:LA}),this.flipYSampler=t.createSampler({minFilter:VA}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=t.createShaderModule({label:"mipmapVertex",code:"\nstruct VarysStruct {\n\t@builtin( position ) Position: vec4<f32>,\n\t@location( 0 ) vTex : vec2<f32>\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( -1.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 ),\n\t\tvec2<f32>( -1.0, -1.0 ),\n\t\tvec2<f32>( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( 0.0, 0.0 ),\n\t\tvec2<f32>( 1.0, 0.0 ),\n\t\tvec2<f32>( 0.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=t.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=t.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(t){let e=this.transferPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({label:`mipmap-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:fA,stripIndexFormat:PA},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({label:`flipY-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:fA,stripIndexFormat:PA},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,s=0){const i=e.format,{width:r,height:n}=e.size,o=this.getTransferPipeline(i),a=this.getFlipYPipeline(i),h=this.device.createTexture({size:{width:r,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,s)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:NA,storeOp:MA,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,u,l),d(a,l,u),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.get(t);void 0===i.useCount&&(i.useCount=0,i.layers=[]);const r=i.layers[s]||this._mipmapCreateBundles(t,e,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,r),this.device.queue.submit([n.finish()]),0!==i.useCount&&(i.layers[s]=r),i.useCount++}_mipmapCreateBundles(t,e,s){const i=this.getTransferPipeline(e.format),r=i.getBindGroupLayout(0);let n=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:MN,baseArrayLayer:s});const o=[];for(let a=1;a<e.mipLevelCount;a++){const h=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:n}]}),u=t.createView({baseMipLevel:a,mipLevelCount:1,dimension:MN,baseArrayLayer:s}),l={colorAttachments:[{view:u,loadOp:NA,storeOp:MA,clearValue:[0,0,0,0]}]},c=this.device.createRenderBundleEncoder({colorFormats:[e.format]});c.setPipeline(i),c.setBindGroup(0,h),c.draw(4,1,0,0),o.push({renderBundles:[c.finish()],passDescriptor:l}),n=u}return o}_mipmapRunBundles(t,e){const s=e.length;for(let i=0;i<s;i++){const s=e[i],r=t.beginRenderPass(s.passDescriptor);r.executeBundles(s.renderBundles),r.end()}}}const XI={512:"never",[ys]:"less",514:"equal",515:"less-equal",516:"greater",518:"greater-equal",519:"always",517:"not-equal"},YI=[0,1,3,2,4,5];class ZI{constructor(t){this.backend=t,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new $a,this.depthTexture.name="depthBuffer"}createSampler(t){const e=this.backend,s=e.device,i=e.get(t),r={addressModeU:this._convertAddressMode(t.wrapS),addressModeV:this._convertAddressMode(t.wrapT),addressModeW:this._convertAddressMode(t.wrapR),magFilter:this._convertFilterMode(t.magFilter),minFilter:this._convertFilterMode(t.minFilter),mipmapFilter:this._convertFilterMode(t.minFilter),maxAnisotropy:t.anisotropy};t.isDepthTexture&&null!==t.compareFunction&&(r.compare=XI[t.compareFunction]),i.sampler=s.createSampler(r)}createDefaultTexture(t){let e;const s=JI(t);t.isCubeTexture?e=this._getDefaultCubeTextureGPU(s):t.isVideoTexture?this.backend.get(t).externalTexture=this._getDefaultVideoFrame():e=this._getDefaultTextureGPU(s),this.backend.get(t).texture=e}createTexture(t,e={}){const s=this.backend,i=s.get(t);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");void 0===e.needsMipmaps&&(e.needsMipmaps=!1),void 0===e.levels&&(e.levels=1),void 0===e.depth&&(e.depth=1);const{width:r,height:n,depth:o,levels:a}=e,h=this._getDimension(t),u=t.internalFormat||e.format||JI(t,s.device);i.format=u;let l=void 0!==e.sampleCount?e.sampleCount:1;l=s.utils.getSampleCount(l);const c=t.isRenderTargetTexture&&!t.isMultisampleRenderTargetTexture?1:l;let d=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===t.isStorageTexture&&(d|=GPUTextureUsage.STORAGE_BINDING),!0!==t.isCompressedTexture&&!0!==t.isCompressedArrayTexture&&(d|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:t.name,size:{width:r,height:n,depthOrArrayLayers:o},mipLevelCount:a,sampleCount:c,dimension:h,format:u,usage:d};if(t.isVideoTexture){const e=t.source.data,s=new VideoFrame(e);p.size.width=s.displayWidth,p.size.height=s.displayHeight,s.close(),i.externalTexture=e}else{if(void 0===u)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(t);i.texture=s.device.createTexture(p)}if(t.isRenderTargetTexture&&l>1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=l,i.msaaTexture=s.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,s=e.get(t);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),e.delete(t)}destroySampler(t){delete this.backend.get(t).sampler}generateMipmaps(t){const e=this.backend.get(t);if(t.isCubeTexture)for(let t=0;t<6;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t);else{const s=t.image.depth||1;for(let t=0;t<s;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t)}}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const t=this.backend,{width:e,height:s}=t.getDrawingBufferSize();return this.colorBuffer=t.device.createTexture({label:"colorBuffer",size:{width:e,height:s,depthOrArrayLayers:1},sampleCount:t.utils.getSampleCount(t.renderer.samples),format:t.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(t=!0,e=!1){const s=this.backend,{width:i,height:r}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,h;if(e?(a=jt,h=Ot):t&&(a=Wt,h=Bt),void 0!==o){if(n.image.width===i&&n.image.height===r&&n.format===a&&n.type===h)return o;this.destroyTexture(n)}return n.name="depthBuffer",n.format=a,n.type=h,n.image.width=i,n.image.height=r,this.createTexture(n,{sampleCount:s.utils.getSampleCount(s.renderer.samples),width:i,height:r}),s.get(n).texture}updateTexture(t,e){const s=this.backend.get(t),{textureDescriptorGPU:i}=s;if(!t.isRenderTargetTexture&&void 0!==i){if(t.isDataTexture)this._copyBufferToTexture(e.image,s.texture,i,0,t.flipY);else if(t.isDataArrayTexture||t.isData3DTexture)for(let r=0;r<e.image.depth;r++)this._copyBufferToTexture(e.image,s.texture,i,r,t.flipY,r);else if(t.isCompressedTexture||t.isCompressedArrayTexture)this._copyCompressedBufferToTexture(t.mipmaps,s.texture,i);else if(t.isCubeTexture)this._copyCubeMapToTexture(e.images,s.texture,i,t.flipY);else if(t.isVideoTexture){const e=t.source.data;s.externalTexture=e}else this._copyImageToTexture(e.image,s.texture,i,0,t.flipY);s.version=t.version,t.onUpdate&&t.onUpdate(t)}}async copyTextureToBuffer(t,e,s,i,r,n){const o=this.backend.device,a=this.backend.get(t),h=a.texture,u=a.textureDescriptorGPU.format,l=this._getBytesPerTexel(u);let c=i*l;c=256*Math.ceil(c/256);const d=o.createBuffer({size:i*r*l,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=o.createCommandEncoder();p.copyTextureToBuffer({texture:h,origin:{x:e,y:s,z:n}},{buffer:d,bytesPerRow:c},{width:i,height:r});const m=this._getTypedArrayType(u);o.queue.submit([p.finish()]),await d.mapAsync(GPUMapMode.READ);return new m(d.getMappedRange())}_isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_getDefaultTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const s=new yi;s.minFilter=ft,s.magFilter=ft,this.createTexture(s,{width:1,height:1,format:t}),this.defaultTexture[t]=e=s}return this.backend.get(e).texture}_getDefaultCubeTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const s=new Xn;s.minFilter=ft,s.magFilter=ft,this.createTexture(s,{width:1,height:1,depth:6}),this.defaultCubeTexture[t]=e=s}return this.backend.get(e).texture}_getDefaultVideoFrame(){let t=this.defaultVideoFrame;if(null===t){const e={timestamp:0,codedWidth:1,codedHeight:1,format:"RGBA"};this.defaultVideoFrame=t=new VideoFrame(new Uint8Array([0,0,0,255]),e)}return t}_copyCubeMapToTexture(t,e,s,i){for(let r=0;r<6;r++){const n=t[r],o=!0===i?YI[r]:r;n.isDataTexture?this._copyBufferToTexture(n.image,e,s,o,i):this._copyImageToTexture(n,e,s,o,i)}}_copyImageToTexture(t,e,s,i,r){this.backend.device.queue.copyExternalImageToTexture({source:t},{texture:e,mipLevel:0,origin:{x:0,y:0,z:i}},{width:t.width,height:t.height,depthOrArrayLayers:1}),!0===r&&this._flipY(e,s,i)}_getPassUtils(){let t=this._passUtils;return null===t&&(this._passUtils=t=new qI(this.backend.device)),t}_generateMipmaps(t,e,s=0){this._getPassUtils().generateMipmaps(t,e,s)}_flipY(t,e,s=0){this._getPassUtils().flipY(t,e,s)}_copyBufferToTexture(t,e,s,i,r,n=0){const o=this.backend.device,a=t.data,h=this._getBytesPerTexel(s.format),u=t.width*h;o.queue.writeTexture({texture:e,mipLevel:0,origin:{x:0,y:0,z:i}},a,{offset:t.width*t.height*h*n,bytesPerRow:u},{width:t.width,height:t.height,depthOrArrayLayers:1}),!0===r&&this._flipY(e,s,i)}_copyCompressedBufferToTexture(t,e,s){const i=this.backend.device,r=this._getBlockData(s.format),n=s.size.depthOrArrayLayers>1;for(let o=0;o<t.length;o++){const a=t[o],h=a.width,u=a.height,l=n?s.size.depthOrArrayLayers:1,c=Math.ceil(h/r.width)*r.byteLength,d=c*Math.ceil(u/r.height);for(let t=0;t<l;t++)i.queue.writeTexture({texture:e,mipLevel:o,origin:{x:0,y:0,z:t}},a.data,{offset:t*d,bytesPerRow:c,rowsPerImage:Math.ceil(u/r.height)},{width:Math.ceil(h/r.width)*r.width,height:Math.ceil(u/r.height)*r.height,depthOrArrayLayers:1})}}_getBlockData(t){return t===FA.BC1RGBAUnorm||t===FA.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:t===FA.BC2RGBAUnorm||t===FA.BC2RGBAUnormSRGB||t===FA.BC3RGBAUnorm||t===FA.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===FA.BC4RUnorm||t===FA.BC4RSNorm?{byteLength:8,width:4,height:4}:t===FA.BC5RGUnorm||t===FA.BC5RGSnorm||t===FA.BC6HRGBUFloat||t===FA.BC6HRGBFloat||t===FA.BC7RGBAUnorm||t===FA.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===FA.ETC2RGB8Unorm||t===FA.ETC2RGB8UnormSRGB||t===FA.ETC2RGB8A1Unorm||t===FA.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:t===FA.ETC2RGBA8Unorm||t===FA.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:t===FA.EACR11Unorm||t===FA.EACR11Snorm?{byteLength:8,width:4,height:4}:t===FA.EACRG11Unorm||t===FA.EACRG11Snorm||t===FA.ASTC4x4Unorm||t===FA.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:t===FA.ASTC5x4Unorm||t===FA.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:t===FA.ASTC5x5Unorm||t===FA.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:t===FA.ASTC6x5Unorm||t===FA.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:t===FA.ASTC6x6Unorm||t===FA.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:t===FA.ASTC8x5Unorm||t===FA.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:t===FA.ASTC8x6Unorm||t===FA.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:t===FA.ASTC8x8Unorm||t===FA.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:t===FA.ASTC10x5Unorm||t===FA.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:t===FA.ASTC10x6Unorm||t===FA.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:t===FA.ASTC10x8Unorm||t===FA.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:t===FA.ASTC10x10Unorm||t===FA.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:t===FA.ASTC12x10Unorm||t===FA.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:t===FA.ASTC12x12Unorm||t===FA.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(t){let e=UA;return t===pt?e=OA:t===gt&&(e=zA),e}_convertFilterMode(t){let e=LA;return t!==ft&&t!==yt&&t!==bt||(e=VA),e}_getBytesPerTexel(t){return t===FA.R8Unorm||t===FA.R8Snorm||t===FA.R8Uint||t===FA.R8Sint?1:t===FA.R16Uint||t===FA.R16Sint||t===FA.R16Float||t===FA.RG8Unorm||t===FA.RG8Snorm||t===FA.RG8Uint||t===FA.RG8Sint?2:t===FA.R32Uint||t===FA.R32Sint||t===FA.R32Float||t===FA.RG16Uint||t===FA.RG16Sint||t===FA.RG16Float||t===FA.RGBA8Unorm||t===FA.RGBA8UnormSRGB||t===FA.RGBA8Snorm||t===FA.RGBA8Uint||t===FA.RGBA8Sint||t===FA.BGRA8Unorm||t===FA.BGRA8UnormSRGB||t===FA.RGB9E5UFloat||t===FA.RGB10A2Unorm||t===FA.RG11B10UFloat||t===FA.Depth32Float||t===FA.Depth24Plus||t===FA.Depth24PlusStencil8||t===FA.Depth32FloatStencil8?4:t===FA.RG32Uint||t===FA.RG32Sint||t===FA.RG32Float||t===FA.RGBA16Uint||t===FA.RGBA16Sint||t===FA.RGBA16Float?8:t===FA.RGBA32Uint||t===FA.RGBA32Sint||t===FA.RGBA32Float?16:void 0}_getTypedArrayType(t){return t===FA.R8Uint?Uint8Array:t===FA.R8Sint?Int8Array:t===FA.R8Unorm?Uint8Array:t===FA.R8Snorm?Int8Array:t===FA.RG8Uint?Uint8Array:t===FA.RG8Sint?Int8Array:t===FA.RG8Unorm?Uint8Array:t===FA.RG8Snorm?Int8Array:t===FA.RGBA8Uint?Uint8Array:t===FA.RGBA8Sint?Int8Array:t===FA.RGBA8Unorm?Uint8Array:t===FA.RGBA8Snorm?Int8Array:t===FA.R16Uint?Uint16Array:t===FA.R16Sint?Int16Array:t===FA.RG16Uint?Uint16Array:t===FA.RG16Sint?Int16Array:t===FA.RGBA16Uint?Uint16Array:t===FA.RGBA16Sint?Int16Array:t===FA.R16Float||t===FA.RG16Float||t===FA.RGBA16Float?Uint16Array:t===FA.R32Uint?Uint32Array:t===FA.R32Sint?Int32Array:t===FA.R32Float?Float32Array:t===FA.RG32Uint?Uint32Array:t===FA.RG32Sint?Int32Array:t===FA.RG32Float?Float32Array:t===FA.RGBA32Uint?Uint32Array:t===FA.RGBA32Sint?Int32Array:t===FA.RGBA32Float?Float32Array:t===FA.BGRA8Unorm||t===FA.BGRA8UnormSRGB?Uint8Array:t===FA.RGB10A2Unorm||t===FA.RGB9E5UFloat||t===FA.RG11B10UFloat?Uint32Array:t===FA.Depth32Float?Float32Array:t===FA.Depth24Plus||t===FA.Depth24PlusStencil8?Uint32Array:t===FA.Depth32FloatStencil8?Float32Array:void 0}_getDimension(t){let e;return e=t.isData3DTexture?SN:wN,e}}function JI(t,e=null){const s=t.format,i=t.type,r=t.colorSpace;let n;if(!0===t.isFramebufferTexture&&t.type===At)n=FA.BGRA8Unorm;else if(!0===t.isCompressedTexture||!0===t.isCompressedArrayTexture)switch(s){case Kt:n=r===Ze?FA.BC1RGBAUnormSRGB:FA.BC1RGBAUnorm;break;case Qt:n=r===Ze?FA.BC2RGBAUnormSRGB:FA.BC2RGBAUnorm;break;case te:n=r===Ze?FA.BC3RGBAUnormSRGB:FA.BC3RGBAUnorm;break;case oe:n=r===Ze?FA.ETC2RGB8UnormSRGB:FA.ETC2RGB8Unorm;break;case ae:n=r===Ze?FA.ETC2RGBA8UnormSRGB:FA.ETC2RGBA8Unorm;break;case he:n=r===Ze?FA.ASTC4x4UnormSRGB:FA.ASTC4x4Unorm;break;case ue:n=r===Ze?FA.ASTC5x4UnormSRGB:FA.ASTC5x4Unorm;break;case le:n=r===Ze?FA.ASTC5x5UnormSRGB:FA.ASTC5x5Unorm;break;case ce:n=r===Ze?FA.ASTC6x5UnormSRGB:FA.ASTC6x5Unorm;break;case de:n=r===Ze?FA.ASTC6x6UnormSRGB:FA.ASTC6x6Unorm;break;case pe:n=r===Ze?FA.ASTC8x5UnormSRGB:FA.ASTC8x5Unorm;break;case me:n=r===Ze?FA.ASTC8x6UnormSRGB:FA.ASTC8x6Unorm;break;case ge:n=r===Ze?FA.ASTC8x8UnormSRGB:FA.ASTC8x8Unorm;break;case fe:n=r===Ze?FA.ASTC10x5UnormSRGB:FA.ASTC10x5Unorm;break;case ye:n=r===Ze?FA.ASTC10x6UnormSRGB:FA.ASTC10x6Unorm;break;case xe:n=r===Ze?FA.ASTC10x8UnormSRGB:FA.ASTC10x8Unorm;break;case be:n=r===Ze?FA.ASTC10x10UnormSRGB:FA.ASTC10x10Unorm;break;case ve:n=r===Ze?FA.ASTC12x10UnormSRGB:FA.ASTC12x10Unorm;break;case Te:n=r===Ze?FA.ASTC12x12UnormSRGB:FA.ASTC12x12Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}else switch(s){case Dt:switch(i){case Nt:n=FA.RGBA8Snorm;break;case Ct:n=FA.RGBA16Sint;break;case Rt:n=FA.RGBA16Uint;break;case Bt:n=FA.RGBA32Uint;break;case Et:n=FA.RGBA32Sint;break;case At:n=r===Ze?FA.RGBA8UnormSRGB:FA.RGBA8Unorm;break;case Pt:n=FA.RGBA16Float;break;case It:n=FA.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",i)}break;case Vt:if(i===zt)n=FA.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",i);break;case Ht:switch(i){case Nt:n=FA.R8Snorm;break;case Ct:n=FA.R16Sint;break;case Rt:n=FA.R16Uint;break;case Bt:n=FA.R32Uint;break;case Et:n=FA.R32Sint;break;case At:n=FA.R8Unorm;break;case Pt:n=FA.R16Float;break;case It:n=FA.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",i)}break;case qt:switch(i){case Nt:n=FA.RG8Snorm;break;case Ct:n=FA.RG16Sint;break;case Rt:n=FA.RG16Uint;break;case Bt:n=FA.RG32Uint;break;case Et:n=FA.RG32Sint;break;case At:n=FA.RG8Unorm;break;case Pt:n=FA.RG16Float;break;case It:n=FA.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",i)}break;case Wt:switch(i){case Rt:n=FA.Depth16Unorm;break;case Bt:n=FA.Depth24Plus;break;case It:n=FA.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",i)}break;case jt:switch(i){case Ot:n=FA.Depth24PlusStencil8;break;case It:e&&!1===e.features.has(IN.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),n=FA.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",i)}break;case $t:switch(i){case Et:n=FA.R32Sint;break;case Bt:n=FA.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",i)}break;case Xt:switch(i){case Et:n=FA.RG32Sint;break;case Bt:n=FA.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",i)}break;case Zt:switch(i){case Et:n=FA.RGBA32Sint;break;case Bt:n=FA.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",i)}break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}return n}const KI=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,QI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,tP={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<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_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class eP extends SB{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(KI);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=QI.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let t=0;t<i.length;t++){const{name:e,type:s}=i[t];let r=s;r.startsWith("texture")?r=s.split("<")[0]:r.startsWith("ptr")&&(r="pointer"),r=tP[r]||r,n.push(new xM(r,e))}const o=t.substring(e[0].length),a=e[3]||"void",h=void 0!==e[1]?e[1]:"";return{type:tP[a]||a,inputs:n,name:h,inputsCode:s,blockCode:o,outputType:a}}throw new Error("FunctionNode: Function is not a WGSL code.")})(t);super(e,s,i),this.inputsCode=r,this.blockCode=n,this.outputType=o}getCode(t=this.name){const e="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class sP extends wB{parseFunction(t){return new eP(t)}}const iP=self.GPUShaderStage,rP={vertex:iP?iP.VERTEX:1,fragment:iP?iP.FRAGMENT:2,compute:iP?iP.COMPUTE:4},nP={instance:!0,swizzleAssign:!1,storageBuffer:!0},oP={"^^":"tsl_xor"},aP={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<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>",imat2:"mat2x2<i32>",umat2:"mat2x2<u32>",bmat2:"mat2x2<bool>",mat3:"mat3x3<f32>",imat3:"mat3x3<i32>",umat3:"mat3x3<u32>",bmat3:"mat3x3<bool>",mat4:"mat4x4<f32>",imat4:"mat4x4<i32>",umat4:"mat4x4<u32>",bmat4:"mat4x4<bool>"},hP={tsl_xor:new xS("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new xS("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new xS("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new xS("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new xS("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new xS("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new xS("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new xS("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 xS("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:new xS("\nfn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {\n\n\tlet uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new xS("\nfn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet iRes = vec2i( textureDimensions( map, level ) );\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},uP={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"};/Windows/g.test(navigator.userAgent)&&(hP.pow_float=new xS("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),hP.pow_vec2=new xS("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[hP.pow_float]),hP.pow_vec3=new xS("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[hP.pow_float]),hP.pow_vec4=new xS("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[hP.pow_float]),uP.pow_float="tsl_pow_float",uP.pow_vec2="tsl_pow_vec2",uP.pow_vec3="tsl_pow_vec3",uP.pow_vec4="tsl_pow_vec4");let lP="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(lP+="diagnostic( off, derivative_uniformity );\n");class cP extends fM{constructor(t,e){super(t,e,new sP),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}_generateTextureSample(t,e,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${s}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${s} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s):this.generateTextureLod(t,e,s,"0")}_generateVideoSample(t,e,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2<f32>( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(t,e,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${s}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s,i):this.generateTextureLod(t,e,s,i)}generateFilteredTexture(t,e,s,i="0"){return this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, tsl_repeatWrapping( ${s}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,s,i,r="0u"){return i?`textureLoad( ${e}, ${s}, ${i}, ${r} )`:`textureLoad( ${e}, ${s}, ${r} )`}generateTextureStore(t,e,s,i){return`textureStore( ${e}, ${s}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!this.isAvailable("float32Filterable")&&!0===t.isDataTexture&&t.type===It||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,s,i,r=this.shaderStage){let n=null;return n=!0===t.isVideoTexture?this._generateVideoSample(e,s,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,s,"0",i,r):this._generateTextureSample(t,e,s,i,r),n}generateTextureGrad(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${e}, ${e}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(t,e,s,i,r,n=this.shaderStage){let o=null;return o=!0===t.isVideoTexture?this._generateVideoSample(e,s,n):this._generateTextureSampleLevel(t,e,s,i,r,n),o}generateTextureBias(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(t,e=this.shaderStage){if(!0===t.isNodeVarying&&!0===t.needsInterpolation){if("vertex"===e)return`varyings.${t.name}`}else if(!0===t.isNodeUniform){const e=t.name,s=t.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?e:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${t.id}.${e}`:t.groupNode.name+"."+e}return super.getPropertyName(t)}getOutputStructName(){return"output"}_getUniformGroupCount(t){return Object.keys(this.uniforms[t]).length}getFunctionOperator(t){const e=oP[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case yN:return"read";case fN:return"write";default:return"read_write"}else switch(t.access){case mN:return"read_write";case gN:return"read";default:return"write"}}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=t.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let n=null;if("texture"===e||"storageTexture"===e?n=new dI(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new pI(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new mI(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(rP[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new WI(`${r.name}_sampler`,r.node,o);t.setVisibility(rP[s]),h.push(t,n),i=[t,n]}else h.push(n),i=[n]}else if("buffer"===e||"storageBuffer"===e){const r=new("storageBuffer"===e?$I:oI)(t,o);r.setVisibility(rP[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new uI(a,o),n.setVisibility(rP[s]),t[a]=n,h.push(n)),i=this.getNodeUniform(r,e),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(t,e,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(t)&&r.set(t,{name:t,property:e,type:s}),e}hasBuiltin(t,e=this.shaderStage){return void 0!==this.builtins[e]&&this.builtins[e].has(t)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));let r=`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(r+=`\treturn ${s.result};\n`),r+="\n}\n",r}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}enableDirective(t,e=this.shaderStage){(this.directives[e]||(this.directives[e]=new Set)).add(t)}getDirectives(t){const e=[],s=this.directives[t];if(void 0!==s)for(const t of s)e.push(`enable ${t};`);return e.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}getBuiltins(t){const e=[],s=this.builtins[t];if(void 0!==s)for(const{name:t,property:i,type:r}of s.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getScopedArray(t,e,s,i){return!1===this.scopedArrays.has(t)&&this.scopedArrays.set(t,{name:t,scope:e,bufferType:s,bufferCount:i}),t}getScopedArrays(t){if("compute"!==t)return;const e=[];for(const{name:t,scope:s,bufferType:i,bufferCount:r}of this.scopedArrays.values()){const n=this.getType(i);e.push(`var<${s}> ${t}: array< ${n}, ${r} >;`)}return e.join("\n")}getAttributes(t){const e=[];if("compute"===t&&(this.getBuiltin("global_invocation_id","id","vec3<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",t),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const s=this.getAttributesArray();for(let t=0,i=s.length;t<i;t++){const i=s[t],r=i.name,n=this.getType(i.type);e.push(`@location( ${t} ) ${r} : ${n}`)}}return e.join(",\n\t")}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t<s.length;t++){const i=s[t];e.push(`\t@location( ${t} ) m${t} : ${i}<f32>`)}const i=this.getBuiltins("output");return i&&e.push("\t"+i),e.join(",\n")}getStructs(t){const e=[],s=this.structs[t];for(let t=0,i=s.length;t<i;t++){const i=s[t],r=i.name;let n=`struct ${r} {\n`;n+=this.getStructMembers(i),n+="\n}",e.push(n),e.push(`\nvar<private> output : ${r};\n\n`)}return e.join("\n\n")}getVar(t,e){return`var ${e} : ${this.getType(t)}`}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`\t${this.getVar(t.type,t.name)};`);return`\n${e.join("\n")}\n`}getVaryings(t){const e=[];if("vertex"===t&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),"vertex"===t||"fragment"===t){const s=this.varyings,i=this.vars[t];for(let r=0;r<s.length;r++){const n=s[r];if(n.needsInterpolation){let t=`@location( ${r} )`;/^(int|uint|ivec|uvec)/.test(n.type)&&(t+=" @interpolate( flat )"),e.push(`${t} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===t&&!1===i.includes(n)&&i.push(n)}}const s=this.getBuiltins(t);s&&e.push(s);const i=e.join(",\n\t");return"vertex"===t?this._getWGSLStruct("VaryingsStruct","\t"+i):i}getUniforms(t){const e=this.uniforms[t],s=[],i=[],r=[],n={};for(const r of e){const e=r.groupNode.name,o=this.bindingsIndexes[e];if("texture"===r.type||"cubeTexture"===r.type||"storageTexture"===r.type||"texture3D"===r.type){const e=r.node.value;let i;"fragment"===t&&!1===this.isUnfilterable(e)&&!0!==r.node.isStorageTextureNode&&(!0===e.isDepthTexture&&null!==e.compareFunction?s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler_comparison;`):s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler;`));let n="";if(!0===e.isMultisampleRenderTargetTexture&&(n="_multisampled"),!0===e.isCubeTexture)i="texture_cube<f32>";else if(!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture)i="texture_2d_array<f32>";else if(!0===e.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===e.isVideoTexture)i="texture_external";else if(!0===e.isData3DTexture)i="texture_3d<f32>";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${JI(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),s=t.bufferCount,n=s>0&&"buffer"===r.type?", "+s:"",a=t.isAtomic?`atomic<${e}>`:`${e}`,h=`\t${r.name} : array< ${a}${n} >\n`,u=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,h,u,o.binding++,o.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(n[e]||(n[e]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in n){const e=n[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const e in t){const s=t[e];s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.structs=this.getStructs(e),s.vars=this.getVars(e),s.codes=this.getCodes(e),s.directives=this.getDirectives(e),s.scopedArrays=this.getScopedArrays(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),h=t.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,t===n&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4<f32>";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",t),s.structs+="\nvar<private> output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(t.vertex),this.fragmentShader=this._getWGSLFragmentCode(t.fragment)):this.computeShader=this._getWGSLComputeCode(t.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(t,e=null){let s;return null!==e&&(s=this._getWGSLMethod(t+"_"+e)),void 0===s&&(s=this._getWGSLMethod(t)),s||t}getType(t){return aP[t]||t}isAvailable(t){let e=nP[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),nP[t]=e),e}_getWGSLMethod(t){return void 0!==hP[t]&&this._include(t),uP[t]}_include(t){const e=hP[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\n// directives\n${t.directives}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\nvar<private> varyings : VaryingsStruct;\n\n// codes\n${t.codes}\n\n@vertex\nfn main( ${t.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(t){return`${this.getSignature()}\n// global\n${lP}\n\n// uniforms\n${t.uniforms}\n\n// structs\n${t.structs}\n\n// codes\n${t.codes}\n\n@fragment\nfn main( ${t.varyings} ) -> ${t.returnType} {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLComputeCode(t,e){return`${this.getSignature()}\n// directives\n${t.directives}\n\n// system\nvar<private> instanceIndex : u32;\n\n// locals\n${t.scopedArrays}\n\n// uniforms\n${t.uniforms}\n\n// codes\n${t.codes}\n\n@compute @workgroup_size( ${e} )\nfn main( ${t.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${e}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${e});\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLStruct(t,e){return`\nstruct ${t} {\n${e}\n};`}_getWGSLStructBinding(t,e,s,i=0,r=0){const n=t+"Struct";return`${this._getWGSLStruct(n,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${t} : ${n};`}}class dP{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=FA.Depth24PlusStencil8:t.depth&&(e=FA.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):this.getPreferredCanvasFormat(),e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?dA:t.isLineSegments||t.isMesh&&!0===e.wireframe?pA:t.isLine?mA:t.isMesh?gA:void 0}getSampleCount(t){let e=1;return t>1&&(e=Math.pow(2,Math.floor(Math.log2(t))),2===e&&(e=4)),e}getSampleCountRenderContext(t){return null!==t.textures?this.getSampleCount(t.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?FA.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const pP=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),mP=new Map([[gn,["float16"]]]),gP=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class fP{constructor(t){this.backend=t}createAttribute(t,e){const s=this._getBufferAttribute(t),i=this.backend,r=i.get(s);let n=r.buffer;if(void 0===n){const o=i.device;let a=s.array;if(!1===t.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const t=new Uint32Array(a.length);for(let e=0;e<a.length;e++)t[e]=a[e];a=t}if(s.array=a,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&3===s.itemSize){a=new a.constructor(4*s.count);for(let t=0;t<s.count;t++)a.set(s.array.subarray(3*t,3*t+3),4*t);s.itemSize=4,s.array=a}const h=a.byteLength+(4-a.byteLength%4)%4;n=o.createBuffer({label:s.name,size:h,usage:e,mappedAtCreation:!0}),new a.constructor(n.getMappedRange()).set(a),n.unmap(),r.buffer=n}}updateAttribute(t){const e=this._getBufferAttribute(t),s=this.backend,i=s.device,r=s.get(e).buffer,n=e.array,o=e.updateRanges;if(0===o.length)i.queue.writeBuffer(r,0,n,0);else{for(let t=0,e=o.length;t<e;t++){const e=o[t];i.queue.writeBuffer(r,0,n,e.start*n.BYTES_PER_ELEMENT,e.count*n.BYTES_PER_ELEMENT)}e.clearUpdateRanges()}}createShaderVertexBuffers(t){const e=t.getAttributes(),s=new Map;for(let t=0;t<e.length;t++){const i=e[t],r=i.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(i);let o=s.get(n);if(void 0===o){let t,e;!0===i.isInterleavedBufferAttribute?(t=i.data.stride*r,e=i.data.isInstancedInterleavedBuffer?BN:EN):(t=i.itemSize*r,e=i.isInstancedBufferAttribute?BN:EN),!1!==i.normalized||i.array.constructor!==Int16Array&&i.array.constructor!==Uint16Array||(t=4),o={arrayStride:t,attributes:[],stepMode:e},s.set(n,o)}const a=this._getVertexFormat(i),h=!0===i.isInterleavedBufferAttribute?i.offset*r:0;o.attributes.push({shaderLocation:t,offset:h,format:a})}return Array.from(s.values())}destroyAttribute(t){const e=this.backend;e.get(this._getBufferAttribute(t)).buffer.destroy(),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,s=e.device,i=e.get(this._getBufferAttribute(t)).buffer,r=i.size,n=s.createBuffer({label:t.name,size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),o=s.createCommandEncoder({});o.copyBufferToBuffer(i,0,n,0,r),n.unmap();const a=o.finish();s.queue.submit([a]),await n.mapAsync(GPUMapMode.READ);return n.getMappedRange()}_getVertexFormat(t){const{itemSize:e,normalized:s}=t,i=t.array.constructor,r=t.constructor;let n;if(1==e)n=gP.get(i);else{const t=(mP.get(r)||pP.get(i))[s?1:0];if(t){const s=i.BYTES_PER_ELEMENT*e,r=4*Math.floor((s+3)/4)/i.BYTES_PER_ELEMENT;if(r%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");n=`${t}x${r}`}}return n||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),n}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}class yP{constructor(t){this.backend=t,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(t){const e=this.backend.device,s=[];let i=0;for(const e of t.bindings){const t={binding:i++,visibility:e.visibility};if(e.isUniformBuffer||e.isStorageBuffer){const s={};e.isStorageBuffer&&(s.type=e.access),t.buffer=s}else if(e.isSampler){const s={};e.texture.isDepthTexture&&null!==e.texture.compareFunction&&(s.type="comparison"),t.sampler=s}else if(e.isSampledTexture&&e.texture.isVideoTexture)t.externalTexture={};else if(e.isSampledTexture&&e.store){const s=this.backend.get(e.texture).texture.format,i=e.access;t.storageTexture={format:s,access:i}}else if(e.isSampledTexture){const s={};if(!0===e.texture.isMultisampleRenderTargetTexture&&(s.multisampled=!0),e.texture.isDepthTexture)s.sampleType=vN;else if(e.texture.isDataTexture||e.texture.isDataArrayTexture||e.texture.isData3DTexture){const t=e.texture.type;t===Et?s.sampleType=TN:t===Bt?s.sampleType=_N:t===It&&(this.backend.hasFeature("float32-filterable")?s.sampleType=xN:s.sampleType=bN)}e.isSampledCubeTexture?s.viewDimension=NN:e.texture.isDataArrayTexture||e.texture.isCompressedArrayTexture?s.viewDimension=AN:e.isSampledTexture3D&&(s.viewDimension=CN),t.texture=s}else console.error(`WebGPUBindingUtils: Unsupported binding "${e}".`);s.push(t)}return e.createBindGroupLayout({entries:s})}createBindings(t){const{backend:e,bindGroupLayoutCache:s}=this,i=e.get(t);let r=s.get(t.bindingsReference);void 0===r&&(r=this.createBindingsLayout(t),s.set(t.bindingsReference,r));const n=this.createBindGroup(t,r);i.layout=r,i.group=n}updateBinding(t){const e=this.backend,s=e.device,i=t.buffer,r=e.get(t).buffer;s.queue.writeBuffer(r,0,i,0)}createBindGroup(t,e){const s=this.backend,i=s.device;let r=0;const n=[];for(const e of t.bindings){if(e.isUniformBuffer){const t=s.get(e);if(void 0===t.buffer){const s=e.byteLength,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=i.createBuffer({label:"bindingBuffer_"+e.name,size:s,usage:r});t.buffer=n}n.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isStorageBuffer){const t=s.get(e);if(void 0===t.buffer){const i=e.attribute;t.buffer=s.get(i).buffer}n.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isSampler){const t=s.get(e.texture);n.push({binding:r,resource:t.sampler})}else if(e.isSampledTexture){const t=s.get(e.texture);let o;if(void 0!==t.externalTexture)o=i.importExternalTexture({source:t.externalTexture});else{const s=e.store?1:t.texture.mipLevelCount,i=`view-${t.texture.width}-${t.texture.height}-${s}`;if(o=t[i],void 0===o){const r=RN;let n;n=e.isSampledCubeTexture?NN:e.isSampledTexture3D?CN:e.texture.isDataArrayTexture||e.texture.isCompressedArrayTexture?AN:MN,o=t[i]=t.texture.createView({aspect:r,dimension:n,mipLevelCount:s})}}n.push({binding:r,resource:o})}r++}return i.createBindGroup({label:"bindGroup_"+t.name,layout:e,entries:n})}}class xP{constructor(t){this.backend=t}_getSampleCount(t){return this.backend.utils.getSampleCountRenderContext(t)}createRenderPipeline(t,e){const{object:s,material:i,geometry:r,pipeline:n}=t,{vertexProgram:o,fragmentProgram:a}=n,h=this.backend,u=h.device,l=h.utils,c=h.get(n),d=[];for(const e of t.getBindings()){const t=h.get(e);d.push(t.layout)}const p=h.attributeUtils.createShaderVertexBuffers(t);let g;!0===i.transparent&&i.blending!==m&&(g=this._getBlending(i));let f={};!0===i.stencilWrite&&(f={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const y=this._getColorWriteMask(i),x=[];if(null!==t.context.textures){const e=t.context.textures;for(let t=0;t<e.length;t++){const s=l.getTextureFormatGPU(e[t]);x.push({format:s,blend:g,writeMask:y})}}else{const e=l.getCurrentColorFormat(t.context);x.push({format:e,blend:g,writeMask:y})}const b=h.get(o).module,v=h.get(a).module,T=this._getPrimitiveState(s,r,i),_=this._getDepthCompare(i),w=l.getCurrentDepthStencilFormat(t.context),S=this._getSampleCount(t.context),M={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},b,{buffers:p}),fragment:Object.assign({},v,{targets:x}),primitive:T,multisample:{count:S,alphaToCoverageEnabled:i.alphaToCoverage&&S>1},layout:u.createPipelineLayout({bindGroupLayouts:d})},A={},N=t.context.depth,C=t.context.stencil;if(!0!==N&&!0!==C||(!0===N&&(A.format=w,A.depthWriteEnabled=i.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=f,A.stencilBack={},A.stencilReadMask=i.stencilFuncMask,A.stencilWriteMask=i.stencilWriteMask),M.depthStencil=A),null===e)c.pipeline=u.createRenderPipeline(M);else{const t=new Promise((t=>{u.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t){const e=this.backend,{utils:s,device:i}=e,r=s.getCurrentDepthStencilFormat(t),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(t)],depthStencilFormat:r,sampleCount:this._getSampleCount(t)};return i.createRenderBundleEncoder(n)}createComputePipeline(t,e){const s=this.backend,i=s.device,r=s.get(t.computeProgram).module,n=s.get(t),o=[];for(const t of e){const e=s.get(t);o.push(e.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(t){let e,s;const i=t.blending,r=t.blendSrc,n=t.blendDst,o=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,a=null!==t.blendDstAlpha?t.blendDstAlpha:n,h=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(h)}}else{const r=(t,i,r,n)=>{e={srcFactor:t,dstFactor:i,operation:QA},s={srcFactor:r,dstFactor:n,operation:QA}};if(t.premultipliedAlpha)switch(i){case 1:r(kA,HA,kA,HA);break;case 2:r(kA,kA,kA,kA);break;case 3:r(DA,WA,DA,kA);break;case 4:r(DA,GA,DA,jA)}else switch(i){case 1:r(jA,HA,kA,HA);break;case 2:r(jA,kA,jA,kA);break;case 3:r(DA,WA,DA,kA);break;case 4:r(DA,GA,DA,GA)}}if(void 0!==e&&void 0!==s)return{color:e,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=DA;break;case 201:e=kA;break;case 202:e=GA;break;case 203:e=WA;break;case R:e=jA;break;case E:e=HA;break;case 208:e=$A;break;case 209:e=qA;break;case 206:e=XA;break;case 207:e=YA;break;case 210:e=ZA;break;case 211:e=JA;break;case 212:e=KA;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const s=t.stencilFunc;switch(s){case 512:e=yA;break;case gs:e=SA;break;case 513:e=xA;break;case 515:e=vA;break;case 514:e=bA;break;case 518:e=wA;break;case 516:e=TA;break;case 517:e=_A;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case es:e=oN;break;case 0:e=aN;break;case 7681:e=hN;break;case 5386:e=uN;break;case 7682:e=lN;break;case 7683:e=cN;break;case 34055:e=dN;break;case 34056:e=pN;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=QA;break;case 101:e=tN;break;case 102:e=eN;break;case 103:e=sN;break;case 104:e=iN;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,s),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?IA:PA),s.side){case c:i.frontFace=CA,i.cullMode=BA;break;case d:i.frontFace=CA,i.cullMode=EA;break;case 2:i.frontFace=CA,i.cullMode=RA;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?nN:rN}_getDepthCompare(t){let e;if(!1===t.depthTest)e=SA;else{const s=t.depthFunc;switch(s){case 0:e=yA;break;case 1:e=SA;break;case 2:e=xA;break;case 3:e=vA;break;case 4:e=bA;break;case 5:e=wA;break;case 6:e=TA;break;case 7:e=_A;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class bP extends wI{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.requiredLimits=void 0===t.requiredLimits?{}:t.requiredLimits,this.trackTimestamp=!0===t.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new dP(this),this.attributeUtils=new fP(this),this.bindingUtils=new yP(this),this.pipelineUtils=new xP(this),this.textureUtils=new ZI(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let s;if(void 0===e.device){const t={powerPreference:e.powerPreference},i=await navigator.gpu.requestAdapter(t);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(IN),n=[];for(const t of r)i.features.has(t)&&n.push(t);const o={requiredFeatures:n,requiredLimits:e.requiredLimits};s=await i.requestDevice(o)}else s=e.device;const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=s,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(IN.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Os}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;if(null===t){const e=this.renderer;t={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(t.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const s=t.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const e=t.colorAttachments[0];return this.renderer.samples>0?e.resolveTarget=this.context.getCurrentTexture().createView():e.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;if(void 0===i||s.width!==e.width||s.height!==e.height||s.activeMipmapLevel!==e.activeMipmapLevel||s.samples!==e.samples){i={},s.descriptors=i;const t=()=>{e.removeEventListener("dispose",t),this.delete(e)};e.addEventListener("dispose",t)}const r=t.getCacheKey();let n=i[r];if(void 0===n){const o=t.textures,a=[];for(let e=0;e<o.length;e++){const s=this.get(o[e]),i=s.texture.createView({baseMipLevel:t.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:t.activeCubeFace,dimension:MN});let r,n;void 0!==s.msaaTexture?(r=s.msaaTexture.createView(),n=i):(r=i,n=void 0),a.push({view:r,resolveTarget:n,loadOp:AA,storeOp:MA})}if(n={colorAttachments:a},t.depth){const e={view:this.get(t.depthTexture).texture.createView()};n.depthStencilAttachment=e}i[r]=n,s.width=e.width,s.height=e.height,s.samples=e.samples,s.activeMipmapLevel=e.activeMipmapLevel}return n}beginRender(t){const e=this.get(t),s=this.device,i=t.occlusionQueryCount;let r,n;i>0&&(e.currentOcclusionQuerySet&&e.currentOcclusionQuerySet.destroy(),e.currentOcclusionQueryBuffer&&e.currentOcclusionQueryBuffer.destroy(),e.currentOcclusionQuerySet=e.occlusionQuerySet,e.currentOcclusionQueryBuffer=e.occlusionQueryBuffer,e.currentOcclusionQueryObjects=e.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),n=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==t.textures){const e=n.colorAttachments;for(let s=0;s<e.length;s++){const i=e[s];t.clearColor?(i.clearValue=0===s?t.clearColorValue:{r:0,g:0,b:0,a:1},i.loadOp=NA,i.storeOp=MA):(i.loadOp=AA,i.storeOp=MA)}}else{const e=n.colorAttachments[0];t.clearColor?(e.clearValue=t.clearColorValue,e.loadOp=NA,e.storeOp=MA):(e.loadOp=AA,e.storeOp=MA)}t.depth&&(t.clearDepth?(o.depthClearValue=t.clearDepthValue,o.depthLoadOp=NA,o.depthStoreOp=MA):(o.depthLoadOp=AA,o.depthStoreOp=MA)),t.stencil&&(t.clearStencil?(o.stencilClearValue=t.clearStencilValue,o.stencilLoadOp=NA,o.stencilStoreOp=MA):(o.stencilLoadOp=AA,o.stencilStoreOp=MA));const a=s.createCommandEncoder({label:"renderContext_"+t.id}),h=a.beginRenderPass(n);if(e.descriptor=n,e.encoder=a,e.currentPass=h,e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},e.renderBundles=[],t.viewport&&this.updateViewport(t),t.scissor){const{x:e,y:s,width:i,height:r}=t.scissorValue;h.setScissorRect(e,s,i,r)}}finishRender(t){const e=this.get(t),s=t.occlusionQueryCount;if(e.renderBundles.length>0&&e.currentPass.executeBundles(e.renderBundles),s>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),s>0){const i=8*s;let r=this.occludedResolveCache.get(i);void 0===r&&(r=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,r));const n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,s,r,0),e.encoder.copyBufferToBuffer(r,0,n,0,i),e.occlusionQueryBuffer=n,this.resolveOccludedAsync(t)}if(this.prepareTimestampBuffer(t,e.encoder),this.device.queue.submit([e.encoder.finish()]),null!==t.textures){const e=t.textures;for(let t=0;t<e.length;t++){const s=e[t];!0===s.generateMipmaps&&this.textureUtils.generateMipmaps(s)}}}isOccluded(t,e){const s=this.get(t);return s.occluded&&s.occluded.has(e)}async resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueryBuffer:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);const r=s.getMappedRange(),n=new BigUint64Array(r);for(let e=0;e<i.length;e++)n[e]!==BigInt(0)&&t.add(i[e]);s.destroy(),e.occluded=t}}updateViewport(t){const{currentPass:e}=this.get(t),{x:s,y:i,width:r,height:n,minDepth:o,maxDepth:a}=t.viewportValue;e.setViewport(s,i,r,n,o,a)}clear(t,e,s,i=null){const r=this.device,n=this.renderer;let o,a,h,u,l=[];if(t){const t=this.getClearColor();if(!0===this.renderer.alpha){const e=t.a;a={r:t.r*e,g:t.g*e,b:t.b*e,a:e}}else a={r:t.r,g:t.g,b:t.b,a:t.a}}if(null===i){h=n.depth,u=n.stencil;const e=this._getDefaultRenderPassDescriptor();if(t){l=e.colorAttachments;const t=l[0];t.clearValue=a,t.loadOp=NA,t.storeOp=MA}(h||u)&&(o=e.depthStencilAttachment)}else{if(h=i.depth,u=i.stencil,t)for(const t of i.textures){const e=this.get(t),s=e.texture.createView();let i,r;void 0!==e.msaaTexture?(i=e.msaaTexture.createView(),r=s):(i=s,r=void 0),l.push({view:i,resolveTarget:r,clearValue:a,loadOp:NA,storeOp:MA})}if(h||u){o={view:this.get(i.depthTexture).texture.createView()}}}h&&(e?(o.depthLoadOp=NA,o.depthClearValue=n.getClearDepth(),o.depthStoreOp=MA):(o.depthLoadOp=AA,o.depthStoreOp=MA)),u&&(s?(o.stencilLoadOp=NA,o.stencilClearValue=n.getClearStencil(),o.stencilStoreOp=MA):(o.stencilLoadOp=AA,o.stencilStoreOp=MA));const c=r.createCommandEncoder({});c.beginRenderPass({colorAttachments:l,depthStencilAttachment:o}).end(),r.queue.submit([c.finish()])}beginCompute(t){const e=this.get(t),s={};this.initTimestampQuery(t,s),e.cmdEncoderGPU=this.device.createCommandEncoder(),e.passEncoderGPU=e.cmdEncoderGPU.beginComputePass(s)}compute(t,e,s,i){const{passEncoderGPU:r}=this.get(t),n=this.get(i).pipeline;r.setPipeline(n);for(let t=0,e=s.length;t<e;t++){const e=s[t],i=this.get(e);r.setBindGroup(t,i.group)}const o=this.device.limits.maxComputeWorkgroupsPerDimension,a=this.get(e);void 0===a.dispatchSize&&(a.dispatchSize={x:0,y:1,z:1});const{dispatchSize:h}=a;e.dispatchCount>o?(h.x=Math.min(e.dispatchCount,o),h.y=Math.ceil(e.dispatchCount/o)):h.x=e.dispatchCount,r.dispatchWorkgroups(h.x,h.y,h.z)}finishCompute(t){const e=this.get(t);e.passEncoderGPU.end(),this.prepareTimestampBuffer(t,e.cmdEncoderGPU),this.device.queue.submit([e.cmdEncoderGPU.finish()])}draw(t,e){const{object:s,context:i,pipeline:r}=t,n=t.getBindings(),o=this.get(i),a=this.get(r).pipeline,h=o.currentSets,u=o.currentPass,l=t.getDrawParameters();if(null===l)return;h.pipeline!==a&&(u.setPipeline(a),h.pipeline=a);const c=h.bindingGroups;for(let t=0,e=n.length;t<e;t++){const e=n[t],s=this.get(e);c[e.index]!==e.id&&(u.setBindGroup(e.index,s.group),c[e.index]=e.id)}const d=t.getIndex(),p=null!==d;if(!0===p&&h.index!==d){const t=this.get(d).buffer,e=d.array instanceof Uint16Array?IA:PA;u.setIndexBuffer(t,e),h.index=d}const m=t.getVertexBuffers();for(let t=0,e=m.length;t<e;t++){const e=m[t];if(h.attributes[t]!==e){const s=this.get(e).buffer;u.setVertexBuffer(t,s),h.attributes[t]=e}}if(void 0!==o.occlusionQuerySet){const t=o.lastOcclusionObject;t!==s&&(null!==t&&!0===t.occlusionTest&&(u.endOcclusionQuery(),o.occlusionQueryIndex++),!0===s.occlusionTest&&(u.beginOcclusionQuery(o.occlusionQueryIndex),o.occlusionQueryObjects[o.occlusionQueryIndex]=s),o.lastOcclusionObject=s)}if(!0===s.isBatchedMesh){const t=s._multiDrawStarts,e=s._multiDrawCounts,i=s._multiDrawCount,r=s._multiDrawInstances,n=p?d.array.BYTES_PER_ELEMENT:1;for(let s=0;s<i;s++){const i=r?r[s]:1,o=i>1?0:s;u.drawIndexed(e[s],i,t[s]/n,0,o)}}else if(!0===p){const{vertexCount:t,instanceCount:i,firstVertex:r}=l;u.drawIndexed(t,i,r,0,0),e.update(s,t,i)}else{const{vertexCount:t,instanceCount:i,firstVertex:r}=l;u.draw(t,i,r,0),e.update(s,t,i)}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCountRenderContext(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),u=r.getPrimitiveTopology(s,i);let l=!1;return e.material===i&&e.materialVersion===i.version&&e.transparent===i.transparent&&e.blending===i.blending&&e.premultipliedAlpha===i.premultipliedAlpha&&e.blendSrc===i.blendSrc&&e.blendDst===i.blendDst&&e.blendEquation===i.blendEquation&&e.blendSrcAlpha===i.blendSrcAlpha&&e.blendDstAlpha===i.blendDstAlpha&&e.blendEquationAlpha===i.blendEquationAlpha&&e.colorWrite===i.colorWrite&&e.depthWrite===i.depthWrite&&e.depthTest===i.depthTest&&e.depthFunc===i.depthFunc&&e.stencilWrite===i.stencilWrite&&e.stencilFunc===i.stencilFunc&&e.stencilFail===i.stencilFail&&e.stencilZFail===i.stencilZFail&&e.stencilZPass===i.stencilZPass&&e.stencilFuncMask===i.stencilFuncMask&&e.stencilWriteMask===i.stencilWriteMask&&e.side===i.side&&e.alphaToCoverage===i.alphaToCoverage&&e.sampleCount===n&&e.colorSpace===o&&e.colorFormat===a&&e.depthStencilFormat===h&&e.primitiveTopology===u&&e.clippingContextCacheKey===t.clippingContext.cacheKey||(e.material=i,e.materialVersion=i.version,e.transparent=i.transparent,e.blending=i.blending,e.premultipliedAlpha=i.premultipliedAlpha,e.blendSrc=i.blendSrc,e.blendDst=i.blendDst,e.blendEquation=i.blendEquation,e.blendSrcAlpha=i.blendSrcAlpha,e.blendDstAlpha=i.blendDstAlpha,e.blendEquationAlpha=i.blendEquationAlpha,e.colorWrite=i.colorWrite,e.depthWrite=i.depthWrite,e.depthTest=i.depthTest,e.depthFunc=i.depthFunc,e.stencilWrite=i.stencilWrite,e.stencilFunc=i.stencilFunc,e.stencilFail=i.stencilFail,e.stencilZFail=i.stencilZFail,e.stencilZPass=i.stencilZPass,e.stencilFuncMask=i.stencilFuncMask,e.stencilWriteMask=i.stencilWriteMask,e.side=i.side,e.alphaToCoverage=i.alphaToCoverage,e.sampleCount=n,e.colorSpace=o,e.colorFormat=a,e.depthStencilFormat=h,e.primitiveTopology=u,e.clippingContextCacheKey=t.clippingContext.cacheKey,l=!0),l}getRenderCacheKey(t){const{object:e,material:s}=t,i=this.utils,r=t.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContext.cacheKey].join()}createSampler(t){this.textureUtils.createSampler(t)}destroySampler(t){this.textureUtils.destroySampler(t)}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r,n){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r,n)}initTimestampQuery(t,e){if(!this.trackTimestamp)return;const s=this.get(t);if(!s.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),s.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.trackTimestamp)return;const s=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:r,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(e.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.trackTimestamp)return;const s=this.get(t);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=s.currentTimestampQueryBuffers;!0!==r&&(s.currentTimestampQueryBuffers.isMappingPending=!0,i.mapAsync(GPUMapMode.READ).then((()=>{const t=new BigUint64Array(i.getMappedRange()),r=Number(t[1]-t[0])/1e6;this.renderer.info.updateTimestamp(e,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new cP(t,e)}createProgram(t){this.get(t).module={module:this.device.createShaderModule({code:t.code,label:t.stage}),entryPoint:"main"}}destroyProgram(t){this.delete(t)}createRenderPipeline(t,e){this.pipelineUtils.createRenderPipeline(t,e)}createComputePipeline(t,e){this.pipelineUtils.createComputePipeline(t,e)}beginBundle(t){const e=this.get(t);e._currentPass=e.currentPass,e._currentSets=e.currentSets,e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},e.currentPass=this.pipelineUtils.createBundleEncoder(t)}finishBundle(t,e){const s=this.get(t),i=s.currentPass.finish();this.get(e).bundleGPU=i,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(t,e){this.get(t).renderBundles.push(this.get(e).bundleGPU)}createBindings(t){this.bindingUtils.createBindings(t)}updateBindings(t){this.bindingUtils.createBindings(t)}updateBinding(t){this.bindingUtils.updateBinding(t)}createIndexAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(t){return this.device.features.has(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=0,l=0,c=t.image.width,d=t.image.height;null!==s&&(h=s.x,u=s.y,l=s.z||0,c=s.width,d=s.height),null!==i&&(n=i.x,o=i.y,a=i.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),m=this.get(t).texture,g=this.get(e).texture;p.copyTextureToTexture({texture:m,mipLevel:r,origin:{x:h,y:u,z:l}},{texture:g,mipLevel:r,origin:{x:n,y:o,z:a}},[c,d,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(t,e,s){const i=this.get(e),{encoder:r,descriptor:n}=i;let o=null;o=e.renderTarget?t.isDepthTexture?this.get(e.depthTexture).texture:this.get(e.textures[0]).texture:t.isDepthTexture?this.textureUtils.getDepthBuffer(e.depth,e.stencil):this.context.getCurrentTexture();const a=this.get(t).texture;if(o.format===a.format){i.currentPass.end(),r.copyTextureToTexture({texture:o,origin:{x:s.x,y:s.y,z:0}},{texture:a},[s.z,s.w]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t);for(let t=0;t<n.colorAttachments.length;t++)n.colorAttachments[t].loadOp=AA;e.depth&&(n.depthStencilAttachment.depthLoadOp=AA),e.stencil&&(n.depthStencilAttachment.stencilLoadOp=AA),i.currentPass=r.beginRenderPass(n),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null}}else console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",o.format,a.format)}}class vP extends gl{constructor(t,e,s,i,r,n){super(t,e,s,i,r,n),this.iesMap=null}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this}}class TP extends XB{constructor(){super(),this.addLight(dB,vl),this.addLight(pB,wl),this.addLight(yB,Ml),this.addLight(xB,gl),this.addLight(vB,Sl),this.addLight(TB,ul),this.addLight(_B,Nl),this.addLight(bB,vP),this.addToneMapping(TR,1),this.addToneMapping(_R,2),this.addToneMapping(wR,3),this.addToneMapping(MR,4),this.addToneMapping(RR,6),this.addToneMapping(ER,7),this.addColorSpace(vR,kf(Je,Ze)),this.addColorSpace(bR,kf(Ze,Je))}}class _P extends eI{constructor(t={}){let e;t.forceWebGL?e=kI:(e=bP,t.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new kI(t)));super(new e(t),t),this.nodes.library=new TP,this.isWebGPURenderer=!0}}const wP=new cT,SP=new tA(wP);class MP{constructor(t,e=Hp(0,0,1,1)){this.renderer=t,this.outputNode=e,this.outputColorTransform=!0,this.needsUpdate=!0,wP.name="PostProcessing"}render(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Je,SP.render(t),t.toneMapping=e,t.outputColorSpace=s}update(){if(!0===this.needsUpdate){const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;SP.material.fragmentNode=!0===this.outputColorTransform?by(this.outputNode,e,s):this.outputNode.context({toneMapping:e,outputColorSpace:s}),SP.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Je,await SP.renderAsync(t),t.toneMapping=e,t.outputColorSpace=s}}class AP extends yi{constructor(t=1,e=1){super(),this.image={width:t,height:e},this.magFilter=Tt,this.minFilter=Tt,this.isStorageTexture=!0}}class NP extends an{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageBufferAttribute=!0}}class CP extends zo{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageInstancedBufferAttribute=!0}}class RP extends Ku{constructor(t){super(t),this.textures={},this.nodes={}}load(t,e,s,i){const r=new el(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(s=>{try{e(this.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),s,i)}parseNodes(t){const e={};if(void 0!==t){for(const s of t){const{uuid:t,type:i}=s;e[t]=this.createNodeFromType(i),e[t].uuid=t}const s={nodes:e,textures:this.textures};for(const i of t){i.meta=s;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=this.createNodeFromType(t.type);e.uuid=t.uuid;const s={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=s,e.deserialize(t),delete t.meta,e}setTextures(t){return this.textures=t,this}setNodes(t){return this.nodes=t,this}createNodeFromType(t){return void 0===this.nodes[t]?(console.error("THREE.NodeLoader: Node type not found:",t),Pp()):Tp(new this.nodes[t])}}class EP extends Cl{constructor(t){super(t),this.nodes={},this.nodeMaterials={}}parse(t){const e=super.parse(t),s=this.nodes,i=t.inputNodes;for(const t in i){const r=i[t];e[t]=s[r]}return e}setNodes(t){return this.nodes=t,this}setNodeMaterials(t){return this.nodeMaterials=t,this}createMaterialFromType(t){const e=this.nodeMaterials[t];return void 0!==e?new e:super.createMaterialFromType(t)}}class BP extends Il{constructor(t){super(t),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(t){return this.nodes=t,this}setNodeMaterials(t){return this.nodeMaterials=t,this}parse(t,e){this._nodesJSON=t.nodes;const s=super.parse(t,e);return this._nodesJSON=null,s}parseNodes(t,e){if(void 0!==t){const s=new RP;return s.setNodes(this.nodes),s.setTextures(e),s.parseNodes(t)}return{}}parseMaterials(t,e){const s={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),r=new EP;r.setTextures(e),r.setNodes(i),r.setNodeMaterials(this.nodeMaterials);for(let e=0,i=t.length;e<i;e++){const i=t[e];s[i.uuid]=r.parse(i)}}return s}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:t}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=t);export{et as ACESFilmicToneMapping,Ev as AONode,v as AddEquation,Z as AddOperation,Ve as AdditiveAnimationBlendMode,f as AdditiveBlending,it as AgXToneMapping,Lt as AlphaFormat,ws as AlwaysCompare,k as AlwaysDepth,gs as AlwaysStencilFunc,Sl as AmbientLight,vB as AmbientLightNode,NC as AnalyticLightNode,mc as AnimationAction,qu as AnimationClip,sl as AnimationLoader,fc as AnimationMixer,pc as AnimationObjectGroup,Fu as AnimationUtils,Ya as ArcCurve,jl as ArrayCamera,Od as ArrayElementNode,ud as ArrowHelper,Gm as AssignNode,nt as AttachedBindMode,Ty as AttributeNode,Kl as Audio,rc as AudioAnalyser,Ll as AudioContext,Jl as AudioListener,Vl as AudioLoader,ld as AxesHelper,t_ as BRDF_GGX,VT as BRDF_Lambert,d as BackSide,We as BasicDepthPacking,IT as BasicEnvironmentNode,a as BasicShadowMap,uv as BatchNode,ya as BatchedMesh,Io as Bone,Du as BooleanKeyframeTrack,Ec as Box2,Ri as Box3,rd as Box3Helper,Ln as BoxGeometry,id as BoxHelper,xv as Break,an as BufferAttribute,ty as BufferAttributeNode,Sn as BufferGeometry,Bl as BufferGeometryLoader,Ex as BufferNode,lb as BumpMapNode,uy as BypassNode,Nt as ByteType,Yu as Cache,ay as CacheNode,kn as Camera,td as CameraHelper,Ha as CanvasTexture,fh as CapsuleGeometry,eh as CatmullRomCurve3,tt as CineonToneMapping,yh as CircleGeometry,mt as ClampToEdgeWrapping,Hl as Clock,xS as CodeNode,Xr as Color,ku as ColorKeyframeTrack,ii as ColorManagement,Gf as ColorSpaceNode,Wa as CompressedArrayTexture,ja as CompressedCubeTexture,Ga as CompressedTexture,il as CompressedTextureLoader,ny as ComputeNode,bh as ConeGeometry,Hd as ConstNode,L as ConstantAlphaFactor,O as ConstantColorFactor,Ef as ContextNode,yv as Continue,dd as Controls,zd as ConvertNode,qn as CubeCamera,ht as CubeReflectionMapping,ut as CubeRefractionMapping,Xn as CubeTexture,nl as CubeTextureLoader,Cx as CubeTextureNode,dt as CubeUVReflectionMapping,nh as CubicBezierCurve,oh as CubicBezierCurve3,Ou as CubicInterpolant,r as CullFaceBack,n as CullFaceFront,o as CullFaceFrontBack,i as CullFaceNone,qa as Curve,ph as CurvePath,b as CustomBlending,st as CustomToneMapping,xh as CylinderGeometry,Nc as Cylindrical,e_ as DFGApprox,JT as D_GGX,wi as Data3DTexture,Ti as DataArrayTexture,Po as DataTexture,ol as DataTextureLoader,rn as DataUtils,rs as DecrementStencilOp,os as DecrementWrapStencilOp,Ju as DefaultLoadingManager,Wt as DepthFormat,jt as DepthStencilFormat,$a as DepthTexture,ot as DetachedBindMode,wl as DirectionalLight,Jc as DirectionalLightHelper,pB as DirectionalLightNode,fy as Discard,Lu as DiscreteInterpolant,Th as DodecahedronGeometry,p as DoubleSide,B as DstAlphaFactor,P as DstColorFactor,Bs as DynamicCopyUsage,Ms as DynamicDrawUsage,Cs as DynamicReadUsage,fg as EPSILON,Ah as EdgesGeometry,Xa as EllipseCurve,hw as EnvironmentNode,xs as EqualCompare,j as EqualDepth,ls as EqualStencilFunc,ST as EquirectUVNode,lt as EquirectangularReflectionMapping,ct as EquirectangularRefractionMapping,dr as Euler,zs as EventDispatcher,my as ExpressionNode,su as ExtrudeGeometry,LT as F_Schlick,el as FileLoader,gn as Float16BufferAttribute,fn as Float32BufferAttribute,It as FloatType,Ap as Fn,Jn as Fog,Zn as FogExp2,dC as FogExp2Node,hC as FogNode,lC as FogRangeNode,ka as FramebufferTexture,lx as FrontFacingNode,c as FrontSide,Ko as Frustum,jm as FunctionCallNode,wS as FunctionNode,MM as FunctionOverloadingNode,Tc as GLBufferAttribute,Ps as GLSL1,Fs as GLSL3,RB as GLSLNodeParser,vs as GreaterCompare,$ as GreaterDepth,_s as GreaterEqualCompare,H as GreaterEqualDepth,ms as GreaterEqualStencilFunc,ds as GreaterStencilFunc,$c as GridHelper,Va as Group,Pt as HalfFloatType,ul as HemisphereLight,Hc as HemisphereLightHelper,TB as HemisphereLightNode,vP as IESSpotLight,bB as IESSpotLightNode,yg as INFINITY,ru as IcosahedronGeometry,Ep as If,Ol as ImageBitmapLoader,rl as ImageLoader,di as ImageUtils,is as IncrementStencilOp,ns as IncrementWrapStencilOp,tv as IndexNode,av as InstanceNode,zo as InstancedBufferAttribute,El as InstancedBufferGeometry,vc as InstancedInterleavedBuffer,Ho as InstancedMesh,pT as InstancedPointsNodeMaterial,cn as Int16BufferAttribute,pn as Int32BufferAttribute,hn as Int8BufferAttribute,Et as IntType,Qn as InterleavedBuffer,eo as InterleavedBufferAttribute,Uu as Interpolant,Ie as InterpolateDiscrete,Pe as InterpolateLinear,Fe as InterpolateSmooth,as as InvertStencilOp,Pv as IrradianceNode,Vd as JoinNode,es as KeepStencilOp,Vu as KeyframeTrack,To as LOD,gh as LatheGeometry,pr as Layers,ys as LessCompare,G as LessDepth,bs as LessEqualCompare,W as LessEqualDepth,cs as LessEqualStencilFunc,us as LessStencilFunc,hl as Light,Nl as LightProbe,_B as LightProbeNode,Bv as LightingContextNode,FT as LightingModel,Rv as LightingNode,Nv as LightsNode,Aa as Line,bT as Line2NodeMaterial,Pc as Line3,xa as LineBasicMaterial,gT as LineBasicNodeMaterial,ah as LineCurve,hh as LineCurve3,Cu as LineDashedMaterial,yT as LineDashedNodeMaterial,Ba as LineLoop,Ea as LineSegments,Tt as LinearFilter,zu as LinearInterpolant,Mt as LinearMipMapLinearFilter,wt as LinearMipMapNearestFilter,St as LinearMipmapLinearFilter,_t as LinearMipmapNearestFilter,Je as LinearSRGBColorSpace,K as LinearToneMapping,Ke as LinearTransfer,Ku as Loader,Rl as LoaderUtils,Zu as LoadingManager,fv as Loop,gv as LoopNode,Re as LoopOnce,Be as LoopPingPong,Ee as LoopRepeat,Gt as LuminanceAlphaFormat,kt as LuminanceFormat,e as MOUSE,wM as MRTNode,Tw as MatcapUVNode,Jr as Material,Cl as MaterialLoader,pb as MaterialNode,Dx as MaterialReferenceNode,Xs as MathUtils,Cc as Matrix2,Zs as Matrix3,sr as Matrix4,S as MaxEquation,Ay as MaxMipLevelNode,On as Mesh,Kr as MeshBasicMaterial,zT as MeshBasicNodeMaterial,Mu as MeshDepthMaterial,Au as MeshDistanceMaterial,Su as MeshLambertMaterial,jT as MeshLambertNodeMaterial,Nu as MeshMatcapMaterial,Sw as MeshMatcapNodeMaterial,wu as MeshNormalMaterial,wT as MeshNormalNodeMaterial,Tu as MeshPhongMaterial,$T as MeshPhongNodeMaterial,vu as MeshPhysicalMaterial,mw as MeshPhysicalNodeMaterial,fw as MeshSSSNodeMaterial,bu as MeshStandardMaterial,dw as MeshStandardNodeMaterial,_u as MeshToonMaterial,vw as MeshToonNodeMaterial,w as MinEquation,gt as MirroredRepeatWrapping,Y as MixOperation,$y as ModelNode,Kb as ModelViewProjectionNode,wv as MorphNode,x as MultiplyBlending,X as MultiplyOperation,ft as NearestFilter,vt as NearestMipMapLinearFilter,xt as NearestMipMapNearestFilter,bt as NearestMipmapLinearFilter,yt as NearestMipmapNearestFilter,rt as NeutralToneMapping,fs as NeverCompare,D as NeverDepth,hs as NeverStencilFunc,m as NoBlending,Ye as NoColorSpace,J as NoToneMapping,Ud as Node,uS as NodeAttribute,fM as NodeBuilder,gS as NodeCache,pS as NodeCode,yM as NodeFrame,xM as NodeFunctionInput,RP as NodeLoader,cT as NodeMaterial,EP as NodeMaterialLoader,gd as NodeMaterialObserver,BP as NodeObjectLoader,Nd as NodeShaderStage,Rd as NodeType,lS as NodeUniform,Cd as NodeUpdateType,Ad as NodeUtils,cS as NodeVar,dS as NodeVarying,Le as NormalAnimationBlendMode,g as NormalBlending,ob as NormalMapNode,Ts as NotEqualCompare,q as NotEqualDepth,ps as NotEqualStencilFunc,Gu as NumberKeyframeTrack,Rr as Object3D,Dy as Object3DNode,Il as ObjectLoader,Xe as ObjectSpaceNormalMap,nu as OctahedronGeometry,A as OneFactor,V as OneMinusConstantAlphaFactor,z as OneMinusConstantColorFactor,I as OneMinusDstAlphaFactor,F as OneMinusDstColorFactor,E as OneMinusSrcAlphaFactor,C as OneMinusSrcColorFactor,Tl as OrthographicCamera,vM as OutputStructNode,h as PCFShadowMap,u as PCFSoftShadowMap,xg as PI,bg as PI2,rM as PMREMGenerator,nw as PMREMNode,fS as ParameterNode,YN as PassNode,mh as Path,Hn as PerspectiveCamera,GT as PhongLightingModel,U_ as PhysicalLightingModel,Yo as Plane,ou as PlaneGeometry,nd as PlaneHelper,vl as PointLight,kc as PointLightHelper,dB as PointLightNode,aA as PointUVNode,za as Points,Ia as PointsMaterial,Aw as PointsNodeMaterial,qc as PolarGridHelper,vh as PolyhedronGeometry,ic as PositionalAudio,MP as PostProcessing,kN as PosterizeNode,dc as PropertyBinding,nc as PropertyMixer,cm as PropertyNode,tA as QuadMesh,uh as QuadraticBezierCurve,lh as QuadraticBezierCurve3,Mi as Quaternion,ju as QuaternionKeyframeTrack,Wu as QuaternionLinearInterpolant,Ne as RED_GREEN_RGTC2_Format,Me as RED_RGTC1_Format,t as REVISION,je as RGBADepthPacking,Dt as RGBAFormat,Zt as RGBAIntegerFormat,be as RGBA_ASTC_10x10_Format,fe as RGBA_ASTC_10x5_Format,ye as RGBA_ASTC_10x6_Format,xe as RGBA_ASTC_10x8_Format,ve as RGBA_ASTC_12x10_Format,Te as RGBA_ASTC_12x12_Format,he as RGBA_ASTC_4x4_Format,ue as RGBA_ASTC_5x4_Format,le as RGBA_ASTC_5x5_Format,ce as RGBA_ASTC_6x5_Format,de as RGBA_ASTC_6x6_Format,pe as RGBA_ASTC_8x5_Format,me as RGBA_ASTC_8x6_Format,ge as RGBA_ASTC_8x8_Format,_e as RGBA_BPTC_Format,ae as RGBA_ETC2_EAC_Format,re as RGBA_PVRTC_2BPPV1_Format,ie as RGBA_PVRTC_4BPPV1_Format,Kt as RGBA_S3TC_DXT1_Format,Qt as RGBA_S3TC_DXT3_Format,te as RGBA_S3TC_DXT5_Format,He as RGBDepthPacking,Vt as RGBFormat,Yt as RGBIntegerFormat,we as RGB_BPTC_SIGNED_Format,Se as RGB_BPTC_UNSIGNED_Format,ne as RGB_ETC1_Format,oe as RGB_ETC2_Format,se as RGB_PVRTC_2BPPV1_Format,ee as RGB_PVRTC_4BPPV1_Format,Jt as RGB_S3TC_DXT1_Format,$e as RGDepthPacking,qt as RGFormat,Xt as RGIntegerFormat,sA as RTTNode,fC as RangeNode,xu as RawShaderMaterial,er as Ray,wc as Raycaster,Ml as RectAreaLight,yB as RectAreaLightNode,Ht as RedFormat,$t as RedIntegerFormat,zx as ReferenceNode,YM as ReflectorNode,Q as ReinhardToneMapping,cy as RemapNode,xy as RenderOutputNode,bi as RenderTarget,Yf as RendererReferenceNode,pt as RepeatWrapping,ss as ReplaceStencilOp,yy as Return,_ as ReverseSubtractEquation,au as RingGeometry,Nw as RotateNode,Ce as SIGNED_RED_GREEN_RGTC2_Format,Ae as SIGNED_RED_RGTC1_Format,Ze as SRGBColorSpace,Qe as SRGBTransfer,Kn as Scene,uA as SceneNode,i_ as Schlick_to_F0,Ov as ScreenNode,oC as ScriptableNode,eC as ScriptableValueNode,Gd as SetNode,Dn as ShaderMaterial,vp as ShaderNode,yu as ShadowMaterial,Pw as ShadowNodeMaterial,Nh as Shape,hu as ShapeGeometry,cd as ShapePath,Qh as ShapeUtils,Ct as ShortType,Oo as Skeleton,Vc as SkeletonHelper,Bo as SkinnedMesh,dv as SkinningNode,mi as Source,qi as Sphere,uu as SphereGeometry,Ac as Spherical,Al as SphericalHarmonics3,ch as SplineCurve,kd as SplitNode,gl as SpotLight,Uc as SpotLightHelper,xB as SpotLightNode,yo as Sprite,so as SpriteMaterial,Ew as SpriteNodeMaterial,CM as SpriteSheetUVNode,R as SrcAlphaFactor,U as SrcAlphaSaturateFactor,N as SrcColorFactor,GS as StackNode,Es as StaticCopyUsage,Ss as StaticDrawUsage,Ns as StaticReadUsage,Wl as StereoCamera,EM as StorageArrayElementNode,NP as StorageBufferAttribute,PN as StorageBufferNode,CP as StorageInstancedBufferAttribute,AP as StorageTexture,ON as StorageTextureNode,Is as StreamCopyUsage,As as StreamDrawUsage,Rs as StreamReadUsage,Hu as StringKeyframeTrack,T as SubtractEquation,y as SubtractiveBlending,eb as TBNViewMatrix,s as TOUCH,qe as TangentSpaceNormalMap,Ld as TempNode,lu as TetrahedronGeometry,yi as Texture,Uw as Texture3DNode,al as TextureLoader,Cy as TextureNode,Sy as TextureSizeNode,Jf as ToneMappingNode,QN as ToonOutlinePassNode,cu as TorusGeometry,du as TorusKnotGeometry,Wr as Triangle,Ge as TriangleFanDrawMode,ke as TriangleStripDrawMode,De as TrianglesDrawMode,IM as TriplanarTexturesNode,pu as TubeGeometry,at as UVMapping,dn as Uint16BufferAttribute,mn as Uint32BufferAttribute,un as Uint8BufferAttribute,ln as Uint8ClampedBufferAttribute,yc as Uniform,Px as UniformArrayNode,im as UniformGroupNode,um as UniformNode,bc as UniformsGroup,At as UnsignedByteType,Ot as UnsignedInt248Type,zt as UnsignedInt5999Type,Bt as UnsignedIntType,Ft as UnsignedShort4444Type,Ut as UnsignedShort5551Type,Rt as UnsignedShortType,VN as UserDataNode,l as VSMShadowMap,YT as V_GGX_SmithCorrelated,Pf as VarNode,Of as VaryingNode,Ys as Vector2,Ai as Vector3,xi as Vector4,$u as VectorKeyframeTrack,nA as VertexColorNode,Da as VideoTexture,tT as ViewportDepthNode,Kv as ViewportDepthTextureNode,jN as ViewportSharedTextureNode,Xv as ViewportTextureNode,zw as VolumeNodeMaterial,Si as WebGL3DRenderTarget,_i as WebGLArrayRenderTarget,Us as WebGLCoordinateSystem,Yn as WebGLCubeRenderTarget,pd as WebGLMultipleRenderTargets,vi as WebGLRenderTarget,Os as WebGPUCoordinateSystem,_P as WebGPURenderer,mu as WireframeGeometry,ze as WrapAroundEnding,Ue as ZeroCurvatureEnding,M as ZeroFactor,Oe as ZeroSlopeEnding,ts as ZeroStencilOp,kg as abs,MR as acesFilmicToneMapping,Vg as acos,qm as add,Xd as addMethodChaining,vy as addNodeElement,RR as agxToneMapping,vg as all,Mm as alphaT,rg as and,Am as anisotropy,Cm as anisotropyB,Nm as anisotropyT,Tg as any,Bp as append,Qp as arrayBuffer,Lg as asin,Wm as assign,Dg as atan,tf as atan2,XR as atomicAdd,KR as atomicAnd,$R as atomicFunc,ZR as atomicMax,JR as atomicMin,QR as atomicOr,qR as atomicStore,YR as atomicSub,tE as atomicXor,Dm as attenuationColor,Vm as attenuationDistance,_y as attribute,lA as backgroundBlurriness,cA as backgroundIntensity,lv as batch,eR as billboarding,hg as bitAnd,ug as bitNot,lg as bitOr,cg as bitXor,Yx as bitangentGeometry,Zx as bitangentLocal,Jx as bitangentView,Kx as bitangentWorld,Kg as bitcast,ew as blur,Op as bool,Bx as buffer,ey as bufferAttribute,cb as bumpMap,hR as burn,Dp as bvec2,jp as bvec3,Xp as bvec4,ly as bypass,hy as cache,Hm as call,Py as cameraFar,Iy as cameraNear,Ly as cameraNormalMatrix,Vy as cameraPosition,Fy as cameraProjectionMatrix,Uy as cameraProjectionMatrixInverse,Oy as cameraViewMatrix,zy as cameraWorldMatrix,ff as cbrt,xR as cdl,Ig as ceil,eE as checker,wR as cineonToneMapping,bf as clamp,xm as clearcoat,bm as clearcoatRoughness,bS as code,Ip as color,$f as colorSpaceToWorking,TT as colorToDirection,oy as compute,Rf as cond,Bf as context,em as convert,rA as convertToTexture,Og as cos,ei as createCanvasElement,lf as cross,Rx as cubeTexture,$g as dFdx,qg as dFdy,Pm as dashSize,Bd as defaultBuildStages,Ed as defaultShaderStages,xp as defined,Sg as degrees,jC as deltaTime,pC as densityFog,aT as depth,KN as depthPass,hf as difference,mm as diffuseColor,vT as directionToColor,km as dispersion,af as distance,Zm as div,uR as dodge,uf as dot,ov as drawIndex,sy as dynamicBufferAttribute,tm as element,gm as emissive,Km as equal,_g as equals,MT as equirectUV,Mg as exp,Ag as exp2,gy as expression,dx as faceDirection,wf as faceForward,Pp as float,Bg as floor,uC as fog,Fg as fract,om as frameGroup,HC as frameId,cx as frontFacing,Jg as fwidth,zC as gain,Fm as gapSize,kf as getColorSpaceMethod,bp as getConstNodeType,Rp as getCurrentStack,J_ as getDirection,CC as getDistanceAttenuation,qT as getGeometryRoughness,XT as getRoughness,cB as getShIrradianceAt,_M as getTextureIndex,nC as global,_S as glsl,MS as glslFn,dR as grayscale,eg as greaterThan,ig as greaterThanEqual,UC as hash,sx as highPrecisionModelNormalViewMatrix,ex as highPrecisionModelViewMatrix,gR as hue,hv as instance,sv as instanceIndex,iy as instancedBufferAttribute,ry as instancedDynamicBufferAttribute,Fp as int,Eg as inverseSqrt,nv as invocationLocalIndex,rv as invocationSubgroupIndex,Om as ior,_m as iridescence,wm as iridescenceIOR,Sm as iridescenceThickness,Lp as ivec2,Gp as ivec3,$p as ivec4,vS as js,If as label,Wg as length,yf as lengthSq,tg as lessThan,sg as lessThanEqual,BC as lightPosition,FC as lightTargetDirection,IC as lightTargetPosition,PC as lightViewPosition,Iv as lightingContext,Cv as lights,hT as linearDepth,vR as linearSRGBTosRGB,TR as linearToneMapping,UR as localId,Ng as log,Cg as log2,bv as loop,fR as luminance,Yp as mat2,Zp as mat3,Jp as mat4,_w as matcapUV,Zb as materialAOMap,mb as materialAlphaTest,Pb as materialAnisotropy,Jb as materialAnisotropyVector,kb as materialAttenuationColor,Db as materialAttenuationDistance,Nb as materialClearcoat,Rb as materialClearcoatNormal,Cb as materialClearcoatRoughness,gb as materialColor,Xb as materialDispersion,yb as materialEmissive,Vb as materialIOR,Fb as materialIridescence,Ub as materialIridescenceIOR,Ob as materialIridescenceThickness,Yb as materialLightMap,$b as materialLineDashOffset,Wb as materialLineDashSize,jb as materialLineGapSize,Gb as materialLineScale,Hb as materialLineWidth,Mb as materialMetalness,Ab as materialNormal,xb as materialOpacity,qb as materialPointWidth,kx as materialReference,wb as materialReflectivity,wx as materialRefractionRatio,Eb as materialRotation,Sb as materialRoughness,Bb as materialSheen,Ib as materialSheenRoughness,fb as materialShininess,bb as materialSpecular,Tb as materialSpecularColor,vb as materialSpecularIntensity,_b as materialSpecularStrength,Lb as materialThickness,zb as materialTransmission,sf as max,Ny as maxMipLevel,ym as metalness,ef as min,xf as mix,Mf as mixElement,rf as mod,Jm as modInt,qy as modelDirection,Ky as modelNormalMatrix,Yy as modelPosition,Zy as modelScale,tx as modelViewMatrix,Jy as modelViewPosition,Qb as modelViewProjection,Xy as modelWorldMatrix,Qy as modelWorldMatrixInverse,Sv as morphReference,SM as mrt,Ym as mul,jE as mx_aastep,oB as mx_cell_noise_float,QE as mx_contrast,aB as mx_fractal_noise_float,hB as mx_fractal_noise_vec2,uB as mx_fractal_noise_vec3,lB as mx_fractal_noise_vec4,kE as mx_hsvtorgb,tB as mx_noise_float,eB as mx_noise_vec3,sB as mx_noise_vec4,$E as mx_ramplr,qE as mx_ramptb,GE as mx_rgbtohsv,KE as mx_safepower,YE as mx_splitlr,ZE as mx_splittb,WE as mx_srgb_texture_to_lin_rec709,JE as mx_transform_uv,iB as mx_worley_noise_float,rB as mx_worley_noise_vec2,nB as mx_worley_noise_vec3,jg as negate,ER as neutralToneMapping,wp as nodeArray,Mp as nodeImmutable,Tp as nodeObject,_p as nodeObjects,Sp as nodeProxy,gx as normalFlat,px as normalGeometry,mx as normalLocal,ab as normalMap,fx as normalView,yx as normalWorld,Pg as normalize,og as not,Qm as notEqual,PR as numWorkgroups,ky as objectDirection,hm as objectGroup,Wy as objectPosition,jy as objectScale,Hy as objectViewPosition,Gy as objectWorldMatrix,Hg as oneMinus,ng as or,sT as orthographicDepthToViewZ,KC as oscSawtooth,YC as oscSine,ZC as oscSquare,JC as oscTriangle,Im as output,TM as outputStruct,cR as overlay,NM as overloadingFn,OC as parabola,sb as parallaxDirection,ib as parallaxUV,yS as parameter,ZN as pass,JN as passTexture,LC as pcurve,nT as perspectiveDepthToLogarithmicDepth,rT as perspectiveDepthToViewZ,ow as pmremTexture,hA as pointUV,Um as pointWidth,ix as positionGeometry,rx as positionLocal,nx as positionPrevious,hx as positionView,ux as positionViewDirection,ox as positionWorld,ax as positionWorldDirection,GN as posterize,cf as pow,df as pow2,pf as pow3,mf as pow4,dm as property,wg as radians,Sf as rand,yC as range,cC as rangeFog,Yg as reciprocal,Lx as reference,Vx as referenceBuffer,of as reflect,Ax as reflectVector,Sx as reflectView,ZM as reflector,Tf as refract,Nx as refractVector,Mx as refractView,_R as reinhardToneMapping,mg as remainder,dy as remap,py as remapClamp,am as renderGroup,by as renderOutput,Zf as rendererReference,Cw as rotate,QC as rotateUV,fm as roughness,Xg as round,iA as rtt,bR as sRGBToLinearSRGB,By as sampler,vf as saturate,pR as saturation,lR as screen,Vv as screenCoordinate,Lv as screenSize,zv as screenUV,aC as scriptable,sC as scriptableValue,Cf as select,Cp as setCurrentStack,Id as shaderStages,nm as sharedUniformGroup,vm as sheen,Tm as sheenRoughness,dg as shiftLeft,pg as shiftRight,Bm as shininess,Gg as sign,Ug as sin,VC as sinc,pv as skinning,mv as skinningReference,_f as smoothstep,Af as smoothstepElement,Rm as specularColor,Em as specularF90,tR as spherizeUV,sm as split,RM as spritesheetUV,Rg as sqrt,WS as stack,nf as step,FN as storage,VR as storageBarrier,UN as storageObject,zN as storageTexture,Kp as string,Xm as sub,iv as subgroupIndex,OR as subgroupSize,zg as tan,Gx as tangentGeometry,Wx as tangentLocal,jx as tangentView,Hx as tangentWorld,Uf as temp,Ry as texture,Ow as texture3D,DR as textureBarrier,T_ as textureBicubic,K_ as textureCubeUV,Ey as textureLoad,My as textureSize,LN as textureStore,Lm as thickness,yR as threshold,WC as time,XC as timerDelta,qC as timerGlobal,$C as timerLocal,Wf as toOutputColorSpace,jf as toWorkingColorSpace,Kf as toneMapping,Qf as toneMappingExposure,tC as toonOutlinePass,gf as transformDirection,Tx as transformNormal,_x as transformNormalToView,rb as transformedBentNormalView,Qx as transformedBitangentView,tb as transformedBitangentWorld,vx as transformedClearcoatNormalView,xx as transformedNormalView,bx as transformedNormalWorld,$x as transformedTangentView,qx as transformedTangentWorld,zm as transmission,Qg as transpose,DC as tri,kC as tri3,GC as triNoise3D,FM as triplanarTexture,PM as triplanarTextures,Zg as trunc,Np as tslFn,Up as uint,lm as uniform,Fx as uniformArray,rm as uniformGroup,Ux as uniforms,DN as userData,wy as uv,Vp as uvec2,Wp as uvec3,qp as uvec4,zf as varying,pm as varyingProperty,zp as vec2,kp as vec3,Hp as vec4,Pd as vectorComponents,aR as velocity,oA as vertexColor,ev as vertexIndex,mR as vibrance,eT as viewZToOrthographicDepth,iT as viewZToPerspectiveDepth,Dv as viewport,$v as viewportBottomLeft,Gv as viewportCoordinate,Qv as viewportDepthTexture,uT as viewportLinearDepth,Zv as viewportMipTexture,jv as viewportResolution,sR as viewportSafeUV,HN as viewportSharedTexture,kv as viewportSize,Yv as viewportTexture,Hv as viewportTopLeft,Wv as viewportUV,TS as wgsl,AS as wgslFn,WR as workgroupArray,LR as workgroupBarrier,FR as workgroupId,Hf as workingToColorSpace,ag as xor};
|