@tomorrowevening/hermes 0.0.162 → 0.0.164

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.
@@ -15,7 +15,7 @@
15
15
  enc -= enc.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);
16
16
  gl_FragColor = enc;
17
17
  }
18
- `,d=c.createShader(35633),p=c.createShader(35632),f=c.createProgram();if(!(p&&d&&f))return;c.shaderSource(d,h),c.shaderSource(p,u),c.compileShader(d),c.compileShader(p),c.attachShader(f,d),c.attachShader(f,p),c.linkProgram(f),c.detachShader(f,d),c.detachShader(f,p),c.deleteShader(d),c.deleteShader(p),c.useProgram(f);const m=c.createBuffer();c.bindBuffer(34962,m),c.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const y=c.getAttribLocation(f,"aPosition");c.vertexAttribPointer(y,3,5126,!1,0,0),c.enableVertexAttribArray(y),c.clearColor(1,1,1,1),c.clear(16384),c.viewport(0,0,1,1),c.drawArrays(4,0,3);const g=new Uint8Array(4);return c.readPixels(0,0,1,1,6408,5121,g),c.deleteProgram(f),c.deleteBuffer(m),g.join("")}(a),i="801621810",n="8016218135",r="80162181161",o=Ps?.isIpad?[["a7",r,12],["a8",n,15],["a8x",n,15],["a9",n,15],["a9x",n,15],["a10",n,15],["a10x",n,15],["a12",i,15],["a12x",i,15],["a12z",i,15],["a14",i,15],["a15",i,15],["m1",i,15],["m2",i,15]]:[["a7",r,12],["a8",n,12],["a9",n,15],["a10",n,15],["a11",i,15],["a12",i,15],["a13",i,15],["a14",i,15],["a15",i,15],["a16",i,15],["a17",i,15]];let l;return s==="80162181255"?l=o.filter(([,,c])=>c>=14):(l=o.filter(([,c])=>c===s),l.length||(l=o)),l.map(([c])=>`apple ${c} gpu`)}class md extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}const Il=[],gd=[];function y0(a,e){if(a===e)return 0;const t=a;a.length>e.length&&(a=e,e=t);let s=a.length,i=e.length;for(;s>0&&a.charCodeAt(~-s)===e.charCodeAt(~-i);)s--,i--;let n,r=0;for(;r<s&&a.charCodeAt(r)===e.charCodeAt(r);)r++;if(s-=r,i-=r,s===0)return i;let o,l,c=0,h=0,u=0;for(;h<s;)gd[h]=a.charCodeAt(r+h),Il[h]=++h;for(;u<i;)for(n=e.charCodeAt(r+u),o=u++,c=u,h=0;h<s;h++)l=n===gd[h]?o:o+1,o=Il[h],c=Il[h]=o>c?l>c?c+1:l:l>o?o+1:l;return c}function x0(a){return a!=null}const _0=({mobileTiers:a=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:t={},glContext:s,failIfMajorPerformanceCaveat:i=!1,benchmarksURL:n="https://unpkg.com/detect-gpu@5.0.70/dist/benchmarks"}={})=>Bl(void 0,void 0,void 0,function*(){const r={};if(Jf)return{tier:0,type:"SSR"};const{isIpad:o=!!Ps?.isIpad,isMobile:l=!!Ps?.isMobile,screenSize:c=window.screen,loadBenchmarks:h=S=>Bl(void 0,void 0,void 0,function*(){const C=yield fetch(`${n}/${S}`).then(w=>w.json());if(parseInt(C.shift().split(".")[0],10)<4)throw new md("Detect GPU benchmark data is out of date. Please update to version 4x");return C})}=t;let{renderer:u}=t;const d=(S,C,w,R,P)=>({device:P,fps:R,gpu:w,isMobile:l,tier:S,type:C});let p,f="";if(u)u=fd(u),p=[u];else{const S=s||function(w,R=!1){const P={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:R,powerPreference:"high-performance",stencil:!1};w&&delete P.powerPreference;const z=window.document.createElement("canvas"),$=z.getContext("webgl",P)||z.getContext("experimental-webgl",P);return $??void 0}(Ps?.isSafari12,i);if(!S)return d(0,"WEBGL_UNSUPPORTED");const C=Ps?.isFirefox?null:S.getExtension("WEBGL_debug_renderer_info");if(u=C?S.getParameter(C.UNMASKED_RENDERER_WEBGL):S.getParameter(S.RENDERER),!u)return d(1,"FALLBACK");f=u,u=fd(u),p=function(w,R,P){return R==="apple gpu"?g0(w,R,P):[R]}(S,u,l)}const m=(yield Promise.all(p.map(function(S){var C;return Bl(this,void 0,void 0,function*(){const w=(be=>{const at=l?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce","adreno"];for(const Ft of at)if(be.includes(Ft))return Ft})(S);if(!w)return;const R=`${l?"m":"d"}-${w}${o?"-ipad":""}.json`,P=r[R]=(C=r[R])!==null&&C!==void 0?C:h(R);let z;try{z=yield P}catch(be){if(be instanceof md)throw be;return}const $=function(be){var at;const Ft=(be=be.replace(/\([^)]+\)/,"")).match(/\d+/)||be.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return(at=Ft?.join("").replace(/\W|amd/g,""))!==null&&at!==void 0?at:""}(S);let q=z.filter(([,be])=>be===$);q.length||(q=z.filter(([be])=>be.includes(S)));const j=q.length;if(j===0)return;const Z=S.split(/[.,()\[\]/\s]/g).sort().filter((be,at,Ft)=>at===0||be!==Ft[at-1]).join(" ");let Q,[we,,,,ue]=j>1?q.map(be=>[be,y0(Z,be[2])]).sort(([,be],[,at])=>be-at)[0][0]:q[0],ge=Number.MAX_VALUE;const{devicePixelRatio:ie}=window,Ee=c.width*ie*c.height*ie;for(const be of ue){const[at,Ft]=be,_r=at*Ft,gn=Math.abs(Ee-_r);gn<ge&&(ge=gn,Q=be)}if(!Q)return;const[,,ke,rt]=Q;return[ge,ke,we,rt]})}))).filter(x0).sort(([S=Number.MAX_VALUE,C],[w=Number.MAX_VALUE,R])=>S===w?C-R:S-w);if(!m.length){const S=m0.find(C=>u.includes(C));return S?d(0,"BLOCKLISTED",S):d(1,"FALLBACK",`${u} (${f})`)}const[,y,g,_]=m[0];if(y===-1)return d(0,"BLOCKLISTED",g,y,_);const b=l?a:e;let T=0;for(let S=0;S<b.length;S++)y>=b[S]&&(T=S);return d(T,"BENCHMARK",g,y,_)});function em(a){let e=0;const t=performance.now();function s(){e++;const i=performance.now();if(i-t>=100){const n=e/((i-t)/1e3),r=Math.round(n/30)*30;a(r)}else requestAnimationFrame(s)}requestAnimationFrame(s)}function tm(a=!1,e=!1){return new Promise(t=>{_0().then(s=>{let i=!1;const n=document.createElement("canvas"),r=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i="transferControlToOffscreen"in n,r){const l=navigator.userAgent.match(/version\/(\d+)/i);i=(l?parseInt(l[1]):0)>=17}const o={dpr:devicePixelRatio,fps:30,width:innerWidth,height:innerHeight,mobile:s.isMobile!==void 0?s.isMobile:!1,supportOffScreenCanvas:i,supportWebGPU:!!navigator.gpu,quality:"Low",dev:a,editor:e};s.tier===3?o.quality="High":s.tier===2&&(o.quality="Medium"),em(l=>{o.fps=l,t(o)})})})}function Ti(a,e,t){return Math.min(e,Math.max(a,t))}function Uo(a,e,t){return(t-a)/(e-a)}function rr(a,e,t){return a*(1-t)+e*t}function b0(a,e,t,s,i){return rr(t,s,Uo(a,e,i))}function T0(a,e){const t=a-e;return Math.sqrt(t*t)}function ss(a,e=1){return Number(a.toFixed(e))}function S0(a,e,t,s){return rr(a,e,1-Math.exp(-t*s))}function v0(a,e=1){return Number(a.toFixed(e))}function w0(a,e,t,s){return a===e&&t===s}function E0(a,e,t,s){return 1/(3*e*a*a+2*t*a+s)}function C0(a,e,t,s,i){return e*(a*a*a)+t*(a*a)+s*a+i}function M0(a,e,t,s,i){const n=a*a;return e*(n*a)+t*n+s*a+i}function A0(a,e,t,s,i){if(a<=0)return 0;if(a>=1)return 1;if(w0(e,t,s,i))return a;const n=0,r=0,o=e,l=t,c=s,h=i,u=1,d=1,p=u-3*c+3*o-n,f=3*c-6*o+3*n,m=3*o-3*n,y=n,g=d-3*h+3*l-r,_=3*h-6*l+3*r,b=3*l-3*r,T=r;let S=a;for(let C=0;C<5;C++){const w=C0(S,p,f,m,y);let R=E0(S,p,f,m);R===1/0&&(R=a),S-=(w-a)*R,S=Math.min(Math.max(S,0),1)}return M0(S,g,_,b,T)}const lh=a=>{a?.dispose()},jh=a=>{if(a)if(Array.isArray(a))a.forEach(e=>jh(e));else{for(const e in a){const t=a[e];t!==null&&t instanceof x.Texture&&lh(t)}if(a.isShaderMaterial===!0){const e=a;for(const t in e.uniforms){const s=e.uniforms[t];s.value!==null&&s.value instanceof x.Texture&&lh(s.value)}}a.dispose()}},Is=a=>{if(a){for(;a.children.length>0;){const e=a.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):Is(e)}if(a.parent&&a.parent.remove(a),a.isMesh){const e=a;e.geometry?.dispose(),jh(e.material)}a.dispose!==void 0&&a.dispose()}};exports.totalThreeObjects=0;const ch=()=>{exports.totalThreeObjects=0},ko=a=>{if(!a)return;let e=a.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),a.parent!==null&&a.parent.uuid.length>0&&(e=`${a.parent.uuid}.${e}`),a.uuid=e,a.isMesh!==void 0){const t=a;if(Array.isArray(t.material))t.material.forEach((s,i)=>{s.uuid=`${e}.material.${i}`});else{const s=t.material;s.uuid=`${e}.material`}}a.children.forEach(t=>ko(t))};class Ri{static renderer;static canvas;static context=null;static scene=null;static camera=null;static material=null;static inited=!1;static width=100;static height=100;static init(){this.inited||(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.context=this.canvas.getContext("2d"),this.inited=!0)}static renderToBlob(e){this.init();const t=e.repeat.clone(),s=e.offset.clone();if(e.repeat.set(1,1),e.offset.set(0,0),this.context!==null){this.context.clearRect(0,0,this.width,this.height);const i=e.image;if(i!=null&&i.width>0){this.canvas.title=e.sourceFile;const n=this.canvas.width/i.width,r=this.renderToCanvas(e);this.context.drawImage(r,0,0,i.width*n,i.height*n)}}return e.repeat.copy(t),e.offset.copy(s),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new x.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new x.Scene,this.material=new x.MeshBasicMaterial;const t=new x.BufferGeometry;t.setAttribute("position",new x.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new x.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new x.Float32BufferAttribute([0,0,2,0,0,2],2));const s=new x.Mesh(t,this.material);this.scene.add(s)}if(e.isRenderTargetTexture)this.material.map=e,this.renderer.render(this.scene,this.camera);else{const t=this.renderer.outputColorSpace,s=e.colorSpace;this.renderer.outputColorSpace=x.LinearSRGBColorSpace,e.colorSpace=x.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=s}return this.renderer.domElement}}function R0(a){return new Promise(e=>{const t=new x.ObjectLoader;t.parseAsync(a.scene).then(s=>{const i=new x.AnimationMixer(s);if(a.animations.length>0){const r=a.animations.map(l=>x.AnimationClip.parse(l));i.clipAction(r[0]).play(),i.getRoot().animations=a.animations,i.getRoot().mixer=i}const n=[];a.cameras&&a.cameras.length>0&&a.cameras.forEach(r=>{const o=t.parse(r);n.push(o)}),e({animations:a.animations,model:s,mixer:i,cameras:n})})})}let hh=[];function N0(a,e){Ri.renderer=e.renderer,a.passes.forEach(t=>{const s=[];s.push({type:"boolean",prop:"Enabled",value:t.enabled});let i=(r,o)=>{console.log("Default Handle Pass:",r,o)};if(t instanceof pd.EffectPass)t.effects.forEach((r,o)=>{r.uniforms.size>0&&r.uniforms.forEach((l,c)=>{const h=`${r.name.replace("Effect","")} ${c}`;if(l.value===null)s.push({prop:c,title:h,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(l.value.isTexture){const u=l.value,d=Ri.renderToBlob(u);s.push({prop:c,title:h,type:"image",value:{offset:[u.offset.x,u.offset.y],repeat:[u.repeat.x,u.repeat.y],src:d}})}else typeof l.value=="number"?s.push({prop:c,title:h,type:"number",value:l.value,step:.01}):typeof l.value=="string"?s.push({prop:c,title:h,type:"string",value:l.value}):typeof l.value=="boolean"&&s.push({prop:c,title:h,type:"boolean",value:l.value})})}),i=(r,o)=>{t.effects.forEach(l=>{l.uniforms.size>0&&l.uniforms.forEach((c,h)=>{h===r&&(c.value=o)})})};else if(t instanceof pd.ShaderPass){const r=t.fullscreenMaterial;for(const o in r.uniforms){const l=r.uniforms[o],c=`${r.name.replace("Material","")} ${o}`;if(l.value===null)s.push({title:c,prop:o,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(l.value.isTexture){const h=l.value,u=Ri.renderToBlob(h);s.push({title:c,prop:o,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof l.value=="number"?s.push({title:c,prop:o,type:"number",value:l.value,step:.01}):typeof l.value=="string"?s.push({title:c,prop:o,type:"string",value:l.value}):typeof l.value=="boolean"&&s.push({title:c,prop:o,type:"boolean",value:l.value})}i=(o,l)=>{const c=r.uniforms[o];c.value=l}}else return;const n=`Pass: ${t.name}`;e.addGroup({title:n,items:s,onUpdate:(r,o)=>{r==="Enabled"?t.enabled=o:i(r,o)}}),hh.push(n)})}function P0(a){hh.forEach(e=>{a.removeGroup(e)}),hh=[]}function D0(a,e,t,s=1024){return new Promise(i=>{const n=e.aspect,r=e.fov,o=e.rotation.clone(),l=t.outputBuffer;e.aspect=1,e.fov=90,e.updateProjectionMatrix();const c=new x.WebGLRenderTarget(s,s,{format:x.RGBAFormat,depthBuffer:!0,stencilBuffer:!1});t.outputBuffer=c,_n(a,c,e,"nx",t,s).then(()=>{_n(a,c,e,"ny",t,s).then(()=>{_n(a,c,e,"nz",t,s).then(()=>{_n(a,c,e,"px",t,s).then(()=>{_n(a,c,e,"py",t,s).then(()=>{_n(a,c,e,"pz",t,s).then(()=>{e.aspect=n,e.fov=r,e.rotation.copy(o),e.updateMatrixWorld(),e.updateProjectionMatrix(),t.outputBuffer=l,c.dispose(),i()})})})})})})})}function _n(a,e,t,s,i,n){return new Promise(r=>{const o=Math.PI/2;switch(s){case"nx":t.rotation.set(0,-o,0);break;case"ny":t.rotation.set(-o,0,Math.PI);break;case"nz":t.rotation.set(0,0,0);break;case"px":t.rotation.set(0,o,0);break;case"py":t.rotation.set(o,0,Math.PI);break;case"pz":t.rotation.set(0,Math.PI,0);break}t.updateMatrixWorld(),i.render();const l=new Uint8Array(n*n*4);a.readRenderTargetPixels(e,0,0,n,n,l);const c=document.createElement("canvas");c.width=c.height=n;const h=c.getContext("2d"),u=h.createImageData(n,n);u.data.set(l),h.putImageData(u,0,0);const d=document.createElement("canvas");d.width=d.height=n;const p=d.getContext("2d");p.translate(0,n),p.scale(1,-1),p.drawImage(c,0,0);const f=d.toDataURL("image/png"),m=document.createElement("a");m.href=f,m.download=`${t.name}_${s}.png`,document.body.appendChild(m),m.click(),m.remove(),r()})}const bn=qh(["ctrlKey","metaKey","shiftKey","button","pointerId","pointerType","clientX","clientY","pageX","pageY"]),F0=qh(["clientX","clientY","deltaX","deltaY","deltaMode"]),O0=qh(["ctrlKey","metaKey","shiftKey","keyCode"]);function B0(a,e){a.preventDefault(),F0(a,e)}function I0(a){a.preventDefault()}function L0(a,e,t){for(const s of e)t[s]=a[s]}function qh(a){return function(t,s){const i={type:t.type};L0(t,a,i),s(i)}}function Ll(a,e){const t=[],s={type:a.type,touches:t};for(let i=0;i<a.touches.length;++i){const n=a.touches[i];t.push({pageX:n.pageX,pageY:n.pageY})}e(s)}const U0={37:!0,38:!0,39:!0,40:!0};function k0(a,e){const{keyCode:t}=a;U0[t]&&(a.preventDefault(),O0(a,e))}const z0={contextmenu:I0,mousedown:bn,mousemove:bn,mouseup:bn,pointerdown:bn,pointermove:bn,pointerup:bn,touchstart:Ll,touchmove:Ll,touchend:Ll,wheel:B0,keydown:k0};let G0=0;class V0{id;worker;constructor(e,t,s){this.id=G0++,this.worker=t;const i=r=>{this.worker.postMessage({type:"event",id:this.id,data:r})};t.postMessage({type:"makeProxy",id:this.id});for(const[r,o]of Object.entries(s))e.addEventListener(r,l=>{o(l,i)});function n(){i({type:"resize",left:0,top:0,width:innerWidth,height:innerHeight})}window.addEventListener("resize",n),n()}}class sm extends x.EventDispatcher{style={};left=0;top=0;width=0;height=0;ownerDocument=void 0;constructor(){super(),this.ownerDocument=this}get clientWidth(){return this.width}set clientWidth(e){this.width=e}get clientHeight(){return this.height}set clientHeight(e){this.height=e}setPointerCapture(){}releasePointerCapture(){}getBoundingClientRect(){return{x:this.left,y:this.top,left:this.left,top:this.top,width:this.width,height:this.height,right:this.left+this.width,bottom:this.top+this.height,toJSON:()=>({})}}handleEvent(e){if(e.type==="size"){this.left=e.left,this.top=e.top,this.width=e.width,this.height=e.height;return}e.preventDefault=da,e.stopPropagation=da,this.dispatchEvent(e)}focus(){}getRootNode(){return this}}class H0{targets={};constructor(){this.handleEvent=this.handleEvent.bind(this)}makeProxy(e){const{id:t}=e,s=new sm;this.targets[t]=s}getProxy(e){return this.targets[e]}handleEvent(e){this.targets[e.id]?.handleEvent(e.data)}}var X=(a=>(a.CUSTOM="ToolEvents::custom",a.REMOTE_CONNECTED="ToolEvents::remoteConnected",a.REMOTE_DISCONNECTED="ToolEvents::remoteDisconnected",a.SELECT_DROPDOWN="ToolEvents::selectDropdown",a.DRAG_UPDATE="ToolEvents::dragUpdate",a.ADD_SCENE="ToolEvents::addScene",a.REFRESH_SCENE="ToolEvents::refreshScene",a.REMOVE_SCENE="ToolEvents::removeScene",a.SET_SCENE="ToolEvents::setScene",a.GET_OBJECT="ToolEvents::getObject",a.SET_OBJECT="ToolEvents::setObject",a.CLEAR_OBJECT="ToolEvents::clearObject",a.UPDATE_OBJECT="ToolEvents::updateObject",a.CREATE_TEXTURE="ToolEvents::createTexture",a.REQUEST_METHOD="ToolEvents::requestMethod",a.ADD_CAMERA="ToolEvents::addCamera",a.REMOVE_CAMERA="ToolEvents::removeCamera",a.ADD_GROUP="ToolEvents::addGroup",a.REMOVE_GROUP="ToolEvents::removeGroup",a.ADD_SPLINE="ToolEvents::addSpline",a.ADD_RENDERER="ToolEvents::addRenderer",a.UPDATE_RENDERER="ToolEvents::updateRenderer",a))(X||{});class W0 extends x.EventDispatcher{assets={audio:new Map,image:new Map,json:new Map,model:new Map,video:new Map};components=new Map;settings={dpr:1,fps:30,width:0,height:0,mobile:!1,supportOffScreenCanvas:!1,supportWebGPU:!1,quality:"Low",dev:!1,editor:!1};appHandlers=[];editorHandlers=[];onUpdateCallback;_appID="";_mode="app";_broadcastChannel=void 0;_webSocket=void 0;_connected=!1;_useBC=!1;playing=!1;rafID=-1;_pingInterval;_lastPingTime=0;_pingTimeout=3e3;_peerConnected=!1;constructor(e){super(),this._appID=e}dispose(){this.stopPing(),this._broadcastChannel!==void 0&&this._broadcastChannel.removeEventListener("message",this.messageHandler),this._webSocket!==void 0&&(this._webSocket.removeEventListener("open",this.openHandler),this._webSocket.removeEventListener("close",this.closeHandler),this._webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(e=>{e.dispose()}),this.components.clear()}detectSettings(e=!1,t=!1){return this._mode=t?"editor":"app",new Promise(s=>{tm(e,t).then(i=>{this.settings=i,s()})})}update(){}draw(){}play=()=>{this.playing||(this.playing=!0,this.onUpdate())};pause=()=>{this.playing&&(this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1)};onUpdate=()=>{this.update(),this.isApp&&this.draw(),this.onUpdateCallback&&this.onUpdateCallback(),this.rafID=requestAnimationFrame(this.onUpdate)};setupRemote(e=!0){this.settings.dev&&(this._useBC=e,e?(this._broadcastChannel=new BroadcastChannel(this._appID),this._broadcastChannel.addEventListener("message",this.messageHandler),this.startPing()):(this._webSocket=new WebSocket(this._appID),this._webSocket.addEventListener("open",this.openHandler),this._webSocket.addEventListener("close",this.closeHandler),this._webSocket.addEventListener("message",this.messageHandler)))}addComponent(e,t){this.components.set(e,t)}send(e){this._mode!==e.target&&(this._useBC?this._broadcastChannel?.postMessage(e):this._connected&&this._webSocket?.send(JSON.stringify(e)))}messageHandler=e=>{let t=e.data;this._useBC||(t=JSON.parse(e.data)),t.target==="editor"?this.handleEditorBroadcast(t):this.handleAppBroadcast(t)};handleAppBroadcast(e){switch(this.appHandlers.forEach(t=>{t.callback(e)}),e.event){case"ping":this.handlePing(e);break;case"custom":this.dispatchEvent({type:"ToolEvents::custom",value:e.data});break}}handleEditorBroadcast(e){switch(this.editorHandlers.forEach(t=>{t.callback(e)}),e.event){case"ping":this.handlePing(e);break;case"custom":this.dispatchEvent({type:"ToolEvents::custom",value:e.data});break}}openHandler=()=>{this._connected=!0,this.startPing()};closeHandler=()=>{this._connected=!1,this._peerConnected=!1,this.stopPing()};get appID(){return this._appID}get connected(){return this._connected}get debugEnabled(){return this.settings.dev}get mode(){return this._mode}get isApp(){return!this.editor}set isApp(e){this.editor=!e}get editor(){return this.settings.editor}set editor(e){this.settings.editor=e,this._mode=e?"editor":"app"}get peerConnected(){return this._peerConnected}startPing(){this.stopPing(),this._pingInterval=setInterval(()=>{this._mode==="app"&&this.sendPing(),this.checkPingTimeout()},1e3)}stopPing(){this._pingInterval!==void 0&&(clearInterval(this._pingInterval),this._pingInterval=void 0)}sendPing(){const e=this._mode==="app"?"editor":"app";this.send({target:e,event:"ping",data:Date.now()})}handlePing(e){this._lastPingTime=Date.now(),this._peerConnected||this.dispatchEvent({type:"ToolEvents::remoteConnected"}),this._peerConnected=!0;const t=this._mode==="app"?"editor":"app";e.data!=="pong"&&this.send({target:t,event:"ping",data:"pong"})}checkPingTimeout(){const e=Date.now();if(this._peerConnected&&e-this._lastPingTime>this._pingTimeout){const t=this._peerConnected;this._peerConnected=!1,t&&this.dispatchEvent({type:"ToolEvents::remoteDisconnected"})}}}class $0{canvas;inputElement;settings;playing=!1;rafID=-1;constructor(e,t,s){this.canvas=e,this.inputElement=t,this.settings=s}dispose(){this.stop()}play(){this.playing||(this.playing=!0,this.onUpdate())}stop(){this.playing&&(this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1)}update(){}draw(){}resize(e,t){this.settings.supportOffScreenCanvas&&(this.inputElement.clientWidth=e,this.inputElement.clientHeight=t,this.inputElement.width=e,this.inputElement.height=t)}onResize=e=>{this.resize(e.width,e.height)};onUpdate=()=>{this.update(),this.draw(),this.rafID=requestAnimationFrame(this.onUpdate)}}class j0 extends x.Scene{clock;cameras;lights;world;constructor(e){super(),this.name=e,this.clock=new x.Clock,this.lights=new x.Group,this.lights.name="lights",this.add(this.lights),this.cameras=new x.Group,this.cameras.name="cameras",this.add(this.cameras),this.world=new x.Group,this.world.name="world",this.add(this.world)}init(){return new Promise(e=>{this.setupLights().then(()=>this.setupCameras()).then(()=>this.setupWorld()).then(()=>this.setupPost()).then(()=>this.setupAnimation()).then(()=>this.setupDebug()).then(()=>e())})}setupLights(){return new Promise(e=>{e()})}setupCameras(){return new Promise(e=>{e()})}setupWorld(){return new Promise(e=>{e()})}setupPost(){return new Promise(e=>{e()})}setupAnimation(){return new Promise(e=>{e()})}setupDebug(){return new Promise(e=>{e()})}dispose(){}update(){}draw(e){}postDraw(){}resize(e,t,s){}show(){this.clock.start(),this.showComplete()}showComplete(){this.enable()}hide(){this.disable(),this.hideComplete()}hideComplete(){this.clock.stop()}enable(){}disable(){}get deltaTime(){return Math.min(this.clock.getDelta(),1/30)}}class ol{app;constructor(e){this.app=e,this.app.appHandlers.push({remote:this,callback:this.handleApp.bind(this)}),this.app.editorHandlers.push({remote:this,callback:this.handleEditor.bind(this)})}dispose(){const e=this.app.appHandlers.findIndex(t=>t.remote===this);e>-1&&(this.app.appHandlers.splice(e,1),this.app.editorHandlers.splice(e,1))}handleApp(e){}handleEditor(e){}}class q0 extends ol{selectDropdown(e,t){this.app.send({event:"selectComponent",target:"app",data:{dropdown:e,value:t}})}updateDropdown(e,t){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:e,value:t}})}handleApp(e){switch(e.event){case"selectComponent":this.app.dispatchEvent({type:X.SELECT_DROPDOWN,value:e.data});break;case"draggableListUpdate":this.app.dispatchEvent({type:X.DRAG_UPDATE,value:e.data});break}}}function Y0(a,e,t){if(a.editor){t.ui.restore(),t.onSelectionChange(r=>{r.length<1||r.forEach(o=>{let l=o.address.sheetId,c="setSheet",h={};switch(o.type){case"Theatre_Sheet_PublicAPI":c="setSheet",h={sheet:o.address.sheetId},e.activeSheet=e.sheets.get(o.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",l+=`_${o.address.objectKey}`,h={id:l,sheet:o.address.sheetId,key:o.address.objectKey},e.activeSheet=e.sheets.get(o.address.sheetId);break}a.send({event:c,target:"app",data:h})})});let s=-1;const i=()=>{if(e.activeSheet!==void 0&&s!==e.activeSheet.sequence.position){s=e.activeSheet.sequence.position;const r=e.activeSheet;a.send({event:"updateTimeline",target:"app",data:{position:s,sheet:r.address.sheetId}})}},n=()=>{i(),requestAnimationFrame(n)};i(),n()}else t.ui.hide()}async function X0(){for(;!document.getElementById("theatrejs-studio-root");)await new Promise(s=>setTimeout(s,100));const a=document.getElementById("theatrejs-studio-root");if(a===null||a.shadowRoot===null)return;const e=a.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t!==null){try{const i=t.children[1].children[1];i.parentElement?.removeChild(i)}catch{}try{const s=t.children[3];s.style.top="0",s.style.right="300px"}catch{}}}function Z0(a,e,t,s,i){const n=1-a;return n*n*n*e+3*n*n*a*t+3*n*a*a*s+a*a*a*i}function Q0(a,e,t){if(a.type!=="bezier"||a.handles.length!==4)throw new Error("Invalid keyframe data for Bézier interpolation.");const[s,i]=a.handles,n=(t-a.position)/(e.position-a.position);return Z0(n,a.value,a.value+s,e.value+i,e.value)}class K0 extends ol{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;rafDriver=void 0;constructor(e,t=!1){super(e),t&&(this.rafDriver=p0.createRafDriver())}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}update(e){this.rafDriver?.tick(e)}getSheetInstance(e,t){return t!==void 0?`${e}-${t}`:e}sheet(e,t){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const s=this.getSheetInstance(e,t);let i=this.sheets.get(s);return i!==void 0||(i=this.project?.sheet(e,t),this.sheets.set(s,i)),i}playSheet(e,t,s){return new Promise(i=>{const n=t!==void 0?{...t}:{};n.rafDriver=this.rafDriver,this.sheet(e,s)?.sequence.play(n).then(r=>i(r)),this.app.send({event:"playSheet",target:"editor",data:{sheet:e,instance:s,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:e,instance:t}})}clearSheetObjects(e){this.sheetObjects.forEach((t,s)=>{s.search(`${e}_`)>-1&&this.unsubscribe(t)})}sheetObject(e,t,s,i,n){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const r=this.sheet(e,n);if(r===void 0)return;const l=`${this.getSheetInstance(e,n)}_${t}`;let c=this.sheetObjects.get(l),h=s;c!==void 0&&(h={...s,...c.value}),c=r.object(t,h),this.sheetObjects.set(l,c),this.sheetObjectCBs.set(l,i!==void 0?i:da);const u=c.onValuesChange(d=>{if(this.app.editor){for(const f in d){const m=d[f];typeof m=="object"&&Kf(m)&&(d[f]={r:m.r,g:m.g,b:m.b,a:m.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:l,values:d}})}const p=this.sheetObjectCBs.get(l);p!==void 0&&p(d)},this.rafDriver);return this.sheetObjectUnsubscribe.set(l,u),c}getSheetObjectKeyframes(e,t,s){const i=this.sheet(e);if(i===void 0)return[];const n=`${e}_${t}`,r=this.sheetObjects.get(n);return r===void 0?[]:i.sequence.__experimental_getKeyframes(r.props[s])}getSheetObjectVectors(e,t){const s=this.sheet(e);if(s===void 0)return[];const i=`${e}_${t}`,n=this.sheetObjects.get(i);if(n===void 0)return[];const r=[],o=s.sequence.__experimental_getKeyframes(n.props.x),l=s.sequence.__experimental_getKeyframes(n.props.y),c=s.sequence.__experimental_getKeyframes(n.props.z),h=new Set;return o.forEach(d=>h.add(d.position)),l.forEach(d=>h.add(d.position)),c.forEach(d=>h.add(d.position)),Array.from(h).sort((d,p)=>d-p).forEach(d=>{const p=(f,m)=>{const y=f.find((b,T)=>b.position<=m&&(f[T+1]?.position||1/0)>m),g=f.find(b=>b.position>m);if(!y)return g?.value||0;if(!g||y.position===m)return y.value;if(y.type==="bezier")return Q0(y,g,m);const _=(m-y.position)/(g.position-y.position);return y.value+_*(g.value-y.value)};r.push({position:d,x:p(o,d),y:p(l,d),z:p(c,d)})}),r}unsubscribe(e){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const t=e.address.sheetId,s=e.address.objectKey;this.sheets.get(t)?.detachObject(s);const n=`${t}_${s}`,r=this.sheetObjectUnsubscribe.get(n);r!==void 0&&(this.sheetObjects.delete(n),this.sheetObjectCBs.delete(n),this.sheetObjectUnsubscribe.delete(n),r())}handleApp(e){let t;switch(e.event){case"setSheet":t=this.sheets.get(e.data.sheet),t!==void 0&&(this.activeSheet=t,this.studio?.setSelection([t]));break;case"setSheetObject":t=this.sheetObjects.get(`${e.data.sheet}_${e.data.key}`),t!==void 0&&this.studio?.setSelection([t]);break;case"updateSheetObject":t=this.sheets.get(e.data.sheet),t!==void 0&&t.sequence.pause(),t=this.sheetObjectCBs.get(e.data.sheetObject),t!==void 0&&t(e.data.values);break;case"updateTimeline":t=this.sheets.get(e.data.sheet),this.activeSheet!==void 0&&(this.activeSheet.sequence.position=e.data.position);break}}handleEditor(e){if(this.app.editor)switch(e.event){case"playSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.play({...e.data.value,rafDriver:this.rafDriver});break;case"pauseSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.pause();break}}handleEditorApp(){if(this.app.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(i=>{i.length<1||i.forEach(n=>{let r=n.address.sheetId,o="setSheet",l={};switch(n.type){case"Theatre_Sheet_PublicAPI":o="setSheet",l={sheet:n.address.sheetId},this.activeSheet=this.sheets.get(n.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":o="setSheetObject",r+=`_${n.address.objectKey}`,l={id:r,sheet:n.address.sheetId,key:n.address.objectKey},this.activeSheet=this.sheets.get(n.address.sheetId);break}this.app.send({event:o,target:"app",data:l})})});let e=-1;const t=()=>{if(this.activeSheet!==void 0&&e!==this.activeSheet.sequence.position){e=this.activeSheet.sequence.position;const i=this.activeSheet;this.app.send({event:"updateTimeline",target:"app",data:{position:e,sheet:i.address.sheetId}})}},s=()=>{t(),requestAnimationFrame(s)};t(),s()}else this.studio?.ui.hide()}}function J0(a){if(a.name==="cameras")return"camera";if(a.name==="interactive")return"interactive";if(a.name==="lights")return"light";if(a.name==="ui")return"ui";if(a.name==="utils")return"utils";const e=a.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function Hn(a){const e={name:a.name,type:a.type,uuid:a.uuid,children:[]};return a.children.forEach(t=>{e.children.push(Hn(t))}),e}function ex(a){const e={};for(const t in a){const s=a[t].value;e[t]={value:s},s===null?e[t].value={src:"",offset:[0,0],repeat:[1,1]}:s!==void 0&&s.isTexture&&(e[t].value={src:s.image.src,offset:[s.offset.x,s.offset.y],repeat:[s.repeat.x,s.repeat.y]})}return e}function tx(a){switch(a){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Tn(a){const e={};for(const t in a){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||tx(t))continue;const s=typeof a[t],i=a[t];switch(s){case"boolean":case"number":case"string":e[t]=i;break;case"object":i!==null?(e[t]=i,i.isTexture?e[t]={src:Ri.renderToBlob(i),offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]}:t==="uniforms"&&(e[t]=ex(e[t]))):t==="glslVersion"?e[t]="":e[t]={src:"",offset:[0,0],repeat:[1,1]};break}}return a.anisotropy!==void 0&&(e.anisotropy=a.anisotropy),a.clearcoat!==void 0&&(e.clearcoat=a.clearcoat),a.iridescence!==void 0&&(e.iridescence=a.iridescence),a.dispersion!==void 0&&(e.dispersion=a.dispersion),a.sheen!==void 0&&(e.sheen=a.sheen),a.transmission!==void 0&&(e.transmission=a.transmission),a.transmission!==void 0&&(e.transmission=a.transmission),e}function Ul(a){a.updateMatrix();const e={name:a.name,type:a.type,uuid:a.uuid,visible:a.visible,matrix:a.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};a.animations.forEach(s=>{e.animations.push({name:s.name,duration:s.duration,blendMode:s.blendMode})});const t=a.type.toLowerCase();if(t.search("mesh")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else if(t.search("points")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else if(t.search("line")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else t.search("camera")>-1?a.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:a.fov,zoom:a.zoom,near:a.near,far:a.far,focus:a.focus,aspect:a.aspect,filmGauge:a.filmGauge,filmOffset:a.filmOffset}:a.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:a.zoom,near:a.near,far:a.far,left:a.left,right:a.right,top:a.top,bottom:a.bottom}):t.search("light")>-1&&(e.lightInfo={color:a.color,intensity:a.intensity,decay:a.decay,distance:a.distance,angle:a.angle,penumbra:a.penumbra,groundColor:a.groundColor,width:a.width,height:a.height});return e}function sx(a,e){const t=e.split(".");switch(t.length){case 1:return a[t[0]];case 2:return a[t[0]][t[1]];case 3:return a[t[0]][t[1]][t[2]];case 4:return a[t[0]][t[1]][t[2]][t[3]];case 5:return a[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return a[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function ix(a,e){for(const t in e)a[t]=e[t]}function qe(a,e,t){if(a===void 0)return;const s=e.split("."),i=s.length;if(typeof t!="object")switch(i){case 1:a[s[0]]=t;break;case 2:a[s[0]][s[1]]=t;break;case 3:a[s[0]][s[1]][s[2]]=t;break;case 4:a[s[0]][s[1]][s[2]][s[3]]=t;break;case 5:a[s[0]][s[1]][s[2]][s[3]][s[4]]=t;break}else{let r;switch(i){case 1:r=a[s[0]];break;case 2:r=a[s[0]][s[1]];break;case 3:r=a[s[0]][s[1]][s[2]];break;case 4:r=a[s[0]][s[1]][s[2]][s[3]];break;case 5:r=a[s[0]][s[1]][s[2]][s[3]][s[4]];break}r!=null&&ix(r,t)}}function im(a){return new Promise((e,t)=>{const s=new Image;s.onload=()=>{const i=new x.Texture(s);i.wrapS=x.RepeatWrapping,i.wrapT=x.RepeatWrapping,i.needsUpdate=!0,e(i)},s.onerror=t,s.src=a})}class nx extends ol{canvas=null;inputElement=null;scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;renderTargetsResize=new Map;groups=new Map;dispose(){this.scenes.forEach(e=>{Is(e)}),this.scenes.clear(),this.scene&&Is(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}getObject(e){this.app.debugEnabled&&(this.renderer!==void 0&&(Ri.renderer=this.renderer),this.app.send({event:"getObject",target:"app",data:e}))}setObject(e){this.renderer!==void 0&&(Ri.renderer=this.renderer);const t=Ul(e);this.app.send({event:"setObject",target:"editor",data:t})}requestMethod(e,t,s,i){this.app.send({event:"requestMethod",target:"app",data:{uuid:e,key:t,value:s,subitem:i}})}updateObject(e,t,s){this.app.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:s}})}createTexture(e,t,s){this.app.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:s}})}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.app.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.app.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,s){this.app.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:s})})}addSpline(e){setTimeout(()=>{this.app.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}setRenderer(e,t=null){if(this.renderer=e,this.canvas=e.domElement,this.inputElement=t!==null?t:this.canvas,!this.app.debugEnabled)return;const s=`#${e.getClearColor(new x.Color).getHexString()}`;this.app.send({event:"addRenderer",target:"editor",data:{autoClear:e.autoClear,autoClearColor:e.autoClearColor,autoClearDepth:e.autoClearDepth,autoClearStencil:e.autoClearStencil,outputColorSpace:e.outputColorSpace,localClippingEnabled:e.localClippingEnabled,clearColor:s,clearAlpha:e.getClearAlpha(),colorManagement:x.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure,type:e.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}updateRenderer(e){this.app.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.app.debugEnabled))return;ch(),ko(e);const t=Hn(e);this.app.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.app.debugEnabled)return;const t=this.scenes.get(e);if(t!==void 0){const s=Hn(t);this.app.send({event:"refreshScene",target:"app",data:s})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.app.debugEnabled))return;const t=Hn(e);this.app.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scenes.forEach((s,i)=>{e.search(i)>-1&&(t=s)}),t}setScene(e){if(e===void 0||(this.scene=e,!this.app.debugEnabled))return;this.renderer!==void 0&&(Ri.renderer=this.renderer),ch(),ko(e);const t=Hn(e);this.app.send({event:"setScene",target:"editor",data:t})}addCamera(e){if(!this.app.debugEnabled)return;const t=Ul(e);this.app.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.app.debugEnabled)return;const t=Ul(e);this.app.send({event:"removeCamera",target:"editor",data:t})}handleApp(e){switch(e.event){case"getObject":this.app.dispatchEvent({type:X.GET_OBJECT,value:e.data});break;case"updateObject":this.app.dispatchEvent({type:X.UPDATE_OBJECT,value:e.data});break;case"createTexture":this.app.dispatchEvent({type:X.CREATE_TEXTURE,value:e.data});break;case"requestMethod":this.app.dispatchEvent({type:X.REQUEST_METHOD,value:e.data});break;case"refreshScene":this.app.send({event:"refreshScene",target:"editor",data:Hn(this.scenes.get(e.data.name))});break;case"updateRenderer":this.renderer&&(this.renderer.autoClearColor=e.data.autoClearColor,this.renderer.outputColorSpace=e.data.outputColorSpace,this.renderer.localClippingEnabled=e.data.localClippingEnabled,this.renderer.setClearColor(e.data.clearColor,e.data.clearAlpha),this.renderer.toneMapping=e.data.toneMapping,this.renderer.toneMappingExposure=e.data.toneMappingExposure,x.ColorManagement.enabled=e.data.colorManagement);break}if(e.event==="updateGroup"){const t=JSON.parse(e.data);this.groups.get(t.group)?.onUpdate(t.prop,t.value)}}handleEditor(e){switch(e.event){case"setObject":this.app.dispatchEvent({type:X.SET_OBJECT,value:e.data});break;case"addScene":this.app.dispatchEvent({type:X.ADD_SCENE,value:e.data});break;case"refreshScene":this.app.dispatchEvent({type:X.REFRESH_SCENE,value:e.data});break;case"removeScene":this.app.dispatchEvent({type:X.REMOVE_SCENE,value:e.data});break;case"setScene":this.app.dispatchEvent({type:X.SET_SCENE,value:e.data});break;case"addCamera":this.app.dispatchEvent({type:X.ADD_CAMERA,value:e.data});break;case"removeCamera":this.app.dispatchEvent({type:X.REMOVE_CAMERA,value:e.data});break;case"addGroup":this.app.dispatchEvent({type:X.ADD_GROUP,value:e.data});break;case"removeGroup":this.app.dispatchEvent({type:X.REMOVE_GROUP,value:e.data});break;case"addSpline":this.app.dispatchEvent({type:X.ADD_SPLINE,value:e.data});break;case"addRenderer":this.app.dispatchEvent({type:X.ADD_RENDERER,value:e.data})}}addRT(e,t=!0,s){const i=new x.WebGLRenderTarget(32,32,s);i.texture.name=e,this.renderTargets.set(e,i),this.renderTargetsResize.set(e,t)}removeRT(e){this.renderTargets.delete(e),this.renderTargetsResize.delete(e)}resize(e,t){const s=this.dpr;this.renderTargets.forEach((n,r)=>{this.renderTargetsResize.get(r)&&n.setSize(e*s,t*s)});const i=!(this.renderer?.domElement instanceof OffscreenCanvas);this.renderer?.setSize(e,t,i)}set dpr(e){this.renderer?.setPixelRatio(Ti(1,2,e))}get dpr(){return this.renderer!==void 0?this.renderer?.getPixelRatio():1}get width(){return this.renderer!==void 0?this.renderer.domElement.width/this.dpr:0}get height(){return this.renderer!==void 0?this.renderer.domElement.height/this.dpr:0}}var Da={exports:{}},Tr={};/**
18
+ `,d=c.createShader(35633),p=c.createShader(35632),f=c.createProgram();if(!(p&&d&&f))return;c.shaderSource(d,h),c.shaderSource(p,u),c.compileShader(d),c.compileShader(p),c.attachShader(f,d),c.attachShader(f,p),c.linkProgram(f),c.detachShader(f,d),c.detachShader(f,p),c.deleteShader(d),c.deleteShader(p),c.useProgram(f);const m=c.createBuffer();c.bindBuffer(34962,m),c.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const y=c.getAttribLocation(f,"aPosition");c.vertexAttribPointer(y,3,5126,!1,0,0),c.enableVertexAttribArray(y),c.clearColor(1,1,1,1),c.clear(16384),c.viewport(0,0,1,1),c.drawArrays(4,0,3);const g=new Uint8Array(4);return c.readPixels(0,0,1,1,6408,5121,g),c.deleteProgram(f),c.deleteBuffer(m),g.join("")}(a),i="801621810",n="8016218135",r="80162181161",o=Ps?.isIpad?[["a7",r,12],["a8",n,15],["a8x",n,15],["a9",n,15],["a9x",n,15],["a10",n,15],["a10x",n,15],["a12",i,15],["a12x",i,15],["a12z",i,15],["a14",i,15],["a15",i,15],["m1",i,15],["m2",i,15]]:[["a7",r,12],["a8",n,12],["a9",n,15],["a10",n,15],["a11",i,15],["a12",i,15],["a13",i,15],["a14",i,15],["a15",i,15],["a16",i,15],["a17",i,15]];let l;return s==="80162181255"?l=o.filter(([,,c])=>c>=14):(l=o.filter(([,c])=>c===s),l.length||(l=o)),l.map(([c])=>`apple ${c} gpu`)}class md extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}const Il=[],gd=[];function y0(a,e){if(a===e)return 0;const t=a;a.length>e.length&&(a=e,e=t);let s=a.length,i=e.length;for(;s>0&&a.charCodeAt(~-s)===e.charCodeAt(~-i);)s--,i--;let n,r=0;for(;r<s&&a.charCodeAt(r)===e.charCodeAt(r);)r++;if(s-=r,i-=r,s===0)return i;let o,l,c=0,h=0,u=0;for(;h<s;)gd[h]=a.charCodeAt(r+h),Il[h]=++h;for(;u<i;)for(n=e.charCodeAt(r+u),o=u++,c=u,h=0;h<s;h++)l=n===gd[h]?o:o+1,o=Il[h],c=Il[h]=o>c?l>c?c+1:l:l>o?o+1:l;return c}function x0(a){return a!=null}const _0=({mobileTiers:a=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:t={},glContext:s,failIfMajorPerformanceCaveat:i=!1,benchmarksURL:n="https://unpkg.com/detect-gpu@5.0.70/dist/benchmarks"}={})=>Bl(void 0,void 0,void 0,function*(){const r={};if(Jf)return{tier:0,type:"SSR"};const{isIpad:o=!!Ps?.isIpad,isMobile:l=!!Ps?.isMobile,screenSize:c=window.screen,loadBenchmarks:h=S=>Bl(void 0,void 0,void 0,function*(){const C=yield fetch(`${n}/${S}`).then(w=>w.json());if(parseInt(C.shift().split(".")[0],10)<4)throw new md("Detect GPU benchmark data is out of date. Please update to version 4x");return C})}=t;let{renderer:u}=t;const d=(S,C,w,R,P)=>({device:P,fps:R,gpu:w,isMobile:l,tier:S,type:C});let p,f="";if(u)u=fd(u),p=[u];else{const S=s||function(w,R=!1){const P={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:R,powerPreference:"high-performance",stencil:!1};w&&delete P.powerPreference;const z=window.document.createElement("canvas"),$=z.getContext("webgl",P)||z.getContext("experimental-webgl",P);return $??void 0}(Ps?.isSafari12,i);if(!S)return d(0,"WEBGL_UNSUPPORTED");const C=Ps?.isFirefox?null:S.getExtension("WEBGL_debug_renderer_info");if(u=C?S.getParameter(C.UNMASKED_RENDERER_WEBGL):S.getParameter(S.RENDERER),!u)return d(1,"FALLBACK");f=u,u=fd(u),p=function(w,R,P){return R==="apple gpu"?g0(w,R,P):[R]}(S,u,l)}const m=(yield Promise.all(p.map(function(S){var C;return Bl(this,void 0,void 0,function*(){const w=(be=>{const at=l?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce","adreno"];for(const Ft of at)if(be.includes(Ft))return Ft})(S);if(!w)return;const R=`${l?"m":"d"}-${w}${o?"-ipad":""}.json`,P=r[R]=(C=r[R])!==null&&C!==void 0?C:h(R);let z;try{z=yield P}catch(be){if(be instanceof md)throw be;return}const $=function(be){var at;const Ft=(be=be.replace(/\([^)]+\)/,"")).match(/\d+/)||be.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return(at=Ft?.join("").replace(/\W|amd/g,""))!==null&&at!==void 0?at:""}(S);let q=z.filter(([,be])=>be===$);q.length||(q=z.filter(([be])=>be.includes(S)));const j=q.length;if(j===0)return;const Z=S.split(/[.,()\[\]/\s]/g).sort().filter((be,at,Ft)=>at===0||be!==Ft[at-1]).join(" ");let Q,[we,,,,ue]=j>1?q.map(be=>[be,y0(Z,be[2])]).sort(([,be],[,at])=>be-at)[0][0]:q[0],ge=Number.MAX_VALUE;const{devicePixelRatio:ie}=window,Ee=c.width*ie*c.height*ie;for(const be of ue){const[at,Ft]=be,_r=at*Ft,gn=Math.abs(Ee-_r);gn<ge&&(ge=gn,Q=be)}if(!Q)return;const[,,ke,rt]=Q;return[ge,ke,we,rt]})}))).filter(x0).sort(([S=Number.MAX_VALUE,C],[w=Number.MAX_VALUE,R])=>S===w?C-R:S-w);if(!m.length){const S=m0.find(C=>u.includes(C));return S?d(0,"BLOCKLISTED",S):d(1,"FALLBACK",`${u} (${f})`)}const[,y,g,_]=m[0];if(y===-1)return d(0,"BLOCKLISTED",g,y,_);const b=l?a:e;let T=0;for(let S=0;S<b.length;S++)y>=b[S]&&(T=S);return d(T,"BENCHMARK",g,y,_)});function em(a){let e=0;const t=performance.now();function s(){e++;const i=performance.now();if(i-t>=100){const n=e/((i-t)/1e3),r=Math.round(n/30)*30;a(r)}else requestAnimationFrame(s)}requestAnimationFrame(s)}function tm(a=!1,e=!1){return new Promise(t=>{_0().then(s=>{let i=!1;const n=document.createElement("canvas"),r=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i="transferControlToOffscreen"in n,r){const l=navigator.userAgent.match(/version\/(\d+)/i);i=(l?parseInt(l[1]):0)>=17}const o={dpr:devicePixelRatio,fps:30,width:innerWidth,height:innerHeight,mobile:s.isMobile!==void 0?s.isMobile:!1,supportOffScreenCanvas:i,supportWebGPU:!!navigator.gpu,quality:"Low",dev:a,editor:e};s.tier===3?o.quality="High":s.tier===2&&(o.quality="Medium"),em(l=>{o.fps=l,t(o)})})})}function Ti(a,e,t){return Math.min(e,Math.max(a,t))}function Uo(a,e,t){return(t-a)/(e-a)}function rr(a,e,t){return a*(1-t)+e*t}function b0(a,e,t,s,i){return rr(t,s,Uo(a,e,i))}function T0(a,e){const t=a-e;return Math.sqrt(t*t)}function ss(a,e=1){return Number(a.toFixed(e))}function S0(a,e,t,s){return rr(a,e,1-Math.exp(-t*s))}function v0(a,e=1){return Number(a.toFixed(e))}function w0(a,e,t,s){return a===e&&t===s}function E0(a,e,t,s){return 1/(3*e*a*a+2*t*a+s)}function C0(a,e,t,s,i){return e*(a*a*a)+t*(a*a)+s*a+i}function M0(a,e,t,s,i){const n=a*a;return e*(n*a)+t*n+s*a+i}function A0(a,e,t,s,i){if(a<=0)return 0;if(a>=1)return 1;if(w0(e,t,s,i))return a;const n=0,r=0,o=e,l=t,c=s,h=i,u=1,d=1,p=u-3*c+3*o-n,f=3*c-6*o+3*n,m=3*o-3*n,y=n,g=d-3*h+3*l-r,_=3*h-6*l+3*r,b=3*l-3*r,T=r;let S=a;for(let C=0;C<5;C++){const w=C0(S,p,f,m,y);let R=E0(S,p,f,m);R===1/0&&(R=a),S-=(w-a)*R,S=Math.min(Math.max(S,0),1)}return M0(S,g,_,b,T)}const lh=a=>{a?.dispose()},jh=a=>{if(a)if(Array.isArray(a))a.forEach(e=>jh(e));else{for(const e in a){const t=a[e];t!==null&&t instanceof x.Texture&&lh(t)}if(a.isShaderMaterial===!0){const e=a;for(const t in e.uniforms){const s=e.uniforms[t];s.value!==null&&s.value instanceof x.Texture&&lh(s.value)}}a.dispose()}},Is=a=>{if(a){for(;a.children.length>0;){const e=a.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):Is(e)}if(a.parent&&a.parent.remove(a),a.isMesh){const e=a;e.geometry?.dispose(),jh(e.material)}a.dispose!==void 0&&a.dispose()}};exports.totalThreeObjects=0;const ch=()=>{exports.totalThreeObjects=0},ko=a=>{if(!a)return;let e=a.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),a.parent!==null&&a.parent.uuid.length>0&&(e=`${a.parent.uuid}.${e}`),a.uuid=e,a.isMesh!==void 0){const t=a;if(Array.isArray(t.material))t.material.forEach((s,i)=>{s.uuid=`${e}.material.${i}`});else{const s=t.material;s.uuid=`${e}.material`}}a.children.forEach(t=>ko(t))};class Ri{static renderer;static canvas;static context=null;static scene=null;static camera=null;static material=null;static inited=!1;static width=100;static height=100;static init(){this.inited||(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.context=this.canvas.getContext("2d"),this.inited=!0)}static renderToBlob(e){this.init();const t=e.repeat.clone(),s=e.offset.clone();if(e.repeat.set(1,1),e.offset.set(0,0),this.context!==null){this.context.clearRect(0,0,this.width,this.height);const i=e.image;if(i!=null&&i.width>0){this.canvas.title=e.sourceFile;const n=this.canvas.width/i.width,r=this.renderToCanvas(e);this.context.drawImage(r,0,0,i.width*n,i.height*n)}}return e.repeat.copy(t),e.offset.copy(s),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new x.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new x.Scene,this.material=new x.MeshBasicMaterial;const t=new x.BufferGeometry;t.setAttribute("position",new x.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new x.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new x.Float32BufferAttribute([0,0,2,0,0,2],2));const s=new x.Mesh(t,this.material);this.scene.add(s)}if(e.isRenderTargetTexture)this.material.map=e,this.renderer.render(this.scene,this.camera);else{const t=this.renderer.outputColorSpace,s=e.colorSpace;this.renderer.outputColorSpace=x.LinearSRGBColorSpace,e.colorSpace=x.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=s}return this.renderer.domElement}}function R0(a){return new Promise(e=>{const t=new x.ObjectLoader;t.parseAsync(a.scene).then(s=>{const i=new x.AnimationMixer(s);if(a.animations.length>0){const r=a.animations.map(l=>x.AnimationClip.parse(l));i.clipAction(r[0]).play(),i.getRoot().animations=a.animations,i.getRoot().mixer=i}const n=[];a.cameras&&a.cameras.length>0&&a.cameras.forEach(r=>{const o=t.parse(r);n.push(o)}),e({animations:a.animations,model:s,mixer:i,cameras:n})})})}let hh=[];function N0(a,e){Ri.renderer=e.renderer,a.passes.forEach(t=>{const s=[];s.push({type:"boolean",prop:"Enabled",value:t.enabled});let i=(r,o)=>{console.log("Default Handle Pass:",r,o)};if(t instanceof pd.EffectPass)t.effects.forEach((r,o)=>{r.uniforms.size>0&&r.uniforms.forEach((l,c)=>{const h=`${r.name.replace("Effect","")} ${c}`;if(l.value===null)s.push({prop:c,title:h,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(l.value.isTexture){const u=l.value,d=Ri.renderToBlob(u);s.push({prop:c,title:h,type:"image",value:{offset:[u.offset.x,u.offset.y],repeat:[u.repeat.x,u.repeat.y],src:d}})}else typeof l.value=="number"?s.push({prop:c,title:h,type:"number",value:l.value,step:.01}):typeof l.value=="string"?s.push({prop:c,title:h,type:"string",value:l.value}):typeof l.value=="boolean"&&s.push({prop:c,title:h,type:"boolean",value:l.value})})}),i=(r,o)=>{t.effects.forEach(l=>{l.uniforms.size>0&&l.uniforms.forEach((c,h)=>{h===r&&(c.value=o)})})};else if(t instanceof pd.ShaderPass){const r=t.fullscreenMaterial;for(const o in r.uniforms){const l=r.uniforms[o],c=`${r.name.replace("Material","")} ${o}`;if(l.value===null)s.push({title:c,prop:o,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(l.value.isTexture){const h=l.value,u=Ri.renderToBlob(h);s.push({title:c,prop:o,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof l.value=="number"?s.push({title:c,prop:o,type:"number",value:l.value,step:.01}):typeof l.value=="string"?s.push({title:c,prop:o,type:"string",value:l.value}):typeof l.value=="boolean"&&s.push({title:c,prop:o,type:"boolean",value:l.value})}i=(o,l)=>{const c=r.uniforms[o];c.value=l}}else return;const n=`Pass: ${t.name}`;e.addGroup({title:n,items:s,onUpdate:(r,o)=>{r==="Enabled"?t.enabled=o:i(r,o)}}),hh.push(n)})}function P0(a){hh.forEach(e=>{a.removeGroup(e)}),hh=[]}function D0(a,e,t,s=1024){return new Promise(i=>{const n=e.aspect,r=e.fov,o=e.rotation.clone(),l=t.outputBuffer;e.aspect=1,e.fov=90,e.updateProjectionMatrix();const c=new x.WebGLRenderTarget(s,s,{format:x.RGBAFormat,depthBuffer:!0,stencilBuffer:!1});t.outputBuffer=c,_n(a,c,e,"nx",t,s).then(()=>{_n(a,c,e,"ny",t,s).then(()=>{_n(a,c,e,"nz",t,s).then(()=>{_n(a,c,e,"px",t,s).then(()=>{_n(a,c,e,"py",t,s).then(()=>{_n(a,c,e,"pz",t,s).then(()=>{e.aspect=n,e.fov=r,e.rotation.copy(o),e.updateMatrixWorld(),e.updateProjectionMatrix(),t.outputBuffer=l,c.dispose(),i()})})})})})})})}function _n(a,e,t,s,i,n){return new Promise(r=>{const o=Math.PI/2;switch(s){case"nx":t.rotation.set(0,-o,0);break;case"ny":t.rotation.set(-o,0,Math.PI);break;case"nz":t.rotation.set(0,0,0);break;case"px":t.rotation.set(0,o,0);break;case"py":t.rotation.set(o,0,Math.PI);break;case"pz":t.rotation.set(0,Math.PI,0);break}t.updateMatrixWorld(),i.render();const l=new Uint8Array(n*n*4);a.readRenderTargetPixels(e,0,0,n,n,l);const c=document.createElement("canvas");c.width=c.height=n;const h=c.getContext("2d"),u=h.createImageData(n,n);u.data.set(l),h.putImageData(u,0,0);const d=document.createElement("canvas");d.width=d.height=n;const p=d.getContext("2d");p.translate(0,n),p.scale(1,-1),p.drawImage(c,0,0);const f=d.toDataURL("image/png"),m=document.createElement("a");m.href=f,m.download=`${t.name}_${s}.png`,document.body.appendChild(m),m.click(),m.remove(),r()})}const bn=qh(["ctrlKey","metaKey","shiftKey","button","pointerId","pointerType","clientX","clientY","pageX","pageY"]),F0=qh(["clientX","clientY","deltaX","deltaY","deltaMode"]),O0=qh(["ctrlKey","metaKey","shiftKey","keyCode"]);function B0(a,e){a.preventDefault(),F0(a,e)}function I0(a){a.preventDefault()}function L0(a,e,t){for(const s of e)t[s]=a[s]}function qh(a){return function(t,s){const i={type:t.type};L0(t,a,i),s(i)}}function Ll(a,e){const t=[],s={type:a.type,touches:t};for(let i=0;i<a.touches.length;++i){const n=a.touches[i];t.push({pageX:n.pageX,pageY:n.pageY})}e(s)}const U0={37:!0,38:!0,39:!0,40:!0};function k0(a,e){const{keyCode:t}=a;U0[t]&&(a.preventDefault(),O0(a,e))}const z0={contextmenu:I0,mousedown:bn,mousemove:bn,mouseup:bn,pointerdown:bn,pointermove:bn,pointerup:bn,touchstart:Ll,touchmove:Ll,touchend:Ll,wheel:B0,keydown:k0};let G0=0;class V0{id;worker;constructor(e,t,s){this.id=G0++,this.worker=t;const i=r=>{this.worker.postMessage({type:"event",id:this.id,data:r})};t.postMessage({type:"makeProxy",id:this.id});for(const[r,o]of Object.entries(s))e.addEventListener(r,l=>{o(l,i)});function n(){i({type:"resize",left:0,top:0,width:innerWidth,height:innerHeight})}window.addEventListener("resize",n),n()}}class sm extends x.EventDispatcher{style={};left=0;top=0;width=0;height=0;ownerDocument=void 0;constructor(){super(),this.ownerDocument=this}get clientWidth(){return this.width}set clientWidth(e){this.width=e}get clientHeight(){return this.height}set clientHeight(e){this.height=e}setPointerCapture(){}releasePointerCapture(){}getBoundingClientRect(){return{x:this.left,y:this.top,left:this.left,top:this.top,width:this.width,height:this.height,right:this.left+this.width,bottom:this.top+this.height,toJSON:()=>({})}}handleEvent(e){if(e.type==="size"){this.left=e.left,this.top=e.top,this.width=e.width,this.height=e.height;return}e.preventDefault=da,e.stopPropagation=da,this.dispatchEvent(e)}focus(){}getRootNode(){return this}}class H0{targets={};constructor(){this.handleEvent=this.handleEvent.bind(this)}makeProxy(e){const{id:t}=e,s=new sm;this.targets[t]=s}getProxy(e){return this.targets[e]}handleEvent(e){this.targets[e.id]?.handleEvent(e.data)}}var X=(a=>(a.CUSTOM="ToolEvents::custom",a.REMOTE_CONNECTED="ToolEvents::remoteConnected",a.REMOTE_DISCONNECTED="ToolEvents::remoteDisconnected",a.SELECT_DROPDOWN="ToolEvents::selectDropdown",a.DRAG_UPDATE="ToolEvents::dragUpdate",a.ADD_SCENE="ToolEvents::addScene",a.REFRESH_SCENE="ToolEvents::refreshScene",a.REMOVE_SCENE="ToolEvents::removeScene",a.SET_SCENE="ToolEvents::setScene",a.GET_OBJECT="ToolEvents::getObject",a.SET_OBJECT="ToolEvents::setObject",a.CLEAR_OBJECT="ToolEvents::clearObject",a.UPDATE_OBJECT="ToolEvents::updateObject",a.CREATE_TEXTURE="ToolEvents::createTexture",a.REQUEST_METHOD="ToolEvents::requestMethod",a.ADD_CAMERA="ToolEvents::addCamera",a.REMOVE_CAMERA="ToolEvents::removeCamera",a.ADD_GROUP="ToolEvents::addGroup",a.REMOVE_GROUP="ToolEvents::removeGroup",a.ADD_SPLINE="ToolEvents::addSpline",a.ADD_RENDERER="ToolEvents::addRenderer",a.UPDATE_RENDERER="ToolEvents::updateRenderer",a))(X||{});class W0 extends x.EventDispatcher{assets={audio:new Map,image:new Map,json:new Map,model:new Map,video:new Map};components=new Map;settings={dpr:1,fps:30,width:0,height:0,mobile:!1,supportOffScreenCanvas:!1,supportWebGPU:!1,quality:"Low",dev:!1,editor:!1};appHandlers=[];editorHandlers=[];onUpdateCallback;_appID="";_mode="app";_broadcastChannel=void 0;_webSocket=void 0;_connected=!1;_useBC=!1;playing=!1;rafID=-1;_pingInterval;_lastPingTime=0;_pingTimeout=3e3;_peerConnected=!1;constructor(e){super(),this._appID=e}dispose(){this.stopPing(),this._broadcastChannel!==void 0&&this._broadcastChannel.removeEventListener("message",this.messageHandler),this._webSocket!==void 0&&(this._webSocket.removeEventListener("open",this.openHandler),this._webSocket.removeEventListener("close",this.closeHandler),this._webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(e=>{e.dispose()}),this.components.clear()}detectSettings(e=!1,t=!1){return this._mode=t?"editor":"app",new Promise(s=>{tm(e,t).then(i=>{this.settings=i,s()})})}update(){}draw(){}play=()=>{this.playing||(this.playing=!0,this.onUpdate())};pause=()=>{this.playing&&(this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1)};onUpdate=()=>{this.update(),this.isApp&&this.draw(),this.onUpdateCallback&&this.onUpdateCallback(),this.rafID=requestAnimationFrame(this.onUpdate)};setupRemote(e=!0){this.settings.dev&&(this._useBC=e,e?(this._broadcastChannel=new BroadcastChannel(this._appID),this._broadcastChannel.addEventListener("message",this.messageHandler),this.startPing()):(this._webSocket=new WebSocket(this._appID),this._webSocket.addEventListener("open",this.openHandler),this._webSocket.addEventListener("close",this.closeHandler),this._webSocket.addEventListener("message",this.messageHandler)))}addComponent(e,t){this.components.set(e,t)}send(e){this._mode!==e.target&&(this._useBC?this._broadcastChannel?.postMessage(e):this._connected&&this._webSocket?.send(JSON.stringify(e)))}messageHandler=e=>{let t=e.data;this._useBC||(t=JSON.parse(e.data)),t.target==="editor"?this.handleEditorBroadcast(t):this.handleAppBroadcast(t)};handleAppBroadcast(e){switch(this.appHandlers.forEach(t=>{t.callback(e)}),e.event){case"ping":this.handlePing(e);break;case"custom":this.dispatchEvent({type:"ToolEvents::custom",value:e.data});break}}handleEditorBroadcast(e){switch(this.editorHandlers.forEach(t=>{t.callback(e)}),e.event){case"ping":this.handlePing(e);break;case"custom":this.dispatchEvent({type:"ToolEvents::custom",value:e.data});break}}openHandler=()=>{this._connected=!0,this.startPing()};closeHandler=()=>{this._connected=!1,this._peerConnected=!1,this.stopPing()};get appID(){return this._appID}get connected(){return this._connected}get debugEnabled(){return this.settings.dev}get mode(){return this._mode}get isApp(){return!this.editor}set isApp(e){this.editor=!e}get editor(){return this.settings.editor}set editor(e){this.settings.editor=e,this._mode=e?"editor":"app"}get peerConnected(){return this._peerConnected}startPing(){this.stopPing(),this._pingInterval=setInterval(()=>{this._mode==="app"&&this.sendPing(),this.checkPingTimeout()},1e3)}stopPing(){this._pingInterval!==void 0&&(clearInterval(this._pingInterval),this._pingInterval=void 0)}sendPing(){const e=this._mode==="app"?"editor":"app";this.send({target:e,event:"ping",data:Date.now()})}handlePing(e){this._lastPingTime=Date.now(),this._peerConnected||this.dispatchEvent({type:"ToolEvents::remoteConnected"}),this._peerConnected=!0;const t=this._mode==="app"?"editor":"app";e.data!=="pong"&&this.send({target:t,event:"ping",data:"pong"})}checkPingTimeout(){const e=Date.now();if(this._peerConnected&&e-this._lastPingTime>this._pingTimeout){const t=this._peerConnected;this._peerConnected=!1,t&&this.dispatchEvent({type:"ToolEvents::remoteDisconnected"})}}}class $0{canvas;inputElement;settings;playing=!1;rafID=-1;constructor(e,t,s){this.canvas=e,this.inputElement=t,this.settings=s}dispose(){this.stop()}play(){this.playing||(this.playing=!0,this.onUpdate())}stop(){this.playing&&(this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1)}update(){}draw(){}resize(e,t){this.settings.supportOffScreenCanvas&&(this.inputElement.clientWidth=e,this.inputElement.clientHeight=t,this.inputElement.width=e,this.inputElement.height=t)}onResize=e=>{this.resize(e.width,e.height)};onUpdate=()=>{this.update(),this.draw(),this.rafID=requestAnimationFrame(this.onUpdate)}}class j0 extends x.Scene{clock;cameras;lights;world;constructor(e){super(),this.name=e,this.clock=new x.Clock,this.lights=new x.Group,this.lights.name="lights",this.add(this.lights),this.cameras=new x.Group,this.cameras.name="cameras",this.add(this.cameras),this.world=new x.Group,this.world.name="world",this.add(this.world)}init(){return new Promise(e=>{this.setupLights().then(()=>this.setupCameras()).then(()=>this.setupWorld()).then(()=>this.setupPost()).then(()=>this.setupAnimation()).then(()=>this.setupDebug()).then(()=>e())})}setupLights(){return new Promise(e=>{e()})}setupCameras(){return new Promise(e=>{e()})}setupWorld(){return new Promise(e=>{e()})}setupPost(){return new Promise(e=>{e()})}setupAnimation(){return new Promise(e=>{e()})}setupDebug(){return new Promise(e=>{e()})}dispose(){}update(){}draw(e){}postDraw(){}resize(e,t,s){}show(){this.clock.start(),this.showComplete()}showComplete(){this.enable()}hide(){this.disable(),this.hideComplete()}hideComplete(){this.clock.stop()}enable(){}disable(){}get deltaTime(){return Math.min(this.clock.getDelta(),1/30)}}class ol{app;constructor(e){this.app=e,this.app.appHandlers.push({remote:this,callback:this.handleApp.bind(this)}),this.app.editorHandlers.push({remote:this,callback:this.handleEditor.bind(this)})}dispose(){const e=this.app.appHandlers.findIndex(t=>t.remote===this);e>-1&&(this.app.appHandlers.splice(e,1),this.app.editorHandlers.splice(e,1))}handleApp(e){}handleEditor(e){}}class q0 extends ol{selectDropdown(e,t){this.app.send({event:"selectComponent",target:"app",data:{dropdown:e,value:t}})}updateDropdown(e,t){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:e,value:t}})}handleApp(e){switch(e.event){case"selectComponent":this.app.dispatchEvent({type:X.SELECT_DROPDOWN,value:e.data});break;case"draggableListUpdate":this.app.dispatchEvent({type:X.DRAG_UPDATE,value:e.data});break}}}function Y0(a,e,t){if(a.editor){t.ui.restore(),t.onSelectionChange(r=>{r.length<1||r.forEach(o=>{let l=o.address.sheetId,c="setSheet",h={};switch(o.type){case"Theatre_Sheet_PublicAPI":c="setSheet",h={sheet:o.address.sheetId},e.activeSheet=e.sheets.get(o.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",l+=`_${o.address.objectKey}`,h={id:l,sheet:o.address.sheetId,key:o.address.objectKey},e.activeSheet=e.sheets.get(o.address.sheetId);break}a.send({event:c,target:"app",data:h})})});let s=-1;const i=()=>{if(e.activeSheet!==void 0&&s!==e.activeSheet.sequence.position){s=e.activeSheet.sequence.position;const r=e.activeSheet;a.send({event:"updateTimeline",target:"app",data:{position:s,sheet:r.address.sheetId}})}},n=()=>{i(),requestAnimationFrame(n)};i(),n()}else t.ui.hide()}async function X0(){for(;!document.getElementById("theatrejs-studio-root");)await new Promise(s=>setTimeout(s,100));const a=document.getElementById("theatrejs-studio-root");if(a===null||a.shadowRoot===null)return;const e=a.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t!==null){try{const i=t.children[1].children[1];i.parentElement?.removeChild(i)}catch{}try{const s=t.children[3];s.style.top="0",s.style.right="300px"}catch{}}}function Z0(a,e,t,s,i){const n=1-a;return n*n*n*e+3*n*n*a*t+3*n*a*a*s+a*a*a*i}function Q0(a,e,t){if(a.type!=="bezier"||a.handles.length!==4)throw new Error("Invalid keyframe data for Bézier interpolation.");const[s,i]=a.handles,n=(t-a.position)/(e.position-a.position);return Z0(n,a.value,a.value+s,e.value+i,e.value)}class K0 extends ol{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;rafDriver=void 0;constructor(e,t=!1){super(e),t&&(this.rafDriver=p0.createRafDriver())}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}update(e){this.rafDriver?.tick(e)}getSheetInstance(e,t){return t!==void 0?`${e}-${t}`:e}sheet(e,t){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const s=this.getSheetInstance(e,t);let i=this.sheets.get(s);return i!==void 0||(i=this.project?.sheet(e,t),this.sheets.set(s,i)),i}playSheet(e,t,s){return new Promise(i=>{const n=t!==void 0?{...t}:{};n.rafDriver=this.rafDriver,this.sheet(e,s)?.sequence.play(n).then(r=>i(r)),this.app.send({event:"playSheet",target:"editor",data:{sheet:e,instance:s,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:e,instance:t}})}clearSheetObjects(e){this.sheetObjects.forEach((t,s)=>{s.search(`${e}_`)>-1&&this.unsubscribe(t)})}sheetObject(e,t,s,i,n){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const r=this.sheet(e,n);if(r===void 0)return;const l=`${this.getSheetInstance(e,n)}_${t}`;let c=this.sheetObjects.get(l),h=s;c!==void 0&&(h={...s,...c.value}),c=r.object(t,h),this.sheetObjects.set(l,c),this.sheetObjectCBs.set(l,i!==void 0?i:da);const u=c.onValuesChange(d=>{if(this.app.editor){for(const f in d){const m=d[f];typeof m=="object"&&Kf(m)&&(d[f]={r:m.r,g:m.g,b:m.b,a:m.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:l,values:d}})}const p=this.sheetObjectCBs.get(l);p!==void 0&&p(d)},this.rafDriver);return this.sheetObjectUnsubscribe.set(l,u),c}getSheetObjectKeyframes(e,t,s){const i=this.sheet(e);if(i===void 0)return[];const n=`${e}_${t}`,r=this.sheetObjects.get(n);return r===void 0?[]:i.sequence.__experimental_getKeyframes(r.props[s])}getSheetObjectVectors(e,t){const s=this.sheet(e);if(s===void 0)return[];const i=`${e}_${t}`,n=this.sheetObjects.get(i);if(n===void 0)return[];const r=[],o=s.sequence.__experimental_getKeyframes(n.props.x),l=s.sequence.__experimental_getKeyframes(n.props.y),c=s.sequence.__experimental_getKeyframes(n.props.z),h=new Set;return o.forEach(d=>h.add(d.position)),l.forEach(d=>h.add(d.position)),c.forEach(d=>h.add(d.position)),Array.from(h).sort((d,p)=>d-p).forEach(d=>{const p=(f,m)=>{const y=f.find((b,T)=>b.position<=m&&(f[T+1]?.position||1/0)>m),g=f.find(b=>b.position>m);if(!y)return g?.value||0;if(!g||y.position===m)return y.value;if(y.type==="bezier")return Q0(y,g,m);const _=(m-y.position)/(g.position-y.position);return y.value+_*(g.value-y.value)};r.push({position:d,x:p(o,d),y:p(l,d),z:p(c,d)})}),r}unsubscribe(e){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const t=e.address.sheetId,s=e.address.objectKey;this.sheets.get(t)?.detachObject(s);const n=`${t}_${s}`,r=this.sheetObjectUnsubscribe.get(n);r!==void 0&&(this.sheetObjects.delete(n),this.sheetObjectCBs.delete(n),this.sheetObjectUnsubscribe.delete(n),r())}handleApp(e){let t;switch(e.event){case"setSheet":t=this.sheets.get(e.data.sheet),t!==void 0&&(this.activeSheet=t,this.studio?.setSelection([t]));break;case"setSheetObject":t=this.sheetObjects.get(`${e.data.sheet}_${e.data.key}`),t!==void 0&&this.studio?.setSelection([t]);break;case"updateSheetObject":t=this.sheets.get(e.data.sheet),t!==void 0&&t.sequence.pause(),t=this.sheetObjectCBs.get(e.data.sheetObject),t!==void 0&&t(e.data.values);break;case"updateTimeline":t=this.sheets.get(e.data.sheet),this.activeSheet!==void 0&&(this.activeSheet.sequence.position=e.data.position);break}}handleEditor(e){if(this.app.editor)switch(e.event){case"playSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.play({...e.data.value,rafDriver:this.rafDriver});break;case"pauseSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.pause();break}}handleEditorApp(){if(this.app.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(i=>{i.length<1||i.forEach(n=>{let r=n.address.sheetId,o="setSheet",l={};switch(n.type){case"Theatre_Sheet_PublicAPI":o="setSheet",l={sheet:n.address.sheetId},this.activeSheet=this.sheets.get(n.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":o="setSheetObject",r+=`_${n.address.objectKey}`,l={id:r,sheet:n.address.sheetId,key:n.address.objectKey},this.activeSheet=this.sheets.get(n.address.sheetId);break}this.app.send({event:o,target:"app",data:l})})});let e=-1;const t=()=>{if(this.activeSheet!==void 0&&e!==this.activeSheet.sequence.position){e=this.activeSheet.sequence.position;const i=this.activeSheet;this.app.send({event:"updateTimeline",target:"app",data:{position:e,sheet:i.address.sheetId}})}},s=()=>{t(),requestAnimationFrame(s)};t(),s()}else this.studio?.ui.hide()}}function J0(a){if(a.name==="cameras")return"camera";if(a.name==="interactive")return"interactive";if(a.name==="lights")return"light";if(a.name==="ui")return"ui";if(a.name==="utils")return"utils";const e=a.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function Hn(a){const e={name:a.name,type:a.type,uuid:a.uuid,children:[]};return a.children.forEach(t=>{e.children.push(Hn(t))}),e}function ex(a){const e={};for(const t in a){const s=a[t].value;e[t]={value:s},s===null?e[t].value={src:"",offset:[0,0],repeat:[1,1]}:s!==void 0&&s.isTexture&&(e[t].value={src:s.image.src,offset:[s.offset.x,s.offset.y],repeat:[s.repeat.x,s.repeat.y]})}return e}function tx(a){switch(a){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Tn(a){const e={};for(const t in a){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||tx(t))continue;const s=typeof a[t],i=a[t];switch(s){case"boolean":case"number":case"string":e[t]=i;break;case"object":i!==null?(e[t]=i,i.isTexture?e[t]={src:Ri.renderToBlob(i),offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]}:t==="uniforms"&&(e[t]=ex(e[t]))):t==="glslVersion"?e[t]="":e[t]={src:"",offset:[0,0],repeat:[1,1]};break}}return a.anisotropy!==void 0&&(e.anisotropy=a.anisotropy),a.clearcoat!==void 0&&(e.clearcoat=a.clearcoat),a.iridescence!==void 0&&(e.iridescence=a.iridescence),a.dispersion!==void 0&&(e.dispersion=a.dispersion),a.sheen!==void 0&&(e.sheen=a.sheen),a.transmission!==void 0&&(e.transmission=a.transmission),a.transmission!==void 0&&(e.transmission=a.transmission),e}function Ul(a){a.updateMatrix();const e={name:a.name,type:a.type,uuid:a.uuid,visible:a.visible,matrix:a.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};a.animations.forEach(s=>{e.animations.push({name:s.name,duration:s.duration,blendMode:s.blendMode})});const t=a.type.toLowerCase();if(t.search("mesh")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else if(t.search("points")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else if(t.search("line")>-1){const s=a;if(Array.isArray(s.material)){const i=[];s.material.forEach(n=>{i.push(Tn(n))}),e.material=i}else e.material=Tn(s.material)}else t.search("camera")>-1?a.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:a.fov,zoom:a.zoom,near:a.near,far:a.far,focus:a.focus,aspect:a.aspect,filmGauge:a.filmGauge,filmOffset:a.filmOffset}:a.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:a.zoom,near:a.near,far:a.far,left:a.left,right:a.right,top:a.top,bottom:a.bottom}):t.search("light")>-1&&(e.lightInfo={color:a.color,intensity:a.intensity,decay:a.decay,distance:a.distance,angle:a.angle,penumbra:a.penumbra,groundColor:a.groundColor,width:a.width,height:a.height});return e}function sx(a,e){const t=e.split(".");switch(t.length){case 1:return a[t[0]];case 2:return a[t[0]][t[1]];case 3:return a[t[0]][t[1]][t[2]];case 4:return a[t[0]][t[1]][t[2]][t[3]];case 5:return a[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return a[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function ix(a,e){for(const t in e)a[t]=e[t]}function qe(a,e,t){if(a===void 0){console.log(`Hermes - Can't set props: ${e}`,t);return}const s=e.split("."),i=s.length;if(typeof t!="object")switch(i){case 1:a[s[0]]=t;break;case 2:a[s[0]][s[1]]=t;break;case 3:a[s[0]][s[1]][s[2]]=t;break;case 4:a[s[0]][s[1]][s[2]][s[3]]=t;break;case 5:a[s[0]][s[1]][s[2]][s[3]][s[4]]=t;break}else{let r;switch(i){case 1:r=a[s[0]];break;case 2:r=a[s[0]][s[1]];break;case 3:r=a[s[0]][s[1]][s[2]];break;case 4:r=a[s[0]][s[1]][s[2]][s[3]];break;case 5:r=a[s[0]][s[1]][s[2]][s[3]][s[4]];break}r!=null?ix(r,t):console.log(`Hermes - Can't set props because target isn't found: ${e}`,t)}}function im(a){return new Promise((e,t)=>{const s=new Image;s.onload=()=>{const i=new x.Texture(s);i.wrapS=x.RepeatWrapping,i.wrapT=x.RepeatWrapping,i.needsUpdate=!0,e(i)},s.onerror=t,s.src=a})}class nx extends ol{canvas=null;inputElement=null;scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;renderTargetsResize=new Map;groups=new Map;dispose(){this.scenes.forEach(e=>{Is(e)}),this.scenes.clear(),this.scene&&Is(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}getObject(e){this.app.debugEnabled&&(this.renderer!==void 0&&(Ri.renderer=this.renderer),this.app.send({event:"getObject",target:"app",data:e}))}setObject(e){this.renderer!==void 0&&(Ri.renderer=this.renderer);const t=Ul(e);this.app.send({event:"setObject",target:"editor",data:t})}requestMethod(e,t,s,i){this.app.send({event:"requestMethod",target:"app",data:{uuid:e,key:t,value:s,subitem:i}})}updateObject(e,t,s){this.app.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:s}})}createTexture(e,t,s){this.app.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:s}})}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.app.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.app.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,s){this.app.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:s})})}addSpline(e){setTimeout(()=>{this.app.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}setRenderer(e,t=null){if(this.renderer=e,this.canvas=e.domElement,this.inputElement=t!==null?t:this.canvas,!this.app.debugEnabled)return;const s=`#${e.getClearColor(new x.Color).getHexString()}`;this.app.send({event:"addRenderer",target:"editor",data:{autoClear:e.autoClear,autoClearColor:e.autoClearColor,autoClearDepth:e.autoClearDepth,autoClearStencil:e.autoClearStencil,outputColorSpace:e.outputColorSpace,localClippingEnabled:e.localClippingEnabled,clearColor:s,clearAlpha:e.getClearAlpha(),colorManagement:x.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure,type:e.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}updateRenderer(e){this.app.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.app.debugEnabled))return;ch(),ko(e);const t=Hn(e);this.app.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.app.debugEnabled)return;const t=this.scenes.get(e);if(t!==void 0){const s=Hn(t);this.app.send({event:"refreshScene",target:"app",data:s})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.app.debugEnabled))return;const t=Hn(e);this.app.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scenes.forEach((s,i)=>{e.search(i)>-1&&(t=s)}),t}setScene(e){if(e===void 0||(this.scene=e,!this.app.debugEnabled))return;this.renderer!==void 0&&(Ri.renderer=this.renderer),ch(),ko(e);const t=Hn(e);this.app.send({event:"setScene",target:"editor",data:t})}addCamera(e){if(!this.app.debugEnabled)return;const t=Ul(e);this.app.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.app.debugEnabled)return;const t=Ul(e);this.app.send({event:"removeCamera",target:"editor",data:t})}handleApp(e){switch(e.event){case"getObject":this.app.dispatchEvent({type:X.GET_OBJECT,value:e.data});break;case"updateObject":this.app.dispatchEvent({type:X.UPDATE_OBJECT,value:e.data});break;case"createTexture":this.app.dispatchEvent({type:X.CREATE_TEXTURE,value:e.data});break;case"requestMethod":this.app.dispatchEvent({type:X.REQUEST_METHOD,value:e.data});break;case"refreshScene":this.app.send({event:"refreshScene",target:"editor",data:Hn(this.scenes.get(e.data.name))});break;case"updateRenderer":this.renderer&&(this.renderer.autoClearColor=e.data.autoClearColor,this.renderer.outputColorSpace=e.data.outputColorSpace,this.renderer.localClippingEnabled=e.data.localClippingEnabled,this.renderer.setClearColor(e.data.clearColor,e.data.clearAlpha),this.renderer.toneMapping=e.data.toneMapping,this.renderer.toneMappingExposure=e.data.toneMappingExposure,x.ColorManagement.enabled=e.data.colorManagement);break}if(e.event==="updateGroup"){const t=JSON.parse(e.data);this.groups.get(t.group)?.onUpdate(t.prop,t.value)}}handleEditor(e){switch(e.event){case"setObject":this.app.dispatchEvent({type:X.SET_OBJECT,value:e.data});break;case"addScene":this.app.dispatchEvent({type:X.ADD_SCENE,value:e.data});break;case"refreshScene":this.app.dispatchEvent({type:X.REFRESH_SCENE,value:e.data});break;case"removeScene":this.app.dispatchEvent({type:X.REMOVE_SCENE,value:e.data});break;case"setScene":this.app.dispatchEvent({type:X.SET_SCENE,value:e.data});break;case"addCamera":this.app.dispatchEvent({type:X.ADD_CAMERA,value:e.data});break;case"removeCamera":this.app.dispatchEvent({type:X.REMOVE_CAMERA,value:e.data});break;case"addGroup":this.app.dispatchEvent({type:X.ADD_GROUP,value:e.data});break;case"removeGroup":this.app.dispatchEvent({type:X.REMOVE_GROUP,value:e.data});break;case"addSpline":this.app.dispatchEvent({type:X.ADD_SPLINE,value:e.data});break;case"addRenderer":this.app.dispatchEvent({type:X.ADD_RENDERER,value:e.data})}}addRT(e,t=!0,s){const i=new x.WebGLRenderTarget(32,32,s);i.texture.name=e,this.renderTargets.set(e,i),this.renderTargetsResize.set(e,t)}removeRT(e){this.renderTargets.delete(e),this.renderTargetsResize.delete(e)}resize(e,t){const s=this.dpr;this.renderTargets.forEach((n,r)=>{this.renderTargetsResize.get(r)&&n.setSize(e*s,t*s)});const i=!(this.renderer?.domElement instanceof OffscreenCanvas);this.renderer?.setSize(e,t,i)}set dpr(e){this.renderer?.setPixelRatio(Ti(1,2,e))}get dpr(){return this.renderer!==void 0?this.renderer?.getPixelRatio():1}get width(){return this.renderer!==void 0?this.renderer.domElement.width/this.dpr:0}get height(){return this.renderer!==void 0?this.renderer.domElement.height/this.dpr:0}}var Da={exports:{}},Tr={};/**
19
19
  * @license React
20
20
  * react-jsx-runtime.production.min.js
21
21
  *
@@ -46,7 +46,7 @@ React keys must be passed directly to JSX without using spread:
46
46
  let props = %s;
47
47
  <%s key={someKey} {...props} />`,Ol,ki,u0,ki),ud[ki+Ol]=!0}}return v===s?a0(Ze):r0(Ze),Ze}}function o0(v,G,Y){return dd(v,G,Y,!0)}function l0(v,G,Y){return dd(v,G,Y,!1)}var c0=l0,h0=o0;Sr.Fragment=s,Sr.jsx=c0,Sr.jsxs=h0}()),Sr}var _d;function ox(){return _d||(_d=1,process.env.NODE_ENV==="production"?Da.exports=rx():Da.exports=ax()),Da.exports}var M=ox();function Yh(a){return a.title.search("<")>-1?M.jsx("button",{className:"svg",dangerouslySetInnerHTML:{__html:a.title}}):M.jsx("button",{children:a.title})}const lx=M.jsxs("svg",{className:"closeIcon",width:"14",height:"14",fill:"none",stroke:"#666666",strokeMiterlimit:"10",children:[M.jsx("circle",{cx:"7",cy:"7",r:"6"}),M.jsx("line",{x1:"4",y1:"4",x2:"10",y2:"10"}),M.jsx("line",{x1:"4",y1:"10",x2:"10",y2:"4"})]}),cx=M.jsx("svg",{className:"dragIcon",width:"14",height:"14",fill:"#666666",stroke:"none",children:M.jsx("path",{d:`M10.43,4H3.57C3.26,4,3,4.22,3,4.5v1C3,5.78,3.26,6,3.57,6h6.86C10.74,6,11,5.78,11,5.5v-1\r
48
48
  C11,4.22,10.74,4,10.43,4z M10.43,8H3.57C3.26,8,3,8.22,3,8.5v1C3,9.78,3.26,10,3.57,10h6.86C10.74,10,11,9.78,11,9.5v-1\r
49
- C11,8.22,10.74,8,10.43,8z`})});function nm(a){return M.jsx("li",{className:`reorder-item ${a.draggingIndex===a.index?"dragging":""}`,draggable:!0,onDragStart:()=>a.onDragStart(a.index),onDragOver:e=>{e.preventDefault(),a.onDragOver(a.index)},onDragEnd:a.onDragEnd,children:M.jsxs("div",{children:[cx,M.jsx("span",{children:a.title}),M.jsx("button",{className:"closeIcon",onClick:()=>a.onDelete(a.index),children:lx})]})})}function rm(a){const[e,t]=W.useState(!1),[s,i]=W.useState(a.options),[n,r]=W.useState(null),o=p=>{a.onDragComplete(p),i(p)},l=p=>{const f=[...s];f.splice(p,1),o(f)},c=p=>{r(p)},h=p=>{if(n===p||n===null)return;const f=[...s],m=f.splice(n,1)[0];f.splice(p,0,m),r(p),i(f)},u=()=>{a.onDragComplete(s),r(null)};let d="dropdown draggable";return a.subdropdown&&(d+=" subdropdown"),M.jsxs("div",{className:d,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[M.jsx(Yh,{title:a.title}),M.jsx("ul",{className:"reorder-list",style:{display:e?"block":"none"},children:s.map((p,f)=>M.jsx(nm,{title:p,index:f,draggingIndex:n,onDelete:l,onDragStart:c,onDragOver:h,onDragEnd:u},p))})]})}function am(a){const[e,t]=W.useState(!1),s=[];a.options.map((n,r)=>{a.onSelect!==void 0&&(n.onSelect=a.onSelect),s.push(M.jsx(om,{option:n},r))});let i="dropdown";return a.subdropdown&&(i+=" subdropdown"),M.jsxs("div",{className:i,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[M.jsx(Yh,{title:a.title}),M.jsx("ul",{style:{visibility:e?"visible":"hidden"},children:s})]})}function om(a){const{option:e}=a,[t,s]=W.useState("");let i;switch(e.type){case"draggable":i=M.jsx(rm,{title:e.title,options:e.value,onDragComplete:n=>{e.onDragComplete!==void 0&&e.onDragComplete(n)},subdropdown:!0});break;case"dropdown":i=M.jsx(am,{title:e.title,options:e.value,onSelect:e.onSelect,subdropdown:!0});break;case"option":i=M.jsx("button",{onClick:()=>{e.onSelect!==void 0&&e.onSelect(e.value),e.selectable&&(t!==e.title?s(e.title):s(""))},children:e.title});break}return M.jsx("li",{className:t===e.title?"selected":"",children:i},ct())}function fa(a){const[e,t]=W.useState(a.open!==void 0?a.open:!0),s=!e||a.children===void 0,i=W.useRef(null),n=()=>{a.app.dispatchEvent({type:X.REMOVE_SCENE,value:a.scene})};return M.jsxs("div",{className:`accordion ${s?"hide":""}`,children:[M.jsxs("button",{className:"toggle",onClick:()=>{const r=!e;a.onToggle!==void 0&&a.onToggle(r),t(r)},children:[M.jsx("p",{className:`status ${e?"open":""}`,children:"Toggle"}),M.jsx("p",{className:"label",children:pa(a.label)})]}),a.onRefresh?M.jsxs(M.Fragment,{children:[M.jsx("button",{className:"visibility",ref:i,onClick:()=>{const o=a.app.components.get("three").getScene(a.scene.uuid);if(o){const l=!o.visible;o.visible=l,i.current.style.opacity=l?"1":"0.25"}}}),M.jsx("button",{className:"refresh",onClick:a.onRefresh}),M.jsx("button",{className:"remove",onClick:n})]}):null,a.button,M.jsx("div",{className:e?"open":"",children:M.jsx("div",{children:a.children})},Math.random())]})}function Xh(a){if(a.child===void 0)return console.log("Hermes - No child attached"),null;const e=W.useRef(null),[t,s]=W.useState(!1),i=a.child.children.length>0,n=[];return a.child.children.length>0&&a.child.children.map((r,o)=>{n.push(M.jsx(Xh,{app:a.app,child:r,three:a.three},o))}),W.useEffect(()=>{if(a.child){const r=a.three.getScene(a.child.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",a.child.uuid);o!==void 0&&(e.current.style.opacity=o.visible?"1":"0.25")}else console.log(`Hermes - Can't find Scene: ${a.child.uuid}`)}},[t]),M.jsxs("div",{className:"childObject",children:[M.jsxs("div",{className:"child",children:[i?M.jsx("button",{className:"status",style:{backgroundPositionX:t?"-14px":"2px"},onClick:()=>{s(!t)}}):null,M.jsx("button",{className:"name",style:{left:i?"20px":"5px"},onClick:()=>{a.child!==void 0?(a.three.getObject(a.child.uuid),!t&&i&&s(!0)):console.log("Hermes - No child attached...")},children:a.child.name.length>0?`${a.child.name} (${a.child.type})`:`${a.child.type}::${a.child.uuid}`}),M.jsx("button",{className:"visibility",ref:e,onClick:()=>{if(a.child){const r=a.three.getScene(a.child.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",a.child.uuid);if(o!==void 0){const l="visible",c=!o.visible;e.current.style.opacity=c?"1":"0.25",a.three.updateObject(a.child.uuid,l,c),qe(o,l,c)}else console.log(`Hermes - Couldn't find object: ${a.child.uuid}`,r)}else console.log(`Hermes - Couldn't find object in scene: ${a.child.uuid}, ${a.child.name}`)}}}),M.jsx("div",{className:`icon ${J0(a.child)}`})]}),M.jsx("div",{className:t?"open":"",children:M.jsx("div",{className:"container",children:n})})]},Math.random())}function uh(a){const e=[];return a.child?.children.map((t,s)=>{e.push(M.jsx(Xh,{app:a.app,child:t,scene:a.scene,three:a.three},s))}),M.jsx("div",{className:`scene ${a.class!==void 0?a.class:""}`,children:e})}function Xr(a){const[e,t]=W.useState(a.defaultValue);return W.useEffect(()=>{let s=!1,i=-1,n=0,r=a.defaultValue,o=!1;const l=p=>{o=p.ctrlKey},c=p=>{s=!0,n=Number(a.input.current?.value),i=p.clientX,document.addEventListener("mouseup",u,!1),document.addEventListener("mousemove",h,!1),document.addEventListener("contextmenu",u,!1)},h=p=>{if(!s)return;const f=a.step!==void 0?a.step:1,m=(p.clientX-i)*f*(o?10:1);r=Number((n+m).toFixed(4)),a.min!==void 0&&(r=Math.max(r,a.min)),a.max!==void 0&&(r=Math.min(r,a.max)),a.onChange!==void 0&&a.onChange(r),t(r)},u=()=>{s=!1,document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u)},d=p=>{const f=Number(p.target.value);a.onChange!==void 0&&a.onChange(f),t(f)};return a.label.current?.addEventListener("mousedown",c,!1),a.sliderRef!==void 0&&a.sliderRef.current?.addEventListener("input",d),document.addEventListener("keydown",l,!1),document.addEventListener("keyup",l,!1),()=>{a.label.current?.removeEventListener("mousedown",c),a.sliderRef!==void 0&&a.sliderRef.current?.removeEventListener("input",d),document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u),document.removeEventListener("keydown",l),document.addEventListener("keyup",l,!1)}},[]),e}function cn(a){const e=W.useRef(null),t=W.useRef(null),[s,i]=W.useState(a.value);return Xr({label:a.labelRef,input:e,sliderRef:t,defaultValue:s,min:a.min,max:a.max,step:a.step,onChange:n=>{i(n),a.onChange!==void 0&&a.onChange(a.prop,n)}}),M.jsxs(M.Fragment,{children:[a.type==="number"&&M.jsx("input",{alt:a.alt,className:a.className,ref:e,type:"number",value:s,min:a.min,max:a.max,step:a.step,disabled:a.disabled,name:ct(),onChange:n=>{if(i(n.target.value),n.target.value.length===0)return;const r=Number(n.target.value);isNaN(r)||a.onChange!==void 0&&a.onChange(a.prop,r)}}),a.type==="range"&&M.jsxs(M.Fragment,{children:[M.jsx("input",{type:"text",value:s.toString(),disabled:a.disabled,ref:e,className:"min",name:ct(),onChange:n=>{if(n.target.value.length===0)return;const r=Number(n.target.value);isNaN(r)||(i(r),a.onChange!==void 0&&a.onChange(a.prop,r))}}),M.jsx("input",{disabled:a.disabled,type:"range",value:s,min:a.min,max:a.max,step:a.step,ref:t,name:ct(),onChange:da})]})]})}function hx(a){const e=W.useRef(null),t=W.useRef(null),s=W.useRef(null),i=W.useRef(null),n=W.useRef(null),r=W.useRef(null),o=W.useRef(null),l=W.useRef(null),c=W.useRef(null),h=W.useRef(null),[u,d]=W.useState(a.value.x),[p,f]=W.useState(a.value.y),[m,y]=W.useState({min:Math.min(a.min,Math.min(a.value.x,a.value.y)),max:Math.max(a.max,Math.max(a.value.x,a.value.y))}),[g,_]=W.useState(!1);Xr({label:o,input:e,defaultValue:u,min:m.min,max:m.max,step:.01,onChange:P=>{d(P),a.onChange({target:{value:{x:P,y:p}}})}}),Xr({label:l,input:t,defaultValue:p,min:m.min,max:m.max,step:.01,onChange:P=>{f(P),a.onChange({target:{value:{x:u,y:P}}})}}),Xr({label:c,input:s,defaultValue:m.min,min:m.min-1,max:m.max+1,step:.01,onChange:P=>{y({min:P,max:m.max})}}),Xr({label:h,input:i,defaultValue:m.max,min:m.min-1,max:m.max+1,step:.01,onChange:P=>{y({min:m.min,max:P})}});function b(){g||(window.addEventListener("mousemove",S),window.addEventListener("mouseup",T),_(!0))}function T(){window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",T),_(!1)}function S(P){const z=n.current.getBoundingClientRect(),$=Ti(0,99,P.clientX-z.left)/99,q=1-Ti(0,99,P.clientY-z.top)/99,j=ss(rr(m.min,m.max,$),3),Z=ss(rr(m.min,m.max,q),3);a.onChange({target:{value:{x:j,y:Z}}}),d(j),f(Z)}function C(){const P=Number(s.current.value);y({min:P,max:m.max}),u<P&&d(Ti(P,m.max,u)),p<P&&f(Ti(P,m.max,p))}function w(){const P=Number(i.current.value);y({min:m.min,max:P}),u>P&&d(Ti(m.min,P,u)),p>P&&f(Ti(m.min,P,p))}W.useEffect(()=>{r.current.style.left=`${Uo(m.min,m.max,u)*100}%`,r.current.style.top=`${(1-Uo(m.min,m.max,p))*100}%`},[m,u,p]);const R=a.step!==void 0?a.step:.01;return M.jsxs("div",{className:"vector2",children:[M.jsxs("div",{className:"fields",children:[M.jsxs("div",{children:[M.jsx("span",{ref:o,children:"X"}),M.jsx("input",{ref:e,type:"number",value:u,min:m.min,max:m.max,step:R,name:ct(),onChange:P=>{if(d(P.target.value),P.target.value.length===0)return;const z=Number(P.target.value);isNaN(z)||(a.onChange({target:{value:{x:z,y:p}}}),z<m.min&&y({min:z,max:m.max}))}})]}),M.jsxs("div",{children:[M.jsx("span",{ref:l,children:"Y"}),M.jsx("input",{ref:t,type:"number",value:p,min:m.min,max:m.max,step:R,name:ct(),onChange:P=>{if(f(P.target.value),P.target.value.length===0)return;const z=Number(P.target.value);isNaN(z)||(a.onChange({target:{value:{x:u,y:z}}}),z>m.max&&y({min:m.min,max:z}))}})]}),M.jsxs("div",{children:[M.jsx("span",{ref:c,children:"Min"}),M.jsx("input",{ref:s,type:"number",value:m.min,step:R,name:ct(),onChange:C})]}),M.jsxs("div",{children:[M.jsx("span",{ref:h,children:"Max"}),M.jsx("input",{ref:i,type:"number",value:m.max,step:R,name:ct(),onChange:w})]})]}),M.jsxs("div",{className:"input",ref:n,onMouseDown:b,onMouseUp:T,children:[M.jsx("div",{className:"x"}),M.jsx("div",{className:"y"}),M.jsx("div",{className:"pt",ref:r})]})]})}const gt=["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 bd=1234567;const na=Math.PI/180,ar=180/Math.PI;function Zs(){const a=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(gt[a&255]+gt[a>>8&255]+gt[a>>16&255]+gt[a>>24&255]+"-"+gt[e&255]+gt[e>>8&255]+"-"+gt[e>>16&15|64]+gt[e>>24&255]+"-"+gt[t&63|128]+gt[t>>8&255]+"-"+gt[t>>16&255]+gt[t>>24&255]+gt[s&255]+gt[s>>8&255]+gt[s>>16&255]+gt[s>>24&255]).toLowerCase()}function de(a,e,t){return Math.max(e,Math.min(t,a))}function Zh(a,e){return(a%e+e)%e}function Ki(a,e,t,s,i){return s+(a-e)*(i-s)/(t-e)}function ux(a,e,t){return a!==e?(t-a)/(e-a):0}function Ni(a,e,t){return(1-t)*a+t*e}function dx(a,e,t,s){return Ni(a,e,1-Math.exp(-t*s))}function px(a,e=1){return e-Math.abs(Zh(a,e*2)-e)}function fx(a,e,t){return a<=e?0:a>=t?1:(a=(a-e)/(t-e),a*a*(3-2*a))}function mx(a,e,t){return a<=e?0:a>=t?1:(a=(a-e)/(t-e),a*a*a*(a*(a*6-15)+10))}function gx(a,e){return a+Math.floor(Math.random()*(e-a+1))}function yx(a,e){return a+Math.random()*(e-a)}function xx(a){return a*(.5-Math.random())}function _x(a){a!==void 0&&(bd=a);let e=bd+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function zo(a){return a*na}function lm(a){return a*ar}function bx(a){return(a&a-1)===0&&a!==0}function Tx(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function Sx(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function vx(a,e,t,s,i){const n=Math.cos,r=Math.sin,o=n(t/2),l=r(t/2),c=n((e+s)/2),h=r((e+s)/2),u=n((e-s)/2),d=r((e-s)/2),p=n((s-e)/2),f=r((s-e)/2);switch(i){case"XYX":a.set(o*h,l*u,l*d,o*c);break;case"YZY":a.set(l*d,o*h,l*u,o*c);break;case"ZXZ":a.set(l*u,l*d,o*h,o*c);break;case"XZX":a.set(o*h,l*f,l*p,o*c);break;case"YXY":a.set(l*p,o*h,l*f,o*c);break;case"ZYZ":a.set(l*f,l*p,o*h,o*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function At(a,e){switch(e.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("Invalid component type.")}}function oe(a,e){switch(e.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("Invalid component type.")}}const wx={DEG2RAD:na,RAD2DEG:ar,generateUUID:Zs,clamp:de,euclideanModulo:Zh,mapLinear:Ki,inverseLerp:ux,lerp:Ni,damp:dx,pingpong:px,smoothstep:fx,smootherstep:mx,randInt:gx,randFloat:yx,randFloatSpread:xx,seededRandom:_x,degToRad:zo,radToDeg:lm,isPowerOfTwo:bx,ceilPowerOfTwo:Tx,floorPowerOfTwo:Sx,setQuaternionFromProperEuler:vx,normalize:oe,denormalize:At};function Td(a){const e=a.value.x!==void 0&&a.value.y!==void 0&&a.value.z!==void 0,t=a.value.isEuler!==void 0,s=a.value.elements!==void 0,i=a.step!==void 0?a.step:.01,n=[];if(t){const r=W.useMemo(()=>a.value,[]);["_x","_y","_z"].forEach(l=>{const c=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("span",{ref:c,children:l.substring(1).toUpperCase()}),M.jsx(cn,{value:lm(r[l]),type:"number",prop:l,step:.1,labelRef:c,onChange:(h,u)=>{r[h]=zo(u),a.onChange({target:{value:r}})}})]},l))})}else if(e){const r=W.useMemo(()=>a.value,[]),o=(c,h)=>{r[c]=h,a.onChange({target:{value:r}})};["x","y","z"].forEach(c=>{const h=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("label",{ref:h,children:c.toUpperCase()}),M.jsx(cn,{value:r[c],type:"number",prop:c,step:i,labelRef:h,onChange:o})]},c))})}else if(s){const r=W.useMemo(()=>a.value,[]),o=(l,c)=>{const h=Number(l);r.elements[h]=c,a.onChange({target:{value:r}})};for(let l=0;l<9;l++){const c=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("label",{ref:c,children:l+1}),M.jsx(cn,{value:r.elements[l],type:"number",prop:l.toString(),step:i,labelRef:c,onChange:o})]},l.toString()))}}return M.jsx("div",{className:"grid3",children:n},Math.random().toString())}function Ex(a){const e=a.value.x!==void 0,t=a.step!==void 0?a.step:.01,s=[];if(e){const i=W.useMemo(()=>a.value,[]),n=(o,l)=>{i[o]=l,a.onChange({target:{value:i}})};["x","y","z","w"].forEach(o=>{const l=W.useRef(null);s.push(M.jsxs("div",{children:[M.jsx("label",{ref:l,children:o.toUpperCase()}),M.jsx(cn,{value:i[o],type:"number",prop:o,step:t,labelRef:l,onChange:n})]},o))})}else{const i=W.useMemo(()=>a.value,[]),n=(r,o)=>{const l=Number(r);i.elements[l]=o,a.onChange({target:{value:i}})};for(let r=0;r<16;r++){const o=W.useRef(null);s.push(M.jsxs("div",{children:[M.jsx("span",{ref:o,children:r+1}),M.jsx(cn,{value:i.elements[r],type:"number",prop:r.toString(),step:t,labelRef:o,onChange:n})]},r.toString()))}}return M.jsx("div",{className:"grid4",children:s})}function Cx(a){return!(a==="defaultAttributeValues"||a==="forceSinglePass"||a==="linecap"||a==="linejoin"||a==="linewidth"||a==="normalMapType"||a==="precision"||a==="shadowSide"||a==="uniformsGroups"||a==="uniformsNeedUpdate"||a==="userData"||a==="version"||a==="wireframeLinecap"||a==="wireframeLinejoin"||a==="wireframeLinewidth"||a.slice(0,4)==="clip"||a.slice(0,7)==="polygon"||a.slice(0,7)==="stencil"||a.slice(0,2)==="is")}function Mx(a){switch(a){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 a}function ll(a){switch(a){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 a}function cm(a){const e=a.toLowerCase();return e.search("intensity")>-1||e==="anisotropyrotation"||e==="blendalpha"||e==="bumpscale"||e==="clearcoatroughness"||e==="displacementbias"||e==="displacementscale"||e==="metalness"||e==="opacity"||e==="reflectivity"||e==="refractionratio"||e==="roughness"||e==="sheenroughness"}function Ax(){const a=document.createElement("input");return a.type="file",new Promise((e,t)=>{a.addEventListener("change",function(){if(a.files===null)t();else{const s=a.files[0],i=new FileReader;i.onload=function(n){e(n.target.result)},i.readAsDataURL(s)}}),a.click()})}const Rx=[{title:"Front",value:x.FrontSide},{title:"Back",value:x.BackSide},{title:"Double",value:x.DoubleSide}],Nx=[{title:"No Blending",value:x.NoBlending},{title:"Normal",value:x.NormalBlending},{title:"Additive",value:x.AdditiveBlending},{title:"Subtractive",value:x.SubtractiveBlending},{title:"Multiply",value:x.MultiplyBlending},{title:"Custom",value:x.CustomBlending}],Px=[{title:"Add",value:x.AddEquation},{title:"Subtract",value:x.SubtractEquation},{title:"Reverse Subtract",value:x.ReverseSubtractEquation},{title:"Min",value:x.MinEquation},{title:"Max",value:x.MaxEquation}],Dx=[{title:"Zero",value:x.ZeroFactor},{title:"One",value:x.OneFactor},{title:"Src Color",value:x.SrcColorFactor},{title:"One Minus Src Color",value:x.OneMinusSrcColorFactor},{title:"Src Alpha",value:x.SrcAlphaFactor},{title:"One Minus Src Alpha",value:x.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:x.DstAlphaFactor},{title:"One Minus Dst Alpha",value:x.OneMinusDstAlphaFactor},{title:"Dst Color",value:x.DstColorFactor},{title:"One Minus Dst Color",value:x.OneMinusDstColorFactor},{title:"Src Alpha Saturate",value:x.SrcAlphaSaturateFactor},{title:"Constant Color",value:x.ConstantColorFactor},{title:"One Minus Constant Color",value:x.OneMinusConstantColorFactor},{title:"Constant Alpha",value:x.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:x.OneMinusConstantAlphaFactor}],Fx=[{title:"Zero",value:x.ZeroFactor},{title:"One",value:x.OneFactor},{title:"Src Color",value:x.SrcColorFactor},{title:"One Minus Src Color",value:x.OneMinusSrcColorFactor},{title:"Src Alpha",value:x.SrcAlphaFactor},{title:"One Minus Src Alpha",value:x.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:x.DstAlphaFactor},{title:"One Minus Dst Alpha",value:x.OneMinusDstAlphaFactor},{title:"Dst Color",value:x.DstColorFactor},{title:"One Minus Dst Color",value:x.OneMinusDstColorFactor},{title:"Constant Color",value:x.ConstantColorFactor},{title:"One Minus Constant Color",value:x.OneMinusConstantColorFactor},{title:"Constant Alpha",value:x.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:x.OneMinusConstantAlphaFactor}];function vr(a,e){a.needsUpdate=!0,a.type="option",a.options=e}function Ox(a,e,t,s){return{type:"boolean",title:ll(a),prop:a,value:e,needsUpdate:!0,onChange:(i,n)=>{s.updateObject(t.uuid,`material.${a}`,n),s.updateObject(t.uuid,"material.needsUpdate",!0);const r=s.getScene(t.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",t.uuid);qe(o,`material.${a}`,n)}}}}function Bx(a,e,t,s){const i={type:"number",title:ll(a),prop:a,value:e,min:void 0,max:void 0,step:.01,needsUpdate:!0,onChange:(n,r)=>{s.updateObject(t.uuid,`material.${a}`,r),s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const l=o.getObjectByProperty("uuid",t.uuid);qe(l,`material.${a}`,r)}}};switch(a){case"blending":vr(i,Nx);break;case"blendDst":vr(i,Fx);break;case"blendEquation":vr(i,Px);break;case"blendSrc":vr(i,Dx);break;case"side":vr(i,Rx);break}return cm(a)&&(i.value=Number(e),i.type="range",i.min=Math.min(0,i.value),i.max=Math.max(1,i.value),i.step=.01),i}function Ix(a,e,t,s){const i={type:"string",title:ll(a),prop:a,value:e,needsUpdate:!0,onChange:(r,o)=>{s.updateObject(t.uuid,`material.${a}`,o),s.updateObject(t.uuid,"material.needsUpdate",!0);const l=s.getScene(t.uuid);if(l!==null){const c=l.getObjectByProperty("uuid",t.uuid);qe(c,`material.${a}`,o)}},onKeyDown:r=>{}};return(a==="vertexShader"||a==="fragmentShader")&&(i.type="field",i.disabled=!1,i.latest=i.value,i.onChange=(r,o)=>{i.latest=o,s.updateObject(t.uuid,`material.${a}`,o);const l=s.getScene(t.uuid);if(l!==null){const c=l.getObjectByProperty("uuid",t.uuid);qe(c,`material.${a}`,o)}},i.onKeyDown=r=>{if(r.key==="Enter"&&(r.altKey||r.metaKey)){s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const l=o.getObjectByProperty("uuid",t.uuid);qe(l,"material.needsUpdate",!0)}}}),i}function Lx(a){return a.x!==void 0&&a.y!==void 0&&a.z===void 0}function Ux(a){return a.x!==void 0&&a.y!==void 0&&a.z!==void 0&&a.w===void 0}function kx(a){return a.x!==void 0&&a.y!==void 0&&a.z!==void 0&&a.w!==void 0}function dh(a){a.sort((e,t)=>e.title<t.title?-1:e.title>t.title?1:0)}function Zr(a,e,t,s,i="",n=!1){const r=ll(a).split(".")[0].replaceAll("[","").replaceAll("]",""),o=i.length>0?`${i}.${a}`:a,l=typeof e;if(l==="boolean"||l==="string")return{title:r,prop:o,type:l,value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(l==="number"){const c={title:r,prop:o,type:"number",value:e,step:.01,disabled:n,onChange:(h,u)=>{s.updateObject(t.uuid,`material.${o}`,u);const d=s.getScene(t.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",t.uuid);qe(p,`material.${o}`,u)}}};return cm(r)&&(c.type="range",c.min=0,c.max=1),c}else{if(e.isColor)return{title:r,prop:o,type:"color",value:e,disabled:n,onChange:(c,h)=>{const u=new x.Color(h);s.updateObject(t.uuid,`material.${o}`,u);const d=s.getScene(t.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",t.uuid);qe(p,`material.${o}`,u)}}};if(Array.isArray(e)){const c=[];for(const h in e){const u=e[h],d=`[${h.toString()}]`;if(u.value!==void 0){const p=Zr(`${d}.value`,u.value,t,s,o,n);p!==void 0&&c.push(p)}else{const p=Zr(d,u,t,s,o,n);p!==void 0&&c.push(p)}}if(c.length>0)return dh(c),{title:r,items:c}}else{if(Lx(e))return{title:r,prop:o,type:"vector2",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(Ux(e))return{title:r,prop:o,type:"grid3",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(kx(e))return{title:r,prop:o,type:"grid4",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(e.isEuler)return{title:r,prop:o,type:"euler",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(e.src!==void 0)return{title:r,type:"image",value:e,disabled:n,onChange:(c,h)=>{const u=Mx(a),d=i.length>0?`${i}.${u}`:u;s.createTexture(t.uuid,`material.${d}`,h);const p=s.getScene(t.uuid);if(p!==null){const f=p.getObjectByProperty("uuid",t.uuid);if(f!==void 0){const m=y=>{const g=f.material,_=d.split(".");switch(_.length){case 1:g[_[0]]=y;break;case 2:g[_[0]][_[1]]=y;break;case 3:g[_[0]][_[1]][_[2]]=y;break;case 4:g[_[0]][_[1]][_[2]][_[3]]=y;break;case 5:g[_[0]][_[1]][_[2]][_[3]][_[4]]=y;break}g.needsUpdate=!0};h.src.length>0?im(h.src).then(y=>{y.offset.set(h.offset[0],h.offset[1]),y.repeat.set(h.repeat[0],h.repeat[1]),m(y)}):m(null)}}}};if(e.elements!==void 0)return{title:r,prop:o,type:e.elements.length>9?"grid4":"grid3",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};{const c=[],h=a==="defines"||a==="extensions";try{for(const u in e){const d=e[u];if(d!==void 0)if(d.value!==void 0){const p=Zr(`${u}.value`,d.value,t,s,o,h);p!==void 0&&c.push(p)}else{const p=Zr(u,d,t,s,o,h);p!==void 0&&c.push(p)}}}catch{console.log("Issue cycling through material object:",a,e)}if(c.length>0)return dh(c),{title:r,items:c}}}}}function Sd(a,e,t){const s=[];for(const i in a){if(!Cx(i))continue;const n=typeof a[i],r=a[i];if(n==="boolean")s.push(Ox(i,r,e,t));else if(n==="number")s.push(Bx(i,r,e,t));else if(n==="string")s.push(Ix(i,r,e,t));else if(n==="object"){const o=Zr(i,r,e,t);o!==void 0&&s.push(o)}else r!==void 0&&console.log("other:",i,n,r)}return dh(s),s.push({title:"Update Material",type:"button",onChange:()=>{t.updateObject(e.uuid,"material.needsUpdate",!0);const i=t.getScene(e.uuid);if(i!==null){const n=i.getObjectByProperty("uuid",e.uuid);qe(n,"material.needsUpdate",!0)}}}),s}function zx(a,e,t){function s(){return`${t.app.appID}_material`}const i=localStorage.getItem(s()),n=i!==null?i==="open":!1;function r(l){localStorage.setItem(s(),l?"open":"closed")}const o=a.material;if(Array.isArray(o)){const l=[],c=o.length;for(let h=0;h<c;h++)l.push(M.jsx(cs,{app:e,title:`Material ${h}`,items:Sd(o[h],a,t)},`Material ${h}`));return M.jsx(M.Fragment,{children:l})}else return M.jsx(cs,{app:e,title:"Material",items:Sd(o,a,t),expanded:n,onToggle:l=>{r(l)}})}const vd="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 Gx(a){const e=a.step!==void 0?a.step:.01,t=W.useRef(null),s=W.useRef(null),i=W.useRef(null),n=W.useRef(null),r=W.useRef(null),[o]=W.useState(a.value),[l,c]=W.useState(a.value.offset[0]),[h,u]=W.useState(a.value.offset[1]),[d,p]=W.useState(a.value.repeat[0]),[f,m]=W.useState(a.value.repeat[1]);function y(_,b,T,S,C){if(a.onChange!==void 0){const w=a.prop!==void 0?a.prop:a.title;a.onChange(w,{src:_,offset:[b,T],repeat:[S,C]})}}function g(_){const b=t.current.src,T=_.target.value;switch(_.target){case s.current:c(T),y(b,T,h,d,f);break;case i.current:u(T),y(b,l,T,d,f);break;case n.current:p(T),y(b,l,h,T,f);break;case r.current:m(T),y(b,l,h,d,T);break}}return M.jsxs("div",{className:"imageField",children:[M.jsx("img",{alt:a.title,ref:t,onClick:()=>{Ax().then(_=>{t.current.src=_,y(_,l,h,d,f)})},src:o.src.length>0?o.src:vd}),M.jsxs("div",{className:"fields",children:[M.jsxs("div",{children:[M.jsx("span",{children:"Offset:"}),M.jsx("input",{ref:s,type:"number",value:l,step:e,name:ct(),onChange:g}),M.jsx("input",{ref:i,type:"number",value:h,step:e,name:ct(),onChange:g})]}),M.jsxs("div",{children:[M.jsx("span",{children:"Repeat:"}),M.jsx("input",{ref:n,type:"number",value:d,step:e,name:ct(),onChange:g}),M.jsx("input",{ref:r,type:"number",value:f,step:e,name:ct(),onChange:g})]}),M.jsx("button",{onClick:()=>{y("",l,h,d,f),t.current.src=vd},children:"Clear"})]})]})}function Eo(a){let e=a.value;e!==void 0&&(e.isColor!==void 0?e=oh(a.value):a.type==="color"&&(e=oh(new x.Color().setStyle(a.value,x.LinearSRGBColorSpace))));const[t,s]=W.useState(e),i=W.useRef(null),n=c=>{let h=c.target.value;if(a.type==="boolean")h=c.target.checked;else if(a.type==="option"&&(typeof a.value=="number"?h=Number(h):typeof a.value=="boolean"?h=!!h:typeof a.value=="object"&&(h=JSON.parse(h)),a.options!==void 0)){const u=a.options.length;for(let d=0;d<u&&a.options[d].value!==h;d++);}s(h),a.onChange!==void 0&&a.onChange(a.prop!==void 0?a.prop:a.title,h)},r={};a.disabled&&(r.opacity=.8);const o=a.type==="field"||a.type==="string"&&(t.length>100||t.search(`
49
+ C11,8.22,10.74,8,10.43,8z`})});function nm(a){return M.jsx("li",{className:`reorder-item ${a.draggingIndex===a.index?"dragging":""}`,draggable:!0,onDragStart:()=>a.onDragStart(a.index),onDragOver:e=>{e.preventDefault(),a.onDragOver(a.index)},onDragEnd:a.onDragEnd,children:M.jsxs("div",{children:[cx,M.jsx("span",{children:a.title}),M.jsx("button",{className:"closeIcon",onClick:()=>a.onDelete(a.index),children:lx})]})})}function rm(a){const[e,t]=W.useState(!1),[s,i]=W.useState(a.options),[n,r]=W.useState(null),o=p=>{a.onDragComplete(p),i(p)},l=p=>{const f=[...s];f.splice(p,1),o(f)},c=p=>{r(p)},h=p=>{if(n===p||n===null)return;const f=[...s],m=f.splice(n,1)[0];f.splice(p,0,m),r(p),i(f)},u=()=>{a.onDragComplete(s),r(null)};let d="dropdown draggable";return a.subdropdown&&(d+=" subdropdown"),M.jsxs("div",{className:d,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[M.jsx(Yh,{title:a.title}),M.jsx("ul",{className:"reorder-list",style:{display:e?"block":"none"},children:s.map((p,f)=>M.jsx(nm,{title:p,index:f,draggingIndex:n,onDelete:l,onDragStart:c,onDragOver:h,onDragEnd:u},p))})]})}function am(a){const[e,t]=W.useState(!1),s=[];a.options.map((n,r)=>{a.onSelect!==void 0&&(n.onSelect=a.onSelect),s.push(M.jsx(om,{option:n},r))});let i="dropdown";return a.subdropdown&&(i+=" subdropdown"),M.jsxs("div",{className:i,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[M.jsx(Yh,{title:a.title}),M.jsx("ul",{style:{visibility:e?"visible":"hidden"},children:s})]})}function om(a){const{option:e}=a,[t,s]=W.useState("");let i;switch(e.type){case"draggable":i=M.jsx(rm,{title:e.title,options:e.value,onDragComplete:n=>{e.onDragComplete!==void 0&&e.onDragComplete(n)},subdropdown:!0});break;case"dropdown":i=M.jsx(am,{title:e.title,options:e.value,onSelect:e.onSelect,subdropdown:!0});break;case"option":i=M.jsx("button",{onClick:()=>{e.onSelect!==void 0&&e.onSelect(e.value),e.selectable&&(t!==e.title?s(e.title):s(""))},children:e.title});break}return M.jsx("li",{className:t===e.title?"selected":"",children:i},ct())}function fa(a){const[e,t]=W.useState(a.open!==void 0?a.open:!0),s=!e||a.children===void 0,i=W.useRef(null),n=()=>{a.app.dispatchEvent({type:X.REMOVE_SCENE,value:a.scene})};return M.jsxs("div",{className:`accordion ${s?"hide":""}`,children:[M.jsxs("button",{className:"toggle",onClick:()=>{const r=!e;a.onToggle!==void 0&&a.onToggle(r),t(r)},children:[M.jsx("p",{className:`status ${e?"open":""}`,children:"Toggle"}),M.jsx("p",{className:"label",children:pa(a.label)})]}),a.onRefresh?M.jsxs(M.Fragment,{children:[M.jsx("button",{className:"visibility",ref:i,onClick:()=>{const o=a.app.components.get("three").getScene(a.scene.uuid);if(o){const l=!o.visible;o.visible=l,i.current.style.opacity=l?"1":"0.25"}}}),M.jsx("button",{className:"refresh",onClick:a.onRefresh}),M.jsx("button",{className:"remove",onClick:n})]}):null,a.button,M.jsx("div",{className:e?"open":"",children:M.jsx("div",{children:a.children})},Math.random())]})}function Xh(a){if(a.child===void 0)return console.log("Hermes - No child attached"),null;const e=W.useRef(null),[t,s]=W.useState(!1),i=a.child.children.length>0,n=[];return a.child.children.length>0&&a.child.children.map((r,o)=>{n.push(M.jsx(Xh,{app:a.app,child:r,three:a.three},o))}),W.useEffect(()=>{if(a.child){const r=a.three.getScene(a.child.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",a.child.uuid);o!==void 0?e.current.style.opacity=o.visible?"1":"0.25":console.log(`Hermes - Can't find child: ${a.child.uuid}`)}else console.log(`Hermes - Can't find Scene: ${a.child.uuid}`)}},[t]),M.jsxs("div",{className:"childObject",children:[M.jsxs("div",{className:"child",children:[i?M.jsx("button",{className:"status",style:{backgroundPositionX:t?"-14px":"2px"},onClick:()=>{s(!t)}}):null,M.jsx("button",{className:"name",style:{left:i?"20px":"5px"},onClick:()=>{a.child!==void 0?(a.three.getObject(a.child.uuid),!t&&i&&s(!0)):console.log("Hermes - No child attached...")},children:a.child.name.length>0?`${a.child.name} (${a.child.type})`:`${a.child.type}::${a.child.uuid}`}),M.jsx("button",{className:"visibility",ref:e,onClick:()=>{if(a.child){const r=a.three.getScene(a.child.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",a.child.uuid);if(o!==void 0){const l="visible",c=!o.visible;e.current.style.opacity=c?"1":"0.25",a.three.updateObject(a.child.uuid,l,c),qe(o,l,c)}else console.log(`Hermes - Couldn't find object: ${a.child.uuid}`,r)}else console.log(`Hermes - Couldn't find object in scene: ${a.child.uuid}, ${a.child.name}`)}}}),M.jsx("div",{className:`icon ${J0(a.child)}`})]}),M.jsx("div",{className:t?"open":"",children:M.jsx("div",{className:"container",children:n})})]},Math.random())}function uh(a){const e=[];return a.child?.children.map((t,s)=>{e.push(M.jsx(Xh,{app:a.app,child:t,scene:a.scene,three:a.three},s))}),M.jsx("div",{className:`scene ${a.class!==void 0?a.class:""}`,children:e})}function Xr(a){const[e,t]=W.useState(a.defaultValue);return W.useEffect(()=>{let s=!1,i=-1,n=0,r=a.defaultValue,o=!1;const l=p=>{o=p.ctrlKey},c=p=>{s=!0,n=Number(a.input.current?.value),i=p.clientX,document.addEventListener("mouseup",u,!1),document.addEventListener("mousemove",h,!1),document.addEventListener("contextmenu",u,!1)},h=p=>{if(!s)return;const f=a.step!==void 0?a.step:1,m=(p.clientX-i)*f*(o?10:1);r=Number((n+m).toFixed(4)),a.min!==void 0&&(r=Math.max(r,a.min)),a.max!==void 0&&(r=Math.min(r,a.max)),a.onChange!==void 0&&a.onChange(r),t(r)},u=()=>{s=!1,document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u)},d=p=>{const f=Number(p.target.value);a.onChange!==void 0&&a.onChange(f),t(f)};return a.label.current?.addEventListener("mousedown",c,!1),a.sliderRef!==void 0&&a.sliderRef.current?.addEventListener("input",d),document.addEventListener("keydown",l,!1),document.addEventListener("keyup",l,!1),()=>{a.label.current?.removeEventListener("mousedown",c),a.sliderRef!==void 0&&a.sliderRef.current?.removeEventListener("input",d),document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u),document.removeEventListener("keydown",l),document.addEventListener("keyup",l,!1)}},[]),e}function cn(a){const e=W.useRef(null),t=W.useRef(null),[s,i]=W.useState(a.value);return Xr({label:a.labelRef,input:e,sliderRef:t,defaultValue:s,min:a.min,max:a.max,step:a.step,onChange:n=>{i(n),a.onChange!==void 0&&a.onChange(a.prop,n)}}),M.jsxs(M.Fragment,{children:[a.type==="number"&&M.jsx("input",{alt:a.alt,className:a.className,ref:e,type:"number",value:s,min:a.min,max:a.max,step:a.step,disabled:a.disabled,name:ct(),onChange:n=>{if(i(n.target.value),n.target.value.length===0)return;const r=Number(n.target.value);isNaN(r)||a.onChange!==void 0&&a.onChange(a.prop,r)}}),a.type==="range"&&M.jsxs(M.Fragment,{children:[M.jsx("input",{type:"text",value:s.toString(),disabled:a.disabled,ref:e,className:"min",name:ct(),onChange:n=>{if(n.target.value.length===0)return;const r=Number(n.target.value);isNaN(r)||(i(r),a.onChange!==void 0&&a.onChange(a.prop,r))}}),M.jsx("input",{disabled:a.disabled,type:"range",value:s,min:a.min,max:a.max,step:a.step,ref:t,name:ct(),onChange:da})]})]})}function hx(a){const e=W.useRef(null),t=W.useRef(null),s=W.useRef(null),i=W.useRef(null),n=W.useRef(null),r=W.useRef(null),o=W.useRef(null),l=W.useRef(null),c=W.useRef(null),h=W.useRef(null),[u,d]=W.useState(a.value.x),[p,f]=W.useState(a.value.y),[m,y]=W.useState({min:Math.min(a.min,Math.min(a.value.x,a.value.y)),max:Math.max(a.max,Math.max(a.value.x,a.value.y))}),[g,_]=W.useState(!1);Xr({label:o,input:e,defaultValue:u,min:m.min,max:m.max,step:.01,onChange:P=>{d(P),a.onChange({target:{value:{x:P,y:p}}})}}),Xr({label:l,input:t,defaultValue:p,min:m.min,max:m.max,step:.01,onChange:P=>{f(P),a.onChange({target:{value:{x:u,y:P}}})}}),Xr({label:c,input:s,defaultValue:m.min,min:m.min-1,max:m.max+1,step:.01,onChange:P=>{y({min:P,max:m.max})}}),Xr({label:h,input:i,defaultValue:m.max,min:m.min-1,max:m.max+1,step:.01,onChange:P=>{y({min:m.min,max:P})}});function b(){g||(window.addEventListener("mousemove",S),window.addEventListener("mouseup",T),_(!0))}function T(){window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",T),_(!1)}function S(P){const z=n.current.getBoundingClientRect(),$=Ti(0,99,P.clientX-z.left)/99,q=1-Ti(0,99,P.clientY-z.top)/99,j=ss(rr(m.min,m.max,$),3),Z=ss(rr(m.min,m.max,q),3);a.onChange({target:{value:{x:j,y:Z}}}),d(j),f(Z)}function C(){const P=Number(s.current.value);y({min:P,max:m.max}),u<P&&d(Ti(P,m.max,u)),p<P&&f(Ti(P,m.max,p))}function w(){const P=Number(i.current.value);y({min:m.min,max:P}),u>P&&d(Ti(m.min,P,u)),p>P&&f(Ti(m.min,P,p))}W.useEffect(()=>{r.current.style.left=`${Uo(m.min,m.max,u)*100}%`,r.current.style.top=`${(1-Uo(m.min,m.max,p))*100}%`},[m,u,p]);const R=a.step!==void 0?a.step:.01;return M.jsxs("div",{className:"vector2",children:[M.jsxs("div",{className:"fields",children:[M.jsxs("div",{children:[M.jsx("span",{ref:o,children:"X"}),M.jsx("input",{ref:e,type:"number",value:u,min:m.min,max:m.max,step:R,name:ct(),onChange:P=>{if(d(P.target.value),P.target.value.length===0)return;const z=Number(P.target.value);isNaN(z)||(a.onChange({target:{value:{x:z,y:p}}}),z<m.min&&y({min:z,max:m.max}))}})]}),M.jsxs("div",{children:[M.jsx("span",{ref:l,children:"Y"}),M.jsx("input",{ref:t,type:"number",value:p,min:m.min,max:m.max,step:R,name:ct(),onChange:P=>{if(f(P.target.value),P.target.value.length===0)return;const z=Number(P.target.value);isNaN(z)||(a.onChange({target:{value:{x:u,y:z}}}),z>m.max&&y({min:m.min,max:z}))}})]}),M.jsxs("div",{children:[M.jsx("span",{ref:c,children:"Min"}),M.jsx("input",{ref:s,type:"number",value:m.min,step:R,name:ct(),onChange:C})]}),M.jsxs("div",{children:[M.jsx("span",{ref:h,children:"Max"}),M.jsx("input",{ref:i,type:"number",value:m.max,step:R,name:ct(),onChange:w})]})]}),M.jsxs("div",{className:"input",ref:n,onMouseDown:b,onMouseUp:T,children:[M.jsx("div",{className:"x"}),M.jsx("div",{className:"y"}),M.jsx("div",{className:"pt",ref:r})]})]})}const gt=["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 bd=1234567;const na=Math.PI/180,ar=180/Math.PI;function Zs(){const a=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,s=Math.random()*4294967295|0;return(gt[a&255]+gt[a>>8&255]+gt[a>>16&255]+gt[a>>24&255]+"-"+gt[e&255]+gt[e>>8&255]+"-"+gt[e>>16&15|64]+gt[e>>24&255]+"-"+gt[t&63|128]+gt[t>>8&255]+"-"+gt[t>>16&255]+gt[t>>24&255]+gt[s&255]+gt[s>>8&255]+gt[s>>16&255]+gt[s>>24&255]).toLowerCase()}function de(a,e,t){return Math.max(e,Math.min(t,a))}function Zh(a,e){return(a%e+e)%e}function Ki(a,e,t,s,i){return s+(a-e)*(i-s)/(t-e)}function ux(a,e,t){return a!==e?(t-a)/(e-a):0}function Ni(a,e,t){return(1-t)*a+t*e}function dx(a,e,t,s){return Ni(a,e,1-Math.exp(-t*s))}function px(a,e=1){return e-Math.abs(Zh(a,e*2)-e)}function fx(a,e,t){return a<=e?0:a>=t?1:(a=(a-e)/(t-e),a*a*(3-2*a))}function mx(a,e,t){return a<=e?0:a>=t?1:(a=(a-e)/(t-e),a*a*a*(a*(a*6-15)+10))}function gx(a,e){return a+Math.floor(Math.random()*(e-a+1))}function yx(a,e){return a+Math.random()*(e-a)}function xx(a){return a*(.5-Math.random())}function _x(a){a!==void 0&&(bd=a);let e=bd+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function zo(a){return a*na}function lm(a){return a*ar}function bx(a){return(a&a-1)===0&&a!==0}function Tx(a){return Math.pow(2,Math.ceil(Math.log(a)/Math.LN2))}function Sx(a){return Math.pow(2,Math.floor(Math.log(a)/Math.LN2))}function vx(a,e,t,s,i){const n=Math.cos,r=Math.sin,o=n(t/2),l=r(t/2),c=n((e+s)/2),h=r((e+s)/2),u=n((e-s)/2),d=r((e-s)/2),p=n((s-e)/2),f=r((s-e)/2);switch(i){case"XYX":a.set(o*h,l*u,l*d,o*c);break;case"YZY":a.set(l*d,o*h,l*u,o*c);break;case"ZXZ":a.set(l*u,l*d,o*h,o*c);break;case"XZX":a.set(o*h,l*f,l*p,o*c);break;case"YXY":a.set(l*p,o*h,l*f,o*c);break;case"ZYZ":a.set(l*f,l*p,o*h,o*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function At(a,e){switch(e.constructor){case Float32Array:return a;case Uint32Array:return a/4294967295;case Uint16Array:return a/65535;case Uint8Array:return a/255;case Int32Array:return Math.max(a/2147483647,-1);case Int16Array:return Math.max(a/32767,-1);case Int8Array:return Math.max(a/127,-1);default:throw new Error("Invalid component type.")}}function oe(a,e){switch(e.constructor){case Float32Array:return a;case Uint32Array:return Math.round(a*4294967295);case Uint16Array:return Math.round(a*65535);case Uint8Array:return Math.round(a*255);case Int32Array:return Math.round(a*2147483647);case Int16Array:return Math.round(a*32767);case Int8Array:return Math.round(a*127);default:throw new Error("Invalid component type.")}}const wx={DEG2RAD:na,RAD2DEG:ar,generateUUID:Zs,clamp:de,euclideanModulo:Zh,mapLinear:Ki,inverseLerp:ux,lerp:Ni,damp:dx,pingpong:px,smoothstep:fx,smootherstep:mx,randInt:gx,randFloat:yx,randFloatSpread:xx,seededRandom:_x,degToRad:zo,radToDeg:lm,isPowerOfTwo:bx,ceilPowerOfTwo:Tx,floorPowerOfTwo:Sx,setQuaternionFromProperEuler:vx,normalize:oe,denormalize:At};function Td(a){const e=a.value.x!==void 0&&a.value.y!==void 0&&a.value.z!==void 0,t=a.value.isEuler!==void 0,s=a.value.elements!==void 0,i=a.step!==void 0?a.step:.01,n=[];if(t){const r=W.useMemo(()=>a.value,[]);["_x","_y","_z"].forEach(l=>{const c=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("span",{ref:c,children:l.substring(1).toUpperCase()}),M.jsx(cn,{value:lm(r[l]),type:"number",prop:l,step:.1,labelRef:c,onChange:(h,u)=>{r[h]=zo(u),a.onChange({target:{value:r}})}})]},l))})}else if(e){const r=W.useMemo(()=>a.value,[]),o=(c,h)=>{r[c]=h,a.onChange({target:{value:r}})};["x","y","z"].forEach(c=>{const h=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("label",{ref:h,children:c.toUpperCase()}),M.jsx(cn,{value:r[c],type:"number",prop:c,step:i,labelRef:h,onChange:o})]},c))})}else if(s){const r=W.useMemo(()=>a.value,[]),o=(l,c)=>{const h=Number(l);r.elements[h]=c,a.onChange({target:{value:r}})};for(let l=0;l<9;l++){const c=W.useRef(null);n.push(M.jsxs("div",{children:[M.jsx("label",{ref:c,children:l+1}),M.jsx(cn,{value:r.elements[l],type:"number",prop:l.toString(),step:i,labelRef:c,onChange:o})]},l.toString()))}}return M.jsx("div",{className:"grid3",children:n},Math.random().toString())}function Ex(a){const e=a.value.x!==void 0,t=a.step!==void 0?a.step:.01,s=[];if(e){const i=W.useMemo(()=>a.value,[]),n=(o,l)=>{i[o]=l,a.onChange({target:{value:i}})};["x","y","z","w"].forEach(o=>{const l=W.useRef(null);s.push(M.jsxs("div",{children:[M.jsx("label",{ref:l,children:o.toUpperCase()}),M.jsx(cn,{value:i[o],type:"number",prop:o,step:t,labelRef:l,onChange:n})]},o))})}else{const i=W.useMemo(()=>a.value,[]),n=(r,o)=>{const l=Number(r);i.elements[l]=o,a.onChange({target:{value:i}})};for(let r=0;r<16;r++){const o=W.useRef(null);s.push(M.jsxs("div",{children:[M.jsx("span",{ref:o,children:r+1}),M.jsx(cn,{value:i.elements[r],type:"number",prop:r.toString(),step:t,labelRef:o,onChange:n})]},r.toString()))}}return M.jsx("div",{className:"grid4",children:s})}function Cx(a){return!(a==="defaultAttributeValues"||a==="forceSinglePass"||a==="linecap"||a==="linejoin"||a==="linewidth"||a==="normalMapType"||a==="precision"||a==="shadowSide"||a==="uniformsGroups"||a==="uniformsNeedUpdate"||a==="userData"||a==="version"||a==="wireframeLinecap"||a==="wireframeLinejoin"||a==="wireframeLinewidth"||a.slice(0,4)==="clip"||a.slice(0,7)==="polygon"||a.slice(0,7)==="stencil"||a.slice(0,2)==="is")}function Mx(a){switch(a){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 a}function ll(a){switch(a){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 a}function cm(a){const e=a.toLowerCase();return e.search("intensity")>-1||e==="anisotropyrotation"||e==="blendalpha"||e==="bumpscale"||e==="clearcoatroughness"||e==="displacementbias"||e==="displacementscale"||e==="metalness"||e==="opacity"||e==="reflectivity"||e==="refractionratio"||e==="roughness"||e==="sheenroughness"}function Ax(){const a=document.createElement("input");return a.type="file",new Promise((e,t)=>{a.addEventListener("change",function(){if(a.files===null)t();else{const s=a.files[0],i=new FileReader;i.onload=function(n){e(n.target.result)},i.readAsDataURL(s)}}),a.click()})}const Rx=[{title:"Front",value:x.FrontSide},{title:"Back",value:x.BackSide},{title:"Double",value:x.DoubleSide}],Nx=[{title:"No Blending",value:x.NoBlending},{title:"Normal",value:x.NormalBlending},{title:"Additive",value:x.AdditiveBlending},{title:"Subtractive",value:x.SubtractiveBlending},{title:"Multiply",value:x.MultiplyBlending},{title:"Custom",value:x.CustomBlending}],Px=[{title:"Add",value:x.AddEquation},{title:"Subtract",value:x.SubtractEquation},{title:"Reverse Subtract",value:x.ReverseSubtractEquation},{title:"Min",value:x.MinEquation},{title:"Max",value:x.MaxEquation}],Dx=[{title:"Zero",value:x.ZeroFactor},{title:"One",value:x.OneFactor},{title:"Src Color",value:x.SrcColorFactor},{title:"One Minus Src Color",value:x.OneMinusSrcColorFactor},{title:"Src Alpha",value:x.SrcAlphaFactor},{title:"One Minus Src Alpha",value:x.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:x.DstAlphaFactor},{title:"One Minus Dst Alpha",value:x.OneMinusDstAlphaFactor},{title:"Dst Color",value:x.DstColorFactor},{title:"One Minus Dst Color",value:x.OneMinusDstColorFactor},{title:"Src Alpha Saturate",value:x.SrcAlphaSaturateFactor},{title:"Constant Color",value:x.ConstantColorFactor},{title:"One Minus Constant Color",value:x.OneMinusConstantColorFactor},{title:"Constant Alpha",value:x.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:x.OneMinusConstantAlphaFactor}],Fx=[{title:"Zero",value:x.ZeroFactor},{title:"One",value:x.OneFactor},{title:"Src Color",value:x.SrcColorFactor},{title:"One Minus Src Color",value:x.OneMinusSrcColorFactor},{title:"Src Alpha",value:x.SrcAlphaFactor},{title:"One Minus Src Alpha",value:x.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:x.DstAlphaFactor},{title:"One Minus Dst Alpha",value:x.OneMinusDstAlphaFactor},{title:"Dst Color",value:x.DstColorFactor},{title:"One Minus Dst Color",value:x.OneMinusDstColorFactor},{title:"Constant Color",value:x.ConstantColorFactor},{title:"One Minus Constant Color",value:x.OneMinusConstantColorFactor},{title:"Constant Alpha",value:x.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:x.OneMinusConstantAlphaFactor}];function vr(a,e){a.needsUpdate=!0,a.type="option",a.options=e}function Ox(a,e,t,s){return{type:"boolean",title:ll(a),prop:a,value:e,needsUpdate:!0,onChange:(i,n)=>{s.updateObject(t.uuid,`material.${a}`,n),s.updateObject(t.uuid,"material.needsUpdate",!0);const r=s.getScene(t.uuid);if(r!==null){const o=r.getObjectByProperty("uuid",t.uuid);qe(o,`material.${a}`,n)}}}}function Bx(a,e,t,s){const i={type:"number",title:ll(a),prop:a,value:e,min:void 0,max:void 0,step:.01,needsUpdate:!0,onChange:(n,r)=>{s.updateObject(t.uuid,`material.${a}`,r),s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const l=o.getObjectByProperty("uuid",t.uuid);qe(l,`material.${a}`,r)}}};switch(a){case"blending":vr(i,Nx);break;case"blendDst":vr(i,Fx);break;case"blendEquation":vr(i,Px);break;case"blendSrc":vr(i,Dx);break;case"side":vr(i,Rx);break}return cm(a)&&(i.value=Number(e),i.type="range",i.min=Math.min(0,i.value),i.max=Math.max(1,i.value),i.step=.01),i}function Ix(a,e,t,s){const i={type:"string",title:ll(a),prop:a,value:e,needsUpdate:!0,onChange:(r,o)=>{s.updateObject(t.uuid,`material.${a}`,o),s.updateObject(t.uuid,"material.needsUpdate",!0);const l=s.getScene(t.uuid);if(l!==null){const c=l.getObjectByProperty("uuid",t.uuid);qe(c,`material.${a}`,o)}},onKeyDown:r=>{}};return(a==="vertexShader"||a==="fragmentShader")&&(i.type="field",i.disabled=!1,i.latest=i.value,i.onChange=(r,o)=>{i.latest=o,s.updateObject(t.uuid,`material.${a}`,o);const l=s.getScene(t.uuid);if(l!==null){const c=l.getObjectByProperty("uuid",t.uuid);qe(c,`material.${a}`,o)}},i.onKeyDown=r=>{if(r.key==="Enter"&&(r.altKey||r.metaKey)){s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const l=o.getObjectByProperty("uuid",t.uuid);qe(l,"material.needsUpdate",!0)}}}),i}function Lx(a){return a.x!==void 0&&a.y!==void 0&&a.z===void 0}function Ux(a){return a.x!==void 0&&a.y!==void 0&&a.z!==void 0&&a.w===void 0}function kx(a){return a.x!==void 0&&a.y!==void 0&&a.z!==void 0&&a.w!==void 0}function dh(a){a.sort((e,t)=>e.title<t.title?-1:e.title>t.title?1:0)}function Zr(a,e,t,s,i="",n=!1){const r=ll(a).split(".")[0].replaceAll("[","").replaceAll("]",""),o=i.length>0?`${i}.${a}`:a,l=typeof e;if(l==="boolean"||l==="string")return{title:r,prop:o,type:l,value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(l==="number"){const c={title:r,prop:o,type:"number",value:e,step:.01,disabled:n,onChange:(h,u)=>{s.updateObject(t.uuid,`material.${o}`,u);const d=s.getScene(t.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",t.uuid);qe(p,`material.${o}`,u)}}};return cm(r)&&(c.type="range",c.min=0,c.max=1),c}else{if(e.isColor)return{title:r,prop:o,type:"color",value:e,disabled:n,onChange:(c,h)=>{const u=new x.Color(h);s.updateObject(t.uuid,`material.${o}`,u);const d=s.getScene(t.uuid);if(d!==null){const p=d.getObjectByProperty("uuid",t.uuid);qe(p,`material.${o}`,u)}}};if(Array.isArray(e)){const c=[];for(const h in e){const u=e[h],d=`[${h.toString()}]`;if(u.value!==void 0){const p=Zr(`${d}.value`,u.value,t,s,o,n);p!==void 0&&c.push(p)}else{const p=Zr(d,u,t,s,o,n);p!==void 0&&c.push(p)}}if(c.length>0)return dh(c),{title:r,items:c}}else{if(Lx(e))return{title:r,prop:o,type:"vector2",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(Ux(e))return{title:r,prop:o,type:"grid3",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(kx(e))return{title:r,prop:o,type:"grid4",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(e.isEuler)return{title:r,prop:o,type:"euler",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};if(e.src!==void 0)return{title:r,type:"image",value:e,disabled:n,onChange:(c,h)=>{const u=Mx(a),d=i.length>0?`${i}.${u}`:u;s.createTexture(t.uuid,`material.${d}`,h);const p=s.getScene(t.uuid);if(p!==null){const f=p.getObjectByProperty("uuid",t.uuid);if(f!==void 0){const m=y=>{const g=f.material,_=d.split(".");switch(_.length){case 1:g[_[0]]=y;break;case 2:g[_[0]][_[1]]=y;break;case 3:g[_[0]][_[1]][_[2]]=y;break;case 4:g[_[0]][_[1]][_[2]][_[3]]=y;break;case 5:g[_[0]][_[1]][_[2]][_[3]][_[4]]=y;break}g.needsUpdate=!0};h.src.length>0?im(h.src).then(y=>{y.offset.set(h.offset[0],h.offset[1]),y.repeat.set(h.repeat[0],h.repeat[1]),m(y)}):m(null)}}}};if(e.elements!==void 0)return{title:r,prop:o,type:e.elements.length>9?"grid4":"grid3",value:e,disabled:n,onChange:(c,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",t.uuid);qe(d,`material.${o}`,h)}}};{const c=[],h=a==="defines"||a==="extensions";try{for(const u in e){const d=e[u];if(d!==void 0)if(d.value!==void 0){const p=Zr(`${u}.value`,d.value,t,s,o,h);p!==void 0&&c.push(p)}else{const p=Zr(u,d,t,s,o,h);p!==void 0&&c.push(p)}}}catch{console.log("Issue cycling through material object:",a,e)}if(c.length>0)return dh(c),{title:r,items:c}}}}}function Sd(a,e,t){const s=[];for(const i in a){if(!Cx(i))continue;const n=typeof a[i],r=a[i];if(n==="boolean")s.push(Ox(i,r,e,t));else if(n==="number")s.push(Bx(i,r,e,t));else if(n==="string")s.push(Ix(i,r,e,t));else if(n==="object"){const o=Zr(i,r,e,t);o!==void 0&&s.push(o)}else r!==void 0&&console.log("other:",i,n,r)}return dh(s),s.push({title:"Update Material",type:"button",onChange:()=>{t.updateObject(e.uuid,"material.needsUpdate",!0);const i=t.getScene(e.uuid);if(i!==null){const n=i.getObjectByProperty("uuid",e.uuid);qe(n,"material.needsUpdate",!0)}}}),s}function zx(a,e,t){function s(){return`${t.app.appID}_material`}const i=localStorage.getItem(s()),n=i!==null?i==="open":!1;function r(l){localStorage.setItem(s(),l?"open":"closed")}const o=a.material;if(Array.isArray(o)){const l=[],c=o.length;for(let h=0;h<c;h++)l.push(M.jsx(cs,{app:e,title:`Material ${h}`,items:Sd(o[h],a,t)},`Material ${h}`));return M.jsx(M.Fragment,{children:l})}else return M.jsx(cs,{app:e,title:"Material",items:Sd(o,a,t),expanded:n,onToggle:l=>{r(l)}})}const vd="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 Gx(a){const e=a.step!==void 0?a.step:.01,t=W.useRef(null),s=W.useRef(null),i=W.useRef(null),n=W.useRef(null),r=W.useRef(null),[o]=W.useState(a.value),[l,c]=W.useState(a.value.offset[0]),[h,u]=W.useState(a.value.offset[1]),[d,p]=W.useState(a.value.repeat[0]),[f,m]=W.useState(a.value.repeat[1]);function y(_,b,T,S,C){if(a.onChange!==void 0){const w=a.prop!==void 0?a.prop:a.title;a.onChange(w,{src:_,offset:[b,T],repeat:[S,C]})}}function g(_){const b=t.current.src,T=_.target.value;switch(_.target){case s.current:c(T),y(b,T,h,d,f);break;case i.current:u(T),y(b,l,T,d,f);break;case n.current:p(T),y(b,l,h,T,f);break;case r.current:m(T),y(b,l,h,d,T);break}}return M.jsxs("div",{className:"imageField",children:[M.jsx("img",{alt:a.title,ref:t,onClick:()=>{Ax().then(_=>{t.current.src=_,y(_,l,h,d,f)})},src:o.src.length>0?o.src:vd}),M.jsxs("div",{className:"fields",children:[M.jsxs("div",{children:[M.jsx("span",{children:"Offset:"}),M.jsx("input",{ref:s,type:"number",value:l,step:e,name:ct(),onChange:g}),M.jsx("input",{ref:i,type:"number",value:h,step:e,name:ct(),onChange:g})]}),M.jsxs("div",{children:[M.jsx("span",{children:"Repeat:"}),M.jsx("input",{ref:n,type:"number",value:d,step:e,name:ct(),onChange:g}),M.jsx("input",{ref:r,type:"number",value:f,step:e,name:ct(),onChange:g})]}),M.jsx("button",{onClick:()=>{y("",l,h,d,f),t.current.src=vd},children:"Clear"})]})]})}function Eo(a){let e=a.value;e!==void 0&&(e.isColor!==void 0?e=oh(a.value):a.type==="color"&&(e=oh(new x.Color().setStyle(a.value,x.LinearSRGBColorSpace))));const[t,s]=W.useState(e),i=W.useRef(null),n=c=>{let h=c.target.value;if(a.type==="boolean")h=c.target.checked;else if(a.type==="option"&&(typeof a.value=="number"?h=Number(h):typeof a.value=="boolean"?h=!!h:typeof a.value=="object"&&(h=JSON.parse(h)),a.options!==void 0)){const u=a.options.length;for(let d=0;d<u&&a.options[d].value!==h;d++);}s(h),a.onChange!==void 0&&a.onChange(a.prop!==void 0?a.prop:a.title,h)},r={};a.disabled&&(r.opacity=.8);const o=a.type==="field"||a.type==="string"&&(t.length>100||t.search(`
50
50
  `)>-1),l=o||a.type==="image"||a.type==="vector2";return M.jsxs("div",{className:`field ${l?"block":""}`,style:r,children:[a.type!=="button"&&M.jsx("span",{ref:i,children:pa(a.title)},"fieldLabel"),a.type==="string"&&!o&&M.jsx("input",{type:"text",disabled:a.disabled,onChange:n,value:t,name:ct()}),(a.type==="field"||a.type==="string"&&o)&&M.jsx("textarea",{cols:50,rows:10,disabled:a.disabled!==void 0?a.disabled:!0,onChange:n,onKeyDown:c=>{a.onKeyDown!==void 0&&a.onKeyDown(c)},value:t,name:ct()}),a.type==="boolean"&&M.jsx("input",{type:"checkbox",disabled:a.disabled,onChange:n,checked:t,name:ct()}),a.type==="number"&&M.jsx(cn,{value:t,type:a.type,prop:a.prop!==void 0?a.prop:a.title,min:a.min,max:a.max,step:a.step,disabled:a.disabled,labelRef:i,onChange:a.onChange}),a.type==="range"&&M.jsx(cn,{value:t,type:a.type,prop:a.prop!==void 0?a.prop:a.title,min:a.min,max:a.max,step:a.step,disabled:a.disabled,labelRef:i,onChange:a.onChange}),a.type==="color"&&M.jsxs(M.Fragment,{children:[M.jsx("input",{type:"text",value:t.toString(),onChange:n,disabled:a.disabled,className:"color",name:ct()}),M.jsx("input",{type:"color",value:t,onChange:n,disabled:a.disabled,name:ct()})]}),a.type==="button"&&M.jsx("button",{disabled:a.disabled,onClick:()=>{a.onChange!==void 0&&a.onChange(a.prop!==void 0?a.prop:a.title,!0)},children:a.title}),a.type==="image"&&M.jsx(Gx,{title:a.title,prop:a.prop,value:a.value,onChange:a.onChange}),a.type==="option"&&M.jsx(M.Fragment,{children:M.jsx("select",{onChange:n,disabled:a.disabled,defaultValue:a.value,name:ct(),children:a.options?.map((c,h)=>M.jsx("option",{value:c.value,children:pa(c.title)},h))})}),a.type==="vector2"&&M.jsx(hx,{step:a.step,value:t,min:0,max:1,onChange:n}),a.type==="grid3"&&M.jsx(Td,{step:a.step,value:t,onChange:n}),a.type==="grid4"&&M.jsx(Ex,{step:a.step,value:t,onChange:n}),a.type==="euler"&&M.jsx(Td,{step:a.step,value:t,onChange:n})]})}function Vx(a){return"items"in a}class cs extends W.Component{subgroupNames=[];subgroupElements=[];valueOverrides=new Map;app;constructor(e){super(e),this.app=e.app,this.state={lastUpdated:Date.now()}}addGroup(e){const t=[];e.items.forEach(n=>{t.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:(r,o)=>{e.onUpdate(r,o)}})});const s=W.createRef(),i=M.jsx(cs,{app:this.app,ref:s,title:e.title,expanded:e.expanded,items:t},Math.random());return this.subgroupNames.push(e.title),this.subgroupElements.push(i),this.setState({lastUpdated:Date.now()}),s}removeGroup(e){const t=this.subgroupNames.length;for(let s=0;s<t;s++){const i=this.subgroupNames[s];if(e===i){this.subgroupNames.splice(s,1),this.subgroupElements.splice(s,1),this.setState({lastUpdated:Date.now()});return}}}setField(e,t){this.valueOverrides.set(e,t),this.setState({lastUpdated:Date.now()})}render(){const e=[];return this.props.items.forEach(t=>{if(Vx(t))e.push(M.jsx(cs,{app:this.app,title:pa(t.title),items:t.items},Math.random()));else{const s=this.valueOverrides.get(t.title),i=s!==void 0?s:t.value;e.push(M.jsx(Eo,{title:t.title,prop:t.prop,value:i,type:t.type,min:t.min,max:t.max,step:t.step,disabled:t.disabled,options:t.options,onChange:(n,r)=>{t.onChange!==void 0&&(this.valueOverrides.delete(t.title),t.onChange(n,r))},onKeyDown:n=>{t.onKeyDown!==void 0&&t.onKeyDown(n)}},Math.random()))}}),this.subgroupElements.forEach(t=>e.push(t)),M.jsx(fa,{app:this.app,label:this.props.title,open:this.props.expanded===!0,onToggle:t=>{this.props.onToggle&&this.props?.onToggle(t)},children:e})}}class xe extends W.Component{static instance;static groups=[];static groupsRefs=[];static groupTitles=[];static app;constructor(e){super(e),this.state={lastUpdate:Date.now()},xe.app=e.app,xe.instance=this,xe.app.addEventListener(X.ADD_GROUP,this.addGroup),xe.app.addEventListener(X.REMOVE_GROUP,this.removeGroup)}componentWillUnmount(){xe.app.removeEventListener(X.ADD_GROUP,this.addGroup),xe.app.removeEventListener(X.REMOVE_GROUP,this.removeGroup)}render(){return M.jsx("div",{className:"customGroups",children:xe.groups},this.state.lastUpdate)}addGroup=e=>{const t=JSON.parse(e.value),s=[];t.items.forEach(i=>{s.push({type:i.type,prop:i.prop,title:i.title!==void 0?i.title:i.prop,value:i.value,min:i.min,max:i.max,step:i.step,options:i.options,disabled:i.disabled,onChange:(n,r)=>{this.props.three.updateGroup(t.title,n,r)}})}),xe.groups.push(M.jsx(cs,{app:xe.app,title:t.title,items:s},Math.random())),xe.groupTitles.push(t.title),this.setState({lastUpdate:Date.now()})};removeGroup=e=>{const t=e.value,s=xe.groupTitles.length;for(let i=0;i<s;i++)if(t===xe.groupTitles[i]){xe.groups.splice(i,1),xe.groupTitles.splice(i,1),this.setState({lastUpdate:Date.now()});return}};static addEditorGroup(e){const t=[];e.items.forEach(n=>{t.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:(r,o)=>{e.onUpdate(r,o)}})});const s=W.createRef(),i=M.jsx(cs,{app:xe.app,ref:s,title:e.title,items:t},Math.random());return xe.groups.push(i),xe.groupsRefs.push(s),xe.groupTitles.push(e.title),s}static removeEditorGroup(e){const t=xe.groupTitles.length;for(let s=0;s<t;s++)if(e===xe.groupTitles[s]){xe.groups.splice(s,1),xe.groupTitles.splice(s,1),xe.instance.setState({lastUpdate:Date.now()});return}}static removeAllGroups(){for(let e=xe.groupTitles.length;e>0;e--)xe.groups.splice(e,1),xe.groupTitles.splice(e,1);xe.instance.setState({lastUpdate:Date.now()})}}function wd(a){switch(a){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 a}function Hx(a,e,t){function s(){return`${t.app.appID}_camera`}const i=localStorage.getItem(s()),n=i!==null?i==="open":!1;function r(l){localStorage.setItem(s(),l?"open":"closed")}const o=[];if(a.perspectiveCameraInfo!==void 0)for(const l in a.perspectiveCameraInfo)o.push({title:wd(l),prop:l,type:"number",step:.01,value:a.perspectiveCameraInfo[l],onChange:(c,h)=>{t.updateObject(a.uuid,c,h),t.requestMethod(a.uuid,"updateProjectionMatrix");const u=t.getScene(a.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",a.uuid);d!==void 0&&(qe(d,c,h),d.updateProjectionMatrix())}}});else if(a.orthographicCameraInfo!==void 0)for(const l in a.orthographicCameraInfo)o.push({title:wd(l),prop:l,type:"number",step:.01,value:a.orthographicCameraInfo[l],onChange:(c,h)=>{t.updateObject(a.uuid,c,h),t.requestMethod(a.uuid,"updateProjectionMatrix");const u=t.getScene(a.uuid);if(u!==null){const d=u.getObjectByProperty("uuid",a.uuid);d!==void 0&&(qe(d,c,h),d.updateProjectionMatrix())}}});return M.jsx(cs,{app:e,title:"Camera",items:o,expanded:n,onToggle:l=>{r(l)}})}class Wx{constructor(e,t){this.nodes=e,this.info=t,this._context=typeof self<"u"?self:null,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),this.info.autoReset===!0&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this._animationLoop!==null&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class Ss{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return;return t.get(e[e.length-1])}set(e,t){let s=this.weakMap;for(let i=0;i<e.length-1;i++){const n=e[i];s.has(n)===!1&&s.set(n,new WeakMap),s=s.get(n)}return s.set(e[e.length-1],t),this}delete(e){let t=this.weakMap;for(let s=0;s<e.length-1;s++)if(t=t.get(e[s]),t===void 0)return!1;return t.delete(e[e.length-1])}}const hm="177",$x=0,jx=1,qx=2,Yx=0,Xx=1,Co=3,Qs=0,zt=1,Zn=2,or=0,Ks=1,Go=2,Vo=3,Ho=4,ra=5,_s=100,um=101,dm=102,Zx=103,Qx=104,Si=200,pm=201,fm=202,mm=203,Wo=204,$o=205,gm=206,ym=207,xm=208,_m=209,bm=210,Tm=0,Sm=1,vm=2,jo=3,wm=4,Em=5,Cm=6,Mm=7,cl=0,Kx=1,Jx=2,Qn=0,e_=1,t_=2,s_=3,i_=4,n_=6,r_=7,Qh=300,ma=301,qo=302,Kh=303,Jh=304,ph=306,lr=1e3,Ai=1001,cr=1002,ht=1003,Am=1004,ga=1005,Qt=1006,fh=1007,Js=1008,Rt=1009,aa=1010,oa=1011,Wn=1012,Ct=1013,Ye=1014,Zt=1015,ns=1016,a_=1017,o_=1018,Pi=1020,Rm=35902,l_=1021,eu=1022,rs=1023,Os=1026,ei=1027,tu=1028,su=1029,ln=1030,iu=1031,c_=1032,nu=1033,kl=33776,Mo=33777,Ao=33778,Ro=33779,Ed=35840,Cd=35841,Md=35842,Ad=35843,Rd=36196,mh=37492,gh=37496,yh=37808,xh=37809,_h=37810,bh=37811,Th=37812,Sh=37813,vh=37814,wh=37815,Eh=37816,Ch=37817,Mh=37818,Ah=37819,Rh=37820,Nh=37821,zl=36492,h_=36283,Nd=36284,Pd=36285,Dd=36286,Di=0,u_=1,ni="",Yt="srgb",Kn="srgb-linear",Yo="linear",se="srgb",d_=0,Ji=7680,p_=7681,f_=7682,m_=7683,g_=34055,y_=34056,x_=5386,__=512,b_=513,T_=514,S_=515,v_=516,w_=517,E_=518,Ph=519,Nm=512,ru=513,Pm=514,Dm=515,Fm=516,Om=517,Bm=518,Im=519,Xo=35044,$n=35048,Lt=2e3,Fi=2001;class Vt{constructor(e,t,s,i,n,r,o,l,c){Vt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,s,i,n,r,o,l,c)}set(e,t,s,i,n,r,o,l,c){const h=this.elements;return h[0]=e,h[1]=i,h[2]=o,h[3]=t,h[4]=n,h[5]=l,h[6]=s,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],this}extractBasis(e,t,s){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const s=e.elements,i=t.elements,n=this.elements,r=s[0],o=s[3],l=s[6],c=s[1],h=s[4],u=s[7],d=s[2],p=s[5],f=s[8],m=i[0],y=i[3],g=i[6],_=i[1],b=i[4],T=i[7],S=i[2],C=i[5],w=i[8];return n[0]=r*m+o*_+l*S,n[3]=r*y+o*b+l*C,n[6]=r*g+o*T+l*w,n[1]=c*m+h*_+u*S,n[4]=c*y+h*b+u*C,n[7]=c*g+h*T+u*w,n[2]=d*m+p*_+f*S,n[5]=d*y+p*b+f*C,n[8]=d*g+p*T+f*w,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],o=e[5],l=e[6],c=e[7],h=e[8];return t*r*h-t*o*c-s*n*h+s*o*l+i*n*c-i*r*l}invert(){const e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],o=e[5],l=e[6],c=e[7],h=e[8],u=h*r-o*c,d=o*l-h*n,p=c*n-r*l,f=t*u+s*d+i*p;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/f;return e[0]=u*m,e[1]=(i*c-h*s)*m,e[2]=(o*s-i*r)*m,e[3]=d*m,e[4]=(h*t-i*l)*m,e[5]=(i*n-o*t)*m,e[6]=p*m,e[7]=(s*l-c*t)*m,e[8]=(r*t-s*n)*m,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,s,i,n,r,o){const l=Math.cos(n),c=Math.sin(n);return this.set(s*l,s*c,-s*(l*r+c*o)+r+e,-i*c,i*l,-i*(-c*r+l*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(Gl.makeScale(e,t)),this}rotate(e){return this.premultiply(Gl.makeRotation(-e)),this}translate(e,t){return this.premultiply(Gl.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,s,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,s=e.elements;for(let i=0;i<9;i++)if(t[i]!==s[i])return!1;return!0}fromArray(e,t=0){for(let s=0;s<9;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){const s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const Gl=new Vt;function Lm(a){for(let e=a.length-1;e>=0;--e)if(a[e]>=65535)return!0;return!1}function Dh(a){return document.createElementNS("http://www.w3.org/1999/xhtml",a)}function C_(){const a=Dh("canvas");return a.style.display="block",a}const Fd={};function ri(a){a in Fd||(Fd[a]=!0,console.warn(a))}const Od=new Vt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Bd=new Vt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function M_(){const a={enabled:!0,workingColorSpace:Kn,spaces:{},convert:function(i,n,r){return this.enabled===!1||n===r||!n||!r||(this.spaces[n].transfer===se&&(i.r=ti(i.r),i.g=ti(i.g),i.b=ti(i.b)),this.spaces[n].primaries!==this.spaces[r].primaries&&(i.applyMatrix3(this.spaces[n].toXYZ),i.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===se&&(i.r=Jn(i.r),i.g=Jn(i.g),i.b=Jn(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===ni?Yo:this.spaces[i].transfer},getLuminanceCoefficients:function(i,n=this.workingColorSpace){return i.fromArray(this.spaces[n].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,n,r){return i.copy(this.spaces[n].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,n){return ri("THREE.ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),a.workingToColorSpace(i,n)},toWorkingColorSpace:function(i,n){return ri("THREE.ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),a.colorSpaceToWorking(i,n)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],s=[.3127,.329];return a.define({[Kn]:{primaries:e,whitePoint:s,transfer:Yo,toXYZ:Od,fromXYZ:Bd,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:Yt},outputColorSpaceConfig:{drawingBufferColorSpace:Yt}},[Yt]:{primaries:e,whitePoint:s,transfer:se,toXYZ:Od,fromXYZ:Bd,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:Yt}}}),a}const Le=M_();function ti(a){return a<.04045?a*.0773993808:Math.pow(a*.9478672986+.0521327014,2.4)}function Jn(a){return a<.0031308?a*12.92:1.055*Math.pow(a,.41666)-.055}const Um={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},ui={h:0,s:0,l:0},Fa={h:0,s:0,l:0};function Vl(a,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?a+(e-a)*6*t:t<1/2?e:t<2/3?a+(e-a)*6*(2/3-t):a}class ve{constructor(e,t,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,s)}set(e,t,s){if(t===void 0&&s===void 0){const i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,s);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=Yt){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Le.colorSpaceToWorking(this,t),this}setRGB(e,t,s,i=Le.workingColorSpace){return this.r=e,this.g=t,this.b=s,Le.colorSpaceToWorking(this,i),this}setHSL(e,t,s,i=Le.workingColorSpace){if(e=Zh(e,1),t=de(t,0,1),s=de(s,0,1),t===0)this.r=this.g=this.b=s;else{const n=s<=.5?s*(1+t):s+t-s*t,r=2*s-n;this.r=Vl(r,n,e+1/3),this.g=Vl(r,n,e),this.b=Vl(r,n,e-1/3)}return Le.colorSpaceToWorking(this,i),this}setStyle(e,t=Yt){function s(n){n!==void 0&&parseFloat(n)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let n;const r=i[1],o=i[2];switch(r){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,t);if(n=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,t);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){const n=i[1],r=n.length;if(r===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(r===6)return this.setHex(parseInt(n,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=Yt){const s=Um[e.toLowerCase()];return s!==void 0?this.setHex(s,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=ti(e.r),this.g=ti(e.g),this.b=ti(e.b),this}copyLinearToSRGB(e){return this.r=Jn(e.r),this.g=Jn(e.g),this.b=Jn(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=Yt){return Le.workingToColorSpace(yt.copy(this),e),Math.round(de(yt.r*255,0,255))*65536+Math.round(de(yt.g*255,0,255))*256+Math.round(de(yt.b*255,0,255))}getHexString(e=Yt){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Le.workingColorSpace){Le.workingToColorSpace(yt.copy(this),t);const s=yt.r,i=yt.g,n=yt.b,r=Math.max(s,i,n),o=Math.min(s,i,n);let l,c;const h=(o+r)/2;if(o===r)l=0,c=0;else{const u=r-o;switch(c=h<=.5?u/(r+o):u/(2-r-o),r){case s:l=(i-n)/u+(i<n?6:0);break;case i:l=(n-s)/u+2;break;case n:l=(s-i)/u+4;break}l/=6}return e.h=l,e.s=c,e.l=h,e}getRGB(e,t=Le.workingColorSpace){return Le.workingToColorSpace(yt.copy(this),t),e.r=yt.r,e.g=yt.g,e.b=yt.b,e}getStyle(e=Yt){Le.workingToColorSpace(yt.copy(this),e);const t=yt.r,s=yt.g,i=yt.b;return e!==Yt?`color(${e} ${t.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(s*255)},${Math.round(i*255)})`}offsetHSL(e,t,s){return this.getHSL(ui),this.setHSL(ui.h+e,ui.s+t,ui.l+s)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,s){return this.r=e.r+(t.r-e.r)*s,this.g=e.g+(t.g-e.g)*s,this.b=e.b+(t.b-e.b)*s,this}lerpHSL(e,t){this.getHSL(ui),e.getHSL(Fa);const s=Ni(ui.h,Fa.h,t),i=Ni(ui.s,Fa.s,t),n=Ni(ui.l,Fa.l,t);return this.setHSL(s,i,n),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,s=this.g,i=this.b,n=e.elements;return this.r=n[0]*t+n[3]*s+n[6]*i,this.g=n[1]*t+n[4]*s+n[7]*i,this.b=n[2]*t+n[5]*s+n[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const yt=new ve;ve.NAMES=Um;class hl{constructor(e,t,s,i){hl.prototype.isMatrix2=!0,this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let s=0;s<4;s++)this.elements[s]=e[s+t];return this}set(e,t,s,i){const n=this.elements;return n[0]=e,n[2]=t,n[1]=s,n[3]=i,this}}class mr{constructor(e=0,t=0,s=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=s,this._w=i}static slerpFlat(e,t,s,i,n,r,o){let l=s[i+0],c=s[i+1],h=s[i+2],u=s[i+3];const d=n[r+0],p=n[r+1],f=n[r+2],m=n[r+3];if(o===0){e[t+0]=l,e[t+1]=c,e[t+2]=h,e[t+3]=u;return}if(o===1){e[t+0]=d,e[t+1]=p,e[t+2]=f,e[t+3]=m;return}if(u!==m||l!==d||c!==p||h!==f){let y=1-o;const g=l*d+c*p+h*f+u*m,_=g>=0?1:-1,b=1-g*g;if(b>Number.EPSILON){const S=Math.sqrt(b),C=Math.atan2(S,g*_);y=Math.sin(y*C)/S,o=Math.sin(o*C)/S}const T=o*_;if(l=l*y+d*T,c=c*y+p*T,h=h*y+f*T,u=u*y+m*T,y===1-o){const S=1/Math.sqrt(l*l+c*c+h*h+u*u);l*=S,c*=S,h*=S,u*=S}}e[t]=l,e[t+1]=c,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,s,i,n,r){const o=s[i],l=s[i+1],c=s[i+2],h=s[i+3],u=n[r],d=n[r+1],p=n[r+2],f=n[r+3];return e[t]=o*f+h*u+l*p-c*d,e[t+1]=l*f+h*d+c*u-o*p,e[t+2]=c*f+h*p+o*d-l*u,e[t+3]=h*f-o*u-l*d-c*p,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,s,i){return this._x=e,this._y=t,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const s=e._x,i=e._y,n=e._z,r=e._order,o=Math.cos,l=Math.sin,c=o(s/2),h=o(i/2),u=o(n/2),d=l(s/2),p=l(i/2),f=l(n/2);switch(r){case"XYZ":this._x=d*h*u+c*p*f,this._y=c*p*u-d*h*f,this._z=c*h*f+d*p*u,this._w=c*h*u-d*p*f;break;case"YXZ":this._x=d*h*u+c*p*f,this._y=c*p*u-d*h*f,this._z=c*h*f-d*p*u,this._w=c*h*u+d*p*f;break;case"ZXY":this._x=d*h*u-c*p*f,this._y=c*p*u+d*h*f,this._z=c*h*f+d*p*u,this._w=c*h*u-d*p*f;break;case"ZYX":this._x=d*h*u-c*p*f,this._y=c*p*u+d*h*f,this._z=c*h*f-d*p*u,this._w=c*h*u+d*p*f;break;case"YZX":this._x=d*h*u+c*p*f,this._y=c*p*u+d*h*f,this._z=c*h*f-d*p*u,this._w=c*h*u-d*p*f;break;case"XZY":this._x=d*h*u-c*p*f,this._y=c*p*u-d*h*f,this._z=c*h*f+d*p*u,this._w=c*h*u+d*p*f;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const s=t/2,i=Math.sin(s);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,s=t[0],i=t[4],n=t[8],r=t[1],o=t[5],l=t[9],c=t[2],h=t[6],u=t[10],d=s+o+u;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(h-l)*p,this._y=(n-c)*p,this._z=(r-i)*p}else if(s>o&&s>u){const p=2*Math.sqrt(1+s-o-u);this._w=(h-l)/p,this._x=.25*p,this._y=(i+r)/p,this._z=(n+c)/p}else if(o>u){const p=2*Math.sqrt(1+o-s-u);this._w=(n-c)/p,this._x=(i+r)/p,this._y=.25*p,this._z=(l+h)/p}else{const p=2*Math.sqrt(1+u-s-o);this._w=(r-i)/p,this._x=(n+c)/p,this._y=(l+h)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let s=e.dot(t)+1;return s<Number.EPSILON?(s=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=s):(this._x=0,this._y=-e.z,this._z=e.y,this._w=s)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=s),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(de(this.dot(e),-1,1)))}rotateTowards(e,t){const s=this.angleTo(e);if(s===0)return this;const i=Math.min(1,t/s);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const s=e._x,i=e._y,n=e._z,r=e._w,o=t._x,l=t._y,c=t._z,h=t._w;return this._x=s*h+r*o+i*c-n*l,this._y=i*h+r*l+n*o-s*c,this._z=n*h+r*c+s*l-i*o,this._w=r*h-s*o-i*l-n*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const s=this._x,i=this._y,n=this._z,r=this._w;let o=r*e._w+s*e._x+i*e._y+n*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=r,this._x=s,this._y=i,this._z=n,this;const l=1-o*o;if(l<=Number.EPSILON){const p=1-t;return this._w=p*r+t*this._w,this._x=p*s+t*this._x,this._y=p*i+t*this._y,this._z=p*n+t*this._z,this.normalize(),this}const c=Math.sqrt(l),h=Math.atan2(c,o),u=Math.sin((1-t)*h)/c,d=Math.sin(t*h)/c;return this._w=r*u+this._w*d,this._x=s*u+this._x*d,this._y=i*u+this._y*d,this._z=n*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,s){return this.copy(e).slerp(t,s)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),n=Math.sqrt(s);return this.set(i*Math.sin(e),i*Math.cos(e),n*Math.sin(t),n*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class N{constructor(e=0,t=0,s=0){N.prototype.isVector3=!0,this.x=e,this.y=t,this.z=s}set(e,t,s){return s===void 0&&(s=this.z),this.x=e,this.y=t,this.z=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Id.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Id.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,s=this.y,i=this.z,n=e.elements;return this.x=n[0]*t+n[3]*s+n[6]*i,this.y=n[1]*t+n[4]*s+n[7]*i,this.z=n[2]*t+n[5]*s+n[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,s=this.y,i=this.z,n=e.elements,r=1/(n[3]*t+n[7]*s+n[11]*i+n[15]);return this.x=(n[0]*t+n[4]*s+n[8]*i+n[12])*r,this.y=(n[1]*t+n[5]*s+n[9]*i+n[13])*r,this.z=(n[2]*t+n[6]*s+n[10]*i+n[14])*r,this}applyQuaternion(e){const t=this.x,s=this.y,i=this.z,n=e.x,r=e.y,o=e.z,l=e.w,c=2*(r*i-o*s),h=2*(o*t-n*i),u=2*(n*s-r*t);return this.x=t+l*c+r*u-o*h,this.y=s+l*h+o*c-n*u,this.z=i+l*u+n*h-r*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,s=this.y,i=this.z,n=e.elements;return this.x=n[0]*t+n[4]*s+n[8]*i,this.y=n[1]*t+n[5]*s+n[9]*i,this.z=n[2]*t+n[6]*s+n[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=de(this.x,e.x,t.x),this.y=de(this.y,e.y,t.y),this.z=de(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=de(this.x,e,t),this.y=de(this.y,e,t),this.z=de(this.z,e,t),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(de(s,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const s=e.x,i=e.y,n=e.z,r=t.x,o=t.y,l=t.z;return this.x=i*l-n*o,this.y=n*r-s*l,this.z=s*o-i*r,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const s=e.dot(this)/t;return this.copy(e).multiplyScalar(s)}projectOnPlane(e){return Hl.copy(this).projectOnVector(e),this.sub(Hl)}reflect(e){return this.sub(Hl.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const s=this.dot(e)/t;return Math.acos(de(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,s=this.y-e.y,i=this.z-e.z;return t*t+s*s+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,s){const i=Math.sin(t)*e;return this.x=i*Math.sin(s),this.y=Math.cos(t)*e,this.z=i*Math.cos(s),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,s){return this.x=e*Math.sin(t),this.y=s,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),s=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=s,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,s=Math.sqrt(1-t*t);return this.x=s*Math.cos(e),this.y=t,this.z=s*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Hl=new N,Id=new mr;class Be{constructor(e,t,s,i,n,r,o,l,c,h,u,d,p,f,m,y){Be.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,s,i,n,r,o,l,c,h,u,d,p,f,m,y)}set(e,t,s,i,n,r,o,l,c,h,u,d,p,f,m,y){const g=this.elements;return g[0]=e,g[4]=t,g[8]=s,g[12]=i,g[1]=n,g[5]=r,g[9]=o,g[13]=l,g[2]=c,g[6]=h,g[10]=u,g[14]=d,g[3]=p,g[7]=f,g[11]=m,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 Be().fromArray(this.elements)}copy(e){const t=this.elements,s=e.elements;return t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],t[4]=s[4],t[5]=s[5],t[6]=s[6],t[7]=s[7],t[8]=s[8],t[9]=s[9],t[10]=s[10],t[11]=s[11],t[12]=s[12],t[13]=s[13],t[14]=s[14],t[15]=s[15],this}copyPosition(e){const t=this.elements,s=e.elements;return t[12]=s[12],t[13]=s[13],t[14]=s[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,s){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(e,t,s){return this.set(e.x,t.x,s.x,0,e.y,t.y,s.y,0,e.z,t.z,s.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,s=e.elements,i=1/Sn.setFromMatrixColumn(e,0).length(),n=1/Sn.setFromMatrixColumn(e,1).length(),r=1/Sn.setFromMatrixColumn(e,2).length();return t[0]=s[0]*i,t[1]=s[1]*i,t[2]=s[2]*i,t[3]=0,t[4]=s[4]*n,t[5]=s[5]*n,t[6]=s[6]*n,t[7]=0,t[8]=s[8]*r,t[9]=s[9]*r,t[10]=s[10]*r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,s=e.x,i=e.y,n=e.z,r=Math.cos(s),o=Math.sin(s),l=Math.cos(i),c=Math.sin(i),h=Math.cos(n),u=Math.sin(n);if(e.order==="XYZ"){const d=r*h,p=r*u,f=o*h,m=o*u;t[0]=l*h,t[4]=-l*u,t[8]=c,t[1]=p+f*c,t[5]=d-m*c,t[9]=-o*l,t[2]=m-d*c,t[6]=f+p*c,t[10]=r*l}else if(e.order==="YXZ"){const d=l*h,p=l*u,f=c*h,m=c*u;t[0]=d+m*o,t[4]=f*o-p,t[8]=r*c,t[1]=r*u,t[5]=r*h,t[9]=-o,t[2]=p*o-f,t[6]=m+d*o,t[10]=r*l}else if(e.order==="ZXY"){const d=l*h,p=l*u,f=c*h,m=c*u;t[0]=d-m*o,t[4]=-r*u,t[8]=f+p*o,t[1]=p+f*o,t[5]=r*h,t[9]=m-d*o,t[2]=-r*c,t[6]=o,t[10]=r*l}else if(e.order==="ZYX"){const d=r*h,p=r*u,f=o*h,m=o*u;t[0]=l*h,t[4]=f*c-p,t[8]=d*c+m,t[1]=l*u,t[5]=m*c+d,t[9]=p*c-f,t[2]=-c,t[6]=o*l,t[10]=r*l}else if(e.order==="YZX"){const d=r*l,p=r*c,f=o*l,m=o*c;t[0]=l*h,t[4]=m-d*u,t[8]=f*u+p,t[1]=u,t[5]=r*h,t[9]=-o*h,t[2]=-c*h,t[6]=p*u+f,t[10]=d-m*u}else if(e.order==="XZY"){const d=r*l,p=r*c,f=o*l,m=o*c;t[0]=l*h,t[4]=-u,t[8]=c*h,t[1]=d*u+m,t[5]=r*h,t[9]=p*u-f,t[2]=f*u-p,t[6]=o*h,t[10]=m*u+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(A_,e,R_)}lookAt(e,t,s){const i=this.elements;return Ht.subVectors(e,t),Ht.lengthSq()===0&&(Ht.z=1),Ht.normalize(),di.crossVectors(s,Ht),di.lengthSq()===0&&(Math.abs(s.z)===1?Ht.x+=1e-4:Ht.z+=1e-4,Ht.normalize(),di.crossVectors(s,Ht)),di.normalize(),Oa.crossVectors(Ht,di),i[0]=di.x,i[4]=Oa.x,i[8]=Ht.x,i[1]=di.y,i[5]=Oa.y,i[9]=Ht.y,i[2]=di.z,i[6]=Oa.z,i[10]=Ht.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const s=e.elements,i=t.elements,n=this.elements,r=s[0],o=s[4],l=s[8],c=s[12],h=s[1],u=s[5],d=s[9],p=s[13],f=s[2],m=s[6],y=s[10],g=s[14],_=s[3],b=s[7],T=s[11],S=s[15],C=i[0],w=i[4],R=i[8],P=i[12],z=i[1],$=i[5],q=i[9],j=i[13],Z=i[2],Q=i[6],we=i[10],ue=i[14],ge=i[3],ie=i[7],Ee=i[11],ke=i[15];return n[0]=r*C+o*z+l*Z+c*ge,n[4]=r*w+o*$+l*Q+c*ie,n[8]=r*R+o*q+l*we+c*Ee,n[12]=r*P+o*j+l*ue+c*ke,n[1]=h*C+u*z+d*Z+p*ge,n[5]=h*w+u*$+d*Q+p*ie,n[9]=h*R+u*q+d*we+p*Ee,n[13]=h*P+u*j+d*ue+p*ke,n[2]=f*C+m*z+y*Z+g*ge,n[6]=f*w+m*$+y*Q+g*ie,n[10]=f*R+m*q+y*we+g*Ee,n[14]=f*P+m*j+y*ue+g*ke,n[3]=_*C+b*z+T*Z+S*ge,n[7]=_*w+b*$+T*Q+S*ie,n[11]=_*R+b*q+T*we+S*Ee,n[15]=_*P+b*j+T*ue+S*ke,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],s=e[4],i=e[8],n=e[12],r=e[1],o=e[5],l=e[9],c=e[13],h=e[2],u=e[6],d=e[10],p=e[14],f=e[3],m=e[7],y=e[11],g=e[15];return f*(+n*l*u-i*c*u-n*o*d+s*c*d+i*o*p-s*l*p)+m*(+t*l*p-t*c*d+n*r*d-i*r*p+i*c*h-n*l*h)+y*(+t*c*u-t*o*p-n*r*u+s*r*p+n*o*h-s*c*h)+g*(-i*o*h-t*l*u+t*o*d+i*r*u-s*r*d+s*l*h)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,s){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=s),this}invert(){const e=this.elements,t=e[0],s=e[1],i=e[2],n=e[3],r=e[4],o=e[5],l=e[6],c=e[7],h=e[8],u=e[9],d=e[10],p=e[11],f=e[12],m=e[13],y=e[14],g=e[15],_=u*y*c-m*d*c+m*l*p-o*y*p-u*l*g+o*d*g,b=f*d*c-h*y*c-f*l*p+r*y*p+h*l*g-r*d*g,T=h*m*c-f*u*c+f*o*p-r*m*p-h*o*g+r*u*g,S=f*u*l-h*m*l-f*o*d+r*m*d+h*o*y-r*u*y,C=t*_+s*b+i*T+n*S;if(C===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/C;return e[0]=_*w,e[1]=(m*d*n-u*y*n-m*i*p+s*y*p+u*i*g-s*d*g)*w,e[2]=(o*y*n-m*l*n+m*i*c-s*y*c-o*i*g+s*l*g)*w,e[3]=(u*l*n-o*d*n-u*i*c+s*d*c+o*i*p-s*l*p)*w,e[4]=b*w,e[5]=(h*y*n-f*d*n+f*i*p-t*y*p-h*i*g+t*d*g)*w,e[6]=(f*l*n-r*y*n-f*i*c+t*y*c+r*i*g-t*l*g)*w,e[7]=(r*d*n-h*l*n+h*i*c-t*d*c-r*i*p+t*l*p)*w,e[8]=T*w,e[9]=(f*u*n-h*m*n-f*s*p+t*m*p+h*s*g-t*u*g)*w,e[10]=(r*m*n-f*o*n+f*s*c-t*m*c-r*s*g+t*o*g)*w,e[11]=(h*o*n-r*u*n-h*s*c+t*u*c+r*s*p-t*o*p)*w,e[12]=S*w,e[13]=(h*m*i-f*u*i+f*s*d-t*m*d-h*s*y+t*u*y)*w,e[14]=(f*o*i-r*m*i-f*s*l+t*m*l+r*s*y-t*o*y)*w,e[15]=(r*u*i-h*o*i+h*s*l-t*u*l-r*s*d+t*o*d)*w,this}scale(e){const t=this.elements,s=e.x,i=e.y,n=e.z;return t[0]*=s,t[4]*=i,t[8]*=n,t[1]*=s,t[5]*=i,t[9]*=n,t[2]*=s,t[6]*=i,t[10]*=n,t[3]*=s,t[7]*=i,t[11]*=n,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],s=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,s,i))}makeTranslation(e,t,s){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,s,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),s=Math.sin(e);return this.set(1,0,0,0,0,t,-s,0,0,s,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,0,s,0,0,1,0,0,-s,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),s=Math.sin(e);return this.set(t,-s,0,0,s,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const s=Math.cos(t),i=Math.sin(t),n=1-s,r=e.x,o=e.y,l=e.z,c=n*r,h=n*o;return this.set(c*r+s,c*o-i*l,c*l+i*o,0,c*o+i*l,h*o+s,h*l-i*r,0,c*l-i*o,h*l+i*r,n*l*l+s,0,0,0,0,1),this}makeScale(e,t,s){return this.set(e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1),this}makeShear(e,t,s,i,n,r){return this.set(1,s,n,0,e,1,r,0,t,i,1,0,0,0,0,1),this}compose(e,t,s){const i=this.elements,n=t._x,r=t._y,o=t._z,l=t._w,c=n+n,h=r+r,u=o+o,d=n*c,p=n*h,f=n*u,m=r*h,y=r*u,g=o*u,_=l*c,b=l*h,T=l*u,S=s.x,C=s.y,w=s.z;return i[0]=(1-(m+g))*S,i[1]=(p+T)*S,i[2]=(f-b)*S,i[3]=0,i[4]=(p-T)*C,i[5]=(1-(d+g))*C,i[6]=(y+_)*C,i[7]=0,i[8]=(f+b)*w,i[9]=(y-_)*w,i[10]=(1-(d+m))*w,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,s){const i=this.elements;let n=Sn.set(i[0],i[1],i[2]).length();const r=Sn.set(i[4],i[5],i[6]).length(),o=Sn.set(i[8],i[9],i[10]).length();this.determinant()<0&&(n=-n),e.x=i[12],e.y=i[13],e.z=i[14],ds.copy(this);const c=1/n,h=1/r,u=1/o;return ds.elements[0]*=c,ds.elements[1]*=c,ds.elements[2]*=c,ds.elements[4]*=h,ds.elements[5]*=h,ds.elements[6]*=h,ds.elements[8]*=u,ds.elements[9]*=u,ds.elements[10]*=u,t.setFromRotationMatrix(ds),s.x=n,s.y=r,s.z=o,this}makePerspective(e,t,s,i,n,r,o=Lt){const l=this.elements,c=2*n/(t-e),h=2*n/(s-i),u=(t+e)/(t-e),d=(s+i)/(s-i);let p,f;if(o===Lt)p=-(r+n)/(r-n),f=-2*r*n/(r-n);else if(o===Fi)p=-r/(r-n),f=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return l[0]=c,l[4]=0,l[8]=u,l[12]=0,l[1]=0,l[5]=h,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=f,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(e,t,s,i,n,r,o=Lt){const l=this.elements,c=1/(t-e),h=1/(s-i),u=1/(r-n),d=(t+e)*c,p=(s+i)*h;let f,m;if(o===Lt)f=(r+n)*u,m=-2*u;else if(o===Fi)f=n*u,m=-1*u;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-d,l[1]=0,l[5]=2*h,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(e){const t=this.elements,s=e.elements;for(let i=0;i<16;i++)if(t[i]!==s[i])return!1;return!0}fromArray(e,t=0){for(let s=0;s<16;s++)this.elements[s]=e[s+t];return this}toArray(e=[],t=0){const s=this.elements;return e[t]=s[0],e[t+1]=s[1],e[t+2]=s[2],e[t+3]=s[3],e[t+4]=s[4],e[t+5]=s[5],e[t+6]=s[6],e[t+7]=s[7],e[t+8]=s[8],e[t+9]=s[9],e[t+10]=s[10],e[t+11]=s[11],e[t+12]=s[12],e[t+13]=s[13],e[t+14]=s[14],e[t+15]=s[15],e}}const Sn=new N,ds=new Be,A_=new N(0,0,0),R_=new N(1,1,1),di=new N,Oa=new N,Ht=new N;class ce{constructor(e=0,t=0){ce.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,s=this.y,i=e.elements;return this.x=i[0]*t+i[3]*s+i[6],this.y=i[1]*t+i[4]*s+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=de(this.x,e.x,t.x),this.y=de(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=de(this.x,e,t),this.y=de(this.y,e,t),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(de(s,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const s=this.dot(e)/t;return Math.acos(de(s,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,s=this.y-e.y;return t*t+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const s=Math.cos(t),i=Math.sin(t),n=this.x-e.x,r=this.y-e.y;return this.x=n*s-r*i+e.x,this.y=n*i+r*s+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class me{constructor(e=0,t=0,s=0,i=1){me.prototype.isVector4=!0,this.x=e,this.y=t,this.z=s,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,s,i){return this.x=e,this.y=t,this.z=s,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,s=this.y,i=this.z,n=this.w,r=e.elements;return this.x=r[0]*t+r[4]*s+r[8]*i+r[12]*n,this.y=r[1]*t+r[5]*s+r[9]*i+r[13]*n,this.z=r[2]*t+r[6]*s+r[10]*i+r[14]*n,this.w=r[3]*t+r[7]*s+r[11]*i+r[15]*n,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,s,i,n;const l=e.elements,c=l[0],h=l[4],u=l[8],d=l[1],p=l[5],f=l[9],m=l[2],y=l[6],g=l[10];if(Math.abs(h-d)<.01&&Math.abs(u-m)<.01&&Math.abs(f-y)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+m)<.1&&Math.abs(f+y)<.1&&Math.abs(c+p+g-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const b=(c+1)/2,T=(p+1)/2,S=(g+1)/2,C=(h+d)/4,w=(u+m)/4,R=(f+y)/4;return b>T&&b>S?b<.01?(s=0,i=.707106781,n=.707106781):(s=Math.sqrt(b),i=C/s,n=w/s):T>S?T<.01?(s=.707106781,i=0,n=.707106781):(i=Math.sqrt(T),s=C/i,n=R/i):S<.01?(s=.707106781,i=.707106781,n=0):(n=Math.sqrt(S),s=w/n,i=R/n),this.set(s,i,n,t),this}let _=Math.sqrt((y-f)*(y-f)+(u-m)*(u-m)+(d-h)*(d-h));return Math.abs(_)<.001&&(_=1),this.x=(y-f)/_,this.y=(u-m)/_,this.z=(d-h)/_,this.w=Math.acos((c+p+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=de(this.x,e.x,t.x),this.y=de(this.y,e.y,t.y),this.z=de(this.z,e.z,t.z),this.w=de(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=de(this.x,e,t),this.y=de(this.y,e,t),this.z=de(this.z,e,t),this.w=de(this.w,e,t),this}clampLength(e,t){const s=this.length();return this.divideScalar(s||1).multiplyScalar(de(s,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this.z=e.z+(t.z-e.z)*s,this.w=e.w+(t.w-e.w)*s,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}function ya(a,e=0){let t=3735928559^e,s=1103547991^e;if(a instanceof Array)for(let i=0,n;i<a.length;i++)n=a[i],t=Math.imul(t^n,2654435761),s=Math.imul(s^n,1597334677);else for(let i=0,n;i<a.length;i++)n=a.charCodeAt(i),t=Math.imul(t^n,2654435761),s=Math.imul(s^n,1597334677);return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&s)+(t>>>0)}const N_=a=>ya(a),au=a=>ya(a),Zo=(...a)=>ya(a);function km(a,e=!1){const t=[];a.isNode===!0&&(t.push(a.id),a=a.getSelf());for(const{property:s,childNode:i}of Qo(a))t.push(ya(s.slice(0,-4)),i.getCacheKey(e));return ya(t)}function*Qo(a,e=!1){for(const t in a){if(t.startsWith("_")===!0)continue;const s=a[t];if(Array.isArray(s)===!0)for(let i=0;i<s.length;i++){const n=s[i];n&&(n.isNode===!0||e&&typeof n.toJSON=="function")&&(yield{property:t,index:i,childNode:n})}else if(s&&s.isNode===!0)yield{property:t,childNode:s};else if(typeof s=="object")for(const i in s){const n=s[i];n&&(n.isNode===!0||e&&typeof n.toJSON=="function")&&(yield{property:t,index:i,childNode:n})}}}const P_=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),Ld=new WeakMap;function D_(a){return P_.get(a)}function Ko(a){if(a==null)return null;const e=typeof a;return a.isNode===!0?"node":e==="number"?"float":e==="boolean"?"bool":e==="string"?"string":e==="function"?"shader":a.isVector2===!0?"vec2":a.isVector3===!0?"vec3":a.isVector4===!0?"vec4":a.isMatrix2===!0?"mat2":a.isMatrix3===!0?"mat3":a.isMatrix4===!0?"mat4":a.isColor===!0?"color":a instanceof ArrayBuffer?"ArrayBuffer":null}function zm(a,...e){const t=a?a.slice(-4):void 0;return e.length===1&&(t==="vec2"?e=[e[0],e[0]]:t==="vec3"?e=[e[0],e[0],e[0]]:t==="vec4"&&(e=[e[0],e[0],e[0],e[0]])),a==="color"?new ve(...e):t==="vec2"?new ce(...e):t==="vec3"?new N(...e):t==="vec4"?new me(...e):t==="mat2"?new hl(...e):t==="mat3"?new Vt(...e):t==="mat4"?new Be(...e):a==="bool"?e[0]||!1:a==="float"||a==="int"||a==="uint"?e[0]||0:a==="string"?e[0]||"":a==="ArrayBuffer"?O_(e[0]):null}function Gm(a){let e=Ld.get(a);return e===void 0&&(e={},Ld.set(a,e)),e}function F_(a){let e="";const t=new Uint8Array(a);for(let s=0;s<t.length;s++)e+=String.fromCharCode(t[s]);return btoa(e)}function O_(a){return Uint8Array.from(atob(a),e=>e.charCodeAt(0)).buffer}let B_=0;function I_(a){const e=Object.keys(a);let t=Object.getPrototypeOf(a);for(;t;){const s=Object.getOwnPropertyDescriptors(t);for(const i in s)if(s[i]!==void 0){const n=s[i];n&&typeof n.get=="function"&&e.push(i)}t=Object.getPrototypeOf(t)}return e}class L_{constructor(e,t,s,i,n,r,o,l,c,h){this.id=B_++,this._nodes=e,this._geometries=t,this.renderer=s,this.object=i,this.material=n,this.scene=r,this.camera=o,this.lightsNode=l,this.context=c,this.geometry=i.geometry,this.version=n.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=h,this.clippingContextCacheKey=h!==null?h.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return this.clippingContext===null||this.clippingContext.cacheKey===this.clippingContextCacheKey?!1:(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return this.material.hardwareClipping===!0?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(const t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(this.attributes!==null)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],i=new Set;for(const n of e){const r=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(r===void 0)continue;s.push(r);const o=r.isInterleavedBufferAttribute?r.data:r;i.add(o)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return this.vertexBuffers===null&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:i,drawRange:n}=this,r=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),l=o!==null;let c=1;if(s.isInstancedBufferGeometry===!0?c=s.instanceCount:e.count!==void 0&&(c=Math.max(0,e.count)),c===0)return null;if(r.instanceCount=c,e.isBatchedMesh===!0)return r;let h=1;t.wireframe===!0&&!e.isPoints&&!e.isLineSegments&&!e.isLine&&!e.isLineLoop&&(h=2);let u=n.start*h,d=(n.start+n.count)*h;i!==null&&(u=Math.max(u,i.start*h),d=Math.min(d,(i.start+i.count)*h));const p=s.attributes.position;let f=1/0;l?f=o.count:p!=null&&(f=p.count),u=Math.max(u,0),d=Math.min(d,f);const m=d-u;return m<0||m===1/0?null:(r.vertexCount=m,r.firstVertex=u,r)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const i=e.attributes[s];t+=s+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(const s of Object.keys(e.morphAttributes).sort()){const i=e.morphAttributes[s];t+="morph-"+s+",";for(let n=0,r=i.length;n<r;n++){const o=i[n];t+=o.id+","}}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const i of I_(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(i))continue;const n=t[i];let r;if(n!==null){const o=typeof n;o==="number"?r=n!==0?"1":"0":o==="object"?(r="{",n.isTexture&&(r+=n.mapping),r+="}"):r=String(n)}else r=String(n);s+=r+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",e._colorsTexture!==null&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),s+=e.receiveShadow+",",N_(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return this.material.isShadowPassMaterial!==!0&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=Zo(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=Zo(e,1)),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const zi=[];class U_{constructor(e,t,s,i,n,r){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=i,this.bindings=n,this.info=r,this.chainMaps={}}get(e,t,s,i,n,r,o,l){const c=this.getChainMap(l);zi[0]=e,zi[1]=t,zi[2]=r,zi[3]=n;let h=c.get(zi);return h===void 0?(h=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,i,n,r,o,l),c.set(zi,h)):(h.updateClipping(o),h.needsGeometryUpdate&&h.setGeometry(e.geometry),(h.version!==t.version||h.needsUpdate)&&(h.initialCacheKey!==h.getCacheKey()?(h.dispose(),h=this.get(e,t,s,i,n,r,o,l)):h.version=t.version)),zi.length=0,h}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ss)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,i,n,r,o,l,c,h,u){const d=this.getChainMap(u),p=new L_(e,t,s,i,n,r,o,l,c,h);return p.onDispose=()=>{this.pipelines.delete(p),this.bindings.delete(p),this.nodes.delete(p),d.delete(p.getChainArray())},p}}class Ii{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return t===void 0&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const as={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4},Ei=16,k_=211,z_=212;class G_ extends Ii{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return t!==null&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(s.version===void 0)t===as.VERTEX?this.backend.createAttribute(e):t===as.INDEX?this.backend.createIndexAttribute(e):t===as.STORAGE?this.backend.createStorageAttribute(e):t===as.INDIRECT&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const i=this._getBufferAttribute(e);(s.version<i.version||i.usage===$n)&&(this.backend.updateAttribute(e),s.version=i.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}const qs=V_();function V_(){const a=new ArrayBuffer(4),e=new Float32Array(a),t=new Uint32Array(a),s=new Uint32Array(512),i=new Uint32Array(512);for(let l=0;l<256;++l){const c=l-127;c<-27?(s[l]=0,s[l|256]=32768,i[l]=24,i[l|256]=24):c<-14?(s[l]=1024>>-c-14,s[l|256]=1024>>-c-14|32768,i[l]=-c-1,i[l|256]=-c-1):c<=15?(s[l]=c+15<<10,s[l|256]=c+15<<10|32768,i[l]=13,i[l|256]=13):c<128?(s[l]=31744,s[l|256]=64512,i[l]=24,i[l|256]=24):(s[l]=31744,s[l|256]=64512,i[l]=13,i[l|256]=13)}const n=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,h=0;for(;(c&8388608)===0;)c<<=1,h-=8388608;c&=-8388609,h+=947912704,n[l]=c|h}for(let l=1024;l<2048;++l)n[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)r[l]=l<<23;r[31]=1199570944,r[32]=2147483648;for(let l=33;l<63;++l)r[l]=2147483648+(l-32<<23);r[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(o[l]=1024);return{floatView:e,uint32View:t,baseTable:s,shiftTable:i,mantissaTable:n,exponentTable:r,offsetTable:o}}function Wt(a){Math.abs(a)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),a=de(a,-65504,65504),qs.floatView[0]=a;const e=qs.uint32View[0],t=e>>23&511;return qs.baseTable[t]+((e&8388607)>>qs.shiftTable[t])}function Ba(a){const e=a>>10;return qs.uint32View[0]=qs.mantissaTable[qs.offsetTable[e]+(a&1023)]+qs.exponentTable[e],qs.floatView[0]}const Qe=new N,Ia=new ce;let H_=0;class os{constructor(e,t,s=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:H_++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=s,this.usage=Xo,this.updateRanges=[],this.gpuType=Zt,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,s){e*=this.itemSize,s*=t.itemSize;for(let i=0,n=this.itemSize;i<n;i++)this.array[e+i]=t.array[s+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,s=this.count;t<s;t++)Ia.fromBufferAttribute(this,t),Ia.applyMatrix3(e),this.setXY(t,Ia.x,Ia.y);else if(this.itemSize===3)for(let t=0,s=this.count;t<s;t++)Qe.fromBufferAttribute(this,t),Qe.applyMatrix3(e),this.setXYZ(t,Qe.x,Qe.y,Qe.z);return this}applyMatrix4(e){for(let t=0,s=this.count;t<s;t++)Qe.fromBufferAttribute(this,t),Qe.applyMatrix4(e),this.setXYZ(t,Qe.x,Qe.y,Qe.z);return this}applyNormalMatrix(e){for(let t=0,s=this.count;t<s;t++)Qe.fromBufferAttribute(this,t),Qe.applyNormalMatrix(e),this.setXYZ(t,Qe.x,Qe.y,Qe.z);return this}transformDirection(e){for(let t=0,s=this.count;t<s;t++)Qe.fromBufferAttribute(this,t),Qe.transformDirection(e),this.setXYZ(t,Qe.x,Qe.y,Qe.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let s=this.array[e*this.itemSize+t];return this.normalized&&(s=At(s,this.array)),s}setComponent(e,t,s){return this.normalized&&(s=oe(s,this.array)),this.array[e*this.itemSize+t]=s,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=At(t,this.array)),t}setX(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=At(t,this.array)),t}setY(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=At(t,this.array)),t}setZ(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=At(t,this.array)),t}setW(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array)),this.array[e+0]=t,this.array[e+1]=s,this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array),i=oe(i,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this}setXYZW(e,t,s,i,n){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array),i=oe(i,this.array),n=oe(n,this.array)),this.array[e+0]=t,this.array[e+1]=s,this.array[e+2]=i,this.array[e+3]=n,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==Xo&&(e.usage=this.usage),e}}class Vm extends os{constructor(e,t,s){super(new Uint16Array(e),t,s)}}class Hm extends os{constructor(e,t,s){super(new Uint32Array(e),t,s)}}class Wm extends os{constructor(e,t,s){super(new Uint16Array(e),t,s),this.isFloat16BufferAttribute=!0}getX(e){let t=Ba(this.array[e*this.itemSize]);return this.normalized&&(t=At(t,this.array)),t}setX(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize]=Wt(t),this}getY(e){let t=Ba(this.array[e*this.itemSize+1]);return this.normalized&&(t=At(t,this.array)),t}setY(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+1]=Wt(t),this}getZ(e){let t=Ba(this.array[e*this.itemSize+2]);return this.normalized&&(t=At(t,this.array)),t}setZ(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+2]=Wt(t),this}getW(e){let t=Ba(this.array[e*this.itemSize+3]);return this.normalized&&(t=At(t,this.array)),t}setW(e,t){return this.normalized&&(t=oe(t,this.array)),this.array[e*this.itemSize+3]=Wt(t),this}setXY(e,t,s){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array)),this.array[e+0]=Wt(t),this.array[e+1]=Wt(s),this}setXYZ(e,t,s,i){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array),i=oe(i,this.array)),this.array[e+0]=Wt(t),this.array[e+1]=Wt(s),this.array[e+2]=Wt(i),this}setXYZW(e,t,s,i,n){return e*=this.itemSize,this.normalized&&(t=oe(t,this.array),s=oe(s,this.array),i=oe(i,this.array),n=oe(n,this.array)),this.array[e+0]=Wt(t),this.array[e+1]=Wt(s),this.array[e+2]=Wt(i),this.array[e+3]=Wt(n),this}}class Nt extends os{constructor(e,t,s){super(new Float32Array(e),t,s)}}function $m(a){return a.index!==null?a.index.version:a.attributes.position.version}function Ud(a){const e=[],t=a.index,s=a.attributes.position;if(t!==null){const n=t.array;for(let r=0,o=n.length;r<o;r+=3){const l=n[r+0],c=n[r+1],h=n[r+2];e.push(l,c,c,h,h,l)}}else{const n=s.array;for(let r=0,o=n.length/3-1;r<o;r+=3){const l=r+0,c=r+1,h=r+2;e.push(l,c,c,h,h,l)}}const i=new(Lm(e)?Hm:Vm)(e,1);return i.version=$m(a),i}class W_ extends Ii{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&this.get(t).initialized===!0}updateForRender(e){this.has(e)===!1&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry,s=this.get(t);s.initialized=!0,this.info.memory.geometries++;const i=()=>{this.info.memory.geometries--;const n=t.index,r=e.getAttributes();n!==null&&this.attributes.delete(n);for(const l of r)this.attributes.delete(l);const o=this.wireframes.get(t);o!==void 0&&this.attributes.delete(o),t.removeEventListener("dispose",i)};t.addEventListener("dispose",i)}updateAttributes(e){const t=e.getAttributes();for(const n of t)n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute?this.updateAttribute(n,as.STORAGE):this.updateAttribute(n,as.VERTEX);const s=this.getIndex(e);s!==null&&this.updateAttribute(s,as.INDEX);const i=e.geometry.indirect;i!==null&&this.updateAttribute(i,as.INDIRECT)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?this.attributeCall.get(e)===void 0?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let i=t.index;if(s.wireframe===!0){const n=this.wireframes;let r=n.get(t);r===void 0?(r=Ud(t),n.set(t,r)):r.version!==$m(t)&&(this.attributes.delete(r),r=Ud(t),n.set(t,r)),i=r}return i}}class $_{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class jm{constructor(e){this.cacheKey=e,this.usedTimes=0}}class j_ extends jm{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class q_ extends jm{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Y_=0;class Wl{constructor(e,t,s,i=null,n=null){this.id=Y_++,this.code=e,this.stage=t,this.name=s,this.transforms=i,this.attributes=n,this.usedTimes=0}}class X_ extends Ii{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,i=this.get(e);if(this._needsComputeUpdate(e)){const n=i.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const r=this.nodes.getForCompute(e);let o=this.programs.compute.get(r.computeShader);o===void 0&&(n&&n.computeProgram.usedTimes===0&&this._releaseProgram(n.computeProgram),o=new Wl(r.computeShader,"compute",e.name,r.transforms,r.nodeAttributes),this.programs.compute.set(r.computeShader,o),s.createProgram(o));const l=this._getComputeCacheKey(e,o);let c=this.caches.get(l);c===void 0&&(n&&n.usedTimes===0&&this._releasePipeline(n),c=this._getComputePipeline(e,o,l,t)),c.usedTimes++,o.usedTimes++,i.version=e.version,i.pipeline=c}return i.pipeline}getForRender(e,t=null){const{backend:s}=this,i=this.get(e);if(this._needsRenderUpdate(e)){const n=i.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const r=e.getNodeBuilderState(),o=e.material?e.material.name:"";let l=this.programs.vertex.get(r.vertexShader);l===void 0&&(n&&n.vertexProgram.usedTimes===0&&this._releaseProgram(n.vertexProgram),l=new Wl(r.vertexShader,"vertex",o),this.programs.vertex.set(r.vertexShader,l),s.createProgram(l));let c=this.programs.fragment.get(r.fragmentShader);c===void 0&&(n&&n.fragmentProgram.usedTimes===0&&this._releaseProgram(n.fragmentProgram),c=new Wl(r.fragmentShader,"fragment",o),this.programs.fragment.set(r.fragmentShader,c),s.createProgram(c));const h=this._getRenderCacheKey(e,l,c);let u=this.caches.get(h);u===void 0?(n&&n.usedTimes===0&&this._releasePipeline(n),u=this._getRenderPipeline(e,l,c,h,t)):e.pipeline=u,u.usedTimes++,l.usedTimes++,c.usedTimes++,i.pipeline=u}return i.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,t.usedTimes===0&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,t.computeProgram.usedTimes===0&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,t.vertexProgram.usedTimes===0&&this._releaseProgram(t.vertexProgram),t.fragmentProgram.usedTimes===0&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,i){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return n===void 0&&(n=new q_(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,i)),n}_getRenderPipeline(e,t,s,i,n){i=i||this._getRenderCacheKey(e,t,s);let r=this.caches.get(i);return r===void 0&&(r=new j_(i,t,s),this.caches.set(i,r),e.pipeline=r,this.backend.createRenderPipeline(e,n)),r}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return t.pipeline===void 0||t.version!==e.version}_needsRenderUpdate(e){return this.get(e).pipeline===void 0||this.backend.needsRenderUpdate(e)}}class Z_ extends Ii{constructor(e,t,s,i,n,r){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=i,this.nodes=t,this.info=r,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const s of t){const i=this.get(s);i.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),i.bindGroup=s)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const s of t){const i=this.get(s);i.bindGroup===void 0&&(this._init(s),this.backend.createBindings(s,t,0),i.bindGroup=s)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const s=t.attribute,i=s.isIndirectStorageBufferAttribute?as.INDIRECT:as.STORAGE;this.attributes.update(s,i)}}_update(e,t){const{backend:s}=this;let i=!1,n=!0,r=0,o=0;for(const l of e.bindings)if(!(l.isNodeUniformsGroup&&this.nodes.updateGroup(l)===!1)){if(l.isStorageBuffer){const c=l.attribute,h=c.isIndirectStorageBufferAttribute?as.INDIRECT:as.STORAGE;this.attributes.update(c,h)}if(l.isUniformBuffer)l.update()&&s.updateBinding(l);else if(l.isSampler)l.update();else if(l.isSampledTexture){const c=this.textures.get(l.texture);l.needsBindingsUpdate(c.generation)&&(i=!0);const h=l.update(),u=l.texture;h&&this.textures.updateTexture(u);const d=s.get(u);if(d.externalTexture!==void 0||c.isDefaultTexture?n=!1:(r=r*10+u.id,o+=u.version),s.isWebGPUBackend===!0&&d.texture===void 0&&d.externalTexture===void 0&&(console.error("Bindings._update: binding should be available:",l,h,u,l.textureNode.value,i),this.textures.updateTexture(u),i=!0),u.isStorageTexture===!0){const p=this.get(u);l.store===!0?p.needsMipmap=!0:this.textures.needsMipmaps(u)&&p.needsMipmap===!0&&(this.backend.generateMipmaps(u),p.needsMipmap=!1)}}}i===!0&&this.backend.updateBindings(e,t,n?r:0,o)}}function Q_(a,e){return a.groupOrder!==e.groupOrder?a.groupOrder-e.groupOrder:a.renderOrder!==e.renderOrder?a.renderOrder-e.renderOrder:a.z!==e.z?a.z-e.z:a.id-e.id}function kd(a,e){return a.groupOrder!==e.groupOrder?a.groupOrder-e.groupOrder:a.renderOrder!==e.renderOrder?a.renderOrder-e.renderOrder:a.z!==e.z?e.z-a.z:a.id-e.id}function zd(a){return(a.transmission>0||a.transmissionNode)&&a.side===Zn&&a.forceSinglePass===!1}class K_{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,i,n,r,o){let l=this.renderItems[this.renderItemsIndex];return l===void 0?(l={id:e.id,object:e,geometry:t,material:s,groupOrder:i,renderOrder:e.renderOrder,z:n,group:r,clippingContext:o},this.renderItems[this.renderItemsIndex]=l):(l.id=e.id,l.object=e,l.geometry=t,l.material=s,l.groupOrder=i,l.renderOrder=e.renderOrder,l.z=n,l.group=r,l.clippingContext=o),this.renderItemsIndex++,l}push(e,t,s,i,n,r,o){const l=this.getNextRenderItem(e,t,s,i,n,r,o);e.occlusionTest===!0&&this.occlusionQueryCount++,s.transparent===!0||s.transmission>0?(zd(s)&&this.transparentDoublePass.push(l),this.transparent.push(l)):this.opaque.push(l)}unshift(e,t,s,i,n,r,o){const l=this.getNextRenderItem(e,t,s,i,n,r,o);s.transparent===!0||s.transmission>0?(zd(s)&&this.transparentDoublePass.unshift(l),this.transparent.unshift(l)):this.opaque.unshift(l)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||Q_),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||kd),this.transparent.length>1&&this.transparent.sort(t||kd)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){const s=this.renderItems[e];if(s.id===null)break;s.id=null,s.object=null,s.geometry=null,s.material=null,s.groupOrder=null,s.renderOrder=null,s.z=null,s.group=null,s.clippingContext=null}}}const wr=[];class J_{constructor(e){this.lighting=e,this.lists=new Ss}get(e,t){const s=this.lists;wr[0]=e,wr[1]=t;let i=s.get(wr);return i===void 0&&(i=new K_(this.lighting,e,t),s.set(wr,i)),wr.length=0,i}dispose(){this.lists=new Ss}}let eb=0;class tb{constructor(){this.id=eb++,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new me,this.scissor=!1,this.scissorValue=new me,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.isRenderContext=!0}getCacheKey(){return qm(this)}}function qm(a){const{textures:e,activeCubeFace:t}=a,s=[t];for(const i of e)s.push(i.id);return au(s)}let dn=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[e]===void 0&&(s[e]=[]),s[e].indexOf(t)===-1&&s[e].push(t)}hasEventListener(e,t){const s=this._listeners;return s===void 0?!1:s[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){const s=this._listeners;if(s===void 0)return;const i=s[e];if(i!==void 0){const n=i.indexOf(t);n!==-1&&i.splice(n,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const s=t[e.type];if(s!==void 0){e.target=this;const i=s.slice(0);for(let n=0,r=i.length;n<r;n++)i[n].call(this,e);e.target=null}}};const Gd=new Be,Vd=new mr;class hs{constructor(e=0,t=0,s=0,i=hs.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=s,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,s,i=this._order){return this._x=e,this._y=t,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,s=!0){const i=e.elements,n=i[0],r=i[4],o=i[8],l=i[1],c=i[5],h=i[9],u=i[2],d=i[6],p=i[10];switch(t){case"XYZ":this._y=Math.asin(de(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-de(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,p),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(de(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(l,n));break;case"ZYX":this._y=Math.asin(-de(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(l,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(de(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(o,p));break;case"XZY":this._z=Math.asin(-de(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,n)):(this._x=Math.atan2(-h,p),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,s===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,s){return Gd.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Gd,t,s)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Vd.setFromEuler(this),this.setFromQuaternion(Vd,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}hs.DEFAULT_ORDER="XYZ";class sb{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let ib=0;const Hd=new N,vn=new mr,Gs=new Be,La=new N,Er=new N,nb=new N,rb=new mr,Wd=new N(1,0,0),$d=new N(0,1,0),jd=new N(0,0,1),qd={type:"added"},ab={type:"removed"},wn={type:"childadded",child:null},$l={type:"childremoved",child:null};class ut extends dn{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:ib++}),this.uuid=Zs(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=ut.DEFAULT_UP.clone();const e=new N,t=new hs,s=new mr,i=new N(1,1,1);function n(){s.setFromEuler(t,!1)}function r(){t.setFromQuaternion(s,void 0,!1)}t._onChange(n),s._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new Be},normalMatrix:{value:new Vt}}),this.matrix=new Be,this.matrixWorld=new Be,this.matrixAutoUpdate=ut.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new sb,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.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return vn.setFromAxisAngle(e,t),this.quaternion.multiply(vn),this}rotateOnWorldAxis(e,t){return vn.setFromAxisAngle(e,t),this.quaternion.premultiply(vn),this}rotateX(e){return this.rotateOnAxis(Wd,e)}rotateY(e){return this.rotateOnAxis($d,e)}rotateZ(e){return this.rotateOnAxis(jd,e)}translateOnAxis(e,t){return Hd.copy(e).applyQuaternion(this.quaternion),this.position.add(Hd.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Wd,e)}translateY(e){return this.translateOnAxis($d,e)}translateZ(e){return this.translateOnAxis(jd,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Gs.copy(this.matrixWorld).invert())}lookAt(e,t,s){e.isVector3?La.copy(e):La.set(e,t,s);const i=this.parent;this.updateWorldMatrix(!0,!1),Er.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Gs.lookAt(Er,La,this.up):Gs.lookAt(La,Er,this.up),this.quaternion.setFromRotationMatrix(Gs),i&&(Gs.extractRotation(i.matrixWorld),vn.setFromRotationMatrix(Gs),this.quaternion.premultiply(vn.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(qd),wn.child=e,this.dispatchEvent(wn),wn.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let s=0;s<arguments.length;s++)this.remove(arguments[s]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(ab),$l.child=e,this.dispatchEvent($l),$l.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Gs.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),Gs.multiply(e.parent.matrixWorld)),e.applyMatrix4(Gs),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(qd),wn.child=e,this.dispatchEvent(wn),wn.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let s=0,i=this.children.length;s<i;s++){const r=this.children[s].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,s=[]){this[e]===t&&s.push(this);const i=this.children;for(let n=0,r=i.length;n<r;n++)i[n].getObjectsByProperty(e,t,s);return s}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Er,e,nb),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Er,rb,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let s=0,i=t.length;s<i;s++)t[s].updateMatrixWorld(e)}updateWorldMatrix(e,t){const s=this.parent;if(e===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),t===!0){const i=this.children;for(let n=0,r=i.length;n<r;n++)i[n].updateWorldMatrix(!1,!0)}}toJSON(e){const t=e===void 0||typeof e=="string",s={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});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),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.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),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(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(o=>({...o})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function n(o,l){return o[l.uuid]===void 0&&(o[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=n(e.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const l=o.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c<h;c++){const u=l[c];n(e.shapes,u)}else n(e.shapes,l)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(e.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let l=0,c=this.material.length;l<c;l++)o.push(n(e.materials,this.material[l]));i.material=o}else i.material=n(e.materials,this.material);if(this.children.length>0){i.children=[];for(let o=0;o<this.children.length;o++)i.children.push(this.children[o].toJSON(e).object)}if(this.animations.length>0){i.animations=[];for(let o=0;o<this.animations.length;o++){const l=this.animations[o];i.animations.push(n(e.animations,l))}}if(t){const o=r(e.geometries),l=r(e.materials),c=r(e.textures),h=r(e.images),u=r(e.shapes),d=r(e.skeletons),p=r(e.animations),f=r(e.nodes);o.length>0&&(s.geometries=o),l.length>0&&(s.materials=l),c.length>0&&(s.textures=c),h.length>0&&(s.images=h),u.length>0&&(s.shapes=u),d.length>0&&(s.skeletons=d),p.length>0&&(s.animations=p),f.length>0&&(s.nodes=f)}return s.object=i,s;function r(o){const l=[];for(const c in o){const h=o[c];delete h.metadata,l.push(h)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let s=0;s<e.children.length;s++){const i=e.children[s];this.add(i.clone())}return this}}ut.DEFAULT_UP=new N(0,1,0);ut.DEFAULT_MATRIX_AUTO_UPDATE=!0;ut.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class ou extends ut{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(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}class lu extends ut{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Be,this.projectionMatrix=new Be,this.projectionMatrixInverse=new Be,this.coordinateSystem=Lt}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const Cr=[],ob=new ou,lb=new lu;class cb{constructor(){this.chainMaps={}}get(e,t,s=null){Cr[0]=e,Cr[1]=t;let i;if(s===null)i="default";else{const o=s.texture.format;i=`${s.textures.length}:${o}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this._getChainMap(i);let r=n.get(Cr);return r===void 0&&(r=new tb,n.set(Cr,r)),Cr.length=0,s!==null&&(r.sampleCount=s.samples===0?1:s.samples),r}getForClear(e=null){return this.get(ob,lb,e)}_getChainMap(e){return this.chainMaps[e]||(this.chainMaps[e]=new Ss)}dispose(){this.chainMaps={}}}let En;class hb{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let s;if(e instanceof HTMLCanvasElement)s=e;else{En===void 0&&(En=Dh("canvas")),En.width=e.width,En.height=e.height;const i=En.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),s=En}return s.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Dh("canvas");t.width=e.width,t.height=e.height;const s=t.getContext("2d");s.drawImage(e,0,0,e.width,e.height);const i=s.getImageData(0,0,e.width,e.height),n=i.data;for(let r=0;r<n.length;r++)n[r]=ti(n[r]/255)*255;return s.putImageData(i,0,0),t}else if(e.data){const t=e.data.slice(0);for(let s=0;s<t.length;s++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[s]=Math.floor(ti(t[s]/255)*255):t[s]=ti(t[s]);return{data:t,width:e.width,height:e.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let ub=0;class cu{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:ub++}),this.uuid=Zs(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(i!==null){let n;if(Array.isArray(i)){n=[];for(let r=0,o=i.length;r<o;r++)i[r].isDataTexture?n.push(jl(i[r].image)):n.push(jl(i[r]))}else n=jl(i);s.url=n}return t||(e.images[this.uuid]=s),s}}function jl(a){return typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&a instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&a instanceof ImageBitmap?hb.getDataURL(a):a.data?{data:Array.from(a.data),width:a.width,height:a.height,type:a.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let db=0;const ql=new N;class Tt extends dn{constructor(e=Tt.DEFAULT_IMAGE,t=Tt.DEFAULT_MAPPING,s=Ai,i=Ai,n=Qt,r=Js,o=rs,l=Rt,c=Tt.DEFAULT_ANISOTROPY,h=ni){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:db++}),this.uuid=Zs(),this.name="",this.source=new cu(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=o,this.internalFormat=null,this.type=l,this.offset=new ce(0,0),this.repeat=new ce(1,1),this.center=new ce(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Vt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(ql).x}get height(){return this.source.getSize(ql).y}get depth(){return this.source.getSize(ql).z}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const s=e[t];if(s===void 0){console.warn(`THREE.Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const i=this[t];if(i===void 0){console.warn(`THREE.Texture.setValues(): property '${t}' does not exist.`);continue}i&&s&&i.isVector2&&s.isVector2||i&&s&&i.isVector3&&s.isVector3||i&&s&&i.isMatrix3&&s.isMatrix3?i.copy(s):this[t]=s}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const s={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(s.userData=this.userData),t||(e.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Qh)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case lr:e.x=e.x-Math.floor(e.x);break;case Ai:e.x=e.x<0?0:1;break;case cr:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case lr:e.y=e.y-Math.floor(e.y);break;case Ai:e.y=e.y<0?0:1;break;case cr:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}Tt.DEFAULT_IMAGE=null;Tt.DEFAULT_MAPPING=Qh;Tt.DEFAULT_ANISOTROPY=1;class Bs extends Tt{constructor(e,t,s=Ye,i,n,r,o=ht,l=ht,c,h=Os,u=1){if(h!==Os&&h!==ei)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const d={width:e,height:t,depth:u};super(d,i,n,r,o,l,h,s,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new cu(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}const pb=new N;class fb extends Ii{constructor(e,t,s){super(),this.renderer=e,this.backend=t,this.info=s}updateRenderTarget(e,t=0){const s=this.get(e),i=e.samples===0?1:e.samples,n=s.depthTextureMips||(s.depthTextureMips={}),r=e.textures,o=this.getSize(r[0]),l=o.width>>t,c=o.height>>t;let h=e.depthTexture||n[t];const u=e.depthBuffer===!0||e.stencilBuffer===!0;let d=!1;h===void 0&&u&&(h=new Bs,h.format=e.stencilBuffer?ei:Os,h.type=e.stencilBuffer?Pi:Ye,h.image.width=l,h.image.height=c,h.image.depth=o.depth,h.isArrayTexture=e.multiview===!0&&o.depth>1,n[t]=h),(s.width!==o.width||o.height!==s.height)&&(d=!0,h&&(h.needsUpdate=!0,h.image.width=l,h.image.height=c,h.image.depth=h.isArrayTexture?h.image.depth:1)),s.width=o.width,s.height=o.height,s.textures=r,s.depthTexture=h||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==i&&(d=!0,h&&(h.needsUpdate=!0),s.sampleCount=i);const p={sampleCount:i};if(e.isXRRenderTarget!==!0){for(let f=0;f<r.length;f++){const m=r[f];d&&(m.needsUpdate=!0),this.updateTexture(m,p)}h&&this.updateTexture(h,p)}if(s.initialized!==!0){s.initialized=!0;const f=()=>{e.removeEventListener("dispose",f);for(let m=0;m<r.length;m++)this._destroyTexture(r[m]);h&&this._destroyTexture(h),this.delete(e)};e.addEventListener("dispose",f)}}updateTexture(e,t={}){const s=this.get(e);if(s.initialized===!0&&s.version===e.version)return;const i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,n=this.backend;if(i&&s.initialized===!0&&(n.destroySampler(e),n.destroyTexture(e)),e.isFramebufferTexture){const c=this.renderer.getRenderTarget();c?e.type=c.texture.type:e.type=Rt}const{width:r,height:o,depth:l}=this.getSize(e);if(t.width=r,t.height=o,t.depth=l,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,r,o):1,i||e.isStorageTexture===!0)n.createSampler(e),n.createTexture(e,t),s.generation=e.version;else if(s.initialized!==!0&&n.createSampler(e),e.version>0){const h=e.image;if(h===void 0)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(h.complete===!1)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const u=[];for(const d of e.images)u.push(d);t.images=u}else t.image=h;(s.isDefaultTexture===void 0||s.isDefaultTexture===!0)&&(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),e.source.dataReady===!0&&n.updateTexture(e,t),t.needsMipmaps&&e.mipmaps.length===0&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version;if(s.initialized!==!0){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const c=()=>{e.removeEventListener("dispose",c),this._destroyTexture(e)};e.addEventListener("dispose",c)}s.version=e.version}getSize(e,t=pb){let s=e.images?e.images[0]:e.image;return s?(s.image!==void 0&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let i;return e.isCompressedTexture?e.mipmaps?i=e.mipmaps.length:i=1:i=Math.floor(Math.log2(Math.max(t,s)))+1,i}needsMipmaps(e){return e.isCompressedTexture===!0||e.generateMipmaps}_destroyTexture(e){this.has(e)===!0&&(this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e),this.info.memory.textures--)}}class hu extends ve{constructor(e,t,s,i=1){super(e,t,s),this.a=i}set(e,t,s,i=1){return this.a=i,super.set(e,t,s)}copy(e){return e.a!==void 0&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const Ua={VERTEX:"vertex"},he={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Xs={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},mb=["fragment","vertex"],Yd=["setup","analyze","generate"],Xd=[...mb,"compute"],gr=["x","y","z","w"],gb={analyze:"setup",generate:"analyze"};let yb=0;class ae extends dn{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=he.NONE,this.updateBeforeType=he.NONE,this.updateAfterType=he.NONE,this.uuid=wx.generateUUID(),this.version=0,this.global=!1,this.parents=!1,this.isNode=!0,this._cacheKey=null,this._cacheKeyVersion=0,Object.defineProperty(this,"id",{value:yb++})}set needsUpdate(e){e===!0&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,he.FRAME)}onRenderUpdate(e){return this.onUpdate(e,he.RENDER)}onObjectUpdate(e){return this.onUpdate(e,he.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of Qo(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return e=e||this.version!==this._cacheKeyVersion,(e===!0||this._cacheKey===null)&&(this._cacheKey=Zo(km(this,e),this.customCacheKey()),this._cacheKeyVersion=this.version),this._cacheKey}customCacheKey(){return 0}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const i of this.getChildren())t["node"+s++]=i;return t.outputNode||null}analyze(e,t=null){const s=e.increaseUsage(this);if(this.parents===!0){const i=e.getDataFromNode(this,"any");i.stages=i.stages||{},i.stages[e.shaderStage]=i.stages[e.shaderStage]||[],i.stages[e.shaderStage].push(t)}if(s===1){const i=e.getNodeProperties(this);for(const n of Object.values(i))n&&n.isNode===!0&&n.build(e,this)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&s.isNode===!0)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);const i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;const n=gb[e.buildStage];if(n&&i.buildStages[n]!==!0){const l=e.getBuildStage();e.setBuildStage(n),this.build(e),e.setBuildStage(l)}e.addNode(this),e.addChain(this);let r=null;const o=e.getBuildStage();if(o==="setup"){this.updateReference(e);const l=e.getNodeProperties(this);if(l.initialized!==!0){l.initialized=!0,l.outputNode=this.setup(e)||l.outputNode||null;for(const c of Object.values(l))if(c&&c.isNode===!0){if(c.parents===!0){const h=e.getNodeProperties(c);h.parents=h.parents||[],h.parents.push(this)}c.build(e)}}r=l.outputNode}else if(o==="analyze")this.analyze(e,t);else if(o==="generate")if(this.generate.length===1){const c=this.getNodeType(e),h=e.getDataFromNode(this);r=h.snippet,r===void 0?h.generated===void 0?(h.generated=!0,r=this.generate(e)||"",h.snippet=r):(console.warn("THREE.Node: Recursion detected.",this),r=""):h.flowCodes!==void 0&&e.context.nodeBlock!==void 0&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,c,t)}else r=this.generate(e,t)||"";return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return Qo(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:i,index:n,childNode:r}of t)n!==void 0?(s[i]===void 0&&(s[i]=Number.isInteger(n)?[]:{}),s[i][n]=r.toJSON(e.meta).uuid):s[i]=r.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(e.inputNodes!==void 0){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const i=[];for(const n of e.inputNodes[s])i.push(t[n]);this[s]=i}else if(typeof e.inputNodes[s]=="object"){const i={};for(const n in e.inputNodes[s]){const r=e.inputNodes[s][n];i[n]=t[r]}this[s]=i}else{const i=e.inputNodes[s];this[s]=t[i]}}}toJSON(e){const{uuid:t,type:s}=this,i=e===void 0||typeof e=="string";i&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];n===void 0&&(n={uuid:t,type:s,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},i!==!0&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta);function r(o){const l=[];for(const c in o){const h=o[c];delete h.metadata,l.push(h)}return l}if(i){const o=r(e.textures),l=r(e.images),c=r(e.nodes);o.length>0&&(n.textures=o),l.length>0&&(n.images=l),c.length>0&&(n.nodes=c)}return n}}class it extends ae{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if(e.getBuildStage()==="generate"){const i=e.getVectorType(this.getNodeType(e,t)),n=e.getDataFromNode(this);if(n.propertyName!==void 0)return e.format(n.propertyName,i,t);if(i!=="void"&&t!=="void"&&this.hasDependencies(e)){const r=super.build(e,i),o=e.getVarFromNode(this,null,i),l=e.getPropertyName(o);return e.addLineFlowCode(`${l} = ${r}`,this),n.snippet=r,n.propertyName=l,e.format(n.propertyName,i,t)}}return super.build(e,t)}}class va extends ae{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){const t=this.indexNode.getNodeType(e),s=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${s}[ ${i} ]`}}class Ym extends ae{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const i of this.convertTo.split("|"))(s===null||e.getTypeLength(t)===e.getTypeLength(i))&&(s=i);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,i=this.getNodeType(e),n=s.build(e,i);return e.format(n,i,t)}}class xb extends it{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return this.nodeType!==null?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,s)=>t+e.getTypeLength(s.getNodeType(e)),0))}generate(e,t){const s=this.getNodeType(e),i=e.getTypeLength(s),n=this.nodes,r=e.getComponentType(s),o=[];let l=0;for(const h of n){if(l>=i){console.error(`THREE.TSL: Length of parameters exceeds maximum length of function '${s}()' type.`);break}let u=h.getNodeType(e),d=e.getTypeLength(u),p;l+d>i&&(console.error(`THREE.TSL: Length of '${s}()' data exceeds maximum length of output type.`),d=i-l,u=e.getTypeFromLength(d)),l+=d,p=h.build(e,u);const f=e.getComponentType(u);f!==r&&(p=e.format(p,f,r)),o.push(p)}const c=`${e.getType(s)}( ${o.join(", ")} )`;return e.format(c,s,t)}}const _b=gr.join("");class Zd extends ae{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(gr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,i=e.getTypeLength(s.getNodeType(e));let n=null;if(i>1){let r=null;this.getVectorLength()>=i&&(r=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const l=s.build(e,r);this.components.length===i&&this.components===_b.slice(0,this.components.length)?n=e.format(l,r,t):n=e.format(`${l}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class bb extends it{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:i}=this,n=this.getNodeType(e),r=e.getComponentType(i.getNodeType(e)),o=e.getTypeFromLength(s.length,r),l=i.build(e,o),c=t.build(e,n),h=e.getTypeLength(n),u=[];for(let d=0;d<h;d++){const p=gr[d];p===s[0]?(u.push(l),d+=s.length-1):u.push(c+"."+p)}return`${e.getType(n)}( ${u.join(", ")} )`}}class Tb extends it{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{components:t,sourceNode:s}=this,i=this.getNodeType(e),n=s.build(e),r=e.getVarFromNode(this),o=e.getPropertyName(r);e.addLineFlowCode(o+" = "+n,this);const l=e.getTypeLength(i),c=[];let h=0;for(let u=0;u<l;u++){const d=gr[u];d===t[h]?(c.push("1.0 - "+(o+"."+d)),h++):c.push(o+"."+d)}return`${e.getType(i)}( ${c.join(", ")} )`}}class uu extends ae{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}getNodeType(){return this.nodeType===null?Ko(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=Ko(this.value),e.nodeType=this.nodeType,e.valueType==="ArrayBuffer"&&(e.value=F_(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?zm(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){console.warn("Abstract function.")}}const Qd=/float|u?int/;class li extends uu{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){const s=this.getNodeType(e);return Qd.test(s)&&Qd.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),s,t)}}class Sb extends ae{static get type(){return"MemberNode"}constructor(e,t){super(),this.node=e,this.property=t,this.isMemberNode=!0}getNodeType(e){return this.node.getMemberType(e,this.property)}generate(e){return this.node.build(e)+"."+this.property}}let hr=null;const jn=new Map;function O(a,e){if(jn.has(a)){console.warn(`THREE.TSL: Redefinition of method chaining '${a}'.`);return}if(typeof e!="function")throw new Error(`THREE.TSL: Node element ${a} is not a function`);jn.set(a,e)}const Xm=a=>a.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Kd=a=>Xm(a).split("").sort().join(""),Zm={setup(a,e){const t=e.shift();return a(pl(t),...e)},get(a,e,t){if(typeof e=="string"&&a[e]===void 0){if(a.isStackNode!==!0&&e==="assign")return(...s)=>(hr.assign(t,...s),t);if(jn.has(e)){const s=jn.get(e);return a.isStackNode?(...i)=>t.add(s(...i)):(...i)=>s(t,...i)}else{if(e==="self")return a;if(e.endsWith("Assign")&&jn.has(e.slice(0,e.length-6))){const s=jn.get(e.slice(0,e.length-6));return a.isStackNode?(...i)=>t.assign(i[0],s(...i)):(...i)=>t.assign(s(t,...i))}else{if(/^[xyzwrgbastpq]{1,4}$/.test(e)===!0)return e=Xm(e),k(new Zd(t,e));if(/^set[XYZWRGBASTPQ]{1,4}$/.test(e)===!0)return e=Kd(e.slice(3).toLowerCase()),s=>k(new bb(a,e,k(s)));if(/^flip[XYZWRGBASTPQ]{1,4}$/.test(e)===!0)return e=Kd(e.slice(4).toLowerCase()),()=>k(new Tb(k(a),e));if(e==="width"||e==="height"||e==="depth")return e==="width"?e="x":e==="height"?e="y":e==="depth"&&(e="z"),k(new Zd(a,e));if(/^\d+$/.test(e)===!0)return k(new va(t,new li(Number(e),"uint")));if(/^get$/.test(e)===!0)return s=>k(new Sb(t,s))}}}return Reflect.get(a,e,t)},set(a,e,t,s){return typeof e=="string"&&a[e]===void 0&&(/^[xyzwrgbastpq]{1,4}$/.test(e)===!0||e==="width"||e==="height"||e==="depth"||/^\d+$/.test(e)===!0)?(s[e].assign(t),!0):Reflect.set(a,e,t,s)}},Yl=new WeakMap,Jd=new WeakMap,vb=function(a,e=null){const t=Ko(a);if(t==="node"){let s=Yl.get(a);return s===void 0&&(s=new Proxy(a,Zm),Yl.set(a,s),Yl.set(s,s)),s}else{if(e===null&&(t==="float"||t==="boolean")||t&&t!=="shader"&&t!=="string")return k(Fh(a,e));if(t==="shader")return L(a)}return a},wb=function(a,e=null){for(const t in a)a[t]=k(a[t],e);return a},Eb=function(a,e=null){const t=a.length;for(let s=0;s<t;s++)a[s]=k(a[s],e);return a},Cb=function(a,e=null,t=null,s=null){const i=h=>k(s!==null?Object.assign(h,s):h);let n,r=e,o,l;function c(h){let u;return r?u=/[a-z]/i.test(r)?r+"()":r:u=a.type,o!==void 0&&h.length<o?(console.error(`THREE.TSL: "${u}" parameter length is less than minimum required.`),h.concat(new Array(o-h.length).fill(0))):l!==void 0&&h.length>l?(console.error(`THREE.TSL: "${u}" parameter length exceeds limit.`),h.slice(0,l)):h}return e===null?n=(...h)=>i(new a(...er(c(h)))):t!==null?(t=k(t),n=(...h)=>i(new a(e,...er(c(h)),t))):n=(...h)=>i(new a(e,...er(c(h)))),n.setParameterLength=(...h)=>(h.length===1?o=l=h[0]:h.length===2&&([o,l]=h),n),n.setName=h=>(r=h,n),n},Mb=function(a,...e){return k(new a(...er(e)))};class Ab extends ae{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t,this.isShaderCallNodeInternal=!0}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){const{shaderNode:t,inputNodes:s}=this,i=e.getNodeProperties(t),n=t.namespace&&t.namespace===e.namespace?e.getNamespace("once"):"once";if(i[n])return i[n];let r=null;if(t.layout){let o=Jd.get(e.constructor);o===void 0&&(o=new WeakMap,Jd.set(e.constructor,o));let l=o.get(t);l===void 0&&(l=k(e.buildFunctionNode(t)),o.set(t,l)),e.addInclude(l),r=k(l.call(s))}else{const o=t.jsFunc,l=s!==null||o.length>1?o(s||[],e):o(e);r=k(l)}return t.once&&(i[n]=r),r}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){const t=e.getNodeProperties(this),s=e.getOutputNamespace();return t[s]=t[s]||this.setupOutput(e),t[s]}build(e,t=null){let s=null;const i=e.getBuildStage(),n=e.getNodeProperties(this),r=e.getOutputNamespace(),o=this.getOutputNode(e);if(i==="setup"){const l=e.getNamespace("initialized");n[l]!==!0&&(n[l]=!0,n[r]=this.getOutputNode(e),n[r].build(e)),s=n[r]}else i==="analyze"?o.build(e,t):i==="generate"&&(s=o.build(e,t)||"");return s}}class Rb extends ae{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1,this.namespace=null}setLayout(e){return this.layout=e,this}call(e=null){return pl(e),k(new Ab(this,e))}setup(){return this.call()}}const Nb=[!1,!0],Pb=[0,1,2,3],Db=[-1,-2],Qm=[.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],du=new Map;for(const a of Nb)du.set(a,new li(a));const pu=new Map;for(const a of Pb)pu.set(a,new li(a,"uint"));const fu=new Map([...pu].map(a=>new li(a.value,"int")));for(const a of Db)fu.set(a,new li(a,"int"));const ul=new Map([...fu].map(a=>new li(a.value)));for(const a of Qm)ul.set(a,new li(a));for(const a of Qm)ul.set(-a,new li(-a));const dl={bool:du,uint:pu,ints:fu,float:ul},ep=new Map([...du,...ul]),Fh=(a,e)=>ep.has(a)?ep.get(a):a.isNode===!0?a:new li(a,e),Fb=a=>{try{return a.getNodeType()}catch{return}},nt=function(a,e=null){return(...t)=>{if((t.length===0||!["bool","float","int","uint"].includes(a)&&t.every(i=>typeof i!="object"))&&(t=[zm(a,...t)]),t.length===1&&e!==null&&e.has(t[0]))return k(e.get(t[0]));if(t.length===1){const i=Fh(t[0],a);return Fb(i)===a?k(i):k(new Ym(i,a))}const s=t.map(i=>Fh(i));return k(new xb(s,a))}},tp=a=>typeof a=="object"&&a!==null?a.value:a,Ob=a=>a!=null?a.nodeType||a.convertTo||(typeof a=="string"?a:null):null;function Qr(a,e){return new Proxy(new Rb(a,e),Zm)}const k=(a,e=null)=>vb(a,e),pl=(a,e=null)=>new wb(a,e),er=(a,e=null)=>new Eb(a,e),U=(...a)=>new Cb(...a),V=(...a)=>new Mb(...a);let Bb=0;const L=(a,e=null)=>{let t=null;e!==null&&(typeof e=="object"?t=e.return:(typeof e=="string"?t=e:console.error("THREE.TSL: Invalid layout type."),e=null));const s=new Qr(a,t),i=(...n)=>{let r;pl(n),n[0]&&(n[0].isNode||Object.getPrototypeOf(n[0])!==Object.prototype)?r=[...n]:r=n[0];const l=s.call(r);return t==="void"&&l.toStack(),l};if(i.shaderNode=s,i.id=s.id,i.getNodeType=(...n)=>s.getNodeType(...n),i.getCacheKey=(...n)=>s.getCacheKey(...n),i.setLayout=n=>(s.setLayout(n),i),i.once=(n=null)=>(s.once=!0,s.namespace=n,i),e!==null){if(typeof e.inputs!="object"){const n={name:"fn"+Bb++,type:t,inputs:[]};for(const r in e)r!=="return"&&n.inputs.push({name:r,type:e[r]});e=n}i.setLayout(e)}return i},Jo=a=>{hr=a},Km=()=>hr,Xe=(...a)=>hr.If(...a);function Jm(a){return hr&&hr.add(a),a}O("toStack",Jm);const Ib=new nt("color"),B=new nt("float",dl.float),Ue=new nt("int",dl.ints),Lb=new nt("uint",dl.uint),mu=new nt("bool",dl.bool),H=new nt("vec2"),js=new nt("ivec2"),Ub=new nt("uvec2"),kb=new nt("bvec2"),I=new nt("vec3"),zb=new nt("ivec3"),Gb=new nt("uvec3"),Vb=new nt("bvec3"),re=new nt("vec4"),Hb=new nt("ivec4"),Wb=new nt("uvec4"),$b=new nt("bvec4"),gu=new nt("mat2"),Pt=new nt("mat3"),tr=new nt("mat4");O("toColor",Ib);O("toFloat",B);O("toInt",Ue);O("toUint",Lb);O("toBool",mu);O("toVec2",H);O("toIVec2",js);O("toUVec2",Ub);O("toBVec2",kb);O("toVec3",I);O("toIVec3",zb);O("toUVec3",Gb);O("toBVec3",Vb);O("toVec4",re);O("toIVec4",Hb);O("toUVec4",Wb);O("toBVec4",$b);O("toMat2",gu);O("toMat3",Pt);O("toMat4",tr);const jb=U(va).setParameterLength(2),qb=(a,e)=>k(new Ym(k(a),e));O("element",jb);O("convert",qb);O("append",a=>(console.warn("THREE.TSL: .append() has been renamed to .toStack()."),Jm(a)));class Yb extends it{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}getNodeType(e,t){return t!=="void"?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(e.isAvailable("swizzleAssign")===!1&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return gr.join("").slice(0,s)!==t.components}return!1}setup(e){const{targetNode:t,sourceNode:s}=this,i=e.getNodeProperties(this);i.sourceNode=s,i.targetNode=t.context({assign:!0})}generate(e,t){const{targetNode:s,sourceNode:i}=e.getNodeProperties(this),n=this.needsSplitAssign(e),r=s.getNodeType(e),o=s.build(e),l=i.build(e,r),c=i.getNodeType(e),h=e.getDataFromNode(this);let u;if(h.initialized===!0)t!=="void"&&(u=o);else if(n){const d=e.getVarFromNode(this,null,r),p=e.getPropertyName(d);e.addLineFlowCode(`${p} = ${l}`,this);const f=s.node,y=f.node.context({assign:!0}).build(e);for(let g=0;g<f.components.length;g++){const _=f.components[g];e.addLineFlowCode(`${y}.${_} = ${p}[ ${g} ]`,this)}t!=="void"&&(u=o)}else u=`${o} = ${l}`,(t==="void"||c==="void")&&(e.addLineFlowCode(u,this),t!=="void"&&(u=o));return h.initialized=!0,e.format(u,r,t)}}const Xb=U(Yb).setParameterLength(2);O("assign",Xb);class sp extends it{static get type(){return"ArrayNode"}constructor(e,t,s=null){super(e),this.count=t,this.values=s,this.isArrayNode=!0}getNodeType(e){return this.nodeType===null&&(this.nodeType=this.values[0].getNodeType(e)),this.nodeType}getElementType(e){return this.getNodeType(e)}generate(e){const t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}const Zb=(...a)=>{let e;if(a.length===1){const t=a[0];e=new sp(null,t.length,t)}else{const t=a[0],s=a[1];e=new sp(t,s)}return k(e)};O("toArray",(a,e)=>Zb(Array(e).fill(a)));class eg extends ae{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.shared=t,this.order=s,this.isUniformGroup=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Qb=a=>new eg(a),yu=(a,e=0)=>new eg(a,!0,e),Kb=yu("frame"),K=yu("render"),tg=Qb("object");class wa extends uu{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=tg}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate(i=>{const n=e(i,s);n!==void 0&&(this.value=n)},t)}generate(e,t){const s=this.getNodeType(e),i=this.getUniformHash(e);let n=e.getNodeFromHash(i);n===void 0&&(e.setHashNode(this,i),n=this);const r=n.getInputType(e),o=e.getUniformFromNode(n,r,e.shaderStage,this.name||e.context.label),l=e.getPropertyName(o);return e.context.label!==void 0&&delete e.context.label,e.format(l,s,t)}}const J=(a,e)=>{const t=Ob(e||a),s=a&&a.isNode===!0?a.node&&a.node.value||a.value:a;return k(new wa(s,t))};class Re extends ae{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0,this.global=!0}getHash(e){return this.name||super.getHash(e)}generate(e){let t;return this.varying===!0?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const sg=(a,e)=>k(new Re(a,e)),el=(a,e)=>k(new Re(a,e,!0)),Se=V(Re,"vec4","DiffuseColor"),ip=V(Re,"vec3","EmissiveColor"),Ys=V(Re,"float","Roughness"),tl=V(Re,"float","Metalness"),Oh=V(Re,"float","Clearcoat"),sl=V(Re,"float","ClearcoatRoughness"),qn=V(Re,"vec3","Sheen"),xu=V(Re,"float","SheenRoughness"),_u=V(Re,"float","Iridescence"),ig=V(Re,"float","IridescenceIOR"),ng=V(Re,"float","IridescenceThickness"),Bh=V(Re,"float","AlphaT"),en=V(Re,"float","Anisotropy"),No=V(Re,"vec3","AnisotropyT"),sr=V(Re,"vec3","AnisotropyB"),qt=V(Re,"color","SpecularColor"),il=V(Re,"float","SpecularF90"),Ih=V(Re,"float","Shininess"),la=V(Re,"vec4","Output"),Xl=V(Re,"float","dashSize"),np=V(Re,"float","gapSize"),Po=V(Re,"float","IOR"),Lh=V(Re,"float","Transmission"),rg=V(Re,"float","Thickness"),ag=V(Re,"float","AttenuationDistance"),og=V(Re,"color","AttenuationColor"),lg=V(Re,"float","Dispersion");class Jb extends it{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}getNodeType(e){return this.functionNode.getNodeType(e)}generate(e){const t=[],s=this.functionNode,i=s.getInputs(e),n=this.parameters,r=(l,c)=>{const h=c.type,u=h==="pointer";let d;return u?d="&"+l.build(e):d=l.build(e,h),d};if(Array.isArray(n)){if(n.length>i.length)console.error("THREE.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(console.error("THREE.TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");n.length<i.length;)n.push(B(0));for(let l=0;l<n.length;l++)t.push(r(n[l],i[l]))}else for(const l of i){const c=n[l.name];c!==void 0?t.push(r(c,l)):(console.error(`THREE.TSL: Input '${l.name}' not found in 'Fn()'.`),t.push(r(B(0),l)))}return`${s.build(e,"property")}( ${t.join(", ")} )`}}const eT=(a,...e)=>(e=e.length>1||e[0]&&e[0].isNode===!0?er(e):pl(e[0]),k(new Jb(k(a),e)));O("call",eT);const tT={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class He extends it{static get type(){return"OperatorNode"}constructor(e,t,s,...i){if(super(),i.length>0){let n=new He(e,t,s);for(let r=0;r<i.length-1;r++)n=new He(e,n,i[r]);t=n,s=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=s,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(tT[this.op],t)}getNodeType(e){const t=this.op,s=this.aNode,i=this.bNode,n=s.getNodeType(e),r=i?i.getNodeType(e):null;if(n==="void"||r==="void")return"void";if(t==="%")return n;if(t==="~"||t==="&"||t==="|"||t==="^"||t===">>"||t==="<<")return e.getIntegerType(n);if(t==="!"||t==="&&"||t==="||"||t==="^^")return"bool";if(t==="=="||t==="!="||t==="<"||t===">"||t==="<="||t===">="){const o=Math.max(e.getTypeLength(n),e.getTypeLength(r));return o>1?`bvec${o}`:"bool"}else{if(e.isMatrix(n)){if(r==="float")return n;if(e.isVector(r))return e.getVectorFromMatrix(n);if(e.isMatrix(r))return n}else if(e.isMatrix(r)){if(n==="float")return r;if(e.isVector(n))return e.getVectorFromMatrix(r)}return e.getTypeLength(r)>e.getTypeLength(n)?r:n}}generate(e,t){const s=this.op,{aNode:i,bNode:n}=this,r=this.getNodeType(e);let o=null,l=null;r!=="void"?(o=i.getNodeType(e),l=n?n.getNodeType(e):null,s==="<"||s===">"||s==="<="||s===">="||s==="=="||s==="!="?e.isVector(o)?l=o:e.isVector(l)?o=l:o!==l&&(o=l="float"):s===">>"||s==="<<"?(o=r,l=e.changeComponentType(l,"uint")):s==="%"?(o=r,l=e.isInteger(o)&&e.isInteger(l)?l:o):e.isMatrix(o)?l==="float"?l="float":e.isVector(l)?l=e.getVectorFromMatrix(o):e.isMatrix(l)||(o=l=r):e.isMatrix(l)?o==="float"?o="float":e.isVector(o)?o=e.getVectorFromMatrix(l):o=l=r:o=l=r):o=l=r;const c=i.build(e,o),h=n?n.build(e,l):null,u=e.getFunctionOperator(s);if(t!=="void"){const d=e.renderer.coordinateSystem===Lt;if(s==="=="||s==="!="||s==="<"||s===">"||s==="<="||s===">=")return d?e.isVector(o)?e.format(`${this.getOperatorMethod(e,t)}( ${c}, ${h} )`,r,t):e.format(`( ${c} ${s} ${h} )`,r,t):e.format(`( ${c} ${s} ${h} )`,r,t);if(s==="%")return e.isInteger(l)?e.format(`( ${c} % ${h} )`,r,t):e.format(`${this.getOperatorMethod(e,r)}( ${c}, ${h} )`,r,t);if(s==="!"||s==="~")return e.format(`(${s}${c})`,o,t);if(u)return e.format(`${u}( ${c}, ${h} )`,r,t);if(e.isMatrix(o)&&l==="float")return e.format(`( ${h} ${s} ${c} )`,r,t);if(o==="float"&&e.isMatrix(l))return e.format(`${c} ${s} ${h}`,r,t);{let p=`( ${c} ${s} ${h} )`;return!d&&r==="bool"&&e.isVector(o)&&e.isVector(l)&&(p=`all${p}`),e.format(p,r,t)}}else if(o!=="void")return u?e.format(`${u}( ${c}, ${h} )`,r,t):e.isMatrix(o)&&l==="float"?e.format(`${h} ${s} ${c}`,r,t):e.format(`${c} ${s} ${h}`,r,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Dt=U(He,"+").setParameterLength(2,1/0).setName("add"),Mt=U(He,"-").setParameterLength(2,1/0).setName("sub"),pe=U(He,"*").setParameterLength(2,1/0).setName("mul"),Ls=U(He,"/").setParameterLength(2,1/0).setName("div"),fl=U(He,"%").setParameterLength(2).setName("mod"),cg=U(He,"==").setParameterLength(2).setName("equal"),sT=U(He,"!=").setParameterLength(2).setName("notEqual"),iT=U(He,"<").setParameterLength(2).setName("lessThan"),nT=U(He,">").setParameterLength(2).setName("greaterThan"),rT=U(He,"<=").setParameterLength(2).setName("lessThanEqual"),aT=U(He,">=").setParameterLength(2).setName("greaterThanEqual"),oT=U(He,"&&").setParameterLength(2,1/0).setName("and"),lT=U(He,"||").setParameterLength(2,1/0).setName("or"),cT=U(He,"!").setParameterLength(1).setName("not"),hT=U(He,"^^").setParameterLength(2).setName("xor"),uT=U(He,"&").setParameterLength(2).setName("bitAnd"),dT=U(He,"~").setParameterLength(2).setName("bitNot"),pT=U(He,"|").setParameterLength(2).setName("bitOr"),fT=U(He,"^").setParameterLength(2).setName("bitXor"),mT=U(He,"<<").setParameterLength(2).setName("shiftLeft"),gT=U(He,">>").setParameterLength(2).setName("shiftRight"),yT=L(([a])=>(a.addAssign(1),a)),xT=L(([a])=>(a.subAssign(1),a)),_T=L(([a])=>{const e=Ue(a).toConst();return a.addAssign(1),e}),bT=L(([a])=>{const e=Ue(a).toConst();return a.subAssign(1),e});O("add",Dt);O("sub",Mt);O("mul",pe);O("div",Ls);O("mod",fl);O("equal",cg);O("notEqual",sT);O("lessThan",iT);O("greaterThan",nT);O("lessThanEqual",rT);O("greaterThanEqual",aT);O("and",oT);O("or",lT);O("not",cT);O("xor",hT);O("bitAnd",uT);O("bitNot",dT);O("bitOr",pT);O("bitXor",fT);O("shiftLeft",mT);O("shiftRight",gT);O("incrementBefore",yT);O("decrementBefore",xT);O("increment",_T);O("decrement",bT);const TT=(a,e)=>(console.warn('THREE.TSL: "remainder()" is deprecated. Use "mod( int( ... ) )" instead.'),fl(a,e)),ST=(a,e)=>(console.warn('THREE.TSL: "modInt()" is deprecated. Use "mod( int( ... ) )" instead.'),fl(Ue(a),Ue(e)));O("remainder",TT);O("modInt",ST);class A extends it{static get type(){return"MathNode"}constructor(e,t,s=null,i=null){if(super(),(e===A.MAX||e===A.MIN)&&arguments.length>3){let n=new A(e,t,s);for(let r=2;r<arguments.length-1;r++)n=new A(e,n,arguments[r]);t=n,s=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=s,this.cNode=i,this.isMathNode=!0}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),r=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(i)?0:e.getTypeLength(i);return n>r&&n>o?t:r>o?s:o>n?i:t}getNodeType(e){const t=this.method;return t===A.LENGTH||t===A.DISTANCE||t===A.DOT?"float":t===A.CROSS?"vec3":t===A.ALL||t===A.ANY?"bool":t===A.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){const{aNode:t,bNode:s,method:i}=this;let n=null;if(i===A.ONE_MINUS)n=Mt(1,t);else if(i===A.RECIPROCAL)n=Ls(1,t);else if(i===A.DIFFERENCE)n=is(Mt(t,s));else if(i===A.TRANSFORM_DIRECTION){let r=t,o=s;e.isMatrix(r.getNodeType(e))?o=re(I(o),0):r=re(I(r),0);const l=pe(r,o).xyz;n=_a(l)}return n!==null?n:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let i=this.method;const n=this.getNodeType(e),r=this.getInputType(e),o=this.aNode,l=this.bNode,c=this.cNode,h=e.renderer.coordinateSystem;if(i===A.NEGATE)return e.format("( - "+o.build(e,r)+" )",n,t);{const u=[];return i===A.CROSS?u.push(o.build(e,n),l.build(e,n)):h===Lt&&i===A.STEP?u.push(o.build(e,e.getTypeLength(o.getNodeType(e))===1?"float":r),l.build(e,r)):h===Lt&&(i===A.MIN||i===A.MAX)?u.push(o.build(e,r),l.build(e,e.getTypeLength(l.getNodeType(e))===1?"float":r)):i===A.REFRACT?u.push(o.build(e,r),l.build(e,r),c.build(e,"float")):i===A.MIX?u.push(o.build(e,r),l.build(e,r),c.build(e,e.getTypeLength(c.getNodeType(e))===1?"float":r)):(h===Fi&&i===A.ATAN&&l!==null&&(i="atan2"),e.shaderStage!=="fragment"&&(i===A.DFDX||i===A.DFDY)&&(console.warn(`THREE.TSL: '${i}' is not supported in the ${e.shaderStage} stage.`),i="/*"+i+"*/"),u.push(o.build(e,r)),l!==null&&u.push(l.build(e,r)),c!==null&&u.push(c.build(e,r))),e.format(`${e.getMethod(i,n)}( ${u.join(", ")} )`,n,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}A.ALL="all";A.ANY="any";A.RADIANS="radians";A.DEGREES="degrees";A.EXP="exp";A.EXP2="exp2";A.LOG="log";A.LOG2="log2";A.SQRT="sqrt";A.INVERSE_SQRT="inversesqrt";A.FLOOR="floor";A.CEIL="ceil";A.NORMALIZE="normalize";A.FRACT="fract";A.SIN="sin";A.COS="cos";A.TAN="tan";A.ASIN="asin";A.ACOS="acos";A.ATAN="atan";A.ABS="abs";A.SIGN="sign";A.LENGTH="length";A.NEGATE="negate";A.ONE_MINUS="oneMinus";A.DFDX="dFdx";A.DFDY="dFdy";A.ROUND="round";A.RECIPROCAL="reciprocal";A.TRUNC="trunc";A.FWIDTH="fwidth";A.TRANSPOSE="transpose";A.BITCAST="bitcast";A.EQUALS="equals";A.MIN="min";A.MAX="max";A.STEP="step";A.REFLECT="reflect";A.DISTANCE="distance";A.DIFFERENCE="difference";A.DOT="dot";A.CROSS="cross";A.POW="pow";A.TRANSFORM_DIRECTION="transformDirection";A.MIX="mix";A.CLAMP="clamp";A.REFRACT="refract";A.SMOOTHSTEP="smoothstep";A.FACEFORWARD="faceforward";const vT=B(1e-6),wT=B(Math.PI),ET=U(A,A.ALL).setParameterLength(1),CT=U(A,A.ANY).setParameterLength(1),MT=U(A,A.RADIANS).setParameterLength(1),AT=U(A,A.DEGREES).setParameterLength(1),hg=U(A,A.EXP).setParameterLength(1),xa=U(A,A.EXP2).setParameterLength(1),ug=U(A,A.LOG).setParameterLength(1),si=U(A,A.LOG2).setParameterLength(1),bu=U(A,A.SQRT).setParameterLength(1),RT=U(A,A.INVERSE_SQRT).setParameterLength(1),hn=U(A,A.FLOOR).setParameterLength(1),Tu=U(A,A.CEIL).setParameterLength(1),_a=U(A,A.NORMALIZE).setParameterLength(1),Li=U(A,A.FRACT).setParameterLength(1),xs=U(A,A.SIN).setParameterLength(1),vi=U(A,A.COS).setParameterLength(1),NT=U(A,A.TAN).setParameterLength(1),PT=U(A,A.ASIN).setParameterLength(1),dg=U(A,A.ACOS).setParameterLength(1),pg=U(A,A.ATAN).setParameterLength(1,2),is=U(A,A.ABS).setParameterLength(1),nl=U(A,A.SIGN).setParameterLength(1),ii=U(A,A.LENGTH).setParameterLength(1),DT=U(A,A.NEGATE).setParameterLength(1),FT=U(A,A.ONE_MINUS).setParameterLength(1),fg=U(A,A.DFDX).setParameterLength(1),mg=U(A,A.DFDY).setParameterLength(1),OT=U(A,A.ROUND).setParameterLength(1),BT=U(A,A.RECIPROCAL).setParameterLength(1),IT=U(A,A.TRUNC).setParameterLength(1),LT=U(A,A.FWIDTH).setParameterLength(1),UT=U(A,A.TRANSPOSE).setParameterLength(1),kT=(a,e)=>(console.warn('THREE.TSL: "equals" is deprecated. Use "equal" inside a vector instead, like: "bvec*( equal( ... ) )"'),cg(a,e)),ur=U(A,A.MIN).setParameterLength(2,1/0),St=U(A,A.MAX).setParameterLength(2,1/0),gg=U(A,A.STEP).setParameterLength(2),zT=U(A,A.REFLECT).setParameterLength(2),GT=U(A,A.DISTANCE).setParameterLength(2),VT=U(A,A.DIFFERENCE).setParameterLength(2),Su=U(A,A.DOT).setParameterLength(2),yg=U(A,A.CROSS).setParameterLength(2),ml=U(A,A.POW).setParameterLength(2),xg=U(A,A.POW,2).setParameterLength(1),HT=U(A,A.POW,3).setParameterLength(1),WT=U(A,A.POW,4).setParameterLength(1),$T=U(A,A.TRANSFORM_DIRECTION).setParameterLength(2),jT=a=>pe(nl(a),ml(is(a),1/3)),_g=a=>Su(a,a),ze=U(A,A.MIX).setParameterLength(3),ai=(a,e=0,t=1)=>k(new A(A.CLAMP,k(a),k(e),k(t))),bg=a=>ai(a),Tg=U(A,A.REFRACT).setParameterLength(3),Oi=U(A,A.SMOOTHSTEP).setParameterLength(3),qT=U(A,A.FACEFORWARD).setParameterLength(3),YT=L(([a])=>{const s=43758.5453,i=Su(a.xy,H(12.9898,78.233)),n=fl(i,wT);return Li(xs(n).mul(s))}),XT=(a,e,t)=>ze(e,t,a),ZT=(a,e,t)=>Oi(e,t,a),QT=(a,e)=>(console.warn('THREE.TSL: "atan2" is overloaded. Use "atan" instead.'),pg(a,e));O("all",ET);O("any",CT);O("equals",kT);O("radians",MT);O("degrees",AT);O("exp",hg);O("exp2",xa);O("log",ug);O("log2",si);O("sqrt",bu);O("inverseSqrt",RT);O("floor",hn);O("ceil",Tu);O("normalize",_a);O("fract",Li);O("sin",xs);O("cos",vi);O("tan",NT);O("asin",PT);O("acos",dg);O("atan",pg);O("abs",is);O("sign",nl);O("length",ii);O("lengthSq",_g);O("negate",DT);O("oneMinus",FT);O("dFdx",fg);O("dFdy",mg);O("round",OT);O("reciprocal",BT);O("trunc",IT);O("fwidth",LT);O("atan2",QT);O("min",ur);O("max",St);O("step",gg);O("reflect",zT);O("distance",GT);O("dot",Su);O("cross",yg);O("pow",ml);O("pow2",xg);O("pow3",HT);O("pow4",WT);O("transformDirection",$T);O("mix",XT);O("clamp",ai);O("refract",Tg);O("smoothstep",ZT);O("faceForward",qT);O("difference",VT);O("saturate",bg);O("cbrt",jT);O("transpose",UT);O("rand",YT);class KT extends ae{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const{ifNode:t,elseNode:s}=e.getNodeProperties(this);if(t===void 0)return this.setup(e),this.getNodeType(e);const i=t.getNodeType(e);if(s!==null){const n=s.getNodeType(e);if(e.getTypeLength(n)>e.getTypeLength(i))return n}return i}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,i!==null&&(e.getDataFromNode(i).parentNodeBlock=n);const r=e.getNodeProperties(this);r.condNode=t,r.ifNode=s.context({nodeBlock:s}),r.elseNode=i?i.context({nodeBlock:i}):null}generate(e,t){const s=this.getNodeType(e),i=e.getDataFromNode(this);if(i.nodeProperty!==void 0)return i.nodeProperty;const{condNode:n,ifNode:r,elseNode:o}=e.getNodeProperties(this),l=e.currentFunctionNode,c=t!=="void",h=c?sg(s).build(e):"";i.nodeProperty=h;const u=n.build(e,"bool");e.addFlowCode(`
51
51
  ${e.tab}if ( ${u} ) {
52
52