123456 |
- /**
- * @license
- * Copyright 2010-2024 Three.js Authors
- * SPDX-License-Identifier: MIT
- */
- const t="167dev",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,l=2,u=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,R=203,C=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,q=6,$=7,X=0,Y=1,J=2,Z=0,Q=1,K=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,lt=302,ut=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,Rt=1011,Ct=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,qt=1029,$t=1030,Xt=1031,Yt=1032,Jt=1033,Zt=33776,Qt=33777,Kt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,le=37809,ue=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,Re=36286,Ce=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=0,qe=1,$e="",Xe="srgb",Ye="srgb-linear",Je="display-p3",Ze="display-p3-linear",Qe="linear",Ke="srgb",ts="rec709",es="p3",ss=0,is=7680,rs=7681,ns=7682,os=7683,as=34055,hs=34056,ls=5386,us=512,cs=513,ds=514,ps=515,ms=516,gs=517,fs=518,ys=519,xs=512,bs=513,vs=514,Ts=515,_s=516,ws=517,Ss=518,Ms=519,As=35044,Ns=35048,Rs=35040,Cs=35045,Es=35049,Bs=35041,Is=35046,Ps=35050,Fs=35042,Us="100",Os="300 es",zs=2e3,Ls=2001;class Vs{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 Ds=["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 ks=1234567;const Gs=Math.PI/180,Ws=180/Math.PI;function js(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,s=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(Ds[255&t]+Ds[t>>8&255]+Ds[t>>16&255]+Ds[t>>24&255]+"-"+Ds[255&e]+Ds[e>>8&255]+"-"+Ds[e>>16&15|64]+Ds[e>>24&255]+"-"+Ds[63&s|128]+Ds[s>>8&255]+"-"+Ds[s>>16&255]+Ds[s>>24&255]+Ds[255&i]+Ds[i>>8&255]+Ds[i>>16&255]+Ds[i>>24&255]).toLowerCase()}function Hs(t,e,s){return Math.max(e,Math.min(s,t))}function qs(t,e){return(t%e+e)%e}function $s(t,e,s){return(1-s)*t+s*e}function Xs(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 Ys(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 Js={DEG2RAD:Gs,RAD2DEG:Ws,generateUUID:js,clamp:Hs,euclideanModulo:qs,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:$s,damp:function(t,e,s,i){return $s(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(qs(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&&(ks=t);let e=ks+=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*Gs},radToDeg:function(t){return t*Ws},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),l=n((e+i)/2),u=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*u,h*c,h*d,a*l);break;case"YZY":t.set(h*d,a*u,h*c,a*l);break;case"ZXZ":t.set(h*c,h*d,a*u,a*l);break;case"XZX":t.set(a*u,h*m,h*p,a*l);break;case"YXY":t.set(h*p,a*u,h*m,a*l);break;case"ZYZ":t.set(h*m,h*p,a*u,a*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Ys,denormalize:Xs};class Zs{constructor(t=0,e=0){Zs.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(Hs(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 Qs{constructor(t,e,s,i,r,n,o,a,h){Qs.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 l=this.elements;return l[0]=t,l[1]=i,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=s,l[7]=n,l[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],l=s[4],u=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+l*y+u*v,r[4]=h*g+l*x+u*T,r[7]=h*f+l*b+u*_,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],l=t[8];return e*n*l-e*o*h-s*r*l+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],l=t[8],u=l*n-o*h,c=o*a-l*r,d=h*r-n*a,p=e*u+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]=u*m,t[1]=(i*h-l*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(l*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(Ks.makeScale(t,e)),this}rotate(t){return this.premultiply(Ks.makeRotation(-t)),this}translate(t,e){return this.premultiply(Ks.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 Ks=new Qs;const ti={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ei(t,e){return new ti[t](e)}function si(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ii(){const t=si("canvas");return t.style.display="block",t}const ri={};function ni(t){t in ri||(ri[t]=!0,console.warn(t))}const oi=(new Qs).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ai=(new Qs).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),hi={[Ye]:{transfer:Qe,primaries:ts,toReference:t=>t,fromReference:t=>t},[Xe]:{transfer:Ke,primaries:ts,toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[Ze]:{transfer:Qe,primaries:es,toReference:t=>t.applyMatrix3(ai),fromReference:t=>t.applyMatrix3(oi)},[Je]:{transfer:Ke,primaries:es,toReference:t=>t.convertSRGBToLinear().applyMatrix3(ai),fromReference:t=>t.applyMatrix3(oi).convertLinearToSRGB()}},li=new Set([Ye,Ze]),ui={enabled:!0,_workingColorSpace:Ye,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!li.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,s){if(!1===this.enabled||e===s||!e||!s)return t;const i=hi[e].toReference;return(0,hi[s].fromReference)(i(t))},fromWorkingColorSpace:function(t,e){return this.convert(t,this._workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this._workingColorSpace)},getPrimaries:function(t){return hi[t].primaries},getTransfer:function(t){return t===$e?Qe:hi[t].transfer}};function ci(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function di(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let pi;class mi{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===pi&&(pi=si("canvas")),pi.width=t.width,pi.height=t.height;const s=pi.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=pi}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=si("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*ci(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*ci(e[t]/255)):e[t]=ci(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 gi=0;class fi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:gi++}),this.uuid=js(),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(yi(i[e].image)):t.push(yi(i[e]))}else t=yi(i);s.url=t}return e||(t.images[this.uuid]=s),s}}function yi(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?mi.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 xi=0;class bi extends Vs{constructor(t=bi.DEFAULT_IMAGE,e=bi.DEFAULT_MAPPING,s=1001,i=1001,r=1006,n=1008,o=1023,a=1009,h=bi.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:xi++}),this.uuid=js(),this.name="",this.source=new fi(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 Zs(0,0),this.repeat=new Zs(1,1),this.center=new Zs(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Qs,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=l,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++}}bi.DEFAULT_IMAGE=null,bi.DEFAULT_MAPPING=at,bi.DEFAULT_ANISOTROPY=1;class vi{constructor(t=0,e=0,s=0,i=1){vi.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],l=a[4],u=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(l-c)<n&&Math.abs(u-m)<n&&Math.abs(p-g)<n){if(Math.abs(l+c)<o&&Math.abs(u+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=(l+c)/4,b=(u+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)+(u-m)*(u-m)+(c-l)*(c-l));return Math.abs(y)<.001&&(y=1),this.x=(g-p)/y,this.y=(u-m)/y,this.z=(c-l)/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 Ti extends Vs{constructor(t=1,e=1,s={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new vi(0,0,t,e),this.scissorTest=!1,this.viewport=new vi(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 bi(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 fi(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 _i extends Ti{constructor(t=1,e=1,s={}){super(t,e,s),this.isWebGLRenderTarget=!0}}class wi extends bi{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 Si extends _i{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGLArrayRenderTarget=!0,this.depth=s,this.texture=new wi(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class Mi extends bi{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 Ai extends _i{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGL3DRenderTarget=!0,this.depth=s,this.texture=new Mi(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class Ni{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],l=s[i+2],u=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]=l,void(t[e+3]=u);if(1===o)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=m);if(u!==m||a!==c||h!==d||l!==p){let t=1-o;const e=a*c+h*d+l*p+u*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,l=l*t+p*r,u=u*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+l*l+u*u);a*=t,h*=t,l*=t,u*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=u}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],l=s[i+3],u=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+l*u+a*d-h*c,t[e+1]=a*p+l*c+h*u-o*d,t[e+2]=h*p+l*d+o*c-a*u,t[e+3]=l*p-o*u-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),l=o(i/2),u=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"YXZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"ZXY":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"ZYX":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"YZX":this._x=c*l*u+h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u-c*d*p;break;case"XZY":this._x=c*l*u-h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u+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],l=e[6],u=e[10],c=s+o+u;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>u){const t=2*Math.sqrt(1+s-o-u);this._w=(l-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>u){const t=2*Math.sqrt(1+o-s-u);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+u-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+l)/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(Hs(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,l=e._w;return this._x=s*l+n*o+i*h-r*a,this._y=i*l+n*a+r*o-s*h,this._z=r*l+n*h+s*a-i*o,this._w=n*l-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),l=Math.atan2(h,o),u=Math.sin((1-e)*l)/h,c=Math.sin(e*l)/h;return this._w=n*u+this._w*c,this._x=s*u+this._x*c,this._y=i*u+this._y*c,this._z=r*u+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 Ri{constructor(t=0,e=0,s=0){Ri.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(Ei.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ei.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),l=2*(o*e-r*i),u=2*(r*s-n*e);return this.x=e+a*h+n*u-o*l,this.y=s+a*l+o*h-r*u,this.z=i+a*u+r*l-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 Ci.copy(this).projectOnVector(t),this.sub(Ci)}reflect(t){return this.sub(Ci.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(Hs(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 Ci=new Ri,Ei=new Ni;class Bi{constructor(t=new Ri(1/0,1/0,1/0),e=new Ri(-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(Pi.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Pi.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=Pi.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,Pi):Pi.fromBufferAttribute(i,e),Pi.applyMatrix4(t.matrixWorld),this.expandByPoint(Pi);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),Fi.copy(t.boundingBox)):(null===s.boundingBox&&s.computeBoundingBox(),Fi.copy(s.boundingBox)),Fi.applyMatrix4(t.matrixWorld),this.union(Fi)}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,Pi),Pi.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(ki),Gi.subVectors(this.max,ki),Ui.subVectors(t.a,ki),Oi.subVectors(t.b,ki),zi.subVectors(t.c,ki),Li.subVectors(Oi,Ui),Vi.subVectors(zi,Oi),Di.subVectors(Ui,zi);let e=[0,-Li.z,Li.y,0,-Vi.z,Vi.y,0,-Di.z,Di.y,Li.z,0,-Li.x,Vi.z,0,-Vi.x,Di.z,0,-Di.x,-Li.y,Li.x,0,-Vi.y,Vi.x,0,-Di.y,Di.x,0];return!!Hi(e,Ui,Oi,zi,Gi)&&(e=[1,0,0,0,1,0,0,0,1],!!Hi(e,Ui,Oi,zi,Gi)&&(Wi.crossVectors(Li,Vi),e=[Wi.x,Wi.y,Wi.z],Hi(e,Ui,Oi,zi,Gi)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Pi).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Pi).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()||(Ii[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ii[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ii[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ii[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ii[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ii[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ii[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ii[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ii)),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 Ii=[new Ri,new Ri,new Ri,new Ri,new Ri,new Ri,new Ri,new Ri],Pi=new Ri,Fi=new Bi,Ui=new Ri,Oi=new Ri,zi=new Ri,Li=new Ri,Vi=new Ri,Di=new Ri,ki=new Ri,Gi=new Ri,Wi=new Ri,ji=new Ri;function Hi(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){ji.fromArray(t,n);const o=r.x*Math.abs(ji.x)+r.y*Math.abs(ji.y)+r.z*Math.abs(ji.z),a=e.dot(ji),h=s.dot(ji),l=i.dot(ji);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const qi=new Bi,$i=new Ri,Xi=new Ri;class Yi{constructor(t=new Ri,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):qi.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;$i.subVectors(t,this.center);const e=$i.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector($i,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):(Xi.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint($i.copy(t.center).add(Xi)),this.expandByPoint($i.copy(t.center).sub(Xi))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Ji=new Ri,Zi=new Ri,Qi=new Ri,Ki=new Ri,tr=new Ri,er=new Ri,sr=new Ri;class ir{constructor(t=new Ri,e=new Ri(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,Ji)),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=Ji.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Ji.copy(this.origin).addScaledVector(this.direction,e),Ji.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Zi.copy(t).add(e).multiplyScalar(.5),Qi.copy(e).sub(t).normalize(),Ki.copy(this.origin).sub(Zi);const r=.5*t.distanceTo(e),n=-this.direction.dot(Qi),o=Ki.dot(this.direction),a=-Ki.dot(Qi),h=Ki.lengthSq(),l=Math.abs(1-n*n);let u,c,d,p;if(l>0)if(u=n*a-o,c=n*o-a,p=r*l,u>=0)if(c>=-p)if(c<=p){const t=1/l;u*=t,c*=t,d=u*(u+n*c+2*o)+c*(n*u+c+2*a)+h}else c=r,u=Math.max(0,-(n*c+o)),d=-u*u+c*(c+2*a)+h;else c=-r,u=Math.max(0,-(n*c+o)),d=-u*u+c*(c+2*a)+h;else c<=-p?(u=Math.max(0,-(-n*r+o)),c=u>0?-r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h):c<=p?(u=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(u=Math.max(0,-(n*r+o)),c=u>0?r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h);else c=n>0?-r:r,u=Math.max(0,-(n*c+o)),d=-u*u+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(Zi).addScaledVector(Qi,c),d}intersectSphere(t,e){Ji.subVectors(t.center,this.origin);const s=Ji.dot(this.direction),i=Ji.dot(Ji)-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,l=1/this.direction.y,u=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),l>=0?(r=(t.min.y-c.y)*l,n=(t.max.y-c.y)*l):(r=(t.max.y-c.y)*l,n=(t.min.y-c.y)*l),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),u>=0?(o=(t.min.z-c.z)*u,a=(t.max.z-c.z)*u):(o=(t.max.z-c.z)*u,a=(t.min.z-c.z)*u),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,Ji)}intersectTriangle(t,e,s,i,r){tr.subVectors(e,t),er.subVectors(s,t),sr.crossVectors(tr,er);let n,o=this.direction.dot(sr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}Ki.subVectors(this.origin,t);const a=n*this.direction.dot(er.crossVectors(Ki,er));if(a<0)return null;const h=n*this.direction.dot(tr.cross(Ki));if(h<0)return null;if(a+h>o)return null;const l=-n*Ki.dot(sr);return l<0?null:this.at(l/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 rr{constructor(t,e,s,i,r,n,o,a,h,l,u,c,d,p,m,g){rr.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,l,u,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,l,u,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]=l,f[10]=u,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 rr).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/nr.setFromMatrixColumn(t,0).length(),r=1/nr.setFromMatrixColumn(t,1).length(),n=1/nr.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),l=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=n*l,s=n*u,i=o*l,r=o*u;e[0]=a*l,e[4]=-a*u,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*l,s=a*u,i=h*l,r=h*u;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*u,e[5]=n*l,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*l,s=a*u,i=h*l,r=h*u;e[0]=t-r*o,e[4]=-n*u,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*l,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*l,s=n*u,i=o*l,r=o*u;e[0]=a*l,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*u,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*l,e[4]=r-t*u,e[8]=i*u+s,e[1]=u,e[5]=n*l,e[9]=-o*l,e[2]=-h*l,e[6]=s*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*l,e[4]=-u,e[8]=h*l,e[1]=t*u+r,e[5]=n*l,e[9]=s*u-i,e[2]=i*u-s,e[6]=o*l,e[10]=r*u+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(ar,t,hr)}lookAt(t,e,s){const i=this.elements;return cr.subVectors(t,e),0===cr.lengthSq()&&(cr.z=1),cr.normalize(),lr.crossVectors(s,cr),0===lr.lengthSq()&&(1===Math.abs(s.z)?cr.x+=1e-4:cr.z+=1e-4,cr.normalize(),lr.crossVectors(s,cr)),lr.normalize(),ur.crossVectors(cr,lr),i[0]=lr.x,i[4]=ur.x,i[8]=cr.x,i[1]=lr.y,i[5]=ur.y,i[9]=cr.y,i[2]=lr.z,i[6]=ur.z,i[10]=cr.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],l=s[1],u=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],R=i[13],C=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*C+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*R+a*I+h*O,r[1]=l*T+u*M+c*C+d*P,r[5]=l*_+u*A+c*E+d*F,r[9]=l*w+u*N+c*B+d*U,r[13]=l*S+u*R+c*I+d*O,r[2]=p*T+m*M+g*C+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*R+g*I+f*O,r[3]=y*T+x*M+b*C+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*R+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],l=t[2],u=t[6],c=t[10],d=t[14];return t[3]*(+r*a*u-i*h*u-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*l-r*a*l)+t[11]*(+e*h*u-e*o*d-r*n*u+s*n*d+r*o*l-s*h*l)+t[15]*(-i*o*l-e*a*u+e*o*c+i*n*u-s*n*c+s*a*l)}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],l=t[8],u=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=u*g*h-m*c*h+m*a*d-o*g*d-u*a*f+o*c*f,x=p*c*h-l*g*h-p*a*d+n*g*d+l*a*f-n*c*f,b=l*m*h-p*u*h+p*o*d-n*m*d-l*o*f+n*u*f,v=p*u*a-l*m*a-p*o*c+n*m*c+l*o*g-n*u*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-u*g*r-m*i*d+s*g*d+u*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]=(u*a*r-o*c*r-u*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(l*g*r-p*c*r+p*i*d-e*g*d-l*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-l*a*r+l*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*u*r-l*m*r-p*s*d+e*m*d+l*s*f-e*u*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(l*o*r-n*u*r-l*s*h+e*u*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(l*m*i-p*u*i+p*s*c-e*m*c-l*s*g+e*u*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*u*i-l*o*i+l*s*a-e*u*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,l=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,l*o+s,l*a-i*n,0,h*a-i*o,l*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,l=n+n,u=o+o,c=r*h,d=r*l,p=r*u,m=n*l,g=n*u,f=o*u,y=a*h,x=a*l,b=a*u,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=nr.set(i[0],i[1],i[2]).length();const n=nr.set(i[4],i[5],i[6]).length(),o=nr.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],or.copy(this);const a=1/r,h=1/n,l=1/o;return or.elements[0]*=a,or.elements[1]*=a,or.elements[2]*=a,or.elements[4]*=h,or.elements[5]*=h,or.elements[6]*=h,or.elements[8]*=l,or.elements[9]*=l,or.elements[10]*=l,e.setFromRotationMatrix(or),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),l=2*r/(s-i),u=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===zs)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Ls)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]=u,a[12]=0,a[1]=0,a[5]=l,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),l=1/(s-i),u=1/(n-r),c=(e+t)*h,d=(s+i)*l;let p,m;if(o===zs)p=(n+r)*u,m=-2*u;else{if(o!==Ls)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*u,m=-1*u}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*l,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 nr=new Ri,or=new rr,ar=new Ri(0,0,0),hr=new Ri(1,1,1),lr=new Ri,ur=new Ri,cr=new Ri,dr=new rr,pr=new Ni;class mr{constructor(t=0,e=0,s=0,i=mr.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],l=i[9],u=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Hs(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-Hs(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(Hs(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-Hs(u,-1,1)),Math.abs(u)<.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(Hs(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-Hs(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,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 dr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(dr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return pr.setFromEuler(this),this.setFromQuaternion(pr,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}}mr.DEFAULT_ORDER="XYZ";class gr{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 fr=0;const yr=new Ri,xr=new Ni,br=new rr,vr=new Ri,Tr=new Ri,_r=new Ri,wr=new Ni,Sr=new Ri(1,0,0),Mr=new Ri(0,1,0),Ar=new Ri(0,0,1),Nr={type:"added"},Rr={type:"removed"},Cr={type:"childadded",child:null},Er={type:"childremoved",child:null};class Br extends Vs{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:fr++}),this.uuid=js(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Br.DEFAULT_UP.clone();const t=new Ri,e=new mr,s=new Ni,i=new Ri(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 rr},normalMatrix:{value:new Qs}}),this.matrix=new rr,this.matrixWorld=new rr,this.matrixAutoUpdate=Br.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Br.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new gr,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 xr.setFromAxisAngle(t,e),this.quaternion.multiply(xr),this}rotateOnWorldAxis(t,e){return xr.setFromAxisAngle(t,e),this.quaternion.premultiply(xr),this}rotateX(t){return this.rotateOnAxis(Sr,t)}rotateY(t){return this.rotateOnAxis(Mr,t)}rotateZ(t){return this.rotateOnAxis(Ar,t)}translateOnAxis(t,e){return yr.copy(t).applyQuaternion(this.quaternion),this.position.add(yr.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Sr,t)}translateY(t){return this.translateOnAxis(Mr,t)}translateZ(t){return this.translateOnAxis(Ar,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(br.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?vr.copy(t):vr.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),Tr.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?br.lookAt(Tr,vr,this.up):br.lookAt(vr,Tr,this.up),this.quaternion.setFromRotationMatrix(br),i&&(br.extractRotation(i.matrixWorld),xr.setFromRotationMatrix(br),this.quaternion.premultiply(xr.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(Nr),Cr.child=t,this.dispatchEvent(Cr),Cr.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(Rr),Er.child=t,this.dispatchEvent(Er),Er.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),br.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),br.multiply(t.parent.matrixWorld)),t.applyMatrix4(br),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Nr),Cr.child=t,this.dispatchEvent(Cr),Cr.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(Tr,t,_r),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Tr,wr,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),l=n(t.animations),u=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),l.length>0&&(s.animations=l),u.length>0&&(s.nodes=u)}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}}Br.DEFAULT_UP=new Ri(0,1,0),Br.DEFAULT_MATRIX_AUTO_UPDATE=!0,Br.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Ir=new Ri,Pr=new Ri,Fr=new Ri,Ur=new Ri,Or=new Ri,zr=new Ri,Lr=new Ri,Vr=new Ri,Dr=new Ri,kr=new Ri;class Gr{constructor(t=new Ri,e=new Ri,s=new Ri){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),Ir.subVectors(t,e),i.cross(Ir);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){Ir.subVectors(i,e),Pr.subVectors(s,e),Fr.subVectors(t,e);const n=Ir.dot(Ir),o=Ir.dot(Pr),a=Ir.dot(Fr),h=Pr.dot(Pr),l=Pr.dot(Fr),u=n*h-o*o;if(0===u)return r.set(0,0,0),null;const c=1/u,d=(h*a-o*l)*c,p=(n*l-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,Ur)&&(Ur.x>=0&&Ur.y>=0&&Ur.x+Ur.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Ur)?(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,Ur.x),a.addScaledVector(n,Ur.y),a.addScaledVector(o,Ur.z),a)}static isFrontFacing(t,e,s,i){return Ir.subVectors(s,e),Pr.subVectors(t,e),Ir.cross(Pr).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 Ir.subVectors(this.c,this.b),Pr.subVectors(this.a,this.b),.5*Ir.cross(Pr).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Gr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Gr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return Gr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return Gr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Gr.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;Or.subVectors(i,s),zr.subVectors(r,s),Vr.subVectors(t,s);const a=Or.dot(Vr),h=zr.dot(Vr);if(a<=0&&h<=0)return e.copy(s);Dr.subVectors(t,i);const l=Or.dot(Dr),u=zr.dot(Dr);if(l>=0&&u<=l)return e.copy(i);const c=a*u-l*h;if(c<=0&&a>=0&&l<=0)return n=a/(a-l),e.copy(s).addScaledVector(Or,n);kr.subVectors(t,r);const d=Or.dot(kr),p=zr.dot(kr);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(zr,o);const g=l*p-d*u;if(g<=0&&u-l>=0&&d-p>=0)return Lr.subVectors(r,i),o=(u-l)/(u-l+(d-p)),e.copy(i).addScaledVector(Lr,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(Or,n).addScaledVector(zr,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Wr={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},jr={h:0,s:0,l:0},Hr={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 $r{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=Xe){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,ui.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=ui.workingColorSpace){return this.r=t,this.g=e,this.b=s,ui.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=ui.workingColorSpace){if(t=qs(t,1),e=Hs(e,0,1),s=Hs(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 ui.toWorkingColorSpace(this,i),this}setStyle(t,e=Xe){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=Xe){const s=Wr[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=ci(t.r),this.g=ci(t.g),this.b=ci(t.b),this}copyLinearToSRGB(t){return this.r=di(t.r),this.g=di(t.g),this.b=di(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Xe){return ui.fromWorkingColorSpace(Xr.copy(this),t),65536*Math.round(Hs(255*Xr.r,0,255))+256*Math.round(Hs(255*Xr.g,0,255))+Math.round(Hs(255*Xr.b,0,255))}getHexString(t=Xe){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ui.workingColorSpace){ui.fromWorkingColorSpace(Xr.copy(this),e);const s=Xr.r,i=Xr.g,r=Xr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const l=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=l<=.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=l,t}getRGB(t,e=ui.workingColorSpace){return ui.fromWorkingColorSpace(Xr.copy(this),e),t.r=Xr.r,t.g=Xr.g,t.b=Xr.b,t}getStyle(t=Xe){ui.fromWorkingColorSpace(Xr.copy(this),t);const e=Xr.r,s=Xr.g,i=Xr.b;return t!==Xe?`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(jr),this.setHSL(jr.h+t,jr.s+e,jr.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(jr),t.getHSL(Hr);const s=$s(jr.h,Hr.h,e),i=$s(jr.s,Hr.s,e),r=$s(jr.l,Hr.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 Xr=new $r;$r.NAMES=Wr;let Yr=0;class Jr extends Vs{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Yr++}),this.uuid=js(),this.name="",this.type="Material",this.blending=1,this.side=c,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=C,this.blendDst=E,this.blendEquation=v,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new $r(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=ys,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=is,this.stencilZFail=is,this.stencilZPass=is,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}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!==C&&(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!==ys&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==is&&(s.stencilFail=this.stencilFail),this.stencilZFail!==is&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==is&&(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.")}onBeforeRender(){console.warn("Material: onBeforeRender() has been removed.")}}class Zr extends Jr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new $r(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 mr,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=Kr();function Kr(){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 tn(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=Hs(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 en(t){const e=t>>10;return Qr.uint32View[0]=Qr.mantissaTable[Qr.offsetTable[e]+(1023&t)]+Qr.exponentTable[e],Qr.floatView[0]}const sn={toHalfFloat:tn,fromHalfFloat:en},rn=new Ri,nn=new Zs;class on{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=As,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=It,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ni("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}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++)nn.fromBufferAttribute(this,e),nn.applyMatrix3(t),this.setXY(e,nn.x,nn.y);else if(3===this.itemSize)for(let e=0,s=this.count;e<s;e++)rn.fromBufferAttribute(this,e),rn.applyMatrix3(t),this.setXYZ(e,rn.x,rn.y,rn.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)rn.fromBufferAttribute(this,e),rn.applyMatrix4(t),this.setXYZ(e,rn.x,rn.y,rn.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)rn.fromBufferAttribute(this,e),rn.applyNormalMatrix(t),this.setXYZ(e,rn.x,rn.y,rn.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)rn.fromBufferAttribute(this,e),rn.transformDirection(t),this.setXYZ(e,rn.x,rn.y,rn.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=Xs(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=Ys(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Xs(e,this.array)),e}setX(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Xs(e,this.array)),e}setY(t,e){return this.normalized&&(e=Ys(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=Xs(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Ys(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=Xs(e,this.array)),e}setW(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=Ys(e,this.array),s=Ys(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=Ys(e,this.array),s=Ys(s,this.array),i=Ys(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=Ys(e,this.array),s=Ys(s,this.array),i=Ys(i,this.array),r=Ys(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!==As&&(t.usage=this.usage),t}}class an extends on{constructor(t,e,s){super(new Int8Array(t),e,s)}}class hn extends on{constructor(t,e,s){super(new Uint8Array(t),e,s)}}class ln extends on{constructor(t,e,s){super(new Uint8ClampedArray(t),e,s)}}class un extends on{constructor(t,e,s){super(new Int16Array(t),e,s)}}class cn extends on{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class dn extends on{constructor(t,e,s){super(new Int32Array(t),e,s)}}class pn extends on{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class mn extends on{constructor(t,e,s){super(new Uint16Array(t),e,s),this.isFloat16BufferAttribute=!0}getX(t){let e=en(this.array[t*this.itemSize]);return this.normalized&&(e=Xs(e,this.array)),e}setX(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize]=tn(e),this}getY(t){let e=en(this.array[t*this.itemSize+1]);return this.normalized&&(e=Xs(e,this.array)),e}setY(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize+1]=tn(e),this}getZ(t){let e=en(this.array[t*this.itemSize+2]);return this.normalized&&(e=Xs(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize+2]=tn(e),this}getW(t){let e=en(this.array[t*this.itemSize+3]);return this.normalized&&(e=Xs(e,this.array)),e}setW(t,e){return this.normalized&&(e=Ys(e,this.array)),this.array[t*this.itemSize+3]=tn(e),this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=Ys(e,this.array),s=Ys(s,this.array)),this.array[t+0]=tn(e),this.array[t+1]=tn(s),this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=Ys(e,this.array),s=Ys(s,this.array),i=Ys(i,this.array)),this.array[t+0]=tn(e),this.array[t+1]=tn(s),this.array[t+2]=tn(i),this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=Ys(e,this.array),s=Ys(s,this.array),i=Ys(i,this.array),r=Ys(r,this.array)),this.array[t+0]=tn(e),this.array[t+1]=tn(s),this.array[t+2]=tn(i),this.array[t+3]=tn(r),this}}class gn extends on{constructor(t,e,s){super(new Float32Array(t),e,s)}}let fn=0;const yn=new rr,xn=new Br,bn=new Ri,vn=new Bi,Tn=new Bi,_n=new Ri;class wn extends Vs{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:fn++}),this.uuid=js(),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)?pn:cn)(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 Qs).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 yn.makeRotationFromQuaternion(t),this.applyMatrix4(yn),this}rotateX(t){return yn.makeRotationX(t),this.applyMatrix4(yn),this}rotateY(t){return yn.makeRotationY(t),this.applyMatrix4(yn),this}rotateZ(t){return yn.makeRotationZ(t),this.applyMatrix4(yn),this}translate(t,e,s){return yn.makeTranslation(t,e,s),this.applyMatrix4(yn),this}scale(t,e,s){return yn.makeScale(t,e,s),this.applyMatrix4(yn),this}lookAt(t){return xn.lookAt(t),xn.updateMatrix(),this.applyMatrix4(xn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(bn).negate(),this.translate(bn.x,bn.y,bn.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 gn(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Bi);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 Ri(-1/0,-1/0,-1/0),new Ri(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];vn.setFromBufferAttribute(s),this.morphTargetsRelative?(_n.addVectors(this.boundingBox.min,vn.min),this.boundingBox.expandByPoint(_n),_n.addVectors(this.boundingBox.max,vn.max),this.boundingBox.expandByPoint(_n)):(this.boundingBox.expandByPoint(vn.min),this.boundingBox.expandByPoint(vn.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 Yi);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 Ri,1/0);if(t){const s=this.boundingSphere.center;if(vn.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];Tn.setFromBufferAttribute(s),this.morphTargetsRelative?(_n.addVectors(vn.min,Tn.min),vn.expandByPoint(_n),_n.addVectors(vn.max,Tn.max),vn.expandByPoint(_n)):(vn.expandByPoint(Tn.min),vn.expandByPoint(Tn.max))}vn.getCenter(s);let i=0;for(let e=0,r=t.count;e<r;e++)_n.fromBufferAttribute(t,e),i=Math.max(i,s.distanceToSquared(_n));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++)_n.fromBufferAttribute(n,e),o&&(bn.fromBufferAttribute(t,e),_n.add(bn)),i=Math.max(i,s.distanceToSquared(_n))}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 on(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),o=[],a=[];for(let t=0;t<s.count;t++)o[t]=new Ri,a[t]=new Ri;const h=new Ri,l=new Ri,u=new Ri,c=new Zs,d=new Zs,p=new Zs,m=new Ri,g=new Ri;function f(t,e,i){h.fromBufferAttribute(s,t),l.fromBufferAttribute(s,e),u.fromBufferAttribute(s,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),l.sub(h),u.sub(h),d.sub(c),p.sub(c);const n=1/(d.x*p.y-p.x*d.y);isFinite(n)&&(m.copy(l).multiplyScalar(p.y).addScaledVector(u,-d.y).multiplyScalar(n),g.copy(u).multiplyScalar(d.x).addScaledVector(l,-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 Ri,b=new Ri,v=new Ri,T=new Ri;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 on(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 Ri,r=new Ri,n=new Ri,o=new Ri,a=new Ri,h=new Ri,l=new Ri,u=new Ri;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),l.subVectors(n,r),u.subVectors(i,r),l.cross(u),o.fromBufferAttribute(s,d),a.fromBufferAttribute(s,p),h.fromBufferAttribute(s,m),o.add(l),a.add(l),h.add(l),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),l.subVectors(n,r),u.subVectors(i,r),l.cross(u),s.setXYZ(t+0,l.x,l.y,l.z),s.setXYZ(t+1,l.x,l.y,l.z),s.setXYZ(t+2,l.x,l.y,l.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)_n.fromBufferAttribute(t,e),_n.normalize(),t.setXYZ(e,_n.x,_n.y,_n.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 on(n,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new wn,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 Sn=new rr,Mn=new ir,An=new Yi,Nn=new Ri,Rn=new Ri,Cn=new Ri,En=new Ri,Bn=new Ri,In=new Ri,Pn=new Zs,Fn=new Zs,Un=new Zs,On=new Ri,zn=new Ri,Ln=new Ri,Vn=new Ri,Dn=new Ri;class kn extends Br{constructor(t=new wn,e=new Zr){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){In.set(0,0,0);for(let s=0,i=r.length;s<i;s++){const i=o[s],a=r[s];0!==i&&(Bn.fromBufferAttribute(a,t),n?In.addScaledVector(Bn,i):In.addScaledVector(Bn.sub(e),i))}e.add(In)}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(),An.copy(s.boundingSphere),An.applyMatrix4(r),Mn.copy(t.ray).recast(t.near),!1===An.containsPoint(Mn.origin)){if(null===Mn.intersectSphere(An,Nn))return;if(Mn.origin.distanceToSquared(Nn)>(t.far-t.near)**2)return}Sn.copy(r).invert(),Mn.copy(t.ray).applyMatrix4(Sn),null!==s.boundingBox&&!1===Mn.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,Mn)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,l=r.attributes.uv1,u=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=Gn(this,p,t,s,h,l,u,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=Gn(this,n,t,s,h,l,u,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=Gn(this,p,t,s,h,l,u,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=Gn(this,n,t,s,h,l,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function Gn(t,e,s,i,r,n,o,a,h,l){t.getVertexPosition(a,Rn),t.getVertexPosition(h,Cn),t.getVertexPosition(l,En);const u=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;Dn.copy(a),Dn.applyMatrix4(t.matrixWorld);const l=s.ray.origin.distanceTo(Dn);return l<s.near||l>s.far?null:{distance:l,point:Dn.clone(),object:t}}(t,e,s,i,Rn,Cn,En,Vn);if(u){r&&(Pn.fromBufferAttribute(r,a),Fn.fromBufferAttribute(r,h),Un.fromBufferAttribute(r,l),u.uv=Gr.getInterpolation(Vn,Rn,Cn,En,Pn,Fn,Un,new Zs)),n&&(Pn.fromBufferAttribute(n,a),Fn.fromBufferAttribute(n,h),Un.fromBufferAttribute(n,l),u.uv1=Gr.getInterpolation(Vn,Rn,Cn,En,Pn,Fn,Un,new Zs)),o&&(On.fromBufferAttribute(o,a),zn.fromBufferAttribute(o,h),Ln.fromBufferAttribute(o,l),u.normal=Gr.getInterpolation(Vn,Rn,Cn,En,On,zn,Ln,new Ri),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const t={a:a,b:h,c:l,normal:new Ri,materialIndex:0};Gr.getNormal(Rn,Cn,En,t.normal),u.face=t}return u}class Wn extends wn{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=[],l=[],u=[];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 Ri;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,l.push(N.x,N.y,N.z),u.push(a/g),u.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 gn(h,3)),this.setAttribute("normal",new gn(l,3)),this.setAttribute("uv",new gn(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Wn(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function jn(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 Hn extends Jr{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",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=jn(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 qn extends Br{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new rr,this.projectionMatrix=new rr,this.projectionMatrixInverse=new rr,this.coordinateSystem=zs}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 $n=new Ri,Xn=new Zs,Yn=new Zs;class Jn extends qn{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*Ws*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Gs*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Ws*Math.atan(Math.tan(.5*Gs*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){$n.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set($n.x,$n.y).multiplyScalar(-t/$n.z),$n.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set($n.x,$n.y).multiplyScalar(-t/$n.z)}getViewSize(t,e){return this.getViewBounds(t,Xn,Yn),e.subVectors(Yn,Xn)}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*Gs*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 Zn=-90;class Qn extends Br{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Jn(Zn,1,t,e);i.layers=this.layers,this.add(i);const r=new Jn(Zn,1,t,e);r.layers=this.layers,this.add(r);const n=new Jn(Zn,1,t,e);n.layers=this.layers,this.add(n);const o=new Jn(Zn,1,t,e);o.layers=this.layers,this.add(o);const a=new Jn(Zn,1,t,e);a.layers=this.layers,this.add(a);const h=new Jn(Zn,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===zs)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!==Ls)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,l]=this.children,u=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,l),t.setRenderTarget(u,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class Kn extends bi{constructor(t,e,s,i,r,n,o,a,h,l){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,l),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class to extends _i{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 Kn(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 Wn(5,5,5),r=new Hn({name:"CubemapFromEquirect",uniforms:jn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new kn(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 eo{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new $r(t),this.density=e}clone(){return new eo(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class so{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new $r(t),this.near=e,this.far=s}clone(){return new so(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class io extends Br{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 mr,this.environmentIntensity=1,this.environmentRotation=new mr,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 ro{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=As,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.version=0,this.uuid=js()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ni("THREE.InterleavedBuffer: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}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=js()),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=js()),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 no=new Ri;class oo{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++)no.fromBufferAttribute(this,e),no.applyMatrix4(t),this.setXYZ(e,no.x,no.y,no.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)no.fromBufferAttribute(this,e),no.applyNormalMatrix(t),this.setXYZ(e,no.x,no.y,no.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)no.fromBufferAttribute(this,e),no.transformDirection(t),this.setXYZ(e,no.x,no.y,no.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=Xs(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=Ys(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=Ys(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Ys(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Ys(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Ys(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=Xs(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=Xs(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=Xs(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=Xs(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Ys(e,this.array),s=Ys(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=Ys(e,this.array),s=Ys(s,this.array),i=Ys(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=Ys(e,this.array),s=Ys(s,this.array),i=Ys(i,this.array),r=Ys(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 on(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 oo(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 ao extends Jr{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new $r(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 ho;const lo=new Ri,uo=new Ri,co=new Ri,po=new Zs,mo=new Zs,go=new rr,fo=new Ri,yo=new Ri,xo=new Ri,bo=new Zs,vo=new Zs,To=new Zs;class _o extends Br{constructor(t=new ao){if(super(),this.isSprite=!0,this.type="Sprite",void 0===ho){ho=new wn;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 ro(t,5);ho.setIndex([0,1,2,0,2,3]),ho.setAttribute("position",new oo(e,3,0,!1)),ho.setAttribute("uv",new oo(e,2,3,!1))}this.geometry=ho,this.material=t,this.center=new Zs(.5,.5)}raycast(t,e){null===t.camera&&console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),uo.setFromMatrixScale(this.matrixWorld),go.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),co.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&uo.multiplyScalar(-co.z);const s=this.material.rotation;let i,r;0!==s&&(r=Math.cos(s),i=Math.sin(s));const n=this.center;wo(fo.set(-.5,-.5,0),co,n,uo,i,r),wo(yo.set(.5,-.5,0),co,n,uo,i,r),wo(xo.set(.5,.5,0),co,n,uo,i,r),bo.set(0,0),vo.set(1,0),To.set(1,1);let o=t.ray.intersectTriangle(fo,yo,xo,!1,lo);if(null===o&&(wo(yo.set(-.5,.5,0),co,n,uo,i,r),vo.set(0,1),o=t.ray.intersectTriangle(fo,xo,yo,!1,lo),null===o))return;const a=t.ray.origin.distanceTo(lo);a<t.near||a>t.far||e.push({distance:a,point:lo.clone(),uv:Gr.getInterpolation(lo,fo,yo,xo,bo,vo,To,new Zs),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 wo(t,e,s,i,r,n){po.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(mo.x=n*po.x-r*po.y,mo.y=r*po.x+n*po.y):mo.copy(po),t.copy(e),t.x+=mo.x,t.y+=mo.y,t.applyMatrix4(go)}const So=new Ri,Mo=new Ri;class Ao extends Br{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}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){So.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(So);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){So.setFromMatrixPosition(t.matrixWorld),Mo.setFromMatrixPosition(this.matrixWorld);const s=So.distanceTo(Mo)/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 No=new Ri,Ro=new vi,Co=new vi,Eo=new Ri,Bo=new rr,Io=new Ri,Po=new Yi,Fo=new rr,Uo=new ir;class Oo extends kn{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=nt,this.bindMatrix=new rr,this.bindMatrixInverse=new rr,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;null===this.boundingBox&&(this.boundingBox=new Bi),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,Io),this.boundingBox.expandByPoint(Io)}computeBoundingSphere(){const t=this.geometry;null===this.boundingSphere&&(this.boundingSphere=new Yi),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,Io),this.boundingSphere.expandByPoint(Io)}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(),Po.copy(this.boundingSphere),Po.applyMatrix4(i),!1!==t.ray.intersectsSphere(Po)&&(Fo.copy(i).invert(),Uo.copy(t.ray).applyMatrix4(Fo),null!==this.boundingBox&&!1===Uo.intersectsBox(this.boundingBox)||this._computeIntersections(t,e,Uo)))}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 vi,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;Ro.fromBufferAttribute(i.attributes.skinIndex,t),Co.fromBufferAttribute(i.attributes.skinWeight,t),No.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const i=Co.getComponent(t);if(0!==i){const r=Ro.getComponent(t);Bo.multiplyMatrices(s.bones[r].matrixWorld,s.boneInverses[r]),e.addScaledVector(Eo.copy(No).applyMatrix4(Bo),i)}}return e.applyMatrix4(this.bindMatrixInverse)}}class zo extends Br{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Lo extends bi{constructor(t=null,e=1,s=1,i,r,n,o,a,h=1003,l=1003,u,c){super(null,n,o,a,h,l,i,r,u,c),this.isDataTexture=!0,this.image={data:t,width:e,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Vo=new rr,Do=new rr;class ko{constructor(t=[],e=[]){this.uuid=js(),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 rr)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const e=new rr;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:Do;Vo.multiplyMatrices(r,e[i]),Vo.toArray(s,16*i)}null!==i&&(i.needsUpdate=!0)}clone(){return new ko(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 Lo(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 zo),this.bones.push(r),this.boneInverses.push((new rr).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 Go extends on{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 Wo=new rr,jo=new rr,Ho=[],qo=new Bi,$o=new rr,Xo=new kn,Yo=new Yi;class Jo extends kn{constructor(t,e,s){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Go(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,$o)}computeBoundingBox(){const t=this.geometry,e=this.count;null===this.boundingBox&&(this.boundingBox=new Bi),null===t.boundingBox&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Wo),qo.copy(t.boundingBox).applyMatrix4(Wo),this.boundingBox.union(qo)}computeBoundingSphere(){const t=this.geometry,e=this.count;null===this.boundingSphere&&(this.boundingSphere=new Yi),null===t.boundingSphere&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Wo),Yo.copy(t.boundingSphere).applyMatrix4(Wo),this.boundingSphere.union(Yo)}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(Xo.geometry=this.geometry,Xo.material=this.material,void 0!==Xo.material&&(null===this.boundingSphere&&this.computeBoundingSphere(),Yo.copy(this.boundingSphere),Yo.applyMatrix4(s),!1!==t.ray.intersectsSphere(Yo)))for(let r=0;r<i;r++){this.getMatrixAt(r,Wo),jo.multiplyMatrices(s,Wo),Xo.matrixWorld=jo,Xo.raycast(t,Ho);for(let t=0,s=Ho.length;t<s;t++){const s=Ho[t];s.instanceId=r,s.object=this,e.push(s)}Ho.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new Go(new Float32Array(3*this.instanceMatrix.count),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 Lo(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 Zo=new Ri,Qo=new Ri,Ko=new Qs;class ta{constructor(t=new Ri(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=Zo.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(Zo),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||Ko.getNormalMatrix(t),i=this.coplanarPoint(Zo).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 ea=new Yi,sa=new Ri;class ia{constructor(t=new ta,e=new ta,s=new ta,i=new ta,r=new ta,n=new ta){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],l=i[5],u=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+l,g+p,b+y).normalize(),s[3].setComponents(a-n,c-l,g-p,b-y).normalize(),s[4].setComponents(a-o,c-u,g-m,b-x).normalize(),e===zs)s[5].setComponents(a+o,c+u,g+m,b+x).normalize();else{if(e!==Ls)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,u,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),ea.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),ea.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ea)}intersectsSprite(t){return ea.center.set(0,0,0),ea.radius=.7071067811865476,ea.applyMatrix4(t.matrixWorld),this.intersectsSphere(ea)}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(sa.x=i.normal.x>0?t.max.x:t.min.x,sa.y=i.normal.y>0?t.max.y:t.min.y,sa.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(sa)<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 ra(t,e){return t.z-e.z}function na(t,e){return e.z-t.z}class oa{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 aa=new rr,ha=new rr,la=new rr,ua=new $r(1,1,1),ca=new rr,da=new ia,pa=new Bi,ma=new Yi,ga=new Ri,fa=new Ri,ya=new Ri,xa=new oa,ba=new kn,va=[];function Ta(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 _a extends kn{get maxInstanceCount(){return this._maxInstanceCount}constructor(t,e,s=2*e,i){super(new wn,i),this.isBatchedMesh=!0,this.perObjectFrustumCulled=!0,this.sortObjects=!0,this.boundingBox=null,this.boundingSphere=null,this.customSort=null,this._drawInfo=[],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 Lo(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 Lo(e,t,t,qt,Bt);this._indirectTexture=s}_initColorsTexture(){let t=Math.sqrt(this._maxIndexCount);t=Math.ceil(t);const e=new Float32Array(t*t*4).fill(1),s=new Lo(e,t,t,Dt,It);s.colorSpace=ui.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),l=new on(h,o,a);e.setAttribute(i,l)}if(null!==t.getIndex()){const t=s>65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new on(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 Bi);const t=this._geometryCount,e=this.boundingBox,s=this._drawInfo;e.makeEmpty();for(let i=0;i<t;i++){if(!1===s[i].active)continue;const t=s[i].geometryIndex;this.getMatrixAt(i,aa),this.getBoundingBoxAt(t,pa).applyMatrix4(aa),e.union(pa)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new Yi);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,aa),this.getBoundingSphereAt(i,ma).applyMatrix4(aa),t.union(ma)}}addInstance(t){if(this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");this._drawInfo.push({visible:!0,active:!0,geometryIndex:t});const e=this._drawInfo.length-1,s=this._matricesTexture,i=s.image.data;la.toArray(i,16*e),s.needsUpdate=!0;const r=this._colorsTexture;return r&&(ua.toArray(r.image.data,4*e),r.needsUpdate=!0),e}addGeometry(t,e=-1,s=-1){if(this._initializeGeometry(t),this._validateGeometry(t),this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let 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(),l=null!==h;if(l&&(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 u=this._geometryCount;return this._geometryCount++,n.push(i),o.push({start:l?i.indexStart:i.vertexStart,count:-1}),a.push({boxInitialized:!1,box:new Bi,sphereInitialized:!1,sphere:new Yi}),this.setGeometryAt(u,t),u}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);Ta(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 l=this._bounds[t];null!==e.boundingBox?(l.box.copy(e.boundingBox),l.boxInitialized=!0):l.boxInitialized=!1,null!==e.boundingSphere?(l.sphere.copy(e.boundingSphere),l.sphereInitialized=!0):l.sphereInitialized=!1;const u=this._drawRanges[t],c=e.getAttribute("position");return u.count=i?n.count:c.count,this._visibilityChanged=!0,t}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(ga.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,pa),pa.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)),ga.fromBufferAttribute(n,s),a=Math.max(a,i.center.distanceToSquared(ga))}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}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;ba.material=this.material,ba.geometry.index=n.index,ba.geometry.attributes=n.attributes,null===ba.geometry.boundingBox&&(ba.geometry.boundingBox=new Bi),null===ba.geometry.boundingSphere&&(ba.geometry.boundingSphere=new Yi);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];ba.geometry.setDrawRange(a.start,a.count),this.getMatrixAt(n,ba.matrixWorld).premultiply(r),this.getBoundingBoxAt(o,ba.geometry.boundingBox),this.getBoundingSphereAt(o,ba.geometry.boundingSphere),ba.raycast(t,va);for(let t=0,s=va.length;t<s;t++){const s=va[t];s.object=this,s.batchId=n,e.push(s)}va.length=0}ba.material=null,ba.geometry.index=null,ba.geometry.attributes={},ba.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.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.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,l=this._multiDrawCounts,u=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(ca.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),da.setFromProjectionMatrix(ca,t.coordinateSystem));let m=0;if(this.sortObjects){ha.copy(this.matrixWorld).invert(),ga.setFromMatrixPosition(s.matrixWorld).applyMatrix4(ha),fa.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(ha);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,aa),this.getBoundingSphereAt(e,ma).applyMatrix4(aa);let s=!1;if(c&&(s=!da.intersectsSphere(ma)),!s){const s=ya.subVectors(ma.center,ga).dot(fa);xa.push(u[e],s,t)}}const t=xa.list,e=this.customSort;null===e?t.sort(r.transparent?na:ra):e.call(this,t,s);for(let e=0,s=t.length;e<s;e++){const s=t[e];h[m]=s.start*o,l[m]=s.count,p[m]=s.index,m++}xa.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,aa),this.getBoundingSphereAt(e,ma).applyMatrix4(aa),s=!da.intersectsSphere(ma)),!s){const s=u[e];h[m]=s.start*o,l[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 wa extends Jr{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new $r(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 Sa=new Ri,Ma=new Ri,Aa=new rr,Na=new ir,Ra=new Yi,Ca=new Ri,Ea=new Ri;class Ba extends Br{constructor(t=new wn,e=new wa){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++)Sa.fromBufferAttribute(e,t-1),Ma.fromBufferAttribute(e,t),s[t]=s[t-1],s[t]+=Sa.distanceTo(Ma);t.setAttribute("lineDistance",new gn(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(),Ra.copy(s.boundingSphere),Ra.applyMatrix4(i),Ra.radius+=r,!1===t.ray.intersectsSphere(Ra))return;Aa.copy(i).invert(),Na.copy(t.ray).applyMatrix4(Aa);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=this.isLineSegments?2:1,l=s.index,u=s.attributes.position;if(null!==l){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=l.getX(r),i=l.getX(r+1),n=Ia(this,t,Na,a,s,i);n&&e.push(n)}if(this.isLineLoop){const r=l.getX(i-1),n=l.getX(s),o=Ia(this,t,Na,a,r,n);o&&e.push(o)}}else{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=Ia(this,t,Na,a,r,r+1);s&&e.push(s)}if(this.isLineLoop){const r=Ia(this,t,Na,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 Ia(t,e,s,i,r,n){const o=t.geometry.attributes.position;Sa.fromBufferAttribute(o,r),Ma.fromBufferAttribute(o,n);if(s.distanceSqToSegment(Sa,Ma,Ca,Ea)>i)return;Ca.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Ca);return a<e.near||a>e.far?void 0:{distance:a,point:Ea.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,object:t}}const Pa=new Ri,Fa=new Ri;class Ua extends Ba{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)Pa.fromBufferAttribute(e,t),Fa.fromBufferAttribute(e,t+1),s[t]=0===t?0:s[t-1],s[t+1]=s[t]+Pa.distanceTo(Fa);t.setAttribute("lineDistance",new gn(s,1))}else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class Oa extends Ba{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class za extends Jr{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new $r(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 La=new rr,Va=new ir,Da=new Yi,ka=new Ri;class Ga extends Br{constructor(t=new wn,e=new za){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(),Da.copy(s.boundingSphere),Da.applyMatrix4(i),Da.radius+=r,!1===t.ray.intersectsSphere(Da))return;La.copy(i).invert(),Va.copy(t.ray).applyMatrix4(La);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=s.index,l=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);ka.fromBufferAttribute(l,r),Wa(ka,r,a,i,t,e,this)}}else{for(let s=Math.max(0,n.start),r=Math.min(l.count,n.start+n.count);s<r;s++)ka.fromBufferAttribute(l,s),Wa(ka,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 Wa(t,e,s,i,r,n,o){const a=Va.distanceSqToPoint(t);if(a<s){const s=new Ri;Va.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,object:o})}}class ja extends Br{constructor(){super(),this.isGroup=!0,this.type="Group"}}class Ha extends bi{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 l=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){l.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 qa extends bi{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class $a extends bi{constructor(t,e,s,i,r,n,o,a,h,l,u,c){super(null,n,o,a,h,l,i,r,u,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Xa extends $a{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 Ya extends $a{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 Ja extends bi{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 Za extends bi{constructor(t,e,s,i,r,n,o,a,h,l=1026){if(l!==Wt&&l!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&l===Wt&&(s=Bt),void 0===s&&l===jt&&(s=Ot),super(null,i,r,n,o,a,l,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 l=s[i];return(i+(n-l)/(s[i+1]-l))/(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 Zs:new Ri);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 Ri,i=[],r=[],n=[],o=new Ri,a=new rr;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ri)}r[0]=new Ri,n[0]=new Ri;let h=Number.MAX_VALUE;const l=Math.abs(i[0].x),u=Math.abs(i[0].y),c=Math.abs(i[0].z);l<=h&&(h=l,s.set(1,0,0)),u<=h&&(h=u,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(Hs(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(Hs(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 Ka 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 Zs){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 th extends Ka{constructor(t,e,s,i,r,n){super(t,e,s,s,i,r,n),this.isArcCurve=!0,this.type="ArcCurve"}}function eh(){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,l=(s-e)/o-(i-e)/(o+a)+(i-s)/a;h*=o,l*=o,r(e,s,h,l)},calc:function(r){const n=r*r;return t+e*r+s*n+i*(n*r)}}}const sh=new Ri,ih=new eh,rh=new eh,nh=new eh;class oh 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 Ri){const s=e,i=this.points,r=i.length,n=(r-(this.closed?0:1))*t;let o,a,h=Math.floor(n),l=n-h;this.closed?h+=h>0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===l&&h===r-1&&(h=r-2,l=1),this.closed||h>0?o=i[(h-1)%r]:(sh.subVectors(i[0],i[1]).add(i[0]),o=sh);const u=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(sh.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=sh),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(o.distanceToSquared(u),t),s=Math.pow(u.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),ih.initNonuniformCatmullRom(o.x,u.x,c.x,a.x,e,s,i),rh.initNonuniformCatmullRom(o.y,u.y,c.y,a.y,e,s,i),nh.initNonuniformCatmullRom(o.z,u.z,c.z,a.z,e,s,i)}else"catmullrom"===this.curveType&&(ih.initCatmullRom(o.x,u.x,c.x,a.x,this.tension),rh.initCatmullRom(o.y,u.y,c.y,a.y,this.tension),nh.initCatmullRom(o.z,u.z,c.z,a.z,this.tension));return s.set(ih.calc(l),rh.calc(l),nh.calc(l)),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 Ri).fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function ah(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 hh(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 lh(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 uh extends Qa{constructor(t=new Zs,e=new Zs,s=new Zs,i=new Zs){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Zs){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(lh(t,i.x,r.x,n.x,o.x),lh(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 ch extends Qa{constructor(t=new Ri,e=new Ri,s=new Ri,i=new Ri){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Ri){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(lh(t,i.x,r.x,n.x,o.x),lh(t,i.y,r.y,n.y,o.y),lh(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 dh extends Qa{constructor(t=new Zs,e=new Zs){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Zs){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 Zs){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 ph extends Qa{constructor(t=new Ri,e=new Ri){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new Ri){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 Ri){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 mh extends Qa{constructor(t=new Zs,e=new Zs,s=new Zs){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Zs){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(hh(t,i.x,r.x,n.x),hh(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 gh extends Qa{constructor(t=new Ri,e=new Ri,s=new Ri){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Ri){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(hh(t,i.x,r.x,n.x),hh(t,i.y,r.y,n.y),hh(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 fh extends Qa{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new Zs){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],l=i[n>i.length-2?i.length-1:n+1],u=i[n>i.length-3?i.length-1:n+2];return s.set(ah(o,a.x,h.x,l.x,u.x),ah(o,a.y,h.y,l.y,u.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 Zs).fromArray(s))}return this}}var yh=Object.freeze({__proto__:null,ArcCurve:th,CatmullRomCurve3:oh,CubicBezierCurve:uh,CubicBezierCurve3:ch,EllipseCurve:Ka,LineCurve:dh,LineCurve3:ph,QuadraticBezierCurve:mh,QuadraticBezierCurve3:gh,SplineCurve:fh});class xh 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 yh[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 yh[s.type]).fromJSON(s))}return this}}class bh extends xh{constructor(t){super(),this.type="Path",this.currentPoint=new Zs,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 dh(this.currentPoint.clone(),new Zs(t,e));return this.curves.push(s),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,s,i){const r=new mh(this.currentPoint.clone(),new Zs(t,e),new Zs(s,i));return this.curves.push(r),this.currentPoint.set(s,i),this}bezierCurveTo(t,e,s,i,r,n){const o=new uh(this.currentPoint.clone(),new Zs(t,e),new Zs(s,i),new Zs(r,n));return this.curves.push(o),this.currentPoint.set(r,n),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),s=new fh(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,l=this.currentPoint.y;return this.absellipse(t+h,e+l,s,i,r,n,o,a),this}absellipse(t,e,s,i,r,n,o,a){const h=new Ka(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 l=h.getPoint(1);return this.currentPoint.copy(l),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 vh extends wn{constructor(t=[new Zs(0,-.5),new Zs(.5,0),new Zs(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=Hs(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],l=1/e,u=new Ri,c=new Zs,d=new Ri,p=new Ri,m=new Ri;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*l*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){u.x=t[s].x*p,u.y=t[s].y,u.z=t[s].x*m,n.push(u.x,u.y,u.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,l=a[3*s+1],d=a[3*s+0]*m;h.push(i,l,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 gn(n,3)),this.setAttribute("uv",new gn(o,2)),this.setAttribute("normal",new gn(h,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new vh(t.points,t.segments,t.phiStart,t.phiLength)}}class Th extends vh{constructor(t=1,e=1,s=4,i=8){const r=new bh;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 Th(t.radius,t.length,t.capSegments,t.radialSegments)}}class _h extends wn{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 Ri,l=new Zs;n.push(0,0,0),o.push(0,0,1),a.push(.5,.5);for(let r=0,u=3;r<=e;r++,u+=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),l.x=(n[u]/t+1)/2,l.y=(n[u+1]/t+1)/2,a.push(l.x,l.y)}for(let t=1;t<=e;t++)r.push(t,t+1,0);this.setIndex(r),this.setAttribute("position",new gn(n,3)),this.setAttribute("normal",new gn(o,3)),this.setAttribute("uv",new gn(a,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new _h(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class wh extends wn{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 l=[],u=[],c=[],d=[];let p=0;const m=[],g=s/2;let f=0;function y(s){const r=p,n=new Zs,m=new Ri;let y=0;const x=!0===s?t:e,b=!0===s?1:-1;for(let t=1;t<=i;t++)u.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,u.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?l.push(i,i+1,e):l.push(i+1,i,e),y+=3}h.addGroup(f,y,!0===s?1:2),f+=y}!function(){const n=new Ri,y=new Ri;let x=0;const b=(e-t)/s;for(let h=0;h<=r;h++){const l=[],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,u.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),l.push(p++)}m.push(l)}for(let t=0;t<i;t++)for(let e=0;e<r;e++){const s=m[e][t],i=m[e+1][t],r=m[e+1][t+1],n=m[e][t+1];l.push(s,i,n),l.push(i,r,n),x+=6}h.addGroup(f,x,0),f+=x}(),!1===n&&(t>0&&y(!0),e>0&&y(!1)),this.setIndex(l),this.setAttribute("position",new gn(u,3)),this.setAttribute("normal",new gn(c,3)),this.setAttribute("uv",new gn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new wh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Sh extends wh{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 Sh(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Mh extends wn{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 l(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 u(t){return Math.atan2(t.z,-t.x)}!function(t){const s=new Ri,i=new Ri,r=new Ri;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 Ri;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 Ri;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=u(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 Ri,e=new Ri,s=new Ri,i=new Ri,o=new Zs,a=new Zs,h=new Zs;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=u(i);l(o,d+0,t,p),l(a,d+2,e,p),l(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 gn(r,3)),this.setAttribute("normal",new gn(r.slice(),3)),this.setAttribute("uv",new gn(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 Mh(t.vertices,t.indices,t.radius,t.details)}}class Ah extends Mh{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 Ah(t.radius,t.detail)}}const Nh=new Ri,Rh=new Ri,Ch=new Ri,Eh=new Gr;class Bh extends wn{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(Gs*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],l=["a","b","c"],u=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}=Eh;if(e.fromBufferAttribute(o,h[0]),s.fromBufferAttribute(o,h[1]),a.fromBufferAttribute(o,h[2]),Eh.getNormal(Ch),u[0]=`${Math.round(e.x*i)},${Math.round(e.y*i)},${Math.round(e.z*i)}`,u[1]=`${Math.round(s.x*i)},${Math.round(s.y*i)},${Math.round(s.z*i)}`,u[2]=`${Math.round(a.x*i)},${Math.round(a.y*i)},${Math.round(a.z*i)}`,u[0]!==u[1]&&u[1]!==u[2]&&u[2]!==u[0])for(let t=0;t<3;t++){const e=(t+1)%3,s=u[t],i=u[e],n=Eh[l[t]],o=Eh[l[e]],a=`${s}_${i}`,p=`${i}_${s}`;p in c&&c[p]?(Ch.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:Ch.clone()})}}for(const t in c)if(c[t]){const{index0:e,index1:s}=c[t];Nh.fromBufferAttribute(o,e),Rh.fromBufferAttribute(o,s),d.push(Nh.x,Nh.y,Nh.z),d.push(Rh.x,Rh.y,Rh.z)}this.setAttribute("position",new gn(d,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}class Ih extends bh{constructor(t){super(t),this.uuid=js(),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 bh).fromJSON(s))}return this}}const Ph=function(t,e,s=2){const i=e&&e.length,r=i?e[0]*s:t.length;let n=Fh(t,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l,u,c,d,p;if(i&&(n=function(t,e,s,i){const r=[];let n,o,a,h,l;for(n=0,o=e.length;n<o;n++)a=e[n]*i,h=n<o-1?e[n+1]*i:t.length,l=Fh(t,a,h,i,!1),l===l.next&&(l.steiner=!0),r.push(Hh(l));for(r.sort(kh),n=0;n<r.length;n++)s=Gh(r[n],s);return s}(t,e,n,s)),t.length>80*s){a=l=t[0],h=u=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>l&&(l=c),d>u&&(u=d);p=Math.max(l-a,u-h),p=0!==p?32767/p:0}return Oh(n,o,s,a,h,p,0),o};function Fh(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=el(n,t[n],t[n+1],o);else for(n=s-i;n>=e;n-=i)o=el(n,t[n],t[n+1],o);return o&&Yh(o,o.next)&&(sl(o),o=o.next),o}function Uh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Yh(i,i.next)&&0!==Xh(i.prev,i,i.next))i=i.next;else{if(sl(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Oh(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=jh(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,l=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e<l&&(a++,i=i.nextZ,i);e++);for(h=l;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,l*=2}while(o>1)}(r)}(t,i,r,n);let a,h,l=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Lh(t,i,r,n):zh(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),sl(t),t=h.next,l=h.next;else if((t=h)===l){o?1===o?Oh(t=Vh(Uh(t),e,s),e,s,i,r,n,2):2===o&&Dh(t,e,s,i,r,n):Oh(Uh(t),e,s,i,r,n,1);break}}function zh(t){const e=t.prev,s=t,i=t.next;if(Xh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,l=i.y,u=r<n?r<o?r:o:n<o?n:o,c=a<h?a<l?a:l:h<l?h:l,d=r>n?r>o?r:o:n>o?n:o,p=a>h?a>l?a:l:h>l?h:l;let m=i.next;for(;m!==e;){if(m.x>=u&&m.x<=d&&m.y>=c&&m.y<=p&&qh(r,a,n,h,o,l,m.x,m.y)&&Xh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Lh(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Xh(r,n,o)>=0)return!1;const a=r.x,h=n.x,l=o.x,u=r.y,c=n.y,d=o.y,p=a<h?a<l?a:l:h<l?h:l,m=u<c?u<d?u:d:c<d?c:d,g=a>h?a>l?a:l:h>l?h:l,f=u>c?u>d?u:d:c>d?c:d,y=jh(p,m,e,s,i),x=jh(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&&qh(a,u,h,c,l,d,b.x,b.y)&&Xh(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&&qh(a,u,h,c,l,d,v.x,v.y)&&Xh(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&&qh(a,u,h,c,l,d,b.x,b.y)&&Xh(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&&qh(a,u,h,c,l,d,v.x,v.y)&&Xh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Vh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!Yh(r,n)&&Jh(r,i,i.next,n)&&Kh(r,n)&&Kh(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),sl(i),sl(i.next),i=t=n),i=i.next}while(i!==t);return Uh(i)}function Dh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&$h(o,t)){let a=tl(o,t);return o=Uh(o,o.next),a=Uh(a,a.next),Oh(o,e,s,i,r,n,0),void Oh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function kh(t,e){return t.x-e.x}function Gh(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,l=s.y;let u,c=1/0;i=s;do{n>=i.x&&i.x>=h&&n!==i.x&&qh(o<l?n:r,o,h,l,o<l?r:n,o,i.x,i.y)&&(u=Math.abs(o-i.y)/(n-i.x),Kh(i,t)&&(u<c||u===c&&(i.x>s.x||i.x===s.x&&Wh(s,i)))&&(s=i,c=u)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=tl(s,t);return Uh(i,i.next),Uh(s,s.next)}function Wh(t,e){return Xh(t.prev,t,e.prev)<0&&Xh(e.next,t,t.next)<0}function jh(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 Hh(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 qh(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 $h(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&&Jh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(Kh(t,e)&&Kh(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)&&(Xh(t.prev,t,e.prev)||Xh(t,e.prev,e))||Yh(t,e)&&Xh(t.prev,t,t.next)>0&&Xh(e.prev,e,e.next)>0)}function Xh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Yh(t,e){return t.x===e.x&&t.y===e.y}function Jh(t,e,s,i){const r=Qh(Xh(t,e,s)),n=Qh(Xh(t,e,i)),o=Qh(Xh(s,i,t)),a=Qh(Xh(s,i,e));return r!==n&&o!==a||(!(0!==r||!Zh(t,s,e))||(!(0!==n||!Zh(t,i,e))||(!(0!==o||!Zh(s,t,i))||!(0!==a||!Zh(s,e,i)))))}function Zh(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 Kh(t,e){return Xh(t.prev,t,t.next)<0?Xh(t,e,t.next)>=0&&Xh(t,t.prev,e)>=0:Xh(t,e,t.prev)<0||Xh(t,t.next,e)<0}function tl(t,e){const s=new il(t.i,t.x,t.y),i=new il(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 el(t,e,s,i){const r=new il(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 sl(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 il(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 rl{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 rl.area(t)<0}static triangulateShape(t,e){const s=[],i=[],r=[];nl(t),ol(s,t);let n=t.length;e.forEach(nl);for(let t=0;t<e.length;t++)i.push(n),n+=e[t].length,ol(s,e[t]);const o=Ph(s,i);for(let t=0;t<o.length;t+=3)r.push(o.slice(t,t+3));return r}}function nl(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function ol(t,e){for(let s=0;s<e.length;s++)t.push(e[s].x),t.push(e[s].y)}class al extends wn{constructor(t=new Ih([new Zs(.5,.5),new Zs(-.5,.5),new Zs(-.5,-.5),new Zs(.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 l=void 0===e.bevelEnabled||e.bevelEnabled,u=void 0!==e.bevelThickness?e.bevelThickness:.2,c=void 0!==e.bevelSize?e.bevelSize:u-.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:hl;let f,y,x,b,v,T=!1;m&&(f=m.getSpacedPoints(a),T=!0,l=!1,y=m.computeFrenetFrames(a,!1),x=new Ri,b=new Ri,v=new Ri),l||(p=0,u=0,c=0,d=0);const _=t.extractPoints(o);let w=_.shape;const S=_.holes;if(!rl.isClockWise(w)){w=w.reverse();for(let t=0,e=S.length;t<e;t++){const e=S[t];rl.isClockWise(e)&&(S[t]=e.reverse())}}const M=rl.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 R=w.length,C=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,l=s.y-t.y,u=o*o+a*a,c=o*l-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(u),d=Math.sqrt(h*h+l*l),p=e.x-a/c,m=e.y+o/c,g=((s.x-l/d-p)*l-(s.y+h/d-m)*h)/(o*l-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 Zs(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(l)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(u)):(i=o,r=a,n=Math.sqrt(u/2))}return new Zs(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=u*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<R;t++){const e=l?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<R;e++){const s=l?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=u*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=R*t,n=R*(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(l){let t=0,e=R*t;for(let t=0;t<C;t++){const s=M[t];L(s[2]+e,s[1]+e,s[0]+e)}t=a+2*p,e=R*t;for(let t=0;t<C;t++){const s=M[t];L(s[0]+e,s[1]+e,s[2]+e)}}else{for(let t=0;t<C;t++){const e=M[t];L(e[2],e[1],e[0])}for(let t=0;t<C;t++){const e=M[t];L(e[0]+R*a,e[1]+R*a,e[2]+R*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 gn(i,3)),this.setAttribute("uv",new gn(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 yh[i.type]).fromJSON(i)),new al(s,t.options)}}const hl={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],l=e[3*r],u=e[3*r+1];return[new Zs(n,o),new Zs(a,h),new Zs(l,u)]},generateSideWallUV:function(t,e,s,i,r,n){const o=e[3*s],a=e[3*s+1],h=e[3*s+2],l=e[3*i],u=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-u)<Math.abs(o-l)?[new Zs(o,1-h),new Zs(l,1-c),new Zs(d,1-m),new Zs(g,1-y)]:[new Zs(a,1-h),new Zs(u,1-c),new Zs(p,1-m),new Zs(f,1-y)]}};class ll extends Mh{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 ll(t.radius,t.detail)}}class ul extends Mh{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 ul(t.radius,t.detail)}}class cl extends wn{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,l=a+1,u=t/o,c=e/a,d=[],p=[],m=[],g=[];for(let t=0;t<l;t++){const e=t*c-n;for(let s=0;s<h;s++){const i=s*u-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 gn(p,3)),this.setAttribute("normal",new gn(m,3)),this.setAttribute("uv",new gn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new cl(t.width,t.height,t.widthSegments,t.heightSegments)}}class dl extends wn{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=[],l=[];let u=t;const c=(e-t)/(i=Math.max(1,i)),d=new Ri,p=new Zs;for(let t=0;t<=i;t++){for(let t=0;t<=s;t++){const i=r+t/s*n;d.x=u*Math.cos(i),d.y=u*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,l.push(p.x,p.y)}u+=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 gn(a,3)),this.setAttribute("normal",new gn(h,3)),this.setAttribute("uv",new gn(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new dl(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class pl extends wn{constructor(t=new Ih([new Zs(0,.5),new Zs(-.5,-.5),new Zs(.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 l=h.shape;const u=h.holes;!1===rl.isClockWise(l)&&(l=l.reverse());for(let t=0,e=u.length;t<e;t++){const e=u[t];!0===rl.isClockWise(e)&&(u[t]=e.reverse())}const c=rl.triangulateShape(l,u);for(let t=0,e=u.length;t<e;t++){const e=u[t];l=l.concat(e)}for(let t=0,e=l.length;t<e;t++){const e=l[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 gn(i,3)),this.setAttribute("normal",new gn(r,3)),this.setAttribute("uv",new gn(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 pl(s,t.curveSegments)}}class ml extends wn{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 l=[],u=new Ri,c=new Ri,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;u.x=-t*Math.cos(i+a*r)*Math.sin(n+y*o),u.y=t*Math.cos(n+y*o),u.z=t*Math.sin(i+a*r)*Math.sin(n+y*o),p.push(u.x,u.y,u.z),c.copy(u).normalize(),m.push(c.x,c.y,c.z),g.push(a+x,1-y),f.push(h++)}l.push(f)}for(let t=0;t<s;t++)for(let i=0;i<e;i++){const e=l[t][i+1],r=l[t][i],o=l[t+1][i],h=l[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 gn(p,3)),this.setAttribute("normal",new gn(m,3)),this.setAttribute("uv",new gn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ml(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class gl extends Mh{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 gl(t.radius,t.detail)}}class fl extends wn{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=[],l=new Ri,u=new Ri,c=new Ri;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;u.x=(t+e*Math.cos(m))*Math.cos(p),u.y=(t+e*Math.cos(m))*Math.sin(p),u.z=e*Math.sin(m),o.push(u.x,u.y,u.z),l.x=t*Math.cos(p),l.y=t*Math.sin(p),c.subVectors(u,l).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 gn(o,3)),this.setAttribute("normal",new gn(a,3)),this.setAttribute("uv",new gn(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new fl(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class yl extends wn{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=[],l=[],u=new Ri,c=new Ri,d=new Ri,p=new Ri,m=new Ri,g=new Ri,f=new Ri;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);u.x=d.x+(n*f.x+p*m.x),u.y=d.y+(n*f.y+p*m.y),u.z=d.z+(n*f.z+p*m.z),a.push(u.x,u.y,u.z),c.subVectors(u,d).normalize(),h.push(c.x,c.y,c.z),l.push(o/s),l.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 gn(a,3)),this.setAttribute("normal",new gn(h,3)),this.setAttribute("uv",new gn(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new yl(t.radius,t.tube,t.tubularSegments,t.radialSegments,t.p,t.q)}}class xl extends wn{constructor(t=new gh(new Ri(-1,-1,0),new Ri(-1,1,0),new Ri(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 Ri,a=new Ri,h=new Zs;let l=new Ri;const u=[],c=[],d=[],p=[];function m(r){l=t.getPointAt(r/e,l);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=l.x+s*a.x,o.y=l.y+s*a.y,o.z=l.z+s*a.z,u.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 gn(u,3)),this.setAttribute("normal",new gn(c,3)),this.setAttribute("uv",new gn(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 xl((new yh[t.path.type]).fromJSON(t.path),t.tubularSegments,t.radius,t.radialSegments,t.closed)}}class bl extends wn{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},null!==t){const e=[],s=new Set,i=new Ri,r=new Ri;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],l=h.start;for(let t=l,a=l+h.count;t<a;t+=3)for(let a=0;a<3;a++){const h=o.getX(t+a),l=o.getX(t+(a+1)%3);i.fromBufferAttribute(n,h),r.fromBufferAttribute(n,l),!0===vl(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===vl(i,r,s)&&(e.push(i.x,i.y,i.z),e.push(r.x,r.y,r.z))}}this.setAttribute("position",new gn(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function vl(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 Tl=Object.freeze({__proto__:null,BoxGeometry:Wn,CapsuleGeometry:Th,CircleGeometry:_h,ConeGeometry:Sh,CylinderGeometry:wh,DodecahedronGeometry:Ah,EdgesGeometry:Bh,ExtrudeGeometry:al,IcosahedronGeometry:ll,LatheGeometry:vh,OctahedronGeometry:ul,PlaneGeometry:cl,PolyhedronGeometry:Mh,RingGeometry:dl,ShapeGeometry:pl,SphereGeometry:ml,TetrahedronGeometry:gl,TorusGeometry:fl,TorusKnotGeometry:yl,TubeGeometry:xl,WireframeGeometry:bl});class _l extends Jr{constructor(t){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new $r(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 wl extends Hn{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Sl extends Jr{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new $r(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 $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(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 mr,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 Ml extends Sl{constructor(t){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new Zs(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Hs(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 $r(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 $r(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new $r(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 Al extends Jr{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new $r(16777215),this.specular=new $r(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new mr,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 Nl extends Jr{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new $r(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(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 Rl extends Jr{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(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 Cl extends Jr{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new $r(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new mr,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 El extends Jr{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Bl extends Jr{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class Il extends Jr{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new $r(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(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 Pl extends wa{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function Fl(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 Ul(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Ol(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 zl(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 Ll(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 Vl={convertArray:Fl,isTypedArray:Ul,getKeyframeOrder:Ol,sortedArray:zl,flattenJSON:Ll,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=[],l=[];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)l.push(e.values[t*a+s])}}0!==h.length&&(e.times=Fl(h,e.times.constructor),e.values=Fl(l,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 l=0;const u=o.getValueSize();o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(l=u/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 Ni).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t<p;++t){const e=t*u+l;if("quaternion"===r)Ni.multiplyQuaternionsFlat(o.values,e,d,0,o.values,e);else{const t=u-2*l;for(let s=0;s<t;++s)o.values[e+s]-=d[s]}}}return t.blendMode=Ve,t}};class Dl{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 kl extends Dl{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),l=this.valueSize;this._weightPrev=h/(e-o),this._weightNext=h/(a-s),this._offsetPrev=r*l,this._offsetNext=n*l}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=t*o,h=a-o,l=this._offsetPrev,u=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[l+t]+y*n[h+t]+x*n[a+t]+b*n[u+t];return r}}class Gl extends Dl{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,l=(s-e)/(i-e),u=1-l;for(let t=0;t!==o;++t)r[t]=n[h+t]*u+n[a+t]*l;return r}}class Wl extends Dl{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t){return this.copySampleValue_(t-1)}}class jl{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=Fl(e,this.TimeBufferType),this.values=Fl(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:Fl(t.times,Array),values:Fl(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(s.interpolation=e)}return s.type=t.ValueTypeName,s}InterpolantFactoryMethodDiscrete(t){return new Wl(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new Gl(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new kl(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&&Ul(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}}jl.prototype.TimeBufferType=Float32Array,jl.prototype.ValueBufferType=Float32Array,jl.prototype.DefaultInterpolation=Pe;class Hl extends jl{constructor(t,e,s){super(t,e,s)}}Hl.prototype.ValueTypeName="bool",Hl.prototype.ValueBufferType=Array,Hl.prototype.DefaultInterpolation=Ie,Hl.prototype.InterpolantFactoryMethodLinear=void 0,Hl.prototype.InterpolantFactoryMethodSmooth=void 0;class ql extends jl{}ql.prototype.ValueTypeName="color";class $l extends jl{}$l.prototype.ValueTypeName="number";class Xl extends Dl{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)Ni.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Yl extends jl{InterpolantFactoryMethodLinear(t){return new Xl(this.times,this.values,this.getValueSize(),t)}}Yl.prototype.ValueTypeName="quaternion",Yl.prototype.InterpolantFactoryMethodSmooth=void 0;class Jl extends jl{constructor(t,e,s){super(t,e,s)}}Jl.prototype.ValueTypeName="string",Jl.prototype.ValueBufferType=Array,Jl.prototype.DefaultInterpolation=Ie,Jl.prototype.InterpolantFactoryMethodLinear=void 0,Jl.prototype.InterpolantFactoryMethodSmooth=void 0;class Zl extends jl{}Zl.prototype.ValueTypeName="vector";class Ql{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=js(),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(Kl(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(jl.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=Ol(o);o=zl(o,1,h),a=zl(a,1,h),i||0!==o[0]||(o.push(r),a.push(a[0])),n.push(new $l(".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=[];Ll(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 $l(".morphTargetInfluence["+s+"]",t,n))}a=t.length*n}else{const n=".bones["+e[t].name+"]";s(Zl,n+".position",r,"pos",i),s(Yl,n+".quaternion",r,"rot",i),s(Zl,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 Kl(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 $l;case"vector":case"vector2":case"vector3":case"vector4":return Zl;case"color":return ql;case"quaternion":return Yl;case"bool":case"boolean":return Hl;case"string":return Jl}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],s=[];Ll(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 tu={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 eu{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 su=new eu;class iu{constructor(t){this.manager=void 0!==t?t:su,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}}iu.DEFAULT_MATERIAL_NAME="__DEFAULT";const ru={};class nu extends Error{constructor(t,e){super(t),this.response=e}}class ou extends iu{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=tu.get(t);if(void 0!==r)return this.manager.itemStart(t),setTimeout((()=>{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==ru[t])return void ru[t].push({onLoad:e,onProgress:s,onError:i});ru[t]=[],ru[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=ru[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 nu(`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=>{tu.add(t,e);const s=ru[t];delete ru[t];for(let t=0,i=s.length;t<i;t++){const i=s[t];i.onLoad&&i.onLoad(e)}})).catch((e=>{const s=ru[t];if(void 0===s)throw this.manager.itemError(t),e;delete ru[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 au extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new ou(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=Ql.parse(t[s]);e.push(i)}return e}}class hu extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=[],o=new $a,a=new ou(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(r.withCredentials);let h=0;function l(l){a.load(t[l],(function(t){const s=r.parse(t,!0);n[l]={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)l(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 lu extends iu{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=tu.get(t);if(void 0!==n)return r.manager.itemStart(t),setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n;const o=si("img");function a(){l(),tu.add(t,this),e&&e(this),r.manager.itemEnd(t)}function h(e){l(),i&&i(e),r.manager.itemError(t),r.manager.itemEnd(t)}function l(){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 uu extends iu{constructor(t){super(t)}load(t,e,s,i){const r=new Kn;r.colorSpace=Xe;const n=new lu(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 cu extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new Lo,o=new ou(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 du extends iu{constructor(t){super(t)}load(t,e,s,i){const r=new bi,n=new lu(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 pu extends Br{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new $r(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 mu extends pu{constructor(t,e,s){super(t,s),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Br.DEFAULT_UP),this.updateMatrix(),this.groundColor=new $r(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const gu=new rr,fu=new Ri,yu=new Ri;class xu{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Zs(512,512),this.map=null,this.mapPass=null,this.matrix=new rr,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new ia,this._frameExtents=new Zs(1,1),this._viewportCount=1,this._viewports=[new vi(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,s=this.matrix;fu.setFromMatrixPosition(t.matrixWorld),e.position.copy(fu),yu.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(yu),e.updateMatrixWorld(),gu.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(gu),s.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),s.multiply(gu)}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 bu extends xu{constructor(){super(new Jn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,s=2*Ws*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 vu extends pu{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(Br.DEFAULT_UP),this.updateMatrix(),this.target=new Br,this.distance=s,this.angle=i,this.penumbra=r,this.decay=n,this.map=null,this.shadow=new bu}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 Tu=new rr,_u=new Ri,wu=new Ri;class Su extends xu{constructor(){super(new Jn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new Zs(4,2),this._viewportCount=6,this._viewports=[new vi(2,1,1,1),new vi(0,1,1,1),new vi(3,1,1,1),new vi(1,1,1,1),new vi(3,0,1,1),new vi(1,0,1,1)],this._cubeDirections=[new Ri(1,0,0),new Ri(-1,0,0),new Ri(0,0,1),new Ri(0,0,-1),new Ri(0,1,0),new Ri(0,-1,0)],this._cubeUps=[new Ri(0,1,0),new Ri(0,1,0),new Ri(0,1,0),new Ri(0,1,0),new Ri(0,0,1),new Ri(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()),_u.setFromMatrixPosition(t.matrixWorld),s.position.copy(_u),wu.copy(s.position),wu.add(this._cubeDirections[e]),s.up.copy(this._cubeUps[e]),s.lookAt(wu),s.updateMatrixWorld(),i.makeTranslation(-_u.x,-_u.y,-_u.z),Tu.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Tu)}}class Mu extends pu{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 Su}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 Au extends qn{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 Nu extends xu{constructor(){super(new Au(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class Ru extends pu{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Br.DEFAULT_UP),this.updateMatrix(),this.target=new Br,this.shadow=new Nu}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Cu extends pu{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class Eu extends pu{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 Bu{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Ri)}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 Iu extends pu{constructor(t=new Bu,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 Pu extends iu{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=this,n=new ou(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=Pu.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 $r).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 $r).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Zs).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ri).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new vi).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new Qs).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new rr).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 Zs).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 Zs).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}static createMaterialFromType(t){return new{ShadowMaterial:_l,SpriteMaterial:ao,RawShaderMaterial:wl,ShaderMaterial:Hn,PointsMaterial:za,MeshPhysicalMaterial:Ml,MeshStandardMaterial:Sl,MeshPhongMaterial:Al,MeshToonMaterial:Nl,MeshNormalMaterial:Rl,MeshLambertMaterial:Cl,MeshDepthMaterial:El,MeshDistanceMaterial:Bl,MeshBasicMaterial:Zr,MeshMatcapMaterial:Il,LineDashedMaterial:Pl,LineBasicMaterial:wa,Material:Jr}[t]}}class Fu{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 Uu extends wn{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 Ou extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new ou(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=ei(r.type,n),a=new ro(o,r.stride);return a.uuid=r.uuid,e[i]=a,a}const r=t.isInstancedBufferGeometry?new Uu:new wn,n=t.data.index;if(void 0!==n){const t=ei(n.type,n.array);r.setIndex(new on(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 oo(e,s.itemSize,s.offset,s.normalized)}else{const t=ei(s.type,s.array);n=new(s.isInstancedBufferAttribute?Go:on)(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 oo(e,r.itemSize,r.offset,r.normalized)}else{const t=ei(r.type,r.array);o=new on(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 l=t.data.boundingSphere;if(void 0!==l){const t=new Ri;void 0!==l.center&&t.fromArray(l.center),r.boundingSphere=new Yi(t,l.radius)}return t.name&&(r.name=t.name),t.userData&&(r.userData=t.userData),r}}class zu extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=""===this.path?Fu.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||n;const o=new ou(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?Fu.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||s;const i=new ou(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),l=this.parseSkeletons(t.skeletons,h);if(this.bindSkeletons(h,l),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 Ih).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 ko).fromJSON(t[e],i);s[r.uuid]=r}return s}parseGeometries(t,e){const s={};if(void 0!==t){const i=new Ou;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 Tl?n=Tl[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 Pu;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=Ql.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:ei(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){const s=new eu(e);r=new lu(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 Lo(s.data,s.width,s.height)))}i[s.uuid]=new fi(t)}else{const t=n(s.url);i[s.uuid]=new fi(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:ei(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){i=new lu(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 Lo(i.data,i.width,i.height)))}s[i.uuid]=new fi(t)}else{const t=await r(i.url);s[i.uuid]=new fi(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 Kn,6===a.length&&(h.needsUpdate=!0)):(h=a&&a.data?new Lo:new bi,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,Lu)),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],Vu),h.wrapT=s(n.wrap[1],Vu)),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,Du)),void 0!==n.magFilter&&(h.magFilter=s(n.magFilter,Du)),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 l(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 u(t){return void 0===i[t]&&console.warn("THREE.ObjectLoader: Undefined texture",t),i[t]}switch(t.type){case"Scene":n=new io,void 0!==t.background&&(Number.isInteger(t.background)?n.background=new $r(t.background):n.background=u(t.background)),void 0!==t.environment&&(n.environment=u(t.environment)),void 0!==t.fog&&("Fog"===t.fog.type?n.fog=new so(t.fog.color,t.fog.near,t.fog.far):"FogExp2"===t.fog.type&&(n.fog=new eo(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 Jn(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 Au(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 Cu(t.color,t.intensity);break;case"DirectionalLight":n=new Ru(t.color,t.intensity),n.target=t.target||"";break;case"PointLight":n=new Mu(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":n=new Eu(t.color,t.intensity,t.width,t.height);break;case"SpotLight":n=new vu(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),n.target=t.target||"";break;case"HemisphereLight":n=new mu(t.color,t.groundColor,t.intensity);break;case"LightProbe":n=(new Iu).fromJSON(t);break;case"SkinnedMesh":o=h(t.geometry),a=l(t.material),n=new Oo(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=l(t.material),n=new kn(o,a);break;case"InstancedMesh":o=h(t.geometry),a=l(t.material);const e=t.count,s=t.instanceMatrix,i=t.instanceColor;n=new Jo(o,a,e),n.instanceMatrix=new Go(new Float32Array(s.array),16),void 0!==i&&(n.instanceColor=new Go(new Float32Array(i.array),i.itemSize));break;case"BatchedMesh":o=h(t.geometry),a=l(t.material),n=new _a(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 Bi;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new Yi;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=u(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=u(t.colorsTexture.uuid));break;case"LOD":n=new Ao;break;case"Line":n=new Ba(h(t.geometry),l(t.material));break;case"LineLoop":n=new Oa(h(t.geometry),l(t.material));break;case"LineSegments":n=new Ua(h(t.geometry),l(t.material));break;case"PointCloud":case"Points":n=new Ga(h(t.geometry),l(t.material));break;case"Sprite":n=new _o(l(t.material));break;case"Group":n=new ja;break;case"Bone":n=new zo;break;default:n=new Br}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 Br}}))}}const Lu={UVMapping:at,CubeReflectionMapping:ht,CubeRefractionMapping:lt,EquirectangularReflectionMapping:ut,EquirectangularRefractionMapping:ct,CubeUVReflectionMapping:306},Vu={RepeatWrapping:pt,ClampToEdgeWrapping:mt,MirroredRepeatWrapping:gt},Du={NearestFilter:ft,NearestMipmapNearestFilter:yt,NearestMipmapLinearFilter:bt,LinearFilter:Tt,LinearMipmapNearestFilter:_t,LinearMipmapLinearFilter:St};class ku extends iu{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=tu.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 tu.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),tu.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));tu.add(t,a),r.manager.itemStart(t)}}let Gu;class Wu{static getContext(){return void 0===Gu&&(Gu=new(window.AudioContext||window.webkitAudioContext)),Gu}static setContext(t){Gu=t}}class ju extends iu{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new ou(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);Wu.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const Hu=new rr,qu=new rr,$u=new rr;class Xu{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Jn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Jn,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,$u.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(Gs*e.fov*.5)/e.zoom;let n,o;qu.elements[12]=-s,Hu.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,$u.elements[0]=2*e.near/(o-n),$u.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy($u),n=-r*e.aspect-i,o=r*e.aspect-i,$u.elements[0]=2*e.near/(o-n),$u.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy($u)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(qu),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Hu)}}class Yu extends Jn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Ju{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Zu(),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=Zu();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Zu(){return("undefined"==typeof performance?Date:performance).now()}const Qu=new Ri,Ku=new Ni,tc=new Ri,ec=new Ri;class sc extends Br{constructor(){super(),this.type="AudioListener",this.context=Wu.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Ju}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(Qu,Ku,tc),ec.set(0,0,-1).applyQuaternion(Ku),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(Qu.x,t),e.positionY.linearRampToValueAtTime(Qu.y,t),e.positionZ.linearRampToValueAtTime(Qu.z,t),e.forwardX.linearRampToValueAtTime(ec.x,t),e.forwardY.linearRampToValueAtTime(ec.y,t),e.forwardZ.linearRampToValueAtTime(ec.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(Qu.x,Qu.y,Qu.z),e.setOrientation(ec.x,ec.y,ec.z,s.x,s.y,s.z)}}class ic extends Br{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(){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(),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 rc=new Ri,nc=new Ni,oc=new Ri,ac=new Ri;class hc extends ic{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(rc,nc,oc),ac.set(0,0,1).applyQuaternion(nc);const e=this.panner;if(e.positionX){const t=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime(rc.x,t),e.positionY.linearRampToValueAtTime(rc.y,t),e.positionZ.linearRampToValueAtTime(rc.z,t),e.orientationX.linearRampToValueAtTime(ac.x,t),e.orientationY.linearRampToValueAtTime(ac.y,t),e.orientationZ.linearRampToValueAtTime(ac.z,t)}else e.setPosition(rc.x,rc.y,rc.z),e.setOrientation(ac.x,ac.y,ac.z)}}class lc{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 uc{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){Ni.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Ni.multiplyQuaternionsFlat(t,n,t,e,t,s),Ni.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 cc="\\[\\]\\.:\\/",dc=new RegExp("["+cc+"]","g"),pc="[^"+cc+"]",mc="[^"+cc.replace("\\.","")+"]",gc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",pc)+/(WCOD+)?/.source.replace("WCOD",mc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",pc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",pc)+"$"),fc=["material","materials","bones","map"];class yc{constructor(t,e,s){this.path=e,this.parsedPath=s||yc.parseTrackName(e),this.node=yc.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 yc.Composite(t,e,s):new yc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(dc,"")}static parseTrackName(t){const e=gc.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!==fc.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=yc.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}}yc.Composite=class{constructor(t,e,s){const i=s||yc.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()}},yc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},yc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},yc.prototype.GetterByBindingType=[yc.prototype._getValue_direct,yc.prototype._getValue_array,yc.prototype._getValue_arrayElement,yc.prototype._getValue_toArray],yc.prototype.SetterByBindingTypeAndVersioning=[[yc.prototype._setValue_direct,yc.prototype._setValue_direct_setNeedsUpdate,yc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[yc.prototype._setValue_array,yc.prototype._setValue_array_setNeedsUpdate,yc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[yc.prototype._setValue_arrayElement,yc.prototype._setValue_arrayElement_setNeedsUpdate,yc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[yc.prototype._setValue_fromArray,yc.prototype._setValue_fromArray_setNeedsUpdate,yc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class xc{constructor(){this.isAnimationObjectGroup=!0,this.uuid=js(),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 l=0,u=arguments.length;l!==u;++l){const u=arguments[l],c=u.uuid;let d=e[c];if(void 0===d){d=a++,e[c]=d,t.push(u);for(let t=0,e=n;t!==e;++t)r[t].push(new yc(u,s[t],i[t]))}else if(d<h){o=t[d];const a=--h,l=t[a];e[l.uuid]=d,t[d]=l,e[c]=a,t[a]=u;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 yc(u,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++,l=t[n];e[l.uuid]=h,t[h]=l,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],l=--n,u=t[l];e[a.uuid]=h,t[h]=a,e[u.uuid]=o,t[o]=u,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[o],r=e[l];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,l=this.nCachedObjects_,u=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(u);for(let s=l,i=a.length;s!==i;++s){const i=a[s];u[s]=new yc(i,t,e)}return u}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 bc{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 vc=new Float32Array(1);class Tc extends Vs{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 l=h[a];void 0===l&&(l={},h[a]=l);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let u=l[h];if(void 0!==u)++u.referenceCount,n[t]=u;else{if(u=n[t],void 0!==u){null===u._cacheIndex&&(++u.referenceCount,this._addInactiveBinding(u,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;u=new uc(yc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++u.referenceCount,this._addInactiveBinding(u,a,h),n[t]=u}o[t].resultBuffer=u.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],l=t._byClipCacheIndex;h._byClipCacheIndex=l,a[l]=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 Gl(new Float32Array(2),new Float32Array(2),1,vc),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?Ql.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 l=new bc(this,n,e,s);return this._bindAction(l,h),this._addInactiveAction(l,o,r),l}existingAction(t,e){const s=e||this._root,i=s.uuid,r="string"==typeof t?Ql.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 _c=class t{constructor(t){this.value=t}clone(){return new t(void 0===this.value.clone?this.value:this.value.clone())}},wc=0,Sc=class extends Vs{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:wc++}),this.name="",this.usage=As,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 Mc extends ro{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 Ac{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 Nc=new rr;class Rc{constructor(t,e,s=0,i=1/0){this.ray=new ir(t,e),this.near=s,this.far=i,this.camera=null,this.layers=new gr,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 Nc.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Nc),this}intersectObject(t,e=!0,s=[]){return Ec(t,this,s,e),s.sort(Cc),s}intersectObjects(t,e=!0,s=[]){for(let i=0,r=t.length;i<r;i++)Ec(t[i],this,s,e);return s.sort(Cc),s}}function Cc(t,e){return t.distance-e.distance}function Ec(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++)Ec(i[t],e,s,!0)}}class Bc{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(Hs(e/this.radius,-1,1))),this}clone(){return(new this.constructor).copy(this)}}class Ic{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)}}const Pc=new Zs;class Fc{constructor(t=new Zs(1/0,1/0),e=new Zs(-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=Pc.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,Pc).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 Uc=new Ri,Oc=new Ri;class zc{constructor(t=new Ri,e=new Ri){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){Uc.subVectors(t,this.start),Oc.subVectors(this.end,this.start);const s=Oc.dot(Oc);let i=Oc.dot(Uc)/s;return e&&(i=Hs(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 Lc=new Ri;class Vc extends Br{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new wn,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 gn(i,3));const r=new wa({fog:!1,toneMapped:!1});this.cone=new Ua(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),Lc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(Lc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}}const Dc=new Ri,kc=new rr,Gc=new rr;class Wc extends Ua{constructor(t){const e=jc(t),s=new wn,i=[],r=[],n=new $r(0,0,1),o=new $r(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 gn(i,3)),s.setAttribute("color",new gn(r,3));super(s,new wa({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");Gc.copy(this.root.matrixWorld).invert();for(let t=0,s=0;t<e.length;t++){const r=e[t];r.parent&&r.parent.isBone&&(kc.multiplyMatrices(Gc,r.matrixWorld),Dc.setFromMatrixPosition(kc),i.setXYZ(s,Dc.x,Dc.y,Dc.z),kc.multiplyMatrices(Gc,r.parent.matrixWorld),Dc.setFromMatrixPosition(kc),i.setXYZ(s+1,Dc.x,Dc.y,Dc.z),s+=2)}s.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose()}}function jc(t){const e=[];!0===t.isBone&&e.push(t);for(let s=0;s<t.children.length;s++)e.push.apply(e,jc(t.children[s]));return e}class Hc extends kn{constructor(t,e,s){super(new ml(e,4,2),new Zr({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 qc=new Ri,$c=new $r,Xc=new $r;class Yc extends Br{constructor(t,e,s){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="HemisphereLightHelper";const i=new ul(e);i.rotateY(.5*Math.PI),this.material=new Zr({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 on(n,3)),this.add(new kn(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");$c.copy(this.light.color),Xc.copy(this.light.groundColor);for(let t=0,s=e.count;t<s;t++){const i=t<s/2?$c:Xc;e.setXYZ(t,i.r,i.g,i.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(qc.setFromMatrixPosition(this.light.matrixWorld).negate())}}class Jc extends Ua{constructor(t=10,e=10,s=4473924,i=8947848){s=new $r(s),i=new $r(i);const r=e/2,n=t/e,o=t/2,a=[],h=[];for(let t=0,l=0,u=-o;t<=e;t++,u+=n){a.push(-o,0,u,o,0,u),a.push(u,0,-o,u,0,o);const e=t===r?s:i;e.toArray(h,l),l+=3,e.toArray(h,l),l+=3,e.toArray(h,l),l+=3,e.toArray(h,l),l+=3}const l=new wn;l.setAttribute("position",new gn(a,3)),l.setAttribute("color",new gn(h,3));super(l,new wa({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}class Zc extends Ua{constructor(t=10,e=16,s=8,i=64,r=4473924,n=8947848){r=new $r(r),n=new $r(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,l=Math.cos(i)*t;o.push(0,0,0),o.push(h,0,l);const u=1&s?r:n;a.push(u.r,u.g,u.b),a.push(u.r,u.g,u.b)}for(let e=0;e<s;e++){const h=1&e?r:n,l=t-t/s*e;for(let t=0;t<i;t++){let e=t/i*(2*Math.PI),s=Math.sin(e)*l,r=Math.cos(e)*l;o.push(s,0,r),a.push(h.r,h.g,h.b),e=(t+1)/i*(2*Math.PI),s=Math.sin(e)*l,r=Math.cos(e)*l,o.push(s,0,r),a.push(h.r,h.g,h.b)}}const h=new wn;h.setAttribute("position",new gn(o,3)),h.setAttribute("color",new gn(a,3));super(h,new wa({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}const Qc=new Ri,Kc=new Ri,td=new Ri;class ed extends Br{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 wn;i.setAttribute("position",new gn([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const r=new wa({fog:!1,toneMapped:!1});this.lightPlane=new Ba(i,r),this.add(this.lightPlane),i=new wn,i.setAttribute("position",new gn([0,0,0,0,0,1],3)),this.targetLine=new Ba(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),Qc.setFromMatrixPosition(this.light.matrixWorld),Kc.setFromMatrixPosition(this.light.target.matrixWorld),td.subVectors(Kc,Qc),this.lightPlane.lookAt(Kc),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(Kc),this.targetLine.scale.z=td.length()}}const sd=new Ri,id=new qn;class rd extends Ua{constructor(t){const e=new wn,s=new wa({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 gn(i,3)),e.setAttribute("color",new gn(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 $r(16755200),l=new $r(16711680),u=new $r(43775),c=new $r(16777215),d=new $r(3355443);this.setColors(h,l,u,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;id.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),nd("c",e,t,id,0,0,-1),nd("t",e,t,id,0,0,1),nd("n1",e,t,id,-1,-1,-1),nd("n2",e,t,id,1,-1,-1),nd("n3",e,t,id,-1,1,-1),nd("n4",e,t,id,1,1,-1),nd("f1",e,t,id,-1,-1,1),nd("f2",e,t,id,1,-1,1),nd("f3",e,t,id,-1,1,1),nd("f4",e,t,id,1,1,1),nd("u1",e,t,id,.7,1.1,-1),nd("u2",e,t,id,-.7,1.1,-1),nd("u3",e,t,id,0,2,-1),nd("cf1",e,t,id,-1,0,1),nd("cf2",e,t,id,1,0,1),nd("cf3",e,t,id,0,-1,1),nd("cf4",e,t,id,0,1,1),nd("cn1",e,t,id,-1,0,-1),nd("cn2",e,t,id,1,0,-1),nd("cn3",e,t,id,0,-1,-1),nd("cn4",e,t,id,0,1,-1),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}function nd(t,e,s,i,r,n,o){sd.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],sd.x,sd.y,sd.z)}}const od=new Bi;class ad extends Ua{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 wn;r.setIndex(new on(s,1)),r.setAttribute("position",new on(i,3)),super(r,new wa({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&&od.setFromObject(this.object),od.isEmpty())return;const e=od.min,s=od.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 hd extends Ua{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 wn;i.setIndex(new on(s,1)),i.setAttribute("position",new gn([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 wa({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 ld extends Ba{constructor(t,e=1,s=16776960){const i=s,r=new wn;r.setAttribute("position",new gn([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 wa({color:i,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const n=new wn;n.setAttribute("position",new gn([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),n.computeBoundingSphere(),this.add(new kn(n,new Zr({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 ud=new Ri;let cd,dd;class pd extends Br{constructor(t=new Ri(0,0,1),e=new Ri(0,0,0),s=1,i=16776960,r=.2*s,n=.2*r){super(),this.type="ArrowHelper",void 0===cd&&(cd=new wn,cd.setAttribute("position",new gn([0,0,0,0,1,0],3)),dd=new wh(0,.5,1,5,1),dd.translate(0,-.5,0)),this.position.copy(e),this.line=new Ba(cd,new wa({color:i,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new kn(dd,new Zr({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{ud.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(ud,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 md extends Ua{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 wn;s.setAttribute("position",new gn(e,3)),s.setAttribute("color",new gn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new wa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new $r,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 gd{constructor(){this.type="ShapePath",this.color=new $r,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new bh,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=rl.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 Ih,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const l=[],u=[];let c,d,p=[],m=0;u[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&&u[m]&&m++,u[m]={s:new Ih,p:c},u[m].s.curves=n.curves,h&&m++,p[m]=[]):p[m].push({h:n,p:c[0]});if(!u[0])return function(t){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s],r=new Ih;r.curves=i.curves,e.push(r)}return e}(i);if(u.length>1){let t=!1,s=0;for(let t=0,e=u.length;t<e;t++)l[t]=[];for(let i=0,r=u.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<u.length;r++)e(o.p,u[r].p)&&(i!==r&&s++,a?(a=!1,l[r].push(o)):t=!0);a&&l[i].push(o)}}s>0&&!1===t&&(p=l)}for(let t=0,e=u.length;t<e;t++){o=u[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 fd extends _i{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}}void 0===self.GPUShaderStage&&(self.GPUShaderStage={VERTEX:1,FRAGMENT:2,COMPUTE:4});let yd=void 0!==navigator.gpu;"undefined"!=typeof window&&yd&&(yd=await navigator.gpu.requestAdapter());class xd{static isAvailable(){return Boolean(yd)}static getStaticAdapter(){return yd}static getErrorMessage(){const t=document.createElement("div");return t.id="webgpumessage",t.style.fontFamily="monospace",t.style.fontSize="13px",t.style.fontWeight="normal",t.style.textAlign="center",t.style.background="#fff",t.style.color="#000",t.style.padding="1.5em",t.style.maxWidth="400px",t.style.margin="5em auto 0",t.innerHTML='Your browser does not support <a href="https://gpuweb.github.io/gpuweb/" style="color:blue">WebGPU</a> yet',t}}class bd{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 vd{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 Td=new ta;let _d=0;class wd{constructor(){this.version=++_d,this.globalClippingCount=0,this.localClippingCount=0,this.localClippingEnabled=!1,this.localClipIntersection=!1,this.planes=[],this.parentVersion=0,this.viewNormalMatrix=new Qs}projectPlanes(t,e){const s=t.length,i=this.planes;for(let r=0;r<s;r++){Td.copy(t[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const s=i[e+r],n=Td.normal;s.x=-n.x,s.y=-n.y,s.z=-n.z,s.w=Td.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 vi);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=_d++)}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 vi;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=_d++)}}let Sd=0;class Md{constructor(t,e,s,i,r,n,o,a,h){this._nodes=t,this._geometries=e,this.id=Sd++,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.updateClipping(h.clippingContext),this.clippingContextVersion=this.clippingContext.version,this.initialNodesCacheKey=this.getNodesCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=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 wd,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))}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}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;let i=e[t];if(null!==i){const t=typeof i;"number"===t?i=0!==i?"1":"0":"object"===t&&(i="{}")}s+=i+","}return s+=this.clippingContextVersion+",",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.count+","),s}get needsUpdate(){return this.initialNodesCacheKey!==this.getNodesCacheKey()||this.clippingNeedsUpdate}getNodesCacheKey(){return this._nodes.getCacheKey(this.scene,this.lightsNode)}getCacheKey(){return this.getMaterialCacheKey()+","+this.getNodesCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}class Ad{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),h=[t,e,n,r];let l=a.get(h);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(h,l)):(l.updateClipping(n.clippingContext),(l.version!==e.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(t,e,s,i,r,n,o)):l.version=e.version)),l}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new vd)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,l){const u=this.getChainMap(l),c=new Md(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),u.delete(c.getChainArray())},c}}class Nd{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 Rd=1,Cd=2,Ed=4,Bd=16;class Id extends Nd{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===Rd?this.backend.createAttribute(t):e===Cd?this.backend.createIndexAttribute(t):e===Ed&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version<e.version||e.usage===Ns)&&(this.backend.updateAttribute(t),s.version=e.version)}}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}function Pd(t){return null!==t.index?t.index.version:t.attributes.position.version}function Fd(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)?pn:cn)(e,1);return r.version=Pd(t),r}class Ud extends Nd{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,Ed):this.updateAttribute(t,Rd);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Cd)}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=Fd(e),t.set(e,s)):s.version!==Pd(e)&&(this.attributes.delete(s),s=Fd(e),t.set(e,s)),i=s}return i}}class Od{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 zd{constructor(t){this.cacheKey=t,this.usedTimes=0}}class Ld extends zd{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class Vd extends zd{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let Dd=0;class kd{constructor(t,e,s=null,i=null){this.id=Dd++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class Gd extends Nd{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 kd(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 kd(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 kd(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let l=this.caches.get(h);void 0===l?(r&&0===r.usedTimes&&this._releasePipeline(r),l=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=l}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 Vd(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 Ld(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 Wd extends Nd{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(t,this.getForCompute(t))}updateForRender(t){this._updateBindings(t,this.getForRender(t))}_updateBindings(t,e){for(const s of e)this._update(t,s,e)}_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,Ed)}}_update(t,e,s){const{backend:i}=this;let r=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&i.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=t.texture;t.needsBindingsUpdate&&(r=!0);const s=t.update();s&&this.textures.updateTexture(t.texture);const n=i.get(t.texture);if(!0===i.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,s,t.texture,t.textureNode.value),this.textures.updateTexture(t.texture),r=!0),!0===e.isStorageTexture){const s=this.get(e);!0===t.store?s.needsMipmap=!0:!0===e.generateMipmaps&&this.textures.needsMipmaps(e)&&!0===s.needsMipmap&&(this.backend.generateMipmaps(e),s.needsMipmap=!1)}}}if(!0===r){const i=this.pipelines.getForRender(t);this.backend.updateBindings(e,s,i)}}}const jd={VERTEX:"vertex",FRAGMENT:"fragment"},Hd={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},qd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},$d=["fragment","vertex"],Xd=["setup","analyze","generate"],Yd=[...$d,"compute"],Jd=["x","y","z","w"];function Zd(t,e=!1){let s="{";!0===t.isNode&&(s+=t.id);for(const{property:i,childNode:r}of Qd(t))s+=","+i.slice(0,-4)+":"+r.getCacheKey(e);return s+="}",s}function*Qd(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 Kd(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 tp(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 $r(...e):"vec2"===s?new Zs(...e):"vec3"===s?new Ri(...e):"vec4"===s?new vi(...e):"mat3"===s?new Qs(...e):"mat4"===s?new rr(...e):"bool"===t?e[0]||!1:"float"===t||"int"===t||"uint"===t?e[0]||0:"string"===t?e[0]||"":"ArrayBuffer"===t?sp(e[0]):null}function ep(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 sp(t){return Uint8Array.from(atob(t),(t=>t.charCodeAt(0))).buffer}var ip=Object.freeze({__proto__:null,arrayBufferToBase64:ep,base64ToArrayBuffer:sp,getCacheKey:Zd,getNodeChildren:Qd,getValueFromType:tp,getValueType:Kd});const rp=new Map;let np=0;class op extends Vs{constructor(t=null){super(),this.nodeType=t,this.updateType=Hd.NONE,this.updateBeforeType=Hd.NONE,this.updateAfterType=Hd.NONE,this.uuid=Js.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:np++})}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,Hd.FRAME)}onRenderUpdate(t){return this.onUpdate(t,Hd.RENDER)}onObjectUpdate(t){return this.onUpdate(t,Hd.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 Qd(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=Zd(this,t),this._cacheKeyVersion=this.version),this._cacheKey}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}construct(t){return console.warn("THREE.Node: construct() is deprecated. Use setup() instead."),this.setup(t)}increaseUsage(t){const e=t.getDataFromNode(this);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}analyze(t){if(1===this.increaseUsage(t)){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){const s=t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length!==s&&(e.outputNode=t.stack);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),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return Qd(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}}function ap(t,e){if("function"!=typeof e||!t)throw new Error(`Node class ${t} is not a class`);rp.has(t)?console.warn(`Redefinition of node class ${t}`):(rp.set(t,e),e.type=t)}function hp(t){const e=rp.get(t);if(void 0!==e)return new e}class lp extends op{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}`),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}ap("TempNode",lp);class up extends op{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")} ]`}}ap("ArrayElementNode",up);class cp extends op{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)}}ap("ConvertNode",cp);class dp extends lp{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)}}ap("JoinNode",dp);const pp=Jd.join("");class mp extends op{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(Jd.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===pp.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}}ap("SplitNode",mp);class gp extends lp{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),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),l=[];for(let t=0;t<h;t++){const e=Jd[t];e===s[0]?(l.push(o),t+=s.length-1):l.push(a+"."+e)}return`${t.getType(r)}( ${l.join(", ")} )`}}ap("SetNode",gp);class fp extends op{constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return null===this.nodeType?Kd(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=Kd(this.value),t.nodeType=this.nodeType,"ArrayBuffer"===t.valueType&&(t.value=ep(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?tp(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.")}}ap("InputNode",fp);class yp extends fp{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)}}ap("ConstNode",yp);let xp=null;const bp=new Map;function vp(t,e){if(bp.has(t))console.warn(`Redefinition of node element ${t}`);else{if("function"!=typeof e)throw new Error(`Node element ${t} is not a function`);bp.set(t,e)}}const Tp=t=>t.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),_p={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)=>(xp.assign(s,...t),s);if(bp.has(e)){const i=bp.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&bp.has(e.slice(0,e.length-6))){const i=bp.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=Tp(e),qp(new mp(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=(e=Tp(e.slice(3).toLowerCase())).split("").sort().join(""),s=>qp(new gp(t,e,s));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),qp(new mp(t,e));if(!0===/^\d+$/.test(e))return qp(new up(s,new yp(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)},wp=new WeakMap,Sp=new WeakMap,Mp=function(t,e=null){for(const s in t)t[s]=qp(t[s],e);return t},Ap=function(t,e=null){const s=t.length;for(let i=0;i<s;i++)t[i]=qp(t[i],e);return t},Np=function(t,e=null,s=null,i=null){const r=t=>qp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...Xp(e))):null!==s?(s=qp(s),(...i)=>r(new t(e,...Xp(i),s))):(...s)=>r(new t(e,...Xp(s)))},Rp=function(t,...e){return qp(new t(...Xp(e)))};class Cp extends op{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode.getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this;if(e.layout){let i=Sp.get(t.constructor);void 0===i&&(i=new WeakMap,Sp.set(t.constructor,i));let r=i.get(e);return void 0===r&&(r=qp(t.buildFunctionNode(e)),i.set(e,r)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(r),qp(r.call(s))}const i=e.jsFunc,r=null!==s?i(s,t.stack,t):i(t.stack,t);return qp(r)}setup(t){const{outputNode:e}=t.getNodeProperties(this);return e||this.setupOutput(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);return null===s?this.call(t).build(t,e):super.generate(t,e)}}class Ep extends op{constructor(t){super(),this.jsFunc=t,this.layout=null,this.global=!0}get isArrayInput(){return/^\((\s+)?\[/.test(this.jsFunc.toString())}setLayout(t){return this.layout=t,this}call(t=null){return $p(t),qp(new Cp(this,t))}setup(){return this.call()}}const Bp=[!1,!0],Ip=[0,1,2,3],Pp=[-1,-2],Fp=[.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],Up=new Map;for(const t of Bp)Up.set(t,new yp(t));const Op=new Map;for(const t of Ip)Op.set(t,new yp(t,"uint"));const zp=new Map([...Op].map((t=>new yp(t.value,"int"))));for(const t of Pp)zp.set(t,new yp(t,"int"));const Lp=new Map([...zp].map((t=>new yp(t.value))));for(const t of Fp)Lp.set(t,new yp(t));for(const t of Fp)Lp.set(-t,new yp(-t));const Vp={bool:Up,uint:Op,ints:zp,float:Lp},Dp=new Map([...Up,...Lp]),kp=(t,e)=>Dp.has(t)?Dp.get(t):!0===t.isNode?t:new yp(t,e),Gp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[tp(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return qp(e.get(s[0]));if(1===s.length){const e=kp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?qp(e):qp(new cp(e,t))}const i=s.map((t=>kp(t)));return qp(new dp(i,t))}},Wp=t=>t&&t.value,jp=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function Hp(t){return new Proxy(new Ep(t),_p)}const qp=(t,e=null)=>function(t,e=null){const s=Kd(t);if("node"===s){let e=wp.get(t);return void 0===e&&(e=new Proxy(t,_p),wp.set(t,e),wp.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?qp(kp(t,e)):"shader"===s?Zp(t):t}(t,e),$p=(t,e=null)=>new Mp(t,e),Xp=(t,e=null)=>new Ap(t,e),Yp=(...t)=>new Np(...t),Jp=(...t)=>new Rp(...t),Zp=t=>{const e=new Hp(t),s=(...t)=>{let s;return $p(t),s=t[0]&&t[0].isNode?[...t]:t[0],e.call(s)};return s.shaderNode=e,s.setLayout=t=>(e.setLayout(t),s),s};ap("ShaderNode",Hp),vp("toGlobal",(t=>(t.global=!0,t)));const Qp=t=>{xp=t},Kp=()=>xp,tm=(...t)=>xp.if(...t);function em(t){return xp&&xp.add(t),t}vp("append",em);const sm=new Gp("color"),im=new Gp("float",Vp.float),rm=new Gp("int",Vp.ints),nm=new Gp("uint",Vp.uint),om=new Gp("bool",Vp.bool),am=new Gp("vec2"),hm=new Gp("ivec2"),lm=new Gp("uvec2"),um=new Gp("bvec2"),cm=new Gp("vec3"),dm=new Gp("ivec3"),pm=new Gp("uvec3"),mm=new Gp("bvec3"),gm=new Gp("vec4"),fm=new Gp("ivec4"),ym=new Gp("uvec4"),xm=new Gp("bvec4"),bm=new Gp("mat2"),vm=new Gp("imat2"),Tm=new Gp("umat2"),_m=new Gp("bmat2"),wm=new Gp("mat3"),Sm=new Gp("imat3"),Mm=new Gp("umat3"),Am=new Gp("bmat3"),Nm=new Gp("mat4"),Rm=new Gp("imat4"),Cm=new Gp("umat4"),Em=new Gp("bmat4"),Bm=(t="")=>qp(new yp(t,"string")),Im=t=>qp(new yp(t,"ArrayBuffer"));vp("toColor",sm),vp("toFloat",im),vp("toInt",rm),vp("toUint",nm),vp("toBool",om),vp("toVec2",am),vp("toIvec2",hm),vp("toUvec2",lm),vp("toBvec2",um),vp("toVec3",cm),vp("toIvec3",dm),vp("toUvec3",pm),vp("toBvec3",mm),vp("toVec4",gm),vp("toIvec4",fm),vp("toUvec4",ym),vp("toBvec4",xm),vp("toMat2",bm),vp("toImat2",vm),vp("toUmat2",Tm),vp("toBmat2",_m),vp("toMat3",wm),vp("toImat3",Sm),vp("toUmat3",Mm),vp("toBmat3",Am),vp("toMat4",Nm),vp("toImat4",Rm),vp("toUmat4",Cm),vp("toBmat4",Em);const Pm=Yp(up),Fm=(t,e)=>qp(new cp(qp(t),e)),Um=(t,e)=>qp(new mp(qp(t),e));vp("element",Pm),vp("convert",Fm);class Om extends lp{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 Jd.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),l=t.getDataFromNode(this);let u;if(!0===l.initialized)"void"!==e&&(u=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`);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} ]`)}"void"!==e&&(u=o)}else u=`${o} = ${a}`,"void"!==e&&"void"!==h||(t.addLineFlowCode(u),"void"!==e&&(u=o));return l.initialized=!0,t.format(u,n,e)}}const zm=Yp(Om);ap("AssignNode",Om),vp("assign",zm);class Lm extends op{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,jd.VERTEX);t.flowNodeFromShaderStage(jd.VERTEX,this.node,i,r),e.propertyName=r}return t.getPropertyName(s)}}const Vm=Yp(Lm);vp("varying",Vm),ap("VaryingNode",Lm);class Dm extends op{constructor(t,e=null,s=null){super(e),this.defaultNode=s,this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=super.getNodeType(t);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 Vm(this).build(t,s)}{console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`);const{defaultNode:i}=this;return null!==i?i.build(t,s):t.generateConst(s)}}}const km=(t,e,s)=>qp(new Dm(t,e,qp(s)));ap("AttributeNode",Dm);class Gm extends op{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.outputNode.build(t)}}const Wm=Yp(Gm);vp("bypass",Wm),ap("BypassNode",Gm);class jm extends op{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,parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const Hm=(t,...e)=>qp(new jm(qp(t),...e));vp("cache",Hm),ap("CacheNode",jm);class qm extends op{constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.context=e}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.context});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.context});const i=this.node.build(t,e);return t.setContext(s),i}}const $m=Yp(qm),Xm=(t,e)=>$m(t,{label:e});vp("context",$m),vp("label",Xm),ap("ContextNode",qm);class Ym extends op{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===Ym.VERTEX)i=t.getVertexIndex();else if(s===Ym.INSTANCE)i=t.getInstanceIndex();else{if(s!==Ym.DRAW)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getDrawIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=Vm(this).build(t,e)}return r}}Ym.VERTEX="vertex",Ym.INSTANCE="instance",Ym.DRAW="draw";const Jm=Jp(Ym,Ym.VERTEX),Zm=Jp(Ym,Ym.INSTANCE),Qm=Jp(Ym,Ym.DRAW);ap("IndexNode",Ym);class Km{start(){}finish(){}direct(){}directRectArea(){}indirectDiffuse(){}indirectSpecular(){}ambientOcclusion(){}}class tg extends op{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}`),r}}const eg=Yp(tg);vp("temp",eg),vp("toVar",((...t)=>eg(...t).append())),ap("VarNode",tg);class sg{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class ig{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 rg{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class ng extends rg{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class og{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}class ag{constructor(){this.keywords=[],this.nodes={},this.keywordsCallback={}}getNode(t){let e=this.nodes[t];return void 0===e&&void 0!==this.keywordsCallback[t]&&(e=this.keywordsCallback[t](t),this.nodes[t]=e),e}addKeyword(t,e){return this.keywords.push(t),this.keywordsCallback[t]=e,this}parse(t){const e=this.keywords,s=new RegExp(`\\b${e.join("\\b|\\b")}\\b`,"g"),i=t.match(s),r=[];if(null!==i)for(const t of i){const e=this.getNode(t);void 0!==e&&-1===r.indexOf(e)&&r.push(e)}return r}include(t,e){const s=this.parse(e);for(const e of s)e.build(t)}}let hg=0;class lg{constructor(t=null){this.id=hg++,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 ug extends op{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 cg=(t,e)=>qp(new ug(t,e)),dg=(t,e)=>qp(new ug(t,e,!0)),pg=Jp(ug,"vec4","DiffuseColor"),mg=Jp(ug,"float","Roughness"),gg=Jp(ug,"float","Metalness"),fg=Jp(ug,"float","Clearcoat"),yg=Jp(ug,"float","ClearcoatRoughness"),xg=Jp(ug,"vec3","Sheen"),bg=Jp(ug,"float","SheenRoughness"),vg=Jp(ug,"float","Iridescence"),Tg=Jp(ug,"float","IridescenceIOR"),_g=Jp(ug,"float","IridescenceThickness"),wg=Jp(ug,"float","AlphaT"),Sg=Jp(ug,"float","Anisotropy"),Mg=Jp(ug,"vec3","AnisotropyT"),Ag=Jp(ug,"vec3","AnisotropyB"),Ng=Jp(ug,"color","SpecularColor"),Rg=Jp(ug,"float","SpecularF90"),Cg=Jp(ug,"float","Shininess"),Eg=Jp(ug,"vec4","Output"),Bg=Jp(ug,"float","dashSize"),Ig=Jp(ug,"float","gapSize"),Pg=Jp(ug,"float","pointWidth"),Fg=Jp(ug,"float","IOR"),Ug=Jp(ug,"float","Transmission"),Og=Jp(ug,"float","Thickness"),zg=Jp(ug,"float","AttenuationDistance"),Lg=Jp(ug,"color","AttenuationColor"),Vg=Jp(ug,"float","Dispersion");ap("PropertyNode",ug);class Dg extends ug{constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const kg=(t,e)=>qp(new Dg(t,e));ap("ParameterNode",Dg);class Gg extends op{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 Wg=Yp(Gg),jg=(t,e)=>Wg(t,e,"js"),Hg=(t,e)=>Wg(t,e,"wgsl"),qg=(t,e)=>Wg(t,e,"glsl");ap("CodeNode",Gg);class $g extends Gg{constructor(t="",e=[],s=""){super(t,e,s),this.keywords={}}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);let a=this.getNodeFunction(t).getCode(o);const h=this.keywords,l=Object.keys(h);if(l.length>0)for(const e of l){const s=new RegExp(`\\b${e}\\b`,"g"),i=h[e].build(t,"property");a=a.replace(s,i)}return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const Xg=(t,e=[],s="")=>{for(let t=0;t<e.length;t++){const s=e[t];"function"==typeof s&&(e[t]=s.functionNode)}const i=qp(new $g(t,e,s)),r=(...t)=>i.call(...t);return r.functionNode=i,r},Yg=(t,e)=>Xg(t,e,"glsl"),Jg=(t,e)=>Xg(t,e,"wgsl");ap("FunctionNode",$g);class Zg extends op{constructor(t,e=!1){super("string"),this.name=t,this.version=0,this.shared=e,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}}const Qg=t=>new Zg(t),Kg=t=>new Zg(t,!0),tf=Kg("frame"),ef=Kg("render"),sf=Qg("object");ap("UniformGroupNode",Zg);class rf extends fp{constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=sf}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 nf=(t,e)=>{const s=jp(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return qp(new rf(i,s))};ap("UniformNode",rf);const of=t=>km("uv"+(t>0?t:""),"vec2");class af extends op{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=this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const hf=Yp(af);vp("textureSize",hf),ap("TextureSizeNode",af);class lf extends lp{constructor(t,e,s,...i){if(super(),i.length>0){let r=new lf(t,e,s);for(let e=0;e<i.length-1;e++)r=new lf(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="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),l=void 0!==r?r.build(t,a):null,u=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&u>1?t.format(`${t.getMethod("lessThan")}( ${h}, ${l} )`,n,e):"<="===s&&u>1?t.format(`${t.getMethod("lessThanEqual")}( ${h}, ${l} )`,n,e):">"===s&&u>1?t.format(`${t.getMethod("greaterThan")}( ${h}, ${l} )`,n,e):">="===s&&u>1?t.format(`${t.getMethod("greaterThanEqual")}( ${h}, ${l} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${l} )`,n,e):t.format(`( ${h} ${s} ${l} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${l} )`,n,e):t.format(`${h} ${s} ${l}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const uf=Yp(lf,"+"),cf=Yp(lf,"-"),df=Yp(lf,"*"),pf=Yp(lf,"/"),mf=Yp(lf,"%"),gf=Yp(lf,"=="),ff=Yp(lf,"!="),yf=Yp(lf,"<"),xf=Yp(lf,">"),bf=Yp(lf,"<="),vf=Yp(lf,">="),Tf=Yp(lf,"&&"),_f=Yp(lf,"||"),wf=Yp(lf,"!"),Sf=Yp(lf,"^^"),Mf=Yp(lf,"&"),Af=Yp(lf,"~"),Nf=Yp(lf,"|"),Rf=Yp(lf,"^"),Cf=Yp(lf,"<<"),Ef=Yp(lf,">>");vp("add",uf),vp("sub",cf),vp("mul",df),vp("div",pf),vp("remainder",mf),vp("equal",gf),vp("notEqual",ff),vp("lessThan",yf),vp("greaterThan",xf),vp("lessThanEqual",bf),vp("greaterThanEqual",vf),vp("and",Tf),vp("or",_f),vp("not",wf),vp("xor",Sf),vp("bitAnd",Mf),vp("bitNot",Af),vp("bitOr",Nf),vp("bitXor",Rf),vp("shiftLeft",Cf),vp("shiftRight",Ef),ap("OperatorNode",lf);class Bf extends lp{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===Bf.LENGTH||e===Bf.DISTANCE||e===Bf.DOT?"float":e===Bf.CROSS?"vec3":e===Bf.ALL?"bool":e===Bf.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===Bf.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===Bf.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=gm(cm(i),0):s=gm(cm(s),0);const r=df(s,i).xyz;return Yf(r).build(t,e)}if(s===Bf.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===Bf.ONE_MINUS)return cf(1,n).build(t,e);if(s===Bf.RECIPROCAL)return pf(1,n).build(t,e);if(s===Bf.DIFFERENCE)return iy(cf(n,o)).build(t,e);{const l=[];return s===Bf.CROSS||s===Bf.MOD?l.push(n.build(t,i),o.build(t,i)):s===Bf.STEP?l.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===Bf.MIN||s===Bf.MAX)||s===Bf.MOD?l.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===Bf.REFRACT?l.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===Bf.MIX?l.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(l.push(n.build(t,r)),null!==o&&l.push(o.build(t,r)),null!==a&&l.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${l.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}Bf.ALL="all",Bf.ANY="any",Bf.EQUALS="equals",Bf.RADIANS="radians",Bf.DEGREES="degrees",Bf.EXP="exp",Bf.EXP2="exp2",Bf.LOG="log",Bf.LOG2="log2",Bf.SQRT="sqrt",Bf.INVERSE_SQRT="inversesqrt",Bf.FLOOR="floor",Bf.CEIL="ceil",Bf.NORMALIZE="normalize",Bf.FRACT="fract",Bf.SIN="sin",Bf.COS="cos",Bf.TAN="tan",Bf.ASIN="asin",Bf.ACOS="acos",Bf.ATAN="atan",Bf.ABS="abs",Bf.SIGN="sign",Bf.LENGTH="length",Bf.NEGATE="negate",Bf.ONE_MINUS="oneMinus",Bf.DFDX="dFdx",Bf.DFDY="dFdy",Bf.ROUND="round",Bf.RECIPROCAL="reciprocal",Bf.TRUNC="trunc",Bf.FWIDTH="fwidth",Bf.BITCAST="bitcast",Bf.TRANSPOSE="transpose",Bf.ATAN2="atan2",Bf.MIN="min",Bf.MAX="max",Bf.MOD="mod",Bf.STEP="step",Bf.REFLECT="reflect",Bf.DISTANCE="distance",Bf.DIFFERENCE="difference",Bf.DOT="dot",Bf.CROSS="cross",Bf.POW="pow",Bf.TRANSFORM_DIRECTION="transformDirection",Bf.MIX="mix",Bf.CLAMP="clamp",Bf.REFRACT="refract",Bf.SMOOTHSTEP="smoothstep",Bf.FACEFORWARD="faceforward";const If=im(1e-6),Pf=im(1e6),Ff=im(Math.PI),Uf=im(2*Math.PI),Of=Yp(Bf,Bf.ALL),zf=Yp(Bf,Bf.ANY),Lf=Yp(Bf,Bf.EQUALS),Vf=Yp(Bf,Bf.RADIANS),Df=Yp(Bf,Bf.DEGREES),kf=Yp(Bf,Bf.EXP),Gf=Yp(Bf,Bf.EXP2),Wf=Yp(Bf,Bf.LOG),jf=Yp(Bf,Bf.LOG2),Hf=Yp(Bf,Bf.SQRT),qf=Yp(Bf,Bf.INVERSE_SQRT),$f=Yp(Bf,Bf.FLOOR),Xf=Yp(Bf,Bf.CEIL),Yf=Yp(Bf,Bf.NORMALIZE),Jf=Yp(Bf,Bf.FRACT),Zf=Yp(Bf,Bf.SIN),Qf=Yp(Bf,Bf.COS),Kf=Yp(Bf,Bf.TAN),ty=Yp(Bf,Bf.ASIN),ey=Yp(Bf,Bf.ACOS),sy=Yp(Bf,Bf.ATAN),iy=Yp(Bf,Bf.ABS),ry=Yp(Bf,Bf.SIGN),ny=Yp(Bf,Bf.LENGTH),oy=Yp(Bf,Bf.NEGATE),ay=Yp(Bf,Bf.ONE_MINUS),hy=Yp(Bf,Bf.DFDX),ly=Yp(Bf,Bf.DFDY),uy=Yp(Bf,Bf.ROUND),cy=Yp(Bf,Bf.RECIPROCAL),dy=Yp(Bf,Bf.TRUNC),py=Yp(Bf,Bf.FWIDTH),my=Yp(Bf,Bf.BITCAST),gy=Yp(Bf,Bf.TRANSPOSE),fy=Yp(Bf,Bf.ATAN2),yy=Yp(Bf,Bf.MIN),xy=Yp(Bf,Bf.MAX),by=Yp(Bf,Bf.MOD),vy=Yp(Bf,Bf.STEP),Ty=Yp(Bf,Bf.REFLECT),_y=Yp(Bf,Bf.DISTANCE),wy=Yp(Bf,Bf.DIFFERENCE),Sy=Yp(Bf,Bf.DOT),My=Yp(Bf,Bf.CROSS),Ay=Yp(Bf,Bf.POW),Ny=Yp(Bf,Bf.POW,2),Ry=Yp(Bf,Bf.POW,3),Cy=Yp(Bf,Bf.POW,4),Ey=Yp(Bf,Bf.TRANSFORM_DIRECTION),By=t=>df(ry(t),Ay(iy(t),1/3)),Iy=t=>Sy(t,t),Py=Yp(Bf,Bf.MIX),Fy=(t,e=0,s=1)=>qp(new Bf(Bf.CLAMP,qp(t),qp(e),qp(s))),Uy=t=>Fy(t),Oy=Yp(Bf,Bf.REFRACT),zy=Yp(Bf,Bf.SMOOTHSTEP),Ly=Yp(Bf,Bf.FACEFORWARD),Vy=Zp((([t])=>{const e=Sy(t.xy,am(12.9898,78.233)),s=by(e,Ff);return Jf(Zf(s).mul(43758.5453))}));vp("all",Of),vp("any",zf),vp("equals",Lf),vp("radians",Vf),vp("degrees",Df),vp("exp",kf),vp("exp2",Gf),vp("log",Wf),vp("log2",jf),vp("sqrt",Hf),vp("inverseSqrt",qf),vp("floor",$f),vp("ceil",Xf),vp("normalize",Yf),vp("fract",Jf),vp("sin",Zf),vp("cos",Qf),vp("tan",Kf),vp("asin",ty),vp("acos",ey),vp("atan",sy),vp("abs",iy),vp("sign",ry),vp("length",ny),vp("lengthSq",Iy),vp("negate",oy),vp("oneMinus",ay),vp("dFdx",hy),vp("dFdy",ly),vp("round",uy),vp("reciprocal",cy),vp("trunc",dy),vp("fwidth",py),vp("atan2",fy),vp("min",yy),vp("max",xy),vp("mod",by),vp("step",vy),vp("reflect",Ty),vp("distance",_y),vp("dot",Sy),vp("cross",My),vp("pow",Ay),vp("pow2",Ny),vp("pow3",Ry),vp("pow4",Cy),vp("transformDirection",Ey),vp("mix",((t,e,s)=>Py(e,s,t))),vp("clamp",Fy),vp("refract",Oy),vp("smoothstep",((t,e,s)=>zy(e,s,t))),vp("faceForward",Ly),vp("difference",wy),vp("saturate",Uy),vp("cbrt",By),vp("transpose",gy),vp("rand",Vy),ap("MathNode",Bf);const Dy=Zp((t=>{const{value:e}=t,{rgb:s}=e,i=s.mul(.9478672986).add(.0521327014).pow(2.4),r=s.mul(.0773993808),n=s.lessThanEqual(.04045),o=Py(i,r,n);return gm(o,e.a)})),ky=Zp((t=>{const{value:e}=t,{rgb:s}=e,i=s.pow(.41666).mul(1.055).sub(.055),r=s.mul(12.92),n=s.lessThanEqual(.0031308),o=Py(i,r,n);return gm(o,e.a)})),Gy=t=>{let e=null;return t===Ye?e="Linear":t===Xe&&(e="sRGB"),e},Wy=(t,e)=>Gy(t)+"To"+Gy(e);class jy extends lp{constructor(t,e){super("vec4"),this.method=t,this.node=e}setup(){const{method:t,node:e}=this;return t===jy.LINEAR_TO_LINEAR?e:Hy[t]({value:e})}}jy.LINEAR_TO_LINEAR="LinearToLinear",jy.LINEAR_TO_sRGB="LinearTosRGB",jy.sRGB_TO_LINEAR="sRGBToLinear";const Hy={[jy.LINEAR_TO_sRGB]:ky,[jy.sRGB_TO_LINEAR]:Dy},qy=(t,e)=>qp(new jy(Wy(Ye,e),qp(t))),$y=(t,e)=>qp(new jy(Wy(e,Ye),qp(t))),Xy=Yp(jy,jy.LINEAR_TO_sRGB),Yy=Yp(jy,jy.sRGB_TO_LINEAR);vp("linearTosRGB",Xy),vp("sRGBToLinear",Yy),vp("linearToColorSpace",qy),vp("colorSpaceToLinear",$y),ap("ColorSpaceNode",jy);class Jy extends op{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)}}const Zy=Yp(Jy);ap("ExpressionNode",Jy);class Qy extends rf{constructor(t){super(0),this.textureNode=t,this.updateType=Hd.FRAME}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 Ky=Yp(Qy);ap("MaxMipLevelNode",Qy);class tx extends rf{constructor(t,e=null,s=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Hd.NONE,this.referenceNode=null,this._value=t,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 of(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){const e=this.value;return nf(e.matrix).mul(cm(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?Hd.FRAME:Hd.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=e.setY(e.y.oneMinus())),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.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){const a=this.value;let h;return h=i?t.generateTextureLevel(a,e,s,i,r):o?t.generateTextureGrad(a,e,s,o,r):n?t.generateTextureCompare(a,e,s,n,r):!1===this.sampler?t.generateTextureLoad(a,e,s,r):t.generateTexture(a,e,s,r),h}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,compareNode:a,depthNode:h,gradNode:l}=s,u=this.generateUV(t,e),c=i?i.build(t,"float"):null,d=h?h.build(t,"int"):null,p=a?a.build(t,"float"):null,m=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,g=t.getVarFromNode(this);o=t.getPropertyName(g);const f=this.generateSnippet(t,r,u,c,d,p,m);t.addLineFlowCode(`${o} = ${f}`),n.snippet=f,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsColorSpaceToLinear(i)&&(a=$y(Zy(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=t,e.referenceNode=this,qp(e)}blur(t){const e=this.clone();return e.levelNode=t.mul(Ky(e)),e.referenceNode=this,qp(e)}level(t){const e=this.clone();return e.levelNode=t,e.referenceNode=this,e}size(t){return hf(this,t)}compare(t){const e=this.clone();return e.compareNode=qp(t),e.referenceNode=this,qp(e)}grad(t,e){const s=this.clone();return s.gradNode=[qp(t),qp(e)],s.referenceNode=this,qp(s)}depth(t){const e=this.clone();return e.depthNode=qp(t),e.referenceNode=this,qp(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value]}update(){const t=this.value;!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t}}const ex=Yp(tx),sx=(...t)=>ex(...t).setSampler(!1),ix=t=>(!0===t.isNode?t:ex(t)).convert("sampler");vp("texture",ex),ap("TextureNode",tx);class rx extends rf{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 nx=(t,e,s)=>qp(new rx(t,e,s));ap("BufferNode",rx);class ox extends up{constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class ax extends rx{constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=Hd.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?Kd(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 qp(new ox(this,qp(t)))}}const hx=(t,e)=>qp(new ax(t,e));ap("UniformsNode",ax);class lx extends up{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 ux extends op{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=null,this.node=null,this.updateType=Hd.OBJECT}element(t){return qp(new lx(this,qp(t)))}setNodeType(t){let e=null;e=null!==this.count?nx(null,t,this.count):Array.isArray(this.getValueFromReference())?hx(null,t):"texture"===t?ex(null):nf(null,t),this.node=e}getNodeType(t){return null===this.node&&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 cx=(t,e,s)=>qp(new ux(t,e,s)),dx=(t,e,s,i)=>qp(new ux(t,e,i,s));ap("ReferenceNode",ux);class px extends ux{constructor(t,e,s=null){super(t,e,s),this.material=s}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const mx=(t,e,s)=>qp(new px(t,e,s));ap("MaterialReferenceNode",px);const gx=Kg("camera").onRenderUpdate((()=>{gx.needsUpdate=!0})),fx=nf("float").label("cameraNear").setGroup(gx).onRenderUpdate((({camera:t})=>t.near)),yx=nf("float").label("cameraFar").setGroup(gx).onRenderUpdate((({camera:t})=>t.far)),xx=nf("float").label("cameraLogDepth").setGroup(gx).onRenderUpdate((({camera:t})=>2/(Math.log(t.far+1)/Math.LN2))),bx=nf("mat4").label("cameraProjectionMatrix").setGroup(gx).onRenderUpdate((({camera:t})=>t.projectionMatrix)),vx=nf("mat4").label("cameraProjectionMatrixInverse").setGroup(gx).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Tx=nf("mat4").label("cameraViewMatrix").setGroup(gx).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),_x=nf("mat4").label("cameraWorldMatrix").setGroup(gx).onRenderUpdate((({camera:t})=>t.matrixWorld)),wx=nf("mat3").label("cameraNormalMatrix").setGroup(gx).onRenderUpdate((({camera:t})=>t.normalMatrix)),Sx=nf(new Ri).label("cameraPosition").setGroup(gx).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Mx extends op{constructor(t=Mx.VIEW_MATRIX,e=null){super(),this.scope=t,this.object3d=e,this.updateType=Hd.OBJECT,this._uniformNode=new rf(null)}getNodeType(){const t=this.scope;return t===Mx.WORLD_MATRIX||t===Mx.VIEW_MATRIX?"mat4":t===Mx.NORMAL_MATRIX?"mat3":t===Mx.POSITION||t===Mx.VIEW_POSITION||t===Mx.DIRECTION||t===Mx.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Mx.VIEW_MATRIX)s.value=e.modelViewMatrix;else if(i===Mx.NORMAL_MATRIX)s.value=e.normalMatrix;else if(i===Mx.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Mx.POSITION)s.value=s.value||new Ri,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Mx.SCALE)s.value=s.value||new Ri,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Mx.DIRECTION)s.value=s.value||new Ri,e.getWorldDirection(s.value);else if(i===Mx.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ri,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Mx.WORLD_MATRIX||e===Mx.VIEW_MATRIX?this._uniformNode.nodeType="mat4":e===Mx.NORMAL_MATRIX?this._uniformNode.nodeType="mat3":e!==Mx.POSITION&&e!==Mx.VIEW_POSITION&&e!==Mx.DIRECTION&&e!==Mx.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}}Mx.VIEW_MATRIX="viewMatrix",Mx.NORMAL_MATRIX="normalMatrix",Mx.WORLD_MATRIX="worldMatrix",Mx.POSITION="position",Mx.SCALE="scale",Mx.VIEW_POSITION="viewPosition",Mx.DIRECTION="direction";const Ax=Yp(Mx,Mx.DIRECTION),Nx=Yp(Mx,Mx.VIEW_MATRIX),Rx=Yp(Mx,Mx.NORMAL_MATRIX),Cx=Yp(Mx,Mx.WORLD_MATRIX),Ex=Yp(Mx,Mx.POSITION),Bx=Yp(Mx,Mx.SCALE),Ix=Yp(Mx,Mx.VIEW_POSITION);ap("Object3DNode",Mx);class Px extends Mx{constructor(t=Px.VIEW_MATRIX){super(t)}update(t){this.object3d=t.object,super.update(t)}}const Fx=Jp(Px,Px.DIRECTION),Ux=Jp(Px,Px.VIEW_MATRIX).label("modelViewMatrix").temp("ModelViewMatrix"),Ox=Jp(Px,Px.NORMAL_MATRIX),zx=Jp(Px,Px.WORLD_MATRIX),Lx=Jp(Px,Px.POSITION),Vx=Jp(Px,Px.SCALE),Dx=Jp(Px,Px.VIEW_POSITION),kx=nf(new rr).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert()));ap("ModelNode",Px);const Gx=km("normal","vec3",cm(0,1,0)),Wx=Gx.toVar("normalLocal"),jx=Vm(Ox.mul(Wx),"v_normalView").normalize().toVar("normalView"),Hx=Vm(jx.transformDirection(Tx),"v_normalWorld").normalize().toVar("transformedNormalWorld"),qx=cg("vec3","transformedNormalView"),$x=qx.transformDirection(Tx).normalize().toVar("transformedNormalWorld"),Xx=cg("vec3","transformedClearcoatNormalView"),Yx=new Map;class Jx extends op{constructor(t){super(),this.scope=t}getCache(t,e){let s=Yx.get(t);return void 0===s&&(s=mx(t,e),Yx.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===Jx.COLOR){const t=this.getColor(s);i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===Jx.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===Jx.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:im(1);else if(s===Jx.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===Jx.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===Jx.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===Jx.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===Jx.EMISSIVE){const t=this.getColor(s);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?t.mul(this.getTexture(s)):t}else if(s===Jx.NORMAL)i=e.normalMap?this.getTexture("normal").normalMap(this.getCache("normalScale","vec2")):e.bumpMap?this.getTexture("bump").r.bumpMap(this.getFloat("bumpScale")):jx;else if(s===Jx.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Jx.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===Jx.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?this.getTexture(s).normalMap(this.getCache(s+"Scale","vec2")):jx;else if(s===Jx.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===Jx.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===Jx.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=bm(Ib.x,Ib.y,Ib.y.negate(),Ib.x).mul(t.rg.mul(2).sub(am(1)).normalize().mul(t.b))}else i=Ib;else if(s===Jx.IRIDESCENCE_THICKNESS){const t=cx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=cx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===Jx.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===Jx.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===Jx.IOR)i=this.getFloat(s);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}Jx.ALPHA_TEST="alphaTest",Jx.COLOR="color",Jx.OPACITY="opacity",Jx.SHININESS="shininess",Jx.SPECULAR="specular",Jx.SPECULAR_STRENGTH="specularStrength",Jx.SPECULAR_INTENSITY="specularIntensity",Jx.SPECULAR_COLOR="specularColor",Jx.REFLECTIVITY="reflectivity",Jx.ROUGHNESS="roughness",Jx.METALNESS="metalness",Jx.NORMAL="normal",Jx.CLEARCOAT="clearcoat",Jx.CLEARCOAT_ROUGHNESS="clearcoatRoughness",Jx.CLEARCOAT_NORMAL="clearcoatNormal",Jx.EMISSIVE="emissive",Jx.ROTATION="rotation",Jx.SHEEN="sheen",Jx.SHEEN_ROUGHNESS="sheenRoughness",Jx.ANISOTROPY="anisotropy",Jx.IRIDESCENCE="iridescence",Jx.IRIDESCENCE_IOR="iridescenceIOR",Jx.IRIDESCENCE_THICKNESS="iridescenceThickness",Jx.IOR="ior",Jx.TRANSMISSION="transmission",Jx.THICKNESS="thickness",Jx.ATTENUATION_DISTANCE="attenuationDistance",Jx.ATTENUATION_COLOR="attenuationColor",Jx.LINE_SCALE="scale",Jx.LINE_DASH_SIZE="dashSize",Jx.LINE_GAP_SIZE="gapSize",Jx.LINE_WIDTH="linewidth",Jx.LINE_DASH_OFFSET="dashOffset",Jx.POINT_WIDTH="pointWidth",Jx.DISPERSION="dispersion";const Zx=Jp(Jx,Jx.ALPHA_TEST),Qx=Jp(Jx,Jx.COLOR),Kx=Jp(Jx,Jx.SHININESS),tb=Jp(Jx,Jx.EMISSIVE),eb=Jp(Jx,Jx.OPACITY),sb=Jp(Jx,Jx.SPECULAR),ib=Jp(Jx,Jx.SPECULAR_INTENSITY),rb=Jp(Jx,Jx.SPECULAR_COLOR),nb=Jp(Jx,Jx.SPECULAR_STRENGTH),ob=Jp(Jx,Jx.REFLECTIVITY),ab=Jp(Jx,Jx.ROUGHNESS),hb=Jp(Jx,Jx.METALNESS),lb=Jp(Jx,Jx.NORMAL),ub=Jp(Jx,Jx.CLEARCOAT),cb=Jp(Jx,Jx.CLEARCOAT_ROUGHNESS),db=Jp(Jx,Jx.CLEARCOAT_NORMAL),pb=Jp(Jx,Jx.ROTATION),mb=Jp(Jx,Jx.SHEEN),gb=Jp(Jx,Jx.SHEEN_ROUGHNESS),fb=Jp(Jx,Jx.ANISOTROPY),yb=Jp(Jx,Jx.IRIDESCENCE),xb=Jp(Jx,Jx.IRIDESCENCE_IOR),bb=Jp(Jx,Jx.IRIDESCENCE_THICKNESS),vb=Jp(Jx,Jx.TRANSMISSION),Tb=Jp(Jx,Jx.THICKNESS),_b=Jp(Jx,Jx.IOR),wb=Jp(Jx,Jx.ATTENUATION_DISTANCE),Sb=Jp(Jx,Jx.ATTENUATION_COLOR),Mb=Jp(Jx,Jx.LINE_SCALE),Ab=Jp(Jx,Jx.LINE_DASH_SIZE),Nb=Jp(Jx,Jx.LINE_GAP_SIZE),Rb=Jp(Jx,Jx.LINE_WIDTH),Cb=Jp(Jx,Jx.LINE_DASH_OFFSET),Eb=Jp(Jx,Jx.POINT_WIDTH),Bb=Jp(Jx,Jx.DISPERSION),Ib=nf(new Zs).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))}));ap("MaterialNode",Jx);const Pb=km("position","vec3"),Fb=Pb.toVar("positionLocal"),Ub=Vm(zx.mul(Fb).xyz,"v_positionWorld"),Ob=Vm(Fb.transformDirection(zx),"v_positionWorldDirection").normalize().toVar("positionWorldDirection"),zb=Vm(Ux.mul(Fb).xyz,"v_positionView"),Lb=Vm(zb.negate(),"v_positionViewDirection").normalize().toVar("positionViewDirection");class Vb extends lp{constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return Vm(t.context.mvp);const e=this.positionNode||Fb;return bx.mul(Ux).mul(e)}}const Db=Yp(Vb);ap("ModelViewProjectionNode",Vb);class kb extends fp{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=As,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 ro(s,r),a=new oo(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=Vm(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 Gb=(t,e,s,i)=>qp(new kb(t,e,s,i)),Wb=(t,e,s,i)=>Gb(t,e,s,i).setUsage(Ns),jb=(t,e,s,i)=>Gb(t,e,s,i).setInstanced(!0),Hb=(t,e,s,i)=>Wb(t,e,s,i).setInstanced(!0);vp("toAttribute",(t=>Gb(t.value))),ap("BufferAttributeNode",kb);class qb extends op{constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Hd.FRAME,this.buffer=null,this.bufferColor=null}setup(){let t=this.instanceMatrixNode;const e=this.instanceMesh;if(null===t){const s=e.instanceMatrix,i=new Mc(s.array,16,1);this.buffer=i;const r=s.usage===Ns?Hb:jb,n=[r(i,"vec4",16,0),r(i,"vec4",16,4),r(i,"vec4",16,8),r(i,"vec4",16,12)];t=Nm(...n),this.instanceMatrixNode=t}const s=e.instanceColor;if(s&&null===this.instanceColorNode){const t=new Go(s.array,3),e=s.usage===Ns?Hb:jb;this.bufferColor=t,this.instanceColorNode=cm(e(t,"vec3",3,0))}const i=t.mul(Fb).xyz,r=wm(t[0].xyz,t[1].xyz,t[2].xyz),n=Wx.div(cm(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2]))),o=r.mul(n).xyz;Fb.assign(i),Wx.assign(o),null!==this.instanceColorNode&&dg("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Ns&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Ns&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const $b=Yp(qb);ap("InstanceNode",qb);const Xb=Zp(((t,e)=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),km("tangent","vec4"))))(),Yb=Xb.xyz.toVar("tangentLocal"),Jb=Vm(Ux.mul(gm(Yb,0)).xyz,"v_tangentView").normalize().toVar("tangentView"),Zb=Vm(Jb.transformDirection(Tx),"v_tangentWorld").normalize().toVar("tangentWorld"),Qb=Jb.toVar("transformedTangentView"),Kb=Qb.transformDirection(Tx).normalize().toVar("transformedTangentWorld");class tv extends op{constructor(t){super("void"),this.batchMesh=t,this.instanceColorNode=null,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=Zm:this.batchingIdNode=Qm);const e=Zp((([t])=>{const e=hf(sx(this.batchMesh._indirectTexture),0),s=rm(t).remainder(rm(e)),i=rm(t).div(rm(e));return sx(this.batchMesh._indirectTexture,hm(s,i),null,"uvec4").x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=this.batchMesh._matricesTexture,i=hf(sx(s),0),r=im(e(rm(this.batchingIdNode))).mul(4).toVar(),n=rm(r.mod(i)),o=rm(r).div(rm(i)),a=Nm(sx(s,hm(n,o)),sx(s,hm(n.add(1),o)),sx(s,hm(n.add(2),o)),sx(s,hm(n.add(3),o))),h=wm(a[0].xyz,a[1].xyz,a[2].xyz);Fb.assign(a.mul(Fb));const l=Wx.div(cm(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),u=h.mul(l).xyz;Wx.assign(u),t.hasGeometryAttribute("tangent")&&Yb.mulAssign(h)}}const ev=Yp(tv);ap("batch",tv);class sv extends op{constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=Hd.OBJECT,this.skinIndexNode=km("skinIndex","uvec4"),this.skinWeightNode=km("skinWeight","vec4"),e?(s=cx("bindMatrix","mat4"),i=cx("bindMatrixInverse","mat4"),r=dx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=nf(t.bindMatrix,"mat4"),i=nf(t.bindMatrixInverse,"mat4"),r=nx(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r}setup(t){const{skinIndexNode:e,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:r,boneMatricesNode:n}=this,o=n.element(e.x),a=n.element(e.y),h=n.element(e.z),l=n.element(e.w),u=i.mul(Fb),c=uf(o.mul(s.x).mul(u),a.mul(s.y).mul(u),h.mul(s.z).mul(u),l.mul(s.w).mul(u)),d=r.mul(c).xyz;let p=uf(s.x.mul(o),s.y.mul(a),s.z.mul(h),s.w.mul(l));p=r.mul(p).mul(i);const m=p.transformDirection(Wx).xyz;Fb.assign(d),Wx.assign(m),t.hasGeometryAttribute("tangent")&&Yb.assign(m)}generate(t,e){if("void"!==e)return Fb.build(t,e)}update(t){(this.useReference?t.object:this.skinnedMesh).skeleton.update()}}const iv=t=>qp(new sv(t)),rv=t=>qp(new sv(t,!0));ap("SkinningNode",sv);class nv extends op{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]=Zy(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,l=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,l=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 u={start:r,end:n,condition:h},c=u.start,d=u.end;let p="",m="",g="";l||(l="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+l;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 ov=(...t)=>qp(new nv(Xp(t,"int"))).append(),av=()=>Zy("continue").append(),hv=()=>Zy("break").append();vp("loop",((t,...e)=>Wm(t,ov(...e)))),ap("LoopNode",nv);const lv=new WeakMap,uv=new vi,cv=Zp((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=rm(Jm).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return sx(t,hm(h,a)).depth(r).mul(e)}));class dv extends op{constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=nf(1),this.updateType=Hd.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=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=lv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],l=t.morphAttributes.color||[];let u=0;!0===e&&(u=1),!0===s&&(u=2),!0===i&&(u=3);let c=t.attributes.position.count*u,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new wi(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*u;for(let x=0;x<n;x++){const b=a[x],v=h[x],T=l[x],_=c*d*4*x;for(let w=0;w<b.count;w++){const S=w*f;!0===e&&(uv.fromBufferAttribute(b,w),m[_+S+0]=uv.x,m[_+S+1]=uv.y,m[_+S+2]=uv.z,m[_+S+3]=0),!0===s&&(uv.fromBufferAttribute(v,w),m[_+S+4]=uv.x,m[_+S+5]=uv.y,m[_+S+6]=uv.z,m[_+S+7]=0),!0===i&&(uv.fromBufferAttribute(T,w),m[_+S+8]=uv.x,m[_+S+9]=uv.y,m[_+S+10]=uv.z,m[_+S+11]=4===T.itemSize?uv.w:1)}}function y(){g.dispose(),lv.delete(t),t.removeEventListener("dispose",y)}o={count:n,texture:g,stride:u,size:new Zs(c,d)},lv.set(t,o),t.addEventListener("dispose",y)}return o}(e);!0===s&&Fb.mulAssign(this.morphBaseInfluence),!0===i&&Wx.mulAssign(this.morphBaseInfluence);const l=rm(h.width);ov(n,(({i:t})=>{const e=im(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(sx(this.mesh.morphTexture,hm(rm(t).add(1),rm(Zm))).r):e.assign(cx("morphTargetInfluences","float").element(t).toVar()),!0===s&&Fb.addAssign(cv({bufferMap:o,influence:e,stride:a,width:l,depth:t,offset:rm(0)})),!0===i&&Wx.addAssign(cv({bufferMap:o,influence:e,stride:a,width:l,depth:t,offset:rm(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 pv=Yp(dv);ap("MorphNode",dv);const mv=Lb.negate().reflect(qx),gv=mv.transformDirection(Tx).toVar("reflectVector");class fv extends tx{constructor(t,e=null,s=null){super(t,e,s),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){return gv}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Ls&&s.isRenderTargetTexture?e:cm(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const yv=Yp(fv);vp("cubeTexture",yv),ap("CubeTextureNode",fv);class xv extends op{constructor(){super("vec3")}generate(){console.warn("Abstract function.")}}ap("LightingNode",xv);let bv=null;class vv extends xv{constructor(t=null){super(),this.updateType=Hd.FRAME,this.light=t,this.rtt=null,this.shadowNode=null,this.shadowMaskNode=null,this.color=new $r,this._defaultColorNode=nf(this.color),this.colorNode=this._defaultColorNode,this.isAnalyticLightNode=!0}getCacheKey(){return super.getCacheKey()+"-"+this.light.id+"-"+(this.light.castShadow?"1":"0")}getHash(){return this.light.uuid}setupShadow(t){const{object:e}=t;if(!1===e.receiveShadow)return;let s=this.shadowNode;if(null===s){null===bv&&(bv=t.createNodeMaterial(),bv.fragmentNode=gm(0,0,0,1),bv.isShadowNodeMaterial=!0);const i=this.light.shadow,r=t.createRenderTarget(i.mapSize.width,i.mapSize.height),n=new Za;n.minFilter=ft,n.magFilter=ft,n.image.width=i.mapSize.width,n.image.height=i.mapSize.height,n.compareFunction=bs,r.depthTexture=n,i.camera.updateProjectionMatrix();const o=cx("intensity","float",i),a=cx("bias","float",i),h=cx("normalBias","float",i),l=e.material.shadowPositionNode||Ub;let u=nf(i.matrix).mul(l.add(Hx.mul(h)));u=u.xyz.div(u.w);const c=u.x.greaterThanEqual(0).and(u.x.lessThanEqual(1)).and(u.y.greaterThanEqual(0)).and(u.y.lessThanEqual(1)).and(u.z.lessThanEqual(1));let d=u.z.add(a);t.renderer.coordinateSystem===Ls&&(d=d.mul(2).sub(1)),u=cm(u.x,u.y.oneMinus(),d);const p=(t,e,s)=>ex(t,e).compare(s);s=p(n,u.xy,u.z);const m=ex(r.texture,u),g=c.mix(1,s.mix(m.a.mix(1,m),1));this.rtt=r,this.colorNode=this.colorNode.mul(Py(1,g,o)),this.shadowNode=s,this.shadowMaskNode=g,this.updateBeforeType=Hd.RENDER}}setup(t){this.light.castShadow?this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{rtt:e,light:s}=this,{renderer:i,scene:r,camera:n}=t,o=r.overrideMaterial;r.overrideMaterial=bv,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const a=i.toneMapping,h=i.getRenderTarget(),l=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{!0===t.castShadow&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.toneMapping=0,i.render(r,s.shadow.camera),i.setRenderTarget(h),i.setRenderObjectFunction(l),i.toneMapping=a,r.overrideMaterial=o}disposeShadow(){this.rtt.dispose(),this.shadowNode=null,this.shadowMaskNode=null,this.rtt=null,this.colorNode=this._defaultColorNode}updateBefore(t){const{light:e}=this;e.castShadow&&this.updateShadow(t)}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}ap("AnalyticLightNode",vv);const Tv=new WeakMap;class _v extends op{constructor(t=[]){super("vec3"),this.totalDiffuseNode=cm().temp("totalDiffuse"),this.totalSpecularNode=cm().temp("totalSpecular"),this.outgoingLightNode=cm().temp("outgoingLight"),this.lightNodes=t,this._hash=null}get hasLight(){return this.lightNodes.length>0}getHash(){if(null===this._hash){const t=[];for(const e of this.lightNodes)t.push(e.getHash());this._hash="lights-"+t.join(",")}return this._hash}analyze(t){const e=t.getDataFromNode(this);for(const s of e.nodes)s.build(t)}setup(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.indirectDiffuse(e,a,t),s.indirectSpecular(e,a,t),s.ambientOcclusion(e,a,t);const{backdrop:h,backdropAlpha:l}=e,{directDiffuse:u,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=u.add(d);null!==h&&(m=cm(null!==l?l.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}_getLightNodeById(t){for(const e of this.lightNodes)if(e.isAnalyticLightNode&&e.light.id===t)return e;return null}fromLights(t=[]){const e=[];t=(t=>t.sort(((t,e)=>t.id-e.id)))(t);for(const s of t){let t=this._getLightNodeById(s.id);if(null===t){const e=s.constructor,i=Tv.has(e)?Tv.get(e):vv;t=qp(new i(s))}e.push(t)}return this.lightNodes=e,this._hash=null,this}}const wv=t=>qp((new _v).fromLights(t)),Sv=Yp(_v);function Mv(t,e){if(Tv.has(t))console.warn(`Redefinition of light node ${e.type}`);else{if("function"!=typeof t)throw new Error(`Light ${t.name} is not a class`);if("function"!=typeof e||!e.type)throw new Error(`Light node ${e.type} is not a class`);Tv.set(t,e)}}class Av extends xv{constructor(t=null){super(),this.aoNode=t}setup(t){const e=this.aoNode.x.sub(1).mul(1).add(1);t.context.ambientOcclusion.mulAssign(e)}}ap("AONode",Av);class Nv extends qm{constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._context=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:cm().temp("directDiffuse"),directSpecular:cm().temp("directSpecular"),indirectDiffuse:cm().temp("indirectDiffuse"),indirectSpecular:cm().temp("indirectSpecular")};return{radiance:cm().temp("radiance"),irradiance:cm().temp("irradiance"),iblIrradiance:cm().temp("iblIrradiance"),ambientOcclusion:im(1).temp("ambientOcclusion"),reflectedLight:s,backdrop:t,backdropAlpha:e}}setup(t){return this.context=this._context||(this._context=this.getContext()),this.context.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const Rv=Yp(Nv);vp("lightingContext",Rv),ap("LightingContextNode",Nv);const Cv=t=>t.mul(Xb.w).xyz,Ev=Vm(Cv(Gx.cross(Xb)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),Bv=Vm(Cv(Wx.cross(Yb)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),Iv=Vm(Cv(jx.cross(Jb)),"v_bitangentView").normalize().toVar("bitangentView"),Pv=Vm(Cv(Hx.cross(Zb)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Fv=Cv(qx.cross(Qb)).normalize().toVar("transformedBitangentView"),Uv=Fv.transformDirection(Tx).normalize().toVar("transformedBitangentWorld"),Ov=wm(Jb,Iv,jx),zv=Lb.mul(Ov),Lv=(t,e)=>t.sub(zv.mul(e)),Vv=(()=>{let t=Ag.cross(Lb);return t=t.cross(Ag).normalize(),t=Py(t,qx,Sg.mul(mg.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})();class Dv extends op{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=t.getNodeProperties(this);e.condNode=this.condNode.cache(),e.ifNode=this.ifNode.cache(),e.elseNode=this.elseNode?this.elseNode.cache():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?cg(s).build(t):"";i.nodeProperty=h;const l=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${l} ) {\n\n`).addFlowTab();let u=n.build(t,s);if(u&&(u=a?h+" = "+u+";":"return "+u+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+u+"\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 kv=Yp(Dv);vp("cond",kv),ap("CondNode",Dv);const Gv=im(1),Wv=im(-2),jv=im(.8),Hv=im(-1),qv=im(.4),$v=im(2),Xv=im(.305),Yv=im(3),Jv=im(.21),Zv=im(4),Qv=im(4),Kv=im(16),tT=Zp((([t])=>{const e=cm(iy(t)).toVar(),s=im(-1).toVar();return tm(e.x.greaterThan(e.z),(()=>{tm(e.x.greaterThan(e.y),(()=>{s.assign(kv(t.x.greaterThan(0),0,3))})).else((()=>{s.assign(kv(t.y.greaterThan(0),1,4))}))})).else((()=>{tm(e.z.greaterThan(e.y),(()=>{s.assign(kv(t.z.greaterThan(0),2,5))})).else((()=>{s.assign(kv(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),eT=Zp((([t,e])=>{const s=am().toVar();return tm(e.equal(0),(()=>{s.assign(am(t.z,t.y).div(iy(t.x)))})).elseif(e.equal(1),(()=>{s.assign(am(t.x.negate(),t.z.negate()).div(iy(t.y)))})).elseif(e.equal(2),(()=>{s.assign(am(t.x.negate(),t.y).div(iy(t.z)))})).elseif(e.equal(3),(()=>{s.assign(am(t.z.negate(),t.y).div(iy(t.x)))})).elseif(e.equal(4),(()=>{s.assign(am(t.x.negate(),t.z).div(iy(t.y)))})).else((()=>{s.assign(am(t.x,t.y).div(iy(t.z)))})),df(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),sT=Zp((([t])=>{const e=im(0).toVar();return tm(t.greaterThanEqual(jv),(()=>{e.assign(Gv.sub(t).mul(Hv.sub(Wv)).div(Gv.sub(jv)).add(Wv))})).elseif(t.greaterThanEqual(qv),(()=>{e.assign(jv.sub(t).mul($v.sub(Hv)).div(jv.sub(qv)).add(Hv))})).elseif(t.greaterThanEqual(Xv),(()=>{e.assign(qv.sub(t).mul(Yv.sub($v)).div(qv.sub(Xv)).add($v))})).elseif(t.greaterThanEqual(Jv),(()=>{e.assign(Xv.sub(t).mul(Zv.sub(Yv)).div(Xv.sub(Jv)).add(Yv))})).else((()=>{e.assign(im(-2).mul(jf(df(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),iT=Zp((([t,e])=>{const s=t.toVar();s.assign(df(2,s).sub(1));const i=cm(s,1).toVar();return tm(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"}]}),rT=Zp((([t,e,s,i,r,n])=>{const o=im(s),a=cm(e),h=Fy(sT(o),Wv,n),l=Jf(h),u=$f(h),c=cm(nT(t,a,u,i,r,n)).toVar();return tm(l.notEqual(0),(()=>{const e=cm(nT(t,a,u.add(1),i,r,n)).toVar();c.assign(Py(c,e,l))})),c})),nT=Zp((([t,e,s,i,r,n])=>{const o=im(s).toVar(),a=cm(e),h=im(tT(a)).toVar(),l=im(xy(Qv.sub(o),0)).toVar();o.assign(xy(o,Qv));const u=im(Gf(o)).toVar(),c=am(eT(a,h).mul(u.sub(2)).add(1)).toVar();return tm(h.greaterThan(2),(()=>{c.y.addAssign(u),h.subAssign(3)})),c.x.addAssign(h.mul(u)),c.x.addAssign(l.mul(df(3,Kv))),c.y.addAssign(df(4,Gf(n).sub(u))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(am(),am())})),oT=Zp((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=Qf(i),l=s.mul(h).add(r.cross(s).mul(Zf(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return nT(t,l,e,n,o,a)})),aT=Zp((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c})=>{const d=cm(kv(e,s,My(s,i))).toVar();tm(Of(d.equals(cm(0))),(()=>{d.assign(cm(i.z,0,i.x.negate()))})),d.assign(Yf(d));const p=cm().toVar();return p.addAssign(r.element(rm(0)).mul(oT({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c}))),ov({start:rm(1),end:t},(({i:t})=>{tm(t.greaterThanEqual(n),(()=>{hv()}));const e=im(o.mul(im(t))).toVar();p.addAssign(r.element(t).mul(oT({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(oT({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c})))})),gm(p,1)}));let hT=null;const lT=new WeakMap;class uT extends lp{constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null,this._texture=ex(null),this._width=nf(0),this._height=nf(0),this._maxMip=nf(0),this.updateBeforeType=Hd.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:function(t){let e=lT.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){if(t.isCubeTexture){if(t.source.data.some((t=>void 0===t)))throw new Error("PMREMNode: Undefined texture in CubeTexture. Use onLoad callback or async loader");e=hT.fromCubemap(t,e)}else{if(void 0===t.image)throw new Error("PMREMNode: Undefined image in Texture. Use onLoad callback or async loader");e=hT.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,lT.set(t,e)}return e.texture}(s),this._pmrem=t,this.updateFromTexture(t))}setup(t){null===hT&&(hT=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===zs&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=cm(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),rT(this._texture,e,i,this._width,this._height,this._maxMip)}}const cT=Yp(uT);ap("PMREMNode",uT);const dT=new WeakMap;class pT extends xv{constructor(t=null){super(),this.envNode=t}setup(t){let e=this.envNode;if(e.isTextureNode){let t=dT.get(e.value);void 0===t&&(t=cT(e.value),dT.set(e.value,t)),e=t}const{material:s}=t,i=s.envMap?cx("envMapIntensity","float",t.material):cx("environmentIntensity","float",t.scene),r=!0===s.useAnisotropy||s.anisotropy>0,n=$m(e,mT(mg,r?Vv:qx)).mul(i),o=$m(e,gT($x)).mul(Math.PI).mul(i),a=Hm(n),h=Hm(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const l=t.context.lightingModel.clearcoatRadiance;if(l){const t=$m(e,mT(yg,Xx)).mul(i),s=Hm(t);l.addAssign(s)}}}const mT=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=Lb.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Tx)),s),getTextureLevel:()=>t}},gT=t=>({getUV:()=>t,getTextureLevel:()=>im(1)});ap("EnvironmentNode",pT);class fT extends xv{constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let yT,xT;ap("IrradianceNode",fT);class bT extends op{constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===bT.VIEWPORT?"vec4":this.scope===bT.COORDINATE?"vec3":"vec2"}getUpdateType(){let t=Hd.NONE;return this.scope!==bT.RESOLUTION&&this.scope!==bT.VIEWPORT||(t=Hd.RENDER),this.updateType=t,t}update({renderer:t}){this.scope===bT.VIEWPORT?t.getViewport(xT):t.getDrawingBufferSize(yT)}setup(){const t=this.scope;let e=null;if(t===bT.RESOLUTION)e=nf(yT||(yT=new Zs));else if(t===bT.VIEWPORT)e=nf(xT||(xT=new vi));else{e=vT.div(TT);let s=e.x,i=e.y;/bottom/i.test(t)&&(i=i.oneMinus()),/right/i.test(t)&&(s=s.oneMinus()),e=am(s,i)}return e}generate(t){if(this.scope===bT.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(TT).outputNode.build(t);e=`${t.getType("vec3")}( ${e}.x, ${s}.y - ${e}.y, ${e}.z )`}return e}return super.generate(t)}}bT.COORDINATE="coordinate",bT.RESOLUTION="resolution",bT.VIEWPORT="viewport",bT.TOP_LEFT="topLeft",bT.BOTTOM_LEFT="bottomLeft",bT.TOP_RIGHT="topRight",bT.BOTTOM_RIGHT="bottomRight";const vT=Jp(bT,bT.COORDINATE),TT=Jp(bT,bT.RESOLUTION),_T=Jp(bT,bT.VIEWPORT),wT=Jp(bT,bT.TOP_LEFT),ST=Jp(bT,bT.BOTTOM_LEFT),MT=Jp(bT,bT.TOP_RIGHT),AT=Jp(bT,bT.BOTTOM_RIGHT);ap("ViewportNode",bT);const NT=new Zs;class RT extends tx{constructor(t=wT,e=null,s=null){null===s&&((s=new qa).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Hd.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(NT);const s=this.value;s.image.width===NT.width&&s.image.height===NT.height||(s.image.width=NT.width,s.image.height=NT.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 CT=Yp(RT),ET=Yp(RT,null,null,{generateMipmaps:!0});vp("viewportTexture",CT),vp("viewportMipTexture",ET),ap("ViewportTextureNode",RT);let BT=null;class IT extends RT{constructor(t=wT,e=null){null===BT&&(BT=new Za),super(t,e,BT)}}const PT=Yp(IT);vp("viewportDepthTexture",PT),ap("ViewportDepthTextureNode",IT);class FT extends op{constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===FT.DEPTH?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===FT.DEPTH)i=null!==s?VT().assign(s):t.isPerspectiveCamera?zT(zb.z,fx,yx):UT(zb.z,fx,yx);else if(e===FT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=LT(s,fx,yx);i=UT(t,fx,yx)}else i=s;else i=UT(zb.z,fx,yx);return i}}const UT=(t,e,s)=>t.add(e).div(e.sub(s)),OT=(t,e,s)=>e.sub(s).mul(t).sub(e),zT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),LT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s));FT.DEPTH="depth",FT.LINEAR_DEPTH="linearDepth";const VT=Yp(FT,FT.DEPTH),DT=Jp(FT,FT.DEPTH),kT=Yp(FT,FT.LINEAR_DEPTH),GT=kT(PT());DT.assign=t=>VT(t),ap("ViewportDepthNode",FT);class WT extends op{constructor(t=WT.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===WT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return Zp((()=>{const i=hx(t),r=cg("float","distanceToPlane"),n=cg("float","distanceToGradient"),o=cg("float","clipOpacity");let a;if(o.assign(1),ov(s,(({i:t})=>{a=i.element(t),r.assign(zb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(zy(n.negate(),n,r)),o.equal(0).discard()})),s<e){const t=cg("float","unionclipOpacity");t.assign(1),ov({start:s,end:e},(({i:e})=>{a=i.element(e),r.assign(zb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(zy(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}pg.a.mulAssign(o),pg.a.equal(0).discard()}))()}setupDefault(t,e,s){return Zp((()=>{const i=hx(t);let r;if(ov(s,(({i:t})=>{r=i.element(t),zb.dot(r.xyz).greaterThan(r.w).discard()})),s<e){const t=cg("bool","clipped");t.assign(!0),ov({start:s,end:e},(({i:e})=>{r=i.element(e),t.assign(zb.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}WT.ALPHA_TO_COVERAGE="alphaToCoverage",WT.DEFAULT="default";class jT extends op{constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===zs&&s.side===d?"false":t.getFrontFacing()}}const HT=Jp(jT),qT=im(HT).mul(2).sub(1);ap("FrontFacingNode",jT);const $T=new Map;class XT extends Jr{constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!0,this.normals=!0,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+Zd(this)}build(t){this.setup(t)}setup(t){let e;t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),t.addFlow("vertex",t.removeStack()),t.addStack();const s=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){!0===this.normals&&this.setupNormal(t),this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==s&&t.stack.add(s);const r=gm(i,pg.a).max(0);e=this.setupOutput(t,r),Eg.assign(e),null!==this.outputNode&&(e=this.outputNode)}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=gm(s)),e=this.setupOutput(t,s)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack())}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:s}=t.clippingContext;let i=null;return(e||s)&&(this.alphaToCoverage?i=qp(new WT(WT.ALPHA_TO_COVERAGE)):t.stack.add(qp(new WT))),i}setupDepth(t){const{renderer:e}=t;let s=this.depthNode;if(null===s&&!0===e.logarithmicDepthBuffer){s=Db().w.add(1).log2().mul(xx).mul(.5)}null!==s&&DT.assign(s).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&pv(e).append(),!0===e.isSkinnedMesh&&rv(e).append(),this.displacementMap){const t=mx("displacementMap","texture"),e=mx("displacementScale","float"),s=mx("displacementBias","float");Fb.addAssign(Wx.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&ev(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&$b(e).append(),null!==this.positionNode&&Fb.assign(this.positionNode);const i=Db();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?gm(this.colorNode):Qx;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=gm(s.xyz.mul(km("color","vec3")),s.a)),t.instanceColor){s=dg("vec3","vInstanceColor").mul(s)}pg.assign(s);const i=this.opacityNode?im(this.opacityNode):eb;if(pg.a.assign(pg.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?im(this.alphaTestNode):Zx;pg.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&pg.a.assign(1)}setupVariants(){}setupNormal(){if(!0===this.flatShading){const t=zb.dFdx().cross(zb.dFdy()).normalize();qx.assign(t.mul(qT))}else{const t=this.normalNode?cm(this.normalNode):lb;qx.assign(t.mul(qT))}}getEnvNode(t){let e=null;return this.envNode?e=this.envNode:this.envMap?e=this.envMap.isCubeTexture?yv(this.envMap):ex(this.envMap):t.environmentNode&&(e=t.environmentNode),e}setupLights(t){const e=this.getEnvNode(t),s=[];if(e&&s.push(new pT(e)),t.material.lightMap&&s.push(new fT(mx("lightMap","texture"))),null!==this.aoNode||t.material.aoMap){const e=null!==this.aoNode?this.aoNode:ex(t.material.aoMap);s.push(new Av(e))}let i=this.lightsNode||t.lightsNode;return s.length>0&&(i=Sv([...i.lightNodes,...s])),i}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=pg.rgb;if(n&&!1!==n.hasLight){const e=this.setupLightingModel(t);o=Rv(n,e,s,i)}else null!==s&&(o=cm(null!==i?Py(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(o=o.add(cm(r||tb))),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=gm(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=Qd(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.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}static fromMaterial(t){if(!0===t.isNodeMaterial)return t;const e=JT(t.type.replace("Material","NodeMaterial"));if(void 0===e)throw new Error(`NodeMaterial: Material "${t.type}" is not compatible.`);for(const s in t)e[s]=t[s];return e}}function YT(t,e){if("function"!=typeof e||!t)throw new Error(`Node material ${t} is not a class`);$T.has(t)?console.warn(`Redefinition of node material ${t}`):($T.set(t,e),e.type=t)}function JT(t){const e=$T.get(t);if(void 0!==e)return new e}YT("NodeMaterial",XT);class ZT{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 QT extends ZT{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class KT extends ZT{constructor(t,e=new Zs){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class t_ extends ZT{constructor(t,e=new Ri){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class e_ extends ZT{constructor(t,e=new vi){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class s_ extends ZT{constructor(t,e=new $r){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class i_ extends ZT{constructor(t,e=new Qs){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class r_ extends ZT{constructor(t,e=new rr){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class n_ extends QT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class o_ extends KT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class a_ extends t_{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class h_ extends e_{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class l_ extends s_{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class u_ extends i_{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class c_ extends r_{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class d_ extends op{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 Hp(e);return this._currentCond=kv(t,s),this.add(this._currentCond)}elseif(t,e){const s=new Hp(e),i=kv(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}else(t){return this._currentCond.elseNode=new Hp(t),this}build(t,...e){const s=Kp();Qp(this);for(const e of this.nodes)e.build(t,"void");return Qp(s),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}}const p_=Yp(d_);ap("StackNode",d_);class m_ extends lp{constructor(t=Ob){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 am(e,s)}}const g_=Yp(m_);ap("EquirectUVNode",m_);class f_ extends to{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 Wn(5,5,5),n=g_(Ob),o=JT("MeshBasicNodeMaterial");o.colorNode=ex(e,n,0),o.side=d,o.blending=m;const a=new kn(r,o),h=new io;h.add(a),e.minFilter===St&&(e.minFilter=Tt);return new Qn(1,10,this).update(t,h),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const y_=[.125,.215,.35,.446,.526,.582],x_=20,b_=new Au(-1,1,1,-1,0,1),v_=new Jn(90,1),T_=new $r;let __=null,w_=0,S_=0;const M_=(1+Math.sqrt(5))/2,A_=1/M_,N_=[new Ri(-M_,A_,0),new Ri(M_,A_,0),new Ri(-A_,0,M_),new Ri(A_,0,M_),new Ri(0,M_,-A_),new Ri(0,M_,A_),new Ri(-1,1,-1),new Ri(1,1,-1),new Ri(-1,1,1),new Ri(1,1,1)],R_=[3,1,5,0,4,2],C_=iT(of(),km("faceIndex")).normalize(),E_=cm(C_.x,C_.y.negate(),C_.z);class B_{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){__=this._renderer.getRenderTarget(),w_=this._renderer.getActiveCubeFace(),S_=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)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=U_(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=O_(),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(__,w_,S_),t.scissorTest=!1,P_(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===ht||t.mapping===lt?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),__=this._renderer.getRenderTarget(),w_=this._renderer.getActiveCubeFace(),S_=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:Ye},i=I_(t,e,s);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=I_(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+y_.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=y_[a-t+4-1]:0===a&&(h=0),i.push(h);const l=1/(o-2),u=-l,c=1+l,d=[u,u,c,u,c,c,u,u,c,c,u,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=R_[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 wn;T.setAttribute("position",new on(x,g)),T.setAttribute("uv",new on(b,f)),T.setAttribute("faceIndex",new on(v,y)),e.push(T),r.push(new kn(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=hx(new Array(x_).fill(0)),r=nf(new Ri(0,1,0)),n=nf(0),o=im(x_),a=nf(0),h=nf(1),l=ex(null),u=nf(0),c=im(1/e),d=im(1/s),p=im(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:E_,dTheta:n,samples:h,envMap:l,mipInt:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=F_();return g.uniforms=m,g.fragmentNode=aT({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}_compileMaterial(t){const e=this._lodMeshes[0];e.material=t,this._renderer.compile(e,b_)}_sceneToCubeUV(t,e,s,i){const r=v_;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(T_),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const t=new Zr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});l=new kn(new Wn,t)}let u=!1;const c=t.background;c?c.isColor&&(l.material.color.copy(c),t.background=null,u=!0):(l.material.color.copy(T_),u=!0),a.setRenderTarget(i),a.clear(),u&&a.render(l,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;P_(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===lt;i?null===this._cubemapMaterial&&(this._cubemapMaterial=U_(t)):null===this._equirectMaterial&&(this._equirectMaterial=O_(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;P_(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,b_)}_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=N_[(i-e-1)%N_.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 l=this._lodMeshes[i];l.material=h;const u=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):x_;m>x_&&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<x_;++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,u.envMap.value=t.texture,u.samples.value=m,u.weights.array=g,u.latitudinal.value="latitudinal"===n?1:0,o&&(u.poleAxis.value=o);const{_lodMax:y}=this;u.dTheta.value=d,u.mipInt.value=y-s;const x=this._sizeLods[i];P_(e,3*x*(i>y-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(l,b_)}}function I_(t,e,s){const i=new Ti(t,e,s);return i.texture.mapping=306,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function P_(t,e,s,i,r){const n=t.height-r-s;t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function F_(){const t=new XT;return t.depthTest=!1,t.depthWrite=!1,t.blending=m,t}function U_(t){const e=F_();return e.fragmentNode=yv(t,E_),e}function O_(t){const e=F_();return e.fragmentNode=ex(t,g_(E_),0),e}let z_=0;class L_{constructor(t="",e=[]){this.name=t,this.bindings=e,this.id=z_++}}const V_=new WeakMap,D_=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),k_=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),G_=t=>(t=Number(t))+(t%1?"":".0");class W_{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.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=p_(),this.stacks=[],this.tab="\t",this.instanceBindGroups=!0,this.currentFunctionNode=null,this.context={keywords:new ag,material:this.material},this.cache=new lg,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null}getBingGroupsCache(){let t=V_.get(this.renderer);return void 0===t&&(t=new vd,V_.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new Ti(t,e,s)}createCubeRenderTarget(t,e){return new f_(t,e)}createPMREMGenerator(){return new B_(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBingGroupsCache(),i=[];let r,n=!0;for(const t of e)if(!0===t.groupNode.shared){const e=t.getNodes();let r=s.get(e);void 0===r&&(s.set(e,t),r=t),i.push(r)}else i.push(t),n=!1;return n?(r=s.get(i),void 0===r&&(r=new L_(t,i),s.set(i,r))):r=new L_(t,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 Yd)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}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!==Hd.NONE&&this.updateNodes.push(t.getSelf()),s!==Hd.NONE&&this.updateBeforeNodes.push(t),i!==Hd.NONE&&this.updateAfterNodes.push(t)}}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}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 lg(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}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 $r:"vec2"===t?e=new Zs:"vec3"===t?e=new Ri:"vec4"===t&&(e=new vi)),"float"===t)return G_(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")}( ${G_(e.r)}, ${G_(e.g)}, ${G_(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 sg(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}needsColorSpaceToLinear(){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=D_.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return k_.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 mn||!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=p_(this.stack),this.stacks.push(Kp()||this.stack),Qp(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,Qp(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 sg("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 ig(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 rg(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 ng(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 og("nodeCode"+n,e),t.push(r),i.code=r}return r}addLineFlowCode(t){return""===t||(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 $g,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout;let s;if(t.isArrayInput){s=[];for(const t of e.inputs)s.push(new Dg(t.type,t.name))}else{s={};for(const t of e.inputs)s[t.name]=new Dg(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 lg,this.stack=p_();for(const s of Xd)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}=this;null!==e?XT.fromMaterial(e).build(this):this.addFlow("compute",t);for(const t of Xd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Yd){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 n_(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new o_(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new a_(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new h_(t);if("color"===e)return new l_(t);if("mat3"===e)return new u_(t);if("mat4"===e)return new c_(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){return JT(t)}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 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 j_{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===Hd.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===Hd.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===Hd.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===Hd.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===Hd.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===Hd.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===Hd.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===Hd.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===Hd.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 H_{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}H_.isNodeFunctionInput=!0;class q_ extends op{constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}ap("StructTypeNode",q_);class $_ extends op{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 q_(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}`)}return s}}const X_=Yp($_);ap("OutputStructNode",$_);class Y_ extends op{constructor(t){super(),this.seedNode=t}setup(){const t=this.seedNode.toUint().mul(747796405).add(2891336453),e=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return e.shiftRight(22).bitXor(e).toFloat().mul(1/2**32)}}const J_=Yp(Y_);vp("hash",J_),ap("HashNode",Y_);const Z_=(t,e)=>Ay(df(4,t.mul(cf(1,t))),e),Q_=(t,e)=>t.lessThan(.5)?Z_(t.mul(2),e).div(2):cf(1,Z_(df(cf(1,t),2),e).div(2)),K_=(t,e,s)=>Ay(pf(Ay(t,e),uf(Ay(t,e),Ay(cf(1,t),s))),1/e),tw=(t,e)=>Zf(Ff.mul(e.mul(t).sub(1))).div(Ff.mul(e.mul(t).sub(1)));vp("parabola",Z_),vp("gain",Q_),vp("pcurve",K_),vp("sinc",tw);const ew=Zp((([t])=>t.fract().sub(.5).abs())),sw=Zp((([t])=>cm(ew(t.z.add(ew(t.y.mul(1)))),ew(t.z.add(ew(t.x.mul(1)))),ew(t.y.add(ew(t.x.mul(1))))))),iw=Zp((([t,e,s])=>{const i=cm(t).toVar(),r=im(1.4).toVar(),n=im(0).toVar(),o=cm(i).toVar();return ov({start:im(0),end:im(3),type:"float",condition:"<="},(()=>{const t=cm(sw(o.mul(2))).toVar();i.addAssign(t.add(s.mul(im(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=im(ew(i.z.add(ew(i.x.add(ew(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n}));let rw;ew.setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),sw.setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),iw.setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class nw extends Dv{constructor(t){rw=rw||Zy("discard"),super(t,rw)}}const ow=Yp(nw),aw=t=>ow(t).append(),hw=()=>Zy("return").append();vp("discard",aw),ap("DiscardNode",nw);class lw extends op{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 uw=Yp(lw),cw=t=>(...e)=>uw(t,...e);ap("FunctionOverloadingNode",lw);class dw extends lp{constructor(){super("vec2")}setup(){const t=cm(Lb.z,0,Lb.x.negate()).normalize(),e=Lb.cross(t);return am(t.dot(qx),e.dot(qx)).mul(.495).add(.5)}}const pw=Jp(dw);ap("MatcapUVNode",dw);class mw extends rf{constructor(t=mw.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=Hd.FRAME}update(t){const e=this.scope,s=this.scale;e===mw.LOCAL?this.value+=t.deltaTime*s:e===mw.DELTA?this.value=t.deltaTime*s:e===mw.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}mw.LOCAL="local",mw.GLOBAL="global",mw.DELTA="delta",mw.FRAME="frame";const gw=(t,e=0)=>qp(new mw(mw.LOCAL,t,e)),fw=(t,e=0)=>qp(new mw(mw.GLOBAL,t,e)),yw=(t,e=0)=>qp(new mw(mw.DELTA,t,e)),xw=Jp(mw,mw.FRAME).toUint();ap("TimerNode",mw);class bw extends op{constructor(t=bw.SINE,e=gw()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=qp(this.timeNode);let s=null;return t===bw.SINE?s=e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):t===bw.SQUARE?s=e.fract().round():t===bw.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===bw.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}bw.SINE="sine",bw.SQUARE="square",bw.TRIANGLE="triangle",bw.SAWTOOTH="sawtooth";const vw=Yp(bw,bw.SINE),Tw=Yp(bw,bw.SQUARE),_w=Yp(bw,bw.TRIANGLE),ww=Yp(bw,bw.SAWTOOTH);ap("OscNode",bw);class Sw extends lp{constructor(t,e){super(),this.scope=t,this.node=e}getNodeType(t){return this.node.getNodeType(t)}setup(){const{scope:t,node:e}=this;let s=null;return t===Sw.DIRECTION_TO_COLOR?s=e.mul(.5).add(.5):t===Sw.COLOR_TO_DIRECTION&&(s=e.mul(2).sub(1)),s}}Sw.DIRECTION_TO_COLOR="directionToColor",Sw.COLOR_TO_DIRECTION="colorToDirection";const Mw=Yp(Sw,Sw.DIRECTION_TO_COLOR),Aw=Yp(Sw,Sw.COLOR_TO_DIRECTION);vp("directionToColor",Mw),vp("colorToDirection",Aw),ap("PackingNode",Sw);class Nw extends op{constructor(t,e,s,i=im(0),r=im(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 Rw=Yp(Nw,null,null,{doClamp:!1}),Cw=Yp(Nw);vp("remap",Rw),vp("remapClamp",Cw),ap("RemapNode",Nw);class Ew extends lp{constructor(t,e,s=am(.5)){super("vec2"),this.uvNode=t,this.rotationNode=e,this.centerNode=s}setup(){const{uvNode:t,rotationNode:e,centerNode:s}=this;return t.sub(s).rotate(e).add(s)}}const Bw=Yp(Ew);vp("rotateUV",Bw),ap("RotateUVNode",Ew);class Iw extends lp{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 bm(t,i,i.negate(),t).mul(s)}{const t=e,i=Nm(gm(1,0,0,0),gm(0,Qf(t.x),Zf(t.x).negate(),0),gm(0,Zf(t.x),Qf(t.x),0),gm(0,0,0,1)),r=Nm(gm(Qf(t.y),0,Zf(t.y),0),gm(0,1,0,0),gm(Zf(t.y).negate(),0,Qf(t.y),0),gm(0,0,0,1)),n=Nm(gm(Qf(t.z),Zf(t.z).negate(),0,0),gm(Zf(t.z),Qf(t.z),0,0),gm(0,0,1,0),gm(0,0,0,1));return i.mul(r).mul(n).mul(gm(s,1)).xyz}}}const Pw=Yp(Iw);vp("rotate",Pw),ap("RotateNode",Iw);class Fw extends op{constructor(t,e=of(),s=im(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(),l=am(o,a);return e.add(l).mul(h)}}const Uw=Yp(Fw);ap("SpriteSheetUVNode",Fw);class Ow extends up{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")&&(this.node.instanceIndex||!0!==this.node.bufferObject||t.setupPBO(this.node)),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(!1===t.isAvailable("storageBuffer")){const{node:e}=this;s=e.instanceIndex||!0!==this.node.bufferObject||!0===i?e.build(t):t.generatePBO(this)}else s=super.generate(t);if(!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}const zw=Yp(Ow);vp("storageElement",zw),ap("StorageArrayElementNode",Ow);class Lw extends op{constructor(t,e=null,s=null,i=im(1),r=Fb,n=Wx){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(cm(1)));const a=r.yz.mul(i),h=r.zx.mul(i),l=r.xy.mul(i),u=t.value,c=null!==e?e.value:u,d=null!==s?s.value:u,p=ex(u,a).mul(o.x),m=ex(c,h).mul(o.y),g=ex(d,l).mul(o.z);return uf(p,m,g)}}const Vw=Yp(Lw),Dw=(...t)=>Vw(...t);vp("triplanarTexture",Dw),ap("TriplanarTexturesNode",Lw);const kw=new ta,Gw=new Ri,Ww=new Ri,jw=new Ri,Hw=new rr,qw=new Ri(0,0,-1),$w=new vi,Xw=new Ri,Yw=new Ri,Jw=new vi,Zw=new Zs,Qw=new Ti,Kw=am(wT.x.oneMinus(),wT.y);let tS=!1;class eS extends tx{constructor(t={}){super(Qw.texture,Kw);const{target:e=new Br,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?Hd.RENDER:Hd.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(Zw),t.setSize(Math.round(Zw.width*s),Math.round(Zw.height*s))}setup(t){return this._updateResolution(Qw,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 Ti(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&&tS)return!1;tS=!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(Zw),this._updateResolution(a,i),Ww.setFromMatrixPosition(n.matrixWorld),jw.setFromMatrixPosition(s.matrixWorld),Hw.extractRotation(n.matrixWorld),Gw.set(0,0,1),Gw.applyMatrix4(Hw),Xw.subVectors(Ww,jw),Xw.dot(Gw)>0)return;Xw.reflect(Gw).negate(),Xw.add(Ww),Hw.extractRotation(s.matrixWorld),qw.set(0,0,-1),qw.applyMatrix4(Hw),qw.add(jw),Yw.subVectors(Ww,qw),Yw.reflect(Gw).negate(),Yw.add(Ww),o.coordinateSystem=s.coordinateSystem,o.position.copy(Xw),o.up.set(0,1,0),o.up.applyMatrix4(Hw),o.up.reflect(Gw),o.lookAt(Yw),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),kw.setFromNormalAndCoplanarPoint(Gw,Ww),kw.applyMatrix4(o.matrixWorldInverse),$w.set(kw.normal.x,kw.normal.y,kw.normal.z,kw.constant);const h=o.projectionMatrix;Jw.x=(Math.sign($w.x)+h.elements[8])/h.elements[0],Jw.y=(Math.sign($w.y)+h.elements[9])/h.elements[5],Jw.z=-1,Jw.w=(1+h.elements[10])/h.elements[14],$w.multiplyScalar(1/$w.dot(Jw));h.elements[2]=$w.x,h.elements[6]=$w.y,h.elements[10]=$w.z-0,h.elements[14]=$w.w,this.value=a.texture,r.visible=!1;const l=i.getRenderTarget();i.setRenderTarget(a),i.render(e,o),i.setRenderTarget(l),r.visible=!0,tS=!1}}const sS=t=>qp(new eS(t)),iS=new Au(-1,1,1,-1,0,1);const rS=new class extends wn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new gn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new gn(e,2))}};class nS extends kn{constructor(t=null){super(rS,t),this.camera=iS}renderAsync(t){return t.renderAsync(this,iS)}render(t){t.render(this,iS)}}const oS=new nS(new XT),aS=new Zs;class hS extends tx{constructor(t,e=null,s=null,i={type:Pt}){const r=new Ti(e,s,i);super(r.texture,of()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this.updateBeforeType=Hd.RENDER}get autoSize(){return null===this.width}setSize(t,e){this.width=t,this.height=e,this.renderTarget.setSize(t,e),this.textureNeedsUpdate=!0}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){const e=t.getSize(aS);this.setSize(e.width,e.height)}oS.material.fragmentNode=this.node;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),oS.render(t),t.setRenderTarget(e)}clone(){const t=new tx(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const lS=(t,...e)=>qp(new hS(qp(t),...e));vp("toTexture",((t,...e)=>t.isTextureNode?t:lS(t,...e))),ap("RTTNode",hS);class uS extends Dm{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 vi(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const cS=(...t)=>qp(new uS(...t));ap("VertexColorNode",uS);class dS extends ux{constructor(t,e,s=null){super(t,e,s),this.renderer=s}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const pS=(t,e,s)=>qp(new dS(t,e,s));ap("RendererReferenceNode",dS);const mS=1/6,gS=t=>df(mS,df(t,df(t,t.negate().add(3)).sub(3)).add(1)),fS=t=>df(mS,df(t,df(t,df(3,t).sub(6))).add(4)),yS=t=>df(mS,df(t,df(t,df(-3,t).add(3)).add(3)).add(1)),xS=t=>df(mS,Ay(t,3)),bS=t=>gS(t).add(fS(t)),vS=t=>yS(t).add(xS(t)),TS=t=>uf(-1,fS(t).div(gS(t).add(fS(t)))),_S=t=>uf(1,xS(t).div(yS(t).add(xS(t)))),wS=(t,e,s)=>{const i=t.uvNode,r=df(i,e.zw).add(.5),n=$f(r),o=Jf(r),a=bS(o.x),h=vS(o.x),l=TS(o.x),u=_S(o.x),c=TS(o.y),d=_S(o.y),p=am(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),m=am(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),g=am(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),f=am(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),y=bS(o.y).mul(uf(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=vS(o.y).mul(uf(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)};class SS extends lp{constructor(t,e=im(3)){super("vec4"),this.textureNode=t,this.blurNode=e}setup(){return((t,e)=>{const s=am(t.size(rm(e))),i=am(t.size(rm(e.add(1)))),r=pf(1,s),n=pf(1,i),o=wS(t,gm(r,s),$f(e)),a=wS(t,gm(n,i),Xf(e));return Jf(e).mix(o,a)})(this.textureNode,this.blurNode)}}const MS=Yp(SS);vp("bicubic",MS),ap("TextureBicubicNode",SS);class AS extends op{constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const NS=Jp(AS);ap("PointUVNode",AS);class RS extends op{constructor(t=RS.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===RS.BACKGROUND_BLURRINESS?i=cx("backgroundBlurriness","float",s):e===RS.BACKGROUND_INTENSITY?i=cx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}RS.BACKGROUND_BLURRINESS="backgroundBlurriness",RS.BACKGROUND_INTENSITY="backgroundIntensity";const CS=Jp(RS,RS.BACKGROUND_BLURRINESS),ES=Jp(RS,RS.BACKGROUND_INTENSITY);ap("SceneNode",RS);const BS="point-list",IS="line-list",PS="line-strip",FS="triangle-list",US="triangle-strip",OS="never",zS="less",LS="equal",VS="less-equal",DS="greater",kS="not-equal",GS="greater-equal",WS="always",jS="store",HS="load",qS="clear",$S="ccw",XS="none",YS="front",JS="back",ZS="uint16",QS="uint32",KS={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"},tM="clamp-to-edge",eM="repeat",sM="mirror-repeat",iM="linear",rM="nearest",nM="zero",oM="one",aM="src",hM="one-minus-src",lM="src-alpha",uM="one-minus-src-alpha",cM="dst",dM="one-minus-dst",pM="dst-alpha",mM="one-minus-dst-alpha",gM="src-alpha-saturated",fM="constant",yM="one-minus-constant",xM="add",bM="subtract",vM="reverse-subtract",TM="min",_M="max",wM=0,SM=15,MM="keep",AM="zero",NM="replace",RM="invert",CM="increment-clamp",EM="decrement-clamp",BM="increment-wrap",IM="decrement-wrap",PM="storage",FM="read-only-storage",UM="write-only",OM="read-only",zM="unfilterable-float",LM="depth",VM="sint",DM="uint",kM="2d",GM="3d",WM="2d",jM="2d-array",HM="cube",qM="3d",$M="all",XM="vertex",YM="instance",JM={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"};class ZM extends rx{constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=PM,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 zw(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(FM)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const e=this.getNodeType(t);null===this._attribute&&(this._attribute=Gb(this.value),this._varying=Vm(this._attribute));const s=this._varying.build(t,e);return t.registerTransform(s,this._attribute),s}}const QM=(t,e,s)=>qp(new ZM(t,e,s)),KM=(t,e,s)=>qp(new ZM(t,e,s).setBufferObject(!0));ap("StorageBufferNode",ZM);class tA extends tx{constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=UM}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(OM)}toWriteOnly(){return this.setAccess(UM)}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)}}const eA=Yp(tA),sA=(t,e,s)=>{const i=eA(t,e,s);return null!==s&&i.append(),i};ap("StorageTextureNode",tA);const iA=Zp((({texture:t,uv:e})=>{const s=1e-4,i=cm().temp();return tm(e.x.lessThan(s),(()=>{i.assign(cm(1,0,0))})).elseif(e.y.lessThan(s),(()=>{i.assign(cm(0,1,0))})).elseif(e.z.lessThan(s),(()=>{i.assign(cm(0,0,1))})).elseif(e.x.greaterThan(.9999),(()=>{i.assign(cm(-1,0,0))})).elseif(e.y.greaterThan(.9999),(()=>{i.assign(cm(0,-1,0))})).elseif(e.z.greaterThan(.9999),(()=>{i.assign(cm(0,0,-1))})).else((()=>{const s=.01,r=t.uv(e.add(cm(-.01,0,0))).r.sub(t.uv(e.add(cm(s,0,0))).r),n=t.uv(e.add(cm(0,-.01,0))).r.sub(t.uv(e.add(cm(0,s,0))).r),o=t.uv(e.add(cm(0,0,-.01))).r.sub(t.uv(e.add(cm(0,0,s))).r);i.assign(cm(r,n,o))})),i.normalize()}));class rA extends tx{constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return cm(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return iA({texture:this,uv:t})}}const nA=Yp(rA);ap("Texture3DNode",rA);class oA extends ux{constructor(t,e,s=null){super(t,e,s),this.userData=s}update(t){this.reference=null!==this.userData?this.userData:t.object.userData,super.update(t)}}const aA=(t,e,s)=>qp(new oA(t,e,s));ap("UserDataNode",oA);const hA=Zp((({base:t,blend:e})=>{const s=s=>e[s].lessThan(If).cond(e[s],t[s].oneMinus().div(e[s]).oneMinus().max(0));return cm(s("x"),s("y"),s("z"))})).setLayout({name:"burnColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),lA=Zp((({base:t,blend:e})=>{const s=s=>e[s].equal(1).cond(e[s],t[s].div(e[s].oneMinus()).max(0));return cm(s("x"),s("y"),s("z"))})).setLayout({name:"dodgeColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),uA=Zp((({base:t,blend:e})=>{const s=s=>t[s].oneMinus().mul(e[s].oneMinus()).oneMinus();return cm(s("x"),s("y"),s("z"))})).setLayout({name:"screenColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),cA=Zp((({base:t,blend:e})=>{const s=s=>t[s].lessThan(.5).cond(t[s].mul(e[s],2),t[s].oneMinus().mul(e[s].oneMinus()).oneMinus());return cm(s("x"),s("y"),s("z"))})).setLayout({name:"overlayColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]});class dA extends lp{constructor(t,e,s){super(),this.blendMode=t,this.baseNode=e,this.blendNode=s}setup(){const{blendMode:t,baseNode:e,blendNode:s}=this,i={base:e,blend:s};let r=null;return t===dA.BURN?r=hA(i):t===dA.DODGE?r=lA(i):t===dA.SCREEN?r=uA(i):t===dA.OVERLAY&&(r=cA(i)),r}}dA.BURN="burn",dA.DODGE="dodge",dA.SCREEN="screen",dA.OVERLAY="overlay";const pA=Yp(dA,dA.BURN),mA=Yp(dA,dA.DODGE),gA=Yp(dA,dA.OVERLAY),fA=Yp(dA,dA.SCREEN);vp("burn",pA),vp("dodge",mA),vp("overlay",gA),vp("screen",fA),ap("BlendModeNode",dA);const yA=Zp((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||of()),forceUVContext:!0}),i=im(s((t=>t)));return am(im(s((t=>t.add(t.dFdx())))).sub(i),im(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),xA=Zp((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(qT),l=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(l).normalize()}));class bA extends lp{constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=yA({textureNode:this.textureNode,bumpScale:t});return xA({surf_pos:zb,surf_norm:jx,dHdxy:e})}}const vA=Yp(bA);vp("bumpMap",vA),ap("BumpMapNode",bA);const TA=Zp((({color:t,adjustment:e})=>e.mix(CA(t.rgb),t.rgb))),_A=Zp((({color:t,adjustment:e})=>{const s=uf(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 Py(t.rgb,i,r)})),wA=Zp((({color:t,adjustment:e})=>{const s=cm(.57735,.57735,.57735),i=e.cos();return cm(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(Sy(s,t.rgb).mul(i.oneMinus())))))}));class SA extends lp{constructor(t,e,s=im(1)){super("vec3"),this.method=t,this.colorNode=e,this.adjustmentNode=s}setup(){const{method:t,colorNode:e,adjustmentNode:s}=this,i={color:e,adjustment:s};let r=null;return t===SA.SATURATION?r=TA(i):t===SA.VIBRANCE?r=_A(i):t===SA.HUE?r=wA(i):console.error(`${this.type}: Method "${this.method}" not supported!`),r}}SA.SATURATION="saturation",SA.VIBRANCE="vibrance",SA.HUE="hue";const MA=Yp(SA,SA.SATURATION),AA=Yp(SA,SA.VIBRANCE),NA=Yp(SA,SA.HUE),RA=cm(.2125,.7154,.0721),CA=(t,e=RA)=>Sy(t,e),EA=(t,e)=>Py(cm(0),t,CA(t).sub(e).max(0));vp("saturation",MA),vp("vibrance",AA),vp("hue",NA),vp("threshold",EA),ap("ColorAdjustmentNode",SA);const BA=Zp((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(),l=s,u=o.cross(l),c=l.cross(n),d=u.mul(a.x).add(c.mul(h.x)),p=u.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=qT.mul(m.inverseSqrt());return uf(d.mul(i.x,g),p.mul(i.y,g),l.mul(i.z)).normalize()}));class IA extends lp{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=cm(i.xy.mul(s),i.z));let r=null;if(1===e)r=Ox.mul(i).normalize();else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?Ov.mul(i).normalize():BA({eye_pos:zb,surf_norm:jx,mapN:i,uv:of()})}return r}}const PA=Yp(IA);vp("normalMap",PA),ap("NormalMapNode",IA);class FA extends lp{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 UA=Yp(FA);vp("posterize",UA),ap("PosterizeNode",FA);const OA=Zp((({color:t,exposure:e})=>t.mul(e).clamp())),zA=Zp((({color:t,exposure:e})=>(t=t.mul(e)).div(t.add(1)).clamp())),LA=Zp((({color:t,exposure: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)})),VA=Zp((({color: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)})),DA=Zp((({color:t,exposure:e})=>{const s=wm(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=wm(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=VA({color:t}),(t=i.mul(t)).clamp()})),kA=wm(cm(1.6605,-.1246,-.0182),cm(-.5876,1.1329,-.1006),cm(-.0728,-.0083,1.1187)),GA=wm(cm(.6274,.0691,.0164),cm(.3293,.9195,.088),cm(.0433,.0113,.8956)),WA=Zp((([t])=>{const e=cm(t).toVar(),s=cm(e.mul(e)).toVar(),i=cm(s.mul(s)).toVar();return im(15.5).mul(i.mul(s)).sub(df(40.14,i.mul(e))).add(df(31.96,i).sub(df(6.868,s.mul(e))).add(df(.4298,s).add(df(.1191,e).sub(.00232))))})),jA=Zp((({color:t,exposure:e})=>{const s=cm(t).toVar(),i=wm(cm(.856627153315983,.137318972929847,.11189821299995),cm(.0951212405381588,.761241990602591,.0767994186031903),cm(.0482516061458583,.101439036467562,.811302368396859)),r=wm(cm(1.1271005818144368,-.1413297634984383,-.14132976349843826),cm(-.11060664309660323,1.157823702216272,-.11060664309660294),cm(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=im(-12.47393),o=im(4.026069);return s.mulAssign(e),s.assign(GA.mul(s)),s.assign(i.mul(s)),s.assign(xy(s,1e-10)),s.assign(jf(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(Fy(s,0,1)),s.assign(WA(s)),s.assign(r.mul(s)),s.assign(Ay(xy(cm(0),s),cm(2.2))),s.assign(kA.mul(s)),s.assign(Fy(s,0,1)),s})),HA=Zp((({color:t,exposure:e})=>{const s=im(.76),i=im(.15);t=t.mul(e);const r=yy(t.r,yy(t.g,t.b)),n=kv(r.lessThan(.08),r.sub(df(6.25,r.mul(r))),.04);t.subAssign(n);const o=xy(t.r,xy(t.g,t.b));tm(o.lessThan(s),(()=>t));const a=cf(1,s),h=cf(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const l=cf(1,pf(1,i.mul(o.sub(h)).add(1)));return Py(t,cm(h),l)})).setLayout({name:"NeutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qA={1:OA,2:zA,3:LA,4:DA,6:jA,7:HA};class $A extends lp{constructor(t=0,e=YA,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){let t=super.getCacheKey();return t="{toneMapping:"+this.toneMapping+",nodes:"+t+"}",t}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;const i={exposure:this.exposureNode,color:e},r=qA[s];let n=null;return r?n=r(i):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const XA=(t,e,s)=>qp(new $A(t,qp(e),qp(s))),YA=pS("toneMappingExposure","float");vp("toneMapping",((t,e,s)=>XA(e,s,t))),ap("ToneMappingNode",$A);let JA=null;class ZA extends RT{constructor(t=wT,e=null){null===JA&&(JA=new qa),super(t,e,JA)}updateReference(){return this}}const QA=Yp(ZA);vp("viewportSharedTexture",QA),ap("ViewportSharedTextureNode",ZA);const KA=new Zs;class tN extends tx{constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class eN extends lp{constructor(t,e,s){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this._pixelRatio=1,this._width=1,this._height=1;const i=new Za;i.isRenderTargetTexture=!0,i.name="PostProcessingDepth";const r=new Ti(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt});r.texture.name="PostProcessing",r.depthTexture=i,this.renderTarget=r,this.updateBeforeType=Hd.FRAME,this._textureNode=qp(new tN(this,r.texture)),this._depthTextureNode=qp(new tN(this,i)),this._linearDepthNode=null,this._viewZNode=null,this._cameraNear=nf(0),this._cameraFar=nf(0),this.isPassNode=!0}isGlobal(){return!0}getTextureNode(){return this._textureNode}getTextureDepthNode(){return this._depthTextureNode}getViewZNode(){if(null===this._viewZNode){const t=this._cameraNear,e=this._cameraFar;this._viewZNode=LT(this._depthTextureNode,t,e)}return this._viewZNode}getLinearDepthNode(){if(null===this._linearDepthNode){const t=this._cameraNear,e=this._cameraFar;this._linearDepthNode=UT(this.getViewZNode(),t,e)}return this._linearDepthNode}setup(){return this.scope===eN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize(KA);this.setSize(r.width,r.height);const n=e.toneMapping,o=e.toneMappingNode,a=e.getRenderTarget();this._cameraNear.value=i.near,this._cameraFar.value=i.far,e.toneMapping=0,e.toneMappingNode=null,e.setRenderTarget(this.renderTarget),e.render(s,i),e.toneMapping=n,e.toneMappingNode=o,e.setRenderTarget(a)}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()}}eN.COLOR="color",eN.DEPTH="depth";const sN=(t,e)=>qp(new eN(eN.COLOR,t,e)),iN=(t,e)=>qp(new tN(t,e)),rN=(t,e)=>qp(new eN(eN.DEPTH,t,e));ap("PassNode",eN);const nN=new nS,oN=new nS;class aN extends lp{constructor(t,e=null,s=2){super("vec4"),this.textureNode=t,this.directionNode=e,this.sigma=s,this._invSize=nf(new Zs),this._passDirection=nf(new Zs),this._horizontalRT=new Ti,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new Ti,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=iN(this,this._verticalRT.texture),this.updateBeforeType=Hd.RENDER,this.resolution=new Zs(1,1)}setSize(t,e){t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._invSize.value.set(1/t,1/e),this._horizontalRT.setSize(t,e),this._verticalRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value,r=e.getRenderTarget(),n=s.value;nN.material=this._material,oN.material=this._material,this.setSize(i.image.width,i.image.height);const o=i.type;this._horizontalRT.texture.type=o,this._verticalRT.texture.type=o,e.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),nN.render(e),s.value=this._horizontalRT.texture,e.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),oN.render(e),e.setRenderTarget(r),s.value=n}getTextureNode(){return this._textureNode}setup(t){const e=this.textureNode;if(!0!==e.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),gm();const s=e.uvNode||of(),i=am(this.directionNode||1),r=t=>e.uv(t),n=Zp((()=>{const t=3+2*this.sigma,e=this._getCoefficients(t),n=this._invSize,o=i.mul(this._passDirection),a=im(e[0]).toVar(),h=gm(r(s).mul(a)).toVar();for(let i=1;i<t;i++){const t=im(i),l=im(e[i]),u=am(o.mul(n.mul(t))).toVar(),c=gm(r(s.add(u))),d=gm(r(s.sub(u)));h.addAssign(c.add(d).mul(l)),a.addAssign(df(2,l))}return h.div(a)}));(this._material||(this._material=t.createNodeMaterial())).fragmentNode=n();return t.getNodeProperties(this).textureNode=e,this._textureNode}_getCoefficients(t){const e=[];for(let s=0;s<t;s++)e.push(.39894*Math.exp(-.5*s*s/(t*t))/t);return e}}const hN=(t,e,s)=>qp(new aN(qp(t).toTexture(),e,s));vp("gaussianBlur",hN);const lN=new Zs,uN=new nS;class cN extends lp{constructor(t,e=.96){super(t),this.textureNode=t,this.textureNodeOld=ex(),this.damp=nf(e),this._compRT=new Ti,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new Ti,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=iN(this,this._compRT.texture),this.updateBeforeType=Hd.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._compRT.setSize(t,e),this._oldRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,e.getDrawingBufferSize(lN),this.setSize(lN.x,lN.y);const r=e.toneMapping,n=e.toneMappingNode,o=e.getRenderTarget(),a=s.value;this.textureNodeOld.value=this._oldRT.texture,e.toneMapping=0,e.toneMappingNode=null,e.setRenderTarget(this._compRT),uN.render(e);const h=this._oldRT;this._oldRT=this._compRT,this._compRT=h,e.toneMapping=r,e.toneMappingNode=n,e.setRenderTarget(o),s.value=a}setup(t){const e=this.textureNode,s=this.textureNodeOld,i=e.uvNode||of();s.uvNode=i;const r=Zp((([t,e])=>{const s=im(e).toVar(),i=gm(t).toVar();return xy(ry(i.sub(s)),0)})),n=Zp((()=>{const t=gm(s),n=gm((t=>e.uv(t))(i));return t.mulAssign(this.damp.mul(r(t,.1))),xy(n,t)})),o=this._materialComposed||(this._materialComposed=t.createNodeMaterial());o.fragmentNode=n(),uN.material=o;return t.getNodeProperties(this).textureNode=e,this._textureNode}}const dN=(t,e)=>qp(new cN(qp(t).toTexture(),e));vp("afterImage",dN);const pN=new nS;class mN extends lp{constructor(t,e,s,i){super("vec4"),this.textureNode=t,this.tresholdNode=e,this.scaleNode=s,this.colorNode=cm(.1,0,1),this.samples=i,this.resolution=new Zs(1,1),this._renderTarget=new Ti,this._renderTarget.texture.name="anamorphic",this._invSize=nf(new Zs),this._textureNode=iN(this,this._renderTarget.texture),this.updateBeforeType=Hd.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._invSize.value.set(1/t,1/e),t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._renderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value;this._renderTarget.texture.type=i.type;const r=e.getRenderTarget(),n=s.value;pN.material=this._material,this.setSize(i.image.width,i.image.height),e.setRenderTarget(this._renderTarget),pN.render(e),e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=e.uvNode||of(),i=Zp((()=>{const t=this.samples,i=Math.floor(t/2),r=cm(0).toVar();return ov({start:-i,end:i},(({i:t})=>{const n=im(t).abs().div(i).oneMinus(),o=(t=>e.uv(t))(am(s.x.add(this._invSize.x.mul(t).mul(this.scaleNode)),s.y)),a=EA(o,this.tresholdNode).mul(n);r.addAssign(a)})),r.mul(this.colorNode)}));(this._material||(this._material=t.createNodeMaterial())).fragmentNode=i();return t.getNodeProperties(this).textureNode=e,this._textureNode}}const gN=(t,e=.9,s=3,i=32)=>qp(new mN(qp(t).toTexture(),qp(e),qp(s),i));vp("anamorphic",gN);class fN extends lp{constructor(t){super(),this.textureNode=t,this.updateBeforeType=Hd.RENDER,this._invSize=nf(new Zs)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const{textureNode:t}=this,e=t.uvNode||of(),s=e=>t.uv(e);return Zp((()=>{const t=this._invSize,i=wm(-1,-2,-1,0,0,0,1,2,1),r=wm(-1,0,1,-2,0,2,-1,0,1),n=CA(s(e.add(t.mul(am(-1,-1)))).xyz),o=CA(s(e.add(t.mul(am(-1,0)))).xyz),a=CA(s(e.add(t.mul(am(-1,1)))).xyz),h=CA(s(e.add(t.mul(am(0,-1)))).xyz),l=CA(s(e.add(t.mul(am(0,0)))).xyz),u=CA(s(e.add(t.mul(am(0,1)))).xyz),c=CA(s(e.add(t.mul(am(1,-1)))).xyz),d=CA(s(e.add(t.mul(am(1,0)))).xyz),p=CA(s(e.add(t.mul(am(1,1)))).xyz),m=uf(i[0][0].mul(n),i[1][0].mul(h),i[2][0].mul(c),i[0][1].mul(o),i[1][1].mul(l),i[2][1].mul(d),i[0][2].mul(a),i[1][2].mul(u),i[2][2].mul(p)),g=uf(r[0][0].mul(n),r[1][0].mul(h),r[2][0].mul(c),r[0][1].mul(o),r[1][1].mul(l),r[2][1].mul(d),r[0][2].mul(a),r[1][2].mul(u),r[2][2].mul(p)),f=m.mul(m).add(g.mul(g)).sqrt();return gm(cm(f),1)}))()}}const yN=t=>qp(new fN(qp(t).toTexture()));vp("sobel",yN);class xN extends lp{constructor(t,e,s,i,r){super(),this.textureNode=t,this.viewZNode=e,this.focusNode=s,this.apertureNode=i,this.maxblurNode=r,this._aspect=nf(0),this.updateBeforeType=Hd.RENDER}updateBefore(){const t=this.textureNode.value;this._aspect.value=t.image.width/t.image.height}setup(){const t=this.textureNode,e=t.uvNode||of(),s=e=>t.uv(e);return Zp((()=>{const t=am(1,this._aspect),i=this.focusNode.add(this.viewZNode),r=am(Fy(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),n=r.mul(.9),o=r.mul(.7),a=r.mul(.4);let h=gm(0);return h=h.add(s(e)),h=h.add(s(e.add(am(0,.4).mul(t).mul(r)))),h=h.add(s(e.add(am(.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(am(.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(am(-.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(am(.4,0).mul(t).mul(r)))),h=h.add(s(e.add(am(.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(am(.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(am(-.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(am(0,-.4).mul(t).mul(r)))),h=h.add(s(e.add(am(-.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(am(-.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(am(.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(am(-.4,0).mul(t).mul(r)))),h=h.add(s(e.add(am(-.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(am(-.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(am(.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(am(.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(am(-.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(am(.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(am(-.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(am(-.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(am(.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(am(-.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(am(.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(am(.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(am(.4,0).mul(t).mul(o)))),h=h.add(s(e.add(am(.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(am(0,-.4).mul(t).mul(o)))),h=h.add(s(e.add(am(-.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(am(-.4,0).mul(t).mul(o)))),h=h.add(s(e.add(am(-.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(am(0,.4).mul(t).mul(o)))),h=h.add(s(e.add(am(.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(am(.4,0).mul(t).mul(a)))),h=h.add(s(e.add(am(.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(am(0,-.4).mul(t).mul(a)))),h=h.add(s(e.add(am(-.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(am(-.4,0).mul(t).mul(a)))),h=h.add(s(e.add(am(-.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(am(0,.4).mul(t).mul(a)))),h=h.div(41),h.a=1,gm(h)}))()}}const bN=(t,e,s=1,i=.025,r=1)=>qp(new xN(qp(t).toTexture(),qp(e),qp(s),qp(i),qp(r)));vp("dof",bN);class vN extends lp{constructor(t,e=new Zs(.5,.5),s=1.57,i=1){super("vec4"),this.inputNode=t,this.center=nf(e),this.angle=nf(s),this.scale=nf(i),this._size=nf(new Zs),this.updateBeforeType=Hd.RENDER}updateBefore(){const t=this.inputNode.value;this._size.value.set(t.image.width,t.image.height)}setup(){const t=this.inputNode,e=Zp((()=>{const t=Zf(this.angle),e=Qf(this.angle),s=of().mul(this._size).sub(this.center),i=am(e.mul(s.x).sub(t.mul(s.y)),t.mul(s.x).add(e.mul(s.y))).mul(this.scale);return Zf(i.x).mul(Zf(i.y)).mul(4)})),s=Zp((()=>{const s=t,i=uf(s.r,s.g,s.b).div(3);return gm(cm(i.mul(10).sub(5).add(e())),s.a)}));return s()}}const TN=(t,e,s,i)=>qp(new vN(qp(t),e,s,i));vp("dotScreen",TN);class _N extends lp{constructor(t,e=.005,s=0){super("vec4"),this.textureNode=t,this.amount=nf(e),this.angle=nf(s)}setup(){const{textureNode:t}=this,e=t.uvNode||of(),s=e=>t.uv(e);return Zp((()=>{const t=am(Qf(this.angle),Zf(this.angle)).mul(this.amount),i=s(e.add(t)),r=s(e),n=s(e.sub(t));return gm(i.r,r.g,n.b,r.a)}))()}}const wN=(t,e,s)=>qp(new _N(qp(t).toTexture(),e,s));vp("rgbShift",wN);class SN extends lp{constructor(t,e=null,s=null){super(),this.inputNode=t,this.intensityNode=e,this.uvNode=s}setup(){const t=this.uvNode||of(),e=Zp((()=>{const e=this.inputNode.rgb,s=Vy(Jf(t.add(gw())));let i=e.add(e.mul(Fy(s.add(.1),0,1)));return null!==this.intensityNode&&(i=Py(e,i,this.intensityNode)),gm(i,this.inputNode.a)}));return e()}}const MN=Yp(SN);vp("film",MN);class AN extends lp{constructor(t,e,s,i){super(),this.inputNode=t,this.lutNode=e,this.size=nf(s),this.intensityNode=i}setup(){const{inputNode:t,lutNode:e}=this,s=Zp((()=>{const s=t,i=im(1).div(this.size),r=im(.5).div(this.size),n=cm(r).add(s.rgb.mul(im(1).sub(i))),o=gm((t=>e.uv(t))(n).rgb,s.a);return gm(Py(s,o,this.intensityNode))}));return s()}}const NN=(t,e,s,i)=>qp(new AN(qp(t),qp(e),s,qp(i)));vp("lut3D",NN);class RN extends lp{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;if(Array.isArray(r))for(let s=0;s<r.length;s++){const n=i[s],o=r[s];e.push(o.build(t,n.type))}else for(const s of i){const i=r[s.name];if(void 0===i)throw new Error(`FunctionCallNode: Input '${s.name}' not found in FunctionNode.`);e.push(i.build(t,s.type))}return`${s.build(t,"property")}( ${e.join(", ")} )`}}const CN=(t,...e)=>(e=e.length>1||e[0]&&!0===e[0].isNode?Xp(e):$p(e[0]),qp(new RN(qp(t),e)));vp("call",CN),ap("FunctionCallNode",RN);class EN extends op{constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new Vs,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:im()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=ep(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?sp(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 BN=Yp(EN);vp("scriptableValue",BN),ap("ScriptableValueNode",EN);class IN 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 PN{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 FN=new IN;class UN extends op{constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new IN,this._output=BN(),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]=BN(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]=BN(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 PN(this),e=FN.get("THREE"),s=FN.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,FN,()=>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:im()}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()}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 ON=Yp(UN);vp("scriptable",ON),ap("ScriptableNode",UN);class zN extends op{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||zb.z).negate()}setup(){return this.factorNode}}const LN=Yp(zN);vp("fog",LN),ap("FogNode",zN);class VN extends zN{constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return zy(this.nearNode,this.farNode,e)}}const DN=Yp(VN);vp("rangeFog",DN),ap("FogRangeNode",VN);class kN extends zN{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 GN=Yp(kN);vp("densityFog",GN),ap("FogExp2Node",kN);let WN=null,jN=null;class HN extends op{constructor(t=im(),e=im()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(Kd(this.minNode.value)),s=t.getTypeLength(Kd(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(Kd(i)),o=t.getTypeLength(Kd(r));WN=WN||new vi,jN=jN||new vi,WN.setScalar(0),jN.setScalar(0),1===n?WN.setScalar(i):i.isColor?WN.set(i.r,i.g,i.b):WN.set(i.x,i.y,i.z||0,i.w||0),1===o?jN.setScalar(r):r.isColor?jN.set(r.r,r.g,r.b):jN.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,l=new Float32Array(h);for(let t=0;t<h;t++){const e=t%a,s=WN.getComponent(e),i=jN.getComponent(e);l[t]=Js.lerp(s,i,Math.random())}const u=this.getNodeType(t);if(e.count<=4096)s=nx(l,"vec4",e.count).element(Zm).convert(u);else{const e=new Go(l,4);t.geometry.setAttribute("__range"+this.id,e),s=jb(e).convert(u)}}else s=im(0);return s}}const qN=Yp(HN);ap("RangeNode",HN);class $N extends op{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=Hd.OBJECT,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(){}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)}}}const XN=(t,e,s)=>qp(new $N(qp(t),e,s));vp("compute",XN),ap("ComputeNode",$N);class YN extends op{constructor(t=YN.TARGET_DIRECTION,e=null){super(),this.scope=t,this.light=e}setup(){const{scope:t,light:e}=this;let s=null;return t===YN.TARGET_DIRECTION&&(s=Tx.transformDirection(Ex(e).sub(Ex(e.target)))),s}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}YN.TARGET_DIRECTION="targetDirection";const JN=Yp(YN,YN.TARGET_DIRECTION);ap("LightNode",YN);const ZN=Zp((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).cond(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));class QN extends vv{constructor(t=null){super(t),this.cutoffDistanceNode=nf(0),this.decayExponentNode=nf(0)}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=Ix(r).sub(zb),a=o.normalize(),h=o.length(),l=ZN({lightDistance:h,cutoffDistance:s,decayExponent:i}),u=e.mul(l),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:u,reflectedLight:c,shadowMask:this.shadowMaskNode},t.stack,t)}}ap("PointLightNode",QN),Mv(Mu,QN);class KN extends vv{constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=JN(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r,shadowMask:this.shadowMaskNode},t.stack,t)}}ap("DirectionalLightNode",KN),Mv(Ru,KN);const tR=new rr,eR=new rr;let sR=null;class iR extends vv{constructor(t=null){super(t),this.halfHeight=nf(new Ri),this.halfWidth=nf(new Ri)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;eR.identity(),tR.copy(e.matrixWorld),tR.premultiply(s),eR.extractRotation(tR),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(eR),this.halfHeight.value.applyMatrix4(eR)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=ex(sR.LTC_FLOAT_1),s=ex(sR.LTC_FLOAT_2)):(e=ex(sR.LTC_HALF_1),s=ex(sR.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=Ix(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){sR=t}}ap("RectAreaLightNode",iR),Mv(Eu,iR);class rR extends vv{constructor(t=null){super(t),this.coneCosNode=nf(0),this.penumbraCosNode=nf(0),this.cutoffDistanceNode=nf(0),this.decayExponentNode=nf(0)}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 zy(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=Ix(n).sub(zb),a=o.normalize(),h=a.dot(JN(n)),l=this.getSpotAttenuation(h),u=o.length(),c=ZN({lightDistance:u,cutoffDistance:i,decayExponent:r}),d=s.mul(l).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p,shadowMask:this.shadowMaskNode},t.stack,t)}}ap("SpotLightNode",rR),Mv(vu,rR);class nR extends vu{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 oR extends rR{getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=ex(e,am(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}ap("IESSpotLightNode",oR),Mv(nR,oR);class aR extends vv{constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}ap("AmbientLightNode",aR),Mv(Cu,aR);class hR extends vv{constructor(t=null){super(t),this.lightPositionNode=Ex(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=nf(new $r)}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=jx.dot(i).mul(.5).add(.5),n=Py(s,e,r);t.context.irradiance.addAssign(n)}}ap("HemisphereLightNode",hR),Mv(mu,hR);const lR=Zp((t=>{const e=t.uv.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()}));class uR extends lp{constructor(t=of()){super("float"),this.uvNode=t}setup(){return lR({uv:this.uvNode})}}const cR=Yp(uR);vp("checker",cR),ap("CheckerNode",uR);class dR extends iu{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=new ou(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]=qp(hp(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=qp(hp(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}}const pR=new za;class mR extends XT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.setDefaultValues(pR),this.setupShaders(),this.setValues(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor;this.vertexNode=Zp((()=>{Vm(am(),"vUv").assign(of());const t=km("instancePosition"),e=cg("vec4","mvPos");e.assign(Ux.mul(gm(t,1)));const s=_T.z.div(_T.w),i=bx.mul(e),r=cg("vec2","offset");return r.assign(Pb.xy),r.assign(r.mul(Eb)),r.assign(r.div(_T.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.assign(i.add(gm(r,0,0))),i}))(),this.fragmentNode=Zp((()=>{const s=Vm(am(),"vUv"),i=cg("float","alpha");i.assign(1);const r=s.x,n=s.y,o=r.mul(r).add(n.mul(n));if(t){const t=cg("float","dlen");t.assign(o.fwidth()),i.assign(zy(t.oneMinus(),t.add(1),o).oneMinus())}else o.greaterThan(1).discard();let a;if(this.pointColorNode)a=this.pointColorNode;else if(e){a=km("instanceColor").mul(Qx)}else a=Qx;return gm(a,i)}))(),this.needsUpdate=!0}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.setupShaders())}}YT("InstancedPointsNodeMaterial",mR);const gR=new wa;class fR extends XT{constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(gR),this.setValues(t)}}YT("LineBasicNodeMaterial",fR);const yR=new Pl;class xR extends XT{constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(yR),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?im(this.dashScaleNode):Mb,s=this.dashSizeNode?im(this.dashSizeNode):Ab,i=this.dashSizeNode?im(this.dashGapNode):Nb;Bg.assign(s),Ig.assign(i);const r=Vm(km("lineDistance").mul(e));(t?r.add(t):r).mod(Bg.add(Ig)).greaterThan(Bg).discard()}}YT("LineDashedNodeMaterial",xR);const bR=new Pl;class vR extends XT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.setDefaultValues(bR),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(),super.setup(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor,s=this.dashed,i=this.worldUnits,r=Zp((({start:t,end:e})=>{const s=bx.element(2).element(2),i=bx.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return gm(Py(t.xyz,e.xyz,i),e.w)}));this.vertexNode=Zp((()=>{dg("vec2","vUv").assign(of());const t=km("instanceStart"),e=km("instanceEnd"),n=cg("vec4","start"),o=cg("vec4","end");n.assign(Ux.mul(gm(t,1))),o.assign(Ux.mul(gm(e,1))),i&&(dg("vec3","worldStart").assign(n.xyz),dg("vec3","worldEnd").assign(o.xyz));const a=_T.z.div(_T.w),h=bx.element(2).element(3).equal(-1);tm(h,(()=>{tm(n.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(r({start:n,end:o}))})).elseif(o.z.lessThan(0).and(n.z.greaterThanEqual(0)),(()=>{n.assign(r({start:o,end:n}))}))}));const l=bx.mul(n),u=bx.mul(o),c=l.xyz.div(l.w),d=u.xyz.div(u.w),p=d.xy.sub(c.xy).temp();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=eg(gm());if(i){const t=o.xyz.sub(n.xyz).normalize(),e=Py(n.xyz,o.xyz,.5).normalize(),i=t.cross(e).normalize(),r=t.cross(i),a=dg("vec4","worldPos");a.assign(Pb.y.lessThan(.5).cond(n,o));const h=Rb.mul(.5);a.addAssign(gm(Pb.x.lessThan(0).cond(i.mul(h),i.mul(h).negate()),0)),s||(a.addAssign(gm(Pb.y.lessThan(.5).cond(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(gm(r.mul(h),0)),tm(Pb.y.greaterThan(1).or(Pb.y.lessThan(0)),(()=>{a.subAssign(gm(r.mul(2).mul(h),0))}))),m.assign(bx.mul(a));const l=eg(cm());l.assign(Pb.y.lessThan(.5).cond(c,d)),m.z.assign(l.z.mul(m.w))}else{const t=cg("vec2","offset");t.assign(am(p.y,p.x.negate())),p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(Pb.x.lessThan(0).cond(t.negate(),t)),tm(Pb.y.lessThan(0),(()=>{t.assign(t.sub(p))})).elseif(Pb.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Rb)),t.assign(t.div(_T.w)),m.assign(Pb.y.lessThan(.5).cond(l,u)),t.assign(t.mul(m.w)),m.assign(m.add(gm(t,0,0)))}return m}))();const n=Zp((({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),l=r.dot(o),u=n.dot(n),c=o.dot(o).mul(u).sub(h.mul(h)),d=a.mul(h).sub(l.mul(u)).div(c).clamp(),p=a.add(h.mul(d)).div(u).clamp();return am(d,p)}));this.fragmentNode=Zp((()=>{const r=dg("vec2","vUv");if(s){const t=this.offsetNode?im(this.offsetNodeNode):Cb,e=this.dashScaleNode?im(this.dashScaleNode):Mb,s=this.dashSizeNode?im(this.dashSizeNode):Ab,i=this.dashSizeNode?im(this.dashGapNode):Nb;Bg.assign(s),Ig.assign(i);const n=km("instanceDistanceStart"),o=km("instanceDistanceEnd"),a=Pb.y.lessThan(.5).cond(e.mul(n),Mb.mul(o)),h=Vm(a.add(Cb)),l=t?h.add(t):h;r.y.lessThan(-1).or(r.y.greaterThan(1)).discard(),l.mod(Bg.add(Ig)).greaterThan(Bg).discard()}const o=cg("float","alpha");if(o.assign(1),i){const e=dg("vec3","worldStart"),i=dg("vec3","worldEnd"),r=dg("vec4","worldPos").xyz.normalize().mul(1e5),a=i.sub(e),h=n({p1:e,p2:i,p3:cm(0,0,0),p4:r}),l=e.add(a.mul(h.x)),u=r.mul(h.y),c=l.sub(u).length().div(Rb);if(!s)if(t){const t=c.fwidth();o.assign(zy(t.negate().add(.5),t.add(.5),c).oneMinus())}else c.greaterThan(.5).discard()}else if(t){const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1)),s=t.mul(t).add(e.mul(e)),i=cg("float","dlen");i.assign(s.fwidth()),tm(r.y.abs().greaterThan(1),(()=>{o.assign(zy(i.oneMinus(),i.add(1),s).oneMinus())}))}else tm(r.y.abs().greaterThan(1),(()=>{const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let a;if(this.lineColorNode)a=this.lineColorNode;else if(e){const t=km("instanceColorStart"),e=km("instanceColorEnd");a=Pb.y.lessThan(.5).cond(t,e).mul(Qx)}else a=Qx;return gm(a,o)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}YT("Line2NodeMaterial",vR);const TR=new Rl;class _R extends XT{constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(TR),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?im(this.opacityNode):eb;pg.assign(gm(Mw(qx),t))}}YT("MeshNormalNodeMaterial",_R);const wR=new Zr;class SR extends XT{constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(wR),this.setValues(t)}}YT("MeshBasicNodeMaterial",SR);const MR=Zp((({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))})),AR=Zp((t=>t.diffuseColor.mul(1/Math.PI))),NR=Zp((({dotNH:t})=>Cg.mul(im(.5)).add(1).mul(im(1/Math.PI)).mul(t.pow(Cg)))),RR=Zp((({lightDirection:t})=>{const e=t.add(Lb).normalize(),s=qx.dot(e).clamp(),i=Lb.dot(e).clamp(),r=MR({f0:Ng,f90:1,dotVH:i}),n=im(.25),o=NR({dotNH:s});return r.mul(n).mul(o)}));class CR extends Km{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=qx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(AR({diffuseColor:pg.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(RR({lightDirection:t})).mul(nb))}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(AR({diffuseColor:pg})))}}const ER=new Cl;class BR extends XT{constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(ER),this.setValues(t)}setupLightingModel(){return new CR(!1)}}YT("MeshLambertNodeMaterial",BR);const IR=new Al;class PR extends XT{constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(IR),this.setValues(t)}setupLightingModel(){return new CR}setupVariants(){const t=(this.shininessNode?im(this.shininessNode):Kx).max(1e-4);Cg.assign(t);const e=this.specularNode||sb;Ng.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}YT("MeshPhongNodeMaterial",PR);const FR=Zp((()=>{const t=Gx.dFdx().abs().max(Gx.dFdy().abs());return t.x.max(t.y).max(t.z)})),UR=Zp((t=>{const{roughness:e}=t,s=FR();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),OR=Zp((({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 pf(.5,r.add(n).max(If))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),zR=Zp((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(cm(t.mul(s),e.mul(i),o).length()),l=o.mul(cm(t.mul(r),e.mul(n),a).length());return pf(.5,h.add(l)).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"}]}),LR=Zp((({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"}]}),VR=im(1/Math.PI),DR=Zp((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=cm(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return VR.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"}]}),kR=Zp((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||qx,l=r.pow2(),u=e.add(Lb).normalize(),c=h.dot(e).clamp(),d=h.dot(Lb).clamp(),p=h.dot(u).clamp(),m=Lb.dot(u).clamp();let g,f,y=MR({f0:s,f90:i,dotVH:m});if(Wp(o)&&(y=vg.mix(y,n)),Wp(a)){const t=Mg.dot(e),s=Mg.dot(Lb),i=Mg.dot(u),r=Ag.dot(e),n=Ag.dot(Lb),o=Ag.dot(u);g=zR({alphaT:wg,alphaB:l,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=DR({alphaT:wg,alphaB:l,dotNH:p,dotTH:i,dotBH:o})}else g=OR({alpha:l,dotNL:c,dotNV:d}),f=LR({alpha:l,dotNH:p});return y.mul(g).mul(f)})),GR=Zp((({roughness:t,dotNV:e})=>{const s=gm(-1,-.0275,-.572,.022),i=gm(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 am(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),WR=Zp((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=GR({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),jR=Zp((({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(cm(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"}]}),HR=Zp((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=im(1).div(s),r=e.pow2().oneMinus().max(.0078125);return im(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"}]}),qR=Zp((({dotNV:t,dotNL:e})=>im(1).div(im(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),$R=Zp((({lightDirection:t})=>{const e=t.add(Lb).normalize(),s=qx.dot(t).clamp(),i=qx.dot(Lb).clamp(),r=qx.dot(e).clamp(),n=HR({roughness:bg,dotNH:r}),o=qR({dotNV:i,dotNL:s});return xg.mul(n).mul(o)})),XR=Zp((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=am(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"}]}),YR=Zp((({f:t})=>{const e=t.length();return xy(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),JR=Zp((({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).cond(o,xy(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"}]}),ZR=Zp((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),l=a.sub(r).toVar(),u=h.cross(l),c=cm().toVar();return tm(u.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),l=t.cross(h).negate(),u=i.mul(wm(h,l,t).transpose()).toVar(),d=u.mul(r.sub(s)).normalize().toVar(),p=u.mul(n.sub(s)).normalize().toVar(),m=u.mul(o.sub(s)).normalize().toVar(),g=u.mul(a.sub(s)).normalize().toVar(),f=cm(0).toVar();f.addAssign(JR({v1:d,v2:p})),f.addAssign(JR({v1:p,v2:m})),f.addAssign(JR({v1:m,v2:g})),f.addAssign(JR({v1:g,v2:d})),c.assign(cm(YR({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"}]}),QR=Zp((([t,e,s,i,r])=>{const n=cm(Oy(e.negate(),Yf(t),pf(1,i))),o=cm(ny(r[0].xyz),ny(r[1].xyz),ny(r[2].xyz));return Yf(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"}]}),KR=Zp((([t,e])=>t.mul(Fy(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),tC=ET(),eC=Zp((([t,e,s])=>{const i=tC.uv(t),r=jf(im(TT.x)).mul(KR(e,s));return i.bicubic(r)})),sC=Zp((([t,e,s])=>(tm(s.notEqual(0),(()=>{const i=Wf(e).negate().div(s);return kf(i.negate().mul(t))})),cm(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),iC=Zp((([t,e,s,i,r,n,o,a,h,l,u,c,d,p,m])=>{let g,f;if(m){g=gm().toVar(),f=cm().toVar();const r=u.sub(1).mul(m.mul(.025)),n=cm(u.sub(r),u,u.add(r));ov({start:0,end:3},(({i:r})=>{const u=n.element(r),m=QR(t,e,c,u,a),y=o.add(m),x=l.mul(h.mul(gm(y,1))),b=am(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(am(b.x,b.y.oneMinus()));const v=eC(b,s,u);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul(sC(ny(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=QR(t,e,c,u,a),n=o.add(r),m=l.mul(h.mul(gm(n,1))),y=am(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(am(y.x,y.y.oneMinus())),g=eC(y,s,u),f=i.mul(sC(ny(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=cm(WR({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return gm(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),rC=wm(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),nC=(t,e)=>t.sub(e).div(t.add(e)).pow2(),oC=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=cm(54856e-17,44201e-17,52481e-17),r=cm(1681e3,1795300,2208400),n=cm(43278e5,93046e5,66121e5),o=im(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=cm(a.x.add(o),a.y,a.z).div(1.0685e-7);return rC.mul(a)},aC=Zp((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=Py(t,e,zy(0,.03,i)),o=t.div(n).pow2().mul(im(1).sub(s.pow2())),a=im(1).sub(o).sqrt(),h=nC(n,t),l=MR({f0:h,f90:1,dotVH:s}),u=l.oneMinus(),c=n.lessThan(t).cond(Math.PI,0),d=im(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return cm(1).add(e).div(cm(1).sub(e))})(r.clamp(0,.9999)),m=nC(p,n.toVec3()),g=MR({f0:m,f90:1,dotVH:a}),f=cm(p.x.lessThan(n).cond(Math.PI,0),p.y.lessThan(n).cond(Math.PI,0),p.z.lessThan(n).cond(Math.PI,0)),y=n.mul(i,a,2),x=cm(d).add(f),b=l.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=u.pow2().mul(g).div(cm(1).sub(b));let _=l.add(T),w=T.sub(u);for(let t=1;t<=2;++t){w=w.mul(v);const e=oC(im(t).mul(y),im(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(cm(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"}]}),hC=Zp((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=kv(s.lessThan(.25),im(-339.2).mul(r).add(im(161.4).mul(s)).sub(25.9),im(-8.48).mul(r).add(im(14.3).mul(s)).sub(9.95)),o=kv(s.lessThan(.25),im(44).mul(r).sub(im(23.7).mul(s)).add(3.26),im(1.97).mul(r).sub(im(3.27).mul(s)).add(.72));return kv(s.lessThan(.25),0,im(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),lC=cm(.04),uC=im(1);class cC extends Km{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=cm().temp("clearcoatRadiance"),this.clearcoatSpecularDirect=cm().temp("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=cm().temp("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=cm().temp("sheenSpecularDirect"),this.sheenSpecularIndirect=cm().temp("sheenSpecularIndirect")),!0===this.iridescence){const t=qx.dot(Lb).clamp();this.iridescenceFresnel=aC({outsideIOR:im(1),eta2:Tg,cosTheta1:t,thinFilmThickness:_g,baseF0:Ng}),this.iridescenceF0=jR({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=Ub,s=Sx.sub(Ub).normalize(),i=$x;t.backdrop=iC(i,s,mg,pg,Ng,Rg,e,zx,Tx,bx,Fg,Og,Lg,zg,this.dispersion?Vg:null),t.backdropAlpha=Ug,pg.a.mulAssign(Py(1,t.backdrop.a,Ug))}}computeMultiscattering(t,e,s){const i=qx.dot(Lb).clamp(),r=GR({roughness:mg,dotNV:i}),n=(this.iridescenceF0?vg.mix(Ng,this.iridescenceF0):Ng).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Ng.add(Ng.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=qx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul($R({lightDirection:t}))),!0===this.clearcoat){const s=Xx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(kR({lightDirection:t,f0:lC,f90:uC,roughness:yg,normalView:Xx})))}s.directDiffuse.addAssign(i.mul(AR({diffuseColor:pg.rgb}))),s.directSpecular.addAssign(i.mul(kR({lightDirection:t,f0:Ng,f90:1,roughness:mg,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),l=e.sub(s).add(i),u=e.add(s).add(i),c=qx,d=Lb,p=zb.toVar(),m=XR({N:c,V:d,roughness:mg}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=wm(cm(g.x,0,g.y),cm(0,1,0),cm(g.z,0,g.w)).toVar(),x=Ng.mul(f.x).add(Ng.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(ZR({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:l,p3:u}))),r.directDiffuse.addAssign(t.mul(pg).mul(ZR({N:c,V:d,P:p,mInv:wm(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:l,p3:u})))}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(AR({diffuseColor:pg})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(xg,hC({normal:qx,viewDir:Lb,roughness:bg}))),!0===this.clearcoat){const t=Xx.dot(Lb).clamp(),e=WR({dotNV:t,specularColor:lC,specularF90:uC,roughness:yg});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=cm().temp("singleScattering"),r=cm().temp("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Rg);const o=i.add(r),a=pg.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=qx.dot(Lb).clamp().add(t),i=mg.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=Xx.dot(Lb).clamp(),s=MR({dotVH:t,f0:lC,f90:uC}),i=e.mul(fg.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(fg));e.assign(i)}if(!0===this.sheen){const t=xg.r.max(xg.g).max(xg.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const dC=new Sl;class pC extends XT{constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(dC),this.setValues(t)}setupLightingModel(){return new cC}setupSpecular(){const t=Py(cm(.04),pg.rgb,gg);Ng.assign(t),Rg.assign(1)}setupVariants(){const t=this.metalnessNode?im(this.metalnessNode):hb;gg.assign(t);let e=this.roughnessNode?im(this.roughnessNode):ab;e=UR({roughness:e}),mg.assign(e),this.setupSpecular(),pg.assign(gm(pg.rgb.mul(t.oneMinus()),pg.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}YT("MeshStandardNodeMaterial",pC);const mC=new Ml;class gC extends pC{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(mC),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?im(this.iorNode):_b;Fg.assign(t),Ng.assign(Py(yy(Ny(Fg.sub(1).div(Fg.add(1))).mul(rb),cm(1)).mul(ib),pg.rgb,gg)),Rg.assign(Py(ib,1,gg))}setupLightingModel(){return new cC(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?im(this.clearcoatNode):ub,e=this.clearcoatRoughnessNode?im(this.clearcoatRoughnessNode):cb;fg.assign(t),yg.assign(UR({roughness:e}))}if(this.useSheen){const t=this.sheenNode?cm(this.sheenNode):mb,e=this.sheenRoughnessNode?im(this.sheenRoughnessNode):gb;xg.assign(t),bg.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?im(this.iridescenceNode):yb,e=this.iridescenceIORNode?im(this.iridescenceIORNode):xb,s=this.iridescenceThicknessNode?im(this.iridescenceThicknessNode):bb;vg.assign(t),Tg.assign(e),_g.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?am(this.anisotropyNode):fb).toVar();Sg.assign(t.length()),tm(Sg.equal(0),(()=>{t.assign(am(1,0))})).else((()=>{t.divAssign(am(Sg)),Sg.assign(Sg.saturate())})),wg.assign(Sg.pow2().mix(mg.pow2(),1)),Mg.assign(Ov[0].mul(t.x).add(Ov[1].mul(t.y))),Ag.assign(Ov[1].mul(t.x).sub(Ov[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?im(this.transmissionNode):vb,e=this.thicknessNode?im(this.thicknessNode):Tb,s=this.attenuationDistanceNode?im(this.attenuationDistanceNode):wb,i=this.attenuationColorNode?cm(this.attenuationColorNode):Sb;if(Ug.assign(t),Og.assign(e),zg.assign(s),Lg.assign(i),this.useDispersion){const t=this.dispersionNode?im(this.dispersionNode):Bb;Vg.assign(t)}}}setupNormal(t){super.setupNormal(t);const e=this.clearcoatNormalNode?cm(this.clearcoatNormalNode):db;Xx.assign(e)}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)}}YT("MeshPhysicalNodeMaterial",gC);class fC extends cC{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:l,thicknessScaleNode:u}=i,c=t.add(qx.mul(o)).normalize(),d=im(Lb.dot(c.negate()).saturate().pow(l).mul(u)),p=cm(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class yC extends gC{constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=im(.1),this.thicknessAmbientNode=im(0),this.thicknessAttenuationNode=im(.1),this.thicknessPowerNode=im(2),this.thicknessScaleNode=im(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new fC(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)}}YT("MeshSSSNodeMaterial",yC);const xC=Zp((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=am(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=mx("gradientMap","texture").context({getUV:()=>r});return cm(t.r)}{const t=r.fwidth().mul(.5);return Py(cm(.7),cm(1),zy(im(.7).sub(t.x),im(.7).add(t.x),r.x))}}));class bC extends Km{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=xC({normal:Gx,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(AR({diffuseColor:pg.rgb})))}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(AR({diffuseColor:pg})))}}const vC=new Nl;class TC extends XT{constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(vC),this.setValues(t)}setupLightingModel(){return new bC}}YT("MeshToonNodeMaterial",TC);const _C=new Il;class wC extends XT{constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(_C),this.setValues(t)}setupVariants(t){const e=pw;let s;s=t.material.matcap?mx("matcap","texture").context({getUV:()=>e}):cm(Py(.2,.8,e.y)),pg.rgb.mulAssign(s.rgb)}}YT("MeshMatcapNodeMaterial",wC);const SC=new za;class MC extends XT{constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.normals=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(SC),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}YT("PointsNodeMaterial",MC);const AC=new ao;class NC extends XT{constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this.normals=!1,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(AC),this.setValues(t)}setupPosition({object:t,context:e}){const{positionNode:s,rotationNode:i,scaleNode:r}=this,n=Fb;let o=Ux.mul(cm(s||0)),a=am(zx[0].xyz.length(),zx[1].xyz.length());null!==r&&(a=a.mul(r));let h=n.xy;t.center&&!0===t.center.isVector2&&(h=h.sub(nf(t.center).sub(.5))),h=h.mul(a);const l=im(i||pb),u=h.rotate(l);o=gm(o.xy.add(u),o.zw);const c=bx.mul(o);return e.vertex=n,c}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}}YT("SpriteNodeMaterial",NC);class RC extends Km{constructor(){super(),this.shadowNode=im(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){pg.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(pg.rgb)}}const CC=new _l;class EC extends XT{constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(CC),this.setValues(t)}setupLightingModel(){return new RC}}YT("ShadowNodeMaterial",EC);class BC extends XT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=nA(this.map,null,0),s=Zp((({orig:t,dir:e})=>{const s=cm(-.5),i=cm(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=yy(n,o),h=xy(n,o),l=xy(a.x,xy(a.y,a.z)),u=yy(h.x,yy(h.y,h.z));return am(l,u)}));this.fragmentNode=Zp((()=>{const t=Vm(cm(kx.mul(gm(Sx,1)))),i=Vm(Pb.sub(t)).normalize(),r=cg("vec2","bounds").assign(s({orig:t,dir:i}));r.x.greaterThan(r.y).discard(),r.assign(am(xy(r.x,0),r.y));const n=cg("vec3","p").assign(t.add(r.x.mul(i))),o=cg("vec3","inc").assign(cm(i.abs().reciprocal())),a=cg("float","delta").assign(yy(o.x,yy(o.y,o.z)));a.divAssign(mx("steps","float"));const h=cg("vec4","ac").assign(gm(mx("base","color"),0));return ov({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=cg("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),hv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),gm(h)}))(),super.setup(t)}}YT("VolumeNodeMaterial",BC);const IC=Pu.createMaterialFromType;Pu.createMaterialFromType=function(t){const e=JT(t);return void 0!==e?e:IC.call(this,t)};class PC extends Pu{constructor(t){super(t),this.nodes={}}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}}class FC extends zu{constructor(t){super(t),this._nodesJSON=null}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 dR;return 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 PC;r.setTextures(e),r.setNodes(i);for(let e=0,i=t.length;e<i;e++){const i=t[e];s[i.uuid]=r.parse(i)}}return s}}class UC{parseFunction(){console.warn("Abstract function.")}}class OC{constructor(t,e,s="",i=""){this.type=t,this.inputs=e,this.name=s,this.precision=i}getCode(){console.warn("Abstract function.")}}OC.isNodeFunction=!0;const zC=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,LC=/[a-z_0-9]+/gi,VC="#pragma main";class DC extends OC{constructor(t){const{type:e,inputs:s,name:i,precision:r,inputsCode:n,blockCode:o,headerCode:a}=(t=>{const e=(t=t.trim()).indexOf(VC),s=-1!==e?t.slice(e+12):t,i=s.match(zC);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=LC.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 H_(s,r,i,e,t))}const l=s.substring(i[0].length),u=void 0!==i[3]?i[3]:"";return{type:i[2],inputs:a,name:u,precision:void 0!==i[1]?i[1]:"",inputsCode:r,blockCode:l,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 kC extends UC{parseFunction(t){return new DC(t)}}const GC=Zp((([t,e,s])=>{const i=im(s).toVar(),r=im(e).toVar(),n=om(t).toVar();return kv(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),WC=Zp((([t,e])=>{const s=om(e).toVar(),i=im(t).toVar();return kv(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),jC=Zp((([t])=>{const e=im(t).toVar();return rm($f(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),HC=Zp((([t,e])=>{const s=im(t).toVar();return e.assign(jC(s)),s.sub(im(e))})),qC=cw([Zp((([t,e,s,i,r,n])=>{const o=im(n).toVar(),a=im(r).toVar(),h=im(i).toVar(),l=im(s).toVar(),u=im(e).toVar(),c=im(t).toVar(),d=im(cf(1,a)).toVar();return cf(1,o).mul(c.mul(d).add(u.mul(a))).add(o.mul(l.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"}]}),Zp((([t,e,s,i,r,n])=>{const o=im(n).toVar(),a=im(r).toVar(),h=cm(i).toVar(),l=cm(s).toVar(),u=cm(e).toVar(),c=cm(t).toVar(),d=im(cf(1,a)).toVar();return cf(1,o).mul(c.mul(d).add(u.mul(a))).add(o.mul(l.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"}]})]),$C=cw([Zp((([t,e,s,i,r,n,o,a,h,l,u])=>{const c=im(u).toVar(),d=im(l).toVar(),p=im(h).toVar(),m=im(a).toVar(),g=im(o).toVar(),f=im(n).toVar(),y=im(r).toVar(),x=im(i).toVar(),b=im(s).toVar(),v=im(e).toVar(),T=im(t).toVar(),_=im(cf(1,p)).toVar(),w=im(cf(1,d)).toVar();return im(cf(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"}]}),Zp((([t,e,s,i,r,n,o,a,h,l,u])=>{const c=im(u).toVar(),d=im(l).toVar(),p=im(h).toVar(),m=cm(a).toVar(),g=cm(o).toVar(),f=cm(n).toVar(),y=cm(r).toVar(),x=cm(i).toVar(),b=cm(s).toVar(),v=cm(e).toVar(),T=cm(t).toVar(),_=im(cf(1,p)).toVar(),w=im(cf(1,d)).toVar();return im(cf(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"}]})]),XC=Zp((([t,e,s])=>{const i=im(s).toVar(),r=im(e).toVar(),n=nm(t).toVar(),o=nm(n.bitAnd(nm(7))).toVar(),a=im(GC(o.lessThan(nm(4)),r,i)).toVar(),h=im(df(2,GC(o.lessThan(nm(4)),i,r))).toVar();return WC(a,om(o.bitAnd(nm(1)))).add(WC(h,om(o.bitAnd(nm(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),YC=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=im(e).toVar(),a=nm(t).toVar(),h=nm(a.bitAnd(nm(15))).toVar(),l=im(GC(h.lessThan(nm(8)),o,n)).toVar(),u=im(GC(h.lessThan(nm(4)),n,GC(h.equal(nm(12)).or(h.equal(nm(14))),o,r))).toVar();return WC(l,om(h.bitAnd(nm(1)))).add(WC(u,om(h.bitAnd(nm(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"}]}),JC=cw([XC,YC]),ZC=Zp((([t,e,s])=>{const i=im(s).toVar(),r=im(e).toVar(),n=pm(t).toVar();return cm(JC(n.x,r,i),JC(n.y,r,i),JC(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"}]}),QC=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=im(e).toVar(),a=pm(t).toVar();return cm(JC(a.x,o,n,r),JC(a.y,o,n,r),JC(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"}]}),KC=cw([ZC,QC]),tE=Zp((([t])=>{const e=im(t).toVar();return df(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),eE=Zp((([t])=>{const e=im(t).toVar();return df(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),sE=cw([tE,Zp((([t])=>{const e=cm(t).toVar();return df(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),iE=cw([eE,Zp((([t])=>{const e=cm(t).toVar();return df(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),rE=Zp((([t,e])=>{const s=rm(e).toVar(),i=nm(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(rm(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),nE=Zp((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(rE(s,rm(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(rE(t,rm(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(rE(e,rm(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(rE(s,rm(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(rE(t,rm(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(rE(e,rm(4))),e.addAssign(t)})),oE=Zp((([t,e,s])=>{const i=nm(s).toVar(),r=nm(e).toVar(),n=nm(t).toVar();return i.bitXorAssign(r),i.subAssign(rE(r,rm(14))),n.bitXorAssign(i),n.subAssign(rE(i,rm(11))),r.bitXorAssign(n),r.subAssign(rE(n,rm(25))),i.bitXorAssign(r),i.subAssign(rE(r,rm(16))),n.bitXorAssign(i),n.subAssign(rE(i,rm(4))),r.bitXorAssign(n),r.subAssign(rE(n,rm(14))),i.bitXorAssign(r),i.subAssign(rE(r,rm(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),aE=Zp((([t])=>{const e=nm(t).toVar();return im(e).div(im(nm(rm(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),hE=Zp((([t])=>{const e=im(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"}]}),lE=cw([Zp((([t])=>{const e=rm(t).toVar(),s=nm(nm(1)).toVar(),i=nm(nm(rm(3735928559)).add(s.shiftLeft(nm(2))).add(nm(13))).toVar();return oE(i.add(nm(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),Zp((([t,e])=>{const s=rm(e).toVar(),i=rm(t).toVar(),r=nm(nm(2)).toVar(),n=nm().toVar(),o=nm().toVar(),a=nm().toVar();return n.assign(o.assign(a.assign(nm(rm(3735928559)).add(r.shiftLeft(nm(2))).add(nm(13))))),n.addAssign(nm(i)),o.addAssign(nm(s)),oE(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Zp((([t,e,s])=>{const i=rm(s).toVar(),r=rm(e).toVar(),n=rm(t).toVar(),o=nm(nm(3)).toVar(),a=nm().toVar(),h=nm().toVar(),l=nm().toVar();return a.assign(h.assign(l.assign(nm(rm(3735928559)).add(o.shiftLeft(nm(2))).add(nm(13))))),a.addAssign(nm(n)),h.addAssign(nm(r)),l.addAssign(nm(i)),oE(a,h,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),Zp((([t,e,s,i])=>{const r=rm(i).toVar(),n=rm(s).toVar(),o=rm(e).toVar(),a=rm(t).toVar(),h=nm(nm(4)).toVar(),l=nm().toVar(),u=nm().toVar(),c=nm().toVar();return l.assign(u.assign(c.assign(nm(rm(3735928559)).add(h.shiftLeft(nm(2))).add(nm(13))))),l.addAssign(nm(a)),u.addAssign(nm(o)),c.addAssign(nm(n)),nE(l,u,c),l.addAssign(nm(r)),oE(l,u,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"}]}),Zp((([t,e,s,i,r])=>{const n=rm(r).toVar(),o=rm(i).toVar(),a=rm(s).toVar(),h=rm(e).toVar(),l=rm(t).toVar(),u=nm(nm(5)).toVar(),c=nm().toVar(),d=nm().toVar(),p=nm().toVar();return c.assign(d.assign(p.assign(nm(rm(3735928559)).add(u.shiftLeft(nm(2))).add(nm(13))))),c.addAssign(nm(l)),d.addAssign(nm(h)),p.addAssign(nm(a)),nE(c,d,p),c.addAssign(nm(o)),d.addAssign(nm(n)),oE(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"}]})]),uE=cw([Zp((([t,e])=>{const s=rm(e).toVar(),i=rm(t).toVar(),r=nm(lE(i,s)).toVar(),n=pm().toVar();return n.x.assign(r.bitAnd(rm(255))),n.y.assign(r.shiftRight(rm(8)).bitAnd(rm(255))),n.z.assign(r.shiftRight(rm(16)).bitAnd(rm(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),Zp((([t,e,s])=>{const i=rm(s).toVar(),r=rm(e).toVar(),n=rm(t).toVar(),o=nm(lE(n,r,i)).toVar(),a=pm().toVar();return a.x.assign(o.bitAnd(rm(255))),a.y.assign(o.shiftRight(rm(8)).bitAnd(rm(255))),a.z.assign(o.shiftRight(rm(16)).bitAnd(rm(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),cE=cw([Zp((([t])=>{const e=am(t).toVar(),s=rm().toVar(),i=rm().toVar(),r=im(HC(e.x,s)).toVar(),n=im(HC(e.y,i)).toVar(),o=im(hE(r)).toVar(),a=im(hE(n)).toVar(),h=im(qC(JC(lE(s,i),r,n),JC(lE(s.add(rm(1)),i),r.sub(1),n),JC(lE(s,i.add(rm(1))),r,n.sub(1)),JC(lE(s.add(rm(1)),i.add(rm(1))),r.sub(1),n.sub(1)),o,a)).toVar();return sE(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),Zp((([t])=>{const e=cm(t).toVar(),s=rm().toVar(),i=rm().toVar(),r=rm().toVar(),n=im(HC(e.x,s)).toVar(),o=im(HC(e.y,i)).toVar(),a=im(HC(e.z,r)).toVar(),h=im(hE(n)).toVar(),l=im(hE(o)).toVar(),u=im(hE(a)).toVar(),c=im($C(JC(lE(s,i,r),n,o,a),JC(lE(s.add(rm(1)),i,r),n.sub(1),o,a),JC(lE(s,i.add(rm(1)),r),n,o.sub(1),a),JC(lE(s.add(rm(1)),i.add(rm(1)),r),n.sub(1),o.sub(1),a),JC(lE(s,i,r.add(rm(1))),n,o,a.sub(1)),JC(lE(s.add(rm(1)),i,r.add(rm(1))),n.sub(1),o,a.sub(1)),JC(lE(s,i.add(rm(1)),r.add(rm(1))),n,o.sub(1),a.sub(1)),JC(lE(s.add(rm(1)),i.add(rm(1)),r.add(rm(1))),n.sub(1),o.sub(1),a.sub(1)),h,l,u)).toVar();return iE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),dE=cw([Zp((([t])=>{const e=am(t).toVar(),s=rm().toVar(),i=rm().toVar(),r=im(HC(e.x,s)).toVar(),n=im(HC(e.y,i)).toVar(),o=im(hE(r)).toVar(),a=im(hE(n)).toVar(),h=cm(qC(KC(uE(s,i),r,n),KC(uE(s.add(rm(1)),i),r.sub(1),n),KC(uE(s,i.add(rm(1))),r,n.sub(1)),KC(uE(s.add(rm(1)),i.add(rm(1))),r.sub(1),n.sub(1)),o,a)).toVar();return sE(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Zp((([t])=>{const e=cm(t).toVar(),s=rm().toVar(),i=rm().toVar(),r=rm().toVar(),n=im(HC(e.x,s)).toVar(),o=im(HC(e.y,i)).toVar(),a=im(HC(e.z,r)).toVar(),h=im(hE(n)).toVar(),l=im(hE(o)).toVar(),u=im(hE(a)).toVar(),c=cm($C(KC(uE(s,i,r),n,o,a),KC(uE(s.add(rm(1)),i,r),n.sub(1),o,a),KC(uE(s,i.add(rm(1)),r),n,o.sub(1),a),KC(uE(s.add(rm(1)),i.add(rm(1)),r),n.sub(1),o.sub(1),a),KC(uE(s,i,r.add(rm(1))),n,o,a.sub(1)),KC(uE(s.add(rm(1)),i,r.add(rm(1))),n.sub(1),o,a.sub(1)),KC(uE(s,i.add(rm(1)),r.add(rm(1))),n,o.sub(1),a.sub(1)),KC(uE(s.add(rm(1)),i.add(rm(1)),r.add(rm(1))),n.sub(1),o.sub(1),a.sub(1)),h,l,u)).toVar();return iE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),pE=cw([Zp((([t])=>{const e=im(t).toVar(),s=rm(jC(e)).toVar();return aE(lE(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),Zp((([t])=>{const e=am(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar();return aE(lE(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),Zp((([t])=>{const e=cm(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar(),r=rm(jC(e.z)).toVar();return aE(lE(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),Zp((([t])=>{const e=gm(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar(),r=rm(jC(e.z)).toVar(),n=rm(jC(e.w)).toVar();return aE(lE(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),mE=cw([Zp((([t])=>{const e=im(t).toVar(),s=rm(jC(e)).toVar();return cm(aE(lE(s,rm(0))),aE(lE(s,rm(1))),aE(lE(s,rm(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),Zp((([t])=>{const e=am(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar();return cm(aE(lE(s,i,rm(0))),aE(lE(s,i,rm(1))),aE(lE(s,i,rm(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),Zp((([t])=>{const e=cm(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar(),r=rm(jC(e.z)).toVar();return cm(aE(lE(s,i,r,rm(0))),aE(lE(s,i,r,rm(1))),aE(lE(s,i,r,rm(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Zp((([t])=>{const e=gm(t).toVar(),s=rm(jC(e.x)).toVar(),i=rm(jC(e.y)).toVar(),r=rm(jC(e.z)).toVar(),n=rm(jC(e.w)).toVar();return cm(aE(lE(s,i,r,n,rm(0))),aE(lE(s,i,r,n,rm(1))),aE(lE(s,i,r,n,rm(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),gE=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=rm(e).toVar(),a=cm(t).toVar(),h=im(0).toVar(),l=im(1).toVar();return ov(o,(()=>{h.addAssign(l.mul(cE(a))),l.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"}]}),fE=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=rm(e).toVar(),a=cm(t).toVar(),h=cm(0).toVar(),l=im(1).toVar();return ov(o,(()=>{h.addAssign(l.mul(dE(a))),l.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"}]}),yE=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=rm(e).toVar(),a=cm(t).toVar();return am(gE(a,o,n,r),gE(a.add(cm(rm(19),rm(193),rm(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"}]}),xE=Zp((([t,e,s,i])=>{const r=im(i).toVar(),n=im(s).toVar(),o=rm(e).toVar(),a=cm(t).toVar(),h=cm(fE(a,o,n,r)).toVar(),l=im(gE(a.add(cm(rm(19),rm(193),rm(17))),o,n,r)).toVar();return gm(h,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),bE=Zp((([t,e,s,i,r,n,o])=>{const a=rm(o).toVar(),h=im(n).toVar(),l=rm(r).toVar(),u=rm(i).toVar(),c=rm(s).toVar(),d=rm(e).toVar(),p=am(t).toVar(),m=cm(mE(am(d.add(u),c.add(l)))).toVar(),g=am(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=am(am(im(d),im(c)).add(g)).toVar(),y=am(f.sub(p)).toVar();return tm(a.equal(rm(2)),(()=>iy(y.x).add(iy(y.y)))),tm(a.equal(rm(3)),(()=>xy(iy(y.x),iy(y.y)))),Sy(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"}]}),vE=cw([bE,Zp((([t,e,s,i,r,n,o,a,h])=>{const l=rm(h).toVar(),u=im(a).toVar(),c=rm(o).toVar(),d=rm(n).toVar(),p=rm(r).toVar(),m=rm(i).toVar(),g=rm(s).toVar(),f=rm(e).toVar(),y=cm(t).toVar(),x=cm(mE(cm(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(u),x.addAssign(.5);const b=cm(cm(im(f),im(g),im(m)).add(x)).toVar(),v=cm(b.sub(y)).toVar();return tm(l.equal(rm(2)),(()=>iy(v.x).add(iy(v.y)).add(iy(v.z)))),tm(l.equal(rm(3)),(()=>xy(xy(iy(v.x),iy(v.y)),iy(v.z)))),Sy(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"}]})]),TE=Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=am(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=am(HC(n.x,o),HC(n.y,a)).toVar(),l=im(1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{const s=im(vE(h,t,e,o,a,r,i)).toVar();l.assign(yy(l,s))}))})),tm(i.equal(rm(0)),(()=>{l.assign(Hf(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),_E=Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=am(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=am(HC(n.x,o),HC(n.y,a)).toVar(),l=am(1e6,1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{const s=im(vE(h,t,e,o,a,r,i)).toVar();tm(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).elseif(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),tm(i.equal(rm(0)),(()=>{l.assign(Hf(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),wE=Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=am(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=am(HC(n.x,o),HC(n.y,a)).toVar(),l=cm(1e6,1e6,1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{const s=im(vE(h,t,e,o,a,r,i)).toVar();tm(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).elseif(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).elseif(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),tm(i.equal(rm(0)),(()=>{l.assign(Hf(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),SE=cw([TE,Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=cm(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=rm().toVar(),l=cm(HC(n.x,o),HC(n.y,a),HC(n.z,h)).toVar(),u=im(1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{ov({start:-1,end:rm(1),name:"z",condition:"<="},(({z:s})=>{const n=im(vE(l,t,e,s,o,a,h,r,i)).toVar();u.assign(yy(u,n))}))}))})),tm(i.equal(rm(0)),(()=>{u.assign(Hf(u))})),u})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),ME=cw([_E,Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=cm(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=rm().toVar(),l=cm(HC(n.x,o),HC(n.y,a),HC(n.z,h)).toVar(),u=am(1e6,1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{ov({start:-1,end:rm(1),name:"z",condition:"<="},(({z:s})=>{const n=im(vE(l,t,e,s,o,a,h,r,i)).toVar();tm(n.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(n)})).elseif(n.lessThan(u.y),(()=>{u.y.assign(n)}))}))}))})),tm(i.equal(rm(0)),(()=>{u.assign(Hf(u))})),u})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),AE=cw([wE,Zp((([t,e,s])=>{const i=rm(s).toVar(),r=im(e).toVar(),n=cm(t).toVar(),o=rm().toVar(),a=rm().toVar(),h=rm().toVar(),l=cm(HC(n.x,o),HC(n.y,a),HC(n.z,h)).toVar(),u=cm(1e6,1e6,1e6).toVar();return ov({start:-1,end:rm(1),name:"x",condition:"<="},(({x:t})=>{ov({start:-1,end:rm(1),name:"y",condition:"<="},(({y:e})=>{ov({start:-1,end:rm(1),name:"z",condition:"<="},(({z:s})=>{const n=im(vE(l,t,e,s,o,a,h,r,i)).toVar();tm(n.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(n)})).elseif(n.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(n)})).elseif(n.lessThan(u.z),(()=>{u.z.assign(n)}))}))}))})),tm(i.equal(rm(0)),(()=>{u.assign(Hf(u))})),u})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),NE=Zp((([t])=>{const e=cm(t).toVar(),s=im(e.x).toVar(),i=im(e.y).toVar(),r=im(e.z).toVar();tm(i.lessThan(1e-4),(()=>cm(r,r,r))).else((()=>{s.assign(df(6,s.sub($f(s))));const t=rm(dy(s)).toVar(),e=im(s.sub(im(t))).toVar(),n=im(r.mul(cf(1,i))).toVar(),o=im(r.mul(cf(1,i.mul(e)))).toVar(),a=im(r.mul(cf(1,i.mul(cf(1,e))))).toVar();return tm(t.equal(rm(0)),(()=>cm(r,a,n))).elseif(t.equal(rm(1)),(()=>cm(o,r,n))).elseif(t.equal(rm(2)),(()=>cm(n,r,a))).elseif(t.equal(rm(3)),(()=>cm(n,o,r))).elseif(t.equal(rm(4)),(()=>cm(a,n,r))),cm(r,n,o)}))})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),RE=Zp((([t])=>{const e=cm(t).toVar(),s=im(e.x).toVar(),i=im(e.y).toVar(),r=im(e.z).toVar(),n=im(yy(s,yy(i,r))).toVar(),o=im(xy(s,xy(i,r))).toVar(),a=im(o.sub(n)).toVar(),h=im().toVar(),l=im().toVar(),u=im().toVar();return u.assign(o),tm(o.greaterThan(0),(()=>{l.assign(a.div(o))})).else((()=>{l.assign(0)})),tm(l.lessThanEqual(0),(()=>{h.assign(0)})).else((()=>{tm(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).elseif(i.greaterThanEqual(o),(()=>{h.assign(uf(2,r.sub(s).div(a)))})).else((()=>{h.assign(uf(4,s.sub(i).div(a)))})),h.mulAssign(1/6),tm(h.lessThan(0),(()=>{h.addAssign(1)}))})),cm(h,l,u)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),CE=Zp((([t])=>{const e=cm(t).toVar(),s=mm(xf(e,cm(.04045))).toVar(),i=cm(e.div(12.92)).toVar(),r=cm(Ay(xy(e.add(cm(.055)),cm(0)).div(1.055),cm(2.4))).toVar();return Py(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),EE=(t,e)=>{t=im(t),e=im(e);const s=am(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return zy(t.sub(s),t.add(s),e)},BE=(t,e,s,i)=>Py(t,e,s[i].clamp()),IE=(t,e,s=of())=>BE(t,e,s,"x"),PE=(t,e,s=of())=>BE(t,e,s,"y"),FE=(t,e,s,i,r)=>Py(t,e,EE(s,i[r])),UE=(t,e,s,i=of())=>FE(t,e,s,i,"x"),OE=(t,e,s,i=of())=>FE(t,e,s,i,"y"),zE=(t=1,e=0,s=of())=>s.mul(t).add(e),LE=(t,e=1)=>(t=im(t)).abs().pow(e).mul(t.sign()),VE=(t,e=1,s=.5)=>im(t).sub(s).mul(e).add(s),DE=(t=of(),e=1,s=0)=>cE(t.convert("vec2|vec3")).mul(e).add(s),kE=(t=of(),e=1,s=0)=>dE(t.convert("vec2|vec3")).mul(e).add(s),GE=(t=of(),e=1,s=0)=>{t=t.convert("vec2|vec3");return gm(dE(t),cE(t.add(am(19,73)))).mul(e).add(s)},WE=(t=of(),e=1)=>SE(t.convert("vec2|vec3"),e,rm(1)),jE=(t=of(),e=1)=>ME(t.convert("vec2|vec3"),e,rm(1)),HE=(t=of(),e=1)=>AE(t.convert("vec2|vec3"),e,rm(1)),qE=(t=of())=>pE(t.convert("vec2|vec3")),$E=(t=of(),e=3,s=2,i=.5,r=1)=>gE(t,rm(e),s,i).mul(r),XE=(t=of(),e=3,s=2,i=.5,r=1)=>yE(t,rm(e),s,i).mul(r),YE=(t=of(),e=3,s=2,i=.5,r=1)=>fE(t,rm(e),s,i).mul(r),JE=(t=of(),e=3,s=2,i=.5,r=1)=>xE(t,rm(e),s,i).mul(r);function ZE(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 QE(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 KE{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new _v([]),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||ZE),this.transparent.length>1&&this.transparent.sort(e||QE)}finish(){this.lightsNode.fromLights(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 tB{constructor(){this.lists=new vd}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new KE,s.set(i,r)),r}dispose(){this.lists=new vd}}let eB=0;class sB{constructor(){this.id=eB++,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 vi,this.scissor=!1,this.scissorValue=new vi,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}}class iB{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.count}:${t}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this.getChainMap(r);let o=n.get(i);return void 0===o&&(o=new sB,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 vd)}dispose(){this.chainMaps={}}}const rB=new Ri;class nB extends Nd{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.texture,o=t.textures,a=this.getSize(n),h=a.width>>e,l=a.height>>e;let u=t.depthTexture||r[e],c=!1;void 0===u&&(u=new Za,u.format=t.stencilBuffer?jt:Wt,u.type=t.stencilBuffer?Ot:Bt,u.image.width=h,u.image.height=l,r[e]=u),s.width===a.width&&a.height===s.height||(c=!0,u.needsUpdate=!0,u.image.width=h,u.image.height=l),s.width=a.width,s.height=a.height,s.textures=o,s.depthTexture=u,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,u.needsUpdate=!0,s.sampleCount=i);const d={sampleCount:i};for(let t=0;t<o.length;t++){const e=o[t];c&&(e.needsUpdate=!0),this.updateTexture(e,d)}if(this.updateTexture(u,d),!0!==s.initialized){s.initialized=!0;const e=()=>{if(t.removeEventListener("dispose",e),void 0!==o)for(let t=0;t<o.length;t++)this._destroyTexture(o[t]);else this._destroyTexture(n);this._destroyTexture(u)};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);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),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0}if(!0!==s.initialized){s.initialized=!0,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=rB){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===ut||e===ct||e===ht||e===lt}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class oB extends $r{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 aB=new oB;class hB extends Nd{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(aB,Ye),aB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(aB,Ye),aB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;aB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=$m(gm(n).mul(ES),{getUV:()=>Hx,getTextureLevel:()=>CS});let e=Db();e=e.setZ(e.w);const i=new XT;i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.vertexNode=e,i.fragmentNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new kn(new ml(1,32,32),i),o.frustumCulled=!1,o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=gm(n).mul(ES),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){aB.multiplyScalar(aB.a);const t=s.clearColorValue;t.r=aB.r,t.g=aB.g,t.b=aB.b,t.a=aB.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 lB{constructor(t,e,s,i,r,n,o,a,h=!0,l=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=l,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.instanceBindGroups=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==(this.instanceBindGroups&&e.bindings[0].groupNode.shared)){const s=new L_(e.name);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}class uB extends Nd{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new j_,this.nodeBuilderCache=new Map,this.callHashCache=new vd,this.groupsData=new vd}updateGroup(t){const e=t.groupNode,s=e.name;if(s===sf.name)return!0;if(s===ef.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===tf.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 lB(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.instanceBindGroups,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()),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),r={callId:i,cacheKey:a.join(",")},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){if(e.background!==s){let t=null;!0===s.isCubeTexture||s.mapping===ut||s.mapping===ct?t=cT(s,Hx):!0===s.isTexture?t=ex(s,ST).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s),e.backgroundNode=t,e.background=s}}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;s.isFogExp2?t=GN(cx("color","color",s),cx("density","float",s)):s.isFog?t=DN(cx("color","color",s),cx("near","float",s),cx("far","float",s)):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=yv(s):!0===s.isTexture?t=ex(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)}getOutputNode(t){let e=ex(t,wT);return this.isToneMappingState&&(this.renderer.toneMappingNode?e=gm(this.renderer.toneMappingNode.context({color:e.rgb}),e.a):0!==this.renderer.toneMapping&&(e=e.toneMapping(this.renderer.toneMapping))),this.renderer.currentColorSpace===Xe&&(e=e.linearToColorSpace(this.renderer.currentColorSpace)),e}updateBefore(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateBeforeNodes)e.updateBeforeNode(t)}updateAfter(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateAfterNodes)e.updateAfterNode(t)}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)}dispose(){super.dispose(),this.nodeFrame=new j_,this.nodeBuilderCache=new Map}}class cB{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class dB{constructor(){this.lists=new vd}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new cB(t,e),s.set(i,r)),r}dispose(){this.lists=new vd}}const pB=new io,mB=new Zs,gB=new vi,fB=new ia,yB=new rr,xB=new Ri,bB=new nS(new XT);class vB{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0}=e;this.domElement=t.getDomElement(),this.backend=t,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Xe,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=!0,this.stencil=!1,this.clippingPlanes=[],this.info=new Od,this.toneMappingNode=null,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new vi(0,0,this._width,this._height),this._scissor=new vi(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._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const r=!0===this.alpha?0:1;this._clearColor=new oB(0,0,0,r),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.shadowMap={enabled:!1,type:null},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null}}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)=>{const s=this.backend;try{await s.init(this)}catch(t){return void e(t)}this._nodes=new uB(this,s),this._animation=new bd(this._nodes,this.info),this._attributes=new Id(s),this._background=new hB(this,this._nodes),this._geometries=new Ud(this._attributes,this.info),this._textures=new nB(this,s,this.info),this._pipelines=new Gd(s,this._nodes),this._bindings=new Wd(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Ad(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new tB,this._bundles=new dB,this._renderContexts=new iB,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:pB;null===s&&(s=t);const l=this._renderTarget,u=this._renderContexts.get(s,e,l),c=this._activeMipmapLevel,d=[];this._currentRenderContext=u,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),u.depth=this.depth,u.stencil=this.stencil,u.clippingContext||(u.clippingContext=new wd),u.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,l);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!==l){this._textures.updateRenderTarget(l,c);const t=this._textures.get(l);u.textures=t.textures,u.depthTexture=t.depthTexture}else u.textures=null,u.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,u);const m=p.opaque,g=p.transparent,f=p.lightsNode;m.length>0&&this._renderObjects(m,e,h,f),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")}_renderBundle(t,e,s){const{object:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this.backend.get(o),h=this._bundles.get(i,r),l=this.backend.get(h);void 0===l.renderContexts&&(l.renderContexts=new Set);const u=!1===l.renderContexts.has(o)||!0===i.needsUpdate;if(l.renderContexts.add(o),u){if(void 0===a.renderObjects||!0===i.needsUpdate){const t=this._nodes.nodeFrame;a.renderObjects=[],a.renderBundles=[],a.scene=e,a.camera=r,a.renderId=t.renderId,a.registerBundlesPhase=!0}this._currentRenderBundle=h;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,i.needsUpdate=!1}else{const t=this._currentRenderContext,e=this.backend.get(t);for(let t=0,s=e.renderObjects.length;t<s;t++){const s=e.renderObjects[t];this._nodes.updateBefore(s),s.object.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,s.object.matrixWorld),s.object.normalMatrix.getNormalMatrix(s.object.modelViewMatrix),this._nodes.updateForRender(s),this._bindings.updateForRender(s),this.backend.draw(s,this.info),this._nodes.updateAfter(s)}}}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{currentColorSpace:t}=this;if(!1===(null===this._renderTarget&&(0!==this.toneMapping||null!==this.toneMappingNode))&&!1===(t!==Ye&&t!==$e))return null;const{width:e,height:s}=this.getDrawingBufferSize(mB),{depth:i,stencil:r}=this;let n=this._frameBufferTarget;return null===n&&(n=new Ti(e,s,{depthBuffer:i,stencilBuffer:r,type:Pt,format:Dt,colorSpace:Ye,generateMipmaps:!1,minFilter:Tt,magFilter:Tt,samples:this.backend.parameters.antialias?4:0}),n.isPostProcessingRenderTarget=!0,this._frameBufferTarget=n),n.depthBuffer=i,n.stencilBuffer=r,n.setSize(e,s),n.viewport.copy(this._viewport),n.scissor.copy(this._scissor),n.viewport.multiplyScalar(this._pixelRatio),n.scissor.multiplyScalar(this._pixelRatio),n.scissorTest=this._scissorTest,n}_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:pB,l=this._renderTarget,u=this._activeCubeFace,c=this._activeMipmapLevel;let d;null!==i?(d=i,this.setRenderTarget(d)):d=l;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(mB),gB.set(0,0,mB.width,mB.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(gB),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(gB),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new wd),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),yB.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),fB.setFromProjectionMatrix(yB,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=u,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const T=v.opaque,_=v.transparent,w=v.bundles,S=v.lightsNode;return w.length>0&&this._renderBundles(w,h,S),T.length>0&&this._renderObjects(T,e,h,S),_.length>0&&this._renderObjects(_,e,h,S),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i&&(this.setRenderTarget(l,u,c),bB.material.fragmentNode=this._nodes.getOutputNode(d.texture),this._renderScene(bB,bB.camera,!1)),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;null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget&&(bB.material.fragmentNode=this._nodes.getOutputNode(i.texture),this._renderScene(bB,bB.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 currentColorSpace(){const t=this._renderTarget;if(null!==t){const e=t.texture;return(Array.isArray(e)?e[0]:e).colorSpace}return 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}async computeAsync(t){!1===this._initialized&&await this.init();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),e.onInit({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),await this.backend.resolveTimestampAsync(t,"compute"),e.renderId=s}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){const e=this._currentRenderContext;this._textures.updateTexture(t),this.backend.copyFramebufferToTexture(t,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){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r)}_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||fB.intersectsSprite(t)){!0===this.sortObjects&&xB.setFromMatrixPosition(t.matrixWorld).applyMatrix4(yB);const e=t.geometry,r=t.material;r.visible&&i.push(t,e,r,s,xB.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||fB.intersectsObject(t))){const e=t.geometry,r=t.material;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),xB.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(yB)),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,xB.z,a)}}else r.visible&&i.push(t,e,r,s,xB.z,null)}if(!0===t.static){const s=i;(i=this._renderLists.get(t,e)).begin(),s.pushBundle({object: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:l}=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,u=this._currentRenderContext.viewportValue;u.copy(t).multiplyScalar(this._pixelRatio).floor(),u.minDepth=e,u.maxDepth=n,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(o,s,r,a,h,l,i)}}}else this._currentRenderObjectFunction(o,s,e,a,h,l,i)}}renderObject(t,e,s,i,r,n,o){let a,h,l;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&&(l=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!==l&&(e.overrideMaterial.depthNode=l),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);if(a.drawRange=n||t.geometry.drawRange,this._nodes.updateBefore(a),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),this._nodes.updateForRender(a),this._geometries.updateForRender(a),this._bindings.updateForRender(a),this._pipelines.updateForRender(a),null!==this._currentRenderBundle&&!0===this._currentRenderBundle.needsUpdate){const t=this.backend.get(a);t.bundleEncoder=void 0,t.lastPipelineGPU=void 0}if(this.backend.draw(a,this.info),null!==this._currentRenderBundle){this.backend.get(this._currentRenderContext).renderObjects.push(a)}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._nodes.updateForRender(o),this._geometries.updateForRender(o),this._bindings.updateForRender(o),this._pipelines.getForRender(o,this._compilationPromises),this._nodes.updateAfter(o)}get compute(){return this.computeAsync}get compile(){return this.compileAsync}}class TB{constructor(t=""){this.name=t,this.visibility=0}setVisibility(t){this.visibility|=t}clone(){return Object.assign(new this.constructor,this)}}class _B extends TB{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)+(Bd-t%Bd)%Bd;var t}get buffer(){return this._buffer}update(){return!0}}class wB extends _B{constructor(t,e=null){super(t,e),this.isUniformBuffer=!0}}let SB=0;class MB extends wB{constructor(t,e){super("UniformBuffer_"+SB++,t?t.value:null),this.nodeUniform=t,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class AB extends wB{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%Bd;0!==n&&Bd-n-i<0?t+=Bd-n:n%i!=0&&(t+=n%i),s.offset=t/this.bytesPerElement,t+=r*this.bytesPerElement}return Math.ceil(t/Bd)*Bd}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 NB=0;class RB extends AB{constructor(t,e){super(t),this.id=NB++,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 CB=0;class EB extends TB{constructor(t,e){super(t),this.id=CB++,this.texture=e,this.version=e?e.version:0,this.store=!1,this.isSampledTexture=!0}get needsBindingsUpdate(){const{texture:t,version:e}=this;return!!t.isVideoTexture||e!==t.version}update(){const{texture:t,version:e}=this;return e!==t.version&&(this.version=t.version,!0)}}class BB extends EB{constructor(t,e,s,i=null){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s,this.access=i}get needsBindingsUpdate(){return this.textureNode.value!==this.texture||super.needsBindingsUpdate}update(){const{textureNode:t}=this;return this.texture!==t.value?(this.texture=t.value,!0):super.update()}}class IB extends BB{constructor(t,e,s,i){super(t,e,s,i),this.isSampledCubeTexture=!0}}class PB extends BB{constructor(t,e,s,i){super(t,e,s,i),this.isSampledTexture3D=!0}}const FB={[Bf.ATAN2]:"atan",textureDimensions:"textureSize",equals:"equal"},UB={low:"lowp",medium:"mediump",high:"highp"},OB={swizzleAssign:!0,storageBuffer:!1},zB="\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 LB extends W_{constructor(t,e){super(t,e,new kC),this.uniformGroups={},this.transforms=[],this.instanceBindGroups=!1}getMethod(t){return FB[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?qt:Ht;2===i?n=r?Xt:$t:3===i?n=r?1032:Vt:4===i&&(n=r?Jt:Dt);const o={Float32Array:It,Uint8Array:At,Uint16Array:Ct,Uint32Array:Bt,Int8Array:Nt,Int16Array:Rt,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 l=a*h*i,u=new t.constructor(l);u.set(t,0),e.array=u;const c=new Lo(e.array,a,h,n,o[e.array.constructor.name]||It);c.needsUpdate=!0,c.isPBOTexture=!0;const d=new tx(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);s.increaseUsage(this);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 l=r.propertySizeName;void 0===l&&(l=h+"Size",this.getVarFromNode(e,l,"uint"),this.addLineFlowCode(`${l} = uint( textureSize( ${n}, 0 ).x )`),r.propertySizeName=l);const{itemSize:u}=i,c="."+Jd.join("").slice(0,u),d=`ivec2(${o} % ${l}, ${o} / ${l})`,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}`),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} )`}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?`${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=UB[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||i instanceof Uint16Array||i instanceof Int16Array)&&(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 )"}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord"}getFragDepth(){return"gl_FragDepth"}getExtensions(t){let e="";if("vertex"===t){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&(e+="#extension GL_ANGLE_multi_draw : require\n")}return e}isAvailable(t){let e=OB[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}OB[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// extensions \n${t.extensions}\n\n// precision\n${zB}\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${zB}\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:{}};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 BB(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new IB(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new PB(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 MB(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 RB(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let VB=null,DB=null,kB=null;class GB{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 VB=VB||new Zs,this.renderer.getDrawingBufferSize(VB)}getScissor(){return DB=DB||new vi,this.renderer.getScissor(DB)}setScissorTest(){}getClearColor(){const t=this.renderer;return kB=kB||new oB,t.getClearColor(kB),kB.getRGB(kB,this.renderer.currentColorSpace),kB}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ii(),"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 WB=0;class jB{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 HB{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,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(i,e,r,n),a.bufferGPU=l,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 u={bufferGPU:l,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||h===i.UNSIGNED_SHORT||t.gpuType===Et,id:WB++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);u=new jB(u,t)}s.set(t,u)}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.getBufferSubData(s.COPY_WRITE_BUFFER,0,h),s.deleteBuffer(a),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 qB,$B,XB=!1;class YB{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={},!1===XB&&(this._init(this.gl),XB=!0)}_init(t){qB={[v]:t.FUNC_ADD,101:t.FUNC_SUBTRACT,102:t.FUNC_REVERSE_SUBTRACT},$B={200:t.ZERO,201:t.ONE,202:t.SRC_COLOR,[C]: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(qB[e],qB[r]),this.currentBlendEquation=e,this.currentBlendEquationAlpha=r),s===this.currentBlendSrc&&i===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&o===this.currentBlendDstAlpha||(h.blendFuncSeparate($B[s],$B[i],$B[n],$B[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.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)}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 JB{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===Rt)return s.SHORT;if(t===Ct)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===qt)return s.RED_INTEGER;if(t===$t)return s.RG;if(t===Xt)return s.RG_INTEGER;if(t===Jt)return s.RGBA_INTEGER;if(t===Zt||t===Qt||t===Kt||t===te)if(e===Xe){if(r=i.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(t===Zt)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(t===Kt)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===Zt)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===Kt)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===Xe?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(t===ae)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(t===he||t===le||t===ue||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===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(t===le)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(t===ue)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(t===ce)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(t===de)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(t===pe)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(t===me)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(t===ge)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(t===fe)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(t===ye)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(t===xe)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(t===be)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(t===ve)return e===Xe?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(t===Te)return e===Xe?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===Xe?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(36283===t||t===Ae||t===Ne||t===Re){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===Re)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 ZB,QB,KB,tI=!1;class eI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===tI&&(this._init(this.gl),tI=!0)}_init(t){ZB={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},QB={[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},KB={512:t.NEVER,519:t.ALWAYS,[bs]: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?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===Xe&&!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===Xe&&!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,{currentAnisotropy:n}=r.get(e);s.texParameteri(t,s.TEXTURE_WRAP_S,ZB[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,ZB[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,ZB[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,QB[e.magFilter]);const o=e.isVideoTexture||e.minFilter!==Tt?e.minFilter:St;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,QB[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,KB[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||n!==e.anisotropy){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy())),r.get(e).currentAnisotropy=e.anisotropy}}}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),l=i.utils.convert(t.type),u=this.getInternalFormat(t.internalFormat,h,l,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),this.setTextureParameters(d,t),t.isDataArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,u,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,u,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,u,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:l,glInternalFormat:u})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:l}=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,l,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:l}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const u=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),t.isCompressedTexture){const i=t.mipmaps;for(let r=0;r<i.length;r++){const n=i[r];if(t.isCompressedArrayTexture){const i=e.image;t.format!==s.RGBA?null!==a?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,r,0,0,0,n.width,n.height,i.depth,a,n.data,0,0):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,r,0,0,0,n.width,n.height,i.depth,a,h,n.data)}else null!==a?s.compressedTexSubImage2D(s.TEXTURE_2D,r,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=u(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,l,a,h,e.image);else{const t=u(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.framebuffer&&(e.deleteFramebuffer(i.framebuffer),i.framebuffer=void 0),i.depthRenderbuffer&&(e.deleteRenderbuffer(i.depthRenderbuffer),i.depthRenderbuffer=void 0),i.stencilRenderbuffer&&(e.deleteRenderbuffer(i.stencilRenderbuffer),i.stencilRenderbuffer=void 0),i.msaaFrameBuffer&&(e.deleteFramebuffer(i.msaaFrameBuffer),i.msaaFrameBuffer=void 0),i.msaaRenderbuffers){for(let t=0;t<i.msaaRenderbuffers.length;t++)e.deleteRenderbuffer(i.msaaRenderbuffers[t]);i.msaaRenderbuffers=void 0}}}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:l,glType:u,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(l,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,u,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,u,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){const{gl:s}=this,{state:i}=this.backend,{textureGPU:r}=this.backend.get(t),n=t.image.width,o=t.image.height;if(!0===t.isDepthTexture||e.renderTarget&&e.renderTarget.samples>0){let a,h;!0===t.isDepthTexture?(a=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,e.stencil&&(a|=s.STENCIL_BUFFER_BIT)):(a=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0);const l=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,l),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,r,0),s.blitFramebuffer(0,0,n,o,0,0,n,o,a,s.NEAREST),s.deleteFramebuffer(l)}else i.bindTexture(s.TEXTURE_2D,r),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,n,o),i.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:l}=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,l)):s.renderbufferStorage(s.RENDERBUFFER,e,h,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r){const{backend:n,gl:o}=this,{textureGPU:a,glFormat:h,glType:l}=this.backend.get(t),u=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,u),o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);const c=this._getTypedArrayType(l),d=i*r*this._getBytesPerTexel(h),p=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.bufferData(o.PIXEL_PACK_BUFFER,d,o.STREAM_READ),o.readPixels(e,s,i,r,h,l,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await n.utils._clientWaitAsync();const m=new c(d/c.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,m),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(u),m}_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.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t){const{gl:e}=this;return t===e.RGBA?4:t===e.RGB?3:t===e.ALPHA?1:void 0}}class sI{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 iI{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 rI={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 nI{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];for(let t=0;t<i.length;t++)a.update(o,r,n,i[t])}}}class oI extends GB{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 sI(this),this.capabilities=new iI(this),this.attributeUtils=new HB(this),this.textureUtils=new eI(this),this.bufferRenderer=new nI(this),this.state=new YB(this),this.utils=new JB(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===e.trackTimestamp,this.extensions.get("EXT_color_buffer_float"),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 zs}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,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).previousContext,r=t.textures;if(null!==r)for(let t=0;t<r.length;t++){const e=r[t];e.generateMipmaps&&this.generateMipmaps(e)}if(this._currentContext=i,null!==t.textures&&t.renderTarget){const i=this.get(t.renderTarget),{samples:r}=t.renderTarget,n=i.framebuffer,o=e.COLOR_BUFFER_BIT;if(r>0){const r=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,r),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,n);for(let s=0;s<a.length;s++)e.blitFramebuffer(0,0,t.width,t.height,0,0,t.width,t.height,o,e.NEAREST),e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray)}}if(null!==i)if(this._setFramebuffer(i),i.viewport)this.updateViewport(i);else{const t=this.gl;t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)}const n=t.occlusionQueryCount;if(n>0){if(n>this.get(t).occlusionQueryIndex){const{gl:t}=this;t.endQuery(t.ANY_SAMPLES_PASSED)}this.resolveOccludedAsync(t)}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,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;null===i&&(i={textures:null,clearColorValue:this.getClearColor()});let o=0;if(t&&(o|=n.COLOR_BUFFER_BIT),e&&(o|=n.DEPTH_BUFFER_BIT),s&&(o|=n.STENCIL_BUFFER_BIT),0!==o){const a=i.clearColorValue||this.getClearColor();if(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 e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.initTimestampQuery(t)}compute(t,e,s,i){const r=this.gl;this.discard||(r.enable(r.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:n,transformBuffers:o,attributes:a}=this.get(i),h=this._getVaoKey(null,a),l=this.vaoCache[h];void 0===l?this._createVao(null,a):r.bindVertexArray(l),r.useProgram(n),this._bindUniforms(s);const u=this._getTransformFeedback(o);r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,u),r.beginTransformFeedback(r.POINTS),a[0].isStorageInstancedBufferAttribute?r.drawArraysInstanced(r.POINTS,0,1,e.count):r.drawArrays(r.POINTS,0,e.count),r.endTransformFeedback(),r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,null);for(let t=0;t<o.length;t++){const e=o[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)}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);this._bindUniforms(t.getBindings());const l=e.isMesh&&e.matrixWorld.determinant()<0;a.setMaterial(i,l),o.useProgram(n);let u=t.staticVao;if(void 0===u){const e=this._getVaoKey(t.getIndex(),t.getAttributes());if(u=this.vaoCache[e],void 0===u){let e;({vaoGPU:u,staticVao:e}=this._createVao(t.getIndex(),t.getAttributes())),e&&(t.staticVao=u)}}o.bindVertexArray(u);const c=t.getIndex(),d=t.geometry,p=t.drawRange,m=p.start,g=h.lastOcclusionObject;if(g!==e&&void 0!==g){if(null!==g&&!0===g.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 f=this.bufferRenderer;let y;if(e.isPoints?f.mode=o.POINTS:e.isLineSegments?f.mode=o.LINES:e.isLine?f.mode=o.LINE_STRIP:e.isLineLoop?f.mode=o.LINE_LOOP:!0===i.wireframe?(a.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),f.mode=o.LINES):f.mode=o.TRIANGLES,f.object=e,null!==c){const t=this.get(c),e=p.count!==1/0?p.count:c.count;f.index=c.count,f.type=t.type,y=e}else{f.index=0;y=p.count!==1/0?p.count:d.attributes.position.count}const x=this.getInstanceCount(t);e.isBatchedMesh?null!==e._multiDrawInstances?f.renderMultiDrawInstances(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount,e._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?f.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount):ni("THREE.WebGLRenderer: WEBGL_multi_draw not supported."):x>1?f.renderInstances(m,y,x):f.render(m,y),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(t){return t.id}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){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new LB(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 s=this.gl,i=this.get(e),{programGPU:r,fragmentShader:n,vertexShader:o}=i;!1===s.getProgramParameter(r,s.LINK_STATUS)&&this._logProgramError(r,n,o),s.useProgram(r);const a=t.getBindings();this._setupBindings(a,r),this.set(e,{programGPU:r})}createComputePipeline(t,e){const s=this.gl,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:r}=t,n=s.createProgram(),o=this.get(i).shaderGPU,a=this.get(r).shaderGPU,h=r.transforms,l=[],u=[];for(let t=0;t<h.length;t++){const e=h[t];l.push(e.varyingName),u.push(e.attributeNode)}s.attachShader(n,o),s.attachShader(n,a),s.transformFeedbackVaryings(n,l,s.SEPARATE_ATTRIBS),s.linkProgram(n),!1===s.getProgramParameter(n,s.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n),this.createBindings(null,e),this._setupBindings(e,n);const c=r.attributes,d=[],p=[];for(let t=0;t<c.length;t++){const e=c[t].node.attribute;d.push(e),this.has(e)||this.attributeUtils.createAttribute(e,s.ARRAY_BUFFER)}for(let t=0;t<u.length;t++){const e=u[t].attribute;this.has(e)||this.attributeUtils.createAttribute(e,s.ARRAY_BUFFER);const i=this.get(e);p.push(i)}this.set(t,{programGPU:n,transformBuffers:p,attributes:d})}createBindings(t,e){this.updateBindings(t,e)}updateBindings(t,e){const{gl:s}=this;let i=0,r=0;for(const t of e)for(const e of t.bindings)if(e.isUniformsGroup||e.isUniformBuffer){const t=s.createBuffer(),r=e.buffer;s.bindBuffer(s.UNIFORM_BUFFER,t),s.bufferData(s.UNIFORM_BUFFER,r,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,i,t),this.set(e,{index:i++,bufferGPU:t})}else if(e.isSampledTexture){const{textureGPU:t,glTextureType:s}=this.get(e.texture);this.set(e,{index:r++,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(rI).filter((e=>rI[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){this.textureUtils.copyFramebufferToTexture(t,e)}_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,l=this.renderer._activeCubeFace,u=!0===r.isWebGLCubeRenderTarget;let c,d=n.msaaFrameBuffer,p=n.depthRenderbuffer;if(u?(void 0===n.cubeFramebuffers&&(n.cubeFramebuffers=[]),c=n.cubeFramebuffers[l]):c=n.framebuffer,void 0===c){c=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,c);const i=t.textures;if(u){n.cubeFramebuffers[l]=c;const{textureGPU:t}=this.get(i[0]);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+l,t,0)}else{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)}n.framebuffer=c,s.drawBuffers(t,c)}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===d){const i=[];d=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,d);const r=[],l=t.textures;for(let s=0;s<l.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],l=this.get(n);e.renderbufferStorageMultisample(e.RENDERBUFFER,o,l.glInternalFormat,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+s,e.RENDERBUFFER,r[s])}if(n.msaaFrameBuffer=d,n.msaaRenderbuffers=r,void 0===p){p=e.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(p,t),n.depthRenderbuffer=p;const s=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(s)}n.invalidationArray=i}i=n.msaaFrameBuffer}else i=c}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 i=this.gl;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?e.bindBufferBase(e.UNIFORM_BUFFER,r,i.bufferGPU):t.isSampledTexture&&s.bindTexture(i.glTextureType,i.textureGPU,e.TEXTURE0+r)}}}class aI extends TB{constructor(t,e){super(t),this.texture=e,this.version=e?e.version:0,this.isSampler=!0}}class hI extends aI{constructor(t,e,s){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s}update(){this.texture=this.textureNode.value}}class lI extends _B{constructor(t,e){super(t,e?e.array:null),this.attribute=e,this.isStorageBuffer=!0}}let uI=0;class cI extends lI{constructor(t,e){super("StorageBuffer_"+uI++,t?t.value:null),this.nodeUniform=t,this.access=t?t.access:PM,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class dI{constructor(t){this.device=t;this.mipmapSampler=t.createSampler({minFilter:iM}),this.flipYSampler=t.createSampler({minFilter:rM}),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({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:US,stripIndexFormat:QS},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:US,stripIndexFormat:QS},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}),l=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:WM,baseArrayLayer:s}),u=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:WM,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:qS,storeOp:jS,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,l,u),d(a,u,l),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.getTransferPipeline(e.format),r=this.device.createCommandEncoder({}),n=i.getBindGroupLayout(0);let o=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:WM,baseArrayLayer:s});for(let a=1;a<e.mipLevelCount;a++){const e=this.device.createBindGroup({layout:n,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:o}]}),h=t.createView({baseMipLevel:a,mipLevelCount:1,dimension:WM,baseArrayLayer:s}),l=r.beginRenderPass({colorAttachments:[{view:h,loadOp:qS,storeOp:jS,clearValue:[0,0,0,0]}]});l.setPipeline(i),l.setBindGroup(0,e),l.draw(4,1,0,0),l.end(),o=h}this.device.queue.submit([r.finish()])}}const pI={512:"never",[bs]:"less",514:"equal",515:"less-equal",516:"greater",518:"greater-equal",519:"always",517:"not-equal"},mI=[0,1,3,2,4,5];class gI{constructor(t){this.backend=t,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.colorBuffer=null,this.depthTexture=new Za,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=pI[t.compareFunction]),i.sampler=s.createSampler(r)}createDefaultTexture(t){let e;const s=fI(t);e=t.isCubeTexture?this._getDefaultCubeTextureGPU(s):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),l=t.internalFormat||e.format||fI(t,s.device);let u=void 0!==e.sampleCount?e.sampleCount:1;u>1&&(u=Math.pow(2,Math.floor(Math.log2(u))),2===u&&(u=4));const c=t.isRenderTargetTexture?1:u;let d=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===t.isStorageTexture&&(d|=GPUTextureUsage.STORAGE_BINDING),!0!==t.isCompressedTexture&&(d|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:t.name,size:{width:r,height:n,depthOrArrayLayers:o},mipLevelCount:a,sampleCount:c,dimension:h,format:l,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===l)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(t);i.texture=s.device.createTexture(p)}if(t.isRenderTargetTexture&&u>1){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=u,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 this._generateMipmaps(e.texture,e.textureDescriptorGPU)}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.parameters.sampleCount,format:KS.BGRA8Unorm,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.parameters.sampleCount,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)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){const n=this.backend.device,o=this.backend.get(t),a=o.texture,h=o.textureDescriptorGPU.format,l=this._getBytesPerTexel(h);let u=i*l;u=256*Math.ceil(u/256);const c=n.createBuffer({size:i*r*l,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),d=n.createCommandEncoder();d.copyTextureToBuffer({texture:a,origin:{x:e,y:s}},{buffer:c,bytesPerRow:u},{width:i,height:r});const p=this._getTypedArrayType(h);n.queue.submit([d.finish()]),await c.mapAsync(GPUMapMode.READ);return new p(c.getMappedRange())}_isEnvironmentTexture(t){const e=t.mapping;return e===ut||e===ct||e===ht||e===lt}_getDefaultTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const s=new bi;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 Kn;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}_copyCubeMapToTexture(t,e,s,i){for(let r=0;r<6;r++){const n=t[r],o=!0===i?mI[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 dI(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),l=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:l},{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);for(let s=0;s<t.length;s++){const n=t[s],o=n.width,a=n.height,h=Math.ceil(o/r.width)*r.byteLength;i.queue.writeTexture({texture:e,mipLevel:s},n.data,{offset:0,bytesPerRow:h},{width:Math.ceil(o/r.width)*r.width,height:Math.ceil(a/r.width)*r.width,depthOrArrayLayers:1})}}_getBlockData(t){return t===KS.BC1RGBAUnorm||t===KS.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:t===KS.BC2RGBAUnorm||t===KS.BC2RGBAUnormSRGB||t===KS.BC3RGBAUnorm||t===KS.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===KS.BC4RUnorm||t===KS.BC4RSNorm?{byteLength:8,width:4,height:4}:t===KS.BC5RGUnorm||t===KS.BC5RGSnorm||t===KS.BC6HRGBUFloat||t===KS.BC6HRGBFloat||t===KS.BC7RGBAUnorm||t===KS.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===KS.ETC2RGB8Unorm||t===KS.ETC2RGB8UnormSRGB||t===KS.ETC2RGB8A1Unorm||t===KS.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:t===KS.ETC2RGBA8Unorm||t===KS.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:t===KS.EACR11Unorm||t===KS.EACR11Snorm?{byteLength:8,width:4,height:4}:t===KS.EACRG11Unorm||t===KS.EACRG11Snorm||t===KS.ASTC4x4Unorm||t===KS.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:t===KS.ASTC5x4Unorm||t===KS.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:t===KS.ASTC5x5Unorm||t===KS.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:t===KS.ASTC6x5Unorm||t===KS.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:t===KS.ASTC6x6Unorm||t===KS.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:t===KS.ASTC8x5Unorm||t===KS.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:t===KS.ASTC8x6Unorm||t===KS.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:t===KS.ASTC8x8Unorm||t===KS.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:t===KS.ASTC10x5Unorm||t===KS.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:t===KS.ASTC10x6Unorm||t===KS.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:t===KS.ASTC10x8Unorm||t===KS.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:t===KS.ASTC10x10Unorm||t===KS.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:t===KS.ASTC12x10Unorm||t===KS.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:t===KS.ASTC12x12Unorm||t===KS.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(t){let e=tM;return t===pt?e=eM:t===gt&&(e=sM),e}_convertFilterMode(t){let e=iM;return t!==ft&&t!==yt&&t!==bt||(e=rM),e}_getBytesPerTexel(t){return t===KS.R8Unorm||t===KS.R8Snorm||t===KS.R8Uint||t===KS.R8Sint?1:t===KS.R16Uint||t===KS.R16Sint||t===KS.R16Float||t===KS.RG8Unorm||t===KS.RG8Snorm||t===KS.RG8Uint||t===KS.RG8Sint?2:t===KS.R32Uint||t===KS.R32Sint||t===KS.R32Float||t===KS.RG16Uint||t===KS.RG16Sint||t===KS.RG16Float||t===KS.RGBA8Unorm||t===KS.RGBA8UnormSRGB||t===KS.RGBA8Snorm||t===KS.RGBA8Uint||t===KS.RGBA8Sint||t===KS.BGRA8Unorm||t===KS.BGRA8UnormSRGB||t===KS.RGB9E5UFloat||t===KS.RGB10A2Unorm||t===KS.RG11B10UFloat||t===KS.Depth32Float||t===KS.Depth24Plus||t===KS.Depth24PlusStencil8||t===KS.Depth32FloatStencil8?4:t===KS.RG32Uint||t===KS.RG32Sint||t===KS.RG32Float||t===KS.RGBA16Uint||t===KS.RGBA16Sint||t===KS.RGBA16Float?8:t===KS.RGBA32Uint||t===KS.RGBA32Sint||t===KS.RGBA32Float?16:void 0}_getTypedArrayType(t){return t===KS.R8Uint?Uint8Array:t===KS.R8Sint?Int8Array:t===KS.R8Unorm?Uint8Array:t===KS.R8Snorm?Int8Array:t===KS.RG8Uint?Uint8Array:t===KS.RG8Sint?Int8Array:t===KS.RG8Unorm?Uint8Array:t===KS.RG8Snorm?Int8Array:t===KS.RGBA8Uint?Uint8Array:t===KS.RGBA8Sint?Int8Array:t===KS.RGBA8Unorm?Uint8Array:t===KS.RGBA8Snorm?Int8Array:t===KS.R16Uint?Uint16Array:t===KS.R16Sint?Int16Array:t===KS.RG16Uint?Uint16Array:t===KS.RG16Sint?Int16Array:t===KS.RGBA16Uint?Uint16Array:t===KS.RGBA16Sint?Int16Array:t===KS.R16Float||t===KS.RG16Float||t===KS.RGBA16Float?Float32Array:t===KS.R32Uint?Uint32Array:t===KS.R32Sint?Int32Array:t===KS.R32Float?Float32Array:t===KS.RG32Uint?Uint32Array:t===KS.RG32Sint?Int32Array:t===KS.RG32Float?Float32Array:t===KS.RGBA32Uint?Uint32Array:t===KS.RGBA32Sint?Int32Array:t===KS.RGBA32Float?Float32Array:t===KS.BGRA8Unorm||t===KS.BGRA8UnormSRGB?Uint8Array:t===KS.RGB10A2Unorm||t===KS.RGB9E5UFloat||t===KS.RG11B10UFloat?Uint32Array:t===KS.Depth32Float?Float32Array:t===KS.Depth24Plus||t===KS.Depth24PlusStencil8?Uint32Array:t===KS.Depth32FloatStencil8?Float32Array:void 0}_getDimension(t){let e;return e=t.isData3DTexture?GM:kM,e}}function fI(t,e=null){const s=t.format,i=t.type,r=t.colorSpace;let n;if(!0===t.isFramebufferTexture&&t.type===At)n=KS.BGRA8Unorm;else if(!0===t.isCompressedTexture)switch(s){case Qt:n=r===Xe?KS.BC1RGBAUnormSRGB:KS.BC1RGBAUnorm;break;case Kt:n=r===Xe?KS.BC2RGBAUnormSRGB:KS.BC2RGBAUnorm;break;case te:n=r===Xe?KS.BC3RGBAUnormSRGB:KS.BC3RGBAUnorm;break;case oe:n=r===Xe?KS.ETC2RGB8UnormSRGB:KS.ETC2RGB8Unorm;break;case ae:n=r===Xe?KS.ETC2RGBA8UnormSRGB:KS.ETC2RGBA8Unorm;break;case he:n=r===Xe?KS.ASTC4x4UnormSRGB:KS.ASTC4x4Unorm;break;case le:n=r===Xe?KS.ASTC5x4UnormSRGB:KS.ASTC5x4Unorm;break;case ue:n=r===Xe?KS.ASTC5x5UnormSRGB:KS.ASTC5x5Unorm;break;case ce:n=r===Xe?KS.ASTC6x5UnormSRGB:KS.ASTC6x5Unorm;break;case de:n=r===Xe?KS.ASTC6x6UnormSRGB:KS.ASTC6x6Unorm;break;case pe:n=r===Xe?KS.ASTC8x5UnormSRGB:KS.ASTC8x5Unorm;break;case me:n=r===Xe?KS.ASTC8x6UnormSRGB:KS.ASTC8x6Unorm;break;case ge:n=r===Xe?KS.ASTC8x8UnormSRGB:KS.ASTC8x8Unorm;break;case fe:n=r===Xe?KS.ASTC10x5UnormSRGB:KS.ASTC10x5Unorm;break;case ye:n=r===Xe?KS.ASTC10x6UnormSRGB:KS.ASTC10x6Unorm;break;case xe:n=r===Xe?KS.ASTC10x8UnormSRGB:KS.ASTC10x8Unorm;break;case be:n=r===Xe?KS.ASTC10x10UnormSRGB:KS.ASTC10x10Unorm;break;case ve:n=r===Xe?KS.ASTC12x10UnormSRGB:KS.ASTC12x10Unorm;break;case Te:n=r===Xe?KS.ASTC12x12UnormSRGB:KS.ASTC12x12Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}else switch(s){case Dt:switch(i){case Nt:n=KS.RGBA8Snorm;break;case Rt:n=KS.RGBA16Sint;break;case Ct:n=KS.RGBA16Uint;break;case Bt:n=KS.RGBA32Uint;break;case Et:n=KS.RGBA32Sint;break;case At:n=r===Xe?KS.RGBA8UnormSRGB:KS.RGBA8Unorm;break;case Pt:n=KS.RGBA16Float;break;case It:n=KS.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",i)}break;case Vt:if(i===zt)n=KS.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",i);break;case Ht:switch(i){case Nt:n=KS.R8Snorm;break;case Rt:n=KS.R16Sint;break;case Ct:n=KS.R16Uint;break;case Bt:n=KS.R32Uint;break;case Et:n=KS.R32Sint;break;case At:n=KS.R8Unorm;break;case Pt:n=KS.R16Float;break;case It:n=KS.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",i)}break;case $t:switch(i){case Nt:n=KS.RG8Snorm;break;case Rt:n=KS.RG16Sint;break;case Ct:n=KS.RG16Uint;break;case Bt:n=KS.RG32Uint;break;case Et:n=KS.RG32Sint;break;case At:n=KS.RG8Unorm;break;case Pt:n=KS.RG16Float;break;case It:n=KS.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",i)}break;case Wt:switch(i){case Ct:n=KS.Depth16Unorm;break;case Bt:n=KS.Depth24Plus;break;case It:n=KS.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",i)}break;case jt:switch(i){case Ot:n=KS.Depth24PlusStencil8;break;case It:e&&!1===e.features.has(JM.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),n=KS.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",i)}break;case qt:switch(i){case Et:n=KS.R32Sint;break;case Bt:n=KS.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",i)}break;case Xt:switch(i){case Et:n=KS.RG32Sint;break;case Bt:n=KS.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",i)}break;case Jt:switch(i){case Et:n=KS.RGBA32Sint;break;case Bt:n=KS.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",i)}break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}return n}const yI=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,xI=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,bI={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_2d:"texture",texture_cube:"cubeTexture",texture_depth_2d:"depthTexture",texture_storage_2d:"storageTexture",texture_3d:"texture3D"};class vI extends OC{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(yI);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=xI.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=bI[r]||r,n.push(new H_(r,e))}const o=t.substring(e[0].length),a=e[3]||"void",h=void 0!==e[1]?e[1]:"";return{type:bI[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 TI extends UC{parseFunction(t){return new vI(t)}}const _I=self.GPUShaderStage,wI={vertex:_I?_I.VERTEX:1,fragment:_I?_I.FRAGMENT:2,compute:_I?_I.COMPUTE:4},SI={instance:!0,swizzleAssign:!1,storageBuffer:!0},MI={"^^":"threejs_xor"},AI={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>"},NI={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"threejs_mod_float",mod_vec2:"threejs_mod_vec2",mod_vec3:"threejs_mod_vec3",mod_vec4:"threejs_mod_vec4",equals_bool:"threejs_equals_bool",equals_bvec2:"threejs_equals_bvec2",equals_bvec3:"threejs_equals_bvec3",equals_bvec4:"threejs_equals_bvec4",lessThanEqual:"threejs_lessThanEqual",greaterThan:"threejs_greaterThan",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"},RI={threejs_xor:new Gg("\nfn threejs_xor( a : bool, b : bool ) -> bool {\n\n\treturn ( a || b ) && !( a && b );\n\n}\n"),lessThanEqual:new Gg("\nfn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {\n\n\treturn vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );\n\n}\n"),greaterThan:new Gg("\nfn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {\n\n\treturn vec3<bool>( a.x > b.x, a.y > b.y, a.z > b.z );\n\n}\n"),mod_float:new Gg("fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new Gg("fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new Gg("fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new Gg("fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new Gg("fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new Gg("fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new Gg("fn threejs_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 Gg("fn threejs_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 Gg("\nfn threejs_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 Gg("\nfn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( textureDimensions( map, level ) );\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 ) ), level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")};class CI extends W_{constructor(t,e){super(t,e,new TI),this.uniformGroups={},this.builtins={}}needsColorSpaceToLinear(t){return!0===t.isVideoTexture&&t.colorSpace!==$e}_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"),`threejs_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, threejs_repeatWrapping( ${s}, ${`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)||!0===t.isDataTexture&&t.type===It}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}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=MI[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case OM:return"read";case UM:return"write";default:return"read_write"}else switch(t.access){case PM:return"read_write";case FM: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 BB(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new IB(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new PB(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(wI[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new hI(`${r.name}_sampler`,r.node,o);t.setVisibility(wI[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?cI:MB)(t,o);r.setVisibility(wI[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new RB(a,o),n.setVisibility(wI[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}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));return`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n\treturn ${s.result};\n\n}`}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xyz"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}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")}getAttributes(t){const e=[];if("compute"===t&&this.getBuiltin("global_invocation_id","id","vec3<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(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;if("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;`)),!0===e.isCubeTexture)i="texture_cube<f32>";else if(!0===e.isDataArrayTexture)i="texture_2d_array<f32>";else if(!0===e.isDepthTexture)i="texture_depth_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<${fI(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture_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?", "+s:"",a=`\t${r.name} : array< ${e}${n} >\n`,h=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,a,h,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:{}};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);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 AI[t]||t}isAvailable(t){let e=SI[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),SI[t]=e),e}_getWGSLMethod(t){return void 0!==RI[t]&&this._include(t),NI[t]}_include(t){const e=RI[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\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\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// system\nvar<private> instanceIndex : u32;\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;\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 EI{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=KS.Depth24PlusStencil8:t.depth&&(e=KS.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).texture.format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):KS.BGRA8Unorm,e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?BS:t.isLineSegments||t.isMesh&&!0===e.wireframe?IS:t.isLine?PS:t.isMesh?FS:void 0}getSampleCount(t){return null!==t.textures?t.sampleCount:this.backend.parameters.sampleCount}}const BI=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),II=new Map([[mn,["float16"]]]),PI=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class FI{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?YM:XM):(t=i.itemSize*r,e=i.isInstancedBufferAttribute?YM:XM),!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)),r=i.buffer,n=r.size;let o=i.readBuffer,a=!0;void 0===o&&(o=s.createBuffer({label:t.name,size:n,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=!1,i.readBuffer=o);const h=s.createCommandEncoder({});h.copyBufferToBuffer(r,0,o,0,n),a&&o.unmap();const l=h.finish();s.queue.submit([l]),await o.mapAsync(GPUMapMode.READ);return o.getMappedRange()}_getVertexFormat(t){const{itemSize:e,normalized:s}=t,i=t.array.constructor,r=t.constructor;let n;if(1==e)n=PI.get(i);else{const t=(II.get(r)||BI.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 UI{constructor(t){this.backend=t}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(e.texture.isDepthTexture)s.sampleType=LM;else if(e.texture.isDataTexture){const t=e.texture.type;t===Et?s.sampleType=VM:t===Bt?s.sampleType=DM:t===It&&(s.sampleType=zM)}e.isSampledCubeTexture?s.viewDimension=HM:e.texture.isDataArrayTexture?s.viewDimension=jM:e.isSampledTexture3D&&(s.viewDimension=qM),t.texture=s}else console.error(`WebGPUBindingUtils: Unsupported binding "${e}".`);s.push(t)}return e.createBindGroupLayout({entries:s})}createBindings(t){const e=this.backend.get(t),s=this.createBindingsLayout(t),i=this.createBindGroup(t,s);e.layout=s,e.group=i}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,a;if(o=e.isSampledCubeTexture?HM:e.isSampledTexture3D?qM:e.texture.isDataArrayTexture?jM:WM,void 0!==t.externalTexture)a=i.importExternalTexture({source:t.externalTexture});else{const s=$M;a=t.texture.createView({aspect:s,dimension:o,mipLevelCount:e.store?1:t.mipLevelCount})}n.push({binding:r,resource:a})}r++}return i.createBindGroup({label:"bindGroup_"+t.name,layout:e,entries:n})}}class OI{constructor(t){this.backend=t}_getSampleCount(t){let e=this.backend.utils.getSampleCount(t);return e>1&&(e=Math.pow(2,Math.floor(Math.log2(e))),2===e&&(e=4)),e}createRenderPipeline(t,e){const{object:s,material:i,geometry:r,pipeline:n}=t,{vertexProgram:o,fragmentProgram:a}=n,h=this.backend,l=h.device,u=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=u.getTextureFormatGPU(e[t]);x.push({format:s,blend:g,writeMask:y})}}else{const e=u.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=u.getCurrentDepthStencilFormat(t.context),S=this._getSampleCount(t.context),M={label:"renderPipeline",vertex:Object.assign({},b,{buffers:p}),fragment:Object.assign({},v,{targets:x}),primitive:T,depthStencil:{format:w,depthWriteEnabled:i.depthWrite,depthCompare:_,stencilFront:f,stencilBack:{},stencilReadMask:i.stencilFuncMask,stencilWriteMask:i.stencilWriteMask},multisample:{count:S,alphaToCoverageEnabled:i.alphaToCoverage},layout:l.createPipelineLayout({bindGroupLayouts:d})};if(null===e)c.pipeline=l.createRenderPipeline(M);else{const t=new Promise((t=>{l.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t,e){const s=this.backend,{utils:i,device:r}=s,n=s.get(t),o=s.get(e),a=i.getCurrentDepthStencilFormat(t),h={label:"renderBundleEncoder",colorFormats:[i.getCurrentColorFormat(t)],depthStencilFormat:a,sampleCount:this._getSampleCount(e.context)},l=r.createRenderBundleEncoder(h);return o.bundleEncoder=l,n.currentSets={attributes:{}},n._renderBundleViewport=t.width+"_"+t.height,l}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:xM},s={srcFactor:r,dstFactor:n,operation:xM}};if(t.premultipliedAlpha)switch(i){case 1:r(lM,uM,oM,uM);break;case 2:r(lM,oM,oM,oM);break;case 3:r(nM,hM,nM,oM);break;case 4:r(nM,aM,nM,lM)}else switch(i){case 1:r(lM,uM,oM,uM);break;case 2:r(lM,oM,lM,oM);break;case 3:r(nM,hM,nM,oM);break;case 4:r(nM,aM,nM,aM)}}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=nM;break;case 201:e=oM;break;case 202:e=aM;break;case 203:e=hM;break;case C:e=lM;break;case E:e=uM;break;case 208:e=cM;break;case 209:e=dM;break;case 206:e=pM;break;case 207:e=mM;break;case 210:e=gM;break;case 211:e=fM;break;case 212:e=yM;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=OS;break;case ys:e=WS;break;case 513:e=zS;break;case 515:e=VS;break;case 514:e=LS;break;case 518:e=GS;break;case 516:e=DS;break;case 517:e=kS;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case is:e=MM;break;case 0:e=AM;break;case 7681:e=NM;break;case 5386:e=RM;break;case 7682:e=CM;break;case 7683:e=EM;break;case 34055:e=BM;break;case 34056:e=IM;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=xM;break;case 101:e=bM;break;case 102:e=vM;break;case 103:e=TM;break;case 104:e=_M;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?ZS:QS),s.side){case c:i.frontFace=$S,i.cullMode=JS;break;case d:i.frontFace=$S,i.cullMode=YS;break;case 2:i.frontFace=$S,i.cullMode=XS;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?SM:wM}_getDepthCompare(t){let e;if(!1===t.depthTest)e=WS;else{const s=t.depthFunc;switch(s){case 0:e=OS;break;case 1:e=WS;break;case 2:e=zS;break;case 3:e=VS;break;case 4:e=LS;break;case 5:e=GS;break;case 6:e=DS;break;case 7:e=kS;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class zI extends GB{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.antialias=!0===t.antialias,!0===this.parameters.antialias?this.parameters.sampleCount=void 0===t.sampleCount?4:t.sampleCount:this.parameters.sampleCount=1,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 EI(this),this.attributeUtils=new FI(this),this.bindingUtils=new UI(this),this.pipelineUtils=new OI(this),this.textureUtils=new gI(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(JM),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.context.configure({device:this.device,format:KS.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Ls}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;const e=this.parameters.antialias;if(null===t){const s=this.renderer;t={colorAttachments:[{view:null}],depthStencilAttachment:{view:this.textureUtils.getDepthBuffer(s.depth,s.stencil).createView()}};const i=t.colorAttachments[0];!0===e?i.view=this.colorBuffer.createView():i.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const s=t.colorAttachments[0];return!0===e?s.resolveTarget=this.context.getCurrentTexture().createView():s.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;void 0===i&&(i=[],s.descriptors=i),s.width===e.width&&s.height===e.height&&s.activeMipmapLevel===e.activeMipmapLevel&&s.samples===e.samples||(i.length=0);let r=i[t.activeCubeFace];if(void 0===r){const n=t.textures,o=[];for(let e=0;e<n.length;e++){const s=this.get(n[e]),i=s.texture.createView({baseMipLevel:t.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:t.activeCubeFace,dimension:WM});let r,a;void 0!==s.msaaTexture?(r=s.msaaTexture.createView(),a=i):(r=i,a=void 0),o.push({view:r,resolveTarget:a,loadOp:HS,storeOp:jS})}r={colorAttachments:o,depthStencilAttachment:{view:this.get(t.depthTexture).texture.createView()}},i[t.activeCubeFace]=r,s.width=e.width,s.height=e.height,s.samples=e.samples,s.activeMipmapLevel=e.activeMipmapLevel}return r}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=t.clearColorValue,i.loadOp=qS,i.storeOp=jS):(i.loadOp=HS,i.storeOp=jS)}}else{const e=n.colorAttachments[0];t.clearColor?(e.clearValue=t.clearColorValue,e.loadOp=qS,e.storeOp=jS):(e.loadOp=HS,e.storeOp=jS)}t.depth&&(t.clearDepth?(o.depthClearValue=t.clearDepthValue,o.depthLoadOp=qS,o.depthStoreOp=jS):(o.depthLoadOp=HS,o.depthStoreOp=jS)),t.stencil&&(t.clearStencil?(o.stencilClearValue=t.clearStencilValue,o.stencilLoadOp=qS,o.stencilStoreOp=jS):(o.stencilLoadOp=HS,o.stencilStoreOp=jS));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:{}},t.viewport&&this.updateViewport(t),t.scissor){const{x:e,y:s,width:i,height:r}=t.scissorValue;h.setScissorRect(e,t.height-r-s,i,r)}}finishRender(t){const e=this.get(t),s=t.occlusionQueryCount;if(void 0!==e.renderBundles&&e.renderBundles.length>0&&(e.registerBundlesPhase=!1,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,t.height-n-i,r,n,o,a)}clear(t,e,s,i=null){const r=this.device,n=this.renderer;let o,a,h,l,u=[];if(t){const t=this.getClearColor();a={r:t.r,g:t.g,b:t.b,a:t.a}}if(null===i){h=n.depth,l=n.stencil;const e=this._getDefaultRenderPassDescriptor();if(t){u=e.colorAttachments;const t=u[0];t.clearValue=a,t.loadOp=qS,t.storeOp=jS}(h||l)&&(o=e.depthStencilAttachment)}else{if(h=i.depth,l=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),u.push({view:i,resolveTarget:r,clearValue:a,loadOp:qS,storeOp:jS})}if(h||l){o={view:this.get(i.depthTexture).texture.createView()}}}h&&(e?(o.depthLoadOp=qS,o.depthClearValue=n.getClearDepth(),o.depthStoreOp=jS):(o.depthLoadOp=HS,o.depthStoreOp=jS)),l&&(s?(o.stencilLoadOp=qS,o.stencilClearValue=n.getClearStencil(),o.stencilStoreOp=jS):(o.stencilLoadOp=HS,o.stencilStoreOp=jS));const c=r.createCommandEncoder({});c.beginRenderPass({colorAttachments:u,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)}r.dispatchWorkgroups(e.dispatchCount)}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,geometry:i,context:r,pipeline:n}=t,o=t.getBindings(),a=this.get(r),h=this.get(n).pipeline,l=a.currentSets,u=this.get(t),{bundleEncoder:c,renderBundle:d,lastPipelineGPU:p}=u,m=this.get(r);if(!0===m.registerBundlesPhase&&void 0!==c&&p===h)return void m.renderBundles.push(d);const g=this.renderer._currentRenderBundle?this.createBundleEncoder(r,t):a.currentPass;l.pipeline!==h&&(g.setPipeline(h),l.pipeline=h);for(let t=0,e=o.length;t<e;t++){const e=o[t],s=this.get(e);g.setBindGroup(t,s.group)}const f=t.getIndex(),y=null!==f;if(!0===y&&l.index!==f){const t=this.get(f).buffer,e=f.array instanceof Uint16Array?ZS:QS;g.setIndexBuffer(t,e),l.index=f}const x=t.getVertexBuffers();for(let t=0,e=x.length;t<e;t++){const e=x[t];if(l.attributes[t]!==e){const s=this.get(e).buffer;g.setVertexBuffer(t,s),l.attributes[t]=e}}if(void 0!==a.occlusionQuerySet){const t=a.lastOcclusionObject;t!==s&&(null!==t&&!0===t.occlusionTest&&(g.endOcclusionQuery(),a.occlusionQueryIndex++),!0===s.occlusionTest&&(g.beginOcclusionQuery(a.occlusionQueryIndex),a.occlusionQueryObjects[a.occlusionQueryIndex]=s),a.lastOcclusionObject=s)}const b=t.drawRange,v=b.start,T=this.getInstanceCount(t);if(0!==T){if(!0===s.isBatchedMesh){const t=s._multiDrawStarts,e=s._multiDrawCounts,i=s._multiDrawCount,r=s._multiDrawInstances,n=f.bytesPerElement||1;for(let s=0;s<i;s++){const i=r?r[s]:1,o=i>1?0:s;g.drawIndexed(e[s]/n,i,t[s]/4,0,o)}}else if(!0===y){const t=b.count!==1/0?b.count:f.count;g.drawIndexed(t,T,v,0,0),e.update(s,t,T)}else{const t=i.attributes.position,r=b.count!==1/0?b.count:t.count;g.draw(r,T,v,0),e.update(s,r,T)}if(this.renderer._currentRenderBundle){const t=g.finish();u.lastPipelineGPU=h,u.renderBundle=t,u.bundleEncoder=g}}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCount(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),l=r.getPrimitiveTopology(s,i);let u=!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===l&&e.clippingContextVersion===t.clippingContextVersion||(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=l,e.clippingContextVersion=t.clippingContextVersion,u=!0),u}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.getSampleCount(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContextVersion].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){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}initTimestampQuery(t,e){if(!this.hasFeature(JM.TimestampQuery)||!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.hasFeature(JM.TimestampQuery)||!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.hasFeature(JM.TimestampQuery)||!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 CI(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)}createBundleEncoder(t,e){return this.pipelineUtils.createBundleEncoder(t,e)}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,l=t.image.width,u=t.image.height;null!==s&&(a=s.x,h=s.y,l=s.width,u=s.height),null!==i&&(n=i.x,o=i.y);const c=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),d=this.get(t).texture,p=this.get(e).texture;c.copyTextureToTexture({texture:d,mipLevel:r,origin:{x:a,y:h,z:0}},{texture:p,mipLevel:r,origin:{x:n,y:o,z:0}},[l,u]),this.device.queue.submit([c.finish()])}copyFramebufferToTexture(t,e){const s=this.get(e),{encoder:i,descriptor:r}=s;let n=null;n=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 o=this.get(t).texture;n.format===o.format?(s.currentPass.end(),i.copyTextureToTexture({texture:n,origin:{x:0,y:0,z:0}},{texture:o},[t.image.width,t.image.height]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t),r.colorAttachments[0].loadOp=HS,e.depth&&(r.depthStencilAttachment.depthLoadOp=HS),e.stencil&&(r.depthStencilAttachment.stencilLoadOp=HS),s.currentPass=i.beginRenderPass(r),s.currentSets={attributes:{}}):console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,o.format)}}class LI extends vB{constructor(t={}){let e;t.forceWebGL?e=oI:xd.isAvailable()?e=zI:(e=oI,console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."));super(new e(t),t),this.isWebGPURenderer=!0}}const VI=new nS(new XT);class DI{constructor(t,e=gm(0,0,1,1)){this.renderer=t,this.outputNode=e}render(){VI.material.fragmentNode=this.outputNode,VI.render(this.renderer)}renderAsync(){return VI.material.fragmentNode=this.outputNode,VI.renderAsync(this.renderer)}set needsUpdate(t){VI.material.needsUpdate=t}}class kI extends bi{constructor(t=1,e=1){super(),this.image={width:t,height:e},this.magFilter=Tt,this.minFilter=Tt,this.isStorageTexture=!0}}class GI extends on{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageBufferAttribute=!0}}class WI extends Go{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageInstancedBufferAttribute=!0}}"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,Av as AONode,v as AddEquation,J as AddOperation,Ve as AdditiveAnimationBlendMode,f as AdditiveBlending,cN as AfterImageNode,it as AgXToneMapping,Lt as AlphaFormat,Ms as AlwaysCompare,k as AlwaysDepth,ys as AlwaysStencilFunc,Cu as AmbientLight,aR as AmbientLightNode,vv as AnalyticLightNode,mN as AnamorphicNode,bc as AnimationAction,Ql as AnimationClip,au as AnimationLoader,Tc as AnimationMixer,xc as AnimationObjectGroup,Vl as AnimationUtils,th as ArcCurve,Yu as ArrayCamera,up as ArrayElementNode,pd as ArrowHelper,Om as AssignNode,nt as AttachedBindMode,Dm as AttributeNode,ic as Audio,lc as AudioAnalyser,Wu as AudioContext,sc as AudioListener,ju as AudioLoader,md as AxesHelper,kR as BRDF_GGX,AR as BRDF_Lambert,d as BackSide,We as BasicDepthPacking,a as BasicShadowMap,tv as BatchNode,_a as BatchedMesh,dA as BlendModeNode,zo as Bone,Hl as BooleanKeyframeTrack,Fc as Box2,Bi as Box3,hd as Box3Helper,Wn as BoxGeometry,ad as BoxHelper,hv as Break,on as BufferAttribute,kb as BufferAttributeNode,wn as BufferGeometry,Ou as BufferGeometryLoader,rx as BufferNode,bA as BumpMapNode,Gm as BypassNode,Nt as ByteType,tu as Cache,jm as CacheNode,qn as Camera,rd as CameraHelper,Ja as CanvasTexture,Th as CapsuleGeometry,oh as CatmullRomCurve3,uR as CheckerNode,tt as CineonToneMapping,_h as CircleGeometry,mt as ClampToEdgeWrapping,Ju as Clock,Gg as CodeNode,$r as Color,SA as ColorAdjustmentNode,ql as ColorKeyframeTrack,ui as ColorManagement,jy as ColorSpaceNode,Xa as CompressedArrayTexture,Ya as CompressedCubeTexture,$a as CompressedTexture,hu as CompressedTextureLoader,$N as ComputeNode,Dv as CondNode,Sh as ConeGeometry,yp as ConstNode,L as ConstantAlphaFactor,O as ConstantColorFactor,qm as ContextNode,av as Continue,cp as ConvertNode,Qn as CubeCamera,ht as CubeReflectionMapping,lt as CubeRefractionMapping,Kn as CubeTexture,uu as CubeTextureLoader,fv as CubeTextureNode,dt as CubeUVReflectionMapping,uh as CubicBezierCurve,ch as CubicBezierCurve3,kl as CubicInterpolant,r as CullFaceBack,n as CullFaceFront,o as CullFaceFrontBack,i as CullFaceNone,Qa as Curve,xh as CurvePath,b as CustomBlending,st as CustomToneMapping,wh as CylinderGeometry,Ic as Cylindrical,GR as DFGApprox,LR as D_GGX,Mi as Data3DTexture,wi as DataArrayTexture,Lo as DataTexture,cu as DataTextureLoader,sn as DataUtils,os as DecrementStencilOp,hs as DecrementWrapStencilOp,su as DefaultLoadingManager,Wt as DepthFormat,xN as DepthOfFieldNode,jt as DepthStencilFormat,Za as DepthTexture,ot as DetachedBindMode,Ru as DirectionalLight,ed as DirectionalLightHelper,KN as DirectionalLightNode,nw as DiscardNode,Wl as DiscreteInterpolant,Je as DisplayP3ColorSpace,Ah as DodecahedronGeometry,vN as DotScreenNode,p as DoubleSide,B as DstAlphaFactor,P as DstColorFactor,Ps as DynamicCopyUsage,Ns as DynamicDrawUsage,Es as DynamicReadUsage,If as EPSILON,Bh as EdgesGeometry,Ka as EllipseCurve,pT as EnvironmentNode,vs as EqualCompare,j as EqualDepth,ds as EqualStencilFunc,m_ as EquirectUVNode,ut as EquirectangularReflectionMapping,ct as EquirectangularRefractionMapping,mr as Euler,Vs as EventDispatcher,Jy as ExpressionNode,al as ExtrudeGeometry,MR as F_Schlick,ou as FileLoader,SN as FilmNode,mn as Float16BufferAttribute,gn as Float32BufferAttribute,It as FloatType,so as Fog,eo as FogExp2,kN as FogExp2Node,zN as FogNode,VN as FogRangeNode,qa as FramebufferTexture,jT as FrontFacingNode,c as FrontSide,ia as Frustum,RN as FunctionCallNode,$g as FunctionNode,lw as FunctionOverloadingNode,Ac as GLBufferAttribute,Us as GLSL1,Os as GLSL3,kC as GLSLNodeParser,aN as GaussianBlurNode,_s as GreaterCompare,q as GreaterDepth,Ss as GreaterEqualCompare,H as GreaterEqualDepth,fs as GreaterEqualStencilFunc,ms as GreaterStencilFunc,Jc as GridHelper,ja as Group,Pt as HalfFloatType,Y_ as HashNode,mu as HemisphereLight,Yc as HemisphereLightHelper,hR as HemisphereLightNode,nR as IESSpotLight,oR as IESSpotLightNode,Pf as INFINITY,ll as IcosahedronGeometry,tm as If,ku as ImageBitmapLoader,lu as ImageLoader,mi as ImageUtils,ns as IncrementStencilOp,as as IncrementWrapStencilOp,Ym as IndexNode,qb as InstanceNode,Go as InstancedBufferAttribute,Uu as InstancedBufferGeometry,Mc as InstancedInterleavedBuffer,Jo as InstancedMesh,mR as InstancedPointsNodeMaterial,un as Int16BufferAttribute,dn as Int32BufferAttribute,an as Int8BufferAttribute,Et as IntType,ro as InterleavedBuffer,oo as InterleavedBufferAttribute,Dl as Interpolant,Ie as InterpolateDiscrete,Pe as InterpolateLinear,Fe as InterpolateSmooth,ls as InvertStencilOp,fT as IrradianceNode,dp as JoinNode,is as KeepStencilOp,jl as KeyframeTrack,Ao as LOD,vh as LatheGeometry,gr as Layers,bs as LessCompare,G as LessDepth,Ts as LessEqualCompare,W as LessEqualDepth,ps as LessEqualStencilFunc,cs as LessStencilFunc,pu as Light,YN as LightNode,Iu as LightProbe,Nv as LightingContextNode,Km as LightingModel,xv as LightingNode,_v as LightsNode,Ba as Line,vR as Line2NodeMaterial,zc as Line3,wa as LineBasicMaterial,fR as LineBasicNodeMaterial,dh as LineCurve,ph as LineCurve3,Pl as LineDashedMaterial,xR as LineDashedNodeMaterial,Oa as LineLoop,Ua as LineSegments,Ze as LinearDisplayP3ColorSpace,Tt as LinearFilter,Gl as LinearInterpolant,Mt as LinearMipMapLinearFilter,wt as LinearMipMapNearestFilter,St as LinearMipmapLinearFilter,_t as LinearMipmapNearestFilter,Ye as LinearSRGBColorSpace,Q as LinearToneMapping,Qe as LinearTransfer,iu as Loader,Fu as LoaderUtils,eu as LoadingManager,nv as LoopNode,Ce as LoopOnce,Be as LoopPingPong,Ee as LoopRepeat,Gt as LuminanceAlphaFormat,kt as LuminanceFormat,AN as Lut3DNode,e as MOUSE,dw as MatcapUVNode,Jr as Material,Pu as MaterialLoader,Jx as MaterialNode,px as MaterialReferenceNode,Bf as MathNode,Js as MathUtils,Qs as Matrix3,rr as Matrix4,S as MaxEquation,Qy as MaxMipLevelNode,kn as Mesh,Zr as MeshBasicMaterial,SR as MeshBasicNodeMaterial,El as MeshDepthMaterial,Bl as MeshDistanceMaterial,Cl as MeshLambertMaterial,BR as MeshLambertNodeMaterial,Il as MeshMatcapMaterial,wC as MeshMatcapNodeMaterial,Rl as MeshNormalMaterial,_R as MeshNormalNodeMaterial,Al as MeshPhongMaterial,PR as MeshPhongNodeMaterial,Ml as MeshPhysicalMaterial,gC as MeshPhysicalNodeMaterial,yC as MeshSSSNodeMaterial,Sl as MeshStandardMaterial,pC as MeshStandardNodeMaterial,Nl as MeshToonMaterial,TC as MeshToonNodeMaterial,w as MinEquation,gt as MirroredRepeatWrapping,Y as MixOperation,Px as ModelNode,Vb as ModelViewProjectionNode,dv 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,xs as NeverCompare,D as NeverDepth,us as NeverStencilFunc,m as NoBlending,$e as NoColorSpace,Z as NoToneMapping,op as Node,sg as NodeAttribute,W_ as NodeBuilder,lg as NodeCache,og as NodeCode,j_ as NodeFrame,H_ as NodeFunctionInput,ag as NodeKeywords,dR as NodeLoader,XT as NodeMaterial,PC as NodeMaterialLoader,FC as NodeObjectLoader,jd as NodeShaderStage,qd as NodeType,ig as NodeUniform,Hd as NodeUpdateType,ip as NodeUtils,rg as NodeVar,ng as NodeVarying,Le as NormalAnimationBlendMode,g as NormalBlending,IA as NormalMapNode,ws as NotEqualCompare,$ as NotEqualDepth,gs as NotEqualStencilFunc,$l as NumberKeyframeTrack,Br as Object3D,Mx as Object3DNode,zu as ObjectLoader,qe as ObjectSpaceNormalMap,ul as OctahedronGeometry,A as OneFactor,V as OneMinusConstantAlphaFactor,z as OneMinusConstantColorFactor,I as OneMinusDstAlphaFactor,F as OneMinusDstColorFactor,E as OneMinusSrcAlphaFactor,R as OneMinusSrcColorFactor,lf as OperatorNode,Au as OrthographicCamera,bw as OscNode,$_ as OutputStructNode,es as P3Primaries,h as PCFShadowMap,l as PCFSoftShadowMap,Ff as PI,Uf as PI2,B_ as PMREMGenerator,uT as PMREMNode,Sw as PackingNode,Dg as ParameterNode,eN as PassNode,bh as Path,Jn as PerspectiveCamera,CR as PhongLightingModel,cC as PhysicalLightingModel,ta as Plane,cl as PlaneGeometry,ld as PlaneHelper,Mu as PointLight,Hc as PointLightHelper,QN as PointLightNode,AS as PointUVNode,Ga as Points,za as PointsMaterial,MC as PointsNodeMaterial,Zc as PolarGridHelper,Mh as PolyhedronGeometry,hc as PositionalAudio,DI as PostProcessing,FA as PosterizeNode,yc as PropertyBinding,uc as PropertyMixer,ug as PropertyNode,nS as QuadMesh,mh as QuadraticBezierCurve,gh as QuadraticBezierCurve3,Ni as Quaternion,Yl as QuaternionKeyframeTrack,Xl as QuaternionLinearInterpolant,Ne as RED_GREEN_RGTC2_Format,Me as RED_RGTC1_Format,t as REVISION,je as RGBADepthPacking,Dt as RGBAFormat,Jt 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,le as RGBA_ASTC_5x4_Format,ue 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,Qt as RGBA_S3TC_DXT1_Format,Kt as RGBA_S3TC_DXT3_Format,te as RGBA_S3TC_DXT5_Format,Vt as RGBFormat,Yt as RGBIntegerFormat,_N as RGBShiftNode,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,Zt as RGB_S3TC_DXT1_Format,$t as RGFormat,Xt as RGIntegerFormat,hS as RTTNode,HN as RangeNode,wl as RawShaderMaterial,ir as Ray,Rc as Raycaster,ts as Rec709Primaries,Eu as RectAreaLight,iR as RectAreaLightNode,Ht as RedFormat,qt as RedIntegerFormat,ux as ReferenceNode,eS as ReflectorNode,K as ReinhardToneMapping,Nw as RemapNode,Ti as RenderTarget,dS as RendererReferenceNode,pt as RepeatWrapping,rs as ReplaceStencilOp,hw as Return,_ as ReverseSubtractEquation,dl as RingGeometry,Iw as RotateNode,Ew as RotateUVNode,Re as SIGNED_RED_GREEN_RGTC2_Format,Ae as SIGNED_RED_RGTC1_Format,Xe as SRGBColorSpace,Ke as SRGBTransfer,io as Scene,RS as SceneNode,jR as Schlick_to_F0,UN as ScriptableNode,EN as ScriptableValueNode,gp as SetNode,Hn as ShaderMaterial,Hp as ShaderNode,_l as ShadowMaterial,EC as ShadowNodeMaterial,Ih as Shape,pl as ShapeGeometry,gd as ShapePath,rl as ShapeUtils,Rt as ShortType,ko as Skeleton,Wc as SkeletonHelper,Oo as SkinnedMesh,sv as SkinningNode,fN as SobelOperatorNode,fi as Source,Yi as Sphere,ml as SphereGeometry,Bc as Spherical,Bu as SphericalHarmonics3,fh as SplineCurve,mp as SplitNode,vu as SpotLight,Vc as SpotLightHelper,rR as SpotLightNode,_o as Sprite,ao as SpriteMaterial,NC as SpriteNodeMaterial,Fw as SpriteSheetUVNode,C as SrcAlphaFactor,U as SrcAlphaSaturateFactor,N as SrcColorFactor,d_ as StackNode,Is as StaticCopyUsage,As as StaticDrawUsage,Cs as StaticReadUsage,Xu as StereoCamera,Ow as StorageArrayElementNode,GI as StorageBufferAttribute,ZM as StorageBufferNode,WI as StorageInstancedBufferAttribute,kI as StorageTexture,tA as StorageTextureNode,Fs as StreamCopyUsage,Rs as StreamDrawUsage,Bs as StreamReadUsage,Jl as StringKeyframeTrack,T as SubtractEquation,y as SubtractiveBlending,Ov as TBNViewMatrix,s as TOUCH,He as TangentSpaceNormalMap,lp as TempNode,gl as TetrahedronGeometry,bi as Texture,rA as Texture3DNode,SS as TextureBicubicNode,du as TextureLoader,tx as TextureNode,af as TextureSizeNode,mw as TimerNode,$A as ToneMappingNode,fl as TorusGeometry,yl as TorusKnotGeometry,Gr as Triangle,Ge as TriangleFanDrawMode,ke as TriangleStripDrawMode,De as TrianglesDrawMode,Lw as TriplanarTexturesNode,xl as TubeGeometry,at as UVMapping,cn as Uint16BufferAttribute,pn as Uint32BufferAttribute,hn as Uint8BufferAttribute,ln as Uint8ClampedBufferAttribute,_c as Uniform,Zg as UniformGroupNode,rf as UniformNode,Sc as UniformsGroup,ax as UniformsNode,At as UnsignedByteType,Ot as UnsignedInt248Type,zt as UnsignedInt5999Type,Bt as UnsignedIntType,Ft as UnsignedShort4444Type,Ut as UnsignedShort5551Type,Ct as UnsignedShortType,oA as UserDataNode,u as VSMShadowMap,OR as V_GGX_SmithCorrelated,tg as VarNode,Lm as VaryingNode,Zs as Vector2,Ri as Vector3,vi as Vector4,Zl as VectorKeyframeTrack,uS as VertexColorNode,Ha as VideoTexture,FT as ViewportDepthNode,IT as ViewportDepthTextureNode,bT as ViewportNode,ZA as ViewportSharedTextureNode,RT as ViewportTextureNode,BC as VolumeNodeMaterial,Ai as WebGL3DRenderTarget,Si as WebGLArrayRenderTarget,zs as WebGLCoordinateSystem,to as WebGLCubeRenderTarget,fd as WebGLMultipleRenderTargets,_i as WebGLRenderTarget,Ls as WebGPUCoordinateSystem,LI as WebGPURenderer,bl as WireframeGeometry,ze as WrapAroundEnding,Ue as ZeroCurvatureEnding,M as ZeroFactor,Oe as ZeroSlopeEnding,ss as ZeroStencilOp,iy as abs,ey as acos,uf as add,Mv as addLightNode,ap as addNodeClass,vp as addNodeElement,YT as addNodeMaterial,dN as afterImage,Of as all,wg as alphaT,gN as anamorphic,Tf as and,Sg as anisotropy,Ag as anisotropyB,Mg as anisotropyT,zf as any,em as append,Im as arrayBuffer,ty as asin,zm as assign,sy as atan,fy as atan2,km as attribute,CS as backgroundBlurriness,ES as backgroundIntensity,ev as batch,Mf as bitAnd,Af as bitNot,Nf as bitOr,Rf as bitXor,Ev as bitangentGeometry,Bv as bitangentLocal,Iv as bitangentView,Pv as bitangentWorld,my as bitcast,aT as blur,_m as bmat2,Am as bmat3,Em as bmat4,om as bool,nx as buffer,Gb as bufferAttribute,vA as bumpMap,pA as burn,um as bvec2,mm as bvec3,xm as bvec4,Wm as bypass,Hm as cache,CN as call,yx as cameraFar,xx as cameraLogDepth,fx as cameraNear,wx as cameraNormalMatrix,Sx as cameraPosition,bx as cameraProjectionMatrix,vx as cameraProjectionMatrixInverse,Tx as cameraViewMatrix,_x as cameraWorldMatrix,By as cbrt,Xf as ceil,cR as checker,Fy as clamp,fg as clearcoat,yg as clearcoatRoughness,Wg as code,sm as color,$y as colorSpaceToLinear,Aw as colorToDirection,XN as compute,kv as cond,$m as context,Fm as convert,Qf as cos,ii as createCanvasElement,hp as createNodeFromType,JT as createNodeMaterialFromType,My as cross,yv as cubeTexture,hy as dFdx,ly as dFdy,Bg as dashSize,Xd as defaultBuildStages,$d as defaultShaderStages,Wp as defined,Df as degrees,GN as densityFog,DT as depth,rN as depthPass,wy as difference,pg as diffuseColor,Mw as directionToColor,aw as discard,_y as distance,pf as div,mA as dodge,bN as dof,Sy as dot,TN as dotScreen,Qm as drawIndex,Wb as dynamicBufferAttribute,Pm as element,gf as equal,Lf as equals,g_ as equirectUV,kf as exp,Gf as exp2,Zy as expression,qT as faceDirection,Ly as faceForward,MN as film,im as float,$f as floor,LN as fog,Jf as fract,tf as frameGroup,xw as frameId,HT as frontFacing,py as fwidth,Q_ as gain,Ig as gapSize,hN as gaussianBlur,jp as getConstNodeType,Kp as getCurrentStack,iT as getDirection,ZN as getDistanceAttenuation,FR as getGeometryRoughness,UR as getRoughness,FN as global,qg as glsl,Yg as glslFn,xf as greaterThan,vf as greaterThanEqual,J_ as hash,NA as hue,vm as imat2,Sm as imat3,Rm as imat4,$b as instance,Zm as instanceIndex,jb as instancedBufferAttribute,Hb as instancedDynamicBufferAttribute,rm as int,qf as inverseSqrt,vg as iridescence,Tg as iridescenceIOR,_g as iridescenceThickness,hm as ivec2,dm as ivec3,fm as ivec4,jg as js,Xm as label,ny as length,Iy as lengthSq,yf as lessThan,bf as lessThanEqual,JN as lightTargetDirection,Rv as lightingContext,wv as lights,Sv as lightsNode,kT as linearDepth,qy as linearToColorSpace,Xy as linearTosRGB,Wf as log,jf as log2,ov as loop,RA as lumaCoeffs,CA as luminance,NN as lut3D,bm as mat2,wm as mat3,Nm as mat4,pw as matcapUV,Zx as materialAlphaTest,fb as materialAnisotropy,Ib as materialAnisotropyVector,ub as materialClearcoat,db as materialClearcoatNormal,cb as materialClearcoatRoughness,Qx as materialColor,Bb as materialDispersion,tb as materialEmissive,yb as materialIridescence,xb as materialIridescenceIOR,bb as materialIridescenceThickness,Cb as materialLineDashOffset,Ab as materialLineDashSize,Nb as materialLineGapSize,Mb as materialLineScale,Rb as materialLineWidth,hb as materialMetalness,lb as materialNormal,eb as materialOpacity,Eb as materialPointWidth,mx as materialReference,ob as materialReflectivity,pb as materialRotation,ab as materialRoughness,mb as materialSheen,gb as materialSheenRoughness,Kx as materialShininess,sb as materialSpecular,nb as materialSpecularStrength,xy as max,Ky as maxMipLevel,gg as metalness,yy as min,Py as mix,by as mod,Fx as modelDirection,Ox as modelNormalMatrix,Lx as modelPosition,Vx as modelScale,Ux as modelViewMatrix,Dx as modelViewPosition,Db as modelViewProjection,zx as modelWorldMatrix,kx as modelWorldMatrixInverse,pv as morphReference,df as mul,EE as mx_aastep,qE as mx_cell_noise_float,VE as mx_contrast,$E as mx_fractal_noise_float,XE as mx_fractal_noise_vec2,YE as mx_fractal_noise_vec3,JE as mx_fractal_noise_vec4,NE as mx_hsvtorgb,DE as mx_noise_float,kE as mx_noise_vec3,GE as mx_noise_vec4,IE as mx_ramplr,PE as mx_ramptb,RE as mx_rgbtohsv,LE as mx_safepower,UE as mx_splitlr,OE as mx_splittb,CE as mx_srgb_texture_to_lin_rec709,zE as mx_transform_uv,WE as mx_worley_noise_float,jE as mx_worley_noise_vec2,HE as mx_worley_noise_vec3,oy as negate,Xp as nodeArray,Jp as nodeImmutable,qp as nodeObject,$p as nodeObjects,Yp as nodeProxy,Gx as normalGeometry,Wx as normalLocal,PA as normalMap,jx as normalView,Hx as normalWorld,Yf as normalize,wf as not,Ax as objectDirection,sf as objectGroup,Rx as objectNormalMatrix,Ex as objectPosition,Bx as objectScale,Nx as objectViewMatrix,Ix as objectViewPosition,Cx as objectWorldMatrix,ay as oneMinus,_f as or,OT as orthographicDepthToViewZ,ww as oscSawtooth,vw as oscSine,Tw as oscSquare,_w as oscTriangle,Eg as output,X_ as outputStruct,gA as overlay,cw as overloadingFn,Z_ as parabola,zv as parallaxDirection,Lv as parallaxUV,kg as parameter,sN as pass,K_ as pcurve,LT as perspectiveDepthToViewZ,cT as pmremTexture,NS as pointUV,Pg as pointWidth,Pb as positionGeometry,Fb as positionLocal,zb as positionView,Lb as positionViewDirection,Ub as positionWorld,Ob as positionWorldDirection,UA as posterize,Ay as pow,Ny as pow2,Ry as pow3,Cy as pow4,cg as property,Vf as radians,Vy as rand,qN as range,DN as rangeFog,cy as reciprocal,cx as reference,dx as referenceBuffer,Ty as reflect,gv as reflectVector,mv as reflectView,sS as reflector,Oy as refract,mf as remainder,Rw as remap,Cw as remapClamp,ef as renderGroup,pS as rendererReference,wN as rgbShift,Pw as rotate,Bw as rotateUV,mg as roughness,uy as round,lS as rtt,Yy as sRGBToLinear,ix as sampler,Uy as saturate,MA as saturation,fA as screen,ON as scriptable,BN as scriptableValue,Qp as setCurrentStack,Yd as shaderStages,xg as sheen,bg as sheenRoughness,Cf as shiftLeft,Ef as shiftRight,Cg as shininess,ry as sign,Zf as sin,tw as sinc,iv as skinning,rv as skinningReference,zy as smoothstep,yN as sobel,Ng as specularColor,Um as split,Uw as spritesheetUV,Hf as sqrt,p_ as stack,vy as step,QM as storage,KM as storageObject,eA as storageTexture,Bm as string,cf as sub,Kf as tan,Xb as tangentGeometry,Yb as tangentLocal,Jb as tangentView,Zb as tangentWorld,eg as temp,ex as texture,nA as texture3D,MS as textureBicubic,rT as textureCubeUV,sx as textureLoad,iN as texturePass,hf as textureSize,sA as textureStore,EA as threshold,yw as timerDelta,fw as timerGlobal,gw as timerLocal,XA as toneMapping,Ey as transformDirection,Vv as transformedBentNormalView,Fv as transformedBitangentView,Uv as transformedBitangentWorld,Xx as transformedClearcoatNormalView,qx as transformedNormalView,$x as transformedNormalWorld,Qb as transformedTangentView,Kb as transformedTangentWorld,gy as transpose,iw as triNoise3D,Dw as triplanarTexture,Vw as triplanarTextures,dy as trunc,Zp as tslFn,nm as uint,Tm as umat2,Mm as umat3,Cm as umat4,nf as uniform,Qg as uniformGroup,hx as uniforms,aA as userData,of as uv,lm as uvec2,pm as uvec3,ym as uvec4,Vm as varying,dg as varyingProperty,am as vec2,cm as vec3,gm as vec4,Jd as vectorComponents,cS as vertexColor,Jm as vertexIndex,AA as vibrance,UT as viewZToOrthographicDepth,zT as viewZToPerspectiveDepth,_T as viewport,ST as viewportBottomLeft,AT as viewportBottomRight,vT as viewportCoordinate,PT as viewportDepthTexture,GT as viewportLinearDepth,ET as viewportMipTexture,TT as viewportResolution,QA as viewportSharedTexture,CT as viewportTexture,wT as viewportTopLeft,MT as viewportTopRight,Hg as wgsl,Jg as wgslFn,Sf as xor};
|