@tomorrowevening/hermes 0.1.36 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ var Wc=Object.defineProperty;var Gc=(r,t,e)=>t in r?Wc(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var v=(r,t,e)=>Gc(r,typeof t!="symbol"?t+"":t,e);import{r as I,j as _,L as Oe,B as ti,F as qn,a as Io,M as F,b as ei,c as qh,S as Yc,D as cr,G as $c,C as ws,P as Po,N as Xc,u as Ms,v as Zc,d as wr,p as qc,e as Qc,f as an,g as Gt,h as Jc,i as ma,k as Kc,m as Sr,l as fa,n as tu,o as ga,q as ya,s as eu,t as xa,I as su,w as iu,x as nu,y as ru,z as Qn,T as Y,A as Lt,E as ou,H as _a,J as Ns,K as _e,O as xo,Q as au,R as xt,U as hu,V as lu,Z as Qh,W as Jh,X as Kh,Y as tl,_ as el,$ as sl,a0 as il,a1 as nl,a2 as rl,a3 as ol,a4 as cu,a5 as al,a6 as hl,a7 as ll,a8 as cl,a9 as uu,aa as du,ab as pu,ac as mu,ad as fu,ae as gu,af as yu,ag as xu,ah as _u,ai as Tu,aj as vu,ak as Ta,al as _o,am as ur,an as U,ao as ul,ap as Cu,aq as ye,ar as Gi,as as si,at as Yt,au as Dt,av as hn,aw as mi,ax as dl,ay as bu,az as is,aA as va,aB as wu,aC as qs,aD as Su,aE as Mu,aF as Nu,aG as Au,aH as Eu,aI as Ou,aJ as Ru,aK as Li,aL as ln,aM as Iu,aN as Ca,aO as ba,aP as Pu,aQ as Lu,aR as Fu,aS as zu,aT as Du,aU as Bu,aV as ku,aW as Uu,aX as Vu,aY as wa,aZ as Sa,a_ as cn,a$ as Hu,b0 as ju,b1 as Wu,b2 as Gu,b3 as Yu,b4 as $u,b5 as Xu,b6 as Zu}from"./index-BlO94fgk.js";const pl=I.forwardRef((r,t)=>_.jsxs("div",{className:"editor",ref:t,style:r.style,children:[r.header&&_.jsx("div",{className:"header",children:r.header}),r.children,r.footer&&_.jsx("div",{className:"footer",children:r.footer})]}));pl.displayName="Editor";class qu extends Oe{constructor(t,e){const s=[1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],i=new ti;i.setAttribute("position",new qn(s,3)),i.computeBoundingSphere();const n=new Io({fog:!1});super(i,n),this.light=t,this.color=e,this.type="RectAreaLightHelper";const o=[1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],a=new ti;a.setAttribute("position",new qn(o,3)),a.computeBoundingSphere(),this.add(new F(a,new ei({side:qh,fog:!1})))}updateMatrixWorld(){if(this.scale.set(.5*this.light.width,.5*this.light.height,1),this.color!==void 0)this.material.color.set(this.color),this.children[0].material.color.set(this.color);else{this.material.color.copy(this.light.color).multiplyScalar(this.light.intensity);const t=this.material.color,e=Math.max(t.r,t.g,t.b);e>1&&t.multiplyScalar(1/e),this.children[0].material.color.copy(this.material.color)}this.matrixWorld.extractRotation(this.light.matrixWorld).scale(this.scale).copyPosition(this.light.matrixWorld),this.children[0].matrixWorld.copy(this.matrixWorld)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}}const To=0,dr=1,Qu=2,Ju=0,Ma=1,Na=100,Aa=204,Ea=205,Oa=3,ml=0,Ku=1,td=2,vo=0,fl=300,Lo=301,gl=302,yl=303,xl=304,Ra=1e3,Oi=1001,Ia=1002,as=1003,Jn=1006,Fo=1008,ed=1009,sd=1013,_l=1014,Tl=1015,id=1016,nd=1023,Pa=1026,rd=1027,od=1030,ad=37490,hd=36285,Mr=0,ld=1,Kn="",xe="srgb",La="srgb-linear",Fa="linear",Fi="srgb",Nr="",vl="rg",cd="ga",As=7680,za=519,ud=513,ii=35044,Co=35048,je=2e3,ni=2001,dd={TEXTURE_COMPARE:"depthTextureCompare"};function pd(r){for(let t=r.length-1;t>=0;--t)if(r[t]>=65535)return!0;return!1}function Da(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}const Ba={};function bo(...r){const t="THREE."+r.shift();console.log(t,...r)}function Cl(r){const t=r[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=r[1];e&&e.isStackTrace?r[0]+=" "+e.getLocation():r[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return r}function W(...r){r=Cl(r);const t="THREE."+r.shift();{const e=r[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...r)}}function rt(...r){r=Cl(r);const t="THREE."+r.shift();{const e=r[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...r)}}function Yi(...r){const t=r.join(" ");t in Ba||(Ba[t]=!0,W(...r))}const Ft=["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 ka=1234567;const zi=Math.PI/180,tr=180/Math.PI;function Ge(){const r=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(Ft[r&255]+Ft[r>>8&255]+Ft[r>>16&255]+Ft[r>>24&255]+"-"+Ft[t&255]+Ft[t>>8&255]+"-"+Ft[t>>16&15|64]+Ft[t>>24&255]+"-"+Ft[e&63|128]+Ft[e>>8&255]+"-"+Ft[e>>16&255]+Ft[e>>24&255]+Ft[s&255]+Ft[s>>8&255]+Ft[s>>16&255]+Ft[s>>24&255]).toLowerCase()}function X(r,t,e){return Math.max(t,Math.min(e,r))}function zo(r,t){return(r%t+t)%t}function ys(r,t,e,s,i){return s+(r-t)*(i-s)/(e-t)}function md(r,t,e){return r!==t?(e-r)/(t-r):0}function ns(r,t,e){return(1-e)*r+e*t}function fd(r,t,e,s){return ns(r,t,1-Math.exp(-e*s))}function gd(r,t=1){return t-Math.abs(zo(r,t*2)-t)}function yd(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*(3-2*r))}function xd(r,t,e){return r<=t?0:r>=e?1:(r=(r-t)/(e-t),r*r*r*(r*(r*6-15)+10))}function _d(r,t){return r+Math.floor(Math.random()*(t-r+1))}function Td(r,t){return r+Math.random()*(t-r)}function vd(r){return r*(.5-Math.random())}function Cd(r){r!==void 0&&(ka=r);let t=ka+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function er(r){return r*zi}function bl(r){return r*tr}function bd(r){return(r&r-1)===0&&r!==0}function wd(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function Sd(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function Md(r,t,e,s,i){const n=Math.cos,o=Math.sin,a=n(e/2),h=o(e/2),l=n((t+s)/2),c=o((t+s)/2),u=n((t-s)/2),d=o((t-s)/2),p=n((s-t)/2),m=o((s-t)/2);switch(i){case"XYX":r.set(a*c,h*u,h*d,a*l);break;case"YZY":r.set(h*d,a*c,h*u,a*l);break;case"ZXZ":r.set(h*u,h*d,a*c,a*l);break;case"XZX":r.set(a*c,h*m,h*p,a*l);break;case"YXY":r.set(h*p,a*c,h*m,a*l);break;case"ZYZ":r.set(h*m,h*p,a*c,a*l);break;default:W("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function Te(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function st(r,t){switch(t.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Nd={DEG2RAD:zi,RAD2DEG:tr,generateUUID:Ge,clamp:X,euclideanModulo:zo,mapLinear:ys,inverseLerp:md,lerp:ns,damp:fd,pingpong:gd,smoothstep:yd,smootherstep:xd,randInt:_d,randFloat:Td,randFloatSpread:vd,seededRandom:Cd,degToRad:er,radToDeg:bl,isPowerOfTwo:bd,ceilPowerOfTwo:wd,floorPowerOfTwo:Sd,setQuaternionFromProperEuler:Md,normalize:st,denormalize:Te};/*!
2
+ * camera-controls
3
+ * https://github.com/yomotsu/camera-controls
4
+ * (c) 2017 @yomotsu
5
+ * Released under the MIT License.
6
+ */const mt={LEFT:1,RIGHT:2,MIDDLE:4},w=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Es={NONE:0,IN:1,OUT:-1};function cs(r){return r.isPerspectiveCamera}function es(r){return r.isOrthographicCamera}const Os=Math.PI*2,Ua=Math.PI/2,wl=1e-5,fi=Math.PI/180;function me(r,t,e){return Math.max(t,Math.min(e,r))}function ht(r,t=wl){return Math.abs(r)<t}function et(r,t,e=wl){return ht(r-t,e)}function Va(r,t){return Math.round(r/t)*t}function gi(r){return isFinite(r)?r:r<0?-Number.MAX_VALUE:Number.MAX_VALUE}function yi(r){return Math.abs(r)<Number.MAX_VALUE?r:r*(1/0)}function un(r,t,e,s,i=1/0,n){s=Math.max(1e-4,s);const o=2/s,a=o*n,h=1/(1+a+.48*a*a+.235*a*a*a);let l=r-t;const c=t,u=i*s;l=me(l,-u,u),t=r-l;const d=(e.value+o*l)*n;e.value=(e.value-o*d)*h;let p=t+(l+d)*h;return c-r>0==p>c&&(p=c,e.value=(p-c)/n),p}function Ha(r,t,e,s,i=1/0,n,o){s=Math.max(1e-4,s);const a=2/s,h=a*n,l=1/(1+h+.48*h*h+.235*h*h*h);let c=t.x,u=t.y,d=t.z,p=r.x-c,m=r.y-u,f=r.z-d;const y=c,g=u,x=d,C=i*s,b=C*C,A=p*p+m*m+f*f;if(A>b){const j=Math.sqrt(A);p=p/j*C,m=m/j*C,f=f/j*C}c=r.x-p,u=r.y-m,d=r.z-f;const N=(e.x+a*p)*n,E=(e.y+a*m)*n,O=(e.z+a*f)*n;e.x=(e.x-a*N)*l,e.y=(e.y-a*E)*l,e.z=(e.z-a*O)*l,o.x=c+(p+N)*l,o.y=u+(m+E)*l,o.z=d+(f+O)*l;const P=y-r.x,k=g-r.y,$=x-r.z,ct=o.x-y,tt=o.y-g,it=o.z-x;return P*ct+k*tt+$*it>0&&(o.x=y,o.y=g,o.z=x,e.x=(o.x-y)/n,e.y=(o.y-g)/n,e.z=(o.z-x)/n),o}function Ar(r,t){t.set(0,0),r.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=r.length,t.y/=r.length}function Er(r,t){return es(r)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}let Ad=class{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners[t];if(i!==void 0){const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const i=s.slice(0);for(let n=0,o=i.length;n<o;n++)i[n].call(this,t)}}};var Or;const Ed="2.10.1",dn=1/8,Od=/Mac/.test((Or=globalThis==null?void 0:globalThis.navigator)===null||Or===void 0?void 0:Or.platform);let V,ja,pn,Rr,$t,G,J,Rs,xi,be,we,us,Wa,Ga,ee,_i,Is,Ya,Ir,$a,Pr,Lr,mn;class Re extends Ad{static install(t){V=t.THREE,ja=Object.freeze(new V.Vector3(0,0,0)),pn=Object.freeze(new V.Vector3(0,1,0)),Rr=Object.freeze(new V.Vector3(0,0,1)),$t=new V.Vector2,G=new V.Vector3,J=new V.Vector3,Rs=new V.Vector3,xi=new V.Vector3,be=new V.Vector3,we=new V.Vector3,us=new V.Vector3,Wa=new V.Vector3,Ga=new V.Vector3,ee=new V.Spherical,_i=new V.Spherical,Is=new V.Box3,Ya=new V.Box3,Ir=new V.Sphere,$a=new V.Quaternion,Pr=new V.Quaternion,Lr=new V.Matrix4,mn=new V.Raycaster}static get ACTION(){return w}set verticalDragToForward(t){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=w.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Es.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new V.Vector3,this._focalOffsetVelocity=new V.Vector3,this._zoomVelocity={value:0},this._truckInternal=(g,x,C,b)=>{let A,N;if(cs(this._camera)){const E=G.copy(this._camera.position).sub(this._target),O=this._camera.getEffectiveFOV()*fi,P=E.length()*Math.tan(O*.5);A=this.truckSpeed*g*P/this._elementRect.height,N=this.truckSpeed*x*P/this._elementRect.height}else if(es(this._camera)){const E=this._camera;A=this.truckSpeed*g*(E.right-E.left)/E.zoom/this._elementRect.width,N=this.truckSpeed*x*(E.top-E.bottom)/E.zoom/this._elementRect.height}else return;b?(C?this.setFocalOffset(this._focalOffsetEnd.x+A,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(A,0,!0),this.forward(-N,!0)):C?this.setFocalOffset(this._focalOffsetEnd.x+A,this._focalOffsetEnd.y+N,this._focalOffsetEnd.z,!0):this.truck(A,N,!0)},this._rotateInternal=(g,x)=>{const C=Os*this.azimuthRotateSpeed*g/this._elementRect.height,b=Os*this.polarRotateSpeed*x/this._elementRect.height;this.rotate(C,b,!0)},this._dollyInternal=(g,x,C)=>{const b=Math.pow(.95,-g*this.dollySpeed),A=this._sphericalEnd.radius,N=this._sphericalEnd.radius*b,E=me(N,this.minDistance,this.maxDistance),O=E-N;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(N,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(O,!0),this._dollyToNoClamp(E,!0)):this._dollyToNoClamp(E,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?N:E)-A,this._dollyControlCoord.set(x,C)),this._lastDollyDirection=Math.sign(-g)},this._zoomInternal=(g,x,C)=>{const b=Math.pow(.95,g*this.dollySpeed),A=this._zoom,N=this._zoom*b;this.zoomTo(N,!0),this.dollyToCursor&&(this._changedZoom+=N-A,this._dollyControlCoord.set(x,C))},typeof V>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new V.Quaternion().setFromUnitVectors(this._camera.up,pn),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=w.NONE,this._target=new V.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new V.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new V.Spherical().setFromVector3(G.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new V.Vector3,new V.Vector3,new V.Vector3,new V.Vector3],this._updateNearPlaneCorners(),this._boundary=new V.Box3(new V.Vector3(-1/0,-1/0,-1/0),new V.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new V.Vector2,this.mouseButtons={left:w.ROTATE,middle:w.DOLLY,right:w.TRUCK,wheel:cs(this._camera)?w.DOLLY:es(this._camera)?w.ZOOM:w.NONE},this.touches={one:w.TOUCH_ROTATE,two:cs(this._camera)?w.TOUCH_DOLLY_TRUCK:es(this._camera)?w.TOUCH_ZOOM_TRUCK:w.NONE,three:w.TOUCH_TRUCK};const s=new V.Vector2,i=new V.Vector2,n=new V.Vector2,o=g=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const b=this._domElement.getBoundingClientRect(),A=g.clientX/b.width,N=g.clientY/b.height;if(A<this._interactiveArea.left||A>this._interactiveArea.right||N<this._interactiveArea.top||N>this._interactiveArea.bottom)return}const x=g.pointerType!=="mouse"?null:(g.buttons&mt.LEFT)===mt.LEFT?mt.LEFT:(g.buttons&mt.MIDDLE)===mt.MIDDLE?mt.MIDDLE:(g.buttons&mt.RIGHT)===mt.RIGHT?mt.RIGHT:null;if(x!==null){const b=this._findPointerByMouseButton(x);b&&this._disposePointer(b)}if((g.buttons&mt.LEFT)===mt.LEFT&&this._lockedPointer)return;const C={pointerId:g.pointerId,clientX:g.clientX,clientY:g.clientY,deltaX:0,deltaY:0,mouseButton:x};this._activePointers.push(C),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,d(g)},a=g=>{g.cancelable&&g.preventDefault();const x=g.pointerId,C=this._lockedPointer||this._findPointerById(x);if(C){if(C.clientX=g.clientX,C.clientY=g.clientY,C.deltaX=g.movementX,C.deltaY=g.movementY,this._state=0,g.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(g.buttons&mt.LEFT)===mt.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(g.buttons&mt.MIDDLE)===mt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(g.buttons&mt.RIGHT)===mt.RIGHT&&(this._state=this._state|this.mouseButtons.right);p()}},h=g=>{const x=this._findPointerById(g.pointerId);if(!(x&&x===this._lockedPointer)){if(x&&this._disposePointer(x),g.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=w.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=w.NONE;m()}};let l=-1;const c=g=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===w.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const N=this._domElement.getBoundingClientRect(),E=g.clientX/N.width,O=g.clientY/N.height;if(E<this._interactiveArea.left||E>this._interactiveArea.right||O<this._interactiveArea.top||O>this._interactiveArea.bottom)return}if(g.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===w.ROTATE||this.mouseButtons.wheel===w.TRUCK){const N=performance.now();l-N<1e3&&this._getClientRect(this._elementRect),l=N}const x=Od?-1:-3,C=g.deltaMode===1||g.ctrlKey?g.deltaY/x:g.deltaY/(x*10),b=this.dollyToCursor?(g.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(g.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case w.ROTATE:{this._rotateInternal(g.deltaX,g.deltaY),this._isUserControllingRotate=!0;break}case w.TRUCK:{this._truckInternal(g.deltaX,g.deltaY,!1,!1),this._isUserControllingTruck=!0;break}case w.SCREEN_PAN:{this._truckInternal(g.deltaX,g.deltaY,!1,!0),this._isUserControllingTruck=!0;break}case w.OFFSET:{this._truckInternal(g.deltaX,g.deltaY,!0,!1),this._isUserControllingOffset=!0;break}case w.DOLLY:{this._dollyInternal(-C,b,A),this._isUserControllingDolly=!0;break}case w.ZOOM:{this._zoomInternal(-C,b,A),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},u=g=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Re.ACTION.NONE){const x=g instanceof PointerEvent?g.pointerId:0,C=this._findPointerById(x);C&&this._disposePointer(C),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h);return}g.preventDefault()}},d=g=>{if(!this._enabled)return;if(Ar(this._activePointers,$t),this._getClientRect(this._elementRect),s.copy($t),i.copy($t),this._activePointers.length>=2){const C=$t.x-this._activePointers[1].clientX,b=$t.y-this._activePointers[1].clientY,A=Math.sqrt(C*C+b*b);n.set(0,A);const N=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,E=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(N,E)}if(this._state=0,!g)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in g&&g.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(g.buttons&mt.LEFT)===mt.LEFT&&(this._state=this._state|this.mouseButtons.left),(g.buttons&mt.MIDDLE)===mt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(g.buttons&mt.RIGHT)===mt.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&w.ROTATE)===w.ROTATE||(this._state&w.TOUCH_ROTATE)===w.TOUCH_ROTATE||(this._state&w.TOUCH_DOLLY_ROTATE)===w.TOUCH_DOLLY_ROTATE||(this._state&w.TOUCH_ZOOM_ROTATE)===w.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&w.TRUCK)===w.TRUCK||(this._state&w.SCREEN_PAN)===w.SCREEN_PAN||(this._state&w.TOUCH_TRUCK)===w.TOUCH_TRUCK||(this._state&w.TOUCH_SCREEN_PAN)===w.TOUCH_SCREEN_PAN||(this._state&w.TOUCH_DOLLY_TRUCK)===w.TOUCH_DOLLY_TRUCK||(this._state&w.TOUCH_DOLLY_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN||(this._state&w.TOUCH_ZOOM_TRUCK)===w.TOUCH_ZOOM_TRUCK||(this._state&w.TOUCH_ZOOM_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&w.DOLLY)===w.DOLLY||(this._state&w.TOUCH_DOLLY)===w.TOUCH_DOLLY||(this._state&w.TOUCH_DOLLY_TRUCK)===w.TOUCH_DOLLY_TRUCK||(this._state&w.TOUCH_DOLLY_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN||(this._state&w.TOUCH_DOLLY_OFFSET)===w.TOUCH_DOLLY_OFFSET||(this._state&w.TOUCH_DOLLY_ROTATE)===w.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&w.ZOOM)===w.ZOOM||(this._state&w.TOUCH_ZOOM)===w.TOUCH_ZOOM||(this._state&w.TOUCH_ZOOM_TRUCK)===w.TOUCH_ZOOM_TRUCK||(this._state&w.TOUCH_ZOOM_SCREEN_PAN)===w.TOUCH_ZOOM_SCREEN_PAN||(this._state&w.TOUCH_ZOOM_OFFSET)===w.TOUCH_ZOOM_OFFSET||(this._state&w.TOUCH_ZOOM_ROTATE)===w.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&w.OFFSET)===w.OFFSET||(this._state&w.TOUCH_OFFSET)===w.TOUCH_OFFSET||(this._state&w.TOUCH_DOLLY_OFFSET)===w.TOUCH_DOLLY_OFFSET||(this._state&w.TOUCH_ZOOM_OFFSET)===w.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},p=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,Ar(this._activePointers,$t);const x=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,C=x?-x.deltaX:i.x-$t.x,b=x?-x.deltaY:i.y-$t.y;if(i.copy($t),((this._state&w.ROTATE)===w.ROTATE||(this._state&w.TOUCH_ROTATE)===w.TOUCH_ROTATE||(this._state&w.TOUCH_DOLLY_ROTATE)===w.TOUCH_DOLLY_ROTATE||(this._state&w.TOUCH_ZOOM_ROTATE)===w.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(C,b),this._isUserControllingRotate=!0),(this._state&w.DOLLY)===w.DOLLY||(this._state&w.ZOOM)===w.ZOOM){const A=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,N=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,E=this.dollyDragInverted?-1:1;(this._state&w.DOLLY)===w.DOLLY?(this._dollyInternal(E*b*dn,A,N),this._isUserControllingDolly=!0):(this._zoomInternal(E*b*dn,A,N),this._isUserControllingZoom=!0)}if((this._state&w.TOUCH_DOLLY)===w.TOUCH_DOLLY||(this._state&w.TOUCH_ZOOM)===w.TOUCH_ZOOM||(this._state&w.TOUCH_DOLLY_TRUCK)===w.TOUCH_DOLLY_TRUCK||(this._state&w.TOUCH_ZOOM_TRUCK)===w.TOUCH_ZOOM_TRUCK||(this._state&w.TOUCH_DOLLY_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN||(this._state&w.TOUCH_ZOOM_SCREEN_PAN)===w.TOUCH_ZOOM_SCREEN_PAN||(this._state&w.TOUCH_DOLLY_OFFSET)===w.TOUCH_DOLLY_OFFSET||(this._state&w.TOUCH_ZOOM_OFFSET)===w.TOUCH_ZOOM_OFFSET||(this._state&w.TOUCH_DOLLY_ROTATE)===w.TOUCH_DOLLY_ROTATE||(this._state&w.TOUCH_ZOOM_ROTATE)===w.TOUCH_ZOOM_ROTATE){const A=$t.x-this._activePointers[1].clientX,N=$t.y-this._activePointers[1].clientY,E=Math.sqrt(A*A+N*N),O=n.y-E;n.set(0,E);const P=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,k=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&w.TOUCH_DOLLY)===w.TOUCH_DOLLY||(this._state&w.TOUCH_DOLLY_ROTATE)===w.TOUCH_DOLLY_ROTATE||(this._state&w.TOUCH_DOLLY_TRUCK)===w.TOUCH_DOLLY_TRUCK||(this._state&w.TOUCH_DOLLY_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN||(this._state&w.TOUCH_DOLLY_OFFSET)===w.TOUCH_DOLLY_OFFSET?(this._dollyInternal(O*dn,P,k),this._isUserControllingDolly=!0):(this._zoomInternal(O*dn,P,k),this._isUserControllingZoom=!0)}((this._state&w.TRUCK)===w.TRUCK||(this._state&w.TOUCH_TRUCK)===w.TOUCH_TRUCK||(this._state&w.TOUCH_DOLLY_TRUCK)===w.TOUCH_DOLLY_TRUCK||(this._state&w.TOUCH_ZOOM_TRUCK)===w.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(C,b,!1,!1),this._isUserControllingTruck=!0),((this._state&w.SCREEN_PAN)===w.SCREEN_PAN||(this._state&w.TOUCH_SCREEN_PAN)===w.TOUCH_SCREEN_PAN||(this._state&w.TOUCH_DOLLY_SCREEN_PAN)===w.TOUCH_DOLLY_SCREEN_PAN||(this._state&w.TOUCH_ZOOM_SCREEN_PAN)===w.TOUCH_ZOOM_SCREEN_PAN)&&(this._truckInternal(C,b,!1,!0),this._isUserControllingTruck=!0),((this._state&w.OFFSET)===w.OFFSET||(this._state&w.TOUCH_OFFSET)===w.TOUCH_OFFSET||(this._state&w.TOUCH_DOLLY_OFFSET)===w.TOUCH_DOLLY_OFFSET||(this._state&w.TOUCH_ZOOM_OFFSET)===w.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(C,b,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},m=()=>{Ar(this._activePointers,$t),i.copy($t),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",y),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),d())},this.unlockPointer=()=>{var g,x,C;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(g=this._domElement)===null||g===void 0||g.ownerDocument.exitPointerLock(),(x=this._domElement)===null||x===void 0||x.ownerDocument.removeEventListener("pointerlockchange",f),(C=this._domElement)===null||C===void 0||C.ownerDocument.removeEventListener("pointerlockerror",y),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},y=()=>{this.unlockPointer()};this._addAllEventListeners=g=>{this._domElement=g,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",o),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",c,{passive:!1}),this._domElement.addEventListener("contextmenu",u)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",o),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",c,{passive:!1}),this._domElement.removeEventListener("contextmenu",u),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",y))},this.cancel=()=>{this._state!==w.NONE&&(this._state=w.NONE,this._activePointers.length=0,m())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=me(t.width,0,1),this._interactiveArea.height=me(t.height,0,1),this._interactiveArea.x=me(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=me(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const i=me(t,this.minAzimuthAngle,this.maxAzimuthAngle),n=me(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const o=!s||et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(o)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Es.NONE,this._changedDolly=0,this._dollyToNoClamp(me(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const o=this._collisionTest(),a=et(o,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,o)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const n=!e||et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(n)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(xi).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||et(this._target.x,this._targetEnd.x,this.restThreshold)&&et(this._target.y,this._targetEnd.y,this.restThreshold)&&et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=me(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||et(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),be.setFromMatrixColumn(this._camera.matrix,0),we.setFromMatrixColumn(this._camera.matrix,1),be.multiplyScalar(t),we.multiplyScalar(-e);const i=G.copy(be).add(we),n=J.copy(this._targetEnd).add(i);return this.moveTo(n.x,n.y,n.z,s)}forward(t,e=!1){G.setFromMatrixColumn(this._camera.matrix,0),G.crossVectors(this._camera.up,G),G.multiplyScalar(t);const s=J.copy(this._targetEnd).add(G);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return G.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+G.x,this._targetEnd.y+G.y,this._targetEnd.z+G.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const n=G.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const o=!i||et(this._target.x,this._targetEnd.x,this.restThreshold)&&et(this._target.y,this._targetEnd.y,this.restThreshold)&&et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}lookInDirectionOf(t,e,s,i=!1){const a=G.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:n=0,paddingBottom:o=0,paddingTop:a=0}={}){const h=[],l=t.isBox3?Is.copy(t):Is.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const c=Va(this._sphericalEnd.theta,Ua),u=Va(this._sphericalEnd.phi,Ua);h.push(this.rotateTo(c,u,e));const d=G.setFromSpherical(this._sphericalEnd).normalize(),p=$a.setFromUnitVectors(d,Rr),m=et(Math.abs(d.y),1);m&&p.multiply(Pr.setFromAxisAngle(pn,c)),p.multiply(this._yAxisUpSpaceInverse);const f=Ya.makeEmpty();J.copy(l.min).applyQuaternion(p),f.expandByPoint(J),J.copy(l.min).setX(l.max.x).applyQuaternion(p),f.expandByPoint(J),J.copy(l.min).setY(l.max.y).applyQuaternion(p),f.expandByPoint(J),J.copy(l.max).setZ(l.min.z).applyQuaternion(p),f.expandByPoint(J),J.copy(l.min).setZ(l.max.z).applyQuaternion(p),f.expandByPoint(J),J.copy(l.max).setY(l.min.y).applyQuaternion(p),f.expandByPoint(J),J.copy(l.max).setX(l.min.x).applyQuaternion(p),f.expandByPoint(J),J.copy(l.max).applyQuaternion(p),f.expandByPoint(J),f.min.x-=i,f.min.y-=o,f.max.x+=n,f.max.y+=a,p.setFromUnitVectors(Rr,d),m&&p.premultiply(Pr.invert()),p.premultiply(this._yAxisUpSpace);const y=f.getSize(G),g=f.getCenter(J).applyQuaternion(p);if(cs(this._camera)){const x=this.getDistanceToFitBox(y.x,y.y,y.z,s);h.push(this.moveTo(g.x,g.y,g.z,e)),h.push(this.dollyTo(x,e)),h.push(this.setFocalOffset(0,0,0,e))}else if(es(this._camera)){const x=this._camera,C=x.right-x.left,b=x.top-x.bottom,A=s?Math.max(C/y.x,b/y.y):Math.min(C/y.x,b/y.y);h.push(this.moveTo(g.x,g.y,g.z,e)),h.push(this.zoomTo(A,e)),h.push(this.setFocalOffset(0,0,0,e))}return Promise.all(h)}fitToSphere(t,e){const s=[],n="isObject3D"in t?Re.createBoundingSphere(t,Ir):Ir.copy(t);if(s.push(this.moveTo(n.center.x,n.center.y,n.center.z,e)),cs(this._camera)){const o=this.getDistanceToFitSphere(n.radius);s.push(this.dollyTo(o,e))}else if(es(this._camera)){const o=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,h=2*n.radius,l=Math.min(o/h,a/h);s.push(this.zoomTo(l,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,n,o,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Es.NONE,this._changedDolly=0;const h=J.set(i,n,o),l=G.set(t,e,s);this._targetEnd.copy(h),this._sphericalEnd.setFromVector3(l.sub(h).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const c=!a||et(this._target.x,this._targetEnd.x,this.restThreshold)&&et(this._target.y,this._targetEnd.y,this.restThreshold)&&et(this._target.z,this._targetEnd.z,this.restThreshold)&&et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(c)}lerpLookAt(t,e,s,i,n,o,a,h,l,c,u,d,p,m=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Es.NONE,this._changedDolly=0;const f=G.set(i,n,o),y=J.set(t,e,s);ee.setFromVector3(y.sub(f).applyQuaternion(this._yAxisUpSpace));const g=Rs.set(c,u,d),x=J.set(a,h,l);_i.setFromVector3(x.sub(g).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(g,p));const C=_i.theta-ee.theta,b=_i.phi-ee.phi,A=_i.radius-ee.radius;this._sphericalEnd.set(ee.radius+A*p,ee.phi+b*p,ee.theta+C*p),this.normalizeRotations(),this._needsUpdate=!0,m||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const N=!m||et(this._target.x,this._targetEnd.x,this.restThreshold)&&et(this._target.y,this._targetEnd.y,this.restThreshold)&&et(this._target.z,this._targetEnd.z,this.restThreshold)&&et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(N)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const n=this.getPosition(G),o=this.setLookAt(n.x,n.y,n.z,t,e,s,i);return this._sphericalEnd.phi=me(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),o}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const n=!i||et(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&et(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&et(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),be.setFromMatrixColumn(this._camera.matrixWorldInverse,0),we.setFromMatrixColumn(this._camera.matrixWorldInverse,1),us.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=G.set(t,e,s),n=i.distanceTo(this._camera.position),o=i.sub(this._camera.position);be.multiplyScalar(o.x),we.multiplyScalar(o.y),us.multiplyScalar(o.z),G.copy(be).add(we).add(us),G.z=G.z+n,this.dollyTo(n,!1),this.setFocalOffset(-G.x,G.y,-G.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new V.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(Er(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=t/e,o=this._camera.getEffectiveFOV()*fi,a=this._camera.aspect;return((i?n>a:n<a)?e:t/a)*.5/Math.tan(o*.5)+s*.5}getDistanceToFitSphere(t){if(Er(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*fi,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new V.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new V.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new V.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new V.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Os,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Os),this._spherical.theta+=Os*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Os)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!et(this._camera.up.x,this._cameraUp0.x)||!et(this._camera.up.y,this._cameraUp0.y)||!et(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(G);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,pn),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=G.subVectors(this._target,this._camera.position).normalize(),e=J.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(G);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,n=Wa.subVectors(this._targetEnd,this._target),o=Ga.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(ht(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=un(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,t),this._needsUpdate=!0}if(ht(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=un(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,t),this._needsUpdate=!0}if(ht(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=un(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,t),this._needsUpdate=!0}if(ht(n.x)&&ht(n.y)&&ht(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Ha(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(ht(o.x)&&ht(o.y)&&ht(o.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Ha(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(ht(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=un(this._zoom,this._zoomEnd,this._zoomVelocity,u,1/0,t)}if(this.dollyToCursor){if(cs(this._camera)&&this._changedDolly!==0){const u=this._spherical.radius-this._lastDistance,d=this._camera,p=this._getCameraDirection(xi),m=G.copy(p).cross(d.up).normalize();m.lengthSq()===0&&(m.x=1);const f=J.crossVectors(m,p),y=this._sphericalEnd.radius*Math.tan(d.getEffectiveFOV()*fi*.5),x=(this._sphericalEnd.radius-u-this._sphericalEnd.radius)/this._sphericalEnd.radius,C=Rs.copy(this._targetEnd).add(m.multiplyScalar(this._dollyControlCoord.x*y*d.aspect)).add(f.multiplyScalar(this._dollyControlCoord.y*y)),b=G.copy(this._targetEnd).lerp(C,x),A=this._lastDollyDirection===Es.IN&&this._spherical.radius<=this.minDistance,N=this._lastDollyDirection===Es.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(A||N)){this._sphericalEnd.radius-=u,this._spherical.radius-=u;const O=J.copy(p).multiplyScalar(-u);b.add(O)}this._boundary.clampPoint(b,b);const E=J.subVectors(b,this._targetEnd);this._targetEnd.copy(b),this._target.add(E),this._changedDolly-=u,ht(this._changedDolly)&&(this._changedDolly=0)}else if(es(this._camera)&&this._changedZoom!==0){const u=this._zoom-this._lastZoom,d=this._camera,p=G.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(d.near+d.far)/(d.near-d.far)).unproject(d),m=J.set(0,0,-1).applyQuaternion(d.quaternion),f=Rs.copy(p).add(m.multiplyScalar(-p.dot(d.up))),g=-(this._zoom-u-this._zoom)/this._zoom,x=this._getCameraDirection(xi),C=this._targetEnd.dot(x),b=G.copy(this._targetEnd).lerp(f,g),A=b.dot(x),N=x.multiplyScalar(A-C);b.sub(N),this._boundary.clampPoint(b,b);const E=J.subVectors(b,this._targetEnd);this._targetEnd.copy(b),this._target.add(E),this._changedZoom-=u,ht(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const h=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,h),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!ht(this._focalOffset.x)||!ht(this._focalOffset.y)||!ht(this._focalOffset.z))&&(be.setFromMatrixColumn(this._camera.matrix,0),we.setFromMatrixColumn(this._camera.matrix,1),us.setFromMatrixColumn(this._camera.matrix,2),be.multiplyScalar(this._focalOffset.x),we.multiplyScalar(-this._focalOffset.y),us.multiplyScalar(this._focalOffset.z),G.copy(be).add(we).add(us),this._camera.position.add(G),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),G.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const c=this._needsUpdate;return c&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):c?(this.dispatchEvent({type:"update"}),ht(e,this.restThreshold)&&ht(s,this.restThreshold)&&ht(i,this.restThreshold)&&ht(n.x,this.restThreshold)&&ht(n.y,this.restThreshold)&&ht(n.z,this.restThreshold)&&ht(o.x,this.restThreshold)&&ht(o.y,this.restThreshold)&&ht(o.z,this.restThreshold)&&ht(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!c&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=c,this._needsUpdate=!1,c}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:gi(this.maxDistance),minZoom:this.minZoom,maxZoom:gi(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:gi(this.maxPolarAngle),minAzimuthAngle:gi(this.minAzimuthAngle),maxAzimuthAngle:gi(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:G.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=yi(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=yi(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=yi(s.maxPolarAngle),this.minAzimuthAngle=yi(s.minAzimuthAngle),this.maxAzimuthAngle=yi(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),ee.setFromVector3(G.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ee.theta,ee.phi,e),this.dollyTo(ee.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}t.setAttribute("data-camera-controls-version",Ed),this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const i=e.lengthSq();if(i===0)return t;const n=J.copy(e).add(t),a=this._boundary.clampPoint(n,Rs).sub(n),h=a.lengthSq();if(h===0)return t.add(e);if(h===i)return t;if(s===0)return t.add(e).add(a);{const l=1+s*h/e.dot(a);return t.add(J.copy(e).multiplyScalar(l)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(cs(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*fi,i=Math.tan(s*.5)*e,n=i*t.aspect;this._nearPlaneCorners[0].set(-n,-i,0),this._nearPlaneCorners[1].set(n,-i,0),this._nearPlaneCorners[2].set(n,i,0),this._nearPlaneCorners[3].set(-n,i,0)}else if(es(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,n=t.top*e,o=t.bottom*e;this._nearPlaneCorners[0].set(s,n,0),this._nearPlaneCorners[1].set(i,n,0),this._nearPlaneCorners[2].set(i,o,0),this._nearPlaneCorners[3].set(s,o,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||Er(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(xi);Lr.lookAt(ja,s,this._camera.up);for(let i=0;i<4;i++){const n=J.copy(this._nearPlaneCorners[i]);n.applyMatrix4(Lr);const o=Rs.addVectors(this._target,n);mn.set(o,s),mn.far=this._spherical.radius+1;const a=mn.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new V.Sphere){const s=e,i=s.center;Is.makeEmpty(),t.traverseVisible(o=>{o.isMesh&&Is.expandByObject(o)}),Is.getCenter(i);let n=0;return t.traverseVisible(o=>{if(!o.isMesh)return;const a=o;if(!a.geometry)return;const h=a.geometry.clone();h.applyMatrix4(a.matrixWorld);const c=h.attributes.position;for(let u=0,d=c.count;u<d;u++)G.fromBufferAttribute(c,u),n=Math.max(n,i.distanceToSquared(G))}),s.radius=Math.sqrt(n),s}}const sr=r=>{const[t,e]=I.useState(r.options[r.index]),s=()=>{r.onToggle(!r.open)},i=o=>{o!==t&&(r.onSelect(o),e(o)),r.onToggle(!1)},n=r.open?`${r.options.length*31-1}px`:"0px";return _.jsxs("div",{className:`dropdown ${r.up===!0?"up":""}`,children:[_.jsx("div",{className:"dropdown-toggle",onClick:s,children:`${r.title}: ${t}`}),_.jsx("ul",{className:"dropdown-menu",style:{height:n},children:r.options.map(o=>_.jsx("li",{onClick:()=>i(o),children:o},o))})]})},ds=I.forwardRef(function(t,e){const s=["Renderer","Depth","Normals","UVs","Wireframe"],[i,n]=I.useState("Renderer"),[o,a]=I.useState(!1),[h,l]=I.useState(!1),[c,u]=I.useState(!1);return _.jsxs("div",{className:`CameraWindow ${t.name}`,children:[_.jsx("div",{ref:e,className:"clickable",onClick:()=>{c&&u(!1)}}),_.jsxs("div",{className:"options",children:[t.camera!==null&&_.jsx(sr,{title:"Camera",index:t.options.indexOf(t.camera.name),open:c,options:t.options,onSelect:t.onSelectCamera,onToggle:d=>{d&&h&&l(!1),u(d)},up:!0}),_.jsx(sr,{title:"Mode",index:s.indexOf(i),open:h,options:s,onSelect:d=>{if(d===i)return;const p=d;t.onSelectRenderMode(p),n(p)},onToggle:d=>{d&&c&&u(!1),o&&a(!1),l(d)},up:!0})]})]})}),Rd=`out vec3 worldPosition;
7
+ uniform float uDistance;
8
+
9
+ void main() {
10
+ // Scale the plane by the drawing distance
11
+ worldPosition = position.xzy * uDistance;
12
+ worldPosition.xz += cameraPosition.xz;
13
+
14
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(worldPosition, 1.0);
15
+ }`,Id=`out vec4 fragColor;
16
+ in vec3 worldPosition;
17
+ uniform float uDivisions;
18
+ uniform float uScale;
19
+ uniform vec3 uColor;
20
+ uniform float uDistance;
21
+ uniform float uGridOpacity;
22
+ uniform float uSubgridOpacity;
23
+
24
+ #define minAlpha 0.00784313725490196
25
+
26
+ float getGrid(float gapSize) {
27
+ vec2 worldPositionByDivision = worldPosition.xz / gapSize;
28
+
29
+ // Inverted, 0 where line, >1 where there's no line
30
+ // We use the worldPosition (which in this case we use similarly to UVs) differential to control the anti-aliasing
31
+ // We need to do the -0.5)-0.5 trick because the result fades out from 0 to 1, and we want both
32
+ // worldPositionByDivision == 0.3 and worldPositionByDivision == 0.7 to result in the same fade, i.e. 0.3,
33
+ // otherwise only one side of the line will be anti-aliased
34
+ vec2 grid = abs(fract(worldPositionByDivision-0.5)-0.5) / fwidth(worldPositionByDivision) / 2.0;
35
+ float gridLine = min(grid.x, grid.y);
36
+
37
+ // Uninvert and clamp
38
+ return 1.0 - min(gridLine, 1.0);
39
+ }
40
+
41
+ void main() {
42
+ float cameraDistanceToGridPlane = max(200.0, distance(cameraPosition.y, worldPosition.y));
43
+ float cameraDistanceToFragmentOnGridPlane = distance(cameraPosition.xyz, worldPosition.xyz);
44
+
45
+ // The size of the grid and subgrid are powers of each other and they are determined based on camera distance.
46
+ // The current grid will become the next subgrid when it becomes too small, and its next power becomes the new grid.
47
+ float subGridPower = pow(uDivisions, floor(log(cameraDistanceToGridPlane) / log(uDivisions)));
48
+ float gridPower = subGridPower * uDivisions;
49
+
50
+ // If we want to fade both the grid and its subgrid, we need to displays 3 different opacities, with the next grid being the third
51
+ float nextGridPower = gridPower * uDivisions;
52
+
53
+ // 1 where grid, 0 where no grid
54
+ float subgrid = getGrid(subGridPower * uScale);
55
+ float grid = getGrid(gridPower * uScale);
56
+ float nextGrid = getGrid(nextGridPower * uScale);
57
+
58
+ // Where we are between the introduction of the current grid power and when we switch to the next grid power
59
+ float stepPercentage = (cameraDistanceToGridPlane - subGridPower)/(gridPower - subGridPower);
60
+
61
+ // The last x percentage of the current step over which we want to fade
62
+ float fadeRange = 0.3;
63
+
64
+ // We calculate the fade percentage from the step percentage and the fade range
65
+ float fadePercentage = max(stepPercentage - 1.0 + fadeRange, 0.0) / fadeRange;
66
+
67
+ // Set base opacity based on how close we are to the drawing distance, with a cubic falloff
68
+ float baseOpacity = subgrid * pow(1.0 - min(cameraDistanceToFragmentOnGridPlane / uDistance, 1.0), 3.0);
69
+
70
+ // Shade the subgrid
71
+ fragColor = vec4(uColor.rgb, (baseOpacity - fadePercentage) * uSubgridOpacity);
72
+
73
+ // Somewhat arbitrary additional fade coefficient to counter anti-aliasing popping when switching between grid powers
74
+ float fadeCoefficient = 0.5;
75
+
76
+ // Shade the grid
77
+ fragColor.a = mix(fragColor.a, baseOpacity * uGridOpacity - fadePercentage * (uGridOpacity - uSubgridOpacity) * fadeCoefficient, grid);
78
+
79
+ // Shade the next grid
80
+ fragColor.a = mix(fragColor.a, baseOpacity * uGridOpacity, nextGrid);
81
+
82
+ if (fragColor.a <= minAlpha) discard;
83
+ }`;class Pd extends Yc{constructor(t){super({extensions:{derivatives:!0},uniforms:{uScale:{value:(t==null?void 0:t.scale)!==void 0?t==null?void 0:t.scale:.1},uDivisions:{value:(t==null?void 0:t.divisions)!==void 0?t==null?void 0:t.divisions:10},uColor:{value:(t==null?void 0:t.color)!==void 0?t==null?void 0:t.color:new ws(16777215)},uDistance:{value:(t==null?void 0:t.distance)!==void 0?t==null?void 0:t.distance:1e4},uSubgridOpacity:{value:(t==null?void 0:t.subgridOpacity)!==void 0?t==null?void 0:t.subgridOpacity:.15},uGridOpacity:{value:(t==null?void 0:t.gridOpacity)!==void 0?t==null?void 0:t.gridOpacity:.25}},glslVersion:$c,side:cr,transparent:!0,name:"InfiniteGrid",vertexShader:Rd,fragmentShader:Id})}get color(){return this.uniforms.uColor.value}set color(t){this.uniforms.uColor.value=t}get gridOpacity(){return this.uniforms.uGridOpacity.value}set gridOpacity(t){this.uniforms.uGridOpacity.value=t}get subgridOpacity(){return this.uniforms.uSubgridOpacity.value}set subgridOpacity(t){this.uniforms.uSubgridOpacity.value=t}}class Ld extends F{constructor(e){const s=new Pd(e);super(new Po,s);v(this,"gridMaterial");this.gridMaterial=s,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}class Fd extends Xc{constructor(e){super();v(this,"uScale");v(this,"uDivisions");v(this,"uColor");v(this,"uDistance");v(this,"uSubgridOpacity");v(this,"uGridOpacity");this.name="InfiniteGrid",this.side=cr,this.transparent=!0,this.uScale=Ms((e==null?void 0:e.scale)??.1),this.uDivisions=Ms((e==null?void 0:e.divisions)??10),this.uColor=Ms((e==null?void 0:e.color)??new ws(16777215)),this.uDistance=Ms((e==null?void 0:e.distance)??1e4),this.uSubgridOpacity=Ms((e==null?void 0:e.subgridOpacity)??.15),this.uGridOpacity=Ms((e==null?void 0:e.gridOpacity)??.25);const{uScale:s,uDivisions:i,uColor:n,uDistance:o,uSubgridOpacity:a,uGridOpacity:h}=this,l=Zc("vec3","vWorldPosition");this.positionNode=wr(()=>{const u=qc.xzy.mul(o).add(Qc(an.x,Gt(0),an.z));return l.assign(u),u})();const c=wr(([u])=>{const d=l.xz.div(u),p=Jc(d),m=ma(Kc(d.sub(.5)).sub(.5)).div(p).div(2),f=Sr(m.x,m.y);return Gt(1).sub(Sr(f,Gt(1)))});this.outputNode=wr(()=>{const u=l,d=fa(Gt(200),ma(an.y.sub(u.y))),p=Gt(tu(an,u)),m=ga(d).div(ga(i)),f=ya(i,eu(m)),y=f.mul(i),g=y.mul(i),x=c(f.mul(s)),C=c(y.mul(s)),b=c(g.mul(s)),A=d.sub(f).div(y.sub(f)),N=Gt(.3),E=fa(A.sub(Gt(1)).add(N),Gt(0)).div(N),O=x.mul(ya(Gt(1).sub(Sr(p.div(o),Gt(1))),Gt(3))),P=Gt(.5),k=O.sub(E).mul(a),$=xa(k,O.mul(h).sub(E.mul(h.sub(a)).mul(P)),C),ct=Gt(xa($,O.mul(h),b));return su(iu(ct,Gt(1/127)),()=>{nu()}),ru(n,ct)})()}get color(){return this.uColor.value}set color(e){this.uColor.value=e}get gridOpacity(){return this.uGridOpacity.value}set gridOpacity(e){this.uGridOpacity.value=e}get subgridOpacity(){return this.uSubgridOpacity.value}set subgridOpacity(e){this.uSubgridOpacity.value=e}}class zd extends F{constructor(e){const s=new Fd(e);super(new Po,s);v(this,"gridMaterial");this.gridMaterial=s,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}function Di(r){const[t,e]=I.useState(r.open!==void 0?r.open:!1),[s,i]=I.useState(r.visible!==void 0?r.visible:!1),n=!t||r.children===void 0,o=()=>{r.three.dispatchEvent({type:Y.REMOVE_SCENE,value:r.scene})};return _.jsxs("div",{className:`accordion ${n?"hide":""}`,children:[_.jsxs("button",{className:"toggle",onClick:()=>{const a=!t;r.onToggle!==void 0&&r.onToggle(a),e(a)},children:[_.jsx("p",{className:`status ${t?"open":""}`,children:"Toggle"}),_.jsx("p",{className:"label",children:Qn(r.label)})]}),r.onRefresh?_.jsxs(_.Fragment,{children:[_.jsx("button",{className:"visibility",style:{opacity:s?1:.25},onClick:()=>{const h=r.three.getScene(r.scene.uuid);if(h){const l=!h.visible;h.visible=l,i(l)}}}),_.jsx("button",{className:"refresh",onClick:r.onRefresh}),_.jsx("button",{className:"remove",onClick:o})]}):null,r.button,_.jsx("div",{className:t?"open":"",children:_.jsx("div",{children:r.children})})]})}function Ri(r){const[t,e]=I.useState(r.defaultValue);return I.useEffect(()=>{var p,m;let s=!1,i=-1,n=0,o=r.defaultValue,a=!1;const h=f=>{a=f.ctrlKey},l=f=>{var y;s=!0,n=Number((y=r.input.current)==null?void 0:y.value),i=f.clientX,document.addEventListener("mouseup",u,!1),document.addEventListener("mousemove",c,!1),document.addEventListener("contextmenu",u,!1)},c=f=>{if(!s)return;const y=r.step!==void 0?r.step:1,g=(f.clientX-i)*y*(a?10:1);o=Number((n+g).toFixed(4)),r.min!==void 0&&(o=Math.max(o,r.min)),r.max!==void 0&&(o=Math.min(o,r.max)),r.onChange!==void 0&&r.onChange(o),e(o)},u=()=>{s=!1,document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",c),document.removeEventListener("contextmenu",u)},d=f=>{const y=Number(f.target.value);r.onChange!==void 0&&r.onChange(y),e(y)};return(p=r.label.current)==null||p.addEventListener("mousedown",l,!1),r.sliderRef!==void 0&&((m=r.sliderRef.current)==null||m.addEventListener("input",d)),document.addEventListener("keydown",h,!1),document.addEventListener("keyup",h,!1),()=>{var f,y;(f=r.label.current)==null||f.removeEventListener("mousedown",l),r.sliderRef!==void 0&&((y=r.sliderRef.current)==null||y.removeEventListener("input",d)),document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",c),document.removeEventListener("contextmenu",u),document.removeEventListener("keydown",h),document.addEventListener("keyup",h,!1)}},[]),t}function vs(r){const t=I.useRef(null),e=I.useRef(null),[s,i]=I.useState(r.value);return Ri({label:r.labelRef,input:t,sliderRef:e,defaultValue:s,min:r.min,max:r.max,step:r.step,onChange:n=>{i(n),r.onChange!==void 0&&r.onChange(r.prop,n)}}),_.jsxs(_.Fragment,{children:[r.type==="number"&&_.jsx("input",{alt:r.alt,className:r.className,ref:t,type:"number",value:s,min:r.min,max:r.max,step:r.step,disabled:r.disabled,name:Lt(),onChange:n=>{if(i(n.target.value),n.target.value.length===0)return;const o=Number(n.target.value);isNaN(o)||r.onChange!==void 0&&r.onChange(r.prop,o)}}),r.type==="range"&&_.jsxs(_.Fragment,{children:[_.jsx("input",{type:"text",value:s.toString(),disabled:r.disabled,ref:t,className:"min",name:Lt(),onChange:n=>{if(n.target.value.length===0)return;const o=Number(n.target.value);isNaN(o)||(i(o),r.onChange!==void 0&&r.onChange(r.prop,o))}}),_.jsx("input",{disabled:r.disabled,type:"range",value:s,min:r.min,max:r.max,step:r.step,ref:e,name:Lt(),onChange:ou})]})]})}function Dd(r){const t=I.useRef(null),e=I.useRef(null),s=I.useRef(null),i=I.useRef(null),n=I.useRef(null),o=I.useRef(null),a=I.useRef(null),h=I.useRef(null),l=I.useRef(null),c=I.useRef(null),[u,d]=I.useState(r.value.x),[p,m]=I.useState(r.value.y),[f,y]=I.useState({min:Math.min(r.min,Math.min(r.value.x,r.value.y)),max:Math.max(r.max,Math.max(r.value.x,r.value.y))}),[g,x]=I.useState(!1);Ri({label:a,input:t,defaultValue:u,min:f.min,max:f.max,step:.01,onChange:P=>{d(P),r.onChange({target:{value:{x:P,y:p}}})}}),Ri({label:h,input:e,defaultValue:p,min:f.min,max:f.max,step:.01,onChange:P=>{m(P),r.onChange({target:{value:{x:u,y:P}}})}}),Ri({label:l,input:s,defaultValue:f.min,min:f.min-1,max:f.max+1,step:.01,onChange:P=>{y({min:P,max:f.max})}}),Ri({label:c,input:i,defaultValue:f.max,min:f.min-1,max:f.max+1,step:.01,onChange:P=>{y({min:f.min,max:P})}});function C(){g||(window.addEventListener("mousemove",A),window.addEventListener("mouseup",b),x(!0))}function b(){window.removeEventListener("mousemove",A),window.removeEventListener("mouseup",b),x(!1)}function A(P){const k=n.current.getBoundingClientRect(),$=Ns(0,99,P.clientX-k.left)/99,ct=1-Ns(0,99,P.clientY-k.top)/99,tt=_e(xo(f.min,f.max,$),3),it=_e(xo(f.min,f.max,ct),3);r.onChange({target:{value:{x:tt,y:it}}}),d(tt),m(it)}function N(){const P=Number(s.current.value);y({min:P,max:f.max}),u<P&&d(Ns(P,f.max,u)),p<P&&m(Ns(P,f.max,p))}function E(){const P=Number(i.current.value);y({min:f.min,max:P}),u>P&&d(Ns(f.min,P,u)),p>P&&m(Ns(f.min,P,p))}I.useEffect(()=>{o.current.style.left=`${_a(f.min,f.max,u)*100}%`,o.current.style.top=`${(1-_a(f.min,f.max,p))*100}%`},[f,u,p]);const O=r.step!==void 0?r.step:.01;return _.jsxs("div",{className:"vector2",children:[_.jsxs("div",{className:"fields",children:[_.jsxs("div",{children:[_.jsx("span",{ref:a,children:"X"}),_.jsx("input",{ref:t,type:"number",value:u,min:f.min,max:f.max,step:O,name:Lt(),onChange:P=>{if(d(P.target.value),P.target.value.length===0)return;const k=Number(P.target.value);isNaN(k)||(r.onChange({target:{value:{x:k,y:p}}}),k<f.min&&y({min:k,max:f.max}))}})]}),_.jsxs("div",{children:[_.jsx("span",{ref:h,children:"Y"}),_.jsx("input",{ref:e,type:"number",value:p,min:f.min,max:f.max,step:O,name:Lt(),onChange:P=>{if(m(P.target.value),P.target.value.length===0)return;const k=Number(P.target.value);isNaN(k)||(r.onChange({target:{value:{x:u,y:k}}}),k>f.max&&y({min:f.min,max:k}))}})]}),_.jsxs("div",{children:[_.jsx("span",{ref:l,children:"Min"}),_.jsx("input",{ref:s,type:"number",value:f.min,step:O,name:Lt(),onChange:N})]}),_.jsxs("div",{children:[_.jsx("span",{ref:c,children:"Max"}),_.jsx("input",{ref:i,type:"number",value:f.max,step:O,name:Lt(),onChange:E})]})]}),_.jsxs("div",{className:"input",ref:n,onMouseDown:C,onMouseUp:b,children:[_.jsx("div",{className:"x"}),_.jsx("div",{className:"y"}),_.jsx("div",{className:"pt",ref:o})]})]})}function Xa(r){const t=r.value.x!==void 0&&r.value.y!==void 0&&r.value.z!==void 0,e=r.value.isEuler!==void 0,s=r.value.elements!==void 0,i=r.step!==void 0?r.step:.01,n=[];if(e){const o=I.useMemo(()=>r.value,[]);["_x","_y","_z"].forEach(h=>{const l=I.useRef(null);n.push(_.jsxs("div",{children:[_.jsx("span",{ref:l,children:h.substring(1).toUpperCase()}),_.jsx(vs,{value:bl(o[h]),type:"number",prop:h,step:.1,labelRef:l,onChange:(c,u)=>{o[c]=er(u),r.onChange({target:{value:o}})}})]},h))})}else if(t){const o=I.useMemo(()=>r.value,[]),a=(l,c)=>{o[l]=c,r.onChange({target:{value:o}})};["x","y","z"].forEach(l=>{const c=I.useRef(null);n.push(_.jsxs("div",{children:[_.jsx("label",{ref:c,children:l.toUpperCase()}),_.jsx(vs,{value:o[l],type:"number",prop:l,step:i,labelRef:c,onChange:a})]},l))})}else if(s){const o=I.useMemo(()=>r.value,[]),a=(h,l)=>{const c=Number(h);o.elements[c]=l,r.onChange({target:{value:o}})};for(let h=0;h<9;h++){const l=I.useRef(null);n.push(_.jsxs("div",{children:[_.jsx("label",{ref:l,children:h+1}),_.jsx(vs,{value:o.elements[h],type:"number",prop:h.toString(),step:i,labelRef:l,onChange:a})]},h.toString()))}}return _.jsx("div",{className:"grid3",children:n},Math.random().toString())}function Bd(r){const t=r.value.x!==void 0,e=r.step!==void 0?r.step:.01,s=[];if(t){const i=I.useMemo(()=>r.value,[]),n=(a,h)=>{i[a]=h,r.onChange({target:{value:i}})};["x","y","z","w"].forEach(a=>{const h=I.useRef(null);s.push(_.jsxs("div",{children:[_.jsx("label",{ref:h,children:a.toUpperCase()}),_.jsx(vs,{value:i[a],type:"number",prop:a,step:e,labelRef:h,onChange:n})]},a))})}else{const i=I.useMemo(()=>r.value,[]),n=(o,a)=>{const h=Number(o);i.elements[h]=a,r.onChange({target:{value:i}})};for(let o=0;o<16;o++){const a=I.useRef(null);s.push(_.jsxs("div",{children:[_.jsx("span",{ref:a,children:o+1}),_.jsx(vs,{value:i.elements[o],type:"number",prop:o.toString(),step:e,labelRef:a,onChange:n})]},o.toString()))}}return _.jsx("div",{className:"grid4",children:s})}function kd(r){return!(r==="defaultAttributeValues"||r==="forceSinglePass"||r==="linecap"||r==="linejoin"||r==="linewidth"||r==="normalMapType"||r==="precision"||r==="shadowSide"||r==="uniformsGroups"||r==="uniformsNeedUpdate"||r==="userData"||r==="version"||r==="wireframeLinecap"||r==="wireframeLinejoin"||r==="wireframeLinewidth"||r.slice(0,4)==="clip"||r.slice(0,7)==="polygon"||r.slice(0,7)==="stencil"||r.slice(0,2)==="is")}function Ud(r){switch(r){case"Alpha Map":return"alphaMap";case"Anisotropy Map":return"anisotropyMap";case"AO Map":return"aoMap";case"Bump Map":return"bumpMap";case"Clearcoat Map":return"clearcoatMap";case"Clearcoat Normal Map":return"clearcoatNormalMap";case"Clearcoat Roughness Map":return"clearcoatRoughnessMap";case"Displacement Map":return"displacementMap";case"Emissive Map":return"emissiveMap";case"Gradient Map":return"gradientMap";case"Iridescence Map":return"iridescenceMap";case"Iridescence Thickness Map":return"iridescenceThicknessMap";case"Map":return"map";case"Matcap":return"matcap";case"Normal Map":return"normalMap";case"Roughness Map":return"roughnessMap";case"Sheen Color Map":return"sheenColorMap";case"Sheen Roughness Map":return"sheenRoughnessMap";case"Specular Color Map":return"specularColorMap";case"Specular Map Intensity":return"specularIntensityMap";case"Thickness Map":return"thicknessMap";case"Transmission Map":return"transmissionMap"}return r}function pr(r){switch(r){case"alphaHash":return"Alpha Hash";case"alphaMap":return"Alpha Map";case"alphaToCoverage":return"Alpha To Coverage";case"anisotropy":return"Anisotropy";case"anisotropyMap":return"Anisotropy Map";case"anisotropyRotation":return"Anisotropy Rotation";case"aoMap":return"AO Map";case"aoMapIntensity":return"AO Map Intensity";case"attenuationColor":return"Attenuation Color";case"attenuationDistance":return"Attenuation Distance";case"blendAlpha":return"Blend Alpha";case"blendColor":return"Blend Color";case"blendDst":return"Blend Dst";case"blendDstAlpha":return"Blend Dst Alha";case"blendEquation":return"Blend Equation";case"blendEquationAlpha":return"Blend Equation Alpha";case"blending":return"Blending";case"blendSrc":return"Blend Src";case"blendSrcAlpha":return"Blend Src Alpha";case"bumpMap":return"Bump Map";case"bumpScale":return"Bump Scale";case"clearcoat":return"Clearcoat";case"clearcoatMap":return"Clearcoat Map";case"clearcoatNormalMap":return"Clearcoat Normal Map";case"clearcoatNormalScale":return"Clearcoat Normal Scale";case"clearcoatRoughness":return"Clearcoat Roughness";case"clearcoatRoughnessMap":return"Clearcoat Roughness Map";case"color":return"Color";case"colorWrite":return"Color Write";case"defines":return"Defines";case"depthFunc":return"Depth Func";case"depthTest":return"Depth Test";case"depthWrite":return"Depth Write";case"dispersion":return"Dispersion";case"displacementBias":return"Displacement Bias";case"displacementMap":return"Displacement Map";case"displacementScale":return"Displacement Scale";case"dithering":return"Dithering";case"emissive":return"Emissive";case"emissiveMap":return"Emissive Map";case"emissiveIntensity":return"Emissive Intensity";case"envMap":return"Environment Map";case"envMapIntensity":return"Environment Map Intensity";case"envMapRotation":return"Environment Map Rotation";case"extensions":return"Extensions";case"flatShading":return"Flat Shading";case"fragmentShader":return"Fragment Shader";case"fog":return"Fog";case"glslVersion":return"GLSL Version";case"gradientMap":return"Gradient Map";case"ior":return"IOR";case"iridescence":return"Iridescence";case"iridescenceIOR":return"Iridescence IOR";case"iridescenceMap":return"Iridescence Map";case"iridescenceThicknessMap":return"Iridescence Thickness Map";case"iridescenceThicknessRange":return"Iridescence Thickness Range";case"lights":return"Lights";case"lightMap":return"Light Map";case"lightMapIntensity":return"Light Map Intensity";case"map":return"Map";case"matcap":return"Matcap";case"metalness":return"Metalness";case"metalnessMap":return"Metalness Map";case"name":return"Name";case"normalMap":return"Normal Map";case"normalScale":return"Normal Scale";case"premultipliedAlpha":return"Premultiplied Alpha";case"opacity":return"Opacity";case"reflectivity":return"Reflectivity";case"refractionRatio":return"Refraction Ratio";case"roughness":return"Roughness";case"roughnessMap":return"Roughness Map";case"sheen":return"Sheen";case"sheenColor":return"Sheen Color";case"sheenColorMap":return"Sheen Color Map";case"sheenRoughness":return"Sheen Roughness";case"sheenRoughnessMap":return"Sheen Roughness Map";case"shininess":return"Shininess";case"side":return"Side";case"size":return"Size";case"sizeAttenuation":return"Size Attenuation";case"specular":return"Specular";case"specularColor":return"Specular Color";case"specularColorMap":return"Specular Color Map";case"specularIntensity":return"Specular Intensity";case"specularIntensityMap":return"Specular Map Intensity";case"thickness":return"Thickness";case"thicknessMap":return"Thickness Map";case"toneMapped":return"Tone Mapped";case"transmission":return"Transmission";case"transmissionMap":return"Transmission Map";case"transparent":return"Transparent";case"type":return"Type";case"uuid":return"UUID";case"uniforms":return"Uniforms";case"vertexColors":return"Vertex Colors";case"vertexShader":return"Vertex Shader";case"visible":return"Visible";case"wireframe":return"Wireframe"}return r}function Sl(r){const t=r.toLowerCase();return t.search("intensity")>-1||t==="anisotropyrotation"||t==="blendalpha"||t==="bumpscale"||t==="clearcoatroughness"||t==="displacementbias"||t==="displacementscale"||t==="metalness"||t==="opacity"||t==="reflectivity"||t==="refractionratio"||t==="roughness"||t==="sheenroughness"}function Vd(){const r=document.createElement("input");return r.type="file",new Promise((t,e)=>{r.addEventListener("change",function(){if(r.files===null)e();else{const s=r.files[0],i=new FileReader;i.onload=function(n){t(n.target.result)},i.readAsDataURL(s)}}),r.click()})}const Hd=[{title:"Front",value:lu},{title:"Back",value:qh},{title:"Double",value:cr}],jd=[{title:"No Blending",value:gu},{title:"Normal",value:yu},{title:"Additive",value:xu},{title:"Subtractive",value:_u},{title:"Multiply",value:Tu},{title:"Custom",value:vu}],Wd=[{title:"Add",value:uu},{title:"Subtract",value:du},{title:"Reverse Subtract",value:pu},{title:"Min",value:mu},{title:"Max",value:fu}],Gd=[{title:"Zero",value:Qh},{title:"One",value:Jh},{title:"Src Color",value:Kh},{title:"One Minus Src Color",value:tl},{title:"Src Alpha",value:el},{title:"One Minus Src Alpha",value:sl},{title:"Dst Alpha",value:il},{title:"One Minus Dst Alpha",value:nl},{title:"Dst Color",value:rl},{title:"One Minus Dst Color",value:ol},{title:"Src Alpha Saturate",value:cu},{title:"Constant Color",value:al},{title:"One Minus Constant Color",value:hl},{title:"Constant Alpha",value:ll},{title:"One Minus Constant Alpha",value:cl}],Yd=[{title:"Zero",value:Qh},{title:"One",value:Jh},{title:"Src Color",value:Kh},{title:"One Minus Src Color",value:tl},{title:"Src Alpha",value:el},{title:"One Minus Src Alpha",value:sl},{title:"Dst Alpha",value:il},{title:"One Minus Dst Alpha",value:nl},{title:"Dst Color",value:rl},{title:"One Minus Dst Color",value:ol},{title:"Constant Color",value:al},{title:"One Minus Constant Color",value:hl},{title:"Constant Alpha",value:ll},{title:"One Minus Constant Alpha",value:cl}];function Ti(r,t){r.needsUpdate=!0,r.type="option",r.options=t}function $d(r,t,e,s){return{type:"boolean",title:pr(r),prop:r,value:t,needsUpdate:!0,onChange:(i,n)=>{s.updateObject(e.uuid,`material.${r}`,n),s.updateObject(e.uuid,"material.needsUpdate",!0);const o=s.getScene(e.uuid);if(o!==null){const a=o.getObjectByProperty("uuid",e.uuid);xt(a,`material.${r}`,n)}}}}function Xd(r,t,e,s){const i={type:"number",title:pr(r),prop:r,value:t,min:void 0,max:void 0,step:.01,needsUpdate:!0,onChange:(n,o)=>{s.updateObject(e.uuid,`material.${r}`,o),s.updateObject(e.uuid,"material.needsUpdate",!0);const a=s.getScene(e.uuid);if(a!==null){const h=a.getObjectByProperty("uuid",e.uuid);xt(h,`material.${r}`,o)}}};switch(r){case"blending":Ti(i,jd);break;case"blendDst":Ti(i,Yd);break;case"blendEquation":Ti(i,Wd);break;case"blendSrc":Ti(i,Gd);break;case"side":Ti(i,Hd);break}return Sl(r)&&(i.value=Number(t),i.type="range",i.min=Math.min(0,i.value),i.max=Math.max(1,i.value),i.step=.01),i}function Zd(r,t,e,s){const i={type:"string",title:pr(r),prop:r,value:t,needsUpdate:!0,onChange:(o,a)=>{s.updateObject(e.uuid,`material.${r}`,a),s.updateObject(e.uuid,"material.needsUpdate",!0);const h=s.getScene(e.uuid);if(h!==null){const l=h.getObjectByProperty("uuid",e.uuid);xt(l,`material.${r}`,a)}},onKeyDown:o=>{}};return(r==="vertexShader"||r==="fragmentShader")&&(i.type="field",i.disabled=!1,i.latest=i.value,i.onChange=(o,a)=>{i.latest=a,s.updateObject(e.uuid,`material.${r}`,a);const h=s.getScene(e.uuid);if(h!==null){const l=h.getObjectByProperty("uuid",e.uuid);xt(l,`material.${r}`,a)}},i.onKeyDown=o=>{if(o.key==="Enter"&&(o.altKey||o.metaKey)){s.updateObject(e.uuid,"material.needsUpdate",!0);const a=s.getScene(e.uuid);if(a!==null){const h=a.getObjectByProperty("uuid",e.uuid);xt(h,"material.needsUpdate",!0)}}}),i}function qd(r){return r.x!==void 0&&r.y!==void 0&&r.z===void 0}function Qd(r){return r.x!==void 0&&r.y!==void 0&&r.z!==void 0&&r.w===void 0}function Jd(r){return r.x!==void 0&&r.y!==void 0&&r.z!==void 0&&r.w!==void 0}function wo(r){r.sort((t,e)=>t.title<e.title?-1:t.title>e.title?1:0)}function $s(r,t,e,s,i="",n=!1){const o=pr(r).split(".")[0].replaceAll("[","").replaceAll("]",""),a=i.length>0?`${i}.${r}`:r,h=typeof t;if(h==="object"&&t!==null&&t.__isUniform===!0)return $s(`${r}.value`,t.value,e,s,i,n);if(h==="boolean"||h==="string")return{title:o,prop:a,type:h,value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};if(h==="number"){const l={title:o,prop:a,type:"number",value:t,step:.01,disabled:n,onChange:(c,u)=>{s.updateObject(e.uuid,`material.${a}`,u);const d=s.getScene(e.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",e.uuid);xt(p,`material.${a}`,u)}}};return Sl(o)&&(l.type="range",l.min=0,l.max=1),l}else{if(t.isColor)return{title:o,prop:a,type:"color",value:t,disabled:n,onChange:(l,c)=>{const u=new ws(c);s.updateObject(e.uuid,`material.${a}`,u);const d=s.getScene(e.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",e.uuid);xt(p,`material.${a}`,u)}}};if(Array.isArray(t)){const l=[];for(const c in t){const u=t[c],d=`[${c.toString()}]`;if(u.value!==void 0){const p=$s(`${d}.value`,u.value,e,s,a,n);p!==void 0&&l.push(p)}else{const p=$s(d,u,e,s,a,n);p!==void 0&&l.push(p)}}if(l.length>0)return wo(l),{title:o,items:l}}else{if(qd(t))return{title:o,prop:a,type:"vector2",value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};if(Qd(t))return{title:o,prop:a,type:"grid3",value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};if(Jd(t))return{title:o,prop:a,type:"grid4",value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};if(t.isEuler)return{title:o,prop:a,type:"euler",value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};if(t.src!==void 0)return{title:o,type:"image",value:t,disabled:n,onChange:(l,c)=>{const u=Ud(r),d=i.length>0?`${i}.${u}`:u;s.createTexture(e.uuid,`material.${d}`,c);const p=s.getScene(e.uuid);if(p!==null){const m=p.getObjectByProperty("uuid",e.uuid);if(m!==void 0){const f=y=>{const g=m.material,x=d.split(".");switch(x.length){case 1:g[x[0]]=y;break;case 2:g[x[0]][x[1]]=y;break;case 3:g[x[0]][x[1]][x[2]]=y;break;case 4:g[x[0]][x[1]][x[2]][x[3]]=y;break;case 5:g[x[0]][x[1]][x[2]][x[3]][x[4]]=y;break}g.needsUpdate=!0};c.src.length>0?hu(c.src).then(y=>{y.offset.set(c.offset[0],c.offset[1]),y.repeat.set(c.repeat[0],c.repeat[1]),f(y)}):f(null)}}}};if(t.elements!==void 0)return{title:o,prop:a,type:t.elements.length>9?"grid4":"grid3",value:t,disabled:n,onChange:(l,c)=>{s.updateObject(e.uuid,`material.${a}`,c);const u=s.getScene(e.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",e.uuid);xt(d,`material.${a}`,c)}}};{const l=[],c=r==="defines"||r==="extensions";try{for(const u in t){const d=t[u];if(d!==void 0)if(d.value!==void 0){const p=$s(`${u}.value`,d.value,e,s,a,c);p!==void 0&&l.push(p)}else{const p=$s(u,d,e,s,a,c);p!==void 0&&l.push(p)}}}catch{console.log("Hermes - Issue cycling through material object:",r,t)}if(l.length>0)return wo(l),{title:o,items:l}}}}}function Za(r,t,e){const s=[];for(const i in r){if(!kd(i)||i.search("Node")>-1||r[i]instanceof au)continue;const n=typeof r[i],o=r[i];if(n==="boolean")s.push($d(i,o,t,e));else if(n==="number")s.push(Xd(i,o,t,e));else if(n==="string")s.push(Zd(i,o,t,e));else if(n==="object"){const a=$s(i,o,t,e);a!==void 0&&s.push(a)}else o!==void 0&&console.log("Hermes - Other Material Prop Type:",i,n,o)}return wo(s),s.push({title:"Update Material",type:"button",onChange:()=>{e.updateObject(t.uuid,"material.needsUpdate",!0);const i=e.getScene(t.uuid);if(i!==null){const n=i.getObjectByProperty("uuid",t.uuid);xt(n,"material.needsUpdate",!0)}}}),s}function Kd(r,t){function e(){return`${t.name}_material`}const s=localStorage.getItem(e()),i=s!==null?s==="open":!1;function n(a){localStorage.setItem(e(),a?"open":"closed")}const o=r.material;if(Array.isArray(o)){const a=[],h=o.length;for(let l=0;l<h;l++)a.push(_.jsx(re,{three:t,title:`Material ${l}`,items:Za(o[l],r,t)},`Material ${l}`));return _.jsx(_.Fragment,{children:a})}else return _.jsx(re,{three:t,title:"Material",items:Za(o,r,t),expanded:i,onToggle:a=>{n(a)}})}const qa="data:image/gif;base64,R0lGODlhDgFkAIAAAP///wAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgOS4xLWMwMDIgNzkuZGJhM2RhM2I1LCAyMDIzLzEyLzE1LTEwOjQyOjM3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjUuNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoyMDk3M0NEODAxQjQxMUVGODVGNENDMkUyMUExNDk1NSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoyMDk3M0NEOTAxQjQxMUVGODVGNENDMkUyMUExNDk1NSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE4ODc3Qzg5MDFCMzExRUY4NUY0Q0MyRTIxQTE0OTU1IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkE4ODc3QzhBMDFCMzExRUY4NUY0Q0MyRTIxQTE0OTU1Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAAAAAAAsAAAAAA4BZAAAAv+Mj6nL7Q+jnLTai7PevPsPhuJIluaJpurKtu4Lx/JM1/aN5/rO9/4PDAqHxKLxiEwql8ym8wmNSqfUqvWKzWq33K73Cw6Lx+Sy+YxOq9fstvsNj8vn9Lr9js/r9/y+/w8YKDhIWGh4iJiouMjY6PgIGSk5SVlpeYmZqTkJAGDQ+dnpuekmGgAKejpKuiZqmprKqoZKGyrbOlqrejub6xvLGyw8TFzcprurGuvqybxq7ETbrItsCz0l7Zpc+6p9/cS967w9/S2FTF0u/mzehK4Oqz3eTl9vf4+fr7/P3+//DzCgwIEECxo8iDChwoUMGzp8CDGixIkUK1q8iDGjxo0XHDt6/AgypMiRJEuaPIkypcqVLFt+KwAAOw==";function tp(r){const t=r.step!==void 0?r.step:.01,e=I.useRef(null),s=I.useRef(null),i=I.useRef(null),n=I.useRef(null),o=I.useRef(null),[a]=I.useState(r.value),[h,l]=I.useState(r.value.offset[0]),[c,u]=I.useState(r.value.offset[1]),[d,p]=I.useState(r.value.repeat[0]),[m,f]=I.useState(r.value.repeat[1]);function y(x,C,b,A,N){if(r.onChange!==void 0){const E=r.prop!==void 0?r.prop:r.title;r.onChange(E,{src:x,offset:[C,b],repeat:[A,N]})}}function g(x){const C=e.current.src,b=x.target.value;switch(x.target){case s.current:l(b),y(C,b,c,d,m);break;case i.current:u(b),y(C,h,b,d,m);break;case n.current:p(b),y(C,h,c,b,m);break;case o.current:f(b),y(C,h,c,d,b);break}}return _.jsxs("div",{className:"imageField",children:[_.jsx("img",{alt:r.title,ref:e,onClick:()=>{Vd().then(x=>{e.current.src=x,y(x,h,c,d,m)})},src:a.src.length>0?a.src:qa}),_.jsxs("div",{className:"fields",children:[_.jsxs("div",{children:[_.jsx("span",{children:"Offset:"}),_.jsx("input",{ref:s,type:"number",value:h,step:t,name:Lt(),onChange:g}),_.jsx("input",{ref:i,type:"number",value:c,step:t,name:Lt(),onChange:g})]}),_.jsxs("div",{children:[_.jsx("span",{children:"Repeat:"}),_.jsx("input",{ref:n,type:"number",value:d,step:t,name:Lt(),onChange:g}),_.jsx("input",{ref:o,type:"number",value:m,step:t,name:Lt(),onChange:g})]}),_.jsx("button",{onClick:()=>{y("",h,c,d,m),e.current.src=qa},children:"Clear"})]})]})}function Yn(r){var l;let t=r.value;t!==void 0&&(t.isColor!==void 0?t=Ta(r.value):r.type==="color"&&(t=Ta(new ws().setStyle(r.value,_o))));const[e,s]=I.useState(t),i=I.useRef(null),n=c=>{let u=c.target.value;if(r.type==="boolean")u=c.target.checked;else if(r.type==="option"&&(typeof r.value=="number"?u=Number(u):typeof r.value=="boolean"?u=!!u:typeof r.value=="object"&&(u=JSON.parse(u)),r.options!==void 0)){const d=r.options.length;for(let p=0;p<d&&r.options[p].value!==u;p++);}s(u),r.onChange!==void 0&&r.onChange(r.prop!==void 0?r.prop:r.title,u)},o={};r.disabled&&(o.opacity=.8);const a=r.type==="field"||r.type==="string"&&(e.length>100||e.search(`
84
+ `)>-1),h=a||r.type==="image"||r.type==="vector2";return _.jsxs("div",{className:`field ${h?"block":""}`,style:o,children:[r.type!=="button"&&_.jsx("span",{ref:i,children:Qn(r.title)},"fieldLabel"),r.type==="string"&&!a&&_.jsx("input",{type:"text",disabled:r.disabled,onChange:n,value:e,name:Lt()}),(r.type==="field"||r.type==="string"&&a)&&_.jsx("textarea",{cols:50,rows:10,disabled:r.disabled!==void 0?r.disabled:!0,onChange:n,onKeyDown:c=>{r.onKeyDown!==void 0&&r.onKeyDown(c)},value:e,name:Lt()}),r.type==="boolean"&&_.jsx("input",{type:"checkbox",disabled:r.disabled,onChange:n,checked:e,name:Lt()}),r.type==="number"&&_.jsx(vs,{value:e,type:r.type,prop:r.prop!==void 0?r.prop:r.title,min:r.min,max:r.max,step:r.step,disabled:r.disabled,labelRef:i,onChange:r.onChange}),r.type==="range"&&_.jsx(vs,{value:e,type:r.type,prop:r.prop!==void 0?r.prop:r.title,min:r.min,max:r.max,step:r.step,disabled:r.disabled,labelRef:i,onChange:r.onChange}),r.type==="color"&&_.jsxs(_.Fragment,{children:[_.jsx("input",{type:"text",value:e.toString(),onChange:n,disabled:r.disabled,className:"color",name:Lt()}),_.jsx("input",{type:"color",value:e,onChange:n,disabled:r.disabled,name:Lt()})]}),r.type==="button"&&_.jsx("button",{disabled:r.disabled,onClick:()=>{r.onChange!==void 0&&r.onChange(r.prop!==void 0?r.prop:r.title,!0)},children:r.title}),r.type==="image"&&_.jsx(tp,{title:r.title,prop:r.prop,value:r.value,onChange:r.onChange}),r.type==="option"&&_.jsx(_.Fragment,{children:_.jsx("select",{onChange:n,disabled:r.disabled,defaultValue:r.value,name:Lt(),children:(l=r.options)==null?void 0:l.map((c,u)=>_.jsx("option",{value:c.value,children:Qn(c.title)},u))})}),r.type==="vector2"&&_.jsx(Dd,{step:r.step,value:e,min:0,max:1,onChange:n}),r.type==="grid3"&&_.jsx(Xa,{step:r.step,value:e,onChange:n}),r.type==="grid4"&&_.jsx(Bd,{step:r.step,value:e,onChange:n}),r.type==="euler"&&_.jsx(Xa,{step:r.step,value:e,onChange:n})]})}function ep(r){return"items"in r}class re extends I.Component{constructor(e){super(e);v(this,"subgroupNames",[]);v(this,"subgroupElements",[]);v(this,"valueOverrides",new Map);v(this,"three");this.three=e.three,this.state={lastUpdated:Date.now()}}addGroup(e){const s=[];e.items.forEach(o=>{s.push({type:o.type,prop:o.prop,title:o.title!==void 0?o.title:o.prop,value:o.value,min:o.min,max:o.max,step:o.step,options:o.options,disabled:o.disabled,onChange:(a,h)=>{e.onUpdate(a,h)}})});const i=I.createRef(),n=_.jsx(re,{three:this.props.three,ref:i,title:e.title,expanded:e.expanded,items:s},e.title);return this.subgroupNames.push(e.title),this.subgroupElements.push(n),this.setState({lastUpdated:Date.now()}),i}removeGroup(e){const s=this.subgroupNames.length;for(let i=0;i<s;i++){const n=this.subgroupNames[i];if(e===n){this.subgroupNames.splice(i,1),this.subgroupElements.splice(i,1),this.setState({lastUpdated:Date.now()});return}}}setField(e,s){this.valueOverrides.set(e,s),this.setState({lastUpdated:Date.now()})}render(){const e=[];return this.props.items.forEach(s=>{if(ep(s))e.push(_.jsx(re,{three:this.props.three,title:Qn(s.title),items:s.items},s.title));else{const i=this.valueOverrides.get(s.title),n=i!==void 0?i:s.value;e.push(_.jsx(Yn,{title:s.title,prop:s.prop,value:n,type:s.type,min:s.min,max:s.max,step:s.step,disabled:s.disabled,options:s.options,onChange:(o,a)=>{s.onChange!==void 0&&(this.valueOverrides.delete(s.title),s.onChange(o,a))},onKeyDown:o=>{s.onKeyDown!==void 0&&s.onKeyDown(o)}},s.title))}}),this.subgroupElements.forEach(s=>e.push(s)),_.jsx(Di,{three:this.props.three,label:this.props.title,open:this.props.expanded===!0,onToggle:s=>{var i;this.props.onToggle&&((i=this.props)==null||i.onToggle(s))},children:e})}}const Z=class Z extends I.Component{constructor(e){super(e);v(this,"addGroup",e=>{const s=JSON.parse(e.value),i=[];s.items.forEach(n=>{i.push({type:n.type,prop:n.prop,title:n.title!==void 0?n.title:n.prop,value:n.value,min:n.min,max:n.max,step:n.step,options:n.options,disabled:n.disabled,onChange:(o,a)=>{this.props.three.updateGroup(s.title,o,a)}})}),Z.groups.push(_.jsx(re,{three:this.props.three,title:s.title,items:i},s.title)),Z.groupTitles.push(s.title),this.setState({lastUpdate:Date.now()})});v(this,"removeGroup",e=>{const s=e.value,i=Z.groupTitles.length;for(let n=0;n<i;n++)if(s===Z.groupTitles[n]){Z.groups.splice(n,1),Z.groupTitles.splice(n,1),this.setState({lastUpdate:Date.now()});return}});this.state={lastUpdate:Date.now()},Z.instance=this,Z.three=e.three,e.three.addEventListener(Y.ADD_GROUP,this.addGroup),e.three.addEventListener(Y.REMOVE_GROUP,this.removeGroup)}componentWillUnmount(){this.props.three.removeEventListener(Y.ADD_GROUP,this.addGroup),this.props.three.removeEventListener(Y.REMOVE_GROUP,this.removeGroup)}render(){return _.jsx("div",{className:"customGroups",children:Z.groups},this.state.lastUpdate)}static addEditorGroup(e){const s=Z.groupTitles.length;for(let a=0;a<s;a++)if(Z.groupTitles[a]===e.title)return Z.groupsRefs[a];const i=[];e.items.forEach(a=>{i.push({type:a.type,prop:a.prop,title:a.title!==void 0?a.title:a.prop,value:a.value,min:a.min,max:a.max,step:a.step,options:a.options,disabled:a.disabled,onChange:(h,l)=>{e.onUpdate(h,l)}})}),e.subgroups&&e.subgroups.length>0&&e.subgroups.forEach(a=>{const h=[];a.items.forEach(l=>{h.push({type:l.type,prop:l.prop,title:l.title!==void 0?l.title:l.prop,value:l.value,min:l.min,max:l.max,step:l.step,options:l.options,disabled:l.disabled,onChange:(c,u)=>{a.onUpdate(c,u)}})}),i.push({three:Z.three,title:a.title,expanded:a.expanded,items:h})});const n=I.createRef(),o=_.jsx(re,{three:Z.three,ref:n,title:e.title,expanded:e.expanded,items:i},e.title);return Z.groups.push(o),Z.groupsRefs.push(n),Z.groupTitles.push(e.title),setTimeout(()=>{var a;(a=Z.instance)==null||a.setState({lastUpdate:Date.now()})},0),n}static removeEditorGroup(e){var i;const s=Z.groupTitles.length;for(let n=0;n<s;n++)if(e===Z.groupTitles[n]){Z.groups.splice(n,1),Z.groupTitles.splice(n,1),(i=Z.instance)==null||i.setState({lastUpdate:Date.now()});return}}static removeAllGroups(){var e;Z.groups=[],Z.groupTitles=[],Z.groupsRefs=[],(e=Z.instance)==null||e.setState({lastUpdate:Date.now()})}};v(Z,"instance"),v(Z,"groups",[]),v(Z,"groupsRefs",[]),v(Z,"groupTitles",[]),v(Z,"three");let rs=Z;const hr=class hr extends I.Component{constructor(e){super(e);v(this,"matrix",new ur);v(this,"position",new U);v(this,"rotation",new ul);v(this,"scale",new U);v(this,"open",!1);v(this,"updateTransform",(e,s)=>{const i=e==="rotation"?{x:s._x,y:s._y,z:s._z}:s;this.props.three.updateObject(this.props.object.uuid,e,i);const n=this.props.three.getScene(this.props.object.uuid);if(n){const o=n.getObjectByProperty("uuid",this.props.object.uuid);xt(o,e,i)}});const s=localStorage.getItem(this.expandedName),i=s!==null?s==="open":!1;this.open=i,this.saveExpanded(),this.state={lastUpdated:0,expanded:i},this.matrix.elements=e.object.matrix,e.object.uuid.length>0&&(this.position.setFromMatrixPosition(this.matrix),this.rotation.setFromRotationMatrix(this.matrix),this.scale.setFromMatrixScale(this.matrix)),hr.instance=this}update(){if(Mt.instance){const e=Mt.instance.selectedItem;if(e===void 0)return;this.position.x=_e(e.position.x,3),this.position.y=_e(e.position.y,3),this.position.z=_e(e.position.z,3),this.rotation.copy(e.rotation),this.scale.x=_e(e.scale.x,3),this.scale.y=_e(e.scale.y,3),this.scale.z=_e(e.scale.z,3),this.setState({lastUpdated:Date.now()})}}render(){return _.jsx(re,{three:this.props.three,title:"Transform",expanded:this.open,items:[{title:"Position",prop:"position",type:"grid3",step:.1,value:this.position,onChange:this.updateTransform},{title:"Rotation",prop:"rotation",type:"euler",value:this.rotation,onChange:this.updateTransform},{title:"Scale",prop:"scale",type:"grid3",value:this.scale,onChange:this.updateTransform},{title:"Visible",prop:"visible",type:"boolean",value:this.props.object.visible,onChange:this.updateTransform}],onToggle:e=>{this.open=e,this.saveExpanded()}},this.state.lastUpdated)}saveExpanded(){localStorage.setItem(this.expandedName,this.open?"open":"closed")}get expandedName(){return`${this.props.three.name}_transform`}};v(hr,"instance");let ir=hr;function Fr(r){const[t,e]=I.useState(r.selected),s="toggle"+(t?" selected":"");return _.jsx("button",{className:s,onClick:()=>{const i=!t;e(i),r.onClick(i)},style:{backgroundImage:`url(${r.icon})`,backgroundPositionX:"center",backgroundPositionY:r.top!==void 0?`${r.top}px`:"center",backgroundSize:`${r.width!==void 0?`${r.width}px`:"26px"} ${r.height}px`}},r.name)}class he{constructor(t,e,s,i,n,o,a,h,l){he.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,s,i,n,o,a,h,l)}set(t,e,s,i,n,o,a,h,l){const c=this.elements;return c[0]=t,c[1]=i,c[2]=a,c[3]=e,c[4]=n,c[5]=h,c[6]=s,c[7]=o,c[8]=l,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,n=this.elements,o=s[0],a=s[3],h=s[6],l=s[1],c=s[4],u=s[7],d=s[2],p=s[5],m=s[8],f=i[0],y=i[3],g=i[6],x=i[1],C=i[4],b=i[7],A=i[2],N=i[5],E=i[8];return n[0]=o*f+a*x+h*A,n[3]=o*y+a*C+h*N,n[6]=o*g+a*b+h*E,n[1]=l*f+c*x+u*A,n[4]=l*y+c*C+u*N,n[7]=l*g+c*b+u*E,n[2]=d*f+p*x+m*A,n[5]=d*y+p*C+m*N,n[8]=d*g+p*b+m*E,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],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8];return e*o*c-e*a*l-s*n*c+s*a*h+i*n*l-i*o*h}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],u=c*o-a*l,d=a*h-c*n,p=l*n-o*h,m=e*u+s*d+i*p;if(m===0)return this.set(0,0,0,0,0,0,0,0,0);const f=1/m;return t[0]=u*f,t[1]=(i*l-c*s)*f,t[2]=(a*s-i*o)*f,t[3]=d*f,t[4]=(c*e-i*h)*f,t[5]=(i*n-a*e)*f,t[6]=p*f,t[7]=(s*h-l*e)*f,t[8]=(o*e-s*n)*f,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,n,o,a){const h=Math.cos(n),l=Math.sin(n);return this.set(s*h,s*l,-s*(h*o+l*a)+o+t,-i*l,i*h,-i*(-l*o+h*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(zr.makeScale(t,e)),this}rotate(t){return this.premultiply(zr.makeRotation(-t)),this}translate(t,e){return this.premultiply(zr.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 i=0;i<9;i++)if(e[i]!==s[i])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 zr=new he,Qa=new he().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ja=new he().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function sp(){const r={enabled:!0,workingColorSpace:La,spaces:{},convert:function(i,n,o){return this.enabled===!1||n===o||!n||!o||(this.spaces[n].transfer===Fi&&(i.r=Ye(i.r),i.g=Ye(i.g),i.b=Ye(i.b)),this.spaces[n].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[n].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===Fi&&(i.r=Qs(i.r),i.g=Qs(i.g),i.b=Qs(i.b))),i},workingToColorSpace:function(i,n){return this.convert(i,this.workingColorSpace,n)},colorSpaceToWorking:function(i,n){return this.convert(i,n,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===Kn?Fa:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,n=this.workingColorSpace){return i.fromArray(this.spaces[n].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,n,o){return i.copy(this.spaces[n].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,n){return Yi("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(i,n)},toWorkingColorSpace:function(i,n){return Yi("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(i,n)}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],s=[.3127,.329];return r.define({[La]:{primaries:t,whitePoint:s,transfer:Fa,toXYZ:Qa,fromXYZ:Ja,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:xe},outputColorSpaceConfig:{drawingBufferColorSpace:xe}},[xe]:{primaries:t,whitePoint:s,transfer:Fi,toXYZ:Qa,fromXYZ:Ja,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:xe}}}),r}const bt=sp();function Ye(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function Qs(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}const Ml={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},$e={h:0,s:0,l:0},fn={h:0,s:0,l:0};function Dr(r,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?r+(t-r)*6*e:e<1/2?t:e<2/3?r+(t-r)*6*(2/3-e):r}class qi{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(e===void 0&&s===void 0){const i=t;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}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=(t&255)/255,bt.colorSpaceToWorking(this,e),this}setRGB(t,e,s,i=bt.workingColorSpace){return this.r=t,this.g=e,this.b=s,bt.colorSpaceToWorking(this,i),this}setHSL(t,e,s,i=bt.workingColorSpace){if(t=zo(t,1),e=X(e,0,1),s=X(s,0,1),e===0)this.r=this.g=this.b=s;else{const n=s<=.5?s*(1+e):s+e-s*e,o=2*s-n;this.r=Dr(o,n,t+1/3),this.g=Dr(o,n,t),this.b=Dr(o,n,t-1/3)}return bt.colorSpaceToWorking(this,i),this}setStyle(t,e=xe){function s(n){n!==void 0&&parseFloat(n)<1&&W("Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let n;const o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,e);if(n=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,e);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return s(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,e);break;default:W("Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const n=i[1],o=n.length;if(o===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(o===6)return this.setHex(parseInt(n,16),e);W("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=xe){const s=Ml[t.toLowerCase()];return s!==void 0?this.setHex(s,e):W("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=Ye(t.r),this.g=Ye(t.g),this.b=Ye(t.b),this}copyLinearToSRGB(t){return this.r=Qs(t.r),this.g=Qs(t.g),this.b=Qs(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=xe){return bt.workingToColorSpace(zt.copy(this),t),Math.round(X(zt.r*255,0,255))*65536+Math.round(X(zt.g*255,0,255))*256+Math.round(X(zt.b*255,0,255))}getHexString(t=xe){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=bt.workingColorSpace){bt.workingToColorSpace(zt.copy(this),e);const s=zt.r,i=zt.g,n=zt.b,o=Math.max(s,i,n),a=Math.min(s,i,n);let h,l;const c=(a+o)/2;if(a===o)h=0,l=0;else{const u=o-a;switch(l=c<=.5?u/(o+a):u/(2-o-a),o){case s:h=(i-n)/u+(i<n?6:0);break;case i:h=(n-s)/u+2;break;case n:h=(s-i)/u+4;break}h/=6}return t.h=h,t.s=l,t.l=c,t}getRGB(t,e=bt.workingColorSpace){return bt.workingToColorSpace(zt.copy(this),e),t.r=zt.r,t.g=zt.g,t.b=zt.b,t}getStyle(t=xe){bt.workingToColorSpace(zt.copy(this),t);const e=zt.r,s=zt.g,i=zt.b;return t!==xe?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(s*255)},${Math.round(i*255)})`}offsetHSL(t,e,s){return this.getHSL($e),this.setHSL($e.h+t,$e.s+e,$e.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($e),t.getHSL(fn);const s=ns($e.h,fn.h,e),i=ns($e.s,fn.s,e),n=ns($e.l,fn.l,e);return this.setHSL(s,i,n),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,n=t.elements;return this.r=n[0]*e+n[3]*s+n[6]*i,this.g=n[1]*e+n[4]*s+n[7]*i,this.b=n[2]*e+n[5]*s+n[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 zt=new qi;qi.NAMES=Ml;class li{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s===void 0?!1:s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners;if(s===void 0)return;const i=s[t];if(i!==void 0){const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const s=e[t.type];if(s!==void 0){t.target=this;const i=s.slice(0);for(let n=0,o=i.length;n<o;n++)i[n].call(this,t);t.target=null}}}let ip=0;class So extends li{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:ip++}),this.uuid=Ge(),this.name="",this.type="Material",this.blending=Ma,this.side=To,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Aa,this.blendDst=Ea,this.blendEquation=Na,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new qi(0,0,0),this.blendAlpha=0,this.depthFunc=Oa,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=za,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=As,this.stencilZFail=As,this.stencilZPass=As,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const s=t[e];if(s===void 0){W(`Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];if(i===void 0){W(`Material: '${e}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const s={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),this.roughness!==void 0&&(s.roughness=this.roughness),this.metalness!==void 0&&(s.metalness=this.metalness),this.sheen!==void 0&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(s.shininess=this.shininess),this.clearcoat!==void 0&&(s.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(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()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(s.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(s.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),this.dispersion!==void 0&&(s.dispersion=this.dispersion),this.iridescence!==void 0&&(s.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(s.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(s.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(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,this.combine!==void 0&&(s.combine=this.combine)),this.envMapRotation!==void 0&&(s.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(s.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(s.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(s.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(s.size=this.size),this.shadowSide!==null&&(s.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(s.sizeAttenuation=this.sizeAttenuation),this.blending!==Ma&&(s.blending=this.blending),this.side!==To&&(s.side=this.side),this.vertexColors===!0&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),this.transparent===!0&&(s.transparent=!0),this.blendSrc!==Aa&&(s.blendSrc=this.blendSrc),this.blendDst!==Ea&&(s.blendDst=this.blendDst),this.blendEquation!==Na&&(s.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(s.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(s.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(s.blendAlpha=this.blendAlpha),this.depthFunc!==Oa&&(s.depthFunc=this.depthFunc),this.depthTest===!1&&(s.depthTest=this.depthTest),this.depthWrite===!1&&(s.depthWrite=this.depthWrite),this.colorWrite===!1&&(s.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==za&&(s.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(s.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==As&&(s.stencilFail=this.stencilFail),this.stencilZFail!==As&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==As&&(s.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(s.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(s.rotation=this.rotation),this.polygonOffset===!0&&(s.polygonOffset=!0),this.polygonOffsetFactor!==0&&(s.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(s.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(s.linewidth=this.linewidth),this.dashSize!==void 0&&(s.dashSize=this.dashSize),this.gapSize!==void 0&&(s.gapSize=this.gapSize),this.scale!==void 0&&(s.scale=this.scale),this.dithering===!0&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),this.alphaHash===!0&&(s.alphaHash=!0),this.alphaToCoverage===!0&&(s.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(s.premultipliedAlpha=!0),this.forceSinglePass===!0&&(s.forceSinglePass=!0),this.allowOverride===!1&&(s.allowOverride=!1),this.wireframe===!0&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(s.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(s.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(s.flatShading=!0),this.visible===!1&&(s.visible=!1),this.toneMapped===!1&&(s.toneMapped=!1),this.fog===!1&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData);function i(n){const o=[];for(const a in n){const h=n[a];delete h.metadata,o.push(h)}return o}if(e){const n=i(t.textures),o=i(t.images);n.length>0&&(s.textures=n),o.length>0&&(s.images=o)}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(e!==null){const i=e.length;s=new Array(i);for(let n=0;n!==i;++n)s[n]=e[n].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.allowOverride=t.allowOverride,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){t===!0&&this.version++}}class Do{constructor(t,e,s,i){Do.prototype.isMatrix2=!0,this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let s=0;s<4;s++)this.elements[s]=t[s+e];return this}set(t,e,s,i){const n=this.elements;return n[0]=t,n[2]=e,n[1]=s,n[3]=i,this}}class ci{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,n,o,a){let h=s[i+0],l=s[i+1],c=s[i+2],u=s[i+3],d=n[o+0],p=n[o+1],m=n[o+2],f=n[o+3];if(u!==f||h!==d||l!==p||c!==m){let y=h*d+l*p+c*m+u*f;y<0&&(d=-d,p=-p,m=-m,f=-f,y=-y);let g=1-a;if(y<.9995){const x=Math.acos(y),C=Math.sin(x);g=Math.sin(g*x)/C,a=Math.sin(a*x)/C,h=h*g+d*a,l=l*g+p*a,c=c*g+m*a,u=u*g+f*a}else{h=h*g+d*a,l=l*g+p*a,c=c*g+m*a,u=u*g+f*a;const x=1/Math.sqrt(h*h+l*l+c*c+u*u);h*=x,l*=x,c*=x,u*=x}}t[e]=h,t[e+1]=l,t[e+2]=c,t[e+3]=u}static multiplyQuaternionsFlat(t,e,s,i,n,o){const a=s[i],h=s[i+1],l=s[i+2],c=s[i+3],u=n[o],d=n[o+1],p=n[o+2],m=n[o+3];return t[e]=a*m+c*u+h*p-l*d,t[e+1]=h*m+c*d+l*u-a*p,t[e+2]=l*m+c*p+a*d-h*u,t[e+3]=c*m-a*u-h*d-l*p,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,n=t._z,o=t._order,a=Math.cos,h=Math.sin,l=a(s/2),c=a(i/2),u=a(n/2),d=h(s/2),p=h(i/2),m=h(n/2);switch(o){case"XYZ":this._x=d*c*u+l*p*m,this._y=l*p*u-d*c*m,this._z=l*c*m+d*p*u,this._w=l*c*u-d*p*m;break;case"YXZ":this._x=d*c*u+l*p*m,this._y=l*p*u-d*c*m,this._z=l*c*m-d*p*u,this._w=l*c*u+d*p*m;break;case"ZXY":this._x=d*c*u-l*p*m,this._y=l*p*u+d*c*m,this._z=l*c*m+d*p*u,this._w=l*c*u-d*p*m;break;case"ZYX":this._x=d*c*u-l*p*m,this._y=l*p*u+d*c*m,this._z=l*c*m-d*p*u,this._w=l*c*u+d*p*m;break;case"YZX":this._x=d*c*u+l*p*m,this._y=l*p*u+d*c*m,this._z=l*c*m-d*p*u,this._w=l*c*u-d*p*m;break;case"XZY":this._x=d*c*u-l*p*m,this._y=l*p*u-d*c*m,this._z=l*c*m+d*p*u,this._w=l*c*u+d*p*m;break;default:W("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return e===!0&&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],n=e[8],o=e[1],a=e[5],h=e[9],l=e[2],c=e[6],u=e[10],d=s+a+u;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(c-h)*p,this._y=(n-l)*p,this._z=(o-i)*p}else if(s>a&&s>u){const p=2*Math.sqrt(1+s-a-u);this._w=(c-h)/p,this._x=.25*p,this._y=(i+o)/p,this._z=(n+l)/p}else if(a>u){const p=2*Math.sqrt(1+a-s-u);this._w=(n-l)/p,this._x=(i+o)/p,this._y=.25*p,this._z=(h+c)/p}else{const p=2*Math.sqrt(1+u-s-a);this._w=(o-i)/p,this._x=(n+l)/p,this._y=(h+c)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(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(X(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(s===0)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 t===0?(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,n=t._z,o=t._w,a=e._x,h=e._y,l=e._z,c=e._w;return this._x=s*c+o*a+i*l-n*h,this._y=i*c+o*h+n*a-s*l,this._z=n*c+o*l+s*h-i*a,this._w=o*c-s*a-i*h-n*l,this._onChangeCallback(),this}slerp(t,e){let s=t._x,i=t._y,n=t._z,o=t._w,a=this.dot(t);a<0&&(s=-s,i=-i,n=-n,o=-o,a=-a);let h=1-e;if(a<.9995){const l=Math.acos(a),c=Math.sin(l);h=Math.sin(h*l)/c,e=Math.sin(e*l)/c,this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+n*e,this._w=this._w*h+o*e,this._onChangeCallback()}else this._x=this._x*h+s*e,this._y=this._y*h+i*e,this._z=this._z*h+n*e,this._w=this._w*h+o*e,this.normalize();return 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),n=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),n*Math.sin(e),n*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 M{constructor(t=0,e=0,s=0){M.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return s===void 0&&(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(Ka.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ka.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,n=t.elements;return this.x=n[0]*e+n[3]*s+n[6]*i,this.y=n[1]*e+n[4]*s+n[7]*i,this.z=n[2]*e+n[5]*s+n[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,n=t.elements,o=1/(n[3]*e+n[7]*s+n[11]*i+n[15]);return this.x=(n[0]*e+n[4]*s+n[8]*i+n[12])*o,this.y=(n[1]*e+n[5]*s+n[9]*i+n[13])*o,this.z=(n[2]*e+n[6]*s+n[10]*i+n[14])*o,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,n=t.x,o=t.y,a=t.z,h=t.w,l=2*(o*i-a*s),c=2*(a*e-n*i),u=2*(n*s-o*e);return this.x=e+h*l+o*u-a*c,this.y=s+h*c+a*l-n*u,this.z=i+h*u+n*c-o*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i,this.y=n[1]*e+n[5]*s+n[9]*i,this.z=n[2]*e+n[6]*s+n[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=X(this.x,t.x,e.x),this.y=X(this.y,t.y,e.y),this.z=X(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=X(this.x,t,e),this.y=X(this.y,t,e),this.z=X(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(X(s,t,e))}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,n=t.z,o=e.x,a=e.y,h=e.z;return this.x=i*h-n*a,this.y=n*o-s*h,this.z=s*a-i*o,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Br.copy(this).projectOnVector(t),this.sub(Br)}reflect(t){return this.sub(Br.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(X(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,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}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=Math.random()*2-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 Br=new M,Ka=new ci;class Rt{constructor(t,e,s,i,n,o,a,h,l,c,u,d,p,m,f,y){Rt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,s,i,n,o,a,h,l,c,u,d,p,m,f,y)}set(t,e,s,i,n,o,a,h,l,c,u,d,p,m,f,y){const g=this.elements;return g[0]=t,g[4]=e,g[8]=s,g[12]=i,g[1]=n,g[5]=o,g[9]=a,g[13]=h,g[2]=l,g[6]=c,g[10]=u,g[14]=d,g[3]=p,g[7]=m,g[11]=f,g[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Rt().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 this.determinant()===0?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(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){if(t.determinant()===0)return this.identity();const e=this.elements,s=t.elements,i=1/Ps.setFromMatrixColumn(t,0).length(),n=1/Ps.setFromMatrixColumn(t,1).length(),o=1/Ps.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]*n,e[5]=s[5]*n,e[6]=s[6]*n,e[7]=0,e[8]=s[8]*o,e[9]=s[9]*o,e[10]=s[10]*o,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,n=t.z,o=Math.cos(s),a=Math.sin(s),h=Math.cos(i),l=Math.sin(i),c=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const d=o*c,p=o*u,m=a*c,f=a*u;e[0]=h*c,e[4]=-h*u,e[8]=l,e[1]=p+m*l,e[5]=d-f*l,e[9]=-a*h,e[2]=f-d*l,e[6]=m+p*l,e[10]=o*h}else if(t.order==="YXZ"){const d=h*c,p=h*u,m=l*c,f=l*u;e[0]=d+f*a,e[4]=m*a-p,e[8]=o*l,e[1]=o*u,e[5]=o*c,e[9]=-a,e[2]=p*a-m,e[6]=f+d*a,e[10]=o*h}else if(t.order==="ZXY"){const d=h*c,p=h*u,m=l*c,f=l*u;e[0]=d-f*a,e[4]=-o*u,e[8]=m+p*a,e[1]=p+m*a,e[5]=o*c,e[9]=f-d*a,e[2]=-o*l,e[6]=a,e[10]=o*h}else if(t.order==="ZYX"){const d=o*c,p=o*u,m=a*c,f=a*u;e[0]=h*c,e[4]=m*l-p,e[8]=d*l+f,e[1]=h*u,e[5]=f*l+d,e[9]=p*l-m,e[2]=-l,e[6]=a*h,e[10]=o*h}else if(t.order==="YZX"){const d=o*h,p=o*l,m=a*h,f=a*l;e[0]=h*c,e[4]=f-d*u,e[8]=m*u+p,e[1]=u,e[5]=o*c,e[9]=-a*c,e[2]=-l*c,e[6]=p*u+m,e[10]=d-f*u}else if(t.order==="XZY"){const d=o*h,p=o*l,m=a*h,f=a*l;e[0]=h*c,e[4]=-u,e[8]=l*c,e[1]=d*u+f,e[5]=o*c,e[9]=p*u-m,e[2]=m*u-p,e[6]=a*c,e[10]=f*u+d}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(np,t,rp)}lookAt(t,e,s){const i=this.elements;return qt.subVectors(t,e),qt.lengthSq()===0&&(qt.z=1),qt.normalize(),Xe.crossVectors(s,qt),Xe.lengthSq()===0&&(Math.abs(s.z)===1?qt.x+=1e-4:qt.z+=1e-4,qt.normalize(),Xe.crossVectors(s,qt)),Xe.normalize(),gn.crossVectors(qt,Xe),i[0]=Xe.x,i[4]=gn.x,i[8]=qt.x,i[1]=Xe.y,i[5]=gn.y,i[9]=qt.y,i[2]=Xe.z,i[6]=gn.z,i[10]=qt.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,n=this.elements,o=s[0],a=s[4],h=s[8],l=s[12],c=s[1],u=s[5],d=s[9],p=s[13],m=s[2],f=s[6],y=s[10],g=s[14],x=s[3],C=s[7],b=s[11],A=s[15],N=i[0],E=i[4],O=i[8],P=i[12],k=i[1],$=i[5],ct=i[9],tt=i[13],it=i[2],j=i[6],le=i[10],Ct=i[14],Ut=i[3],Q=i[7],gt=i[11],At=i[15];return n[0]=o*N+a*k+h*it+l*Ut,n[4]=o*E+a*$+h*j+l*Q,n[8]=o*O+a*ct+h*le+l*gt,n[12]=o*P+a*tt+h*Ct+l*At,n[1]=c*N+u*k+d*it+p*Ut,n[5]=c*E+u*$+d*j+p*Q,n[9]=c*O+u*ct+d*le+p*gt,n[13]=c*P+u*tt+d*Ct+p*At,n[2]=m*N+f*k+y*it+g*Ut,n[6]=m*E+f*$+y*j+g*Q,n[10]=m*O+f*ct+y*le+g*gt,n[14]=m*P+f*tt+y*Ct+g*At,n[3]=x*N+C*k+b*it+A*Ut,n[7]=x*E+C*$+b*j+A*Q,n[11]=x*O+C*ct+b*le+A*gt,n[15]=x*P+C*tt+b*Ct+A*At,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],n=t[12],o=t[1],a=t[5],h=t[9],l=t[13],c=t[2],u=t[6],d=t[10],p=t[14],m=t[3],f=t[7],y=t[11],g=t[15],x=h*p-l*d,C=a*p-l*u,b=a*d-h*u,A=o*p-l*c,N=o*d-h*c,E=o*u-a*c;return e*(f*x-y*C+g*b)-s*(m*x-y*A+g*N)+i*(m*C-f*A+g*E)-n*(m*b-f*N+y*E)}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],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],u=t[9],d=t[10],p=t[11],m=t[12],f=t[13],y=t[14],g=t[15],x=e*a-s*o,C=e*h-i*o,b=e*l-n*o,A=s*h-i*a,N=s*l-n*a,E=i*l-n*h,O=c*f-u*m,P=c*y-d*m,k=c*g-p*m,$=u*y-d*f,ct=u*g-p*f,tt=d*g-p*y,it=x*tt-C*ct+b*$+A*k-N*P+E*O;if(it===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const j=1/it;return t[0]=(a*tt-h*ct+l*$)*j,t[1]=(i*ct-s*tt-n*$)*j,t[2]=(f*E-y*N+g*A)*j,t[3]=(d*N-u*E-p*A)*j,t[4]=(h*k-o*tt-l*P)*j,t[5]=(e*tt-i*k+n*P)*j,t[6]=(y*b-m*E-g*C)*j,t[7]=(c*E-d*b+p*C)*j,t[8]=(o*ct-a*k+l*O)*j,t[9]=(s*k-e*ct-n*O)*j,t[10]=(m*N-f*b+g*x)*j,t[11]=(u*b-c*N-p*x)*j,t[12]=(a*P-o*$-h*O)*j,t[13]=(e*$-s*P+i*O)*j,t[14]=(f*C-m*A-y*x)*j,t[15]=(c*A-u*C+d*x)*j,this}scale(t){const e=this.elements,s=t.x,i=t.y,n=t.z;return e[0]*=s,e[4]*=i,e[8]*=n,e[1]*=s,e[5]*=i,e[9]*=n,e[2]*=s,e[6]*=i,e[10]*=n,e[3]*=s,e[7]*=i,e[11]*=n,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),n=1-s,o=t.x,a=t.y,h=t.z,l=n*o,c=n*a;return this.set(l*o+s,l*a-i*h,l*h+i*a,0,l*a+i*h,c*a+s,c*h-i*o,0,l*h-i*a,c*h+i*o,n*h*h+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,n,o){return this.set(1,s,n,0,t,1,o,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,n=e._x,o=e._y,a=e._z,h=e._w,l=n+n,c=o+o,u=a+a,d=n*l,p=n*c,m=n*u,f=o*c,y=o*u,g=a*u,x=h*l,C=h*c,b=h*u,A=s.x,N=s.y,E=s.z;return i[0]=(1-(f+g))*A,i[1]=(p+b)*A,i[2]=(m-C)*A,i[3]=0,i[4]=(p-b)*N,i[5]=(1-(d+g))*N,i[6]=(y+x)*N,i[7]=0,i[8]=(m+C)*E,i[9]=(y-x)*E,i[10]=(1-(d+f))*E,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;t.x=i[12],t.y=i[13],t.z=i[14];const n=this.determinant();if(n===0)return s.set(1,1,1),e.identity(),this;let o=Ps.set(i[0],i[1],i[2]).length();const a=Ps.set(i[4],i[5],i[6]).length(),h=Ps.set(i[8],i[9],i[10]).length();n<0&&(o=-o),ue.copy(this);const l=1/o,c=1/a,u=1/h;return ue.elements[0]*=l,ue.elements[1]*=l,ue.elements[2]*=l,ue.elements[4]*=c,ue.elements[5]*=c,ue.elements[6]*=c,ue.elements[8]*=u,ue.elements[9]*=u,ue.elements[10]*=u,e.setFromRotationMatrix(ue),s.x=o,s.y=a,s.z=h,this}makePerspective(t,e,s,i,n,o,a=je,h=!1){const l=this.elements,c=2*n/(e-t),u=2*n/(s-i),d=(e+t)/(e-t),p=(s+i)/(s-i);let m,f;if(h)m=n/(o-n),f=o*n/(o-n);else if(a===je)m=-(o+n)/(o-n),f=-2*o*n/(o-n);else if(a===ni)m=-o/(o-n),f=-o*n/(o-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=c,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=u,l[9]=p,l[13]=0,l[2]=0,l[6]=0,l[10]=m,l[14]=f,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,s,i,n,o,a=je,h=!1){const l=this.elements,c=2/(e-t),u=2/(s-i),d=-(e+t)/(e-t),p=-(s+i)/(s-i);let m,f;if(h)m=1/(o-n),f=o/(o-n);else if(a===je)m=-2/(o-n),f=-(o+n)/(o-n);else if(a===ni)m=-1/(o-n),f=-n/(o-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=c,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=u,l[9]=0,l[13]=p,l[2]=0,l[6]=0,l[10]=m,l[14]=f,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let i=0;i<16;i++)if(e[i]!==s[i])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 Ps=new M,ue=new Rt,np=new M(0,0,0),rp=new M(1,1,1),Xe=new M,gn=new M,qt=new M;class _t{constructor(t=0,e=0){_t.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=X(this.x,t.x,e.x),this.y=X(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=X(this.x,t,e),this.y=X(this.y,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(X(s,t,e))}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(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(X(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),n=this.x-t.x,o=this.y-t.y;return this.x=n*s-o*i+t.x,this.y=n*i+o*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Wt{constructor(t=0,e=0,s=0,i=1){Wt.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=t.w!==void 0?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,n=this.w,o=t.elements;return this.x=o[0]*e+o[4]*s+o[8]*i+o[12]*n,this.y=o[1]*e+o[5]*s+o[9]*i+o[13]*n,this.z=o[2]*e+o[6]*s+o[10]*i+o[14]*n,this.w=o[3]*e+o[7]*s+o[11]*i+o[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,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,n;const h=t.elements,l=h[0],c=h[4],u=h[8],d=h[1],p=h[5],m=h[9],f=h[2],y=h[6],g=h[10];if(Math.abs(c-d)<.01&&Math.abs(u-f)<.01&&Math.abs(m-y)<.01){if(Math.abs(c+d)<.1&&Math.abs(u+f)<.1&&Math.abs(m+y)<.1&&Math.abs(l+p+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const C=(l+1)/2,b=(p+1)/2,A=(g+1)/2,N=(c+d)/4,E=(u+f)/4,O=(m+y)/4;return C>b&&C>A?C<.01?(s=0,i=.707106781,n=.707106781):(s=Math.sqrt(C),i=N/s,n=E/s):b>A?b<.01?(s=.707106781,i=0,n=.707106781):(i=Math.sqrt(b),s=N/i,n=O/i):A<.01?(s=.707106781,i=.707106781,n=0):(n=Math.sqrt(A),s=E/n,i=O/n),this.set(s,i,n,e),this}let x=Math.sqrt((y-m)*(y-m)+(u-f)*(u-f)+(d-c)*(d-c));return Math.abs(x)<.001&&(x=1),this.x=(y-m)/x,this.y=(u-f)/x,this.z=(d-c)/x,this.w=Math.acos((l+p+g-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=X(this.x,t.x,e.x),this.y=X(this.y,t.y,e.y),this.z=X(this.z,t.z,e.z),this.w=X(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=X(this.x,t,e),this.y=X(this.y,t,e),this.z=X(this.z,t,e),this.w=X(this.w,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(X(s,t,e))}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}}const op=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];function ap(r){const t=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return r.split(`
85
+ `).map(e=>{const s=e.match(t);if(!s)return null;const i=s[1]||s[2]||"",n=s[3].split("?")[0],o=parseInt(s[4],10),a=parseInt(s[5],10),h=n.split("/").pop();return{fn:i,file:h,line:o,column:a}}).filter(e=>e&&!op.some(s=>s.test(e.file)))}class oe{constructor(t=null){this.isStackTrace=!0,this.stack=ap(t||new Error().stack)}getLocation(){if(this.stack.length===0)return"[Unknown location]";const t=this.stack[0],e=t.fn;return`${e?`"${e}()" at `:""}"${t.file}:${t.line}"`}getError(t){if(this.stack.length===0)return t;const e=this.stack.map(s=>{const i=`${s.file}:${s.line}:${s.column}`;return s.fn?` at ${s.fn} (${i})`:` at ${i}`}).join(`
86
+ `);return`${t}
87
+ ${e}`}}function Bo(r,t=0){let e=3735928559^t,s=1103547991^t;if(r instanceof Array)for(let i=0,n;i<r.length;i++)n=r[i],e=Math.imul(e^n,2654435761),s=Math.imul(s^n,1597334677);else for(let i=0,n;i<r.length;i++)n=r.charCodeAt(i),e=Math.imul(e^n,2654435761),s=Math.imul(s^n,1597334677);return e=Math.imul(e^e>>>16,2246822507),e^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(e^e>>>13,3266489909),4294967296*(2097151&s)+(e>>>0)}const ko=r=>Bo(r),Nl=r=>Bo(r),Al=(...r)=>Bo(r),hp=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]);function lp(r){return hp.get(r)}function nr(r){if(r==null)return null;const t=typeof r;return r.isNode===!0?"node":t==="number"?"float":t==="boolean"?"bool":t==="string"?"string":t==="function"?"shader":r.isVector2===!0?"vec2":r.isVector3===!0?"vec3":r.isVector4===!0?"vec4":r.isMatrix2===!0?"mat2":r.isMatrix3===!0?"mat3":r.isMatrix4===!0?"mat4":r.isColor===!0?"color":r instanceof ArrayBuffer?"ArrayBuffer":null}function Uo(r,...t){const e=r?r.slice(-4):void 0;return t.length===1&&(e==="vec2"?t=[t[0],t[0]]:e==="vec3"?t=[t[0],t[0],t[0]]:e==="vec4"&&(t=[t[0],t[0],t[0],t[0]])),r==="color"?new qi(...t):e==="vec2"?new _t(...t):e==="vec3"?new M(...t):e==="vec4"?new Wt(...t):e==="mat2"?new Do(...t):e==="mat3"?new he(...t):e==="mat4"?new Rt(...t):r==="bool"?t[0]||!1:r==="float"||r==="int"||r==="uint"?t[0]||0:r==="string"?t[0]||"":r==="ArrayBuffer"?up(t[0]):null}function cp(r){let t="";const e=new Uint8Array(r);for(let s=0;s<e.length;s++)t+=String.fromCharCode(e[s]);return btoa(t)}function up(r){return Uint8Array.from(atob(r),t=>t.charCodeAt(0)).buffer}const yn={VERTEX:"vertex"},nt={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},th={READ_ONLY:"readOnly",READ_WRITE:"readWrite"},Qi=["x","y","z","w"],dp={analyze:"setup",generate:"analyze"};let pp=0;class B extends li{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=nt.NONE,this.updateBeforeType=nt.NONE,this.updateAfterType=nt.NONE,this.uuid=Nd.generateUUID(),this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:pp++}),this.stackTrace=null,B.captureStackTrace===!0&&(this.stackTrace=new oe)}set needsUpdate(t){t===!0&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this),this}onFrameUpdate(t){return this.onUpdate(t,nt.FRAME)}onRenderUpdate(t){return this.onUpdate(t,nt.RENDER)}onObjectUpdate(t){return this.onUpdate(t,nt.OBJECT)}onReference(t){return this.updateReference=t.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of this._getChildren())yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}_getChildren(t=new Set){const e=[];t.add(this);for(const s of Object.getOwnPropertyNames(this)){const i=this[s];if(!(s.startsWith("_")===!0||t.has(i))){if(Array.isArray(i)===!0)for(let n=0;n<i.length;n++){const o=i[n];o&&o.isNode===!0&&e.push({property:s,index:n,childNode:o})}else if(i&&i.isNode===!0)e.push({property:s,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(const n in i){if(n.startsWith("_")===!0)continue;const o=i[n];o&&o.isNode===!0&&e.push({property:s,index:n,childNode:o})}}}return e}getCacheKey(t=!1,e=null){if(t=t||this.version!==this._cacheKeyVersion,t===!0||this._cacheKey===null){e===null&&(e=new Set);const s=[];for(const{property:i,childNode:n}of this._getChildren(e))s.push(ko(i.slice(0,-4)),n.getCacheKey(t,e));this._cacheKey=Al(Nl(s),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getMemberType(){return"void"}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}getArrayCount(){return null}setup(t){const e=t.getNodeProperties(this);let s=0;for(const i of this.getChildren())e["node"+s++]=i;return e.outputNode||null}analyze(t,e=null){const s=t.increaseUsage(this);if(this.parents===!0){const i=t.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[t.shaderStage]=i.stages[t.shaderStage]||[],i.stages[t.shaderStage].push(e)}if(s===1){const i=t.getNodeProperties(this);for(const n of Object.values(i))n&&n.isNode===!0&&n.build(t,this)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(t,e)}updateBefore(){W("Abstract function.")}updateAfter(){W("Abstract function.")}update(){W("Abstract function.")}before(t){return this._beforeNodes===null&&(this._beforeNodes=[]),this._beforeNodes.push(t),this}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);if(this._beforeNodes!==null){const h=this._beforeNodes;this._beforeNodes=null;for(const l of h)l.build(t,e);this._beforeNodes=h}const i=t.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[t.buildStage]=!0;const n=dp[t.buildStage];if(n&&i.buildStages[n]!==!0){const h=t.getBuildStage();t.setBuildStage(n),this.build(t),t.setBuildStage(h)}t.addChain(this);let o=null;const a=t.getBuildStage();if(a==="setup"){t.addNode(this),this.updateReference(t);const h=t.getNodeProperties(this);if(h.initialized!==!0){h.initialized=!0,h.outputNode=this.setup(t)||h.outputNode||null;for(const l of Object.values(h))if(l&&l.isNode===!0){if(l.parents===!0){const c=t.getNodeProperties(l);c.parents=c.parents||[],c.parents.push(this)}l.build(t)}t.addSequentialNode(this)}o=h.outputNode}else if(a==="analyze")this.analyze(t,e);else if(a==="generate"){if(this.generate.length<2){const l=this.getNodeType(t),c=t.getDataFromNode(this);o=c.snippet,o===void 0?c.generated===void 0?(c.generated=!0,o=this.generate(t)||"",c.snippet=o):(W("Node: Recursion detected.",this),o="/* Recursion detected. */"):c.flowCodes!==void 0&&t.context.nodeBlock!==void 0&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),o=t.format(o,l,e)}else o=this.generate(t,e)||"";o===""&&e!==null&&e!=="void"&&e!=="OutputType"&&(rt(`TSL: Invalid generated code, expected a "${e}".`),o=t.generateConst(e))}return t.removeChain(this),o}getSerializeChildren(){return this._getChildren()}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:n,childNode:o}of e)n!==void 0?(s[i]===void 0&&(s[i]=Number.isInteger(n)?[]:{}),s[i][n]=o.toJSON(t.meta).uuid):s[i]=o.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(t.inputNodes!==void 0){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const n of t.inputNodes[s])i.push(e[n]);this[s]=i}else if(typeof t.inputNodes[s]=="object"){const i={};for(const n in t.inputNodes[s]){const o=t.inputNodes[s][n];i[n]=e[o]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=t===void 0||typeof t=="string";i&&(t={textures:{},images:{},nodes:{}});let n=t.nodes[e];n===void 0&&(n={uuid:e,type:s,meta:t,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(t.nodes[n.uuid]=n),this.serialize(n),delete n.meta);function o(a){const h=[];for(const l in a){const c=a[l];delete c.metadata,h.push(c)}return h}if(i){const a=o(t.textures),h=o(t.images),l=o(t.nodes);a.length>0&&(n.textures=a),h.length>0&&(n.images=h),l.length>0&&(n.nodes=l)}return n}}B.captureStackTrace=!1;class ui extends B{static get type(){return"ArrayElementNode"}constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}getMemberType(t,e){return this.node.getMemberType(t,e)}generate(t){const e=this.indexNode.getNodeType(t),s=this.node.build(t),i=this.indexNode.build(t,!t.isVector(e)&&t.isInteger(e)?e:"uint");return`${s}[ ${i} ]`}}class El extends B{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))(s===null||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),n=s.build(t,i);return t.format(n,i,e)}}class It extends B{static get type(){return"TempNode"}constructor(t=null){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if(t.getBuildStage()==="generate"){const i=t.getVectorType(this.getNodeType(t,e)),n=t.getDataFromNode(this);if(n.propertyName!==void 0)return t.format(n.propertyName,i,e);if(i!=="void"&&e!=="void"&&this.hasDependencies(t)){const o=super.build(t,i),a=t.getVarFromNode(this,null,i),h=t.getPropertyName(a);return t.addLineFlowCode(`${h} = ${o}`,this),n.snippet=o,n.propertyName=h,t.format(n.propertyName,i,e)}}return super.build(t,e)}}class mp extends It{static get type(){return"JoinNode"}constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return this.nodeType!==null?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=t.getTypeLength(s),n=this.nodes,o=t.getComponentType(s),a=[];let h=0;for(const c of n){if(h>=i){rt(`TSL: Length of parameters exceeds maximum length of function '${s}()' type.`,this.stackTrace);break}let u=c.getNodeType(t),d=t.getTypeLength(u),p;if(h+d>i&&(rt(`TSL: Length of '${s}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-h,u=t.getTypeFromLength(d)),h+=d,p=c.build(t,u),t.getComponentType(u)!==o){const f=t.getTypeFromLength(d,o);p=t.format(p,u,f)}a.push(p)}const l=`${t.getType(s)}( ${a.join(", ")} )`;return t.format(l,s,e)}}const fp=Qi.join("");class gp extends B{static get type(){return"SplitNode"}constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Qi.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))}getScope(){return this.node.getScope()}generate(t,e){const s=this.node,i=t.getTypeLength(s.getNodeType(t));let n=null;if(i>1){let o=null;this.getVectorLength()>=i&&(o=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const h=s.build(t,o);this.components.length===i&&this.components===fp.slice(0,this.components.length)?n=t.format(h,o,e):n=t.format(`${h}.${this.components}`,this.getNodeType(t),e)}else n=s.build(t,e);return n}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class yp extends It{static get type(){return"SetNode"}constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,n=this.getNodeType(t),o=t.getComponentType(i.getNodeType(t)),a=t.getTypeFromLength(s.length,o),h=i.build(t,a),l=e.build(t,n),c=t.getTypeLength(n),u=[];for(let d=0;d<c;d++){const p=Qi[d];p===s[0]?(u.push(h),d+=s.length-1):u.push(l+"."+p)}return`${t.getType(n)}( ${u.join(", ")} )`}}class xp extends It{static get type(){return"FlipNode"}constructor(t,e){super(),this.sourceNode=t,this.components=e}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{components:e,sourceNode:s}=this,i=this.getNodeType(t),n=s.build(t),o=t.getVarFromNode(this),a=t.getPropertyName(o);t.addLineFlowCode(a+" = "+n,this);const h=t.getTypeLength(i),l=[];let c=0;for(let u=0;u<h;u++){const d=Qi[u];d===e[c]?(l.push("1.0 - "+(a+"."+d)),c++):l.push(a+"."+d)}return`${t.getType(i)}( ${l.join(", ")} )`}}class Vo extends B{static get type(){return"InputNode"}constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return this.nodeType===null?nr(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=nr(this.value),t.nodeType=this.nodeType,t.valueType==="ArrayBuffer"&&(t.value=cp(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?Uo(t.valueType,...t.value):t.value,this.precision=t.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(t.value))}generate(){W("Abstract function.")}}const eh=/float|u?int/;class Le extends Vo{static get type(){return"ConstNode"}constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const s=this.getNodeType(t);return eh.test(s)&&eh.test(e)?t.generateConst(e,this.value):t.format(this.generateConst(t),s,e)}}class _p extends B{static get type(){return"MemberNode"}constructor(t,e){super(),this.structNode=t,this.property=e,this.isMemberNode=!0}hasMember(t){return this.structNode.isMemberNode&&this.structNode.hasMember(t)===!1?!1:this.structNode.getMemberType(t,this.property)!=="void"}getNodeType(t){return this.hasMember(t)===!1?"float":this.structNode.getMemberType(t,this.property)}getMemberType(t,e){if(this.hasMember(t)===!1)return"float";const s=this.getNodeType(t);return t.getStructTypeNode(s).getMemberType(t,e)}generate(t){if(this.hasMember(t)===!1){W(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);const s=this.getNodeType(t);return t.generateConst(s)}return this.structNode.build(t)+"."+this.property}}let Tp=null;const Mo=new Map;function S(r,t){if(Mo.has(r)){W(`TSL: Redefinition of method chaining '${r}'.`);return}if(typeof t!="function")throw new Error(`THREE.TSL: Node element ${r} is not a function`);Mo.set(r,t),r!=="assign"&&(B.prototype[r]=function(...e){return this.isStackNode?this.addToStack(t(...e)):t(this,...e)},B.prototype[r+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}const vp=r=>r.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),sh=r=>vp(r).split("").sort().join("");B.prototype.assign=function(...r){if(this.isStackNode!==!0)return rt("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new oe),this;{const t=Mo.get("assign");return this.addToStack(t(...r))}};B.prototype.toVarIntent=function(){return this};B.prototype.get=function(r){return new _p(this,r)};const Bi={};function xn(r,t,e){Bi[r]=Bi[t]=Bi[e]={get(){this._cache=this._cache||{};let o=this._cache[r];return o===void 0&&(o=new gp(this,r),this._cache[r]=o),o},set(o){this[r].assign(D(o))}};const s=r.toUpperCase(),i=t.toUpperCase(),n=e.toUpperCase();B.prototype["set"+s]=B.prototype["set"+i]=B.prototype["set"+n]=function(o){const a=sh(r);return new yp(this,a,D(o))},B.prototype["flip"+s]=B.prototype["flip"+i]=B.prototype["flip"+n]=function(){const o=sh(r);return new xp(this,o)}}const Se=["x","y","z","w"],Me=["r","g","b","a"],Ne=["s","t","p","q"];for(let r=0;r<4;r++){let t=Se[r],e=Me[r],s=Ne[r];xn(t,e,s);for(let i=0;i<4;i++){t=Se[r]+Se[i],e=Me[r]+Me[i],s=Ne[r]+Ne[i],xn(t,e,s);for(let n=0;n<4;n++){t=Se[r]+Se[i]+Se[n],e=Me[r]+Me[i]+Me[n],s=Ne[r]+Ne[i]+Ne[n],xn(t,e,s);for(let o=0;o<4;o++)t=Se[r]+Se[i]+Se[n]+Se[o],e=Me[r]+Me[i]+Me[n]+Me[o],s=Ne[r]+Ne[i]+Ne[n]+Ne[o],xn(t,e,s)}}}for(let r=0;r<32;r++)Bi[r]={get(){this._cache=this._cache||{};let t=this._cache[r];return t===void 0&&(t=new ui(this,new Le(r,"uint")),this._cache[r]=t),t},set(t){this[r].assign(D(t))}};Object.defineProperties(B.prototype,Bi);const ih=new WeakMap,Cp=function(r,t=null){const e=nr(r);return e==="node"?r:t===null&&(e==="float"||e==="boolean")||e&&e!=="shader"&&e!=="string"?D(No(r,t)):e==="shader"?r.isFn?r:z(r):r},bp=function(r,t=null){for(const e in r)r[e]=D(r[e],t);return r},wp=function(r,t=null){const e=r.length;for(let s=0;s<e;s++)r[s]=D(r[s],t);return r},Ol=function(r,t=null,e=null,s=null){function i(c){return s!==null?(c=D(Object.assign(c,s)),s.intent===!0&&(c=c.toVarIntent())):c=D(c),c}let n,o=t,a,h;function l(c){let u;return o?u=/[a-z]/i.test(o)?o+"()":o:u=r.type,a!==void 0&&c.length<a?(rt(`TSL: "${u}" parameter length is less than minimum required.`,new oe),c.concat(new Array(a-c.length).fill(0))):h!==void 0&&c.length>h?(rt(`TSL: "${u}" parameter length exceeds limit.`,new oe),c.slice(0,h)):c}return t===null?n=(...c)=>i(new r(...Js(l(c)))):e!==null?(e=D(e),n=(...c)=>i(new r(t,...Js(l(c)),e))):n=(...c)=>i(new r(t,...Js(l(c)))),n.setParameterLength=(...c)=>(c.length===1?a=h=c[0]:c.length===2&&([a,h]=c),n),n.setName=c=>(o=c,n),n},Sp=function(r,...t){return new r(...Js(t))};class Mp extends B{constructor(t,e){super(),this.shaderNode=t,this.rawInputs=e,this.isShaderCallNodeInternal=!0}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}getElementType(t){return this.getOutputNode(t).getElementType(t)}getMemberType(t,e){return this.getOutputNode(t).getMemberType(t,e)}call(t){const{shaderNode:e,rawInputs:s}=this,i=t.getNodeProperties(e),n=t.getClosestSubBuild(e.subBuilds)||"",o=n||"default";if(i[o])return i[o];const a=t.subBuildFn,h=t.fnCall;t.subBuildFn=n,t.fnCall=this;let l=null;if(e.layout){let c=ih.get(t.constructor);c===void 0&&(c=new WeakMap,ih.set(t.constructor,c));let u=c.get(e);u===void 0&&(u=D(t.buildFunctionNode(e)),c.set(e,u)),t.addInclude(u);const d=s?Np(s):null;l=D(u.call(d))}else{const c=new Proxy(t,{get:(f,y,g)=>{let x;return Symbol.iterator===y?x=function*(){yield void 0}:x=Reflect.get(f,y,g),x}}),u=s?Ap(s):null,d=Array.isArray(s)?s.length>0:s!==null,p=e.jsFunc,m=d||p.length>1?p(u,c):p(c);l=D(m)}return t.subBuildFn=a,t.fnCall=h,e.once&&(i[o]=l),l}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}getOutputNode(t){const e=t.getNodeProperties(this),s=t.getSubBuildOutput(this);return e[s]=e[s]||this.setupOutput(t),e[s].subBuild=t.getClosestSubBuild(this),e[s]}build(t,e=null){let s=null;const i=t.getBuildStage(),n=t.getNodeProperties(this),o=t.getSubBuildOutput(this),a=this.getOutputNode(t),h=t.fnCall;if(t.fnCall=this,i==="setup"){const l=t.getSubBuildProperty("initialized",this);if(n[l]!==!0&&(n[l]=!0,n[o]=this.getOutputNode(t),n[o].build(t),this.shaderNode.subBuilds))for(const c of t.chaining){const u=t.getDataFromNode(c,"any");u.subBuilds=u.subBuilds||new Set;for(const d of this.shaderNode.subBuilds)u.subBuilds.add(d)}s=n[o]}else i==="analyze"?a.build(t,e):i==="generate"&&(s=a.build(t,e)||"");return t.fnCall=h,s}}function Np(r){let t;return Go(r),r[0]&&(r[0].isNode||Object.getPrototypeOf(r[0])!==Object.prototype)?t=[...r]:t=r[0],t}function Ap(r){let t=0;return Go(r),new Proxy(r,{get:(e,s,i)=>{let n;if(s==="length")return n=r.length,n;if(Symbol.iterator===s)n=function*(){for(const o of r)yield D(o)};else{if(r.length>0)if(Object.getPrototypeOf(r[0])===Object.prototype){const o=r[0];o[s]===void 0?n=o[t++]:n=Reflect.get(o,s,i)}else r[0]instanceof B&&(r[s]===void 0?n=r[t++]:n=Reflect.get(r,s,i));else n=Reflect.get(e,s,i);n=D(n)}return n}})}class Ep extends B{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}getLayout(){return this.layout}call(t=null){return new Mp(this,t)}setup(){return this.call()}}const Op=[!1,!0],Rp=[0,1,2,3],Ip=[-1,-2],Rl=[.5,1.5,1/3,1e-6,1e6,Math.PI,Math.PI*2,1/Math.PI,2/Math.PI,1/(Math.PI*2),Math.PI/2],Ho=new Map;for(const r of Op)Ho.set(r,new Le(r));const jo=new Map;for(const r of Rp)jo.set(r,new Le(r,"uint"));const Wo=new Map([...jo].map(r=>new Le(r.value,"int")));for(const r of Ip)Wo.set(r,new Le(r,"int"));const mr=new Map([...Wo].map(r=>new Le(r.value)));for(const r of Rl)mr.set(r,new Le(r));for(const r of Rl)mr.set(-r,new Le(-r));const fr={bool:Ho,uint:jo,ints:Wo,float:mr},nh=new Map([...Ho,...mr]),No=(r,t)=>nh.has(r)?nh.get(r):r.isNode===!0?r:new Le(r,t),vt=function(r,t=null){return(...e)=>{for(const i of e)if(i===void 0)return rt(`TSL: Invalid parameter for the type "${r}".`,new oe),new Le(0,r);if((e.length===0||!["bool","float","int","uint"].includes(r)&&e.every(i=>{const n=typeof i;return n!=="object"&&n!=="function"}))&&(e=[Uo(r,...e)]),e.length===1&&t!==null&&t.has(e[0]))return _n(t.get(e[0]));if(e.length===1){const i=No(e[0],r);return i.nodeType===r?_n(i):_n(new El(i,r))}const s=e.map(i=>No(i));return _n(new mp(s,r))}},Pp=r=>r!=null?r.nodeType||r.convertTo||(typeof r=="string"?r:null):null;function Lp(r,t){return new Ep(r,t)}const D=(r,t=null)=>Cp(r,t),_n=(r,t=null)=>D(r,t).toVarIntent(),Go=(r,t=null)=>new bp(r,t),Js=(r,t=null)=>new wp(r,t),at=(r,t=null,e=null,s=null)=>new Ol(r,t,e,s),ft=(r,...t)=>new Sp(r,...t),L=(r,t=null,e=null,s={})=>new Ol(r,t,e,{...s,intent:!0});let Fp=0;class zp extends B{constructor(t,e=null){super();let s=null;e!==null&&(typeof e=="object"?s=e.return:(typeof e=="string"?s=e:rt("TSL: Invalid layout type.",new oe),e=null)),this.shaderNode=new Lp(t,s),e!==null&&this.setLayout(e),this.isFn=!0}setLayout(t){const e=this.shaderNode.nodeType;if(typeof t.inputs!="object"){const s={name:"fn"+Fp++,type:e,inputs:[]};for(const i in t)i!=="return"&&s.inputs.push({name:i,type:t[i]});t=s}return this.shaderNode.setLayout(t),this}getNodeType(t){return this.shaderNode.getNodeType(t)||"float"}call(...t){const e=this.shaderNode.call(t);return this.shaderNode.nodeType==="void"&&e.toStack(),e.toVarIntent()}once(t=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=t,this}generate(t){const e=this.getNodeType(t);return rt('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),t.generateConst(e)}}function z(r,t=null){const e=new zp(r,t);return new Proxy(()=>{},{apply(s,i,n){return e.call(...n)},get(s,i,n){return Reflect.get(e,i,n)},set(s,i,n,o){return Reflect.set(e,i,n,o)}})}const ss=(...r)=>Tp.If(...r);function Dp(r){return r}S("toStack",Dp);const Bp=new vt("color"),K=new vt("float",fr.float),wt=new vt("int",fr.ints),Pt=new vt("uint",fr.uint),Yo=new vt("bool",fr.bool),Ce=new vt("vec2"),Ie=new vt("ivec2"),Il=new vt("uvec2"),kp=new vt("bvec2"),H=new vt("vec3"),Pl=new vt("ivec3"),Ll=new vt("uvec3"),Up=new vt("bvec3"),Nt=new vt("vec4"),Fl=new vt("ivec4"),zl=new vt("uvec4"),Vp=new vt("bvec4"),Dl=new vt("mat2"),ls=new vt("mat3"),gr=new vt("mat4");S("toColor",Bp);S("toFloat",K);S("toInt",wt);S("toUint",Pt);S("toBool",Yo);S("toVec2",Ce);S("toIVec2",Ie);S("toUVec2",Il);S("toBVec2",kp);S("toVec3",H);S("toIVec3",Pl);S("toUVec3",Ll);S("toBVec3",Up);S("toVec4",Nt);S("toIVec4",Fl);S("toUVec4",zl);S("toBVec4",Vp);S("toMat2",Dl);S("toMat3",ls);S("toMat4",gr);const Hp=at(ui).setParameterLength(2),jp=(r,t)=>new El(D(r),t);S("element",Hp);S("convert",jp);S("append",r=>(W("TSL: .append() has been renamed to .toStack().",new oe),r));class Ji extends B{static get type(){return"PropertyNode"}constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0,this.global=!0}customCacheKey(){return ko(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(t){return this.name||super.getHash(t)}generate(t){let e;return this.varying===!0?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const Wp=(r,t)=>new Ji(r,t),rr=(r,t)=>new Ji(r,t,!0),Bt=ft(Ji,"vec4","DiffuseColor"),rh=ft(Ji,"vec3","EmissiveColor"),ki=ft(Ji,"vec4","Output");class Bl extends B{static get type(){return"UniformGroupNode"}constructor(t,e=!1,s=1){super("string"),this.name=t,this.shared=e,this.order=s,this.isUniformGroup=!0}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const Gp=r=>new Bl(r),kl=(r,t=0)=>new Bl(r,!0,t),Xt=kl("render"),Yp=Gp("object");class Ki extends Vo{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=Yp}setName(t){return this.name=t,this}label(t){return W('TSL: "label()" has been deprecated. Use "setName()" instead.',new oe),this.setName(t)}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){return t=t.bind(this),super.onUpdate(s=>{const i=t(s,this);i!==void 0&&(this.value=i)},e)}getInputType(t){let e=super.getInputType(t);return e==="bool"&&(e="uint"),e}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let n=t.getNodeFromHash(i);n===void 0&&(t.setHashNode(this,i),n=this);const o=n.getInputType(t),a=t.getUniformFromNode(n,o,t.shaderStage,this.name||t.context.nodeName),h=t.getPropertyName(a);t.context.nodeName!==void 0&&delete t.context.nodeName;let l=h;if(s==="bool"){const c=t.getDataFromNode(this);let u=c.propertyName;if(u===void 0){const d=t.getVarFromNode(this,null,"bool");u=t.getPropertyName(d),c.propertyName=u,l=t.format(h,o,s),t.addLineFlowCode(`${u} = ${l}`,this)}l=u}return t.format(l,s,e)}}const Tt=(r,t)=>{const e=Pp(t||r);if(e===r&&(r=Uo(e)),r&&r.isNode===!0){let s=r.value;r.traverse(i=>{i.isConstNode===!0&&(s=i.value)}),r=s}return new Ki(r,e)};class oh extends It{static get type(){return"ArrayNode"}constructor(t,e,s=null){super(t),this.count=e,this.values=s,this.isArrayNode=!0}getArrayCount(){return this.count}getNodeType(t){return this.nodeType===null?this.values[0].getNodeType(t):this.nodeType}getElementType(t){return this.getNodeType(t)}getMemberType(t,e){return this.nodeType===null?this.values[0].getMemberType(t,e):super.getMemberType(t,e)}generate(t){const e=this.getNodeType(t);return t.generateArray(e,this.count,this.values)}}const $p=(...r)=>{let t;if(r.length===1){const e=r[0];t=new oh(null,e.length,e)}else{const e=r[0],s=r[1];t=new oh(e,s)}return D(t)};S("toArray",(r,t)=>$p(Array(t).fill(r)));class Xp extends It{static get type(){return"AssignNode"}constructor(t,e){super(),this.targetNode=t,this.sourceNode=e,this.isAssignNode=!0}hasDependencies(){return!1}getNodeType(t,e){return e!=="void"?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(t.isAvailable("swizzleAssign")===!1&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return Qi.join("").slice(0,s)!==e.components}return!1}setup(t){const{targetNode:e,sourceNode:s}=this,i=e.getScope(),n=t.getDataFromNode(i);n.assign=!0;const o=t.getNodeProperties(this);o.sourceNode=s,o.targetNode=e.context({assign:!0})}generate(t,e){const{targetNode:s,sourceNode:i}=t.getNodeProperties(this),n=this.needsSplitAssign(t),o=s.build(t),a=s.getNodeType(t),h=i.build(t,a),l=i.getNodeType(t),c=t.getDataFromNode(this);let u;if(c.initialized===!0)e!=="void"&&(u=o);else if(n){const d=t.getVarFromNode(this,null,a),p=t.getPropertyName(d);t.addLineFlowCode(`${p} = ${h}`,this);const m=s.node,y=m.node.context({assign:!0}).build(t);for(let g=0;g<m.components.length;g++){const x=m.components[g];t.addLineFlowCode(`${y}.${x} = ${p}[ ${g} ]`,this)}e!=="void"&&(u=o)}else u=`${o} = ${h}`,(e==="void"||l==="void")&&(t.addLineFlowCode(u,this),e!=="void"&&(u=o));return c.initialized=!0,t.format(u,a,e)}}const Zp=at(Xp).setParameterLength(2);S("assign",Zp);class qp extends It{static get type(){return"FunctionCallNode"}constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}getMemberType(t,e){return this.functionNode.getMemberType(t,e)}generate(t){const e=[],s=this.functionNode,i=s.getInputs(t),n=this.parameters,o=(h,l)=>{const c=l.type,u=c==="pointer";let d;return u?d="&"+h.build(t):d=h.build(t,c),d};if(Array.isArray(n)){if(n.length>i.length)rt("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),n.length=i.length;else if(n.length<i.length)for(rt("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");n.length<i.length;)n.push(K(0));for(let h=0;h<n.length;h++)e.push(o(n[h],i[h]))}else for(const h of i){const l=n[h.name];l!==void 0?e.push(o(l,h)):(rt(`TSL: Input '${h.name}' not found in 'Fn()'.`),e.push(o(K(0),h)))}return`${s.build(t,"property")}( ${e.join(", ")} )`}}const Qp=(r,...t)=>(t=t.length>1||t[0]&&t[0].isNode===!0?Js(t):Go(t[0]),new qp(D(r),t));S("call",Qp);const Jp={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class pt extends It{static get type(){return"OperatorNode"}constructor(t,e,s,...i){if(super(),i.length>0){let n=new pt(t,e,s);for(let o=0;o<i.length-1;o++)n=new pt(t,n,i[o]);e=n,s=i[i.length-1]}this.op=t,this.aNode=e,this.bNode=s,this.isOperatorNode=!0}getOperatorMethod(t,e){return t.getMethod(Jp[this.op],e)}getNodeType(t,e=null){const s=this.op,i=this.aNode,n=this.bNode,o=i.getNodeType(t),a=n?n.getNodeType(t):null;if(o==="void"||a==="void")return e||"void";if(s==="%")return o;if(s==="~"||s==="&"||s==="|"||s==="^"||s===">>"||s==="<<")return t.getIntegerType(o);if(s==="!"||s==="&&"||s==="||"||s==="^^")return"bool";if(s==="=="||s==="!="||s==="<"||s===">"||s==="<="||s===">="){const h=Math.max(t.getTypeLength(o),t.getTypeLength(a));return h>1?`bvec${h}`:"bool"}else{if(t.isMatrix(o)){if(a==="float")return o;if(t.isVector(a))return t.getVectorFromMatrix(o);if(t.isMatrix(a))return o}else if(t.isMatrix(a)){if(o==="float")return a;if(t.isVector(o))return t.getVectorFromMatrix(a)}return t.getTypeLength(a)>t.getTypeLength(o)?a:o}}generate(t,e){const s=this.op,{aNode:i,bNode:n}=this,o=this.getNodeType(t,e);let a=null,h=null;o!=="void"?(a=i.getNodeType(t),h=n?n.getNodeType(t):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="||s==="!="?t.isVector(a)?h=a:t.isVector(h)?a=h:a!==h&&(a=h="float"):s===">>"||s==="<<"?(a=o,h=t.changeComponentType(h,"uint")):s==="%"?(a=o,h=t.isInteger(a)&&t.isInteger(h)?h:a):t.isMatrix(a)?h==="float"?h="float":t.isVector(h)?h=t.getVectorFromMatrix(a):t.isMatrix(h)||(a=h=o):t.isMatrix(h)?a==="float"?a="float":t.isVector(a)?a=t.getVectorFromMatrix(h):a=h=o:a=h=o):a=h=o;const l=i.build(t,a),c=n?n.build(t,h):null,u=t.getFunctionOperator(s);if(e!=="void"){const d=t.renderer.coordinateSystem===je;if(s==="=="||s==="!="||s==="<"||s===">"||s==="<="||s===">=")return d?t.isVector(a)?t.format(`${this.getOperatorMethod(t,e)}( ${l}, ${c} )`,o,e):t.format(`( ${l} ${s} ${c} )`,o,e):t.format(`( ${l} ${s} ${c} )`,o,e);if(s==="%")return t.isInteger(h)?t.format(`( ${l} % ${c} )`,o,e):t.format(`${this.getOperatorMethod(t,o)}( ${l}, ${c} )`,o,e);if(s==="!"||s==="~")return t.format(`(${s}${l})`,a,e);if(u)return t.format(`${u}( ${l}, ${c} )`,o,e);if(t.isMatrix(a)&&h==="float")return t.format(`( ${c} ${s} ${l} )`,o,e);if(a==="float"&&t.isMatrix(h))return t.format(`${l} ${s} ${c}`,o,e);{let p=`( ${l} ${s} ${c} )`;return!d&&o==="bool"&&t.isVector(a)&&t.isVector(h)&&(p=`all${p}`),t.format(p,o,e)}}else if(a!=="void")return u?t.format(`${u}( ${l}, ${c} )`,o,e):t.isMatrix(a)&&h==="float"?t.format(`${c} ${s} ${l}`,o,e):t.format(`${l} ${s} ${c}`,o,e)}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const $i=L(pt,"+").setParameterLength(2,1/0).setName("add"),Ve=L(pt,"-").setParameterLength(2,1/0).setName("sub"),Ht=L(pt,"*").setParameterLength(2,1/0).setName("mul"),Ul=L(pt,"/").setParameterLength(2,1/0).setName("div"),$o=L(pt,"%").setParameterLength(2).setName("mod"),Kp=L(pt,"==").setParameterLength(2).setName("equal"),tm=L(pt,"!=").setParameterLength(2).setName("notEqual"),em=L(pt,"<").setParameterLength(2).setName("lessThan"),sm=L(pt,">").setParameterLength(2).setName("greaterThan"),im=L(pt,"<=").setParameterLength(2).setName("lessThanEqual"),nm=L(pt,">=").setParameterLength(2).setName("greaterThanEqual"),rm=L(pt,"&&").setParameterLength(2,1/0).setName("and"),om=L(pt,"||").setParameterLength(2,1/0).setName("or"),am=L(pt,"!").setParameterLength(1).setName("not"),hm=L(pt,"^^").setParameterLength(2).setName("xor"),lm=L(pt,"&").setParameterLength(2).setName("bitAnd"),cm=L(pt,"~").setParameterLength(1).setName("bitNot"),um=L(pt,"|").setParameterLength(2).setName("bitOr"),dm=L(pt,"^").setParameterLength(2).setName("bitXor"),pm=L(pt,"<<").setParameterLength(2).setName("shiftLeft"),mm=L(pt,">>").setParameterLength(2).setName("shiftRight"),fm=z(([r])=>(r.addAssign(1),r)),gm=z(([r])=>(r.subAssign(1),r)),ym=z(([r])=>{const t=wt(r).toConst();return r.addAssign(1),t}),xm=z(([r])=>{const t=wt(r).toConst();return r.subAssign(1),t});S("add",$i);S("sub",Ve);S("mul",Ht);S("div",Ul);S("mod",$o);S("equal",Kp);S("notEqual",tm);S("lessThan",em);S("greaterThan",sm);S("lessThanEqual",im);S("greaterThanEqual",nm);S("and",rm);S("or",om);S("not",am);S("xor",hm);S("bitAnd",lm);S("bitNot",cm);S("bitOr",um);S("bitXor",dm);S("shiftLeft",pm);S("shiftRight",mm);S("incrementBefore",fm);S("decrementBefore",gm);S("increment",ym);S("decrement",xm);const _m=(r,t)=>(W('TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.',new oe),$o(wt(r),wt(t)));S("modInt",_m);class T extends It{static get type(){return"MathNode"}constructor(t,e,s=null,i=null){if(super(),(t===T.MAX||t===T.MIN)&&arguments.length>3){let n=new T(t,e,s);for(let o=2;o<arguments.length-1;o++)n=new T(t,n,arguments[o]);e=n,s=arguments[arguments.length-1],i=null}this.method=t,this.aNode=e,this.bNode=s,this.cNode=i,this.isMathNode=!0}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,n=t.isMatrix(e)?0:t.getTypeLength(e),o=t.isMatrix(s)?0:t.getTypeLength(s),a=t.isMatrix(i)?0:t.getTypeLength(i);return n>o&&n>a?e:o>a?s:a>n?i:e}getNodeType(t){const e=this.method;return e===T.LENGTH||e===T.DISTANCE||e===T.DOT?"float":e===T.CROSS?"vec3":e===T.ALL||e===T.ANY?"bool":e===T.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):this.getInputType(t)}setup(t){const{aNode:e,bNode:s,method:i}=this;let n=null;if(i===T.ONE_MINUS)n=Ve(1,e);else if(i===T.RECIPROCAL)n=Ul(1,e);else if(i===T.DIFFERENCE)n=yr(Ve(e,s));else if(i===T.TRANSFORM_DIRECTION){let o=e,a=s;t.isMatrix(o.getNodeType(t))?a=Nt(H(a),0):o=Nt(H(o),0);const h=Ht(o,a).xyz;n=Hl(h)}return n!==null?n:super.setup(t)}generate(t,e){if(t.getNodeProperties(this).outputNode)return super.generate(t,e);let i=this.method;const n=this.getNodeType(t),o=this.getInputType(t),a=this.aNode,h=this.bNode,l=this.cNode,c=t.renderer.coordinateSystem;if(i===T.NEGATE)return t.format("( - "+a.build(t,o)+" )",n,e);{const u=[];return i===T.CROSS?u.push(a.build(t,n),h.build(t,n)):c===je&&i===T.STEP?u.push(a.build(t,t.getTypeLength(a.getNodeType(t))===1?"float":o),h.build(t,o)):c===je&&(i===T.MIN||i===T.MAX)?u.push(a.build(t,o),h.build(t,t.getTypeLength(h.getNodeType(t))===1?"float":o)):i===T.REFRACT?u.push(a.build(t,o),h.build(t,o),l.build(t,"float")):i===T.MIX?u.push(a.build(t,o),h.build(t,o),l.build(t,t.getTypeLength(l.getNodeType(t))===1?"float":o)):(c===ni&&i===T.ATAN&&h!==null&&(i="atan2"),t.shaderStage!=="fragment"&&(i===T.DFDX||i===T.DFDY)&&(W(`TSL: '${i}' is not supported in the ${t.shaderStage} stage.`,this.stackTrace),i="/*"+i+"*/"),u.push(a.build(t,o)),h!==null&&u.push(h.build(t,o)),l!==null&&u.push(l.build(t,o))),t.format(`${t.getMethod(i,n)}( ${u.join(", ")} )`,n,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}T.ALL="all";T.ANY="any";T.RADIANS="radians";T.DEGREES="degrees";T.EXP="exp";T.EXP2="exp2";T.LOG="log";T.LOG2="log2";T.SQRT="sqrt";T.INVERSE_SQRT="inversesqrt";T.FLOOR="floor";T.CEIL="ceil";T.NORMALIZE="normalize";T.FRACT="fract";T.SIN="sin";T.COS="cos";T.TAN="tan";T.ASIN="asin";T.ACOS="acos";T.ATAN="atan";T.ABS="abs";T.SIGN="sign";T.LENGTH="length";T.NEGATE="negate";T.ONE_MINUS="oneMinus";T.DFDX="dFdx";T.DFDY="dFdy";T.ROUND="round";T.RECIPROCAL="reciprocal";T.TRUNC="trunc";T.FWIDTH="fwidth";T.TRANSPOSE="transpose";T.DETERMINANT="determinant";T.INVERSE="inverse";T.EQUALS="equals";T.MIN="min";T.MAX="max";T.STEP="step";T.REFLECT="reflect";T.DISTANCE="distance";T.DIFFERENCE="difference";T.DOT="dot";T.CROSS="cross";T.POW="pow";T.TRANSFORM_DIRECTION="transformDirection";T.MIX="mix";T.CLAMP="clamp";T.REFRACT="refract";T.SMOOTHSTEP="smoothstep";T.FACEFORWARD="faceforward";const Tm=K(Math.PI),vm=L(T,T.ALL).setParameterLength(1),Cm=L(T,T.ANY).setParameterLength(1),bm=L(T,T.RADIANS).setParameterLength(1),wm=L(T,T.DEGREES).setParameterLength(1),Sm=L(T,T.EXP).setParameterLength(1),Ao=L(T,T.EXP2).setParameterLength(1),Mm=L(T,T.LOG).setParameterLength(1),Ks=L(T,T.LOG2).setParameterLength(1),Xo=L(T,T.SQRT).setParameterLength(1),Nm=L(T,T.INVERSE_SQRT).setParameterLength(1),$n=L(T,T.FLOOR).setParameterLength(1),Vl=L(T,T.CEIL).setParameterLength(1),Hl=L(T,T.NORMALIZE).setParameterLength(1),ri=L(T,T.FRACT).setParameterLength(1),Xi=L(T,T.SIN).setParameterLength(1),jl=L(T,T.COS).setParameterLength(1),Am=L(T,T.TAN).setParameterLength(1),Em=L(T,T.ASIN).setParameterLength(1),Om=L(T,T.ACOS).setParameterLength(1),Rm=L(T,T.ATAN).setParameterLength(1,2),yr=L(T,T.ABS).setParameterLength(1),Wl=L(T,T.SIGN).setParameterLength(1),Eo=L(T,T.LENGTH).setParameterLength(1),Gl=L(T,T.NEGATE).setParameterLength(1),Im=L(T,T.ONE_MINUS).setParameterLength(1),Yl=L(T,T.DFDX).setParameterLength(1),$l=L(T,T.DFDY).setParameterLength(1),Pm=L(T,T.ROUND).setParameterLength(1),Lm=L(T,T.RECIPROCAL).setParameterLength(1),Fm=L(T,T.TRUNC).setParameterLength(1),Xl=L(T,T.FWIDTH).setParameterLength(1),zm=L(T,T.TRANSPOSE).setParameterLength(1),Dm=L(T,T.DETERMINANT).setParameterLength(1),Bm=L(T,T.INVERSE).setParameterLength(1),Zl=L(T,T.MIN).setParameterLength(2,1/0),ql=L(T,T.MAX).setParameterLength(2,1/0),Ql=L(T,T.STEP).setParameterLength(2),km=L(T,T.REFLECT).setParameterLength(2),Um=L(T,T.DISTANCE).setParameterLength(2),Vm=L(T,T.DIFFERENCE).setParameterLength(2),tn=L(T,T.DOT).setParameterLength(2),Hm=L(T,T.CROSS).setParameterLength(2),Jl=L(T,T.POW).setParameterLength(2),jm=r=>Ht(r,r),Wm=r=>Ht(r,r,r),Gm=r=>Ht(r,r,r,r),Ym=L(T,T.TRANSFORM_DIRECTION).setParameterLength(2),$m=r=>Ht(Wl(r),Jl(yr(r),1/3)),Kl=r=>tn(r,r),oi=L(T,T.MIX).setParameterLength(3),Zo=(r,t=0,e=1)=>new T(T.CLAMP,D(r),D(t),D(e)),tc=r=>Zo(r),Xm=L(T,T.REFRACT).setParameterLength(3),ai=L(T,T.SMOOTHSTEP).setParameterLength(3),Zm=L(T,T.FACEFORWARD).setParameterLength(3),qm=z(([r])=>{const s=43758.5453,i=tn(r.xy,Ce(12.9898,78.233)),n=$o(i,Tm);return ri(Xi(n).mul(s))}),Qm=(r,t,e)=>oi(t,e,r),Jm=(r,t,e)=>ai(t,e,r),Km=(r,t)=>Ql(t,r);S("all",vm);S("any",Cm);S("radians",bm);S("degrees",wm);S("exp",Sm);S("exp2",Ao);S("log",Mm);S("log2",Ks);S("sqrt",Xo);S("inverseSqrt",Nm);S("floor",$n);S("ceil",Vl);S("normalize",Hl);S("fract",ri);S("sin",Xi);S("cos",jl);S("tan",Am);S("asin",Em);S("acos",Om);S("atan",Rm);S("abs",yr);S("sign",Wl);S("length",Eo);S("lengthSq",Kl);S("negate",Gl);S("oneMinus",Im);S("dFdx",Yl);S("dFdy",$l);S("round",Pm);S("reciprocal",Lm);S("trunc",Fm);S("fwidth",Xl);S("min",Zl);S("max",ql);S("step",Km);S("reflect",km);S("distance",Um);S("dot",tn);S("cross",Hm);S("pow",Jl);S("pow2",jm);S("pow3",Wm);S("pow4",Gm);S("transformDirection",Ym);S("mix",Qm);S("clamp",Zo);S("refract",Xm);S("smoothstep",Jm);S("faceForward",Zm);S("difference",Vm);S("saturate",tc);S("cbrt",$m);S("transpose",zm);S("determinant",Dm);S("inverse",Bm);S("rand",qm);class tf extends B{static get type(){return"ConditionalNode"}constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const{ifNode:e,elseNode:s}=t.getNodeProperties(this);if(e===void 0)return t.flowBuildStage(this,"setup"),this.getNodeType(t);const i=e.getNodeType(t);if(s!==null){const n=s.getNodeType(t);if(t.getTypeLength(n)>t.getTypeLength(i))return n}return i}setup(t){const e=this.condNode,s=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,n=t.context.nodeBlock;t.getDataFromNode(s).parentNodeBlock=n,i!==null&&(t.getDataFromNode(i).parentNodeBlock=n);const o=t.context.uniformFlow,a=t.getNodeProperties(this);a.condNode=e,a.ifNode=o?s:s.context({nodeBlock:s}),a.elseNode=i?o?i:i.context({nodeBlock:i}):null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;const{condNode:n,ifNode:o,elseNode:a}=t.getNodeProperties(this),h=t.currentFunctionNode,l=e!=="void",c=l?Wp(s).build(t):"";i.nodeProperty=c;const u=n.build(t,"bool");if(t.context.uniformFlow&&a!==null){const m=o.build(t,s),f=a.build(t,s),y=t.getTernary(u,m,f);return t.format(y,s,e)}t.addFlowCode(`
88
+ ${t.tab}if ( ${u} ) {
89
+
90
+ `).addFlowTab();let p=o.build(t,s);if(p&&(l?p=c+" = "+p+";":(p="return "+p+";",h===null&&(W("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),p="// "+p))),t.removeFlowTab().addFlowCode(t.tab+" "+p+`
91
+
92
+ `+t.tab+"}"),a!==null){t.addFlowCode(` else {
93
+
94
+ `).addFlowTab();let m=a.build(t,s);m&&(l?m=c+" = "+m+";":(m="return "+m+";",h===null&&(W("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),m="// "+m))),t.removeFlowTab().addFlowCode(t.tab+" "+m+`
95
+
96
+ `+t.tab+`}
97
+
98
+ `)}else t.addFlowCode(`
99
+
100
+ `);return t.format(c,s,e)}}const qo=at(tf).setParameterLength(2,3);S("select",qo);class ec extends B{static get type(){return"ContextNode"}constructor(t=null,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}getFlowContextData(){const t=[];return this.traverse(e=>{e.isContextNode===!0&&t.push(e.value)}),Object.assign({},...t)}getMemberType(t,e){return this.node.getMemberType(t,e)}analyze(t){const e=t.addContext(this.value);this.node.build(t),t.setContext(e)}setup(t){const e=t.addContext(this.value);this.node.build(t),t.setContext(e)}generate(t,e){const s=t.addContext(this.value),i=this.node.build(t,e);return t.setContext(s),i}}const di=(r=null,t={})=>{let e=r;return(e===null||e.isNode!==!0)&&(t=e||t,e=null),new ec(e,t)},ef=r=>di(r,{uniformFlow:!0}),sc=(r,t)=>di(r,{nodeName:t});function sf(r,t,e=null){return di(e,{getShadow:({light:s,shadowColorNode:i})=>t===s?i.mul(r):i})}function nf(r,t=null){return di(t,{getAO:(e,{material:s})=>s.transparent===!0?e:e!==null?e.mul(r):r})}function rf(r,t){return W('TSL: "label()" has been deprecated. Use "setName()" instead.'),sc(r,t)}S("context",di);S("label",rf);S("uniformFlow",ef);S("setName",sc);S("builtinShadowContext",(r,t,e)=>sf(t,e,r));S("builtinAOContext",(r,t)=>nf(t,r));class of extends B{static get type(){return"VarNode"}constructor(t,e=null,s=!1){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0,this.readOnly=s,this.parents=!0,this.intent=!1}setIntent(t){return this.intent=t,this}isIntent(t){return t.getDataFromNode(this).forceDeclaration===!0?!1:this.intent}getIntent(){return this.intent}getMemberType(t,e){return this.node.getMemberType(t,e)}getElementType(t){return this.node.getElementType(t)}getNodeType(t){return this.node.getNodeType(t)}getArrayCount(t){return this.node.getArrayCount(t)}isAssign(t){return t.getDataFromNode(this).assign}build(...t){const e=t[0];if(this._hasStack(e)===!1&&e.buildStage==="setup"&&(e.context.nodeLoop||e.context.nodeBlock)){let s=!1;if(this.node.isShaderCallNodeInternal&&this.node.shaderNode.getLayout()===null&&e.fnCall&&e.fnCall.shaderNode&&e.getDataFromNode(this.node.shaderNode).hasLoop){const o=e.getDataFromNode(this);o.forceDeclaration=!0,s=!0}const i=e.getBaseStack();s?i.addToStackBefore(this):i.addToStack(this)}return this.isIntent(e)&&this.isAssign(e)!==!0?this.node.build(...t):super.build(...t)}generate(t){const{node:e,name:s,readOnly:i}=this,{renderer:n}=t,o=n.backend.isWebGPUBackend===!0;let a=!1,h=!1;i&&(a=t.isDeterministic(e),h=o?i:a);const l=this.getNodeType(t);if(l=="void")return this.isIntent(t)!==!0&&rt('TSL: ".toVar()" can not be used with void type.',this.stackTrace),e.build(t);const c=t.getVectorType(l),u=e.build(t,c),d=t.getVarFromNode(this,s,c,void 0,h),p=t.getPropertyName(d);let m=p;if(h)if(o)m=a?`const ${p}`:`let ${p}`;else{const f=e.getArrayCount(t);m=`const ${t.getVar(d.type,p,f)}`}return t.addLineFlowCode(`${m} = ${u}`,this),p}_hasStack(t){return t.getDataFromNode(this).stack!==void 0}}const Qo=at(of),af=(r,t=null)=>Qo(r,t).toStack(),hf=(r,t=null)=>Qo(r,t,!0).toStack(),lf=r=>Qo(r).setIntent(!0).toStack();S("toVar",af);S("toConst",hf);S("toVarIntent",lf);class cf extends B{static get type(){return"SubBuild"}constructor(t,e,s=null){super(s),this.node=t,this.name=e,this.isSubBuildNode=!0}getNodeType(t){if(this.nodeType!==null)return this.nodeType;t.addSubBuild(this.name);const e=this.node.getNodeType(t);return t.removeSubBuild(),e}build(t,...e){t.addSubBuild(this.name);const s=this.node.build(t,...e);return t.removeSubBuild(),s}}const Ui=(r,t,e=null)=>new cf(D(r),t,e);class uf extends B{static get type(){return"VaryingNode"}constructor(t,e=null){super(),this.node=Ui(t,"VERTEX"),this.name=e,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(t,e=null){return this.interpolationType=t,this.interpolationSampling=e,this}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(s===void 0){const i=this.name,n=this.getNodeType(t),o=this.interpolationType,a=this.interpolationSampling;e.varying=s=t.getVaryingFromNode(this,i,n,o,a),e.node=Ui(this.node,"VERTEX")}return s.needsInterpolation||(s.needsInterpolation=t.shaderStage==="fragment"),s}setup(t){this.setupVarying(t),t.flowNodeFromShaderStage(yn.VERTEX,this.node)}analyze(t){this.setupVarying(t),t.flowNodeFromShaderStage(yn.VERTEX,this.node)}generate(t){const e=t.getSubBuildProperty("property",t.currentStack),s=t.getNodeProperties(this),i=this.setupVarying(t);if(s[e]===void 0){const n=this.getNodeType(t),o=t.getPropertyName(i,yn.VERTEX);t.flowNodeFromShaderStage(yn.VERTEX,s.node,n,o),s[e]=o}return t.getPropertyName(i)}}const pi=at(uf).setParameterLength(1,2),df=r=>pi(r);S("toVarying",pi);S("toVertexStage",df);const pf=z(([r])=>{const t=r.mul(.9478672986).add(.0521327014).pow(2.4),e=r.mul(.0773993808),s=r.lessThanEqual(.04045);return oi(t,e,s)}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),mf=z(([r])=>{const t=r.pow(.41666).mul(1.055).sub(.055),e=r.mul(12.92),s=r.lessThanEqual(.0031308);return oi(t,e,s)}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Jo="WorkingColorSpace",ff="OutputColorSpace";class ic extends It{static get type(){return"ColorSpaceNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this.source=e,this.target=s}resolveColorSpace(t,e){return e===Jo?bt.workingColorSpace:e===ff?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{colorNode:e}=this,s=this.resolveColorSpace(t,this.source),i=this.resolveColorSpace(t,this.target);let n=e;return bt.enabled===!1||s===i||!s||!i||(bt.getTransfer(s)===Fi&&(n=Nt(pf(n.rgb),n.a)),bt.getPrimaries(s)!==bt.getPrimaries(i)&&(n=Nt(ls(bt._getMatrix(new he,s,i)).mul(n.rgb),n.a)),bt.getTransfer(i)===Fi&&(n=Nt(mf(n.rgb),n.a))),n}}const gf=(r,t)=>new ic(D(r),Jo,t),nc=(r,t)=>new ic(D(r),t,Jo);S("workingToColorSpace",gf);S("colorSpaceToWorking",nc);let yf=class extends ui{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}};class xf extends B{static get type(){return"ReferenceBaseNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=nt.OBJECT}setGroup(t){return this.group=t,this}element(t){return new yf(this,D(t))}setNodeType(t){const e=Tt(null,t);this.group!==null&&e.setGroup(this.group),this.node=e}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let i=1;i<e.length;i++)s=s[e[i]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}class _f extends xf{static get type(){return"RendererReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.renderer=s,this.setGroup(Xt)}updateReference(t){return this.reference=this.renderer!==null?this.renderer:t.renderer,this.reference}}const Tf=(r,t,e=null)=>new _f(r,t,e);class vf extends It{static get type(){return"ToneMappingNode"}constructor(t,e=bf,s=null){super("vec3"),this._toneMapping=t,this.exposureNode=e,this.colorNode=s}customCacheKey(){return Al(this._toneMapping)}setToneMapping(t){return this._toneMapping=t,this}getToneMapping(){return this._toneMapping}setup(t){const e=this.colorNode||t.context.color,s=this._toneMapping;if(s===vo)return e;let i=null;const n=t.renderer.library.getToneMappingFunction(s);return n!==null?i=Nt(n(e.rgb,this.exposureNode),e.a):(rt("ToneMappingNode: Unsupported Tone Mapping configuration.",s),i=e),i}}const Cf=(r,t,e)=>new vf(r,D(t),D(e)),bf=Tf("toneMappingExposure","float");S("toneMapping",(r,t,e)=>Cf(t,e,r));const yt=new M,Tn=new _t;let wf=0;class os{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:wf++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=s,this.usage=ii,this.updateRanges=[],this.gpuType=Tl,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,n=this.itemSize;i<n;i++)this.array[t+i]=e.array[s+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,s=this.count;e<s;e++)Tn.fromBufferAttribute(this,e),Tn.applyMatrix3(t),this.setXY(e,Tn.x,Tn.y);else if(this.itemSize===3)for(let e=0,s=this.count;e<s;e++)yt.fromBufferAttribute(this,e),yt.applyMatrix3(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)yt.fromBufferAttribute(this,e),yt.applyMatrix4(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)yt.fromBufferAttribute(this,e),yt.applyNormalMatrix(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)yt.fromBufferAttribute(this,e),yt.transformDirection(t),this.setXYZ(e,yt.x,yt.y,yt.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=Te(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=st(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Te(e,this.array)),e}setX(t,e){return this.normalized&&(e=st(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Te(e,this.array)),e}setY(t,e){return this.normalized&&(e=st(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=Te(e,this.array)),e}setZ(t,e){return this.normalized&&(e=st(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=Te(e,this.array)),e}setW(t,e){return this.normalized&&(e=st(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=st(e,this.array),s=st(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=st(e,this.array),s=st(s,this.array),i=st(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this}setXYZW(t,e,s,i,n){return t*=this.itemSize,this.normalized&&(e=st(e,this.array),s=st(s,this.array),i=st(i,this.array),n=st(n,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this.array[t+3]=n,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!==ii&&(t.usage=this.usage),t}}class Sf extends os{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class Mf extends os{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class Xn extends os{constructor(t,e,s){super(new Float32Array(t),e,s)}}const Vt=new M;class Ko{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++)Vt.fromBufferAttribute(this,e),Vt.applyMatrix4(t),this.setXYZ(e,Vt.x,Vt.y,Vt.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)Vt.fromBufferAttribute(this,e),Vt.applyNormalMatrix(t),this.setXYZ(e,Vt.x,Vt.y,Vt.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)Vt.fromBufferAttribute(this,e),Vt.transformDirection(t),this.setXYZ(e,Vt.x,Vt.y,Vt.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=Te(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=st(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=st(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=st(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=st(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=st(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=Te(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=Te(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=Te(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=Te(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=st(e,this.array),s=st(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=st(e,this.array),s=st(s,this.array),i=st(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,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=st(e,this.array),s=st(s,this.array),i=st(i,this.array),n=st(n,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]=n,this}clone(t){if(t===void 0){bo("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const i=s*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)e.push(this.data.array[i+n])}return new os(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Ko(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){bo("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let s=0;s<this.count;s++){const i=s*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)e.push(this.data.array[i+n])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(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 rc{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=ii,this.updateRanges=[],this.version=0,this.uuid=Ge()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let i=0,n=this.stride;i<n;i++)this.array[t+i]=e.array[s+i];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ge()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(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 t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Ge()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(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 ah=new WeakMap;function hh(r,t){let e=ah.get(r);return e===void 0&&(e=new rc(r,t),ah.set(r,e)),e}class Ze extends Vo{static get type(){return"BufferAttributeNode"}constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=ii,this.instanced=!1,this.attribute=null,this.global=!0,t&&t.isBufferAttribute===!0&&t.itemSize<=4&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(this.bufferStride===0&&this.bufferOffset===0){let e=t.globalCache.getData(this.value);return e===void 0&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return this.bufferType===null&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(this.attribute!==null)return;const e=this.getNodeType(t),s=t.getTypeLength(e),i=this.value,n=this.bufferStride||s,o=this.bufferOffset;let a;i.isInterleavedBuffer===!0?a=i:i.isBufferAttribute===!0?a=hh(i.array,n):a=hh(i,n);const h=new Ko(a,s,o);a.setUsage(this.usage),this.attribute=h,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let n=null;return t.shaderStage==="vertex"||t.shaderStage==="compute"?(this.name=i,n=i):n=pi(this).build(t,e),n}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&this.attribute.isBufferAttribute===!0&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}function ta(r,t=null,e=0,s=0,i=ii,n=!1){return t==="mat3"||t===null&&r.itemSize===9?ls(new Ze(r,"vec3",9,0).setUsage(i).setInstanced(n),new Ze(r,"vec3",9,3).setUsage(i).setInstanced(n),new Ze(r,"vec3",9,6).setUsage(i).setInstanced(n)):t==="mat4"||t===null&&r.itemSize===16?gr(new Ze(r,"vec4",16,0).setUsage(i).setInstanced(n),new Ze(r,"vec4",16,4).setUsage(i).setInstanced(n),new Ze(r,"vec4",16,8).setUsage(i).setInstanced(n),new Ze(r,"vec4",16,12).setUsage(i).setInstanced(n)):new Ze(r,t,e,s).setUsage(i)}const oc=(r,t=null,e=0,s=0)=>ta(r,t,e,s),lh=(r,t=null,e=0,s=0)=>ta(r,t,e,s,ii,!0),ch=(r,t=null,e=0,s=0)=>ta(r,t,e,s,Co,!0);S("toAttribute",r=>oc(r.value));class Nf extends B{static get type(){return"ComputeNode"}constructor(t,e){super("void"),this.isComputeNode=!0,this.computeNode=t,this.workgroupSize=e,this.count=null,this.version=1,this.name="",this.updateBeforeType=nt.OBJECT,this.onInitFunction=null}setCount(t){return this.count=t,this}getCount(){return this.count}dispose(){this.dispatchEvent({type:"dispose"})}setName(t){return this.name=t,this}label(t){return W('TSL: "label()" has been deprecated. Use "setName()" instead.',new oe),this.setName(t)}onInit(t){return this.onInitFunction=t,this}updateBefore({renderer:t}){t.compute(this)}setup(t){const e=this.computeNode.build(t);if(e){const s=t.getNodeProperties(this);s.outputComputeNode=e.outputNode,e.outputNode=null}return e}generate(t,e){const{shaderStage:s}=t;if(s==="compute"){const i=this.computeNode.build(t,"void");i!==""&&t.addLineFlowCode(i,this)}else{const n=t.getNodeProperties(this).outputComputeNode;if(n)return n.build(t,e)}}}const ac=(r,t=[64])=>{(t.length===0||t.length>3)&&rt("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new oe);for(let e=0;e<t.length;e++){const s=t[e];(typeof s!="number"||s<=0||!Number.isInteger(s))&&rt(`TSL: compute() workgroupSize element at index [ ${e} ] must be a positive integer`,new oe)}for(;t.length<3;)t.push(1);return new Nf(D(r),t)},Af=(r,t,e)=>ac(r,e).setCount(t);S("compute",Af);S("computeKernel",ac);class Ef extends B{static get type(){return"IsolateNode"}constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isIsolateNode=!0}getNodeType(t){const e=t.getCache(),s=t.getCacheFromNode(this,this.parent);t.setCache(s);const i=this.node.getNodeType(t);return t.setCache(e),i}build(t,...e){const s=t.getCache(),i=t.getCacheFromNode(this,this.parent);t.setCache(i);const n=this.node.build(t,...e);return t.setCache(s),n}setParent(t){return this.parent=t,this}getParent(){return this.parent}}const hc=r=>new Ef(D(r));function Of(r,t=!0){return W('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),hc(r).setParent(t)}S("cache",Of);S("isolate",hc);class Rf extends B{static get type(){return"BypassNode"}constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return e!==""&&t.addLineFlowCode(e,this),this.outputNode.build(t)}}const If=at(Rf).setParameterLength(2);S("bypass",If);class lc extends B{static get type(){return"RemapNode"}constructor(t,e,s,i=K(0),n=K(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=n,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:n,doClamp:o}=this;let a=t.sub(e).div(s.sub(e));return o===!0&&(a=a.clamp()),a.mul(n.sub(i)).add(i)}}const Pf=at(lc,null,null,{doClamp:!1}).setParameterLength(3,5),cc=at(lc).setParameterLength(3,5);S("remap",Pf);S("remapClamp",cc);class Lf extends B{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if(s==="void")t.addLineFlowCode(i,this);else return t.format(i,s,e)}}const Cs=at(Lf).setParameterLength(1,2),Ff=r=>(r?qo(r,Cs("discard")):Cs("discard")).toStack();S("discard",Ff);class zf extends It{static get type(){return"RenderOutputNode"}constructor(t,e,s){super("vec4"),this.colorNode=t,this._toneMapping=e,this.outputColorSpace=s,this.isRenderOutputNode=!0}setToneMapping(t){return this._toneMapping=t,this}getToneMapping(){return this._toneMapping}setup({context:t}){let e=this.colorNode||t.color;const s=(this._toneMapping!==null?this._toneMapping:t.toneMapping)||vo,i=(this.outputColorSpace!==null?this.outputColorSpace:t.outputColorSpace)||Kn;return s!==vo&&(e=e.toneMapping(s)),i!==Kn&&i!==bt.workingColorSpace&&(e=e.workingToColorSpace(i)),e}}const Df=(r,t=null,e=null)=>new zf(D(r),t,e);S("renderOutput",Df);class Bf extends It{static get type(){return"DebugNode"}constructor(t,e=null){super(),this.node=t,this.callback=e}getNodeType(t){return this.node.getNodeType(t)}setup(t){return this.node.build(t)}analyze(t){return this.node.build(t)}generate(t){const e=this.callback,s=this.node.build(t);if(e!==null)e(t,s);else{const i="--- TSL debug - "+t.shaderStage+" shader ---",n="-".repeat(i.length);let o="";o+="// #"+i+`#
101
+ `,o+=t.flow.code.replace(/^\t/mg,"")+`
102
+ `,o+="/* ... */ "+s+` /* ... */
103
+ `,o+="// #"+n+`#
104
+ `,bo(o)}return s}}const kf=(r,t=null)=>new Bf(D(r),t).toStack();S("debug",kf);class Uf{constructor(){this._renderer=null,this.currentFrame=null}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(t){return this._renderer=t,this}getRenderer(){return this._renderer}init(){}begin(){}finish(){}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}}class Vf extends B{static get type(){return"InspectorNode"}constructor(t,e="",s=null){super(),this.node=t,this.name=e,this.callback=s,this.updateType=nt.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(t){t.renderer.inspector.inspect(this)}getNodeType(t){return this.node.getNodeType(t)}setup(t){let e=this.node;return t.context.inspector===!0&&this.callback!==null&&(e=this.callback(e)),t.renderer.backend.isWebGPUBackend!==!0&&t.renderer.inspector.constructor!==Uf&&Yi('TSL: ".toInspector()" is only available with WebGPU.'),e}}function Hf(r,t="",e=null){return r=D(r),r.before(new Vf(r,t,e))}S("toInspector",Hf);class uc extends B{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(e===null){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(t.hasGeometryAttribute(e)===!0){const n=t.geometry.getAttribute(e),o=t.getTypeFromAttribute(n),a=t.getAttribute(e,o);return t.shaderStage==="vertex"?t.format(a.name,o,s):pi(this).build(t,s)}else return W(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(s)}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const hi=(r,t=null)=>new uc(r,t),en=(r=0)=>hi("uv"+(r>0?r:""),"vec2");class jf extends B{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=this.levelNode===null?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const Vi=at(jf).setParameterLength(1,2);class Wf extends Ki{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=nt.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&s.width!==void 0){const{width:i,height:n}=s;this.value=Math.log2(Math.max(i,n))}}}const Gf=at(Wf).setParameterLength(1);let Ls;class Yf{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let s;if(t instanceof HTMLCanvasElement)s=t;else{Ls===void 0&&(Ls=Da("canvas")),Ls.width=t.width,Ls.height=t.height;const i=Ls.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),s=Ls}return s.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=Da("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),n=i.data;for(let o=0;o<n.length;o++)n[o]=Ye(n[o]/255)*255;return s.putImageData(i,0,0),e}else if(t.data){const e=t.data.slice(0);for(let s=0;s<e.length;s++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[s]=Math.floor(Ye(e[s]/255)*255):e[s]=Ye(e[s]);return{data:e,width:t.width,height:t.height}}else return W("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let $f=0;class ea{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:$f++}),this.uuid=Ge(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(i!==null){let n;if(Array.isArray(i)){n=[];for(let o=0,a=i.length;o<a;o++)i[o].isDataTexture?n.push(kr(i[o].image)):n.push(kr(i[o]))}else n=kr(i);s.url=n}return e||(t.images[this.uuid]=s),s}}function kr(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?Yf.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(W("Texture: Unable to serialize Texture."),{})}let Xf=0;const Ur=new M;class te extends li{constructor(t=te.DEFAULT_IMAGE,e=te.DEFAULT_MAPPING,s=Oi,i=Oi,n=Jn,o=Fo,a=nd,h=ed,l=te.DEFAULT_ANISOTROPY,c=Kn){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Xf++}),this.uuid=Ge(),this.name="",this.source=new ea(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=n,this.minFilter=o,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=h,this.offset=new _t(0,0),this.repeat=new _t(1,1),this.center=new _t(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new he,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=c,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(Ur).x}get height(){return this.source.getSize(Ur).y}get depth(){return this.source.getSize(Ur).z}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)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}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.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const s=t[e];if(s===void 0){W(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const i=this[e];if(i===void 0){W(`Texture.setValues(): property '${e}' does not exist.`);continue}i&&s&&i.isVector2&&s.isVector2||i&&s&&i.isVector3&&s.isVector3||i&&s&&i.isMatrix3&&s.isMatrix3?i.copy(s):this[e]=s}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const s={metadata:{version:4.7,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!==fl)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Ra:t.x=t.x-Math.floor(t.x);break;case Oi:t.x=t.x<0?0:1;break;case Ia:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Ra:t.y=t.y-Math.floor(t.y);break;case Oi:t.y=t.y<0?0:1;break;case Ia:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}te.DEFAULT_IMAGE=null;te.DEFAULT_MAPPING=fl;te.DEFAULT_ANISOTROPY=1;class Zf extends Error{constructor(t,e=null){super(t),this.name="NodeError",this.stackTrace=e}}const dc=new te;class xr extends Ki{static get type(){return"TextureNode"}constructor(t=dc,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=nt.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this._flipYUniform=null,this.setUpdateMatrix(e===null)}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 this.value.isDepthTexture===!0?"float":this.value.type===_l?"uvec4":this.value.type===sd?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return en(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return this._matrixUniform===null&&(this._matrixUniform=Tt(this.value.matrix)),this._matrixUniform.mul(H(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this}setupUV(t,e){return t.isFlipY()&&(this._flipYUniform===null&&(this._flipYUniform=Tt(!1)),e=e.toVar(),this.sampler?e=this._flipYUniform.select(e.flipY(),e):e=this._flipYUniform.select(e.setY(wt(Vi(this,this.levelNode).y).sub(e.y).sub(1)),e)),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;const s=this.value;if(!s||s.isTexture!==!0)throw new Zf("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);const i=z(()=>{let h=this.uvNode;return(h===null||t.context.forceUVContext===!0)&&t.context.getUV&&(h=t.context.getUV(this,t)),h||(h=this.getDefaultUV()),this.updateMatrix===!0&&(h=this.getTransformedUV(h)),h=this.setupUV(t,h),this.updateType=this._matrixUniform!==null||this._flipYUniform!==null?nt.OBJECT:nt.NONE,h})();let n=this.levelNode;n===null&&t.context.getTextureLevel&&(n=t.context.getTextureLevel(this));let o=null,a=null;this.compareNode!==null&&(t.renderer.hasCompatibility(dd.TEXTURE_COMPARE)?o=this.compareNode:this.value.compareFunction===null||this.value.compareFunction===ud?a=this.compareNode:(o=this.compareNode,Yi('TSL: Only "LessCompare" is supported for depth texture comparison fallback.'))),e.uvNode=i,e.levelNode=n,e.biasNode=this.biasNode,e.compareNode=o,e.compareStepNode=a,e.gradNode=this.gradNode,e.depthNode=this.depthNode,e.offsetNode=this.offsetNode}generateUV(t,e){return e.build(t,this.sampler===!0?"vec2":"ivec2")}generateOffset(t,e){return e.build(t,"ivec2")}generateSnippet(t,e,s,i,n,o,a,h,l){const c=this.value;let u;return n?u=t.generateTextureBias(c,e,s,n,o,l):h?u=t.generateTextureGrad(c,e,s,h,o,l):a?u=t.generateTextureCompare(c,e,s,a,o,l):this.sampler===!1?u=t.generateTextureLoad(c,e,s,i,o,l):i?u=t.generateTextureLevel(c,e,s,i,o,l):u=t.generateTexture(c,e,s,o,l),u}generate(t,e){const s=this.value,i=t.getNodeProperties(this),n=super.generate(t,"property");if(/^sampler/.test(e))return n+"_sampler";if(t.isReference(e))return n;{const o=t.getDataFromNode(this),a=this.getNodeType(t);let h=o.propertyName;if(h===void 0){const{uvNode:c,levelNode:u,biasNode:d,compareNode:p,compareStepNode:m,depthNode:f,gradNode:y,offsetNode:g}=i,x=this.generateUV(t,c),C=u?u.build(t,"float"):null,b=d?d.build(t,"float"):null,A=f?f.build(t,"int"):null,N=p?p.build(t,"float"):null,E=m?m.build(t,"float"):null,O=y?[y[0].build(t,"vec2"),y[1].build(t,"vec2")]:null,P=g?this.generateOffset(t,g):null,k=t.getVarFromNode(this);h=t.getPropertyName(k);let $=this.generateSnippet(t,n,x,C,b,A,N,O,P);E!==null&&($=Ql(Cs(E,"float"),Cs($,a)).build(t,a)),t.addLineFlowCode(`${h} = ${$}`,this),o.snippet=$,o.propertyName=h}let l=h;return t.needsToWorkingColorSpace(s)&&(l=nc(Cs(l,a),s.colorSpace).setup(t).build(t,a)),t.format(l,a,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}sample(t){const e=this.clone();return e.uvNode=D(t),e.referenceNode=this.getBase(),D(e)}load(t){return this.sample(t).setSampler(!1)}blur(t){const e=this.clone();e.biasNode=D(t).mul(Gf(e)),e.referenceNode=this.getBase();const s=e.value;return e.generateMipmaps===!1&&(s&&s.generateMipmaps===!1||s.minFilter===as||s.magFilter===as)&&(W("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),e.biasNode=null),D(e)}level(t){const e=this.clone();return e.levelNode=D(t),e.referenceNode=this.getBase(),D(e)}size(t){return Vi(this,t)}bias(t){const e=this.clone();return e.biasNode=D(t),e.referenceNode=this.getBase(),D(e)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(t){const e=this.clone();return e.compareNode=D(t),e.referenceNode=this.getBase(),D(e)}grad(t,e){const s=this.clone();return s.gradNode=[D(t),D(e)],s.referenceNode=this.getBase(),D(s)}depth(t){const e=this.clone();return e.depthNode=D(t),e.referenceNode=this.getBase(),D(e)}offset(t){const e=this.clone();return e.offsetNode=D(t),e.referenceNode=this.getBase(),D(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;e!==null&&(e.value=t.matrix),t.matrixAutoUpdate===!0&&t.updateMatrix();const s=this._flipYUniform;s!==null&&(s.value=t.image instanceof ImageBitmap&&t.flipY===!0||t.isRenderTargetTexture===!0||t.isFramebufferTexture===!0||t.isDepthTexture===!0)}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t.depthNode=this.depthNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.offsetNode=this.offsetNode,t}}const qf=at(xr).setParameterLength(1,4).setName("texture"),sa=(r=dc,t=null,e=null,s=null)=>{let i;return r&&r.isTextureNode===!0?(i=D(r.clone()),i.referenceNode=r.getBase(),t!==null&&(i.uvNode=D(t)),e!==null&&(i.levelNode=D(e)),s!==null&&(i.biasNode=D(s))):i=qf(r,t,e,s),i},fe=(...r)=>sa(...r).setSampler(!1);class ia extends Ki{static get type(){return"BufferNode"}constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s,this.updateRanges=[]}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const pc=(r,t,e)=>new ia(r,t,e);class Qf extends ui{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),s=this.getNodeType(),i=this.node.getPaddedType();return t.format(e,i,s)}}class Jf extends ia{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null),this.array=t,this.elementType=e===null?nr(t[0]):e,this.paddedType=this.getPaddedType(),this.updateType=nt.RENDER,this.isArrayBufferNode=!0}getNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){const t=this.elementType;let e="vec4";return t==="mat2"?e="mat2":/mat/.test(t)===!0?e="mat4":t.charAt(0)==="i"?e="ivec4":t.charAt(0)==="u"&&(e="uvec4"),e}update(){const{array:t,value:e}=this,s=this.elementType;if(s==="float"||s==="int"||s==="uint")for(let i=0;i<t.length;i++){const n=i*4;e[n]=t[i]}else if(s==="color")for(let i=0;i<t.length;i++){const n=i*4,o=t[i];e[n]=o.r,e[n+1]=o.g,e[n+2]=o.b||0}else if(s==="mat2")for(let i=0;i<t.length;i++){const n=i*4,o=t[i];e[n]=o.elements[0],e[n+1]=o.elements[1],e[n+2]=o.elements[2],e[n+3]=o.elements[3]}else if(s==="mat3")for(let i=0;i<t.length;i++){const n=i*16,o=t[i];e[n]=o.elements[0],e[n+1]=o.elements[1],e[n+2]=o.elements[2],e[n+4]=o.elements[3],e[n+5]=o.elements[4],e[n+6]=o.elements[5],e[n+8]=o.elements[6],e[n+9]=o.elements[7],e[n+10]=o.elements[8],e[n+15]=1}else if(s==="mat4")for(let i=0;i<t.length;i++){const n=i*16,o=t[i];for(let a=0;a<o.elements.length;a++)e[n+a]=o.elements[a]}else for(let i=0;i<t.length;i++){const n=i*4,o=t[i];e[n]=o.x,e[n+1]=o.y,e[n+2]=o.z||0,e[n+3]=o.w||0}}setup(t){const e=this.array.length,s=this.elementType;let i=Float32Array;const n=this.paddedType,o=t.getTypeLength(n);return s.charAt(0)==="i"&&(i=Int32Array),s.charAt(0)==="u"&&(i=Uint32Array),this.value=new i(e*o),this.bufferCount=e,this.bufferType=n,this.update(),super.setup(t)}element(t){return new Qf(this,D(t))}}const He=(r,t)=>new Jf(r,t);class Kf extends B{constructor(t){super("float"),this.name=t,this.isBuiltinNode=!0}generate(){return this.name}}const _r=at(Kf).setParameterLength(1);let vi,Ci;class ut extends B{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this._output=null,this.isViewportNode=!0}getNodeType(){return this.scope===ut.DPR?"float":this.scope===ut.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=nt.NONE;return(this.scope===ut.SIZE||this.scope===ut.VIEWPORT||this.scope===ut.DPR)&&(t=nt.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===ut.VIEWPORT?e!==null?Ci.copy(e.viewport):(t.getViewport(Ci),Ci.multiplyScalar(t.getPixelRatio())):this.scope===ut.DPR?this._output.value=t.getPixelRatio():e!==null?(vi.width=e.width,vi.height=e.height):t.getDrawingBufferSize(vi)}setup(){const t=this.scope;let e=null;return t===ut.SIZE?e=Tt(vi||(vi=new _t)):t===ut.VIEWPORT?e=Tt(Ci||(Ci=new Wt)):t===ut.DPR?e=Tt(1):e=Ce(mc.div(uh)),this._output=e,e}generate(t){if(this.scope===ut.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(uh).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}ut.COORDINATE="coordinate";ut.VIEWPORT="viewport";ut.SIZE="size";ut.UV="uv";ut.DPR="dpr";const na=ft(ut,ut.UV),uh=ft(ut,ut.SIZE),mc=ft(ut,ut.COORDINATE),fc=ft(ut,ut.VIEWPORT);fc.zw;fc.xy;let Vr=null,vn=null,Hr=null,Cn=null,jr=null,bn=null;const ra=Tt(0,"uint").setName("u_cameraIndex").setGroup(kl("cameraIndex")).toVarying("v_cameraIndex"),_s=Tt("float").setName("cameraNear").setGroup(Xt).onRenderUpdate(({camera:r})=>r.near),Ts=Tt("float").setName("cameraFar").setGroup(Xt).onRenderUpdate(({camera:r})=>r.far),tg=z(({camera:r})=>{let t;if(r.isArrayCamera&&r.cameras.length>0){const e=[];for(const s of r.cameras)e.push(s.projectionMatrix);vn===null?vn=He(e).setGroup(Xt).setName("cameraProjectionMatrices"):vn.array=e,t=vn.element(r.isMultiViewCamera?_r("gl_ViewID_OVR"):ra).toConst("cameraProjectionMatrix")}else Vr===null&&(Vr=Tt(r.projectionMatrix).setName("cameraProjectionMatrix").setGroup(Xt).onRenderUpdate(({camera:e})=>e.projectionMatrix)),t=Vr;return t}).once()(),eg=z(({camera:r})=>{let t;if(r.isArrayCamera&&r.cameras.length>0){const e=[];for(const s of r.cameras)e.push(s.projectionMatrixInverse);Cn===null?Cn=He(e).setGroup(Xt).setName("cameraProjectionMatricesInverse"):Cn.array=e,t=Cn.element(r.isMultiViewCamera?_r("gl_ViewID_OVR"):ra).toConst("cameraProjectionMatrixInverse")}else Hr===null&&(Hr=Tt(r.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(Xt).onRenderUpdate(({camera:e})=>e.projectionMatrixInverse)),t=Hr;return t}).once()(),sn=z(({camera:r})=>{let t;if(r.isArrayCamera&&r.cameras.length>0){const e=[];for(const s of r.cameras)e.push(s.matrixWorldInverse);bn===null?bn=He(e).setGroup(Xt).setName("cameraViewMatrices"):bn.array=e,t=bn.element(r.isMultiViewCamera?_r("gl_ViewID_OVR"):ra).toConst("cameraViewMatrix")}else jr===null&&(jr=Tt(r.matrixWorldInverse).setName("cameraViewMatrix").setGroup(Xt).onRenderUpdate(({camera:e})=>e.matrixWorldInverse)),t=jr;return t}).once()();class nn{constructor(t=new M(1/0,1/0,1/0),e=new M(-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(de.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(de.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=de.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(s!==void 0){const n=s.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let o=0,a=n.count;o<a;o++)t.isMesh===!0?t.getVertexPosition(o,de):de.fromBufferAttribute(n,o),de.applyMatrix4(t.matrixWorld),this.expandByPoint(de);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),wn.copy(t.boundingBox)):(s.boundingBox===null&&s.computeBoundingBox(),wn.copy(s.boundingBox)),wn.applyMatrix4(t.matrixWorld),this.union(wn)}const i=t.children;for(let n=0,o=i.length;n<o;n++)this.expandByObject(i[n],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,de),de.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(bi),Sn.subVectors(this.max,bi),Fs.subVectors(t.a,bi),zs.subVectors(t.b,bi),Ds.subVectors(t.c,bi),qe.subVectors(zs,Fs),Qe.subVectors(Ds,zs),ps.subVectors(Fs,Ds);let e=[0,-qe.z,qe.y,0,-Qe.z,Qe.y,0,-ps.z,ps.y,qe.z,0,-qe.x,Qe.z,0,-Qe.x,ps.z,0,-ps.x,-qe.y,qe.x,0,-Qe.y,Qe.x,0,-ps.y,ps.x,0];return!Wr(e,Fs,zs,Ds,Sn)||(e=[1,0,0,0,1,0,0,0,1],!Wr(e,Fs,zs,Ds,Sn))?!1:(Mn.crossVectors(qe,Qe),e=[Mn.x,Mn.y,Mn.z],Wr(e,Fs,zs,Ds,Sn))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,de).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(de).length()*.5),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()?this:(ze[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),ze[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),ze[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),ze[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),ze[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),ze[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),ze[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),ze[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(ze),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)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const ze=[new M,new M,new M,new M,new M,new M,new M,new M],de=new M,wn=new nn,Fs=new M,zs=new M,Ds=new M,qe=new M,Qe=new M,ps=new M,bi=new M,Sn=new M,Mn=new M,ms=new M;function Wr(r,t,e,s,i){for(let n=0,o=r.length-3;n<=o;n+=3){ms.fromArray(r,n);const a=i.x*Math.abs(ms.x)+i.y*Math.abs(ms.y)+i.z*Math.abs(ms.z),h=t.dot(ms),l=e.dot(ms),c=s.dot(ms);if(Math.max(-Math.max(h,l,c),Math.min(h,l,c))>a)return!1}return!0}const sg=new nn,wi=new M,Gr=new M;class oa{constructor(t=new M,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;e!==void 0?s.copy(e):sg.setFromPoints(t).getCenter(s);let i=0;for(let n=0,o=t.length;n<o;n++)i=Math.max(i,s.distanceToSquared(t[n]));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;wi.subVectors(t,this.center);const e=wi.lengthSq();if(e>this.radius*this.radius){const s=Math.sqrt(e),i=(s-this.radius)*.5;this.center.addScaledVector(wi,i/s),this.radius+=i}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Gr.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(wi.copy(t.center).add(Gr)),this.expandByPoint(wi.copy(t.center).sub(Gr))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}const dh=new oa;class lt extends B{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=nt.OBJECT,this.uniformNode=new Ki(null)}getNodeType(){const t=this.scope;if(t===lt.WORLD_MATRIX)return"mat4";if(t===lt.POSITION||t===lt.VIEW_POSITION||t===lt.DIRECTION||t===lt.SCALE)return"vec3";if(t===lt.RADIUS)return"float"}update(t){const e=this.object3d,s=this.uniformNode,i=this.scope;if(i===lt.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===lt.POSITION)s.value=s.value||new M,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===lt.SCALE)s.value=s.value||new M,s.value.setFromMatrixScale(e.matrixWorld);else if(i===lt.DIRECTION)s.value=s.value||new M,e.getWorldDirection(s.value);else if(i===lt.VIEW_POSITION){const n=t.camera;s.value=s.value||new M,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(n.matrixWorldInverse)}else if(i===lt.RADIUS){const n=t.object.geometry;n.boundingSphere===null&&n.computeBoundingSphere(),dh.copy(n.boundingSphere).applyMatrix4(e.matrixWorld),s.value=dh.radius}}generate(t){const e=this.scope;return e===lt.WORLD_MATRIX?this.uniformNode.nodeType="mat4":e===lt.POSITION||e===lt.VIEW_POSITION||e===lt.DIRECTION||e===lt.SCALE?this.uniformNode.nodeType="vec3":e===lt.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}lt.WORLD_MATRIX="worldMatrix";lt.POSITION="position";lt.SCALE="scale";lt.VIEW_POSITION="viewPosition";lt.DIRECTION="direction";lt.RADIUS="radius";class ph extends lt{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}const Tr=ft(ph,ph.WORLD_MATRIX),ig=Tt(new he).onObjectUpdate(({object:r},t)=>t.value.getNormalMatrix(r.matrixWorld)),gc=z(r=>r.context.modelViewMatrix||ng).once()().toVar("modelViewMatrix"),ng=sn.mul(Tr),rg=z(r=>r.shaderStage!=="fragment"?(Yi("TSL: `clipSpace` is only available in fragment stage."),Nt()):r.context.clipSpace.toVarying("v_clipSpace")).once()(),yc=hi("position","vec3"),jt=yc.toVarying("positionLocal"),or=yc.toVarying("positionPrevious"),og=z(r=>Tr.mul(jt).xyz.toVarying(r.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),xc=z(()=>jt.transformDirection(Tr).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),Ot=z(r=>{if(r.shaderStage==="fragment"&&r.material.vertexNode){const t=eg.mul(rg);return t.xyz.div(t.w).toVar("positionView")}return r.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),_c=z(r=>{let t;return r.camera.isOrthographicCamera?t=H(0,0,1):t=Ot.negate().toVarying("v_positionViewDirection").normalize(),t.toVar("positionViewDirection")},"vec3").once(["POSITION"])();class ag extends B{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){if(t.shaderStage!=="fragment")return"true";const{material:e}=t;return e.side===dr?"false":t.getFrontFacing()}}const hg=ft(ag),Tc=K(hg).mul(2).sub(1),rn=z(([r],{material:t})=>{const e=t.side;return e===dr?r=r.mul(-1):e===Qu&&(r=r.mul(Tc)),r}),lg=hi("normal","vec3"),Pe=z(r=>r.geometry.hasAttribute("normal")===!1?(W('TSL: Vertex attribute "normal" not found on geometry.'),H(0,1,0)):lg,"vec3").once()().toVar("normalLocal"),cg=Ot.dFdx().cross(Ot.dFdy()).normalize().toVar("normalFlat"),vc=z(r=>{let t;return r.isFlatShading()?t=cg:t=Cc(Pe).toVarying("v_normalViewGeometry").normalize(),t},"vec3").once()().toVar("normalViewGeometry"),ae=z(r=>{let t;return r.subBuildFn==="NORMAL"||r.subBuildFn==="VERTEX"?(t=vc,r.isFlatShading()!==!0&&(t=rn(t))):t=r.context.setupNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),ug=ae.transformDirection(sn).toVar("normalWorld"),dg=z(({subBuildFn:r,context:t})=>{let e;return r==="NORMAL"||r==="VERTEX"?e=ae:e=t.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),e},"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),pg=z(([r,t=Tr])=>{const e=ls(t),s=r.div(H(e[0].dot(e[0]),e[1].dot(e[1]),e[2].dot(e[2])));return e.mul(s).xyz}),Cc=z(([r],t)=>{const e=t.context.modelNormalViewMatrix;if(e)return e.transformDirection(r);const s=ig.mul(r);return sn.transformDirection(s)});z(()=>(W('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),ae)).once(["NORMAL","VERTEX"])();z(()=>(W('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),ug)).once(["NORMAL","VERTEX"])();z(()=>(W('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),dg)).once(["NORMAL","VERTEX"])();const mh=new Rt,fh=new ci;class hs{constructor(t=0,e=0,s=0,i=hs.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,n=i[0],o=i[4],a=i[8],h=i[1],l=i[5],c=i[9],u=i[2],d=i[6],p=i[10];switch(e){case"XYZ":this._y=Math.asin(X(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,p),this._z=Math.atan2(-o,n)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-X(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,p),this._z=Math.atan2(h,l)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(X(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-o,l)):(this._y=0,this._z=Math.atan2(h,n));break;case"ZYX":this._y=Math.asin(-X(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(h,n)):(this._x=0,this._z=Math.atan2(-o,l));break;case"YZX":this._z=Math.asin(X(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(-c,l),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,p));break;case"XZY":this._z=Math.asin(-X(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-c,p),this._y=0);break;default:W("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,s===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return mh.makeRotationFromQuaternion(t),this.setFromRotationMatrix(mh,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return fh.setFromEuler(this),this.setFromQuaternion(fh,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],t[3]!==void 0&&(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}}hs.DEFAULT_ORDER="XYZ";const gh=new hs,Yr=new Rt,mg=Tt(0).onReference(({material:r})=>r).onObjectUpdate(({material:r})=>r.refractionRatio),fg=Tt(new Rt).onReference(function(r){return r.material}).onObjectUpdate(function({material:r,scene:t}){const e=t.environment!==null&&r.envMap===null?t.environmentRotation:r.envMapRotation;return e?(gh.copy(e),Yr.makeRotationFromEuler(gh)):Yr.identity(),Yr}),gg=_c.negate().reflect(ae),yg=_c.negate().refract(ae,mg),xg=gg.transformDirection(sn).toVar("reflectVector"),_g=yg.transformDirection(sn).toVar("reflectVector");class aa extends te{constructor(t=[],e=Lo,s,i,n,o,a,h,l,c){super(t,e,s,i,n,o,a,h,l,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}const Tg=new aa;class vg extends xr{static get type(){return"CubeTextureNode"}constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return this.value.isDepthTexture===!0?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===Lo?xg:t.mapping===gl?_g:(rt('CubeTextureNode: Mapping "%s" not supported.',t.mapping),H(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return s.isDepthTexture===!0?t.renderer.coordinateSystem===ni?H(e.x,e.y.negate(),e.z):e:((t.renderer.coordinateSystem===ni||!s.isRenderTargetTexture)&&(e=H(e.x.negate(),e.yz)),fg.mul(e))}generateUV(t,e){return e.build(t,this.sampler===!0?"vec3":"ivec3")}}const Cg=at(vg).setParameterLength(1,4).setName("cubeTexture"),bc=(r=Tg,t=null,e=null,s=null)=>{let i;return r&&r.isCubeTextureNode===!0?(i=D(r.clone()),i.referenceNode=r,t!==null&&(i.uvNode=D(t)),e!==null&&(i.levelNode=D(e)),s!==null&&(i.biasNode=D(s))):i=Cg(r,t,e,s),i};class bg extends ui{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class ha extends B{static get type(){return"ReferenceNode"}constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=nt.OBJECT}element(t){return new bg(this,D(t))}setGroup(t){return this.group=t,this}setName(t){return this.name=t,this}label(t){return W('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(t)}setNodeType(t){let e=null;this.count!==null?e=pc(null,t,this.count):Array.isArray(this.getValueFromReference())?e=He(null,t):t==="texture"?e=sa(null):t==="cubeTexture"?e=bc(null):e=Tt(null,t),this.group!==null&&e.setGroup(this.group),this.name!==null&&e.setName(this.name),this.node=e}getNodeType(t){return this.node===null&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let i=1;i<e.length;i++)s=s[e[i]];return s}updateReference(t){return this.reference=this.object!==null?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){this.node===null&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}const Zi=(r,t,e)=>new ha(r,t,e),yh=(r,t,e,s)=>new ha(r,t,s,e);class wg extends ha{static get type(){return"MaterialReferenceNode"}constructor(t,e,s=null){super(t,e,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=this.material!==null?this.material:t.material,this.reference}}const Xs=(r,t,e=null)=>new wg(r,t,e),wc=en(),Sg=Ot.dFdx(),Mg=Ot.dFdy(),Sc=wc.dFdx(),Mc=wc.dFdy(),Nc=ae,Ac=Mg.cross(Nc),Ec=Nc.cross(Sg),Oo=Ac.mul(Sc.x).add(Ec.mul(Mc.x)),Ro=Ac.mul(Sc.y).add(Ec.mul(Mc.y)),xh=Oo.dot(Oo).max(Ro.dot(Ro)),Oc=xh.equal(0).select(0,xh.inverseSqrt()),Ng=Oo.mul(Oc).toVar("tangentViewFrame"),Ag=Ro.mul(Oc).toVar("bitangentViewFrame"),Rc=hi("tangent","vec4"),ar=Rc.xyz.toVar("tangentLocal"),Ic=z(r=>{let t;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?t=gc.mul(Nt(ar,0)).xyz.toVarying("v_tangentView").normalize():t=Ng,r.isFlatShading()!==!0&&(t=rn(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),Eg=z(([r,t],e)=>{let s=r.mul(Rc.w).xyz;return e.subBuildFn==="NORMAL"&&e.isFlatShading()!==!0&&(s=s.toVarying(t)),s}).once(["NORMAL"]),Og=z(r=>{let t;return r.subBuildFn==="VERTEX"||r.geometry.hasAttribute("tangent")?t=Eg(ae.cross(Ic),"v_bitangentView").normalize():t=Ag,r.isFlatShading()!==!0&&(t=rn(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),Rg=ls(Ic,Og,ae).toVar("TBNViewMatrix"),_h=r=>H(r,Xo(tc(K(1).sub(tn(r,r)))));class Ig extends It{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=Mr,this.unpackNormalMode=Nr}setup(t){const{normalMapType:e,scaleNode:s,unpackNormalMode:i}=this;let n=this.node.mul(2).sub(1);if(e===Mr?i===vl?n=_h(n.xy):i===cd?n=_h(n.yw):i!==Nr&&console.error(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==Nr&&console.error(`THREE.NodeMaterial: Normal map type '${e}' is not compatible with unpack normal mode '${i}'`),s!==null){let a=s;t.isFlatShading()===!0&&(a=rn(a)),n=H(n.xy.mul(a),n.z)}let o=null;return e===ld?o=Cc(n):e===Mr?o=Rg.mul(n).normalize():(rt(`NodeMaterial: Unsupported normal map type: ${e}`),o=ae),o}}const Th=at(Ig).setParameterLength(1,2),Pg=z(({textureNode:r,bumpScale:t})=>{const e=i=>r.isolate().context({getUV:n=>i(n.uvNode||en()),forceUVContext:!0}),s=K(e(i=>i));return Ce(K(e(i=>i.add(i.dFdx()))).sub(s),K(e(i=>i.add(i.dFdy()))).sub(s)).mul(t)}),Lg=z(r=>{const{surf_pos:t,surf_norm:e,dHdxy:s}=r,i=t.dFdx().normalize(),n=t.dFdy().normalize(),o=e,a=n.cross(o),h=o.cross(i),l=i.dot(a).mul(Tc),c=l.sign().mul(s.x.mul(a).add(s.y.mul(h)));return l.abs().mul(e).sub(c).normalize()});class Fg extends It{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=this.scaleNode!==null?this.scaleNode:1,e=Pg({textureNode:this.textureNode,bumpScale:t});return Lg({surf_pos:Ot,surf_norm:ae,dHdxy:e})}}const zg=at(Fg).setParameterLength(1,2),vh=new Map;class R extends B{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let s=vh.get(t);return s===void 0&&(s=Xs(t,e),vh.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache(t==="map"?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let i=null;if(s===R.COLOR){const n=e.color!==void 0?this.getColor(s):H();e.map&&e.map.isTexture===!0?i=n.mul(this.getTexture("map")):i=n}else if(s===R.OPACITY){const n=this.getFloat(s);e.alphaMap&&e.alphaMap.isTexture===!0?i=n.mul(this.getTexture("alpha")):i=n}else if(s===R.SPECULAR_STRENGTH)e.specularMap&&e.specularMap.isTexture===!0?i=this.getTexture("specular").r:i=K(1);else if(s===R.SPECULAR_INTENSITY){const n=this.getFloat(s);e.specularIntensityMap&&e.specularIntensityMap.isTexture===!0?i=n.mul(this.getTexture(s).a):i=n}else if(s===R.SPECULAR_COLOR){const n=this.getColor(s);e.specularColorMap&&e.specularColorMap.isTexture===!0?i=n.mul(this.getTexture(s).rgb):i=n}else if(s===R.ROUGHNESS){const n=this.getFloat(s);e.roughnessMap&&e.roughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).g):i=n}else if(s===R.METALNESS){const n=this.getFloat(s);e.metalnessMap&&e.metalnessMap.isTexture===!0?i=n.mul(this.getTexture(s).b):i=n}else if(s===R.EMISSIVE){const n=this.getFloat("emissiveIntensity"),o=this.getColor(s).mul(n);e.emissiveMap&&e.emissiveMap.isTexture===!0?i=o.mul(this.getTexture(s)):i=o}else if(s===R.NORMAL)e.normalMap?(i=Th(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=e.normalMapType,(e.normalMap.format==od||e.normalMap.format==hd||e.normalMap.format==ad)&&(i.unpackNormalMode=vl)):e.bumpMap?i=zg(this.getTexture("bump").r,this.getFloat("bumpScale")):i=ae;else if(s===R.CLEARCOAT){const n=this.getFloat(s);e.clearcoatMap&&e.clearcoatMap.isTexture===!0?i=n.mul(this.getTexture(s).r):i=n}else if(s===R.CLEARCOAT_ROUGHNESS){const n=this.getFloat(s);e.clearcoatRoughnessMap&&e.clearcoatRoughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).r):i=n}else if(s===R.CLEARCOAT_NORMAL)e.clearcoatNormalMap?i=Th(this.getTexture(s),this.getCache(s+"Scale","vec2")):i=ae;else if(s===R.SHEEN){const n=this.getColor("sheenColor").mul(this.getFloat("sheen"));e.sheenColorMap&&e.sheenColorMap.isTexture===!0?i=n.mul(this.getTexture("sheenColor").rgb):i=n}else if(s===R.SHEEN_ROUGHNESS){const n=this.getFloat(s);e.sheenRoughnessMap&&e.sheenRoughnessMap.isTexture===!0?i=n.mul(this.getTexture(s).a):i=n,i=i.clamp(1e-4,1)}else if(s===R.ANISOTROPY)if(e.anisotropyMap&&e.anisotropyMap.isTexture===!0){const n=this.getTexture(s);i=Dl(Si.x,Si.y,Si.y.negate(),Si.x).mul(n.rg.mul(2).sub(Ce(1)).normalize().mul(n.b))}else i=Si;else if(s===R.IRIDESCENCE_THICKNESS){const n=Zi("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const o=Zi("0","float",e.iridescenceThicknessRange);i=n.sub(o).mul(this.getTexture(s).g).add(o)}else i=n}else if(s===R.TRANSMISSION){const n=this.getFloat(s);e.transmissionMap?i=n.mul(this.getTexture(s).r):i=n}else if(s===R.THICKNESS){const n=this.getFloat(s);e.thicknessMap?i=n.mul(this.getTexture(s).g):i=n}else if(s===R.IOR)i=this.getFloat(s);else if(s===R.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===R.AO)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else if(s===R.LINE_DASH_OFFSET)i=e.dashOffset?this.getFloat(s):K(0);else{const n=this.getNodeType(t);i=this.getCache(s,n)}return i}}R.ALPHA_TEST="alphaTest";R.COLOR="color";R.OPACITY="opacity";R.SHININESS="shininess";R.SPECULAR="specular";R.SPECULAR_STRENGTH="specularStrength";R.SPECULAR_INTENSITY="specularIntensity";R.SPECULAR_COLOR="specularColor";R.REFLECTIVITY="reflectivity";R.ROUGHNESS="roughness";R.METALNESS="metalness";R.NORMAL="normal";R.CLEARCOAT="clearcoat";R.CLEARCOAT_ROUGHNESS="clearcoatRoughness";R.CLEARCOAT_NORMAL="clearcoatNormal";R.EMISSIVE="emissive";R.ROTATION="rotation";R.SHEEN="sheen";R.SHEEN_ROUGHNESS="sheenRoughness";R.ANISOTROPY="anisotropy";R.IRIDESCENCE="iridescence";R.IRIDESCENCE_IOR="iridescenceIOR";R.IRIDESCENCE_THICKNESS="iridescenceThickness";R.IOR="ior";R.TRANSMISSION="transmission";R.THICKNESS="thickness";R.ATTENUATION_DISTANCE="attenuationDistance";R.ATTENUATION_COLOR="attenuationColor";R.LINE_SCALE="scale";R.LINE_DASH_SIZE="dashSize";R.LINE_GAP_SIZE="gapSize";R.LINE_WIDTH="linewidth";R.LINE_DASH_OFFSET="dashOffset";R.POINT_SIZE="size";R.DISPERSION="dispersion";R.LIGHT_MAP="light";R.AO="ao";const Dg=ft(R,R.ALPHA_TEST),Bg=ft(R,R.COLOR),kg=ft(R,R.EMISSIVE),Ug=ft(R,R.OPACITY),$r=ft(R,R.SPECULAR_STRENGTH),Xr=ft(R,R.REFLECTIVITY),Vg=ft(R,R.NORMAL),Pc=ft(R,R.LIGHT_MAP),Hg=ft(R,R.AO),Si=Tt(new _t).onReference(function(r){return r.material}).onRenderUpdate(function({material:r}){this.value.set(r.anisotropy*Math.cos(r.anisotropyRotation),r.anisotropy*Math.sin(r.anisotropyRotation))}),jg=z(r=>r.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class Wg extends ui{static get type(){return"StorageArrayElementNode"}constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}getMemberType(t,e){const s=this.storageBufferNode.structTypeNode;return s?s.getMemberType(t,e):"void"}setup(t){return t.isAvailable("storageBuffer")===!1&&this.node.isPBO===!0&&t.setupPBO(this.node),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(t.isAvailable("storageBuffer")===!1?this.node.isPBO===!0&&i!==!0&&(this.node.value.isInstancedBufferAttribute||t.shaderStage!=="compute")?s=t.generatePBO(this):s=this.node.build(t):s=super.generate(t),i!==!0){const n=this.getNodeType(t);s=t.format(s,n,e)}return s}}const Gg=at(Wg).setParameterLength(2);class Yg extends ia{static get type(){return"StorageBufferNode"}constructor(t,e=null,s=0){let i,n=null;e&&e.isStruct?(i="struct",n=e.layout,(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute)&&(s=t.count)):e===null&&(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute)?(i=lp(t.itemSize),s=t.count):i=e,super(t,i,s),this.isStorageBufferNode=!0,this.structTypeNode=n,this.access=th.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,t.isStorageBufferAttribute!==!0&&t.isStorageInstancedBufferAttribute!==!0&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(this.bufferCount===0){let e=t.globalCache.getData(this.value);return e===void 0&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(t){return Gg(this,t)}setPBO(t){return this.isPBO=t,this}getPBO(){return this.isPBO}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(th.READ_ONLY)}setAtomic(t){return this.isAtomic=t,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return this._attribute===null&&(this._attribute=oc(this.value),this._varying=pi(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(t){if(this.structTypeNode!==null)return this.structTypeNode.getNodeType(t);if(t.isAvailable("storageBuffer")||t.isAvailable("indirectStorageBuffer"))return super.getNodeType(t);const{attribute:e}=this.getAttributeData();return e.getNodeType(t)}getMemberType(t,e){return this.structTypeNode!==null?this.structTypeNode.getMemberType(t,e):"void"}generate(t){if(this.structTypeNode!==null&&this.structTypeNode.build(t),t.isAvailable("storageBuffer")||t.isAvailable("indirectStorageBuffer"))return super.generate(t);const{attribute:e,varying:s}=this.getAttributeData(),i=s.build(t);return t.registerTransform(i,e),i}}const Ch=(r,t=null,e=0)=>new Yg(r,t,e);class St extends B{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i;if(s===St.VERTEX)i=t.getVertexIndex();else if(s===St.INSTANCE)i=t.getInstanceIndex();else if(s===St.DRAW)i=t.getDrawIndex();else if(s===St.INVOCATION_LOCAL)i=t.getInvocationLocalIndex();else if(s===St.INVOCATION_SUBGROUP)i=t.getInvocationSubgroupIndex();else if(s===St.SUBGROUP)i=t.getSubgroupIndex();else throw new Error("THREE.IndexNode: Unknown scope: "+s);let n;return t.shaderStage==="vertex"||t.shaderStage==="compute"?n=i:n=pi(this).build(t,e),n}}St.VERTEX="vertex";St.INSTANCE="instance";St.SUBGROUP="subgroup";St.INVOCATION_LOCAL="invocationLocal";St.INVOCATION_SUBGROUP="invocationSubgroup";St.DRAW="draw";const $g=ft(St,St.VERTEX),Hi=ft(St,St.INSTANCE),Xg=ft(St,St.DRAW);class Zg extends rc{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 qg extends os{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}}class Qg extends B{static get type(){return"InstanceNode"}constructor(t,e,s=null){super("void"),this.count=t,this.instanceMatrix=e,this.instanceColor=s,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=nt.FRAME,this.buffer=null,this.bufferColor=null,this.previousInstanceMatrixNode=null}get isStorageMatrix(){const{instanceMatrix:t}=this;return t&&t.isStorageInstancedBufferAttribute===!0}get isStorageColor(){const{instanceColor:t}=this;return t&&t.isStorageInstancedBufferAttribute===!0}setup(t){let{instanceMatrixNode:e,instanceColorNode:s}=this;e===null&&(e=this._createInstanceMatrixNode(!0,t),this.instanceMatrixNode=e);const{instanceColor:i,isStorageColor:n}=this;if(i&&s===null){if(n)s=Ch(i,"vec3",Math.max(i.count,1)).element(Hi);else{const a=new qg(i.array,3),h=i.usage===Co?ch:lh;this.bufferColor=a,s=H(h(a,"vec3",3,0))}this.instanceColorNode=s}const o=e.mul(jt).xyz;if(jt.assign(o),t.needsPreviousData()&&or.assign(this.getPreviousInstancedPosition(t)),t.hasGeometryAttribute("normal")){const a=pg(Pe,e);Pe.assign(a)}this.instanceColorNode!==null&&rr("vec3","vInstanceColor").assign(this.instanceColorNode)}update(t){this.buffer!==null&&this.isStorageMatrix!==!0&&(this.buffer.clearUpdateRanges(),this.buffer.updateRanges.push(...this.instanceMatrix.updateRanges),this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version)),this.instanceColor&&this.bufferColor!==null&&this.isStorageColor!==!0&&(this.bufferColor.clearUpdateRanges(),this.bufferColor.updateRanges.push(...this.instanceColor.updateRanges),this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)),this.previousInstanceMatrixNode!==null&&t.object.previousInstanceMatrix.array.set(this.instanceMatrix.array)}getPreviousInstancedPosition(t){const e=t.object;return this.previousInstanceMatrixNode===null&&(e.previousInstanceMatrix=this.instanceMatrix.clone(),this.previousInstanceMatrixNode=this._createInstanceMatrixNode(!1,t)),this.previousInstanceMatrixNode.mul(or).xyz}_createInstanceMatrixNode(t,e){let s;const{instanceMatrix:i}=this,{count:n}=i;if(this.isStorageMatrix)s=Ch(i,"mat4",Math.max(n,1)).element(Hi);else if(n*16*4<=e.getUniformBufferLimit())s=pc(i.array,"mat4",Math.max(n,1)).element(Hi);else{const a=new Zg(i.array,16,1);t===!0&&(this.buffer=a);const h=i.usage===Co?ch:lh,l=[h(a,"vec4",16,0),h(a,"vec4",16,4),h(a,"vec4",16,8),h(a,"vec4",16,12)];s=gr(...l)}return s}}class Jg extends Qg{static get type(){return"InstancedMeshNode"}constructor(t){const{count:e,instanceMatrix:s,instanceColor:i}=t;super(e,s,i),this.instancedMesh=t}}const Kg=at(Jg).setParameterLength(1);class ty extends B{static get type(){return"BatchNode"}constructor(t){super("void"),this.batchMesh=t,this.batchingIdNode=null}setup(t){this.batchingIdNode===null&&(t.getDrawIndex()===null?this.batchingIdNode=Hi:this.batchingIdNode=Xg);const s=z(([m])=>{const f=wt(Vi(fe(this.batchMesh._indirectTexture),0).x).toConst(),y=wt(m).mod(f).toConst(),g=wt(m).div(f).toConst();return fe(this.batchMesh._indirectTexture,Ie(y,g)).x}).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]})(wt(this.batchingIdNode)),i=this.batchMesh._matricesTexture,n=wt(Vi(fe(i),0).x).toConst(),o=K(s).mul(4).toInt().toConst(),a=o.mod(n).toConst(),h=o.div(n).toConst(),l=gr(fe(i,Ie(a,h)),fe(i,Ie(a.add(1),h)),fe(i,Ie(a.add(2),h)),fe(i,Ie(a.add(3),h))),c=this.batchMesh._colorsTexture;if(c!==null){const f=z(([y])=>{const g=wt(Vi(fe(c),0).x).toConst(),x=y,C=x.mod(g).toConst(),b=x.div(g).toConst();return fe(c,Ie(C,b)).rgb}).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]})(s);rr("vec3","vBatchColor").assign(f)}const u=ls(l);jt.assign(l.mul(jt));const d=Pe.div(H(u[0].dot(u[0]),u[1].dot(u[1]),u[2].dot(u[2]))),p=u.mul(d).xyz;Pe.assign(p),t.hasGeometryAttribute("tangent")&&ar.mulAssign(u)}}const ey=at(ty).setParameterLength(1),bh=new WeakMap;class sy extends B{static get type(){return"SkinningNode"}constructor(t){super("void"),this.skinnedMesh=t,this.updateType=nt.OBJECT,this.skinIndexNode=hi("skinIndex","uvec4"),this.skinWeightNode=hi("skinWeight","vec4"),this.bindMatrixNode=Zi("bindMatrix","mat4"),this.bindMatrixInverseNode=Zi("bindMatrixInverse","mat4"),this.boneMatricesNode=yh("skeleton.boneMatrices","mat4",t.skeleton.bones.length),this.positionNode=jt,this.toPositionNode=jt,this.previousBoneMatricesNode=null}getSkinnedPosition(t=this.boneMatricesNode,e=this.positionNode){const{skinIndexNode:s,skinWeightNode:i,bindMatrixNode:n,bindMatrixInverseNode:o}=this,a=t.element(s.x),h=t.element(s.y),l=t.element(s.z),c=t.element(s.w),u=n.mul(e),d=$i(a.mul(i.x).mul(u),h.mul(i.y).mul(u),l.mul(i.z).mul(u),c.mul(i.w).mul(u));return o.mul(d).xyz}getSkinnedNormalAndTangent(t=this.boneMatricesNode,e=Pe,s=ar){const{skinIndexNode:i,skinWeightNode:n,bindMatrixNode:o,bindMatrixInverseNode:a}=this,h=t.element(i.x),l=t.element(i.y),c=t.element(i.z),u=t.element(i.w);let d=$i(n.x.mul(h),n.y.mul(l),n.z.mul(c),n.w.mul(u));d=a.mul(d).mul(o);const p=d.transformDirection(e).xyz,m=d.transformDirection(s).xyz;return{skinNormal:p,skinTangent:m}}getPreviousSkinnedPosition(t){const e=t.object;return this.previousBoneMatricesNode===null&&(e.skeleton.previousBoneMatrices=new Float32Array(e.skeleton.boneMatrices),this.previousBoneMatricesNode=yh("skeleton.previousBoneMatrices","mat4",e.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,or)}setup(t){t.needsPreviousData()&&or.assign(this.getPreviousSkinnedPosition(t));const e=this.getSkinnedPosition();if(this.toPositionNode&&this.toPositionNode.assign(e),t.hasGeometryAttribute("normal")){const{skinNormal:s,skinTangent:i}=this.getSkinnedNormalAndTangent();Pe.assign(s),t.hasGeometryAttribute("tangent")&&ar.assign(i)}return e}generate(t,e){if(e!=="void")return super.generate(t,e)}update(t){const e=t.object&&t.object.skeleton?t.object.skeleton:this.skinnedMesh.skeleton;bh.get(e)!==t.frameId&&(bh.set(e,t.frameId),this.previousBoneMatricesNode!==null&&(e.previousBoneMatrices===null&&(e.previousBoneMatrices=new Float32Array(e.boneMatrices)),e.previousBoneMatrices.set(e.boneMatrices)),e.update())}}const iy=r=>new sy(r);class ny extends B{static get type(){return"LoopNode"}constructor(t=[]){super("void"),this.params=t}getVarName(t){return String.fromCharCode(105+t)}getProperties(t){const e=t.getNodeProperties(this);if(e.stackNode!==void 0)return e;const s={};for(let a=0,h=this.params.length-1;a<h;a++){const l=this.params[a],c=l.isNode!==!0&&l.name||this.getVarName(a),u=l.isNode!==!0&&l.type||"int";s[c]=Cs(c,u)}const i=t.addStack(),n=this.params[this.params.length-1](s);e.returnsNode=n.context({nodeLoop:n}),e.stackNode=i;const o=this.params[0];if(o.isNode!==!0&&typeof o.update=="function"){const a=z(this.params[0].update)(s);e.updateNode=a.context({nodeLoop:a})}return t.removeStack(),e}setup(t){if(this.getProperties(t),t.fnCall){const e=t.getDataFromNode(t.fnCall.shaderNode);e.hasLoop=!0}}generate(t){const e=this.getProperties(t),s=this.params,i=e.stackNode;for(let o=0,a=s.length-1;o<a;o++){const h=s[o];let l=!1,c=null,u=null,d=null,p=null,m=null,f=null;h.isNode?h.getNodeType(t)==="bool"?(l=!0,p="bool",u=h.build(t,p)):(p="int",d=this.getVarName(o),c="0",u=h.build(t,p),m="<"):(p=h.type||"int",d=h.name||this.getVarName(o),c=h.start,u=h.end,m=h.condition,f=h.update,typeof c=="number"?c=t.generateConst(p,c):c&&c.isNode&&(c=c.build(t,p)),typeof u=="number"?u=t.generateConst(p,u):u&&u.isNode&&(u=u.build(t,p)),c!==void 0&&u===void 0?(c=c+" - 1",u="0",m=">="):u!==void 0&&c===void 0&&(c="0",m="<"),m===void 0&&(Number(c)>Number(u)?m=">=":m="<"));let y;if(l)y=`while ( ${u} )`;else{const g={start:c,end:u},x=g.start,C=g.end;let b;const A=()=>m.includes("<")?"+=":"-=";if(f!=null)switch(typeof f){case"function":b=t.flowStagesNode(e.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":b=d+" "+A()+" "+t.generateConst(p,f);break;case"string":b=d+" "+f;break;default:f.isNode?b=d+" "+A()+" "+f.build(t):(rt("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),b="break /* invalid update */")}else p==="int"||p==="uint"?f=m.includes("<")?"++":"--":f=A()+" 1.",b=d+" "+f;const N=t.getVar(p,d)+" = "+x,E=d+" "+m+" "+C;y=`for ( ${N}; ${E}; ${b} )`}t.addFlowCode((o===0?`
105
+ `:"")+t.tab+y+` {
106
+
107
+ `).addFlowTab()}const n=i.build(t,"void");e.returnsNode.build(t,"void"),t.removeFlowTab().addFlowCode(`
108
+ `+t.tab+n);for(let o=0,a=this.params.length-1;o<a;o++)t.addFlowCode((o===0?"":t.tab)+`}
109
+
110
+ `).removeFlowTab();t.addFlowTab()}}const Zs=(...r)=>new ny(Js(r,"int")).toStack();class ry extends te{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=as,this.minFilter=as,this.wrapR=Oi,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}const Zr=new WeakMap,Qt=new Wt,wh=z(({bufferMap:r,influence:t,stride:e,width:s,depth:i,offset:n})=>{const o=wt($g).mul(e).add(n),a=o.div(s),h=o.sub(a.mul(s));return fe(r,Ie(h,a)).depth(i).xyz.mul(t)});function oy(r){const t=r.morphAttributes.position!==void 0,e=r.morphAttributes.normal!==void 0,s=r.morphAttributes.color!==void 0,i=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,n=i!==void 0?i.length:0;let o=Zr.get(r);if(o===void 0||o.count!==n){let g=function(){f.dispose(),Zr.delete(r),r.removeEventListener("dispose",g)};o!==void 0&&o.texture.dispose();const a=r.morphAttributes.position||[],h=r.morphAttributes.normal||[],l=r.morphAttributes.color||[];let c=0;t===!0&&(c=1),e===!0&&(c=2),s===!0&&(c=3);let u=r.attributes.position.count*c,d=1;const p=4096;u>p&&(d=Math.ceil(u/p),u=p);const m=new Float32Array(u*d*4*n),f=new ry(m,u,d,n);f.type=Tl,f.needsUpdate=!0;const y=c*4;for(let x=0;x<n;x++){const C=a[x],b=h[x],A=l[x],N=u*d*4*x;for(let E=0;E<C.count;E++){const O=E*y;t===!0&&(Qt.fromBufferAttribute(C,E),m[N+O+0]=Qt.x,m[N+O+1]=Qt.y,m[N+O+2]=Qt.z,m[N+O+3]=0),e===!0&&(Qt.fromBufferAttribute(b,E),m[N+O+4]=Qt.x,m[N+O+5]=Qt.y,m[N+O+6]=Qt.z,m[N+O+7]=0),s===!0&&(Qt.fromBufferAttribute(A,E),m[N+O+8]=Qt.x,m[N+O+9]=Qt.y,m[N+O+10]=Qt.z,m[N+O+11]=A.itemSize===4?Qt.w:1)}}o={count:n,texture:f,stride:c,size:new _t(u,d)},Zr.set(r,o),r.addEventListener("dispose",g)}return o}class ay extends B{static get type(){return"MorphNode"}constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=Tt(1),this.updateType=nt.OBJECT}setup(t){const{geometry:e}=t,s=e.morphAttributes.position!==void 0,i=e.hasAttribute("normal")&&e.morphAttributes.normal!==void 0,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=n!==void 0?n.length:0,{texture:a,stride:h,size:l}=oy(e);s===!0&&jt.mulAssign(this.morphBaseInfluence),i===!0&&Pe.mulAssign(this.morphBaseInfluence);const c=wt(l.width);Zs(o,({i:u})=>{const d=K(0).toVar();this.mesh.count>1&&this.mesh.morphTexture!==null&&this.mesh.morphTexture!==void 0?d.assign(fe(this.mesh.morphTexture,Ie(wt(u).add(1),wt(Hi))).r):d.assign(Zi("morphTargetInfluences","float").element(u).toVar()),ss(d.notEqual(0),()=>{s===!0&&jt.addAssign(wh({bufferMap:a,influence:d,stride:h,width:c,depth:u,offset:wt(0)})),i===!0&&Pe.addAssign(wh({bufferMap:a,influence:d,stride:h,width:c,depth:u,offset:wt(1)}))})})}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce((e,s)=>e+s,0)}}const hy=at(ay).setParameterLength(1);class vr extends B{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class ly extends vr{static get type(){return"AONode"}constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}class cy extends ec{static get type(){return"LightingContextNode"}constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s=H().toVar("directDiffuse"),i=H().toVar("directSpecular"),n=H().toVar("indirectDiffuse"),o=H().toVar("indirectSpecular"),a={directDiffuse:s,directSpecular:i,indirectDiffuse:n,indirectSpecular:o};return{radiance:H().toVar("radiance"),irradiance:H().toVar("irradiance"),iblIrradiance:H().toVar("iblIrradiance"),ambientOcclusion:K(1).toVar("ambientOcclusion"),reflectedLight:a,backdrop:t,backdropAlpha:e}}setup(t){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const uy=at(cy);class dy extends vr{static get type(){return"IrradianceNode"}constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}class py extends te{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=as,this.minFilter=as,this.generateMipmaps=!1,this.needsUpdate=!0}}const Bs=new _t;class my extends xr{static get type(){return"ViewportTextureNode"}constructor(t=na,e=null,s=null){let i=null;s===null?(i=new py,i.minFilter=Fo,s=i):i=s,super(s,t,e),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=nt.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(t=null){let e,s;if(this.referenceNode?(e=this.referenceNode.defaultFramebuffer,s=this.referenceNode._cacheTextures):(e=this.defaultFramebuffer,s=this._cacheTextures),t===null)return e;if(s.has(t)===!1){const i=e.clone();s.set(t,i)}return s.get(t)}updateReference(t){const e=t.renderer.getRenderTarget();return this.value=this.getTextureForReference(e),this.value}updateBefore(t){const e=t.renderer,s=e.getRenderTarget();s===null?e.getDrawingBufferSize(Bs):Bs.set(s.width,s.height);const i=this.getTextureForReference(s);(i.image.width!==Bs.width||i.image.height!==Bs.height)&&(i.image.width=Bs.width,i.image.height=Bs.height,i.needsUpdate=!0);const n=i.generateMipmaps;i.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(i),i.generateMipmaps=n}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}class la extends te{constructor(t,e,s=_l,i,n,o,a=as,h=as,l,c=Pa,u=1){if(c!==Pa&&c!==rd)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:t,height:e,depth:u};super(d,i,n,o,a,h,c,s,l),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.source=new ea(Object.assign({},t.image)),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}let Nn=null;class fy extends my{static get type(){return"ViewportDepthTextureNode"}constructor(t=na,e=null){Nn===null&&(Nn=new la),super(t,e,Nn)}getTextureForReference(){return Nn}}const gy=at(fy).setParameterLength(0,2);class Zt extends B{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===Zt.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===Zt.DEPTH_BASE)s!==null&&(i=Fc().assign(s));else if(e===Zt.DEPTH)t.isPerspectiveCamera?i=yy(Ot.z,_s,Ts):i=ji(Ot.z,_s,Ts);else if(e===Zt.LINEAR_DEPTH)if(s!==null)if(t.isPerspectiveCamera){const n=Lc(s,_s,Ts);i=ji(n,_s,Ts)}else i=s;else i=ji(Ot.z,_s,Ts);return i}}Zt.DEPTH_BASE="depthBase";Zt.DEPTH="depth";Zt.LINEAR_DEPTH="linearDepth";const ji=(r,t,e)=>r.add(t).div(t.sub(e)),yy=(r,t,e)=>t.add(r).mul(e).div(e.sub(t).mul(r)),Lc=z(([r,t,e],s)=>s.renderer.reversedDepthBuffer===!0?t.mul(e).div(t.sub(e).mul(r).sub(t)):t.mul(e).div(e.sub(t).mul(r).sub(e))),xy=(r,t,e)=>{t=t.max(1e-6).toVar();const s=Ks(r.negate().div(t)),i=Ks(e.div(t));return s.div(i)},Fc=at(Zt,Zt.DEPTH_BASE),zc=ft(Zt,Zt.DEPTH),Dc=at(Zt,Zt.LINEAR_DEPTH).setParameterLength(0,1);gy();zc.assign=r=>Fc(r);class ie extends B{static get type(){return"ClippingNode"}constructor(t=ie.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{intersectionPlanes:s,unionPlanes:i}=e;return this.hardwareClipping=t.material.hardwareClipping,this.scope===ie.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,i):this.scope===ie.HARDWARE?this.setupHardwareClipping(i,t):this.setupDefault(s,i)}setupAlphaToCoverage(t,e){return z(()=>{const s=K().toVar("distanceToPlane"),i=K().toVar("distanceToGradient"),n=K(1).toVar("clipOpacity"),o=e.length;if(this.hardwareClipping===!1&&o>0){const h=He(e).setGroup(Xt);Zs(o,({i:l})=>{const c=h.element(l);s.assign(Ot.dot(c.xyz).negate().add(c.w)),i.assign(s.fwidth().div(2)),n.mulAssign(ai(i.negate(),i,s))})}const a=t.length;if(a>0){const h=He(t).setGroup(Xt),l=K(1).toVar("intersectionClipOpacity");Zs(a,({i:c})=>{const u=h.element(c);s.assign(Ot.dot(u.xyz).negate().add(u.w)),i.assign(s.fwidth().div(2)),l.mulAssign(ai(i.negate(),i,s).oneMinus())}),n.mulAssign(l.oneMinus())}Bt.a.mulAssign(n),Bt.a.equal(0).discard()})()}setupDefault(t,e){return z(()=>{const s=e.length;if(this.hardwareClipping===!1&&s>0){const n=He(e).setGroup(Xt);Zs(s,({i:o})=>{const a=n.element(o);Ot.dot(a.xyz).greaterThan(a.w).discard()})}const i=t.length;if(i>0){const n=He(t).setGroup(Xt),o=Yo(!0).toVar("clipped");Zs(i,({i:a})=>{const h=n.element(a);o.assign(Ot.dot(h.xyz).greaterThan(h.w).and(o))}),o.discard()}})()}setupHardwareClipping(t,e){const s=t.length;return e.enableHardwareClipping(s),z(()=>{const i=He(t).setGroup(Xt),n=_r(e.getClipDistance());Zs(s,({i:o})=>{const a=i.element(o),h=Ot.dot(a.xyz).sub(a.w).negate();n.element(o).assign(h)})})()}}ie.ALPHA_TO_COVERAGE="alphaToCoverage";ie.DEFAULT="default";ie.HARDWARE="hardware";const _y=()=>new ie,Ty=()=>new ie(ie.ALPHA_TO_COVERAGE),vy=()=>new ie(ie.HARDWARE),Cy=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","lightMapIntensity","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"],qr=new WeakMap;class by{constructor(t){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(t),this.hasAnimation=t.object.isSkinnedMesh===!0,this.refreshUniforms=Cy,this.renderId=0}firstInitialization(t){return this.renderObjects.has(t)===!1?(this.getRenderObjectData(t),!0):!1}needsVelocity(t){const e=t.getMRT();return e!==null&&e.has("velocity")}getRenderObjectData(t){let e=this.renderObjects.get(t);if(e===void 0){const{geometry:s,material:i,object:n}=t;if(e={material:this.getMaterialData(i),geometry:{id:s.id,attributes:this.getAttributesData(s.attributes),indexId:s.index?s.index.id:null,indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:n.matrixWorld.clone()},n.center&&(e.center=n.center.clone()),n.morphTargetInfluences&&(e.morphTargetInfluences=n.morphTargetInfluences.slice()),t.bundle!==null&&(e.version=t.bundle.version),e.material.transmission>0){const{width:o,height:a}=t.context;e.bufferWidth=o,e.bufferHeight=a}e.lights=this.getLightsData(t.lightsNode.getLights()),this.renderObjects.set(t,e)}return e}getAttributesData(t){const e={};for(const s in t){const i=t[s];e[s]={id:i.id,version:i.version}}return e}containsNode(t){const e=t.material;for(const s in e)if(e[s]&&e[s].isNode)return!0;return!!(t.context.modelViewMatrix||t.context.modelNormalViewMatrix||t.context.getAO||t.context.getShadow)}getMaterialData(t){const e={};for(const s of this.refreshUniforms){const i=t[s];i!=null&&(typeof i=="object"&&i.clone!==void 0?i.isTexture===!0?e[s]={id:i.id,version:i.version}:e[s]=i.clone():e[s]=i)}return e}equals(t,e){const{object:s,material:i,geometry:n}=t,o=this.getRenderObjectData(t);if(o.worldMatrix.equals(s.matrixWorld)!==!0)return o.worldMatrix.copy(s.matrixWorld),!1;const a=o.material;for(const x in a){const C=a[x],b=i[x];if(C.equals!==void 0){if(C.equals(b)===!1)return C.copy(b),!1}else if(b.isTexture===!0){if(C.id!==b.id||C.version!==b.version)return C.id=b.id,C.version=b.version,!1}else if(C!==b)return a[x]=b,!1}if(a.transmission>0){const{width:x,height:C}=t.context;if(o.bufferWidth!==x||o.bufferHeight!==C)return o.bufferWidth=x,o.bufferHeight=C,!1}const h=o.geometry,l=n.attributes,c=h.attributes,u=Object.keys(c),d=Object.keys(l);if(h.id!==n.id)return h.id=n.id,!1;if(u.length!==d.length)return o.geometry.attributes=this.getAttributesData(l),!1;for(const x of u){const C=c[x],b=l[x];if(b===void 0)return delete c[x],!1;if(C.id!==b.id||C.version!==b.version)return C.id=b.id,C.version=b.version,!1}const p=n.index,m=h.indexId,f=h.indexVersion,y=p?p.id:null,g=p?p.version:null;if(m!==y||f!==g)return h.indexId=y,h.indexVersion=g,!1;if(h.drawRange.start!==n.drawRange.start||h.drawRange.count!==n.drawRange.count)return h.drawRange.start=n.drawRange.start,h.drawRange.count=n.drawRange.count,!1;if(o.morphTargetInfluences){let x=!1;for(let C=0;C<o.morphTargetInfluences.length;C++)o.morphTargetInfluences[C]!==s.morphTargetInfluences[C]&&(o.morphTargetInfluences[C]=s.morphTargetInfluences[C],x=!0);if(x)return!1}if(o.lights){for(let x=0;x<e.length;x++)if(o.lights[x].map!==e[x].map)return!1}return o.center&&o.center.equals(s.center)===!1?(o.center.copy(s.center),!0):(t.bundle!==null&&(o.version=t.bundle.version),!0)}getLightsData(t){const e=[];for(const s of t)s.isSpotLight===!0&&s.map!==null&&e.push({map:s.map.version});return e}getLights(t,e){if(qr.has(t)){const i=qr.get(t);if(i.renderId===e)return i.lightsData}const s=this.getLightsData(t.getLights());return qr.set(t,{renderId:e,lightsData:s}),s}needsRefresh(t,e){if(this.hasNode||this.hasAnimation||this.firstInitialization(t)||this.needsVelocity(e.renderer))return!0;const{renderId:s}=e;if(this.renderId!==s)return this.renderId=s,!0;const i=t.object.static===!0,n=t.bundle!==null&&t.bundle.static===!0&&this.getRenderObjectData(t).version===t.bundle.version;if(i||n)return!1;const o=this.getLights(t.lightsNode,s);return this.equals(t,o)!==!0}}const wy=.05,Sh=z(([r])=>ri(Ht(1e4,Xi(Ht(17,r.x).add(Ht(.1,r.y)))).mul($i(.1,yr(Xi(Ht(13,r.y).add(r.x))))))),Mh=z(([r])=>Sh(Ce(Sh(r.xy),r.z))),Sy=z(([r])=>{const t=ql(Eo(Yl(r.xyz)),Eo($l(r.xyz))),e=K(1).div(K(wy).mul(t)).toVar("pixScale"),s=Ce(Ao($n(Ks(e))),Ao(Vl(Ks(e)))),i=Ce(Mh($n(s.x.mul(r.xyz))),Mh($n(s.y.mul(r.xyz)))),n=ri(Ks(e)),o=$i(Ht(n.oneMinus(),i.x),Ht(n,i.y)),a=Zl(n,n.oneMinus()),h=H(o.mul(o).div(Ht(2,a).mul(Ve(1,a))),o.sub(Ht(.5,a)).div(Ve(1,a)),Ve(1,Ve(1,o).mul(Ve(1,o)).div(Ht(2,a).mul(Ve(1,a))))),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(h.x,h.y),h.z);return Zo(l,1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class My extends uc{static get type(){return"VertexColorNode"}constructor(t){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),s=t.hasGeometryAttribute(e);let i;return s===!0?i=super.generate(t):i=t.generateConst(this.nodeType,new Wt(1,1,1,1)),i}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const Ny=(r=0)=>new My(r),Ay=z(([r])=>Nt(r.rgb.mul(r.a),r.a),{color:"vec4",return:"vec4"});class Bc extends So{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(t){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){const t=[];for(const e of Object.getOwnPropertyNames(this)){if(e.startsWith("_")===!0)continue;const s=this[e];s&&s.isNode===!0&&t.push({property:e,childNode:s})}return t}customProgramCacheKey(){const t=[];for(const{property:e,childNode:s}of this._getNodeChildren())t.push(ko(e.slice(0,-4)),s.getCacheKey());return this.type+Nl(t)}build(t){this.setup(t)}setupObserver(t){return new by(t)}setup(t){t.context.setupNormal=()=>Ui(this.setupNormal(t),"NORMAL","vec3"),t.context.setupPositionView=()=>this.setupPositionView(t),t.context.setupModelViewProjection=()=>this.setupModelViewProjection(t);const e=t.renderer,s=e.getRenderTarget();e.contextNode.isContextNode===!0?t.context={...t.context,...e.contextNode.getFlowContextData()}:rt('NodeMaterial: "renderer.contextNode" must be an instance of `context()`.'),this.contextNode!==null&&(this.contextNode.isContextNode===!0?t.context={...t.context,...this.contextNode.getFlowContextData()}:rt('NodeMaterial: "material.contextNode" must be an instance of `context()`.')),t.addStack();const i=this.setupVertex(t),n=Ui(this.vertexNode||i,"VERTEX");t.context.clipSpace=n,t.stack.outputNode=n,this.setupHardwareClipping(t),this.geometryNode!==null&&(t.stack.outputNode=t.stack.outputNode.bypass(this.geometryNode)),t.addFlow("vertex",t.removeStack()),t.addStack();let o;const a=this.setupClipping(t);if((this.depthWrite===!0||this.depthTest===!0)&&(s!==null?s.depthBuffer===!0&&this.setupDepth(t):e.depth===!0&&this.setupDepth(t)),this.fragmentNode===null){this.setupDiffuseColor(t),this.setupVariants(t);const h=this.setupLighting(t);a!==null&&t.stack.addToStack(a);const l=Nt(h,Bt.a).max(0);o=this.setupOutput(t,l),ki.assign(o);const c=this.outputNode!==null;if(c&&(o=this.outputNode),t.context.getOutput&&(o=t.context.getOutput(o,t)),s!==null){const u=e.getMRT(),d=this.mrtNode;u!==null?(c&&ki.assign(o),o=u,d!==null&&(o=u.merge(d))):d!==null&&(o=d)}}else{let h=this.fragmentNode;h.isOutputStructNode!==!0&&(h=Nt(h)),o=this.setupOutput(t,h)}t.stack.outputNode=o,t.addFlow("fragment",t.removeStack()),t.observer=this.setupObserver(t)}setupClipping(t){if(t.clippingContext===null)return null;const{unionPlanes:e,intersectionPlanes:s}=t.clippingContext;let i=null;if(e.length>0||s.length>0){const n=t.renderer.currentSamples;this.alphaToCoverage&&n>1?i=Ty():t.stack.addToStack(_y())}return i}setupHardwareClipping(t){if(this.hardwareClipping=!1,t.clippingContext===null)return;const e=t.clippingContext.unionPlanes.length;e>0&&e<=8&&t.isAvailable("clipDistance")&&(t.stack.addToStack(vy()),this.hardwareClipping=!0)}setupDepth(t){const{renderer:e,camera:s}=t;let i=this.depthNode;if(i===null){const n=e.getMRT();n&&n.has("depth")?i=n.get("depth"):e.logarithmicDepthBuffer===!0&&(s.isPerspectiveCamera?i=xy(Ot.z,_s,Ts):i=ji(Ot.z,_s,Ts))}i!==null&&zc.assign(i).toStack()}setupPositionView(){return gc.mul(jt).xyz}setupModelViewProjection(){return tg.mul(Ot)}setupVertex(t){return t.addStack(),this.setupPosition(t),t.context.position=t.removeStack(),jg}setupPosition(t){const{object:e,geometry:s}=t;if((s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&hy(e).toStack(),e.isSkinnedMesh===!0&&iy(e).toStack(),this.displacementMap){const i=Xs("displacementMap","texture"),n=Xs("displacementScale","float"),o=Xs("displacementBias","float");jt.addAssign(Pe.normalize().mul(i.x.mul(n).add(o)))}return e.isBatchedMesh&&ey(e).toStack(),e.isInstancedMesh&&e.instanceMatrix&&e.instanceMatrix.isInstancedBufferAttribute===!0&&Kg(e).toStack(),this.positionNode!==null&&jt.assign(Ui(this.positionNode,"POSITION","vec3")),jt}setupDiffuseColor(t){const{object:e,geometry:s}=t;this.maskNode!==null&&Yo(this.maskNode).not().discard();let i=this.colorNode?Nt(this.colorNode):Bg;this.vertexColors===!0&&s.hasAttribute("color")&&(i=i.mul(Ny())),e.instanceColor&&(i=rr("vec3","vInstanceColor").mul(i)),e.isBatchedMesh&&e._colorsTexture&&(i=rr("vec3","vBatchColor").mul(i)),Bt.assign(i);const n=this.opacityNode?K(this.opacityNode):Ug;Bt.a.assign(Bt.a.mul(n));let o=null;(this.alphaTestNode!==null||this.alphaTest>0)&&(o=this.alphaTestNode!==null?K(this.alphaTestNode):Dg,this.alphaToCoverage===!0?(Bt.a=ai(o,o.add(Xl(Bt.a)),Bt.a),Bt.a.lessThanEqual(0).discard()):Bt.a.lessThanEqual(o).discard()),this.alphaHash===!0&&Bt.a.lessThan(Sy(jt)).discard(),t.isOpaque()&&Bt.a.assign(1)}setupVariants(){}setupOutgoingLight(){return this.lights===!0?H(0):Bt.rgb}setupNormal(){return this.normalNode?H(this.normalNode):Vg}setupEnvironment(){let t=null;return this.envNode?t=this.envNode:this.envMap&&(t=this.envMap.isCubeTexture?Xs("envMap","cubeTexture"):Xs("envMap","texture")),t}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new dy(Pc)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);const i=this.setupLightMap(t);i&&i.isLightingNode&&e.push(i);let n=this.aoNode;n===null&&t.material.aoMap&&(n=Hg),t.context.getAO&&(n=t.context.getAO(n,t)),n&&e.push(new ly(n));let o=this.lightsNode||t.lightsNode;return e.length>0&&(o=t.renderer.lighting.createNode([...o.getLights(),...e])),o}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:n}=this,a=this.lights===!0||this.lightsNode!==null?this.setupLights(t):null;let h=this.setupOutgoingLight(t);if(a&&a.getScope().hasLights){const l=this.setupLightingModel(t)||null;h=uy(a,l,s,i)}else s!==null&&(h=H(i!==null?oi(h,s,i):s));return(n&&n.isNode===!0||e.emissive&&e.emissive.isColor===!0)&&(rh.assign(H(n||kg)),h=h.add(rh)),h}setupFog(t,e){const s=t.fogNode;return s&&(ki.assign(e),e=Nt(s.toVar())),e}setupPremultipliedAlpha(t,e){return Ay(e)}setupOutput(t,e){return this.fog===!0&&(e=this.setupFog(t,e)),this.premultipliedAlpha===!0&&(e=this.setupPremultipliedAlpha(t,e)),e}setDefaultValues(t){for(const s in t){const i=t[s];this[s]===void 0&&(this[s]=i,i&&i.clone&&(this[s]=i.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const s in e)Object.getOwnPropertyDescriptor(this.constructor.prototype,s)===void 0&&e[s].get!==void 0&&Object.defineProperty(this.constructor.prototype,s,e[s])}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{},nodes:{}});const s=So.prototype.toJSON.call(this,t);s.inputNodes={};for(const{property:n,childNode:o}of this._getNodeChildren())s.inputNodes[n]=o.toJSON(t).uuid;function i(n){const o=[];for(const a in n){const h=n[a];delete h.metadata,o.push(h)}return o}if(e){const n=i(t.textures),o=i(t.images),a=i(t.nodes);n.length>0&&(s.textures=n),o.length>0&&(s.images=o),a.length>0&&(s.nodes=a)}return s}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.aoNode=t.aoNode,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.maskNode=t.maskNode,this.maskShadowNode=t.maskShadowNode,this.positionNode=t.positionNode,this.geometryNode=t.geometryNode,this.depthNode=t.depthNode,this.receivedShadowPositionNode=t.receivedShadowPositionNode,this.castShadowPositionNode=t.castShadowPositionNode,this.receivedShadowNode=t.receivedShadowNode,this.castShadowNode=t.castShadowNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,this.contextNode=t.contextNode,super.copy(t)}}const Ey=z(([r=xc])=>{const t=r.z.atan(r.x).mul(1/(Math.PI*2)).add(.5),e=r.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Ce(t,e)});class ca extends li{constructor(t=1,e=1,s={}){super(),s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Jn,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},s),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=s.depth,this.scissor=new Wt(0,0,t,e),this.scissorTest=!1,this.viewport=new Wt(0,0,t,e),this.textures=[];const i={width:t,height:e,depth:s.depth},n=new te(i),o=s.count;for(let a=0;a<o;a++)this.textures[a]=n.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this._setTextureOptions(s),this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=s.depthTexture,this.samples=s.samples,this.multiview=s.multiview}_setTextureOptions(t={}){const e={minFilter:Jn,generateMipmaps:!1,flipY:!1,internalFormat:null};t.mapping!==void 0&&(e.mapping=t.mapping),t.wrapS!==void 0&&(e.wrapS=t.wrapS),t.wrapT!==void 0&&(e.wrapT=t.wrapT),t.wrapR!==void 0&&(e.wrapR=t.wrapR),t.magFilter!==void 0&&(e.magFilter=t.magFilter),t.minFilter!==void 0&&(e.minFilter=t.minFilter),t.format!==void 0&&(e.format=t.format),t.type!==void 0&&(e.type=t.type),t.anisotropy!==void 0&&(e.anisotropy=t.anisotropy),t.colorSpace!==void 0&&(e.colorSpace=t.colorSpace),t.flipY!==void 0&&(e.flipY=t.flipY),t.generateMipmaps!==void 0&&(e.generateMipmaps=t.generateMipmaps),t.internalFormat!==void 0&&(e.internalFormat=t.internalFormat);for(let s=0;s<this.textures.length;s++)this.textures[s].setValues(e)}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}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,n=this.textures.length;i<n;i++)this.textures[i].image.width=t,this.textures[i].image.height=e,this.textures[i].image.depth=s,this.textures[i].isData3DTexture!==!0&&(this.textures[i].isArrayTexture=this.textures[i].image.depth>1);this.dispose()}this.viewport.set(0,0,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,this.textures[e].renderTarget=this;const i=Object.assign({},t.textures[e].image);this.textures[e].source=new ea(i)}return this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Oy{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(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let Ry=0;const Nh=new M,ks=new ci,De=new Rt,An=new M,Mi=new M,Iy=new M,Py=new ci,Ah=new M(1,0,0),Eh=new M(0,1,0),Oh=new M(0,0,1),Rh={type:"added"},Ly={type:"removed"},Us={type:"childadded",child:null},Qr={type:"childremoved",child:null};class ne extends li{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Ry++}),this.uuid=Ge(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=ne.DEFAULT_UP.clone();const t=new M,e=new hs,s=new ci,i=new M(1,1,1);function n(){s.setFromEuler(e,!1)}function o(){e.setFromQuaternion(s,void 0,!1)}e._onChange(n),s._onChange(o),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 Rt},normalMatrix:{value:new he}}),this.matrix=new Rt,this.matrixWorld=new Rt,this.matrixAutoUpdate=ne.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=ne.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Oy,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(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 ks.setFromAxisAngle(t,e),this.quaternion.multiply(ks),this}rotateOnWorldAxis(t,e){return ks.setFromAxisAngle(t,e),this.quaternion.premultiply(ks),this}rotateX(t){return this.rotateOnAxis(Ah,t)}rotateY(t){return this.rotateOnAxis(Eh,t)}rotateZ(t){return this.rotateOnAxis(Oh,t)}translateOnAxis(t,e){return Nh.copy(t).applyQuaternion(this.quaternion),this.position.add(Nh.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Ah,t)}translateY(t){return this.translateOnAxis(Eh,t)}translateZ(t){return this.translateOnAxis(Oh,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(De.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?An.copy(t):An.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),Mi.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?De.lookAt(Mi,An,this.up):De.lookAt(An,Mi,this.up),this.quaternion.setFromRotationMatrix(De),i&&(De.extractRotation(i.matrixWorld),ks.setFromRotationMatrix(De),this.quaternion.premultiply(ks.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(rt("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(Rh),Us.child=t,this.dispatchEvent(Us),Us.child=null):rt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Ly),Qr.child=t,this.dispatchEvent(Qr),Qr.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),De.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),De.multiply(t.parent.matrixWorld)),t.applyMatrix4(De),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Rh),Us.child=t,this.dispatchEvent(Us),Us.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 o=this.children[s].getObjectByProperty(t,e);if(o!==void 0)return o}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const i=this.children;for(let n=0,o=i.length;n<o;n++)i[n].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(Mi,t,Iy),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Mi,Py,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(this.visible===!1)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;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,s=t.y,i=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*s-n[8]*i,n[13]+=s-n[1]*e-n[5]*s-n[9]*i,n[14]+=i-n[2]*e-n[6]*s-n[10]*i}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?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(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const i=this.children;for(let n=0,o=i.length;n<o;n++)i[n].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),this.static!==!1&&(i.static=this.static),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.pivot!==null&&(i.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function n(a,h){return a[h.uuid]===void 0&&(a[h.uuid]=h.toJSON(t)),h.uuid}if(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&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const h=a.shapes;if(Array.isArray(h))for(let l=0,c=h.length;l<c;l++){const u=h[l];n(t.shapes,u)}else n(t.shapes,h)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let h=0,l=this.material.length;h<l;h++)a.push(n(t.materials,this.material[h]));i.material=a}else i.material=n(t.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){const h=this.animations[a];i.animations.push(n(t.animations,h))}}if(e){const a=o(t.geometries),h=o(t.materials),l=o(t.textures),c=o(t.images),u=o(t.shapes),d=o(t.skeletons),p=o(t.animations),m=o(t.nodes);a.length>0&&(s.geometries=a),h.length>0&&(s.materials=h),l.length>0&&(s.textures=l),c.length>0&&(s.images=c),u.length>0&&(s.shapes=u),d.length>0&&(s.skeletons=d),p.length>0&&(s.animations=p),m.length>0&&(s.nodes=m)}return s.object=i,s;function o(a){const h=[];for(const l in a){const c=a[l];delete c.metadata,h.push(c)}return h}}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),t.pivot!==null&&(this.pivot=t.pivot.clone()),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.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let s=0;s<t.children.length;s++){const i=t.children[s];this.add(i.clone())}return this}}ne.DEFAULT_UP=new M(0,1,0);ne.DEFAULT_MATRIX_AUTO_UPDATE=!0;ne.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class Fy extends ne{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 hs,this.environmentIntensity=1,this.environmentRotation=new hs,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(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),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}const En=new M,On=new ci,Ae=new M;class zy extends ne{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Rt,this.projectionMatrix=new Rt,this.projectionMatrixInverse=new Rt,this.coordinateSystem=je,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}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.matrixWorld.decompose(En,On,Ae),Ae.x===1&&Ae.y===1&&Ae.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(En,On,Ae.set(1,1,1)).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorld.decompose(En,On,Ae),Ae.x===1&&Ae.y===1&&Ae.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(En,On,Ae.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const Je=new M,Ih=new _t,Ph=new _t;class Vs extends zy{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=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=tr*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(zi*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return tr*2*Math.atan(Math.tan(zi*.5*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){Je.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Je.x,Je.y).multiplyScalar(-t/Je.z),Je.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Je.x,Je.y).multiplyScalar(-t/Je.z)}getViewSize(t,e){return this.getViewBounds(t,Ih,Ph),e.subVectors(Ph,Ih)}setViewOffset(t,e,s,i,n,o){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=n,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(zi*.5*this.fov)/this.zoom,s=2*e,i=this.aspect*s,n=-.5*i;const o=this.view;if(this.view!==null&&this.view.enabled){const h=o.fullWidth,l=o.fullHeight;n+=o.offsetX*i/h,e-=o.offsetY*s/l,i*=o.width/h,s*=o.height/l}const a=this.filmOffset;a!==0&&(n+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(n,n+i,e,e-s,t,this.far,this.coordinateSystem,this.reversedDepth),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,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Hs=-90,js=1;class Dy extends ne{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Vs(Hs,js,t,e);i.layers=this.layers,this.add(i);const n=new Vs(Hs,js,t,e);n.layers=this.layers,this.add(n);const o=new Vs(Hs,js,t,e);o.layers=this.layers,this.add(o);const a=new Vs(Hs,js,t,e);a.layers=this.layers,this.add(a);const h=new Vs(Hs,js,t,e);h.layers=this.layers,this.add(h);const l=new Vs(Hs,js,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,n,o,a,h]=e;for(const l of e)this.remove(l);if(t===je)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),n.up.set(0,0,-1),n.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),h.up.set(0,1,0),h.lookAt(0,0,-1);else if(t===ni)s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),n.up.set(0,0,1),n.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),h.up.set(0,-1,0),h.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[n,o,a,h,l,c]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),p=t.getActiveMipmapLevel(),m=t.xr.enabled;t.xr.enabled=!1;const f=s.texture.generateMipmaps;s.texture.generateMipmaps=!1;let y=!1;t.isWebGLRenderer===!0?y=t.state.buffers.depth.getReversed():y=t.reversedDepthBuffer,t.setRenderTarget(s,0,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,n),t.setRenderTarget(s,1,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,o),t.setRenderTarget(s,2,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,a),t.setRenderTarget(s,3,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,h),t.setRenderTarget(s,4,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,l),s.texture.generateMipmaps=f,t.setRenderTarget(s,5,i),y&&t.autoClear===!1&&t.clearDepth(),t.render(e,c),t.setRenderTarget(u,d,p),t.xr.enabled=m,s.texture.needsPMREMUpdate=!0}}let By=0;const se=new Rt,Jr=new ne,Ws=new M,Jt=new nn,Ni=new nn,Et=new M;class Cr extends li{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:By++}),this.uuid=Ge(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(pd(t)?Mf:Sf)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}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 this.attributes[t]!==void 0}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;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(s!==void 0){const n=new he().getNormalMatrix(t);s.applyNormalMatrix(n),s.needsUpdate=!0}const i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(t),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return se.makeRotationFromQuaternion(t),this.applyMatrix4(se),this}rotateX(t){return se.makeRotationX(t),this.applyMatrix4(se),this}rotateY(t){return se.makeRotationY(t),this.applyMatrix4(se),this}rotateZ(t){return se.makeRotationZ(t),this.applyMatrix4(se),this}translate(t,e,s){return se.makeTranslation(t,e,s),this.applyMatrix4(se),this}scale(t,e,s){return se.makeScale(t,e,s),this.applyMatrix4(se),this}lookAt(t){return Jr.lookAt(t),Jr.updateMatrix(),this.applyMatrix4(Jr.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ws).negate(),this.translate(Ws.x,Ws.y,Ws.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const s=[];for(let i=0,n=t.length;i<n;i++){const o=t[i];s.push(o.x,o.y,o.z||0)}this.setAttribute("position",new Xn(s,3))}else{const s=Math.min(t.length,e.count);for(let i=0;i<s;i++){const n=t[i];e.setXYZ(i,n.x,n.y,n.z||0)}t.length>e.count&&W("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new nn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){rt("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new M(-1/0,-1/0,-1/0),new M(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let s=0,i=e.length;s<i;s++){const n=e[s];Jt.setFromBufferAttribute(n),this.morphTargetsRelative?(Et.addVectors(this.boundingBox.min,Jt.min),this.boundingBox.expandByPoint(Et),Et.addVectors(this.boundingBox.max,Jt.max),this.boundingBox.expandByPoint(Et)):(this.boundingBox.expandByPoint(Jt.min),this.boundingBox.expandByPoint(Jt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&rt('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new oa);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){rt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new M,1/0);return}if(t){const s=this.boundingSphere.center;if(Jt.setFromBufferAttribute(t),e)for(let n=0,o=e.length;n<o;n++){const a=e[n];Ni.setFromBufferAttribute(a),this.morphTargetsRelative?(Et.addVectors(Jt.min,Ni.min),Jt.expandByPoint(Et),Et.addVectors(Jt.max,Ni.max),Jt.expandByPoint(Et)):(Jt.expandByPoint(Ni.min),Jt.expandByPoint(Ni.max))}Jt.getCenter(s);let i=0;for(let n=0,o=t.count;n<o;n++)Et.fromBufferAttribute(t,n),i=Math.max(i,s.distanceToSquared(Et));if(e)for(let n=0,o=e.length;n<o;n++){const a=e[n],h=this.morphTargetsRelative;for(let l=0,c=a.count;l<c;l++)Et.fromBufferAttribute(a,l),h&&(Ws.fromBufferAttribute(t,l),Et.add(Ws)),i=Math.max(i,s.distanceToSquared(Et))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&rt('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(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){rt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const s=e.position,i=e.normal,n=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new os(new Float32Array(4*s.count),4));const o=this.getAttribute("tangent"),a=[],h=[];for(let O=0;O<s.count;O++)a[O]=new M,h[O]=new M;const l=new M,c=new M,u=new M,d=new _t,p=new _t,m=new _t,f=new M,y=new M;function g(O,P,k){l.fromBufferAttribute(s,O),c.fromBufferAttribute(s,P),u.fromBufferAttribute(s,k),d.fromBufferAttribute(n,O),p.fromBufferAttribute(n,P),m.fromBufferAttribute(n,k),c.sub(l),u.sub(l),p.sub(d),m.sub(d);const $=1/(p.x*m.y-m.x*p.y);isFinite($)&&(f.copy(c).multiplyScalar(m.y).addScaledVector(u,-p.y).multiplyScalar($),y.copy(u).multiplyScalar(p.x).addScaledVector(c,-m.x).multiplyScalar($),a[O].add(f),a[P].add(f),a[k].add(f),h[O].add(y),h[P].add(y),h[k].add(y))}let x=this.groups;x.length===0&&(x=[{start:0,count:t.count}]);for(let O=0,P=x.length;O<P;++O){const k=x[O],$=k.start,ct=k.count;for(let tt=$,it=$+ct;tt<it;tt+=3)g(t.getX(tt+0),t.getX(tt+1),t.getX(tt+2))}const C=new M,b=new M,A=new M,N=new M;function E(O){A.fromBufferAttribute(i,O),N.copy(A);const P=a[O];C.copy(P),C.sub(A.multiplyScalar(A.dot(P))).normalize(),b.crossVectors(N,P);const $=b.dot(h[O])<0?-1:1;o.setXYZW(O,C.x,C.y,C.z,$)}for(let O=0,P=x.length;O<P;++O){const k=x[O],$=k.start,ct=k.count;for(let tt=$,it=$+ct;tt<it;tt+=3)E(t.getX(tt+0)),E(t.getX(tt+1)),E(t.getX(tt+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let s=this.getAttribute("normal");if(s===void 0)s=new os(new Float32Array(e.count*3),3),this.setAttribute("normal",s);else for(let d=0,p=s.count;d<p;d++)s.setXYZ(d,0,0,0);const i=new M,n=new M,o=new M,a=new M,h=new M,l=new M,c=new M,u=new M;if(t)for(let d=0,p=t.count;d<p;d+=3){const m=t.getX(d+0),f=t.getX(d+1),y=t.getX(d+2);i.fromBufferAttribute(e,m),n.fromBufferAttribute(e,f),o.fromBufferAttribute(e,y),c.subVectors(o,n),u.subVectors(i,n),c.cross(u),a.fromBufferAttribute(s,m),h.fromBufferAttribute(s,f),l.fromBufferAttribute(s,y),a.add(c),h.add(c),l.add(c),s.setXYZ(m,a.x,a.y,a.z),s.setXYZ(f,h.x,h.y,h.z),s.setXYZ(y,l.x,l.y,l.z)}else for(let d=0,p=e.count;d<p;d+=3)i.fromBufferAttribute(e,d+0),n.fromBufferAttribute(e,d+1),o.fromBufferAttribute(e,d+2),c.subVectors(o,n),u.subVectors(i,n),c.cross(u),s.setXYZ(d+0,c.x,c.y,c.z),s.setXYZ(d+1,c.x,c.y,c.z),s.setXYZ(d+2,c.x,c.y,c.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)Et.fromBufferAttribute(t,e),Et.normalize(),t.setXYZ(e,Et.x,Et.y,Et.z)}toNonIndexed(){function t(a,h){const l=a.array,c=a.itemSize,u=a.normalized,d=new l.constructor(h.length*c);let p=0,m=0;for(let f=0,y=h.length;f<y;f++){a.isInterleavedBufferAttribute?p=h[f]*a.data.stride+a.offset:p=h[f]*c;for(let g=0;g<c;g++)d[m++]=l[p++]}return new os(d,c,u)}if(this.index===null)return W("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Cr,s=this.index.array,i=this.attributes;for(const a in i){const h=i[a],l=t(h,s);e.setAttribute(a,l)}const n=this.morphAttributes;for(const a in n){const h=[],l=n[a];for(let c=0,u=l.length;c<u;c++){const d=l[c],p=t(d,s);h.push(p)}e.morphAttributes[a]=h}e.morphTargetsRelative=this.morphTargetsRelative;const o=this.groups;for(let a=0,h=o.length;a<h;a++){const l=o[a];e.addGroup(l.start,l.count,l.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,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),this.parameters!==void 0){const h=this.parameters;for(const l in h)h[l]!==void 0&&(t[l]=h[l]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const h in s){const l=s[h];t.data.attributes[h]=l.toJSON(t.data)}const i={};let n=!1;for(const h in this.morphAttributes){const l=this.morphAttributes[h],c=[];for(let u=0,d=l.length;u<d;u++){const p=l[u];c.push(p.toJSON(t.data))}c.length>0&&(i[h]=c,n=!0)}n&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(t.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),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;s!==null&&this.setIndex(s.clone());const i=t.attributes;for(const l in i){const c=i[l];this.setAttribute(l,c.clone(e))}const n=t.morphAttributes;for(const l in n){const c=[],u=n[l];for(let d=0,p=u.length;d<p;d++)c.push(u[d].clone(e));this.morphAttributes[l]=c}this.morphTargetsRelative=t.morphTargetsRelative;const o=t.groups;for(let l=0,c=o.length;l<c;l++){const u=o[l];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const h=t.boundingSphere;return h!==null&&(this.boundingSphere=h.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ua extends Cr{constructor(t=1,e=1,s=1,i=1,n=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:n,depthSegments:o};const a=this;i=Math.floor(i),n=Math.floor(n),o=Math.floor(o);const h=[],l=[],c=[],u=[];let d=0,p=0;m("z","y","x",-1,-1,s,e,t,o,n,0),m("z","y","x",1,-1,s,e,-t,o,n,1),m("x","z","y",1,1,t,s,e,i,o,2),m("x","z","y",1,-1,t,s,-e,i,o,3),m("x","y","z",1,-1,t,e,s,i,n,4),m("x","y","z",-1,-1,t,e,-s,i,n,5),this.setIndex(h),this.setAttribute("position",new Xn(l,3)),this.setAttribute("normal",new Xn(c,3)),this.setAttribute("uv",new Xn(u,2));function m(f,y,g,x,C,b,A,N,E,O,P){const k=b/E,$=A/O,ct=b/2,tt=A/2,it=N/2,j=E+1,le=O+1;let Ct=0,Ut=0;const Q=new M;for(let gt=0;gt<le;gt++){const At=gt*$-tt;for(let ce=0;ce<j;ce++){const Ss=ce*k-ct;Q[f]=Ss*x,Q[y]=At*C,Q[g]=it,l.push(Q.x,Q.y,Q.z),Q[f]=0,Q[y]=0,Q[g]=N>0?1:-1,c.push(Q.x,Q.y,Q.z),u.push(ce/E),u.push(1-gt/O),Ct+=1}}for(let gt=0;gt<O;gt++)for(let At=0;At<E;At++){const ce=d+At+j*gt,Ss=d+At+j*(gt+1),on=d+(At+1)+j*(gt+1),pa=d+(At+1)+j*gt;h.push(ce,Ss,pa),h.push(Ss,on,pa),Ut+=6}a.addGroup(p,Ut,P),p+=Ut,d+=Ct}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ua(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}const Be=new M,Kr=new M,Rn=new M,Ke=new M,to=new M,In=new M,eo=new M;class ky{constructor(t=new M,e=new M(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,Be)),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=Be.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Be.copy(this.origin).addScaledVector(this.direction,e),Be.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Kr.copy(t).add(e).multiplyScalar(.5),Rn.copy(e).sub(t).normalize(),Ke.copy(this.origin).sub(Kr);const n=t.distanceTo(e)*.5,o=-this.direction.dot(Rn),a=Ke.dot(this.direction),h=-Ke.dot(Rn),l=Ke.lengthSq(),c=Math.abs(1-o*o);let u,d,p,m;if(c>0)if(u=o*h-a,d=o*a-h,m=n*c,u>=0)if(d>=-m)if(d<=m){const f=1/c;u*=f,d*=f,p=u*(u+o*d+2*a)+d*(o*u+d+2*h)+l}else d=n,u=Math.max(0,-(o*d+a)),p=-u*u+d*(d+2*h)+l;else d=-n,u=Math.max(0,-(o*d+a)),p=-u*u+d*(d+2*h)+l;else d<=-m?(u=Math.max(0,-(-o*n+a)),d=u>0?-n:Math.min(Math.max(-n,-h),n),p=-u*u+d*(d+2*h)+l):d<=m?(u=0,d=Math.min(Math.max(-n,-h),n),p=d*(d+2*h)+l):(u=Math.max(0,-(o*n+a)),d=u>0?n:Math.min(Math.max(-n,-h),n),p=-u*u+d*(d+2*h)+l);else d=o>0?-n:n,u=Math.max(0,-(o*d+a)),p=-u*u+d*(d+2*h)+l;return s&&s.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(Kr).addScaledVector(Rn,d),p}intersectSphere(t,e){Be.subVectors(t.center,this.origin);const s=Be.dot(this.direction),i=Be.dot(Be)-s*s,n=t.radius*t.radius;if(i>n)return null;const o=Math.sqrt(n-i),a=s-o,h=s+o;return h<0?null:a<0?this.at(h,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?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 s===null?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,n,o,a,h;const l=1/this.direction.x,c=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(s=(t.min.x-d.x)*l,i=(t.max.x-d.x)*l):(s=(t.max.x-d.x)*l,i=(t.min.x-d.x)*l),c>=0?(n=(t.min.y-d.y)*c,o=(t.max.y-d.y)*c):(n=(t.max.y-d.y)*c,o=(t.min.y-d.y)*c),s>o||n>i||((n>s||isNaN(s))&&(s=n),(o<i||isNaN(i))&&(i=o),u>=0?(a=(t.min.z-d.z)*u,h=(t.max.z-d.z)*u):(a=(t.max.z-d.z)*u,h=(t.min.z-d.z)*u),s>h||a>i)||((a>s||s!==s)&&(s=a),(h<i||i!==i)&&(i=h),i<0)?null:this.at(s>=0?s:i,e)}intersectsBox(t){return this.intersectBox(t,Be)!==null}intersectTriangle(t,e,s,i,n){to.subVectors(e,t),In.subVectors(s,t),eo.crossVectors(to,In);let o=this.direction.dot(eo),a;if(o>0){if(i)return null;a=1}else if(o<0)a=-1,o=-o;else return null;Ke.subVectors(this.origin,t);const h=a*this.direction.dot(In.crossVectors(Ke,In));if(h<0)return null;const l=a*this.direction.dot(to.cross(Ke));if(l<0||h+l>o)return null;const c=-a*Ke.dot(eo);return c<0?null:this.at(c/o,n)}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)}}const pe=new M,ke=new M,so=new M,Ue=new M,Gs=new M,Ys=new M,Lh=new M,io=new M,no=new M,ro=new M,oo=new Wt,ao=new Wt,ho=new Wt;class ve{constructor(t=new M,e=new M,s=new M){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),pe.subVectors(t,e),i.cross(pe);const n=i.lengthSq();return n>0?i.multiplyScalar(1/Math.sqrt(n)):i.set(0,0,0)}static getBarycoord(t,e,s,i,n){pe.subVectors(i,e),ke.subVectors(s,e),so.subVectors(t,e);const o=pe.dot(pe),a=pe.dot(ke),h=pe.dot(so),l=ke.dot(ke),c=ke.dot(so),u=o*l-a*a;if(u===0)return n.set(0,0,0),null;const d=1/u,p=(l*h-a*c)*d,m=(o*c-a*h)*d;return n.set(1-p-m,m,p)}static containsPoint(t,e,s,i){return this.getBarycoord(t,e,s,i,Ue)===null?!1:Ue.x>=0&&Ue.y>=0&&Ue.x+Ue.y<=1}static getInterpolation(t,e,s,i,n,o,a,h){return this.getBarycoord(t,e,s,i,Ue)===null?(h.x=0,h.y=0,"z"in h&&(h.z=0),"w"in h&&(h.w=0),null):(h.setScalar(0),h.addScaledVector(n,Ue.x),h.addScaledVector(o,Ue.y),h.addScaledVector(a,Ue.z),h)}static getInterpolatedAttribute(t,e,s,i,n,o){return oo.setScalar(0),ao.setScalar(0),ho.setScalar(0),oo.fromBufferAttribute(t,e),ao.fromBufferAttribute(t,s),ho.fromBufferAttribute(t,i),o.setScalar(0),o.addScaledVector(oo,n.x),o.addScaledVector(ao,n.y),o.addScaledVector(ho,n.z),o}static isFrontFacing(t,e,s,i){return pe.subVectors(s,e),ke.subVectors(t,e),pe.cross(ke).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 pe.subVectors(this.c,this.b),ke.subVectors(this.a,this.b),pe.cross(ke).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return ve.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return ve.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,n){return ve.getInterpolation(t,this.a,this.b,this.c,e,s,i,n)}containsPoint(t){return ve.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return ve.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,n=this.c;let o,a;Gs.subVectors(i,s),Ys.subVectors(n,s),io.subVectors(t,s);const h=Gs.dot(io),l=Ys.dot(io);if(h<=0&&l<=0)return e.copy(s);no.subVectors(t,i);const c=Gs.dot(no),u=Ys.dot(no);if(c>=0&&u<=c)return e.copy(i);const d=h*u-c*l;if(d<=0&&h>=0&&c<=0)return o=h/(h-c),e.copy(s).addScaledVector(Gs,o);ro.subVectors(t,n);const p=Gs.dot(ro),m=Ys.dot(ro);if(m>=0&&p<=m)return e.copy(n);const f=p*l-h*m;if(f<=0&&l>=0&&m<=0)return a=l/(l-m),e.copy(s).addScaledVector(Ys,a);const y=c*m-p*u;if(y<=0&&u-c>=0&&p-m>=0)return Lh.subVectors(n,i),a=(u-c)/(u-c+(p-m)),e.copy(i).addScaledVector(Lh,a);const g=1/(y+f+d);return o=f*g,a=d*g,e.copy(s).addScaledVector(Gs,o).addScaledVector(Ys,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class kc extends So{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new qi(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 hs,this.combine=ml,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 Fh=new Rt,fs=new ky,Pn=new oa,zh=new M,Ln=new M,Fn=new M,zn=new M,lo=new M,Dn=new M,Dh=new M,Bn=new M;class Uy extends ne{constructor(t=new Cr,e=new kc){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,s=Object.keys(e);if(s.length>0){const i=e[s[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let n=0,o=i.length;n<o;n++){const a=i[n].name||String(n);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=n}}}}getVertexPosition(t,e){const s=this.geometry,i=s.attributes.position,n=s.morphAttributes.position,o=s.morphTargetsRelative;e.fromBufferAttribute(i,t);const a=this.morphTargetInfluences;if(n&&a){Dn.set(0,0,0);for(let h=0,l=n.length;h<l;h++){const c=a[h],u=n[h];c!==0&&(lo.fromBufferAttribute(u,t),o?Dn.addScaledVector(lo,c):Dn.addScaledVector(lo.sub(e),c))}e.add(Dn)}return e}raycast(t,e){const s=this.geometry,i=this.material,n=this.matrixWorld;i!==void 0&&(s.boundingSphere===null&&s.computeBoundingSphere(),Pn.copy(s.boundingSphere),Pn.applyMatrix4(n),fs.copy(t.ray).recast(t.near),!(Pn.containsPoint(fs.origin)===!1&&(fs.intersectSphere(Pn,zh)===null||fs.origin.distanceToSquared(zh)>(t.far-t.near)**2))&&(Fh.copy(n).invert(),fs.copy(t.ray).applyMatrix4(Fh),!(s.boundingBox!==null&&fs.intersectsBox(s.boundingBox)===!1)&&this._computeIntersections(t,e,fs)))}_computeIntersections(t,e,s){let i;const n=this.geometry,o=this.material,a=n.index,h=n.attributes.position,l=n.attributes.uv,c=n.attributes.uv1,u=n.attributes.normal,d=n.groups,p=n.drawRange;if(a!==null)if(Array.isArray(o))for(let m=0,f=d.length;m<f;m++){const y=d[m],g=o[y.materialIndex],x=Math.max(y.start,p.start),C=Math.min(a.count,Math.min(y.start+y.count,p.start+p.count));for(let b=x,A=C;b<A;b+=3){const N=a.getX(b),E=a.getX(b+1),O=a.getX(b+2);i=kn(this,g,t,s,l,c,u,N,E,O),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=y.materialIndex,e.push(i))}}else{const m=Math.max(0,p.start),f=Math.min(a.count,p.start+p.count);for(let y=m,g=f;y<g;y+=3){const x=a.getX(y),C=a.getX(y+1),b=a.getX(y+2);i=kn(this,o,t,s,l,c,u,x,C,b),i&&(i.faceIndex=Math.floor(y/3),e.push(i))}}else if(h!==void 0)if(Array.isArray(o))for(let m=0,f=d.length;m<f;m++){const y=d[m],g=o[y.materialIndex],x=Math.max(y.start,p.start),C=Math.min(h.count,Math.min(y.start+y.count,p.start+p.count));for(let b=x,A=C;b<A;b+=3){const N=b,E=b+1,O=b+2;i=kn(this,g,t,s,l,c,u,N,E,O),i&&(i.faceIndex=Math.floor(b/3),i.face.materialIndex=y.materialIndex,e.push(i))}}else{const m=Math.max(0,p.start),f=Math.min(h.count,p.start+p.count);for(let y=m,g=f;y<g;y+=3){const x=y,C=y+1,b=y+2;i=kn(this,o,t,s,l,c,u,x,C,b),i&&(i.faceIndex=Math.floor(y/3),e.push(i))}}}}function Vy(r,t,e,s,i,n,o,a){let h;if(t.side===dr?h=s.intersectTriangle(o,n,i,!0,a):h=s.intersectTriangle(i,n,o,t.side===To,a),h===null)return null;Bn.copy(a),Bn.applyMatrix4(r.matrixWorld);const l=e.ray.origin.distanceTo(Bn);return l<e.near||l>e.far?null:{distance:l,point:Bn.clone(),object:r}}function kn(r,t,e,s,i,n,o,a,h,l){r.getVertexPosition(a,Ln),r.getVertexPosition(h,Fn),r.getVertexPosition(l,zn);const c=Vy(r,t,e,s,Ln,Fn,zn,Dh);if(c){const u=new M;ve.getBarycoord(Dh,Ln,Fn,zn,u),i&&(c.uv=ve.getInterpolatedAttribute(i,a,h,l,u,new _t)),n&&(c.uv1=ve.getInterpolatedAttribute(n,a,h,l,u,new _t)),o&&(c.normal=ve.getInterpolatedAttribute(o,a,h,l,u,new M),c.normal.dot(s.direction)>0&&c.normal.multiplyScalar(-1));const d={a,b:h,c:l,normal:new M,materialIndex:0};ve.getNormal(Ln,Fn,zn,d.normal),c.face=d,c.barycoord=u}return c}class Hy extends ca{constructor(t=1,e={}){super(t,t,e),this.isCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new aa(i),this._setTextureOptions(e),this.texture.isRenderTargetTexture=!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 n=new ua(5,5,5),o=Ey(xc),a=new Bc;a.colorNode=sa(e,o,0),a.side=dr,a.blending=Ju;const h=new Uy(n,a),l=new Fy;l.add(h),e.minFilter===Fo&&(e.minFilter=Jn);const c=new Dy(1,10,this),u=t.getMRT();return t.setMRT(null),c.update(t,l),t.setMRT(u),e.minFilter=s,e.currentGenerateMipmaps=i,h.geometry.dispose(),h.material.dispose(),this}clear(t,e=!0,s=!0,i=!0){const n=t.getRenderTarget();for(let o=0;o<6;o++)t.setRenderTarget(this,o),t.clear(e,s,i);t.setRenderTarget(n)}}const Wi=new WeakMap;class jy extends It{static get type(){return"CubeMapNode"}constructor(t){super("vec3"),this.envNode=t,this._cubeTexture=null,this._cubeTextureNode=bc(null);const e=new aa;e.isRenderTargetTexture=!0,this._defaultTexture=e,this.updateBeforeType=nt.RENDER}updateBefore(t){const{renderer:e,material:s}=t,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const n=i.isTextureNode?i.value:s[i.property];if(n&&n.isTexture){const o=n.mapping;if(o===yl||o===xl){if(Wi.has(n)){const a=Wi.get(n);Bh(a,n.mapping),this._cubeTexture=a}else{const a=n.image;if(Wy(a)){const h=new Hy(a.height);h.fromEquirectangularTexture(e,n),Bh(h.texture,n.mapping),this._cubeTexture=h.texture,Wi.set(n,h.texture),n.addEventListener("dispose",Uc)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(t){return this.updateBefore(t),this._cubeTextureNode}}function Wy(r){return r==null?!1:r.height>0}function Uc(r){const t=r.target;t.removeEventListener("dispose",Uc);const e=Wi.get(t);e!==void 0&&(Wi.delete(t),e.dispose())}function Bh(r,t){t===yl?r.mapping=Lo:t===xl&&(r.mapping=gl)}const Gy=at(jy).setParameterLength(1);class Yy extends vr{static get type(){return"BasicEnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=Gy(this.envNode)}}class $y extends vr{static get type(){return"BasicLightMapNode"}constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=K(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}class Xy{start(t){t.lightsNode.setupLights(t,t.lightsNode.getLightNodes(t)),this.indirect(t)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Zy extends Xy{constructor(){super()}indirect({context:t}){const e=t.ambientOcclusion,s=t.reflectedLight,i=t.irradianceLightMap;s.indirectDiffuse.assign(Nt(0)),i?s.indirectDiffuse.addAssign(i):s.indirectDiffuse.addAssign(Nt(1,1,1,0)),s.indirectDiffuse.mulAssign(e),s.indirectDiffuse.mulAssign(Bt.rgb)}finish(t){const{material:e,context:s}=t,i=s.outgoingLight,n=t.context.environment;if(n)switch(e.combine){case ml:i.rgb.assign(oi(i.rgb,i.rgb.mul(n.rgb),$r.mul(Xr)));break;case Ku:i.rgb.assign(oi(i.rgb,n.rgb,$r.mul(Xr)));break;case td:i.rgb.addAssign(n.rgb.mul($r.mul(Xr)));break;default:W("BasicLightingModel: Unsupported .combine value:",e.combine);break}}}const qy=new kc;class Vc extends Bc{static get type(){return"MeshBasicNodeMaterial"}constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(qy),this.setValues(t)}setupNormal(){return rn(vc)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new Yy(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new $y(Pc)),e}setupOutgoingLight(){return Bt.rgb}setupLightingModel(){return new Zy}}class Hc extends It{static get type(){return"BitcastNode"}constructor(t,e,s=null){super(),this.valueNode=t,this.conversionType=e,this.inputType=s,this.isBitcastNode=!0}getNodeType(t){if(this.inputType!==null){const e=this.valueNode.getNodeType(t),s=t.getTypeLength(e);return t.getTypeFromLength(s,this.conversionType)}return this.conversionType}generate(t){const e=this.getNodeType(t);let s="";if(this.inputType!==null){const i=this.valueNode.getNodeType(t);s=t.getTypeLength(i)===1?this.inputType:t.changeComponentType(i,this.inputType)}else s=this.valueNode.getNodeType(t);return`${t.getBitcastMethod(e,s)}( ${this.valueNode.build(t,s)} )`}}const Qy=L(Hc).setParameterLength(2),Jy=r=>new Hc(r,"uint","float"),Un={};class bs extends T{static get type(){return"BitcountNode"}constructor(t,e){super(t,e),this.isBitcountNode=!0}_resolveElementType(t,e,s){s==="int"?e.assign(Qy(t,"uint")):e.assign(t)}_returnDataNode(t){switch(t){case"uint":return Pt;case"int":return wt;case"uvec2":return Il;case"uvec3":return Ll;case"uvec4":return zl;case"ivec2":return Ie;case"ivec3":return Pl;case"ivec4":return Fl}}_createTrailingZerosBaseLayout(t,e){const s=this._returnDataNode(e);return z(([n])=>{const o=Pt(0);this._resolveElementType(n,o,e);const a=K(o.bitAnd(Gl(o))),l=Jy(a).shiftRight(23).sub(127);return s(l)}).setLayout({name:t,type:e,inputs:[{name:"value",type:e}]})}_createLeadingZerosBaseLayout(t,e){const s=this._returnDataNode(e);return z(([n])=>{ss(n.equal(Pt(0)),()=>Pt(32));const o=Pt(0),a=Pt(0);return this._resolveElementType(n,o,e),ss(o.shiftRight(16).equal(0),()=>{a.addAssign(16),o.shiftLeftAssign(16)}),ss(o.shiftRight(24).equal(0),()=>{a.addAssign(8),o.shiftLeftAssign(8)}),ss(o.shiftRight(28).equal(0),()=>{a.addAssign(4),o.shiftLeftAssign(4)}),ss(o.shiftRight(30).equal(0),()=>{a.addAssign(2),o.shiftLeftAssign(2)}),ss(o.shiftRight(31).equal(0),()=>{a.addAssign(1)}),s(a)}).setLayout({name:t,type:e,inputs:[{name:"value",type:e}]})}_createOneBitsBaseLayout(t,e){const s=this._returnDataNode(e);return z(([n])=>{const o=Pt(0);this._resolveElementType(n,o,e),o.assign(o.sub(o.shiftRight(Pt(1)).bitAnd(Pt(1431655765)))),o.assign(o.bitAnd(Pt(858993459)).add(o.shiftRight(Pt(2)).bitAnd(Pt(858993459))));const a=o.add(o.shiftRight(Pt(4))).bitAnd(Pt(252645135)).mul(Pt(16843009)).shiftRight(Pt(24));return s(a)}).setLayout({name:t,type:e,inputs:[{name:"value",type:e}]})}_createMainLayout(t,e,s,i){const n=this._returnDataNode(e);return z(([a])=>{if(s===1)return n(i(a));{const h=n(0),l=["x","y","z","w"];for(let c=0;c<s;c++){const u=l[c];h[u].assign(i(a[u]))}return h}}).setLayout({name:t,type:e,inputs:[{name:"value",type:e}]})}setup(t){const{method:e,aNode:s}=this,{renderer:i}=t;if(i.backend.isWebGPUBackend)return super.setup(t);const n=this.getInputType(t),o=t.getElementType(n),a=t.getTypeLength(n),h=`${e}_base_${o}`,l=`${e}_${n}`;let c=Un[h];if(c===void 0){switch(e){case bs.COUNT_LEADING_ZEROS:{c=this._createLeadingZerosBaseLayout(h,o);break}case bs.COUNT_TRAILING_ZEROS:{c=this._createTrailingZerosBaseLayout(h,o);break}case bs.COUNT_ONE_BITS:{c=this._createOneBitsBaseLayout(h,o);break}}Un[h]=c}let u=Un[l];return u===void 0&&(u=this._createMainLayout(l,n,a,c),Un[l]=u),z(()=>u(s))()}}bs.COUNT_TRAILING_ZEROS="countTrailingZeros";bs.COUNT_LEADING_ZEROS="countLeadingZeros";bs.COUNT_ONE_BITS="countOneBits";const co=new M,Ky=new M,t0=new he;class e0{constructor(t=new M(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=co.subVectors(s,e).cross(Ky.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(co),i=this.normal.dot(s);if(i===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/i;return n<0||n>1?null:e.copy(t.start).addScaledVector(s,n)}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||t0.getNormalMatrix(t),i=this.coplanarPoint(co).applyMatrix4(t),n=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(n),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)}}new e0;new M;new M;new M;new Rt;new M(0,0,-1);new Wt;new M;new M;new Wt;new _t;const s0=new ca;na.flipX();s0.depthTexture=new la(1,1);z(([r])=>ri(K(52.9829189).mul(ri(tn(r,Ce(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]});z(([r,t,e])=>{const s=K(2.399963229728653),i=Xo(K(r).add(.5).div(K(t))),n=K(r).mul(s).add(e);return Ce(jl(n),Xi(n)).mul(i)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});class We extends B{static get type(){return"EventNode"}constructor(t,e){super("void"),this.eventType=t,this.callback=e,t===We.OBJECT?this.updateType=nt.OBJECT:t===We.MATERIAL?this.updateType=nt.RENDER:t===We.BEFORE_OBJECT?this.updateBeforeType=nt.OBJECT:t===We.BEFORE_MATERIAL&&(this.updateBeforeType=nt.RENDER)}update(t){this.callback(t)}updateBefore(t){this.callback(t)}}We.OBJECT="object";We.MATERIAL="material";We.BEFORE_OBJECT="beforeObject";We.BEFORE_MATERIAL="beforeMaterial";z(({texture:r,uv:t})=>{const s=H().toVar();return ss(t.x.lessThan(1e-4),()=>{s.assign(H(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{s.assign(H(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{s.assign(H(0,0,1))}).ElseIf(t.x.greaterThan(1-1e-4),()=>{s.assign(H(-1,0,0))}).ElseIf(t.y.greaterThan(1-1e-4),()=>{s.assign(H(0,-1,0))}).ElseIf(t.z.greaterThan(1-1e-4),()=>{s.assign(H(0,0,-1))}).Else(()=>{const n=r.sample(t.add(H(-.01,0,0))).r.sub(r.sample(t.add(H(.01,0,0))).r),o=r.sample(t.add(H(0,-.01,0))).r.sub(r.sample(t.add(H(0,.01,0))).r),a=r.sample(t.add(H(0,0,-.01))).r.sub(r.sample(t.add(H(0,0,.01))).r);s.assign(H(n,o,a))}),s.normalize()});z(([r,t])=>r.mul(t).floor().div(t));const Vn=new _t;class i0 extends xr{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.isPassTextureNode=!0,this.setUpdateMatrix(!1)}setup(t){const e=t.getNodeProperties(this);return e.passNode=this.passNode,super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class kh extends i0{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s,this.isPassMultipleTextureNode=!0}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){const t=new this.constructor(this.passNode,this.textureName,this.previousTexture);return t.uvNode=this.uvNode,t.levelNode=this.levelNode,t.biasNode=this.biasNode,t.sampler=this.sampler,t.depthNode=this.depthNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.offsetNode=this.offsetNode,t}}class br extends It{static get type(){return"PassNode"}constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const n=new la;n.isRenderTargetTexture=!0,n.name="depth";const o=new ca(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:id,...i});o.texture.name="output",o.depthTexture=n,this.renderTarget=o,this.overrideMaterial=null,this.transparent=!0,this.opaque=!0,this.contextNode=null,this._contextNodeCache=null,this._textures={output:o.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=Tt(0),this._cameraFar=Tt(0),this._mrt=null,this._layers=null,this._resolutionScale=1,this._viewport=null,this._scissor=null,this.isPassNode=!0,this.updateBeforeType=nt.FRAME,this.global=!0}setResolutionScale(t){return this._resolutionScale=t,this}getResolutionScale(){return this._resolutionScale}setResolution(t){return W("PassNode: .setResolution() is deprecated. Use .setResolutionScale() instead."),this.setResolutionScale(t)}getResolution(){return W("PassNode: .getResolution() is deprecated. Use .getResolutionScale() instead."),this.getResolutionScale()}setLayers(t){return this._layers=t,this}getLayers(){return this._layers}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}getTexture(t){let e=this._textures[t];return e===void 0&&(e=this.renderTarget.texture.clone(),e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)),e}getPreviousTexture(t){let e=this._previousTextures[t];return e===void 0&&(e=this.getTexture(t).clone(),this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(e!==void 0){const s=this._textures[t],i=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[i]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return e===void 0&&(e=new kh(this,t),e.updateTexture(),this._textureNodes[t]=e),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return e===void 0&&(this._textureNodes[t]===void 0&&this.getTextureNode(t),e=new kh(this,t,!0),e.updateTexture(),this._previousTextureNodes[t]=e),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(e===void 0){const s=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=Lc(this.getTextureNode(t),s,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(e===void 0){const s=this._cameraNear,i=this._cameraFar,n=this.getViewZNode(t);this._linearDepthNodes[t]=e=ji(n,s,i)}return e}async compileAsync(t){const e=t.getRenderTarget(),s=t.getMRT();t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),await t.compileAsync(this.scene,this.camera),t.setRenderTarget(e),t.setMRT(s)}setup({renderer:t}){return this.renderTarget.samples=this.options.samples===void 0?t.samples:this.options.samples,this.renderTarget.texture.type=t.getOutputBufferType(),this.scope===br.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s}=this;let i,n;const o=e.getOutputRenderTarget();o&&o.isXRRenderTarget===!0?(n=1,i=e.xr.getCamera(),e.xr.updateCamera(i),Vn.set(o.width,o.height)):(i=this.camera,n=e.getPixelRatio(),e.getSize(Vn)),this._pixelRatio=n,this.setSize(Vn.width,Vn.height);const a=e.getRenderTarget(),h=e.getMRT(),l=e.autoClear,c=e.transparent,u=e.opaque,d=i.layers.mask,p=e.contextNode,m=s.overrideMaterial;this._cameraNear.value=i.near,this._cameraFar.value=i.far,this._layers!==null&&(i.layers.mask=this._layers.mask);for(const y in this._previousTextures)this.toggleTexture(y);this.overrideMaterial!==null&&(s.overrideMaterial=this.overrideMaterial),e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.autoClear=!0,e.transparent=this.transparent,e.opaque=this.opaque,this.contextNode!==null&&((this._contextNodeCache===null||this._contextNodeCache.version!==this.version)&&(this._contextNodeCache={version:this.version,context:di({...e.contextNode.getFlowContextData(),...this.contextNode.getFlowContextData()})}),e.contextNode=this._contextNodeCache.context);const f=s.name;s.name=this.name?this.name:s.name,e.render(s,i),s.name=f,s.overrideMaterial=m,e.setRenderTarget(a),e.setMRT(h),e.autoClear=l,e.transparent=c,e.opaque=u,e.contextNode=p,i.layers.mask=d}setSize(t,e){this._width=t,this._height=e;const s=Math.floor(this._width*this._pixelRatio*this._resolutionScale),i=Math.floor(this._height*this._pixelRatio*this._resolutionScale);this.renderTarget.setSize(s,i),this._scissor!==null&&this.renderTarget.scissor.copy(this._scissor),this._viewport!==null&&this.renderTarget.viewport.copy(this._viewport)}setScissor(t,e,s,i){t===null?this._scissor=null:(this._scissor===null&&(this._scissor=new Wt),t.isVector4?this._scissor.copy(t):this._scissor.set(t,e,s,i),this._scissor.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setViewport(t,e,s,i){t===null?this._viewport=null:(this._viewport===null&&(this._viewport=new Wt),t.isVector4?this._viewport.copy(t):this._viewport.set(t,e,s,i),this._viewport.multiplyScalar(this._pixelRatio*this._resolutionScale).floor())}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}br.COLOR="color";br.DEPTH="depth";H(1.6605,-.1246,-.0182),H(-.5876,1.1329,-.1006),H(-.0728,-.0083,1.1187);H(.6274,.0691,.0164),H(.3293,.9195,.088),H(.0433,.0113,.8956);function da(r){let t;const e=r.context.getViewZ;return e!==void 0&&(t=e(this)),(t||Ot.z).negate()}z(([r,t],e)=>{const s=da(e);return ai(r,t,s)});z(([r],t)=>{const e=da(t);return r.mul(r,e,e).negate().exp().oneMinus()});z(([r,t],e)=>{const s=da(e),n=t.sub(og.y).max(0).toConst().mul(s).toConst();return r.mul(r,n,n).negate().exp().oneMinus()});z(([r,t])=>Nt(t.toFloat().mix(ki.rgb,r.toVec3()),ki.a));class n0 extends B{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;s.backend.isWebGLBackend===!0?t.addFlowCode(` // ${e}Barrier
111
+ `):t.addLineFlowCode(`${e}Barrier()`,this)}}at(n0);class Fe extends B{static get type(){return"AtomicFunctionNode"}constructor(t,e,s){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.parents=!0}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=t.getNodeProperties(this),s=e.parents,i=this.method,n=this.getNodeType(t),o=this.getInputType(t),a=this.pointerNode,h=this.valueNode,l=[];l.push(`&${a.build(t,o)}`),h!==null&&l.push(h.build(t,o));const c=`${t.getMethod(i,n)}( ${l.join(", ")} )`;if(s?s.length===1&&s[0].isStackNode===!0:!1)t.addLineFlowCode(c,this);else return e.constNode===void 0&&(e.constNode=Cs(c,n).toConst()),e.constNode.build(t)}}Fe.ATOMIC_LOAD="atomicLoad";Fe.ATOMIC_STORE="atomicStore";Fe.ATOMIC_ADD="atomicAdd";Fe.ATOMIC_SUB="atomicSub";Fe.ATOMIC_MAX="atomicMax";Fe.ATOMIC_MIN="atomicMin";Fe.ATOMIC_AND="atomicAnd";Fe.ATOMIC_OR="atomicOr";Fe.ATOMIC_XOR="atomicXor";at(Fe);class q extends It{static get type(){return"SubgroupFunctionNode"}constructor(t,e=null,s=null){super(),this.method=t,this.aNode=e,this.bNode=s}getInputType(t){const e=this.aNode?this.aNode.getNodeType(t):null,s=this.bNode?this.bNode.getNodeType(t):null,i=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s);return i>n?e:s}getNodeType(t){const e=this.method;return e===q.SUBGROUP_ELECT?"bool":e===q.SUBGROUP_BALLOT?"uvec4":this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),n=this.getInputType(t),o=this.aNode,a=this.bNode,h=[];if(s===q.SUBGROUP_BROADCAST||s===q.SUBGROUP_SHUFFLE||s===q.QUAD_BROADCAST){const c=a.getNodeType(t);h.push(o.build(t,i),a.build(t,c==="float"?"int":i))}else s===q.SUBGROUP_SHUFFLE_XOR||s===q.SUBGROUP_SHUFFLE_DOWN||s===q.SUBGROUP_SHUFFLE_UP?h.push(o.build(t,i),a.build(t,"uint")):(o!==null&&h.push(o.build(t,n)),a!==null&&h.push(a.build(t,n)));const l=h.length===0?"()":`( ${h.join(", ")} )`;return t.format(`${t.getMethod(s,i)}${l}`,i,e)}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}q.SUBGROUP_ELECT="subgroupElect";q.SUBGROUP_BALLOT="subgroupBallot";q.SUBGROUP_ADD="subgroupAdd";q.SUBGROUP_INCLUSIVE_ADD="subgroupInclusiveAdd";q.SUBGROUP_EXCLUSIVE_AND="subgroupExclusiveAdd";q.SUBGROUP_MUL="subgroupMul";q.SUBGROUP_INCLUSIVE_MUL="subgroupInclusiveMul";q.SUBGROUP_EXCLUSIVE_MUL="subgroupExclusiveMul";q.SUBGROUP_AND="subgroupAnd";q.SUBGROUP_OR="subgroupOr";q.SUBGROUP_XOR="subgroupXor";q.SUBGROUP_MIN="subgroupMin";q.SUBGROUP_MAX="subgroupMax";q.SUBGROUP_ALL="subgroupAll";q.SUBGROUP_ANY="subgroupAny";q.SUBGROUP_BROADCAST_FIRST="subgroupBroadcastFirst";q.QUAD_SWAP_X="quadSwapX";q.QUAD_SWAP_Y="quadSwapY";q.QUAD_SWAP_DIAGONAL="quadSwapDiagonal";q.SUBGROUP_BROADCAST="subgroupBroadcast";q.SUBGROUP_SHUFFLE="subgroupShuffle";q.SUBGROUP_SHUFFLE_XOR="subgroupShuffleXor";q.SUBGROUP_SHUFFLE_UP="subgroupShuffleUp";q.SUBGROUP_SHUFFLE_DOWN="subgroupShuffleDown";q.QUAD_BROADCAST="quadBroadcast";z(([r=en()],{renderer:t,material:e})=>{const s=Kl(r.mul(2).sub(1));let i;if(e.alphaToCoverage&&t.currentSamples>0){const n=K(s.fwidth()).toVar();i=ai(n.oneMinus(),n.add(1),s).oneMinus()}else i=qo(s.greaterThan(1),0,1);return i});class r0 extends Vc{constructor(){super();const t=cc(Dc(),.1,.5,0,1).oneMinus();this.colorNode=Nt(t,t,t,1)}}class o0 extends Vc{constructor(){super(),this.colorNode=Nt(en(),0,1)}}const gs=new Gi,kt=new U,ts=new U,dt=new ye,Uh={X:new U(1,0,0),Y:new U(0,1,0),Z:new U(0,0,1)},uo={type:"change"},Vh={type:"mouseDown",mode:null},Hh={type:"mouseUp",mode:null},jh={type:"objectChange"};class a0 extends Cu{constructor(t,e=null){super(void 0,e);const s=new p0(this);this._root=s;const i=new m0;this._gizmo=i,s.add(i);const n=new f0;this._plane=n,s.add(n);const o=this;function a(C,b){let A=b;Object.defineProperty(o,C,{get:function(){return A!==void 0?A:b},set:function(N){A!==N&&(A=N,n[C]=N,i[C]=N,o.dispatchEvent({type:C+"-changed",value:N}),o.dispatchEvent(uo))}}),o[C]=b,n[C]=b,i[C]=b}a("camera",t),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const h=new U,l=new U,c=new ye,u=new ye,d=new U,p=new ye,m=new U,f=new U,y=new U,g=0,x=new U;a("worldPosition",h),a("worldPositionStart",l),a("worldQuaternion",c),a("worldQuaternionStart",u),a("cameraPosition",d),a("cameraQuaternion",p),a("pointStart",m),a("pointEnd",f),a("rotationAxis",y),a("rotationAngle",g),a("eye",x),this._offset=new U,this._startNorm=new U,this._endNorm=new U,this._cameraScale=new U,this._parentPosition=new U,this._parentQuaternion=new ye,this._parentQuaternionInv=new ye,this._parentScale=new U,this._worldScaleStart=new U,this._worldQuaternionInv=new ye,this._worldScale=new U,this._positionStart=new U,this._quaternionStart=new ye,this._scaleStart=new U,this._getPointer=h0.bind(this),this._onPointerDown=c0.bind(this),this._onPointerHover=l0.bind(this),this._onPointerMove=u0.bind(this),this._onPointerUp=d0.bind(this),e!==null&&this.connect(e)}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(t){if(this.object===void 0||this.dragging===!0)return;t!==null&&gs.setFromCamera(t,this.camera);const e=po(this._gizmo.picker[this.mode],gs);e?this.axis=e.object.name:this.axis=null}pointerDown(t){if(!(this.object===void 0||this.dragging===!0||t!=null&&t.button!==0)&&this.axis!==null){t!==null&&gs.setFromCamera(t,this.camera);const e=po(this._plane,gs,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,Vh.mode=this.mode,this.dispatchEvent(Vh)}}pointerMove(t){const e=this.axis,s=this.mode,i=this.object;let n=this.space;if(s==="scale"?n="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(n="world"),i===void 0||e===null||this.dragging===!1||t!==null&&t.button!==-1)return;t!==null&&gs.setFromCamera(t,this.camera);const o=po(this._plane,gs,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),n==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),n==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(n==="local"&&(i.position.applyQuaternion(dt.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),n==="world"&&(i.parent&&i.position.add(kt.setFromMatrixPosition(i.parent.matrixWorld)),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(kt.setFromMatrixPosition(i.parent.matrixWorld)))),i.position.x=Math.max(this.minX,Math.min(this.maxX,i.position.x)),i.position.y=Math.max(this.minY,Math.min(this.maxY,i.position.y)),i.position.z=Math.max(this.minZ,Math.min(this.maxZ,i.position.z));else if(s==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),ts.set(a,a,a)}else kt.copy(this.pointStart),ts.copy(this.pointEnd),kt.applyQuaternion(this._worldQuaternionInv),ts.applyQuaternion(this._worldQuaternionInv),ts.divide(kt),e.search("X")===-1&&(ts.x=1),e.search("Y")===-1&&(ts.y=1),e.search("Z")===-1&&(ts.z=1);i.scale.copy(this._scaleStart).multiply(ts),this.scaleSnap&&(e.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(kt.setFromMatrixPosition(this.camera.matrixWorld));let h=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(kt.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(Uh[e]),kt.copy(Uh[e]),n==="local"&&kt.applyQuaternion(this.worldQuaternion),kt.cross(this.eye),kt.length()===0?h=!0:this.rotationAngle=this._offset.dot(kt.normalize())*a),(e==="E"||h)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),n==="local"&&e!=="E"&&e!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(dt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(dt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(uo),this.dispatchEvent(jh)}}pointerUp(t){t!==null&&t.button!==0||(this.dragging&&this.axis!==null&&(Hh.mode=this.mode,this.dispatchEvent(Hh)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(t){return this.object=t,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(uo),this.dispatchEvent(jh),this.pointStart.copy(this.pointEnd))}getRaycaster(){return gs}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}setColors(t,e,s,i){const n=this._gizmo.materialLib;n.xAxis.color.set(t),n.yAxis.color.set(e),n.zAxis.color.set(s),n.active.color.set(i),n.xAxisTransparent.color.set(t),n.yAxisTransparent.color.set(e),n.zAxisTransparent.color.set(s),n.activeTransparent.color.set(i),n.xAxis._color&&n.xAxis._color.set(t),n.yAxis._color&&n.yAxis._color.set(e),n.zAxis._color&&n.zAxis._color.set(s),n.active._color&&n.active._color.set(i),n.xAxisTransparent._color&&n.xAxisTransparent._color.set(t),n.yAxisTransparent._color&&n.yAxisTransparent._color.set(e),n.zAxisTransparent._color&&n.zAxisTransparent._color.set(s),n.activeTransparent._color&&n.activeTransparent._color.set(i)}}function h0(r){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:r.button};{const t=this.domElement.getBoundingClientRect();return{x:(r.clientX-t.left)/t.width*2-1,y:-(r.clientY-t.top)/t.height*2+1,button:r.button}}}function l0(r){if(this.enabled)switch(r.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(r));break}}function c0(r){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(r)),this.pointerDown(this._getPointer(r)))}function u0(r){this.enabled&&this.pointerMove(this._getPointer(r))}function d0(r){this.enabled&&(this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(r)))}function po(r,t,e){const s=t.intersectObject(r,!0);for(let i=0;i<s.length;i++)if(s[i].object.visible||e)return s[i];return!1}const Hn=new ul,ot=new U(0,1,0),Wh=new U(0,0,0),Gh=new ur,jn=new ye,Zn=new ye,Ee=new U,Yh=new ur,Ii=new U(1,0,0),xs=new U(0,1,0),Pi=new U(0,0,1),Wn=new U,Ai=new U,Ei=new U;class p0 extends si{constructor(t){super(),this.isTransformControlsRoot=!0,this.controls=t,this.visible=!1}updateMatrixWorld(t){const e=this.controls;e.object!==void 0&&(e.object.updateMatrixWorld(),e.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):e.object.parent.matrixWorld.decompose(e._parentPosition,e._parentQuaternion,e._parentScale),e.object.matrixWorld.decompose(e.worldPosition,e.worldQuaternion,e._worldScale),e._parentQuaternionInv.copy(e._parentQuaternion).invert(),e._worldQuaternionInv.copy(e.worldQuaternion).invert()),e.camera.updateMatrixWorld(),e.camera.matrixWorld.decompose(e.cameraPosition,e.cameraQuaternion,e._cameraScale),e.camera.isOrthographicCamera?e.camera.getWorldDirection(e.eye).negate():e.eye.copy(e.cameraPosition).sub(e.worldPosition).normalize(),super.updateMatrixWorld(t)}dispose(){this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}class m0 extends si{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const t=new ei({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new Io({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=t.clone();s.opacity=.15;const i=e.clone();i.opacity=.5;const n=t.clone();n.color.setHex(16711680);const o=t.clone();o.color.setHex(65280);const a=t.clone();a.color.setHex(255);const h=t.clone();h.color.setHex(16711680),h.opacity=.5;const l=t.clone();l.color.setHex(65280),l.opacity=.5;const c=t.clone();c.color.setHex(255),c.opacity=.5;const u=t.clone();u.opacity=.25;const d=t.clone();d.color.setHex(16776960),d.opacity=.25;const p=t.clone();p.color.setHex(16776960);const m=t.clone();m.color.setHex(7895160),this.materialLib={xAxis:n,yAxis:o,zAxis:a,active:p,xAxisTransparent:h,yAxisTransparent:l,zAxisTransparent:c,activeTransparent:d};const f=new Yt(0,.04,.1,12);f.translate(0,.05,0);const y=new Dt(.08,.08,.08);y.translate(0,.04,0);const g=new ti;g.setAttribute("position",new qn([0,0,0,1,0,0],3));const x=new Yt(.0075,.0075,.5,3);x.translate(0,.25,0);function C(j,le){const Ct=new mi(j,.0075,3,64,le*Math.PI*2);return Ct.rotateY(Math.PI/2),Ct.rotateX(Math.PI/2),Ct}function b(){const j=new ti;return j.setAttribute("position",new qn([0,0,0,1,1,1],3)),j}const A={X:[[new F(f,n),[.5,0,0],[0,0,-Math.PI/2]],[new F(f,n),[-.5,0,0],[0,0,Math.PI/2]],[new F(x,n),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new F(f,o),[0,.5,0]],[new F(f,o),[0,-.5,0],[Math.PI,0,0]],[new F(x,o)]],Z:[[new F(f,a),[0,0,.5],[Math.PI/2,0,0]],[new F(f,a),[0,0,-.5],[-Math.PI/2,0,0]],[new F(x,a),null,[Math.PI/2,0,0]]],XYZ:[[new F(new hn(.1,0),u),[0,0,0]]],XY:[[new F(new Dt(.15,.15,.01),c),[.15,.15,0]]],YZ:[[new F(new Dt(.15,.15,.01),h),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new F(new Dt(.15,.15,.01),l),[.15,0,.15],[-Math.PI/2,0,0]]]},N={X:[[new F(new Yt(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new F(new Yt(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new F(new Yt(.2,0,.6,4),s),[0,.3,0]],[new F(new Yt(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new F(new Yt(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new F(new Yt(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new F(new hn(.2,0),s)]],XY:[[new F(new Dt(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new F(new Dt(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new F(new Dt(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},E={START:[[new F(new hn(.01,2),i),null,null,null,"helper"]],END:[[new F(new hn(.01,2),i),null,null,null,"helper"]],DELTA:[[new Oe(b(),i),null,null,null,"helper"]],X:[[new Oe(g,i),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Oe(g,i),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Oe(g,i),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},O={XYZE:[[new F(C(.5,1),m),null,[0,Math.PI/2,0]]],X:[[new F(C(.5,.5),n)]],Y:[[new F(C(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new F(C(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new F(C(.75,1),d),null,[0,Math.PI/2,0]]]},P={AXIS:[[new Oe(g,i),[-1e3,0,0],null,[1e6,1,1],"helper"]]},k={XYZE:[[new F(new dl(.25,10,8),s)]],X:[[new F(new mi(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new F(new mi(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new F(new mi(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new F(new mi(.75,.1,2,24),s)]]},$={X:[[new F(y,n),[.5,0,0],[0,0,-Math.PI/2]],[new F(x,n),[0,0,0],[0,0,-Math.PI/2]],[new F(y,n),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new F(y,o),[0,.5,0]],[new F(x,o)],[new F(y,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new F(y,a),[0,0,.5],[Math.PI/2,0,0]],[new F(x,a),[0,0,0],[Math.PI/2,0,0]],[new F(y,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new F(new Dt(.15,.15,.01),c),[.15,.15,0]]],YZ:[[new F(new Dt(.15,.15,.01),h),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new F(new Dt(.15,.15,.01),l),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new F(new Dt(.1,.1,.1),u)]]},ct={X:[[new F(new Yt(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new F(new Yt(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new F(new Yt(.2,0,.6,4),s),[0,.3,0]],[new F(new Yt(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new F(new Yt(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new F(new Yt(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new F(new Dt(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new F(new Dt(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new F(new Dt(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new F(new Dt(.2,.2,.2),s),[0,0,0]]]},tt={X:[[new Oe(g,i),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new Oe(g,i),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new Oe(g,i),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function it(j){const le=new si;for(const Ct in j)for(let Ut=j[Ct].length;Ut--;){const Q=j[Ct][Ut][0].clone(),gt=j[Ct][Ut][1],At=j[Ct][Ut][2],ce=j[Ct][Ut][3],Ss=j[Ct][Ut][4];Q.name=Ct,Q.tag=Ss,gt&&Q.position.set(gt[0],gt[1],gt[2]),At&&Q.rotation.set(At[0],At[1],At[2]),ce&&Q.scale.set(ce[0],ce[1],ce[2]),Q.updateMatrix();const on=Q.geometry.clone();on.applyMatrix4(Q.matrix),Q.geometry=on,Q.renderOrder=1/0,Q.position.set(0,0,0),Q.rotation.set(0,0,0),Q.scale.set(1,1,1),le.add(Q)}return le}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=it(A)),this.add(this.gizmo.rotate=it(O)),this.add(this.gizmo.scale=it($)),this.add(this.picker.translate=it(N)),this.add(this.picker.rotate=it(k)),this.add(this.picker.scale=it(ct)),this.add(this.helper.translate=it(E)),this.add(this.helper.rotate=it(P)),this.add(this.helper.scale=it(tt)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(t){const s=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Zn;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let i=[];i=i.concat(this.picker[this.mode].children),i=i.concat(this.gizmo[this.mode].children),i=i.concat(this.helper[this.mode].children);for(let n=0;n<i.length;n++){const o=i[n];o.visible=!0,o.rotation.set(0,0,0),o.position.copy(this.worldPosition);let a;if(this.camera.isOrthographicCamera?a=(this.camera.top-this.camera.bottom)/this.camera.zoom:a=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),o.scale.set(1,1,1).multiplyScalar(a*this.size/4),o.tag==="helper"){o.visible=!1,o.name==="AXIS"?(o.visible=!!this.axis,this.axis==="X"&&(dt.setFromEuler(Hn.set(0,0,0)),o.quaternion.copy(s).multiply(dt),Math.abs(ot.copy(Ii).applyQuaternion(s).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Y"&&(dt.setFromEuler(Hn.set(0,0,Math.PI/2)),o.quaternion.copy(s).multiply(dt),Math.abs(ot.copy(xs).applyQuaternion(s).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Z"&&(dt.setFromEuler(Hn.set(0,Math.PI/2,0)),o.quaternion.copy(s).multiply(dt),Math.abs(ot.copy(Pi).applyQuaternion(s).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="XYZE"&&(dt.setFromEuler(Hn.set(0,Math.PI/2,0)),ot.copy(this.rotationAxis),o.quaternion.setFromRotationMatrix(Gh.lookAt(Wh,ot,xs)),o.quaternion.multiply(dt),o.visible=this.dragging),this.axis==="E"&&(o.visible=!1)):o.name==="START"?(o.position.copy(this.worldPositionStart),o.visible=this.dragging):o.name==="END"?(o.position.copy(this.worldPosition),o.visible=this.dragging):o.name==="DELTA"?(o.position.copy(this.worldPositionStart),o.quaternion.copy(this.worldQuaternionStart),kt.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),kt.applyQuaternion(this.worldQuaternionStart.clone().invert()),o.scale.copy(kt),o.visible=this.dragging):(o.quaternion.copy(s),this.dragging?o.position.copy(this.worldPositionStart):o.position.copy(this.worldPosition),this.axis&&(o.visible=this.axis.search(o.name)!==-1));continue}o.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(o.name==="X"&&Math.abs(ot.copy(Ii).applyQuaternion(s).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Y"&&Math.abs(ot.copy(xs).applyQuaternion(s).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Z"&&Math.abs(ot.copy(Pi).applyQuaternion(s).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XY"&&Math.abs(ot.copy(Pi).applyQuaternion(s).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="YZ"&&Math.abs(ot.copy(Ii).applyQuaternion(s).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XZ"&&Math.abs(ot.copy(xs).applyQuaternion(s).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1)):this.mode==="rotate"&&(jn.copy(s),ot.copy(this.eye).applyQuaternion(dt.copy(s).invert()),o.name.search("E")!==-1&&o.quaternion.setFromRotationMatrix(Gh.lookAt(this.eye,Wh,xs)),o.name==="X"&&(dt.setFromAxisAngle(Ii,Math.atan2(-ot.y,ot.z)),dt.multiplyQuaternions(jn,dt),o.quaternion.copy(dt)),o.name==="Y"&&(dt.setFromAxisAngle(xs,Math.atan2(ot.x,ot.z)),dt.multiplyQuaternions(jn,dt),o.quaternion.copy(dt)),o.name==="Z"&&(dt.setFromAxisAngle(Pi,Math.atan2(ot.y,ot.x)),dt.multiplyQuaternions(jn,dt),o.quaternion.copy(dt))),o.visible=o.visible&&(o.name.indexOf("X")===-1||this.showX),o.visible=o.visible&&(o.name.indexOf("Y")===-1||this.showY),o.visible=o.visible&&(o.name.indexOf("Z")===-1||this.showZ),o.visible=o.visible&&(o.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),o.material._color=o.material._color||o.material.color.clone(),o.material._opacity=o.material._opacity||o.material.opacity,o.material.color.copy(o.material._color),o.material.opacity=o.material._opacity,this.enabled&&this.axis&&(o.name===this.axis?(o.material.color.copy(this.materialLib.active.color),o.material.opacity=1):this.axis.split("").some(function(h){return o.name===h})&&(o.material.color.copy(this.materialLib.active.color),o.material.opacity=1))}super.updateMatrixWorld(t)}}class f0 extends F{constructor(){super(new Po(1e5,1e5,2,2),new ei({visible:!1,wireframe:!0,side:cr,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),Wn.copy(Ii).applyQuaternion(e==="local"?this.worldQuaternion:Zn),Ai.copy(xs).applyQuaternion(e==="local"?this.worldQuaternion:Zn),Ei.copy(Pi).applyQuaternion(e==="local"?this.worldQuaternion:Zn),ot.copy(Ai),this.mode){case"translate":case"scale":switch(this.axis){case"X":ot.copy(this.eye).cross(Wn),Ee.copy(Wn).cross(ot);break;case"Y":ot.copy(this.eye).cross(Ai),Ee.copy(Ai).cross(ot);break;case"Z":ot.copy(this.eye).cross(Ei),Ee.copy(Ei).cross(ot);break;case"XY":Ee.copy(Ei);break;case"YZ":Ee.copy(Wn);break;case"XZ":ot.copy(Ei),Ee.copy(Ai);break;case"XYZ":case"E":Ee.set(0,0,0);break}break;case"rotate":default:Ee.set(0,0,0)}Ee.length()===0?this.quaternion.copy(this.cameraQuaternion):(Yh.lookAt(kt.set(0,0,0),Ee,ot),this.quaternion.setFromRotationMatrix(Yh)),super.updateMatrixWorld(t)}}const ge=class ge extends bu{constructor(){super(...arguments);v(this,"three");v(this,"activeCamera");v(this,"controls",new Map);v(this,"visibility",new Map);v(this,"setScene",()=>{this.clear()})}setApp(e){this.three=e,this.three.addEventListener(Y.SET_SCENE,this.setScene)}clear(){for(const e of this.controls.values()){e.detach(),e.disconnect();const s=e.getHelper();is(s)}this.controls=new Map,this.visibility=new Map}add(e){let s=this.controls.get(e);if(s===void 0){const i=document.querySelector(".clickable");s=new a0(this.activeCamera,i),s.getHelper().name=e,s.setSize(.5),s.setSpace("local"),this.controls.set(e,s),this.visibility.set(e,!0),s.addEventListener("mouseDown",()=>{this.dispatchEvent({type:ge.DRAG_START})}),s.addEventListener("mouseUp",()=>{this.dispatchEvent({type:ge.DRAG_END})}),s.addEventListener("dragging-changed",n=>{var o;(o=Mt.instance)==null||o.toggleOrbitControls(n.value)})}return s}get(e){return this.controls.get(e)}remove(e){const s=this.get(e);return s===void 0?!1:(s.detach(),s.disconnect(),is(s.getHelper()),this.controls.delete(e),!0)}enabled(e){this.controls.forEach(s=>{s.enabled=e})}updateCamera(e,s){this.activeCamera=e,this.controls.forEach(i=>{i.camera!==e&&(i.camera=e,e.getWorldPosition(i.cameraPosition),e.getWorldQuaternion(i.cameraQuaternion)),i.domElement!==s&&(i.disconnect(),i.domElement=s,i.connect(s))})}show(){this.controls.forEach(e=>{const s=e.getHelper(),i=this.visibility.get(s.name);i!==void 0&&(s.visible=i)})}hide(){this.controls.forEach(e=>{const s=e.getHelper();this.visibility.set(s.name,s.visible),s.visible=!1})}static get instance(){return ge._instance||(ge._instance=new ge),ge._instance}};v(ge,"DRAG_START","Transform::dragStart"),v(ge,"DRAG_END","Transform::dragEnd"),v(ge,"_instance");let Kt=ge;const g0=new Dt,mo=new qs;class fo extends si{constructor(e,s){const i=new ws(ns(.5,1,Math.random()),ns(.5,1,Math.random()),ns(.5,1,Math.random()));super();v(this,"curve",new va);v(this,"line");v(this,"draggable");v(this,"curvePos");v(this,"tension",.5);v(this,"closed",!1);v(this,"subdivide",50);v(this,"curveType");v(this,"offset",1);v(this,"lineMaterial");v(this,"_camera");v(this,"_curvePercentage",0);v(this,"_draggableScale",10);v(this,"_transform");v(this,"raycaster");v(this,"draggedMat",new ei);v(this,"parentGroup");v(this,"group");v(this,"dispose",()=>{this._transform&&(this._transform.removeEventListener("objectChange",this.updateSpline),Kt.instance.remove(this.name)),this.disable(),this.parentGroup.removeGroup(this.name)});v(this,"hideTransform",()=>{var e;(e=this._transform)==null||e.detach()});v(this,"exportSpline",()=>{const e=[];this.draggable.children.forEach(s=>{e.push([_e(s.position.x,3),_e(s.position.y,3),_e(s.position.z,3)])}),wu({name:this.name,points:e,tension:this.tension,closed:this.closed,subdivide:this.subdivide,type:this.curveType}),console.log("Spline copied!")});v(this,"showPoints",(e=!0)=>{this.draggable.visible=e});v(this,"addPoints",(e=[])=>{if(e.length>0){const s=e.length-1;for(let i=0;i<s;i++)this.addPoint(e[i],!1);this.addPoint(e[s])}});v(this,"addPoint",(e,s=!0)=>{var a;const i=this.draggable.children.length,n=new F(g0,this.draggedMat);n.name=`point_${i}`,n.position.copy(e),n.scale.setScalar(this._draggableScale),this.draggable.add(n),(a=this._transform)==null||a.attach(n);const o=this.points.length>1;return o&&s&&this.updateSpline(),this.line.visible=o,this.updateCurrentPoint(),n});v(this,"addNextPt",()=>{const e=this.draggable.children.length,s=e>1?this.draggable.children[e-1].position.clone():new U,i=this.addPoint(s);this.updateField(i.position)});v(this,"removePoint",e=>{var s,i,n;if(((s=this._transform)==null?void 0:s.object)===e){(i=this._transform)==null||i.detach();const o=this.draggable.children[this.draggable.children.length-1];(n=this._transform)==null||n.attach(o),this.updateField(o.position)}is(e),this.updateSpline()});v(this,"removePointAt",e=>{const s=this.draggable.children[e];this.removePoint(s)});v(this,"removeSelectedPt",()=>{var e,s;((e=this._transform)==null?void 0:e.object)!==void 0&&this.removePoint((s=this._transform)==null?void 0:s.object)});v(this,"updateSpline",()=>{this.points.length<2||(this.curve=new va(this.points,this.closed,this.curveType,this.tension),this.line.geometry.dispose(),this.line.geometry=new ti().setFromPoints(this.curve.getPoints(this.subdivide)),this.curvePos.position.copy(this.getPointAt(this._curvePercentage)))});v(this,"onMouseClick",e=>{var o,a;if(!Mt.instance||!Mt.instance.currentWindow||this._transform&&!this._transform.getHelper().visible)return;const i=Mt.instance.currentWindow.current.getBoundingClientRect();mo.x=(e.clientX-i.x)/i.width*2-1,mo.y=-((e.clientY-i.y)/i.height)*2+1,this.raycaster.setFromCamera(mo,this.camera);const n=this.raycaster.intersectObjects(this.draggable.children,!1);if(n.length>0){const h=n[0].object;h!==((o=this._transform)==null?void 0:o.object)&&((a=this._transform)==null||a.attach(h),this.updateField(h.position))}});v(this,"onUpdateTransform",()=>{this.updateCurrentPoint(),this.updateSpline()});v(this,"debugPoint",e=>{e.name,e.visible=this.draggable.visible});this.name=e,this.lineMaterial=new Io({color:i}),this.line=new Oe(new ti,this.lineMaterial),this.line.name="line",this.line.visible=!1,this.add(this.line),this._camera=s,this.curveType="catmullrom",this.draggedMat.color=i,this.draggable=new si,this.draggable.name="draggablePoints",this.add(this.draggable),this.curvePos=new F(new dl(1.5),new ei({color:i})),this.curvePos.name="curvePos",this.curvePos.scale.setScalar(this._draggableScale),this.curvePos.visible=!1,this.add(this.curvePos),this.raycaster=new Gi,this.raycaster.params.Line.threshold=3,this.enable()}enable(){document.addEventListener("pointerdown",this.onMouseClick)}disable(){document.removeEventListener("pointerdown",this.onMouseClick)}updateLastPoint(e){const s=this.draggable.children.length;s>0&&(this.draggable.children[s-1].position.copy(e),this.updateSpline())}updateField(e){var s;(s=this.group.current)==null||s.setField("Current Point",e)}getPointAt(e){return this.curve.points.length>1?this.curve.getPointAt(e):this.curve.points.length===1?this.curve.points[0]:new U}getTangentAt(e){return this.curve.getTangentAt(e)}get points(){const e=[];return this.draggable.children.forEach(s=>{e.push(s.position)}),e}get total(){return this.draggable.children.length}get draggableScale(){return this._draggableScale}set draggableScale(e){this._draggableScale=e,this.draggable.children.forEach(s=>s.scale.setScalar(e)),this.curvePos.scale.setScalar(e)}get camera(){return this._camera}set camera(e){this._camera=e,this._transform!==void 0&&(this._transform.camera=e)}get curvePercentage(){return this._curvePercentage}set curvePercentage(e){this._curvePercentage=e,this.curvePos.position.copy(this.getPointAt(e))}updateCurrentPoint(){var e,s;if((e=this._transform)!=null&&e.object&&this.group){const i=(s=this._transform)==null?void 0:s.object;i.name.search("point")>-1&&this.updateField(i.position)}}initDebug(e,s){var o;const i=this.draggable.children;this.visible=s,this.parentGroup=e,this._transform=Kt.instance.add(this.name),this._transform.camera=this._camera,this._transform.addEventListener("objectChange",this.onUpdateTransform),i.length>0&&this._transform.attach(i[i.length-1]),(o=Mt.instance)==null||o.helpersContainer.add(this._transform.getHelper());const n=i.length>0?i[i.length-1].position:{x:0,y:0,z:0};this.group=e.addGroup({title:this.name,expanded:s,items:[{prop:"Closed",type:"boolean",value:this.closed},{prop:"Visible",type:"boolean",value:this.visible},{prop:"Show Position",type:"boolean",value:this.curvePos.visible},{prop:"Show Points",type:"boolean",value:this.draggable.visible},{prop:"Color",type:"color",value:`#${this.draggedMat.color.getHexString()}`},{prop:"Curve",type:"option",options:[{title:"Catmullrom",value:"catmullrom"},{title:"Centripetal",value:"centripetal"},{title:"Chordal",value:"chordal"}]},{prop:"Draggable Scale",type:"range",min:.01,max:100,step:.01,value:this._draggableScale},{prop:"Subdivide",type:"range",min:1,max:1e3,step:1,value:this.subdivide},{prop:"Tension",type:"range",min:0,max:1,step:.01,value:this.tension},{prop:"New Pt Offset",type:"range",min:0,max:10,value:this.offset},{prop:"Curve At",type:"range",min:0,max:1,step:.01,value:0},{prop:"Toggle Transform",type:"button"},{prop:"Add Point",type:"button"},{prop:"Remove Point",type:"button"},{prop:"Export",type:"button"},{prop:"Delete",type:"button"},{prop:"Current Point",type:"grid3",value:n}],onUpdate:(a,h)=>{var l,c;switch(a){case"Closed":this.closed=h,this.updateSpline();break;case"Visible":this.visible=h;break;case"Color":this.lineMaterial.color.setStyle(h),this.draggedMat.color.setStyle(h);break;case"Curve":this.curveType=h,this.updateSpline();break;case"Draggable Scale":this.draggableScale=h;break;case"Subdivide":this.subdivide=h,this.updateSpline();break;case"Tension":this.tension=h,this.updateSpline();break;case"New Pt Offset":this.offset=h;break;case"Curve At":this.curvePos.position.copy(this.getPointAt(h));break;case"Show Position":this.curvePos.visible=h;break;case"Show Points":this.draggable.visible=h;break;case"Toggle Transform":this._transform&&(this._transform.getHelper().visible=!this._transform.getHelper().visible);break;case"Add Point":this.addNextPt();break;case"Remove Point":this.removeSelectedPt();break;case"Export":this.exportSpline();break;case"Delete":this.parent.currentSpline=null,is(this);break;case"Current Point":if(this.group.current&&((l=this._transform)!=null&&l.object)){const u=(c=this._transform)==null?void 0:c.object;u.name.search("point")>-1&&(u.position.copy(h),this.updateSpline())}break}}}),this.draggable.children.forEach(a=>{this.debugPoint(a)})}}let Gn=0;class y0 extends si{constructor(e,s){super();v(this,"defaultScale",10);v(this,"currentSpline",null);v(this,"_camera");v(this,"group",null);v(this,"three");v(this,"splineDataText","");v(this,"createSpline",(e=[])=>{const s=`Spline ${Gn+1}`,i=new fo(s,this._camera);return i.addPoints(e),this.addSpline(i,!0),Gn++,i});v(this,"createSplineFromArray",e=>{const s=[];return e.forEach(i=>{s.push(new U(i[0],i[1],i[2]))}),this.createSpline(s)});v(this,"createSplineFromCatmullRom",e=>this.createSpline(e.points));v(this,"createSplineFromJSON",e=>{const s=[];e.points.forEach(n=>{s.push(new U(n[0],n[1],n[2]))});const i=new fo(e.name,this._camera);return i.closed=e.closed,i.subdivide=e.subdivide,i.tension=e.tension,i.type=e.type,i.addPoints(s),i.updateSpline(),this.addSpline(i,!1),i});v(this,"showPoints",(e=!0)=>{this.children.forEach(s=>{s.showPoints(e)})});v(this,"onAddSpline",e=>{const s=JSON.parse(e.value),i=s.name!==void 0?s.name:`Spline ${Gn+1}`,n=new fo(i,this.camera);s.tension!==void 0&&(n.tension=s.tension),s.closed!==void 0&&(n.closed=s.closed),s.subdivide!==void 0&&(n.subdivide=s.subdivide),s.type!==void 0&&(n.curveType=s.type);const o=[];s.points.forEach(a=>{o.push(new U(a[0],a[1],a[2]))}),n.addPoints(o),this.addSpline(n,!1),Gn++});v(this,"isMouseDown",!1);v(this,"onClickCanvas",e=>{var h;if(e.button!==0)return;if(this._camera.type!=="OrthographicCamera"){console.warn("Spline Editor - 3D Camera not supported in Draw Mode");return}const i=e.target.getBoundingClientRect(),n=(e.clientX-i.left)/i.width*2-1,o=-((e.clientY-i.top)/i.height)*2+1;if(Mt.instance){const l=new Gi;l.setFromCamera(new qs(n,o),this._camera);const c=l.intersectObjects(Mt.instance.helpersContainer.children,!0);for(let u=0;u<c.length;u++){const d=c[u];if(!(d.object.isLine||d.object.isTransformControlsPlane)&&d.object.isObject3D)return}}this.currentSpline===null&&(this.currentSpline=this.createSpline());const a=this.mouseToSplinePos(n,o,i.width,i.height);(h=this.currentSpline)==null||h.addPoint(a),this.isMouseDown=!0});v(this,"onMouseMove",e=>{var h,l;if(!this.isMouseDown)return;const i=e.target.getBoundingClientRect(),n=(e.clientX-i.left)/i.width*2-1,o=-((e.clientY-i.top)/i.height)*2+1,a=this.mouseToSplinePos(n,o,i.width,i.height);(h=this.currentSpline)==null||h.updateLastPoint(a),(l=this.currentSpline)==null||l.updateField(a)});v(this,"onMouseUp",()=>{this.isMouseDown=!1});this.name="Spline Editor",this._camera=e,this.three=s,this.three.addEventListener(Y.ADD_SPLINE,this.onAddSpline)}initDebug(){this.group=rs.addEditorGroup({title:this.name,items:[{type:"field",prop:"Spline Data",value:"",disabled:!1},{type:"button",prop:"Import Spline"},{type:"button",prop:"New Spline"},{type:"boolean",prop:"Show Points",value:!0},{type:"boolean",prop:"Draw Mode",value:!1},{type:"boolean",prop:"Visible",value:this.visible},{type:"range",prop:"Default Scale",min:0,max:50,step:.01,value:this.defaultScale}],onUpdate:(e,s)=>{switch(e){case"New Spline":this.createSpline();break;case"Spline Data":this.splineDataText=s;break;case"Import Spline":this.createSplineFromJSON(JSON.parse(this.splineDataText));break;case"Show Points":this.showPoints(s);break;case"Visible":this.visible=s;break;case"Default Scale":this.defaultScale=s;break;case"Draw Mode":s?this.enableClickToDraw():this.disableClickToDraw();break}}})}dispose(){this.three.removeEventListener(Y.ADD_SPLINE,this.onAddSpline),rs.removeEditorGroup(this.name)}addSpline(e,s){var i;e.draggableScale=this.defaultScale,e.hideTransform(),((i=this.group)==null?void 0:i.current)!==null&&e.initDebug(this.group.current,s),this.add(e),this.currentSpline=e}enableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.addEventListener("mousedown",this.onClickCanvas),e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("mouseup",this.onMouseUp)})}disableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.removeEventListener("mousedown",this.onClickCanvas),e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("mouseup",this.onMouseUp)})}mouseToSplinePos(e,s,i,n){const o=new U,a=Math.PI/2,h=this._camera,l=h.zoom,c=h.rotation.x===-6123233995736766e-32&&h.rotation.y===0&&h.rotation.z===0,u=h.rotation.x===-Math.PI&&h.rotation.y===12246467991473532e-32&&h.rotation.z===Math.PI,d=h.rotation.x===-6162975822039155e-48&&h.rotation.y===-a&&h.rotation.z===0,p=h.rotation.x===-6162975822039155e-48&&h.rotation.y===a&&h.rotation.z===0,m=h.rotation.x===-1.5707953264174506&&h.rotation.y===0&&h.rotation.z===0,f=h.rotation.x===1.5707953264174506&&h.rotation.y===0&&h.rotation.z===0;let y=e,g=s;u||p?y*=-1:m&&(g*=-1);const x=i/2/l,C=n/2/l;if(this.currentSpline===null&&(this.currentSpline=this.createSpline()),c||u){const b=y*x+h.position.x,A=g*C+h.position.y;o.set(b,A,0)}else if(d||p){const b=y*x+h.position.z,A=g*C+h.position.y;o.set(0,A,b)}else if(m||f){const b=y*x+h.position.x,A=g*C+h.position.z;o.set(b,0,A)}return o}get camera(){return this._camera}set camera(e){this._camera=e,this.children.forEach(s=>{const i=s;i.camera=e})}}const $h=["Single","Side by Side","Stacked","Quad"],x0="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC60lEQVRYhe2YT4hNcRTHP48xpmYaNAvRyEQxEhnKQljYsRm9/EmSyJiMFAsMZWNhJYoNIUVJ2VGiyb9ZzIpMpkQSahbGv9GMYWrM+1rc2zjvzvvdd+99rzdvMd+6de75nd+5387vnN/v/G5KEuWMKRNNIB8mCRaKiiL5qQb2ApuBuUAV0Ad0AJeB3sSeJRX6LJbULTf6JTUn9Z+KWMUpPyp/Avoa4CNQZ3Sj/lNpdL/xottR7AjOkHRUUpekN5I6JbVLavDH75lIfZN0UFKTpCWS0pJem/HeJBEMG6yV1ONYtgFJbZJ+GF1jDh+zJb03NuliEuwMkMo4yErS2RA/LcbuYVyCrm1mA7Dal/8Cu4FG4JD/HsTTkCy6a+SVMTPQuc1sBKb78nHghi+/A+YBxwL2lbhRY+ThuARdEVxu5JdGFvACr0otdoZ8Y4+Rn0Sn5sFFsMvI6YB9MzA1YJ8mN8k1wAHzfj4uQVdyrpI0aJL7oqTtkq4FiqPLyCOSbktqlbRL0jlJQ2b8QdwCUZ4qvhRStZL0XFK1pMd57CRvq5mfhKBriRfiFUMY6oD7eOdwPlQAN4G10dfWg+uouwXsiOssAj4AC+JMcEWwvnAuOTEr7gTXPmg34zagOwkbIIOXAo9CbDYBrcBXYN+4UUdy2sRflyS5zVNlfPX7ugpJW5V9nI7mmh+lYU0lCZ2B3TOnAVuAk0BTwC5nuhWro46KauBOQJch5OpRaoIW34GreGf+YZdRqS9NAj4Bp4ClQDvwOWxCqSM4ADQEdKE5XvbXzlITrAVe4TW+M6NMKDXBFLAMuAD0ACfIc7pMZBXXA2cY3/xmodQRHAL2A2+NLtj8ZiEKwUL/z2WMPAJcAVYALWSf8dZuDFGWeBHwKxm3sWYhiGG8Tfo6sA2vSfiSy4GrH3wGrDcfKSSKKf6v1E9yF0XK9Q1XBPuMXMw8HXTonQFwETwNzMFr64v1jzgFHIk9ybHEZYPJo65QlD3Bf2/Q/eaHPiSWAAAAAElFTkSuQmCC",_0="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAETklEQVRYhe2YXYhVVRTHf3d0/JhyUrMpFbImM+whSa3Mynww+4AeIgiKoozooQ+KyMyXIAujF6OXqHyI6iEKKYgIP/owsjSFqCkprdDUTEcjbWZ0HHV+Pex1ucfb9Z57Z9REXHA4Z++99l7/s/ZZ/7X2KaiczNLwfwPIk9MA+yunNMAG4DHgV+BvoB3YFff2TPstYEyfrajVroI6Sr1GvahsbJC63HzZq04pmztSvU5tVRuqYRiYg78JeBR4HPg5ntdmxovz9wJfA3uAxuibDLQCA+IqynnAQuBuYCnwMLC1rx48U12U8cZqdWqMDcx4cI16qTpYbVKHqa+ovWUeHKsujn7VL9ULq2HI+wY7gVeBJdGeFu3J4ZUiy/cAXeHRRuAQsC/GC0B3eG4BcH/0tUV7czUAeVsMsBF4Kha9HZgCvAncAuwPnXHA0wFuGLANuDrGuoGDwFxgTqzzQ7RX5FrP2eLsdb76vnogtme6+nE8H1YPlQXHwbi3q9eqn0e7Tb25VrsF68vFY0lb1AGcDTwItGQ8tQM4AIwGmqP/EPAu8A0wElgJfFGzxTo8mKWXu9Rd4ZF96jvqjSbauEC9Sn1O3R463epLaku99voCsFXdkAH3kNpcQW+IiT/bQne3eufxBtioPqP2mKhioXpWzpxb1T8C5Ifh4ZptVoriRmAIKdrI3Lujf3bobAPeJpF0NVkKrAFuI9HTOBIxnxFrF4OgQKKr/dnJlQA+AcwABgOHA4zAamA5cE7orQL+zAEHiWI+A2bFC7aSguheYCgpqAphZz3wSB7AecCICv2TgH8oFRib4gVqka0k0h8CXAxMBW6ooDejFoCvA9OBQUAvKWM0kDz4XUZvNKXtyZMWUl7vBbaQXq457PeEziDgx/KJlQAuIPFdMcEXv5OdYWBP9M8k8VpnDQCvB4aTSrCNJB5cSdrW3tBpIJVnR0qdUTxAfdGUOVTnmwqEanNmqltC/9OgqePKg5eom8PgdvW+oJ9Kupera0O3U50TL3lcAaI+oHaF4R3qa6Z822wq0Saq89T1lmSxOrxeW/Xm4uGkiqQDmECKuKHxHW0HdpMiewSpvGqKeR8Ay0iBsYIjg6261PE2o9Q3Yqv+MqWxO9R1Hl12qs+q49Vlppy82pSr+5xJKsko4AXgHlJ0t5NIeg3wLXAlqZhtIUV8J6nmWwX8QiLjdhL5TwMWkY4R6/rrwYKlMr1Y321QZ/vfwBijPqm+rF4Wc7PjE9QllurGVeoV5gRNHsAm9fnMom3qrKPoTjKdMXaYyrFygEWQ72XWW24qhPu8xcUc2UU6O8wFPjmK7jhgPHAuMJGUGQ6U6WwE5sfzTXGvei7KA9hFOiR9D/wOfFVFt4dS2tpfRe83Ur7/CPiJakfOGgBCypubatArl2r8VfOax/LfzABKtePAzHO/5FgC7KBEzB2kOrDfUm8mOeFySv9+OyFyGmB/5aQH+C9BVKmVCNuMZgAAAABJRU5ErkJggg==",T0="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAQ0lEQVQ4jWP8////fwYqAxYozUhFM/8zkaKYWIWkGEq0b0ZdSjQY5i79TyWagRGaTUdzFEEw6lLqGzqwLoVVJ1StpwA9sBwbUqAh5gAAAABJRU5ErkJggg==",lr=class lr extends I.Component{constructor(e){super(e);v(this,"scene");v(this,"renderer");v(this,"currentScene");v(this,"scenes",new Map);v(this,"cameras",new Map);v(this,"controls",new Map);v(this,"currentCamera");v(this,"currentWindow");v(this,"helpersContainer",new Su);v(this,"grid");v(this,"cameraHelpers",new Map);v(this,"lightHelpers",new Map);v(this,"interactionHelper",new Mu(25));v(this,"currentTransform");v(this,"splineEditor");v(this,"depthMaterial");v(this,"normalsMaterial");v(this,"uvMaterial");v(this,"wireframeMaterial",new ei({opacity:.33,transparent:!0,wireframe:!0}));v(this,"playing",!1);v(this,"rafID",-1);v(this,"cameraControlsRafID",-1);v(this,"width",0);v(this,"height",0);v(this,"tlCam",null);v(this,"trCam",null);v(this,"blCam",null);v(this,"brCam",null);v(this,"tlRender","Renderer");v(this,"trRender","Renderer");v(this,"blRender","Renderer");v(this,"brRender","Renderer");v(this,"cameraVisibility",!0);v(this,"lightVisibility",!0);v(this,"gridVisibility",!0);v(this,"rendererReady",!1);v(this,"selectedItem");v(this,"cameraControlsStartTime",0);v(this,"cameraControlsLastTime",0);v(this,"debugCamera");v(this,"raycaster",new Gi);v(this,"pointer",new qs);v(this,"cameraControls");v(this,"canvasRef");v(this,"containerRef");v(this,"tlWindow");v(this,"trWindow");v(this,"blWindow");v(this,"brWindow");v(this,"editorCameras",["Top","Bottom","Left","Right","Front","Back","Orthographic","UI","Debug"]);v(this,"setupRenderer",e=>{var n,o,a;const s=e.value;if(this.renderer){if(this.renderer instanceof Li&&s.type==="WebGLRenderer"||this.renderer instanceof ln&&s.type==="WebGPURenderer")return;this.renderer.dispose()}this.rendererReady=!1;const i=this.canvasRef.current;this.props.three.canvas=i,s.type==="WebGLRenderer"?(this.renderer=new Li({canvas:i,stencil:!1}),this.grid&&(this.scene.remove(this.grid),is(this.grid)),this.grid=new Ld,this.scene.add(this.grid),this.rendererReady=!0):s.type==="WebGPURenderer"&&(this.renderer=new ln({canvas:i,stencil:!1}),this.grid&&(this.scene.remove(this.grid),is(this.grid)),this.grid=new zd,this.scene.add(this.grid)),this.renderer&&(this.renderer.autoClear=!1,this.renderer.shadowMap.enabled=!0,this.renderer.setClearColor(0),this.renderer.setPixelRatio(devicePixelRatio),this.renderer.setScissorTest(!0),this.resize(),this.props.three.renderer=this.renderer,(n=this.depthMaterial)==null||n.dispose(),(o=this.normalsMaterial)==null||o.dispose(),(a=this.uvMaterial)==null||a.dispose(),this.depthMaterial=new r0,this.normalsMaterial=new Iu,this.uvMaterial=new o0,s.type==="WebGPURenderer"?this.renderer.init().then(()=>{this.rendererReady=!0,this.props.three.requestScene()}):this.props.three.requestScene())});v(this,"onUpdate",()=>{this.playing&&(this.update(),this.draw(),this.rafID=requestAnimationFrame(this.onUpdate))});v(this,"resize",()=>{var a;this.width=window.innerWidth-300,this.height=window.innerHeight,(a=this.renderer)==null||a.setSize(this.width,this.height);const e=Math.floor(this.width/2),s=Math.floor(this.height/2);this.props.three.resize(this.width,this.height),this.props.onSceneResize!==void 0&&this.currentScene!==void 0&&this.props.onSceneResize(this.currentScene,this.width,this.height);let i=this.width,n=this.height;switch(this.state.mode){case"Side by Side":i=e,n=this.height;break;case"Stacked":i=this.width,n=s;break;case"Quad":i=e,n=s;break}const o=i/n;this.cameras.forEach(h=>{var l;h instanceof ba?(h.left=i/-2,h.right=i/2,h.top=n/2,h.bottom=n/-2,h.name==="UI"&&(h.position.x=this.width/2,h.position.y=this.height/-2,h.position.z=100),h.updateProjectionMatrix()):h instanceof Ca&&(h.aspect=o,h.updateProjectionMatrix()),(l=this.cameraHelpers.get(h.name))==null||l.update()})});v(this,"addScene",e=>{const s=this.props.scenes.get(e.value.name);if(s!==void 0){const i=this.scenes.get(e.value.name);if(i!==void 0){this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(i),this.props.three.scene=i;return}const n=new s;n.visible=!1,this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(n),this.props.three.scene=n,this.scenes.set(e.value.name,n),this.scene.add(n)}else console.log("Hermes - Scene not found:",e.value.name,this.props.scenes)});v(this,"sceneUpdate",e=>{this.currentScene!==void 0&&(this.currentScene.visible=!1,this.clearLightHelpers());const s=this.scene.getObjectByName(e.value.name);s!==void 0&&(this.currentScene=s,this.currentScene.visible=!0,this.addLightHelpers(this.currentScene)),this.cameraHelpers.forEach((i,n)=>{const o=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",n)!==void 0;i.visible=this.cameraVisibility&&o})});v(this,"removeScene",e=>{const s=e.value.name;this.scenes.delete(s);const i=this.scene.getObjectByName(s);i&&setTimeout(()=>{is(i)},100),this.clearLightHelpers()});v(this,"addCamera",e=>{var o;const s=e.value,i=s.uuid,n=(o=this.props.three.scene)==null?void 0:o.getObjectByProperty("uuid",s.uuid);if(n!==void 0){const a=n;this.cameras.set(i,a);const h=new Pu(a),l=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",i)!==void 0;h.visible=this.cameraVisibility&&l,this.cameraHelpers.set(i,h),this.helpersContainer.add(h),this.setState({lastUpdate:Date.now()})}});v(this,"removeCamera",e=>{const i=e.value.uuid,n=this.cameraHelpers.get(i);n!==void 0&&(this.helpersContainer.remove(n),n.dispose()),this.cameras.delete(i),this.setState({lastUpdate:Date.now()})});v(this,"onMouseMove",e=>{var u;const s=new qs;(u=this.renderer)==null||u.getSize(s);const i=Math.min(e.clientX,s.x),n=Math.min(e.clientY,s.y);this.pointer.x=ys(i,0,s.x,-1,1),this.pointer.y=ys(n,0,s.y,1,-1);const o=s.x/2,a=s.y/2,h=()=>{i<o?this.pointer.x=ys(i,0,o,-1,1):this.pointer.x=ys(i,o,s.x,-1,1)},l=()=>{n<a?this.pointer.y=ys(n,0,a,1,-1):this.pointer.y=ys(n,a,s.y,1,-1)};switch(this.state.mode){case"Quad":h(),l();break;case"Side by Side":h();break;case"Stacked":l(),l();break}if(this.updateCamera(i,n,o,a),this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const c=this.raycaster.intersectObjects(this.currentScene.children);c.length>0&&this.interactionHelper.position.copy(c[0].point)});v(this,"onClick",e=>{if(this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const s=new qs;if(this.renderer.getSize(s),e.clientX>=s.x)return;this.onMouseMove(e);const i=this.raycaster.intersectObjects(this.currentScene.children);i.length>0&&(this.props.three.getObject(i[0].object.uuid),this.interactionHelper.visible=!1,this.setState({interactionMode:"Orbit",lastUpdate:Date.now()}))});v(this,"onKey",e=>{if(this.selectedItem!==void 0){if(e.ctrlKey){if(this.currentCamera.name==="UI")return;const s=this.controls.get(this.currentCamera.name);e.key==="0"?(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.selectedItem instanceof F||this.selectedItem instanceof Lu?(this.selectedItem.geometry.computeBoundingBox(),this.cameraControls.fitToBox(this.selectedItem.geometry.boundingBox,!0)):this.cameraControls.fitToSphere(this.selectedItem,!0),this.updateCameraControls(s,!0)):e.key==="1"?(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,Math.PI*.5,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(s)):e.key==="2"?(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,0,!0),this.cameraControls.moveTo(this.selectedItem.position.x,0,this.selectedItem.position.z,!0),this.updateCameraControls(s)):e.key==="3"?(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI/2,Math.PI/2,!0),this.cameraControls.moveTo(0,this.selectedItem.position.y,this.selectedItem.position.z,!0),this.updateCameraControls(s)):e.key==="4"?(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI,Math.PI/2,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(s)):e.key==="5"&&(e.preventDefault(),this.clearControls(),this.cameraControls=new Re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(er(45),er(45),!0),this.updateCameraControls(s))}else if(this.currentTransform!==void 0)switch(e.key){case"r":this.currentTransform.setMode("rotate");break;case"s":this.currentTransform.setMode("scale");break;case"t":this.currentTransform.setMode("translate");break;case"q":this.currentTransform.setSpace(this.currentTransform.space==="local"?"world":"local");break}}});v(this,"onSetSelectedItem",e=>{this.selectedItem!==void 0&&this.updateSelectedItemHelper(!1),this.selectedItem=void 0;const s=e.value.uuid;if(this.scenes.forEach(i=>{s.search(i.uuid)>-1&&(this.selectedItem=i.getObjectByProperty("uuid",s))}),this.selectedItem===void 0){console.log(`Hermes - Can't find selected item: ${e.value.uuid}, ${e.value.name}`);return}this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),Kt.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=Kt.instance.add(e.value.name),this.currentTransform&&(this.currentTransform.attach(this.selectedItem),this.helpersContainer.add(this.currentTransform.getHelper()),this.currentTransform.addEventListener("objectChange",this.onUpdateTransform)),this.updateSelectedItemHelper(!0)});v(this,"onUpdateTransform",()=>{this.selectedItem!==void 0&&(this.props.three.updateObject(this.selectedItem.uuid,"position",this.selectedItem.position),this.props.three.updateObject(this.selectedItem.uuid,"rotation",{x:this.selectedItem.rotation.x,y:this.selectedItem.rotation.y,z:this.selectedItem.rotation.z}),this.props.three.updateObject(this.selectedItem.uuid,"scale",this.selectedItem.scale),ir.instance.update())});v(this,"clearLightHelpers",()=>{this.lightHelpers.forEach(e=>{this.helpersContainer.remove(e),e.dispose()}),this.lightHelpers.clear()});v(this,"addLightHelpers",e=>{e.traverse(s=>{if(s.type.search("Light")>-1){let i;switch(s.type){case"DirectionalLight":i=new Bu(s,100),i.name=`${s.name}Helper`,i.visible=this.lightVisibility,this.lightHelpers.set(s.name,i),this.helpersContainer.add(i);break;case"HemisphereLight":i=new Du(s,250),i.name=`${s.name}Helper`,i.visible=this.lightVisibility,this.lightHelpers.set(s.name,i),this.helpersContainer.add(i);break;case"RectAreaLight":i=new qu(s),i.name=`${s.name}Helper`,i.visible=this.lightVisibility,this.lightHelpers.set(s.name,i),this.helpersContainer.add(i);break;case"PointLight":i=new zu(s,100),i.name=`${s.name}Helper`,i.visible=this.lightVisibility,this.lightHelpers.set(s.name,i),this.helpersContainer.add(i);break;case"SpotLight":i=new Fu(s),i.name=`${s.name}Helper`,i.visible=this.lightVisibility,this.lightHelpers.set(s.name,i),this.helpersContainer.add(i);break}}})});v(this,"updateCamera",(e,s,i,n)=>{switch(this.state.mode){case"Quad":s<n?e<i?this.currentCamera=this.tlCam:this.currentCamera=this.trCam:e<i?this.currentCamera=this.blCam:this.currentCamera=this.brCam;break;case"Side by Side":e<i?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break;case"Single":this.currentCamera=this.tlCam;break;case"Stacked":s<n?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break}this.splineEditor.camera=this.currentCamera,this.raycaster.setFromCamera(this.pointer,this.currentCamera),this.currentCamera===this.tlCam?this.currentWindow=this.tlWindow:this.currentCamera===this.trCam?this.currentWindow=this.trWindow:this.currentCamera===this.blCam?this.currentWindow=this.blWindow:this.currentCamera===this.brCam&&(this.currentWindow=this.brWindow),Kt.instance.updateCamera(this.currentCamera,this.currentWindow.current)});v(this,"updateCameraControls",(e,s=!1)=>{if(this.selectedItem===void 0)return;cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.cameraControls&&(this.cameraControls.smoothTime=.1);const i=.15;this.cameraControlsStartTime=performance.now(),this.cameraControlsLastTime=this.cameraControlsStartTime,this.selectedItem.getWorldPosition(e.target0);const n=()=>{const o=performance.now(),a=(o-this.cameraControlsLastTime)/1e3;this.cameraControlsLastTime=o,this.cameraControls&&this.cameraControls.update(a),s&&(e.target.lerp(e.target0,i),e.object.position.lerp(e.position0,i),e.object.zoom=xo(e.object.zoom,e.zoom0,i),e.object.updateProjectionMatrix(),e.dispatchEvent({type:"change"})),(o-this.cameraControlsStartTime)/1e3>=.5?(cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.clearControls()):this.cameraControlsRafID=requestAnimationFrame(n)};n()});v(this,"clearControls",()=>{this.cameraControls!==void 0&&(this.cameraControls.disconnect(),this.cameraControls.dispose(),this.cameraControls=void 0)});v(this,"drawDouble",()=>{const e=this.getSceneOverride(this.tlRender),s=this.getSceneOverride(this.trRender),i=Math.floor(this.width/2),n=Math.floor(this.height/2),o=this.renderer instanceof ln;if(this.state.mode==="Side by Side")this.drawTo(0,0,i,this.height,this.tlCam,e),this.drawTo(i,0,i,this.height,this.trCam,s);else{const a=this.height-n;o?(this.drawTo(0,0,this.width,n,this.tlCam,e),this.drawTo(0,a,this.width,n,this.trCam,s)):(this.drawTo(0,a,this.width,n,this.tlCam,e),this.drawTo(0,0,this.width,n,this.trCam,s))}});v(this,"drawQuad",()=>{const e=this.renderer instanceof ln,s=this.getSceneOverride(this.tlRender),i=this.getSceneOverride(this.trRender),n=this.getSceneOverride(this.blRender),o=this.getSceneOverride(this.brRender),a=Math.floor(this.width/2),h=Math.floor(this.height/2),l=this.height-h;let c=0,u=e?0:this.height-h;c=0,this.drawTo(c,u,a,h,this.tlCam,s),c=a,this.drawTo(c,u,a,h,this.trCam,i),u=e?l:0,c=0,this.scene.overrideMaterial=n,this.drawTo(c,u,a,h,this.blCam,n),c=a,this.drawTo(c,u,a,h,this.brCam,o)});this.props.three.addEventListener(Y.ADD_RENDERER,this.setupRenderer),this.scene=new Nu,this.scene.name=this.scene.uuid="",this.canvasRef=I.createRef(),this.containerRef=I.createRef(),this.tlWindow=I.createRef(),this.trWindow=I.createRef(),this.blWindow=I.createRef(),this.brWindow=I.createRef();const s=e.three.name,i=localStorage,n=i.getItem(`${s}_mode`);this.state={mode:n!==null?n:"Single",modeOpen:!1,renderModeOpen:!1,interactionMode:"Orbit",interactionModeOpen:!1,lastUpdate:Date.now()},i.setItem(`${s}_mode`,this.state.mode),i.setItem(`${s}_tlCam`,i.getItem(`${s}_tlCam`)!==null?i.getItem(`${s}_tlCam`):"Debug"),i.setItem(`${s}_trCam`,i.getItem(`${s}_trCam`)!==null?i.getItem(`${s}_trCam`):"Orthographic"),i.setItem(`${s}_blCam`,i.getItem(`${s}_blCam`)!==null?i.getItem(`${s}_blCam`):"Front"),i.setItem(`${s}_brCam`,i.getItem(`${s}_brCam`)!==null?i.getItem(`${s}_brCam`):"Top"),i.setItem(`${s}_tlRender`,i.getItem(`${s}_tlRender`)!==null?i.getItem(`${s}_tlRender`):"Renderer"),i.setItem(`${s}_trRender`,i.getItem(`${s}_trRender`)!==null?i.getItem(`${s}_trRender`):"Renderer"),i.setItem(`${s}_blRender`,i.getItem(`${s}_blRender`)!==null?i.getItem(`${s}_blRender`):"Renderer"),i.setItem(`${s}_brRender`,i.getItem(`${s}_brRender`)!==null?i.getItem(`${s}_brRender`):"Renderer");const o={Vector2:qs,Vector3:U,Vector4:Ru,Quaternion:ye,Matrix4:ur,Spherical:Ou,Box3:Eu,Sphere:Au,Raycaster:Gi};Re.install({THREE:o}),this.setupScene(),this.setupTools();const a=localStorage.getItem(this.expandedCameraVisibility);a!==null&&(this.cameraVisibility=a==="open"),this.saveExpandedCameraVisibility();const h=localStorage.getItem(this.expandedLightVisibility);h!==null&&(this.lightVisibility=h==="open"),this.saveExpandedLightVisibility();const l=localStorage.getItem(this.expandedGridVisibility);l!==null&&(this.gridVisibility=l==="open"),this.grid&&(this.grid.visible=this.gridVisibility),this.saveExpandedGridVisibility(),lr.instance=this}componentDidMount(){this.enable(),this.assignControls(),this.resize(),this.play(),Kt.instance.setApp(this.props.three),Kt.instance.activeCamera=this.debugCamera,this.props.three.requestRenderer()}componentDidUpdate(e,s,i){s.mode!==this.state.mode&&(this.assignControls(),this.resize())}componentWillUnmount(){this.disable(),this.clear(),rs.removeEditorGroup("View Settings")}render(){const e=[];return this.cameras.forEach((s,i)=>{e.push(i)}),_.jsxs("div",{className:"multiview",children:[_.jsx("canvas",{ref:this.canvasRef}),_.jsxs("div",{className:`cameras ${this.state.mode==="Single"||this.state.mode==="Stacked"?"single":""}`,ref:this.containerRef,children:[this.state.mode==="Single"&&_.jsx(_.Fragment,{children:_.jsx(ds,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.tlCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=i,localStorage.setItem(`${this.appID}_tlCam`,i.name),this.createControls(i,this.tlWindow.current))},onSelectRenderMode:s=>{this.tlRender=s,localStorage.setItem(`${this.appID}_tlRender`,s)}})}),(this.state.mode==="Side by Side"||this.state.mode==="Stacked")&&_.jsxs(_.Fragment,{children:[_.jsx(ds,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.tlCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=i,localStorage.setItem(`${this.appID}_tlCam`,i.name),this.createControls(i,this.tlWindow.current))},onSelectRenderMode:s=>{this.tlRender=s,localStorage.setItem(`${this.appID}_tlRender`,s)}}),_.jsx(ds,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.trCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.trCam),this.trCam=i,localStorage.setItem(`${this.appID}_trCam`,i.name),this.createControls(i,this.trWindow.current))},onSelectRenderMode:s=>{this.trRender=s,localStorage.setItem(`${this.appID}_trRender`,s)}})]}),this.state.mode==="Quad"&&_.jsxs(_.Fragment,{children:[_.jsx(ds,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.tlCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=i,localStorage.setItem(`${this.appID}_tlCam`,i.name),this.createControls(i,this.tlWindow.current))},onSelectRenderMode:s=>{this.tlRender=s,localStorage.setItem(`${this.appID}_tlRender`,s)}}),_.jsx(ds,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.trCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.trCam),this.trCam=i,localStorage.setItem(`${this.appID}_trCam`,i.name),this.createControls(i,this.trWindow.current))},onSelectRenderMode:s=>{this.trRender=s,localStorage.setItem(`${this.appID}_trRender`,s)}}),_.jsx(ds,{name:"bl",camera:this.blCam,options:e,ref:this.blWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.blCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.blCam),this.blCam=i,localStorage.setItem(`${this.appID}_blCam`,i.name),this.createControls(i,this.blWindow.current))},onSelectRenderMode:s=>{this.blRender=s,localStorage.setItem(`${this.appID}_blRender`,s)}}),_.jsx(ds,{name:"br",camera:this.brCam,options:e,ref:this.brWindow,onSelectCamera:s=>{var n;(n=this.controls.get(this.brCam.name))==null||n.dispose();const i=this.cameras.get(s);i!==void 0&&(this.clearCamera(this.brCam),this.brCam=i,localStorage.setItem(`${this.appID}_brCam`,i.name),this.createControls(i,this.brWindow.current))},onSelectRenderMode:s=>{this.brRender=s,localStorage.setItem(`${this.appID}_brRender`,s)}})]})]}),_.jsxs("div",{className:"settings",children:[_.jsx(sr,{title:"View",index:$h.indexOf(this.state.mode),options:$h,onSelect:s=>{s!==this.state.mode&&(this.killControls(),this.setState({mode:s}),localStorage.setItem(`${this.appID}_mode`,s))},open:this.state.modeOpen,onToggle:s=>{this.setState({modeOpen:s,renderModeOpen:!1,interactionModeOpen:!1})}}),_.jsx(sr,{title:"Interact",index:this.state.interactionMode==="Orbit"?0:1,options:["Orbit Mode","Selection Mode"],onSelect:s=>{this.interactionHelper.visible=s==="Selection Mode",this.setState({interactionMode:this.interactionHelper.visible?"Selection":"Orbit"})},open:this.state.interactionModeOpen,onToggle:s=>{this.setState({modeOpen:!1,renderModeOpen:!1,interactionModeOpen:s})}}),_.jsx(Fr,{name:"cameraHelper",icon:x0,selected:this.cameraVisibility,height:24,top:2,onClick:s=>{if(this.cameraVisibility=s,this.saveExpandedCameraVisibility(),this.cameraHelpers.forEach(i=>{i.visible=s}),this.selectedItem!==void 0&&!s){const i=this.cameraHelpers.get(this.selectedItem.name);i!==void 0&&(i.visible=!0)}}}),_.jsx(Fr,{name:"lightHelper",icon:_0,selected:this.lightVisibility,height:24,top:4,onClick:s=>{if(this.lightVisibility=s,this.saveExpandedLightVisibility(),this.lightHelpers.forEach(i=>{i.visible=s}),this.selectedItem!==void 0&&!s&&this.selectedItem.isLight===!0){const i=this.lightHelpers.get(this.selectedItem.name);i!==void 0&&(i.visible=!0)}}}),_.jsx(Fr,{name:"gridHelper",icon:T0,selected:this.gridVisibility,height:21,width:21,onClick:s=>{this.setGridVisibility(s)}})]},this.state.lastUpdate)]})}setupScene(){this.helpersContainer.name="helpers",this.scene.add(this.helpersContainer),this.interactionHelper.name="interactionHelper",this.interactionHelper.visible=!1,this.helpersContainer.add(this.interactionHelper);const e=(o,a)=>{const h=new ba(-100,100,100,-100,0,3e3);return h.name=o,h.position.copy(a),h.lookAt(0,0,0),this.cameras.set(o,h),h},s=1e3;e("Top",new U(0,s,0)),e("Bottom",new U(0,-s,0)),e("Left",new U(-s,0,0)),e("Right",new U(s,0,0)),e("Front",new U(0,0,s)),e("Back",new U(0,0,-s)),e("Orthographic",new U(s,s,s)),e("UI",new U),this.debugCamera=new Ca(60,1,.01,3e3),this.debugCamera.name="Debug",this.debugCamera.position.set(300,300,300),this.debugCamera.lookAt(0,0,0),this.cameras.set("Debug",this.debugCamera),this.currentCamera=this.debugCamera;const i=localStorage,n=this.props.three.name;this.tlCam=this.cameras.get(i.getItem(`${n}_tlCam`)),this.trCam=this.cameras.get(i.getItem(`${n}_trCam`)),this.blCam=this.cameras.get(i.getItem(`${n}_blCam`)),this.brCam=this.cameras.get(i.getItem(`${n}_brCam`)),this.tlCam===void 0&&(this.tlCam=this.cameras.get("Debug")),this.trCam===void 0&&(this.trCam=this.cameras.get("Orthographic")),this.blCam===void 0&&(this.blCam=this.cameras.get("Front")),this.brCam===void 0&&(this.brCam=this.cameras.get("Top")),rs.addEditorGroup({title:"Editor",items:[{type:"button",prop:"Hide All Transforms"},{type:"button",prop:"Resize"}],onUpdate:(o,a)=>{switch(o){case"Hide All Transforms":Kt.instance.hide();break;case"Resize":this.resize();break}},subgroups:[{title:"Debug Camera",items:[{type:"range",prop:"Near",step:1e-4,min:.001,max:1e3,value:this.debugCamera.near},{type:"range",prop:"Far",step:.001,min:.001,max:1e4,value:this.debugCamera.far}],onUpdate:(o,a)=>{switch(o){case"Near":this.debugCamera.near=a,this.debugCamera.updateProjectionMatrix();break;case"Far":this.debugCamera.far=a,this.debugCamera.updateProjectionMatrix();break}}},{title:"Grid",items:[{type:"number",prop:"Position",value:0},{type:"color",prop:"Color",value:"#FFFFFF"},{type:"range",prop:"Grid Opacity",value:.25,min:0,max:1,step:.01},{type:"range",prop:"Subgrid Opacity",value:.15,min:0,max:1,step:.01}],onUpdate:(o,a)=>{switch(o){case"Position":this.grid&&(this.grid.position.y=a);break;case"Color":this.grid&&this.grid.color.setStyle(a);break;case"Grid Opacity":this.grid&&(this.grid.gridOpacity=a);break;case"Subgrid Opacity":this.grid&&(this.grid.subgridOpacity=a);break}}}]})}setupTools(){this.splineEditor=new y0(this.currentCamera,this.three),this.splineEditor.initDebug(),this.helpersContainer.add(this.splineEditor)}play(){this.playing=!0,this.onUpdate()}pause(){this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1}toggleOrbitControls(e){this.controls.forEach(s=>{s.enabled=!e})}clear(){this.three.dispatchEvent({type:Y.CLEAR_OBJECT}),rs.removeAllGroups(),this.clearLightHelpers(),this.clearControls(),this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),Kt.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=void 0,Kt.instance.clear(),this.cameras.forEach(e=>{this.editorCameras.indexOf(e.name)<0&&this.three.dispatchEvent({type:Y.REMOVE_CAMERA,value:e})}),this.currentCamera=this.debugCamera,this.currentScene=void 0,this.scenes.forEach(e=>{this.three.dispatchEvent({type:Y.REMOVE_SCENE,value:e})}),this.scenes.clear()}setGridVisibility(e){this.gridVisibility=e,this.saveExpandedGridVisibility(),this.grid&&(this.grid.visible=e)}update(){this.controls.forEach(e=>e.update()),this.cameraHelpers.forEach(e=>e.update()),this.lightHelpers.forEach(e=>{e.update!==void 0&&e.update()}),this.props.onSceneUpdate!==void 0&&this.currentScene!==void 0&&this.props.onSceneUpdate(this.currentScene)}draw(){var e;if(this.rendererReady)switch(this.renderer&&((e=this.renderer)==null||e.clear()),this.state.mode){case"Single":this.drawSingle();break;case"Side by Side":case"Stacked":this.drawDouble();break;case"Quad":this.drawQuad();break}}enable(){const e=this.containerRef.current;e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("click",this.onClick),window.addEventListener("keydown",this.onKey),window.addEventListener("resize",this.resize),this.three.addEventListener(Y.ADD_SCENE,this.addScene),this.three.addEventListener(Y.SET_SCENE,this.sceneUpdate),this.three.addEventListener(Y.REMOVE_SCENE,this.removeScene),this.three.addEventListener(Y.ADD_CAMERA,this.addCamera),this.three.addEventListener(Y.REMOVE_CAMERA,this.removeCamera),this.three.addEventListener(Y.SET_OBJECT,this.onSetSelectedItem)}disable(){const e=this.containerRef.current;e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("click",this.onClick),window.removeEventListener("keydown",this.onKey),window.removeEventListener("resize",this.resize),this.three.removeEventListener(Y.ADD_SCENE,this.addScene),this.three.removeEventListener(Y.SET_SCENE,this.sceneUpdate),this.three.removeEventListener(Y.REMOVE_SCENE,this.removeScene),this.three.removeEventListener(Y.ADD_CAMERA,this.addCamera),this.three.removeEventListener(Y.REMOVE_CAMERA,this.removeCamera),this.three.removeEventListener(Y.SET_OBJECT,this.onSetSelectedItem)}updateSelectedItemHelper(e){if(this.selectedItem!==void 0)if(this.cameraVisibility){if(this.selectedItem.isLight===!0&&!this.lightVisibility){const s=this.lightHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=e)}}else{const s=this.cameraHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=e)}}createControls(e,s){const i=this.controls.get(e.name);if(i!==void 0&&i.dispose(),this.controls.delete(e.name),e.name==="UI")return;const n=new ku(e,s);switch(n.enableDamping=!0,n.dampingFactor=.1,e.name){case"Top":case"Bottom":case"Left":case"Right":case"Front":case"Back":n.enableRotate=!1;break}this.controls.set(e.name,n)}clearCamera(e){const s=this.cameraHelpers.get(e.name);s!==void 0&&(this.helpersContainer.remove(s),s.dispose(),this.cameraHelpers.delete(e.name));const i=this.controls.get(e.name);i!==void 0&&(i.dispose(),this.controls.delete(e.name))}killControls(){this.controls.forEach((e,s)=>{e.dispose();const i=this.cameraHelpers.get(s);i!==void 0&&(this.helpersContainer.remove(i),i.dispose()),this.cameraHelpers.delete(s),this.controls.delete(s)}),this.controls.clear(),this.cameraHelpers.clear()}assignControls(){switch(this.state.mode){case"Single":this.createControls(this.tlCam,this.tlWindow.current);break;case"Side by Side":case"Stacked":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current);break;case"Quad":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current),this.createControls(this.blCam,this.blWindow.current),this.createControls(this.brCam,this.brWindow.current);break}}saveExpandedCameraVisibility(){localStorage.setItem(this.expandedCameraVisibility,this.cameraVisibility?"open":"closed")}saveExpandedLightVisibility(){localStorage.setItem(this.expandedLightVisibility,this.lightVisibility?"open":"closed")}saveExpandedGridVisibility(){localStorage.setItem(this.expandedGridVisibility,this.gridVisibility?"open":"closed")}getSceneOverride(e){switch(e){case"Depth":return this.depthMaterial;case"Normals":return this.normalsMaterial;case"Renderer":return null;case"UVs":return this.uvMaterial;case"Wireframe":return this.wireframeMaterial}return null}drawTo(e,s,i,n,o,a){var h,l,c;switch(o.name){case"Left":case"Right":this.grid&&(this.grid.rotation.z=Math.PI/2);break;case"Front":case"Back":this.grid&&(this.grid.rotation.x=Math.PI/2);break}this.scene.overrideMaterial=a,this.renderer&&((h=this.renderer)==null||h.setScissor(e,s,i,n),(l=this.renderer)==null||l.setViewport(e,s,i,n),(c=this.renderer)==null||c.render(this.scene,o)),this.grid&&this.grid.rotation.set(0,0,0)}drawSingle(){const e=this.getSceneOverride(this.tlRender);this.drawTo(0,0,this.width,this.height,this.tlCam,e)}get appID(){return this.props.three.name}get mode(){return this.state.mode}get three(){return this.props.three}get expandedCameraVisibility(){return`${this.appID}_multiviewCameraVisibility`}get expandedLightVisibility(){return`${this.appID}_multiviewLightVisibility`}get expandedGridVisibility(){return`${this.appID}_multiviewGridVisibility`}};v(lr,"instance",null);let Mt=lr;function jc(r){if(r.child===void 0)return console.log("Hermes - No child attached"),null;const t=I.useRef(null),[e,s]=I.useState(!1),i=r.child.children.length>0,n=[];return r.child.children.length>0&&r.child.children.map((o,a)=>{n.push(_.jsx(jc,{child:o,three:r.three},a))}),I.useEffect(()=>{if(r.child){const o=r.child.uuid.split(".")[0],a=r.three.getScene(o);if(a!==null)try{const h=a.getObjectByProperty("uuid",r.child.uuid);h!==void 0?t.current.style.opacity=h.visible?"1":"0.25":console.log(`Hermes - Can't find child: ${r.child.uuid}`)}catch(h){console.log("Error looking for child:",h),console.log(r.child),console.log(r.three.scenes),console.log(a)}else console.log(`Hermes (ChildObject) - Can't find Scene: ${o} with child UUID: ${r.child.uuid}`,r.three.scenes,r.three.scene,a)}},[e]),_.jsxs("div",{className:"childObject",children:[_.jsxs("div",{className:"child",children:[i?_.jsx("button",{className:"status",style:{backgroundPositionX:e?"-14px":"2px"},onClick:()=>{s(!e)}}):null,_.jsx("button",{className:"name",style:{left:i?"20px":"5px"},onClick:()=>{r.child!==void 0?(r.three.getObject(r.child.uuid),!e&&i&&s(!0)):console.log("Hermes - No child attached...")},children:r.child.name.length>0?`${r.child.name} (${r.child.type})`:`${r.child.type}::${r.child.uuid}`}),_.jsx("button",{className:"visibility",ref:t,onClick:()=>{if(r.child){const o=r.three.getScene(r.child.uuid);if(o!==null){const a=o.getObjectByProperty("uuid",r.child.uuid);if(a!==void 0){const h="visible",l=!a.visible;t.current.style.opacity=l?"1":"0.25",r.three.updateObject(r.child.uuid,h,l),xt(a,h,l)}else console.log(`Hermes - Couldn't find object: ${r.child.uuid}`,o)}else console.log(`Hermes - Couldn't find object in scene: ${r.child.uuid}, ${r.child.name}`)}}}),_.jsx("div",{className:`icon ${Uu(r.child)}`})]}),_.jsx("div",{className:e?"open":"",children:_.jsx("div",{className:"container",children:n})})]})}function go(r){var e;const t=[];return(e=r.child)==null||e.children.map((s,i)=>{t.push(_.jsx(jc,{child:s,scene:r.scene,three:r.three},i))}),_.jsx("div",{className:`scene ${r.class!==void 0?r.class:""}`,children:t})}function Xh(r){switch(r){case"fov":return"FOV";case"zoom":return"Zoom";case"near":return"Near";case"far":return"Far";case"focus":return"Focus";case"aspect":return"Aspect";case"filmGauge":return"Film Gauge";case"filmOffset":return"Film Offset";case"left":return"Left";case"right":return"Right";case"top":return"Top";case"bottom":return"Bottom"}return r}function v0(r,t){function e(){return`${t.name}_camera`}const s=localStorage.getItem(e()),i=s!==null?s==="open":!1;function n(a){localStorage.setItem(e(),a?"open":"closed")}const o=[];if(r.perspectiveCameraInfo!==void 0)for(const a in r.perspectiveCameraInfo)o.push({title:Xh(a),prop:a,type:"number",step:.01,value:r.perspectiveCameraInfo[a],onChange:(h,l)=>{t.updateObject(r.uuid,h,l),t.requestMethod(r.uuid,"updateProjectionMatrix");const c=t.getScene(r.uuid);if(c!==null){const u=c.getObjectByProperty("uuid",r.uuid);u!==void 0&&(xt(u,h,l),u.updateProjectionMatrix())}}});else if(r.orthographicCameraInfo!==void 0)for(const a in r.orthographicCameraInfo)o.push({title:Xh(a),prop:a,type:"number",step:.01,value:r.orthographicCameraInfo[a],onChange:(h,l)=>{t.updateObject(r.uuid,h,l),t.requestMethod(r.uuid,"updateProjectionMatrix");const c=t.getScene(r.uuid);if(c!==null){const u=c.getObjectByProperty("uuid",r.uuid);u!==void 0&&(xt(u,h,l),u.updateProjectionMatrix())}}});return _.jsx(re,{three:t,title:"Camera",items:o,expanded:i,onToggle:a=>{n(a)}})}function Zh(r){switch(r){case"color":return"Color";case"intensity":return"Intensity";case"decay":return"Decay";case"distance":return"Distance";case"angle":return"Angle";case"penumbra":return"Penumbra";case"groundColor":return"Ground Color";case"width":return"Width";case"height":return"Height"}return r}function C0(r,t){function e(){return`${t.name}_light`}const s=localStorage.getItem(e()),i=s!==null?s==="open":!1;function n(a){localStorage.setItem(e(),a?"open":"closed")}const o=[];if(r.lightInfo!==void 0)for(const a in r.lightInfo){const h=r.lightInfo[a];h!==void 0&&(h.isColor!==void 0?o.push({title:Zh(a),prop:a,type:"color",value:h,onChange:(l,c)=>{const u=new ws(c);t.updateObject(r.uuid,l,u);const d=t.getScene(r.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",r.uuid);xt(p,l,u)}}}):o.push({title:Zh(a),prop:a,type:typeof h,value:h,step:typeof h=="number"?.01:void 0,onChange:(l,c)=>{t.updateObject(r.uuid,l,c);const u=t.getScene(r.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",r.uuid);xt(d,l,c)}}}))}return _.jsx(re,{three:t,title:"Light",items:o,expanded:i,onToggle:a=>{n(a)}})}function b0(r){var d;const t=r.object,e=r.three;function s(){return`${e.name}_animation`}const i=localStorage.getItem(s()),n=i!==null?i==="open":!1;function o(p){localStorage.setItem(s(),p?"open":"closed")}const a=[],h=[];let l=0;t.animations.forEach(p=>{l=Math.max(l,p.duration),p.duration>0&&h.push({title:p.name,items:[{title:"Duration",type:"number",value:p.duration,disabled:!0},{title:"Blend Mode",type:"option",disabled:!0,options:[{title:"Normal",value:2500},{title:"Additive",value:2501}]}]})}),a.push({title:"Animations",items:h});let c;const u=e.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);if(p!==void 0){const m=p.mixer;if(m!==void 0){const y=[{title:"Time Scale",type:"range",value:m.timeScale,step:.01,min:-1,max:2,onChange:(g,x)=>{m.timeScale=x,e.updateObject(t.uuid,"mixer.timeScale",x)}}];y.push({title:"Stop All",type:"button",onChange:()=>{m.stopAllAction(),e.requestMethod(t.uuid,"stopAllAction",void 0,"mixer")}}),a.push({title:"Mixer",items:y}),c=new Vu(p),(d=Mt.instance)==null||d.scene.add(c)}}}return I.useEffect(()=>()=>{c!==void 0&&is(c)},[]),_.jsx(re,{three:r.three,title:"Animation",items:a,expanded:n,onToggle:p=>{o(p)}})}const yo={name:"",uuid:"",type:"",visible:!1,matrix:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};function w0(r){const[t,e]=I.useState(yo);I.useEffect(()=>{function o(h){e(h.value)}function a(){e(yo)}return r.three.addEventListener(Y.CLEAR_OBJECT,a),r.three.addEventListener(Y.SET_SCENE,a),r.three.addEventListener(Y.SET_OBJECT,o),()=>{r.three.removeEventListener(Y.CLEAR_OBJECT,a),r.three.removeEventListener(Y.SET_SCENE,a),r.three.removeEventListener(Y.SET_OBJECT,o)}},[]);const s=t.type.toLowerCase(),i=t.animations.length>0||t.mixer!==void 0,n=s.search("mesh")>-1||s.search("line")>-1||s.search("points")>-1;return _.jsx(Di,{three:r.three,label:"Inspector",button:t.uuid.length>0?_.jsx("button",{className:"remove",onClick:()=>{Kt.instance.remove(t.name),e(yo)}}):void 0,children:_.jsx("div",{id:"Inspector",className:r.class,children:t.uuid.length>0&&_.jsxs(_.Fragment,{children:[_.jsxs(_.Fragment,{children:[_.jsx(Yn,{type:"string",title:"Name",prop:"name",value:t.name,disabled:!0}),_.jsx(Yn,{type:"string",title:"Type",prop:"type",value:t.type,disabled:!0}),_.jsx(Yn,{type:"string",title:"UUID",prop:"uuid",value:t.uuid,disabled:!0})]}),_.jsxs(_.Fragment,{children:[_.jsx(ir,{object:t,three:r.three}),i?_.jsx(b0,{object:t,three:r.three}):null,s.search("camera")>-1?v0(t,r.three):null,s.search("light")>-1?C0(t,r.three):null,n?Kd(t,r.three):null]})]})})},"Inspector")}class S0 extends I.Component{constructor(e){super(e);v(this,"autoClear",!0);v(this,"autoClearColor",!0);v(this,"autoClearDepth",!0);v(this,"autoClearStencil",!0);v(this,"outputColorSpace",wa);v(this,"localClippingEnabled",!1);v(this,"clearColor",new ws(0));v(this,"clearAlpha",1);v(this,"toneMapping",Sa);v(this,"toneMappingExposure",1);v(this,"type","");v(this,"onAddRenderer",e=>{const s=e.value;if(this.autoClear=s.autoClear,this.autoClearColor=s.autoClearColor,this.autoClearDepth=s.autoClearDepth,this.autoClearStencil=s.autoClearStencil,this.outputColorSpace=s.outputColorSpace,this.localClippingEnabled=s.localClippingEnabled,this.clearAlpha=s.clearAlpha,this.type=s.type,this.toneMapping=s.toneMapping,this.toneMappingExposure=s.toneMappingExposure,this.clearColor.setStyle(s.clearColor,_o),cn.enabled=s.colorManagement,Mt.instance){const i=Mt.instance.renderer;i&&(i.autoClearColor=this.autoClearColor,i.outputColorSpace=this.outputColorSpace,i instanceof Li&&(i.localClippingEnabled=this.localClippingEnabled),i.toneMapping=this.toneMapping,i.toneMappingExposure=this.toneMappingExposure,i.setClearColor(s.clearColor,this.clearAlpha))}this.setState({lastUpdated:Date.now()})});const s=localStorage.getItem(this.expandedName),i=s!==null?s==="open":!1;if(this.state={expanded:i,lastUpdated:Date.now()},this.saveExpanded(i),Mt.instance){const n=Mt.instance.renderer;n&&(this.autoClear=n.autoClear,this.autoClearColor=n.autoClearColor,this.autoClearDepth=n.autoClearDepth,this.autoClearStencil=n.autoClearStencil,this.clearAlpha=n.getClearAlpha(),this.toneMapping=n.toneMapping,this.toneMappingExposure=n.toneMappingExposure,n instanceof Li&&(this.localClippingEnabled=n.localClippingEnabled,n.getClearColor(this.clearColor)))}this.props.three.addEventListener(Y.ADD_RENDERER,this.onAddRenderer)}componentWillUnmount(){this.props.three.removeEventListener(Y.ADD_RENDERER,this.onAddRenderer)}render(){const e=()=>{if(Mt.instance){const s=Mt.instance.renderer;s&&(s.autoClearColor=this.autoClearColor,s.outputColorSpace=this.outputColorSpace,s instanceof Li&&(s.localClippingEnabled=this.localClippingEnabled),s.toneMapping=this.toneMapping,s.toneMappingExposure=this.toneMappingExposure,s.setClearColor(this.clearColor.getStyle(),this.clearAlpha),this.props.three.updateRenderer({autoClear:this.autoClear,autoClearColor:this.autoClearColor,autoClearDepth:this.autoClearDepth,autoClearStencil:this.autoClearStencil,outputColorSpace:this.outputColorSpace,localClippingEnabled:this.localClippingEnabled,clearAlpha:this.clearAlpha,clearColor:this.clearColor.getStyle(),colorManagement:cn.enabled,toneMapping:this.toneMapping,toneMappingExposure:this.toneMappingExposure}))}};return _.jsx(re,{three:this.props.three,title:"Renderer",expanded:this.state.expanded,items:[{type:"boolean",title:"Auto Clear",value:this.autoClear,onChange:(s,i)=>{this.autoClear=i}},{type:"boolean",title:"Auto Clear Color",value:this.autoClearColor,onChange:(s,i)=>{this.autoClearColor=i,e()}},{type:"boolean",title:"Auto Clear Depth",value:this.autoClearDepth,onChange:(s,i)=>{this.autoClearDepth=i,e()}},{type:"boolean",title:"Auto Clear Stencil",value:this.autoClearStencil,onChange:(s,i)=>{this.autoClearStencil=i,e()}},{type:"boolean",title:"Local Clipping",value:this.localClippingEnabled,onChange:(s,i)=>{this.localClippingEnabled=i,e()}},{type:"color",title:"Clear Color",value:`#${this.clearColor.getHexString()}`,onChange:(s,i)=>{this.clearColor.setStyle(i),e()}},{type:"range",title:"Clear Alpha",min:0,max:1,step:.01,value:this.clearAlpha,onChange:(s,i)=>{this.clearAlpha=i,e()}},{type:"boolean",title:"Color Management",value:cn.enabled,onChange:(s,i)=>{cn.enabled=i,e()}},{type:"option",title:"Color Space",value:this.outputColorSpace,options:[{title:"No Color Space",value:Hu},{title:"SRB Color Space",value:wa},{title:"Linear SRB Color Space",value:_o}],onChange:(s,i)=>{this.outputColorSpace=i,e()}},{type:"option",title:"Tone Mapping",value:this.toneMapping,options:[{title:"None ",value:Sa},{title:"Linear ",value:ju},{title:"Reinhard",value:Wu},{title:"Cineon ",value:Gu},{title:"ACES Filmic",value:Yu},{title:"AgX",value:$u},{title:"Neutral",value:Xu},{title:"Custom",value:Zu}],onChange:(s,i)=>{this.toneMapping=i,e()}},{type:"range",title:"Tone Mapping Exposure",value:this.toneMappingExposure,min:0,max:2,step:.01,onChange:(s,i)=>{this.toneMappingExposure=i,e()}},{type:"string",title:"Type",value:this.type,disabled:!0},{type:"button",title:"Resize Scenes from Source",onChange:()=>{this.props.three.requestSize()}}],onToggle:s=>{this.setState({expanded:s}),this.saveExpanded(s)}},"renderer")}saveExpanded(e){localStorage.setItem(this.expandedName,e?"open":"closed")}get expandedName(){return`${this.props.three.name}_renderer`}}function M0(r){const[t]=I.useState([]),[e]=I.useState([]),[s,i]=I.useState(0),n=l=>{const c=l.value;for(let u=0;u<t.length;u++)if(c.uuid===t[u].uuid)return;t.push(c),e.push(_.jsx(Di,{three:r.three,label:`Scene: ${c.name}`,scene:c,open:!1,visible:!1,onRefresh:()=>{r.three.refreshScene(c.name)},children:_.jsx(go,{child:c,scene:c,three:r.three})},c.name)),i(Date.now())},o=l=>{const c=l.value;for(let u=0;u<t.length;u++)if(c.uuid===t[u].uuid){t[u]=c,e[u]=_.jsx(Di,{three:r.three,label:`Scene: ${c.name}`,scene:c,open:e[u].props.open,visible:e[u].props.visible,onRefresh:()=>{r.three.refreshScene(c.name)},children:_.jsx(go,{child:c,scene:c,three:r.three})},c.name),i(Date.now());return}},a=l=>{const c=l.value;for(let u=0;u<t.length;u++)if(c.uuid===t[u].uuid){t.splice(u,1),e.splice(u,1),i(Date.now());return}},h=l=>{const c=l.value.name;for(let u=0;u<t.length;u++){const d=t[u],p=d.name===c;e[u]=_.jsx(Di,{three:r.three,label:`Scene: ${d.name}`,scene:d,open:p,visible:p,onRefresh:()=>{r.three.refreshScene(d.name)},children:_.jsx(go,{child:d,scene:d,three:r.three})},d.name)}i(Date.now())};return I.useEffect(()=>(r.three.addEventListener(Y.ADD_SCENE,n),r.three.addEventListener(Y.SET_SCENE,h),r.three.addEventListener(Y.REFRESH_SCENE,o),r.three.addEventListener(Y.REMOVE_SCENE,a),()=>{r.three.removeEventListener(Y.ADD_SCENE,n),r.three.removeEventListener(Y.SET_SCENE,h),r.three.removeEventListener(Y.REFRESH_SCENE,o),r.three.removeEventListener(Y.REMOVE_SCENE,a)}),[]),_.jsxs("div",{id:"SidePanel",children:[_.jsx("div",{className:"scenes",children:e},s),_.jsx(w0,{three:r.three}),_.jsx(S0,{three:r.three}),_.jsx(rs,{three:r.three})]})}function R0(r){return _.jsxs(pl,{children:[_.jsx(Mt,{three:r.three,scenes:r.scenes,onSceneAdd:r.onSceneAdd,onSceneResize:r.onSceneResize,onSceneUpdate:r.onSceneUpdate}),_.jsx(M0,{three:r.three})]})}export{R0 as default};