@tomorrowevening/hermes 0.1.36 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var Pi=Object.create;var At=Object.defineProperty;var Di=Object.getOwnPropertyDescriptor;var Ii=Object.getOwnPropertyNames;var Li=Object.getPrototypeOf,Ui=Object.prototype.hasOwnProperty;var ki=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ii(e))!Ui.call(i,n)&&n!==t&&At(i,n,{get:()=>e[n],enumerable:!(s=Di(e,n))||s.enumerable});return i};var Ni=(i,e,t)=>(t=i!=null?Pi(Li(i)):{},ki(e||!i||!i.__esModule?At(t,"default",{value:i,enumerable:!0}):t,i));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@tomorrowevening/theatre-core"),b=require("react"),m=require("three"),w=require("three/webgpu"),d=require("react/jsx-runtime"),$=require("three/src/math/MathUtils.js"),Fi=require("three/examples/jsm/helpers/RectAreaLightHelper.js"),ji=require("three/examples/jsm/controls/OrbitControls.js"),R=require("three/tsl"),Kt=require("three/src/materials/nodes/MeshBasicNodeMaterial.js"),je=require("three/src/nodes/TSL.js"),zi=require("three/examples/jsm/controls/TransformControls.js"),ze=()=>{},Hi=()=>{};function He(i){return i.substring(0,1).toUpperCase()+i.substring(1)}function Xt(i){const e=JSON.stringify(i);return navigator.clipboard.writeText(e),e}function Y(){return Math.round(Math.random()*1e6).toString()}function Qt(i){return i.r!==void 0&&i.g!==void 0&&i.b!==void 0}function vt(i){const e=Math.round(i.r*255),t=Math.round(i.g*255),s=Math.round(i.b*255),n=c=>{const l=c.toString(16);return l.length===1?"0"+l:l},r=n(e),a=n(t),o=n(s);return"#"+r+a+o}function st(i,e,t,s){return new(t||(t=Promise))(function(n,r){function a(l){try{c(s.next(l))}catch(h){r(h)}}function o(l){try{c(s.throw(l))}catch(h){r(h)}}function c(l){var h;l.done?n(l.value):(h=l.value,h instanceof t?h:new t(function(u){u(h)})).then(a,o)}c((s=s.apply(i,[])).next())})}const Bi=["geforce 320m","geforce 8600","geforce 8600m gt","geforce 8800 gs","geforce 8800 gt","geforce 9400","geforce 9400m g","geforce 9400m","geforce 9600m gt","geforce 9600m","geforce fx go5200","geforce gt 120","geforce gt 130","geforce gt 330m","geforce gtx 285","google swiftshader","intel g41","intel g45","intel gma 4500mhd","intel gma x3100","intel hd 3000","intel q45","legacy","mali-2","mali-3","mali-4","quadro fx 1500","quadro fx 4","quadro fx 5","radeon hd 2400","radeon hd 2600","radeon hd 4670","radeon hd 4850","radeon hd 4870","radeon hd 5670","radeon hd 5750","radeon hd 6290","radeon hd 6300","radeon hd 6310","radeon hd 6320","radeon hd 6490m","radeon hd 6630m","radeon hd 6750m","radeon hd 6770m","radeon hd 6970m","sgx 543","sgx543"];function Rt(i){return i=i.toLowerCase().replace(/.*angle ?\((.+)\)(?: on vulkan [0-9.]+)?$/i,"$1").replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g,"").replace(/(?:vulkan|opengl) \d+\.\d+(?:\.\d+)?(?: \((.*)\))?/,"$1")}const Jt=typeof window>"u",ne=(()=>{if(Jt)return;const{userAgent:i,platform:e,maxTouchPoints:t}=window.navigator,s=/(iphone|ipod|ipad)/i.test(i),n=e==="iPad"||e==="MacIntel"&&t>0&&!window.MSStream;return{isIpad:n,isMobile:/android/i.test(i)||s||n,isSafari12:/Version\/12.+Safari/.test(i),isFirefox:/Firefox/.test(i)}})();function Vi(i,e,t){if(!t)return[e];const s=function(l){const h=`
1
+ "use strict";var Ri=Object.create;var At=Object.defineProperty;var Pi=Object.getOwnPropertyDescriptor;var Di=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Li=Object.prototype.hasOwnProperty;var Ui=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Di(e))!Li.call(i,n)&&n!==t&&At(i,n,{get:()=>e[n],enumerable:!(s=Pi(e,n))||s.enumerable});return i};var ki=(i,e,t)=>(t=i!=null?Ri(Ii(i)):{},Ui(e||!i||!i.__esModule?At(t,"default",{value:i,enumerable:!0}):t,i));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@tomorrowevening/theatre-core"),b=require("react"),m=require("three"),w=require("three/webgpu"),d=require("react/jsx-runtime"),$=require("three/src/math/MathUtils.js"),Ni=require("three/examples/jsm/helpers/RectAreaLightHelper.js"),Fi=require("three/examples/jsm/controls/OrbitControls.js"),R=require("three/tsl"),Kt=require("three/src/materials/nodes/MeshBasicNodeMaterial.js"),je=require("three/src/nodes/TSL.js"),ji=require("three/examples/jsm/controls/TransformControls.js"),ze=()=>{},zi=()=>{};function He(i){return i.substring(0,1).toUpperCase()+i.substring(1)}function Xt(i){const e=JSON.stringify(i);return navigator.clipboard.writeText(e),e}function Y(){return Math.round(Math.random()*1e6).toString()}function Qt(i){return i.r!==void 0&&i.g!==void 0&&i.b!==void 0}function vt(i){const e=Math.round(i.r*255),t=Math.round(i.g*255),s=Math.round(i.b*255),n=c=>{const l=c.toString(16);return l.length===1?"0"+l:l},r=n(e),a=n(t),o=n(s);return"#"+r+a+o}function st(i,e,t,s){return new(t||(t=Promise))(function(n,r){function a(l){try{c(s.next(l))}catch(h){r(h)}}function o(l){try{c(s.throw(l))}catch(h){r(h)}}function c(l){var h;l.done?n(l.value):(h=l.value,h instanceof t?h:new t(function(u){u(h)})).then(a,o)}c((s=s.apply(i,[])).next())})}const Hi=["geforce 320m","geforce 8600","geforce 8600m gt","geforce 8800 gs","geforce 8800 gt","geforce 9400","geforce 9400m g","geforce 9400m","geforce 9600m gt","geforce 9600m","geforce fx go5200","geforce gt 120","geforce gt 130","geforce gt 330m","geforce gtx 285","google swiftshader","intel g41","intel g45","intel gma 4500mhd","intel gma x3100","intel hd 3000","intel q45","legacy","mali-2","mali-3","mali-4","quadro fx 1500","quadro fx 4","quadro fx 5","radeon hd 2400","radeon hd 2600","radeon hd 4670","radeon hd 4850","radeon hd 4870","radeon hd 5670","radeon hd 5750","radeon hd 6290","radeon hd 6300","radeon hd 6310","radeon hd 6320","radeon hd 6490m","radeon hd 6630m","radeon hd 6750m","radeon hd 6770m","radeon hd 6970m","sgx 543","sgx543"];function Rt(i){return i=i.toLowerCase().replace(/.*angle ?\((.+)\)(?: on vulkan [0-9.]+)?$/i,"$1").replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g,"").replace(/(?:vulkan|opengl) \d+\.\d+(?:\.\d+)?(?: \((.*)\))?/,"$1")}const Jt=typeof window>"u",ne=(()=>{if(Jt)return;const{userAgent:i,platform:e,maxTouchPoints:t}=window.navigator,s=/(iphone|ipod|ipad)/i.test(i),n=e==="iPad"||e==="MacIntel"&&t>0&&!window.MSStream;return{isIpad:n,isMobile:/android/i.test(i)||s||n,isSafari12:/Version\/12.+Safari/.test(i),isFirefox:/Firefox/.test(i)}})();function Bi(i,e,t){if(!t)return[e];const s=function(l){const h=`
2
2
  precision highp float;
3
3
  attribute vec3 aPosition;
4
4
  varying float vvv;
@@ -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
- `,p=l.createShader(35633),g=l.createShader(35632),C=l.createProgram();if(!(g&&p&&C))return;l.shaderSource(p,h),l.shaderSource(g,u),l.compileShader(p),l.compileShader(g),l.attachShader(C,p),l.attachShader(C,g),l.linkProgram(C),l.detachShader(C,p),l.detachShader(C,g),l.deleteShader(p),l.deleteShader(g),l.useProgram(C);const _=l.createBuffer();l.bindBuffer(34962,_),l.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const E=l.getAttribLocation(C,"aPosition");l.vertexAttribPointer(E,3,5126,!1,0,0),l.enableVertexAttribArray(E),l.clearColor(1,1,1,1),l.clear(16384),l.viewport(0,0,1,1),l.drawArrays(4,0,3);const v=new Uint8Array(4);return l.readPixels(0,0,1,1,6408,5121,v),l.deleteProgram(C),l.deleteBuffer(_),v.join("")}(i),n="801621810",r="8016218135",a="80162181161",o=ne?.isIpad?[["a7",a,12],["a8",r,15],["a8x",r,15],["a9",r,15],["a9x",r,15],["a10",r,15],["a10x",r,15],["a12",n,15],["a12x",n,15],["a12z",n,15],["a14",n,15],["a15",n,15],["m1",n,15],["m2",n,15]]:[["a7",a,12],["a8",r,12],["a9",r,15],["a10",r,15],["a11",n,15],["a12",n,15],["a13",n,15],["a14",n,15],["a15",n,15],["a16",n,15],["a17",n,15]];let c;return s==="80162181255"?c=o.filter(([,,l])=>l>=14):(c=o.filter(([,l])=>l===s),c.length||(c=o)),c.map(([l])=>`apple ${l} gpu`)}class Pt extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}const nt=[],Dt=[];function Gi(i,e){if(i===e)return 0;const t=i;i.length>e.length&&(i=e,e=t);let s=i.length,n=e.length;for(;s>0&&i.charCodeAt(~-s)===e.charCodeAt(~-n);)s--,n--;let r,a=0;for(;a<s&&i.charCodeAt(a)===e.charCodeAt(a);)a++;if(s-=a,n-=a,s===0)return n;let o,c,l=0,h=0,u=0;for(;h<s;)Dt[h]=i.charCodeAt(a+h),nt[h]=++h;for(;u<n;)for(r=e.charCodeAt(a+u),o=u++,l=u,h=0;h<s;h++)c=r===Dt[h]?o:o+1,o=nt[h],l=nt[h]=o>l?c>l?l+1:c:c>o?o+1:c;return l}function Wi(i){return i!=null}const Yi=({mobileTiers:i=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:t={},glContext:s,failIfMajorPerformanceCaveat:n=!1,benchmarksURL:r="https://unpkg.com/detect-gpu@5.0.70/dist/benchmarks"}={})=>st(void 0,void 0,void 0,function*(){const a={};if(Jt)return{tier:0,type:"SSR"};const{isIpad:o=!!ne?.isIpad,isMobile:c=!!ne?.isMobile,screenSize:l=window.screen,loadBenchmarks:h=S=>st(void 0,void 0,void 0,function*(){const T=yield fetch(`${r}/${S}`).then(M=>M.json());if(parseInt(T.shift().split(".")[0],10)<4)throw new Pt("Detect GPU benchmark data is out of date. Please update to version 4x");return T})}=t;let{renderer:u}=t;const p=(S,T,M,U,A)=>({device:A,fps:U,gpu:M,isMobile:c,tier:S,type:T});let g,C="";if(u)u=Rt(u),g=[u];else{const S=s||function(M,U=!1){const A={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:U,powerPreference:"high-performance",stencil:!1};M&&delete A.powerPreference;const j=window.document.createElement("canvas"),ee=j.getContext("webgl",A)||j.getContext("experimental-webgl",A);return ee??void 0}(ne?.isSafari12,n);if(!S)return p(0,"WEBGL_UNSUPPORTED");const T=ne?.isFirefox?null:S.getExtension("WEBGL_debug_renderer_info");if(u=T?S.getParameter(T.UNMASKED_RENDERER_WEBGL):S.getParameter(S.RENDERER),!u)return p(1,"FALLBACK");C=u,u=Rt(u),g=function(M,U,A){return U==="apple gpu"?Vi(M,U,A):[U]}(S,u,c)}const _=(yield Promise.all(g.map(function(S){var T;return st(this,void 0,void 0,function*(){const M=(B=>{const Z=c?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce","adreno"];for(const le of Z)if(B.includes(le))return le})(S);if(!M)return;const U=`${c?"m":"d"}-${M}${o?"-ipad":""}.json`,A=a[U]=(T=a[U])!==null&&T!==void 0?T:h(U);let j;try{j=yield A}catch(B){if(B instanceof Pt)throw B;return}const ee=function(B){var Z;const le=(B=B.replace(/\([^)]+\)/,"")).match(/\d+/)||B.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return(Z=le?.join("").replace(/\W|amd/g,""))!==null&&Z!==void 0?Z:""}(S);let oe=j.filter(([,B])=>B===ee);oe.length||(oe=j.filter(([B])=>B.includes(S)));const ue=oe.length;if(ue===0)return;const _e=S.split(/[.,()\[\]/\s]/g).sort().filter((B,Z,le)=>Z===0||B!==le[Z-1]).join(" ");let pe,[Oi,,,,wi]=ue>1?oe.map(B=>[B,Gi(_e,B[2])]).sort(([,B],[,Z])=>B-Z)[0][0]:oe[0],it=Number.MAX_VALUE;const{devicePixelRatio:Tt}=window,Ti=l.width*Tt*l.height*Tt;for(const B of wi){const[Z,le]=B,Ri=Z*le,Mt=Math.abs(Ti-Ri);Mt<it&&(it=Mt,pe=B)}if(!pe)return;const[,,Mi,Ai]=pe;return[it,Mi,Oi,Ai]})}))).filter(Wi).sort(([S=Number.MAX_VALUE,T],[M=Number.MAX_VALUE,U])=>S===M?T-U:S-M);if(!_.length){const S=Bi.find(T=>u.includes(T));return S?p(0,"BLOCKLISTED",S):p(1,"FALLBACK",`${u} (${C})`)}const[,E,v,y]=_[0];if(E===-1)return p(0,"BLOCKLISTED",v,E,y);const x=c?i:e;let O=0;for(let S=0;S<x.length;S++)E>=x[S]&&(O=S);return p(O,"BENCHMARK",v,E,y)});function ei(i){let e=0;const t=performance.now();function s(){e++;const n=performance.now();if(n-t>=100){const r=e/((n-t)/1e3),a=Math.round(r/30)*30;i(a)}else requestAnimationFrame(s)}requestAnimationFrame(s)}function ti(i=!1,e=!1){return new Promise(t=>{Yi().then(s=>{let n=!1;const r=document.createElement("canvas"),a=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(n="transferControlToOffscreen"in r,a){const c=navigator.userAgent.match(/version\/(\d+)/i);n=(c?parseInt(c[1]):0)>=17}const o={dpr:devicePixelRatio,fps:30,width:innerWidth,height:innerHeight,mobile:s.isMobile!==void 0?s.isMobile:!1,supportOffScreenCanvas:n,supportWebGPU:!!navigator.gpu,quality:"Low",dev:i,editor:e};s.tier===3?o.quality="High":s.tier===2&&(o.quality="Medium"),ei(c=>{o.fps=c,t(o)})})})}const qi=`
18
+ `,p=l.createShader(35633),g=l.createShader(35632),C=l.createProgram();if(!(g&&p&&C))return;l.shaderSource(p,h),l.shaderSource(g,u),l.compileShader(p),l.compileShader(g),l.attachShader(C,p),l.attachShader(C,g),l.linkProgram(C),l.detachShader(C,p),l.detachShader(C,g),l.deleteShader(p),l.deleteShader(g),l.useProgram(C);const _=l.createBuffer();l.bindBuffer(34962,_),l.bufferData(34962,new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),35044);const E=l.getAttribLocation(C,"aPosition");l.vertexAttribPointer(E,3,5126,!1,0,0),l.enableVertexAttribArray(E),l.clearColor(1,1,1,1),l.clear(16384),l.viewport(0,0,1,1),l.drawArrays(4,0,3);const v=new Uint8Array(4);return l.readPixels(0,0,1,1,6408,5121,v),l.deleteProgram(C),l.deleteBuffer(_),v.join("")}(i),n="801621810",r="8016218135",a="80162181161",o=ne?.isIpad?[["a7",a,12],["a8",r,15],["a8x",r,15],["a9",r,15],["a9x",r,15],["a10",r,15],["a10x",r,15],["a12",n,15],["a12x",n,15],["a12z",n,15],["a14",n,15],["a15",n,15],["m1",n,15],["m2",n,15]]:[["a7",a,12],["a8",r,12],["a9",r,15],["a10",r,15],["a11",n,15],["a12",n,15],["a13",n,15],["a14",n,15],["a15",n,15],["a16",n,15],["a17",n,15]];let c;return s==="80162181255"?c=o.filter(([,,l])=>l>=14):(c=o.filter(([,l])=>l===s),c.length||(c=o)),c.map(([l])=>`apple ${l} gpu`)}class Pt extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}const nt=[],Dt=[];function Vi(i,e){if(i===e)return 0;const t=i;i.length>e.length&&(i=e,e=t);let s=i.length,n=e.length;for(;s>0&&i.charCodeAt(~-s)===e.charCodeAt(~-n);)s--,n--;let r,a=0;for(;a<s&&i.charCodeAt(a)===e.charCodeAt(a);)a++;if(s-=a,n-=a,s===0)return n;let o,c,l=0,h=0,u=0;for(;h<s;)Dt[h]=i.charCodeAt(a+h),nt[h]=++h;for(;u<n;)for(r=e.charCodeAt(a+u),o=u++,l=u,h=0;h<s;h++)c=r===Dt[h]?o:o+1,o=nt[h],l=nt[h]=o>l?c>l?l+1:c:c>o?o+1:c;return l}function Gi(i){return i!=null}const Wi=({mobileTiers:i=[0,15,30,60],desktopTiers:e=[0,15,30,60],override:t={},glContext:s,failIfMajorPerformanceCaveat:n=!1,benchmarksURL:r="https://unpkg.com/detect-gpu@5.0.70/dist/benchmarks"}={})=>st(void 0,void 0,void 0,function*(){const a={};if(Jt)return{tier:0,type:"SSR"};const{isIpad:o=!!ne?.isIpad,isMobile:c=!!ne?.isMobile,screenSize:l=window.screen,loadBenchmarks:h=S=>st(void 0,void 0,void 0,function*(){const T=yield fetch(`${r}/${S}`).then(M=>M.json());if(parseInt(T.shift().split(".")[0],10)<4)throw new Pt("Detect GPU benchmark data is out of date. Please update to version 4x");return T})}=t;let{renderer:u}=t;const p=(S,T,M,U,A)=>({device:A,fps:U,gpu:M,isMobile:c,tier:S,type:T});let g,C="";if(u)u=Rt(u),g=[u];else{const S=s||function(M,U=!1){const A={alpha:!1,antialias:!1,depth:!1,failIfMajorPerformanceCaveat:U,powerPreference:"high-performance",stencil:!1};M&&delete A.powerPreference;const j=window.document.createElement("canvas"),ee=j.getContext("webgl",A)||j.getContext("experimental-webgl",A);return ee??void 0}(ne?.isSafari12,n);if(!S)return p(0,"WEBGL_UNSUPPORTED");const T=ne?.isFirefox?null:S.getExtension("WEBGL_debug_renderer_info");if(u=T?S.getParameter(T.UNMASKED_RENDERER_WEBGL):S.getParameter(S.RENDERER),!u)return p(1,"FALLBACK");C=u,u=Rt(u),g=function(M,U,A){return U==="apple gpu"?Bi(M,U,A):[U]}(S,u,c)}const _=(yield Promise.all(g.map(function(S){var T;return st(this,void 0,void 0,function*(){const M=(B=>{const Z=c?["adreno","apple","mali-t","mali","nvidia","powervr","samsung"]:["intel","apple","amd","radeon","nvidia","geforce","adreno"];for(const le of Z)if(B.includes(le))return le})(S);if(!M)return;const U=`${c?"m":"d"}-${M}${o?"-ipad":""}.json`,A=a[U]=(T=a[U])!==null&&T!==void 0?T:h(U);let j;try{j=yield A}catch(B){if(B instanceof Pt)throw B;return}const ee=function(B){var Z;const le=(B=B.replace(/\([^)]+\)/,"")).match(/\d+/)||B.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);return(Z=le?.join("").replace(/\W|amd/g,""))!==null&&Z!==void 0?Z:""}(S);let oe=j.filter(([,B])=>B===ee);oe.length||(oe=j.filter(([B])=>B.includes(S)));const ue=oe.length;if(ue===0)return;const _e=S.split(/[.,()\[\]/\s]/g).sort().filter((B,Z,le)=>Z===0||B!==le[Z-1]).join(" ");let pe,[xi,,,,Oi]=ue>1?oe.map(B=>[B,Vi(_e,B[2])]).sort(([,B],[,Z])=>B-Z)[0][0]:oe[0],it=Number.MAX_VALUE;const{devicePixelRatio:Tt}=window,wi=l.width*Tt*l.height*Tt;for(const B of Oi){const[Z,le]=B,Ai=Z*le,Mt=Math.abs(wi-Ai);Mt<it&&(it=Mt,pe=B)}if(!pe)return;const[,,Ti,Mi]=pe;return[it,Ti,xi,Mi]})}))).filter(Gi).sort(([S=Number.MAX_VALUE,T],[M=Number.MAX_VALUE,U])=>S===M?T-U:S-M);if(!_.length){const S=Hi.find(T=>u.includes(T));return S?p(0,"BLOCKLISTED",S):p(1,"FALLBACK",`${u} (${C})`)}const[,E,v,y]=_[0];if(E===-1)return p(0,"BLOCKLISTED",v,E,y);const x=c?i:e;let O=0;for(let S=0;S<x.length;S++)E>=x[S]&&(O=S);return p(O,"BENCHMARK",v,E,y)});function ei(i){let e=0;const t=performance.now();function s(){e++;const n=performance.now();if(n-t>=100){const r=e/((n-t)/1e3),a=Math.round(r/30)*30;i(a)}else requestAnimationFrame(s)}requestAnimationFrame(s)}function ti(i=!1,e=!1){return new Promise(t=>{Wi().then(s=>{let n=!1;const r=document.createElement("canvas"),a=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(n="transferControlToOffscreen"in r,a){const c=navigator.userAgent.match(/version\/(\d+)/i);n=(c?parseInt(c[1]):0)>=17}const o={dpr:devicePixelRatio,fps:30,width:innerWidth,height:innerHeight,mobile:s.isMobile!==void 0?s.isMobile:!1,supportOffScreenCanvas:n,supportWebGPU:!!navigator.gpu,quality:"Low",dev:i,editor:e};s.tier===3?o.quality="High":s.tier===2&&(o.quality="Medium"),ei(c=>{o.fps=c,t(o)})})})}const Yi=`
19
19
  self.onmessage = async ({ data }) => {
20
20
  if (data.type !== 'encode') return;
21
21
  const { bitmap, index, format, quality } = data;
@@ -27,15 +27,15 @@ self.onmessage = async ({ data }) => {
27
27
  const blob = await canvas.convertToBlob({ type: mime, quality });
28
28
  self.postMessage({ type: 'encoded', index, blob });
29
29
  };
30
- `;class $i{worker;source;transfer;ctx;opts;_capturing=!1;_captured=0;_encoded=0;_pending=0;_lastFrameTime=-1/0;frames=new Map;constructor(e,t={}){this.source=e,this.transfer=document.createElement("canvas"),this.transfer.width=e.width,this.transfer.height=e.height,this.ctx=this.transfer.getContext("2d",{willReadFrequently:!0}),this.opts={format:t.format??"png",quality:t.quality??.92,prefix:t.prefix??"frame",padLength:t.padLength??5,maxQueue:t.maxQueue??32,fps:t.fps??30,onProgress:t.onProgress??(()=>{}),onError:t.onError??(r=>console.error("[ImageSequenceCapturer]",r))};const s=new Blob([qi],{type:"application/javascript"}),n=URL.createObjectURL(s);this.worker=new Worker(n),URL.revokeObjectURL(n),this.worker.onmessage=({data:r})=>{r.type==="encoded"&&(this.frames.set(r.index,r.blob),this._pending--,this._encoded++,this.opts.onProgress(this._captured,this._encoded))},this.worker.onerror=r=>this.opts.onError(new Error(r.message))}get isCapturing(){return this._capturing}get framesCaptured(){return this._captured}get framesEncoded(){return this._encoded}get isIdle(){return this._pending===0}resize(){this.transfer.width=this.source.width,this.transfer.height=this.source.height}start(){this._capturing=!0,this._captured=0,this._encoded=0,this._pending=0,this._lastFrameTime=-1/0,this.frames.clear()}stop(){this._capturing=!1}captureFrame(){if(!this._capturing||this._pending>=this.opts.maxQueue)return!1;const e=performance.now();if(e-this._lastFrameTime<1e3/this.opts.fps)return!1;this._lastFrameTime=e,this.ctx.drawImage(this.source,0,0);const t=this._captured++;return this._pending++,createImageBitmap(this.transfer).then(s=>{this.worker.postMessage({type:"encode",bitmap:s,index:t,format:this.opts.format,quality:this.opts.quality},[s])}).catch(s=>{this._pending--,this.opts.onError(s)}),!0}flush(){return new Promise(e=>{const t=()=>this._pending===0?e():setTimeout(t,16);t()})}async download(){await this.flush();const e=this.opts.format==="jpeg"?"jpg":this.opts.format,s=[...this.frames.entries()].sort(([n],[r])=>n-r).map(([n,r])=>({name:`${this.opts.prefix}_${String(n).padStart(this.opts.padLength,"0")}.${e}`,blob:r}));if("showDirectoryPicker"in window)try{const n=await window.showDirectoryPicker({mode:"readwrite",startIn:"downloads"});await Promise.all(s.map(async({name:r,blob:a})=>{const c=await(await n.getFileHandle(r,{create:!0})).createWritable();await c.write(a),await c.close()}));return}catch(n){if(n.name==="AbortError")return}for(const{name:n,blob:r}of s){const a=URL.createObjectURL(r);Object.assign(document.createElement("a"),{href:a,download:n}).click(),URL.revokeObjectURL(a),await new Promise(c=>setTimeout(c,50))}}reset(){this._capturing=!1,this._captured=0,this._encoded=0,this._pending=0,this.frames.clear()}destroy(){this.reset(),this.worker.terminate()}}function de(i,e,t){return Math.min(e,Math.max(i,t))}function Xe(i,e,t){return(t-i)/(e-i)}function Re(i,e,t){return i*(1-t)+e*t}function Zi(i,e,t,s,n){return Re(t,s,Xe(i,e,n))}function Ki(i,e){const t=i-e;return Math.sqrt(t*t)}function Xi(i,e,t,s){return Re(i,e,1-Math.exp(-t*s))}function X(i,e=1){return Number(i.toFixed(e))}function Qi(i,e,t,s){return Math.atan2(s-e,t-i)}function Ji(i,e,t,s){return i===e&&t===s}function es(i,e,t,s){return 1/(3*e*i*i+2*t*i+s)}function ts(i,e,t,s,n){return e*(i*i*i)+t*(i*i)+s*i+n}function is(i,e,t,s,n){const r=i*i;return e*(r*i)+t*r+s*i+n}function ss(i,e,t,s,n){if(i<=0)return 0;if(i>=1)return 1;if(Ji(e,t,s,n))return i;const r=0,a=0,o=e,c=t,l=s,h=n,u=1,p=1,g=u-3*l+3*o-r,C=3*l-6*o+3*r,_=3*o-3*r,E=r,v=p-3*h+3*c-a,y=3*h-6*c+3*a,x=3*c-3*a,O=a;let S=i;for(let T=0;T<5;T++){const M=ts(S,g,C,_,E);let U=es(S,g,C,_);U===1/0&&(U=i),S-=(M-i)*U,S=Math.min(Math.max(S,0),1)}return is(S,v,y,x,O)}const Be=i=>Math.round(Math.min(1,Math.max(0,i))*255).toString(16).padStart(2,"0");function ns({r:i,g:e,b:t,a:s=1}){const n=`#${Be(i)}${Be(e)}${Be(t)}`;return s<1?`${n}${Be(s)}`:n}let ye;function rs(){const[i,e]=b.useState(ye);return b.useEffect(()=>{ye||import("@tomorrowevening/theatre-studio").then(t=>{ye=t.default,ye.initialize(),ye.ui.hide(),e(ye)})},[]),i}async function as(){for(;!document.getElementById("theatrejs-studio-root");)await new Promise(s=>setTimeout(s,100));const i=document.getElementById("theatrejs-studio-root");if(i===null||i.shadowRoot===null)return;const e=i.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t!==null){try{const n=t.children[1].children[1];n.parentElement?.removeChild(n)}catch{}try{const s=t.children[3];s.style.top="0",s.style.right="300px"}catch{}}}function os(i,e,t,s){s.sheetObject(i,e,{transform:{position:{x:t.position.x,y:t.position.y,z:t.position.z},rotation:{x:t.rotation.x,y:t.rotation.y,z:t.rotation.z},scale:{x:t.scale.x,y:t.scale.y,z:t.scale.z},visible:t.visible}},n=>{const r=n.transform;t.position.copy(r.position),t.rotation.copy(r.rotation),t.scale.copy(r.scale),t.visible=r.visible})}const ls=["allowOverride","alphaHash","alphaTest","alphaToCoverage","blendAlpha","blendColor","blendDst","blendDstAlpha","blendEquation","blendEquationAlpha","blendSrc","blendSrcAlpha","blending","clipIntersection","clipShadows","clipping","clippingPlanes","colorWrite","combine","defaultAttributeValues","defines","depthFunc","depthTest","depthWrite","dithering","extensions","fog","forceSinglePass","fragmentShader","glslVersion","id","index0AttributeName","index1AttributeName","index2AttributeName","index3AttributeName","index4AttributeName","isMaterial","lights","linewidth","name","needsUpdate","polygonOffset","polygonOffsetFactor","polygonOffsetUnits","precision","premultipliedAlpha","shadowSide","side","stencilFail","stencilFunc","stencilFuncMask","stencilRef","stencilWrite","stencilWriteMask","stencilZFail","stencilZPass","toneMapped","transparent","type","uniformsGroups","uniformsNeedUpdate","userData","uuid","version","vertexColors","vertexShader","visible","wireframe","wireframeLinewidth","wireframeLinecap","wireframeLinejoin"];function It(i){const e=typeof i;if(i===null||i.isTexture)return"texture";if(e==="boolean")return"boolean";if(e==="number")return"number";if(e==="string")return"string";if(e==="object"){if(i.isColor)return"color";if(i.isVector2)return"vector2";if(i.isVector3)return"vector3";if(i.isVector4)return"vector4";if(i.isMatrix2)return"matrix2";if(i.isMatrix3)return"matrix3";if(i.isMatrix4)return"matrix4";if(i.isEuler)return"euler";if(Array.isArray(i))return"array"}return"object"}function ii(i){const e=[];for(const s in i){const n=ls.find(o=>o===s),r=s.indexOf("_")===0||s.indexOf("is")===0;if(!(n||r))if(s==="uniforms"){const o=i.uniforms;for(const c in o){const l=o[c].value,h=It(l);h==="array"||h==="object"||e.push({name:`uniforms.${c}.value`,type:h,value:l})}}else{const o=It(i[s]);e.push({name:s,type:o,value:i[s]})}}return e.filter(s=>s.type!=="array"&&s.type!=="object"&&s.type!=="texture")}function si(i){const e={},t={nudgeMultiplier:.01};return i.forEach(s=>{let n=s.value;switch(s.type){case"color":n=I.types.rgba({r:n.r,g:n.g,b:n.b,a:1});break;case"number":n=I.types.number(n,t);break;case"euler":case"vector3":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t),z:I.types.number(n.z,t)};break;case"vector2":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t)};break;case"vector4":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t),z:I.types.number(n.z,t),w:I.types.number(n.w,t)};break;case"matrix2":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t)};break;case"matrix3":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t),4:I.types.number(n.elements[4],t),5:I.types.number(n.elements[5],t),6:I.types.number(n.elements[6],t),7:I.types.number(n.elements[7],t),8:I.types.number(n.elements[8],t)};break;case"matrix4":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t),4:I.types.number(n.elements[4],t),5:I.types.number(n.elements[5],t),6:I.types.number(n.elements[6],t),7:I.types.number(n.elements[7],t),8:I.types.number(n.elements[8],t),9:I.types.number(n.elements[9],t),10:I.types.number(n.elements[10],t),11:I.types.number(n.elements[11],t),12:I.types.number(n.elements[12],t),13:I.types.number(n.elements[13],t),14:I.types.number(n.elements[14],t),15:I.types.number(n.elements[15],t)};break}if(s.name.includes(".")){const r=s.name.split(".");let a=e;for(let o=0;o<r.length-1;o++){const c=r[o];a[c]||(a[c]={}),a=a[c]}a[r[r.length-1]]=n}else e[s.name]=n}),e}function ni(i,e,t){e.forEach(s=>{if(i[s.name]!==void 0)switch(s.type){case"boolean":case"number":i[s.name]=t.material[s.name];break;case"color":case"euler":case"matrix2":case"matrix3":case"matrix4":case"vector2":case"vector3":case"vector4":i[s.name].copy(t.material[s.name]);break}})}function cs(i,e,t,s){if(!t.isMaterial)return;const n=ii(t),r=si(n);s.sheetObject(i,e,{material:r},a=>{ni(t,n,a)})}const Je=new m.BufferGeometry;Je.setAttribute("position",new m.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3));Je.setAttribute("normal",new m.Float32BufferAttribute([0,0,1,0,0,1],3));Je.setAttribute("uv",new m.Float32BufferAttribute([0,0,2,0,0,2],2));const hs=new m.OrthographicCamera(-.5,.5,.5,-.5,0,100),_t=i=>{i?.dispose()},bt=i=>{if(i)if(Array.isArray(i))i.forEach(e=>bt(e));else{for(const e in i){const t=i[e];t!==null&&t instanceof m.Texture&&_t(t)}if(i.isShaderMaterial===!0){const e=i;for(const t in e.uniforms){const s=e.uniforms[t];s.value!==null&&s.value instanceof m.Texture&&_t(s.value)}}i.dispose()}},Q=i=>{if(i){for(;i.children.length>0;){const e=i.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):Q(e)}if(i.parent&&i.parent.remove(i),i.isMesh){const e=i;e.geometry?.dispose(),bt(e.material)}i.dispose!==void 0&&i.dispose()}};exports.totalThreeObjects=0;const Ne=()=>{exports.totalThreeObjects=0},Me=i=>{if(!i)return;let e=i.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),i.parent!==null&&i.parent.uuid.length>0&&(e=`${i.parent.uuid}.${e}`),i.uuid=e,i.isMesh!==void 0){const t=i;if(Array.isArray(t.material))t.material.forEach((s,n)=>{s.uuid=`${e}.material.${n}`});else{const s=t.material;s.uuid=`${e}.material`}}i.children.forEach(t=>Me(t))};class ae{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 n=e.image;if(n!=null&&n.width>0){this.canvas.title=e.sourceFile;const r=this.canvas.width/n.width,a=this.renderToCanvas(e);this.context.drawImage(a,0,0,n.width*r,n.height*r)}}return e.repeat.copy(t),e.offset.copy(s),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new m.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new m.Scene,this.material=new m.MeshBasicMaterial;const t=new m.BufferGeometry;t.setAttribute("position",new m.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new m.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new m.Float32BufferAttribute([0,0,2,0,0,2],2));const s=new m.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=m.LinearSRGBColorSpace,e.colorSpace=m.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=s}return this.renderer.domElement}}function ds(i){return new Promise(e=>{const t=new m.ObjectLoader;t.parseAsync(i.scene).then(s=>{const n=new m.AnimationMixer(s);if(i.animations.length>0){const a=i.animations.map(c=>m.AnimationClip.parse(c));n.clipAction(a[0]).play(),n.getRoot().animations=i.animations,n.getRoot().mixer=n}const r=[];i.cameras&&i.cameras.length>0&&i.cameras.forEach(a=>{const o=t.parse(a);r.push(o)}),e({animations:i.animations,model:s,mixer:n,cameras:r})})})}const us=(i,e,t,s)=>{i.setRenderTarget(s),i.clear(),i.render(e,t)};function ri(i,e,t,s){i.applyMatrix4(new m.Matrix4().makeTranslation(e,-t,-s))}function ps(i){i.computeBoundingBox();const e=i.boundingBox,t=(e.max.x-e.min.x)/2,s=(e.max.y-e.min.y)/2;ri(i,t,s,0)}function ms(i,e,t){i.left=e/-2,i.right=e/2,i.top=t/2,i.bottom=t/-2,i.position.x=e/2,i.position.y=t/-2,i.updateProjectionMatrix()}function fs(i,e,t){const s=1.7777777777777777,n=e/t;let r=e,a=t;n>s?r=t*s:a=e/s,i.left=r/-2,i.right=r/2,i.top=a/2,i.bottom=a/-2,i.updateProjectionMatrix()}function gs(){let e="transferControlToOffscreen"in document.createElement("canvas");if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)){const s=navigator.userAgent.match(/version\/(\d+)/i);e=(s?parseInt(s[1]):0)>=17}return e}function vs(i,e,t=!0,s=!1){i.renderOrder=-e;const n=i.material;Array.isArray(n)?n.forEach(r=>{r.colorWrite=t,r.depthWrite=s,r.stencilWrite=!0,r.stencilRef=e,r.stencilFunc=m.AlwaysStencilFunc,r.stencilFail=m.ReplaceStencilOp,r.stencilZFail=m.ReplaceStencilOp,r.stencilZPass=m.ReplaceStencilOp}):(n.colorWrite=t,n.depthWrite=s,n.stencilWrite=!0,n.stencilRef=e,n.stencilFunc=m.AlwaysStencilFunc,n.stencilFail=m.ReplaceStencilOp,n.stencilZFail=m.ReplaceStencilOp,n.stencilZPass=m.ReplaceStencilOp)}function _s(i,e,t=!1){const s=i.material;Array.isArray(s)?s.forEach(n=>{n.stencilWrite=!0,n.stencilRef=e,n.stencilFunc=t?m.NotEqualStencilFunc:m.EqualStencilFunc,n.stencilFail=m.KeepStencilOp,n.stencilZFail=m.KeepStencilOp,n.stencilZPass=m.KeepStencilOp}):(s.stencilWrite=!0,s.stencilRef=e,s.stencilFunc=t?m.NotEqualStencilFunc:m.EqualStencilFunc,s.stencilFail=m.KeepStencilOp,s.stencilZFail=m.KeepStencilOp,s.stencilZPass=m.KeepStencilOp)}function ys(i){i.blending=m.NormalBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.SrcAlphaFactor,i.blendDst=m.OneMinusSrcAlphaFactor,i.needsUpdate=!0}function Cs(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.SrcAlphaFactor,i.blendDst=m.OneFactor,i.needsUpdate=!0}function bs(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.DstColorFactor,i.blendDst=m.OneMinusSrcAlphaFactor,i.needsUpdate=!0}function Es(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.OneMinusDstColorFactor,i.blendDst=m.OneFactor,i.needsUpdate=!0}let yt=[];function ai(i,e,t=!0){ae.renderer=e.renderer;const s=[];s.push({type:"boolean",prop:"Enabled",value:i.enabled});let n=(a,o)=>{console.log("Default Handle Pass:",a,o)};if(i.name==="EffectPass")i.effects.forEach(a=>{a.uniforms.size>0&&a.uniforms.forEach((o,c)=>{if(c==="map")return;const l=`${a.name.replace("Effect","")} ${c}`;if(o.value===null&&t)s.push({prop:c,title:l,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(o.value.isTexture&&t){const h=o.value,u=ae.renderToBlob(h);s.push({prop:c,title:l,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof o.value=="number"?s.push({prop:c,title:l,type:"number",value:o.value,step:.01}):typeof o.value=="string"?s.push({prop:c,title:l,type:"string",value:o.value}):typeof o.value=="boolean"&&s.push({prop:c,title:l,type:"boolean",value:o.value})})}),n=(a,o)=>{i.effects.forEach(c=>{c.uniforms.size>0&&c.uniforms.forEach((l,h)=>{h===a&&(l.value=o)})})};else if(i.name==="ShaderPass"){const a=i.fullscreenMaterial;for(const o in a.uniforms){if(o==="inputBuffer"||o==="map")continue;const c=a.uniforms[o],l=`${a.name.replace("Material","")} ${o}`;if(c.value===null&&t)s.push({title:l,prop:o,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(c.value.isTexture&&t){const h=c.value,u=ae.renderToBlob(h);s.push({title:l,prop:o,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof c.value=="number"?s.push({title:l,prop:o,type:"number",value:c.value,step:.01}):typeof c.value=="string"?s.push({title:l,prop:o,type:"string",value:c.value}):typeof c.value=="boolean"&&s.push({title:l,prop:o,type:"boolean",value:c.value})}n=(o,c)=>{const l=a.uniforms[o];l.value=c}}else return;const r=`${i.name}: ${i.scene.name}`;e.addGroup({title:r,items:s,onUpdate:(a,o)=>{a==="Enabled"?i.enabled=o:n(a,o)}}),yt.push(r)}function Ss(i,e){i.passes.forEach(t=>{ai(t,e)})}function xs(i){yt.forEach(e=>{i.removeGroup(e)}),yt=[]}function Os(i,e,t,s=1024){return new Promise(n=>{const r=e.aspect,a=e.fov,o=e.rotation.clone(),c=t.outputBuffer;e.aspect=1,e.fov=90,e.updateProjectionMatrix();const l=new m.WebGLRenderTarget(s,s,{format:m.RGBAFormat,depthBuffer:!0,stencilBuffer:!1});t.outputBuffer=l,Ce(i,l,e,"nx",t,s).then(()=>{Ce(i,l,e,"ny",t,s).then(()=>{Ce(i,l,e,"nz",t,s).then(()=>{Ce(i,l,e,"px",t,s).then(()=>{Ce(i,l,e,"py",t,s).then(()=>{Ce(i,l,e,"pz",t,s).then(()=>{e.aspect=r,e.fov=a,e.rotation.copy(o),e.updateMatrixWorld(),e.updateProjectionMatrix(),t.outputBuffer=c,l.dispose(),n()})})})})})})})}function Ce(i,e,t,s,n,r){return new Promise(a=>{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(),n.render();const c=new Uint8Array(r*r*4);i.readRenderTargetPixels(e,0,0,r,r,c);const l=document.createElement("canvas");l.width=l.height=r;const h=l.getContext("2d"),u=h.createImageData(r,r);u.data.set(c),h.putImageData(u,0,0);const p=document.createElement("canvas");p.width=p.height=r;const g=p.getContext("2d");g.translate(0,r),g.scale(1,-1),g.drawImage(l,0,0);const C=p.toDataURL("image/png"),_=document.createElement("a");_.href=C,_.download=`${t.name}_${s}.png`,document.body.appendChild(_),_.click(),_.remove(),a()})}const be=Et(["ctrlKey","metaKey","shiftKey","button","pointerId","pointerType","clientX","clientY","pageX","pageY"]),ws=Et(["clientX","clientY","deltaX","deltaY","deltaMode"]),Ts=Et(["ctrlKey","metaKey","shiftKey","keyCode"]);function Ms(i,e){i.preventDefault(),ws(i,e)}function As(i){i.preventDefault()}function Rs(i,e,t){for(const s of e)t[s]=i[s]}function Et(i){return function(t,s){const n={type:t.type};Rs(t,i,n),s(n)}}function rt(i,e){const t=[],s={type:i.type,touches:t};for(let n=0;n<i.touches.length;++n){const r=i.touches[n];t.push({pageX:r.pageX,pageY:r.pageY})}e(s)}const Ps={37:!0,38:!0,39:!0,40:!0};function Ds(i,e){const{keyCode:t}=i;Ps[t]&&(i.preventDefault(),Ts(i,e))}const Is={contextmenu:As,mousedown:be,mousemove:be,mouseup:be,pointerdown:be,pointermove:be,pointerup:be,touchstart:rt,touchmove:rt,touchend:rt,wheel:Ms,keydown:Ds};let Ls=0;class Us{id;worker;constructor(e,t,s){this.id=Ls++,this.worker=t;const n=a=>{this.worker.postMessage({type:"event",id:this.id,data:a})};t.postMessage({type:"makeProxy",id:this.id});for(const[a,o]of Object.entries(s))e.addEventListener(a,c=>{o(c,n)});function r(){n({type:"resize",left:0,top:0,width:innerWidth,height:innerHeight})}window.addEventListener("resize",r),r()}}class oi extends m.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=ze,e.stopPropagation=ze,this.dispatchEvent(e)}focus(){}getRootNode(){return this}}class ks{targets={};constructor(){this.handleEvent=this.handleEvent.bind(this)}makeProxy(e){const{id:t}=e,s=new oi;this.targets[t]=s}getProxy(e){return this.targets[e]}handleEvent(e){this.targets[e.id]?.handleEvent(e.data)}}class Ns{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};onUpdateCallback;playing=!1;rafID=-1;constructor(e,t=!1){this.settings.dev=e,this.settings.editor=t}dispose(){this.pause(),this.components.forEach(e=>e.dispose()),this.components.clear()}detectSettings(){return new Promise(e=>{ti(this.settings.dev,this.settings.editor).then(t=>{this.settings=t,e()})})}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)};addComponent(e,t){this.components.set(e,t)}get debugEnabled(){return this.settings.dev}get isApp(){return!this.editor}set isApp(e){this.editor=!e}get editor(){return this.settings.editor}set editor(e){this.settings.editor=e}}class St{name;debug;editor;broadcastChannel;onMessageHandler;constructor(e,t=!1,s=!1){this.name=e,this.debug=t,this.editor=s,t&&(this.broadcastChannel=new BroadcastChannel(e),this.onMessageHandler=this.messageHandler.bind(this),this.broadcastChannel.addEventListener("message",this.onMessageHandler))}dispose(){this.broadcastChannel?.removeEventListener("message",this.onMessageHandler),this.broadcastChannel?.close()}send(e){if(this.editor&&e.target==="app"||!this.editor&&e.target==="editor")try{this.broadcastChannel?.postMessage(e)}catch(s){console.log("Hermes - Error sending message:"),console.log(s),console.log(e)}}messageHandler(e){const t=e.data;t.target==="app"?this.handleApp(t):this.handleEditor(t)}handleApp(e){}handleEditor(e){}}function Fs(i,e,t,s,n){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*s+i*i*i*n}function js(i,e,t){if(i.type!=="bezier"||i.handles.length!==4)throw new Error("Invalid keyframe data for Bézier interpolation.");const[s,n]=i.handles,r=(t-i.position)/(e.position-i.position);return Fs(r,i.value,i.value+s,e.value+n,e.value)}class zs extends St{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;constructor(e=!1,t=!1){super("RemoteTheatre",e,t)}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}loadProject(e,t){return this.project=I.getProject(e,{state:t}),new Promise((s,n)=>{this.project?.ready.then(()=>{if(t){const r=t.sheetsById;for(const a in r)this.sheet(a)}s()}).catch(()=>n())})}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 n=this.sheets.get(s);return n!==void 0||(n=this.project?.sheet(e,t),this.sheets.set(s,n)),n}playSheet(e,t,s){return new Promise(n=>{this.sheet(e,s)?.sequence.play(t).then(r=>n(r)),this.send({event:"playSheet",target:"editor",data:{sheet:e,instance:s,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.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,n,r){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const a=this.sheet(e,r);if(a===void 0)return;const c=`${this.getSheetInstance(e,r)}_${t}`;let l=this.sheetObjects.get(c),h=s;l!==void 0&&(h={...s,...l.value}),l=a.object(t,h,{reconfigure:!0}),this.sheetObjects.set(c,l),this.sheetObjectCBs.set(c,n!==void 0?n:ze);function u(g,C,_){if(typeof _=="object")if(Qt(_))g[C]={r:_.r,g:_.g,b:_.b,a:_.a};else for(const E in _){const v=_[E];typeof v=="object"&&u(_,E,v)}}const p=l.onValuesChange(g=>{const C=this.sheetObjectCBs.get(c);if(this.editor){for(const _ in g){const E=g[_];typeof E=="object"&&u(g,_,E)}this.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:c,values:g}}),C&&C(g)}else C&&C(g)});return this.sheetObjectUnsubscribe.set(c,p),l}getSheetObjectKeyframes(e,t,s){const n=this.sheet(e);if(n===void 0)return[];const r=`${e}_${t}`,a=this.sheetObjects.get(r);return a===void 0?[]:n.sequence.__experimental_getKeyframes(a.props[s])}getSheetObjectVectors(e,t){const s=this.sheet(e);if(s===void 0)return[];const n=`${e}_${t}`,r=this.sheetObjects.get(n);if(r===void 0)return[];const a=[],o=s.sequence.__experimental_getKeyframes(r.props.x),c=s.sequence.__experimental_getKeyframes(r.props.y),l=s.sequence.__experimental_getKeyframes(r.props.z),h=new Set;return o.forEach(p=>h.add(p.position)),c.forEach(p=>h.add(p.position)),l.forEach(p=>h.add(p.position)),Array.from(h).sort((p,g)=>p-g).forEach(p=>{const g=(C,_)=>{const E=C.find((x,O)=>x.position<=_&&(C[O+1]?.position||1/0)>_),v=C.find(x=>x.position>_);if(!E)return v?.value||0;if(!v||E.position===_)return E.value;if(E.type==="bezier")return js(E,v,_);const y=(_-E.position)/(v.position-E.position);return E.value+y*(v.value-E.value)};a.push({position:p,x:g(o,p),y:g(c,p),z:g(l,p)})}),a}update(e){}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 r=`${t}_${s}`,a=this.sheetObjectUnsubscribe.get(r);a!==void 0&&(this.sheetObjects.delete(r),this.sheetObjectCBs.delete(r),this.sheetObjectUnsubscribe.delete(r),a())}handleApp(e){let t;switch(e.event){case"setSheet":t=this.sheets.get(e.data.sheet),t!==void 0?this.studio?.setSelection([t]):console.log(`Hermes - Can't set Sheet: ${e.data.sheet}`,t);break;case"setSheetObject":t=this.sheetObjects.get(`${e.data.sheet}_${e.data.key}`),t!==void 0?this.studio?.setSelection([t]):console.log(`Hermes - Can't set Sheet Object: ${e.data.sheet}, ${e.data.key}: ${e.data.sheet}_${e.data.key}`,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):console.log(`Hermes - Can't update Sheet Object: ${e.data.sheetObject}, ${e.data.sheet}`,t);break;case"updateTimeline":t=this.sheets.get(e.data.sheet),t!==void 0?t.sequence.position=e.data.position:console.log(`Hermes - Can't update sheet position: ${e.data.sheet}, ${e.data.position}`);break}}handleEditor(e){switch(e.event){case"playSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.play(e.data.value);break;case"pauseSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.pause();break}}getSheetNames(){const e=[];return this.sheets.forEach((t,s)=>{e.push(s)}),e}handleEditorApp(){if(this.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(n=>{n.length<1||n.forEach(r=>{let a=r.address.sheetId,o="setSheet",c={};switch(r.type){case"Theatre_Sheet_PublicAPI":o="setSheet",c={sheet:r.address.sheetId},this.activeSheet=this.sheets.get(r.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":o="setSheetObject",a+=`_${r.address.objectKey}`,c={id:a,sheet:r.address.sheetId,key:r.address.objectKey},this.activeSheet=this.sheets.get(r.address.sheetId);break}this.send({event:o,target:"app",data:c})})});let e=-1;const t=()=>{if(this.activeSheet!==void 0&&e!==this.activeSheet.sequence.position){e=this.activeSheet.sequence.position;const n=this.activeSheet;this.send({event:"updateTimeline",target:"app",data:{position:e,sheet:n.address.sheetId}})}},s=()=>{t(),requestAnimationFrame(s)};t(),s()}else this.studio?.ui.hide()}}function Hs(i){if(i.name==="cameras")return"camera";if(i.name==="interactive")return"interactive";if(i.name==="lights")return"light";if(i.name==="ui")return"ui";if(i.name==="utils")return"utils";const e=i.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function ce(i){const e={name:i.name,type:i.type,uuid:i.uuid,children:[]};return i.children.forEach(t=>{e.children.push(ce(t))}),e}function Lt(i){return{src:i.image?.src??"",offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]}}const Ut={src:"",offset:[0,0],repeat:[1,1]};function Bs(i){const e={};for(const t in i){const s=i[t];if(s!==null&&typeof s=="object"&&Object.prototype.hasOwnProperty.call(s,"value")){const r=s.value;r==null?e[t]={value:Ut}:r.isTexture?e[t]={value:Lt(r)}:e[t]={value:r}}else s==null?e[t]=Ut:s.isTexture?e[t]=Lt(s):e[t]=s}return e}function Vs(i){switch(i){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Ee(i){const e={};for(const t in i){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||Vs(t))continue;const s=typeof i[t],n=i[t];switch(s){case"boolean":case"number":case"string":e[t]=n;break;case"object":if(n!==null)if(n.isTexture)e[t]={src:ae.renderToBlob(n),offset:[n.offset.x,n.offset.y],repeat:[n.repeat.x,n.repeat.y]};else if(n.isUniformNode){const r=n.value;e[t]={__isUniform:!0,value:r?.isTexture?{src:ae.renderToBlob(r),offset:[r.offset.x,r.offset.y],repeat:[r.repeat.x,r.repeat.y]}:r}}else t==="uniforms"?e[t]=Bs(n):t.search("Node")>-1||(e[t]=n);else t==="glslVersion"?e[t]="":t.search("Node")>-1||(e[t]={src:"",offset:[0,0],repeat:[1,1]});break}}return i.anisotropy!==void 0&&(e.anisotropy=i.anisotropy),i.clearcoat!==void 0&&(e.clearcoat=i.clearcoat),i.iridescence!==void 0&&(e.iridescence=i.iridescence),i.dispersion!==void 0&&(e.dispersion=i.dispersion),i.sheen!==void 0&&(e.sheen=i.sheen),i.transmission!==void 0&&(e.transmission=i.transmission),i.transmission!==void 0&&(e.transmission=i.transmission),e}function at(i){i.updateMatrix();const e={name:i.name,type:i.type,uuid:i.uuid,visible:i.visible,matrix:i.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};i.animations.forEach(s=>{e.animations.push({name:s.name,duration:s.duration,blendMode:s.blendMode})});const t=i.type.toLowerCase();if(t.search("mesh")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else if(t.search("points")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else if(t.search("line")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else t.search("camera")>-1?i.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:i.fov,zoom:i.zoom,near:i.near,far:i.far,focus:i.focus,aspect:i.aspect,filmGauge:i.filmGauge,filmOffset:i.filmOffset}:i.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:i.zoom,near:i.near,far:i.far,left:i.left,right:i.right,top:i.top,bottom:i.bottom}):t.search("light")>-1&&(e.lightInfo={color:i.color,intensity:i.intensity,decay:i.decay,distance:i.distance,angle:i.angle,penumbra:i.penumbra,groundColor:i.groundColor,width:i.width,height:i.height});return e}function Gs(i,e){const t=e.split(".");switch(t.length){case 1:return i[t[0]];case 2:return i[t[0]][t[1]];case 3:return i[t[0]][t[1]][t[2]];case 4:return i[t[0]][t[1]][t[2]][t[3]];case 5:return i[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return i[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function Ws(i,e){for(const t in e)i[t]=e[t]}function V(i,e,t){if(i===void 0){console.log(`Hermes - Can't set props: ${e}`,t);return}const s=e.split("."),n=s.length;if(typeof t!="object")switch(n){case 1:i[s[0]]=t;break;case 2:i[s[0]][s[1]]=t;break;case 3:i[s[0]][s[1]][s[2]]=t;break;case 4:i[s[0]][s[1]][s[2]][s[3]]=t;break;case 5:i[s[0]][s[1]][s[2]][s[3]][s[4]]=t;break}else{let a;switch(n){case 1:a=i[s[0]];break;case 2:a=i[s[0]][s[1]];break;case 3:a=i[s[0]][s[1]][s[2]];break;case 4:a=i[s[0]][s[1]][s[2]][s[3]];break;case 5:a=i[s[0]][s[1]][s[2]][s[3]][s[4]];break}a!=null?Ws(a,t):console.log(`Hermes - Can't set props because target isn't found: ${e}`,t)}}function li(i){return new Promise((e,t)=>{const s=new Image;s.onload=()=>{const n=new m.Texture(s);n.wrapS=m.RepeatWrapping,n.wrapT=m.RepeatWrapping,n.needsUpdate=!0,e(n)},s.onerror=t,s.src=i})}var L=(i=>(i.CUSTOM="ToolEvents::custom",i.SELECT_DROPDOWN="ToolEvents::selectDropdown",i.DRAG_UPDATE="ToolEvents::dragUpdate",i.ADD_SCENE="ToolEvents::addScene",i.REFRESH_SCENE="ToolEvents::refreshScene",i.REMOVE_SCENE="ToolEvents::removeScene",i.SET_SCENE="ToolEvents::setScene",i.SET_OBJECT="ToolEvents::setObject",i.CLEAR_OBJECT="ToolEvents::clearObject",i.ADD_CAMERA="ToolEvents::addCamera",i.REMOVE_CAMERA="ToolEvents::removeCamera",i.ADD_GROUP="ToolEvents::addGroup",i.REMOVE_GROUP="ToolEvents::removeGroup",i.ADD_SPLINE="ToolEvents::addSpline",i.ADD_RENDERER="ToolEvents::addRenderer",i.UPDATE_RENDERER="ToolEvents::updateRenderer",i))(L||{});class Ys extends St{name;canvas=null;inputElement=null;scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;renderTargetsResize=new Map;groups=new Map;_listeners={};constructor(e,t=!1,s=!1){super("RemoteThree",t,s),this.name=e}dispose(){this.scenes.forEach(e=>{Q(e)}),this.scenes.clear(),this.scene&&Q(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}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 n=s[e];if(n!==void 0){const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const s=t[e.type];if(s!==void 0){const n={...e,target:this},r=s.slice(0);for(let a=0,o=r.length;a<o;a++)r[a].call(this,n)}}getObjectByUUID(e){const t=e.split(".")[0],s=this.scenes.get(t);if(s!==void 0)return s.getObjectByProperty("uuid",e)}getObject(e){if(!this.debug)return;this.renderer!==void 0&&(ae.renderer=this.renderer);const t=this.getObjectByUUID(e);t&&this.setObject(t)}setObject(e){this.renderer!==void 0&&(ae.renderer=this.renderer);const t=at(e);this.dispatchEvent({type:"ToolEvents::setObject",value:t})}requestMethod(e,t,s,n){const r=this.getObjectByUUID(e);if(r)try{n!==void 0?Gs(r,n)[t](s):r[t](s)}catch(a){console.log("Hermes - Error requesting method:",e,t,s),console.log(a)}}updateObject(e,t,s){this.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:s}})}createTexture(e,t,s){this.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:s}})}onUpdateObject(e,t,s){const n=this.getObjectByUUID(e);n&&V(n,t,s)}onCreateTexture(e,t,s){const n=this.getObjectByUUID(e);if(n){const r=a=>{const o=t.split(".");switch(o.length){case 1:n[o[0]]=a;break;case 2:n[o[0]][o[1]]=a;break;case 3:n[o[0]][o[1]][o[2]]=a;break;case 4:n[o[0]][o[1]][o[2]][o[3]]=a;break;case 5:n[o[0]][o[1]][o[2]][o[3]][o[4]]=a;break}n.material.needsUpdate=!0};s.src.length>0?li(s.src).then(a=>{a.offset.set(s.offset[0],s.offset[1]),a.repeat.set(s.repeat[0],s.repeat[1]),r(a)}):r(null)}}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,s){this.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:s})})}addSplineCurve(e){setTimeout(()=>{this.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}addSplineObject(e){setTimeout(()=>{this.send({event:"addSpline",target:"editor",data:JSON.stringify(e)})},1)}setRenderer(e,t=null){if(this.renderer=e,this.canvas=e.domElement,this.inputElement=t!==null?t:this.canvas,!this.debug)return;const s=`#${e.getClearColor(new w.Color).getHexString()}`;this.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:w.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure,type:e.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}updateRenderer(e){this.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.debug))return;Ne(),Me(e);const t=ce(e);this.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.debug)return;const t=this.scenes.get(e);if(t!==void 0){const s=ce(t);this.send({event:"refreshScene",target:"app",data:s})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.debug))return;const t=ce(e);this.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scene!==void 0&&this.scene.uuid.search(e)>-1?this.scene:(this.scenes.forEach((s,n)=>{e.search(n)>-1&&(t=s)}),t)}setScene(e){if(e===void 0||(this.scene=e,!this.debug))return;this.renderer!==void 0&&(ae.renderer=this.renderer),Ne(),Me(e);const t=ce(e);this.send({event:"setScene",target:"editor",data:t})}requestSize(){this.send({event:"requestSize",target:"app"})}requestRenderer(){this.send({event:"requestRenderer",target:"app"})}requestScene(){this.send({event:"requestScene",target:"app"})}addCamera(e){if(!this.debug)return;const t=at(e);this.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.debug)return;const t=at(e);this.send({event:"removeCamera",target:"editor",data:t})}handleApp(e){switch(e.event){case"refreshScene":this.send({event:"refreshScene",target:"editor",data:ce(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,w.ColorManagement.enabled=e.data.colorManagement);break;case"requestRenderer":if(this.renderer!==void 0){const t=`#${this.renderer.getClearColor(new w.Color).getHexString()}`;this.send({event:"addRenderer",target:"editor",data:{autoClear:this.renderer.autoClear,autoClearColor:this.renderer.autoClearColor,autoClearDepth:this.renderer.autoClearDepth,autoClearStencil:this.renderer.autoClearStencil,outputColorSpace:this.renderer.outputColorSpace,localClippingEnabled:this.renderer.localClippingEnabled,clearColor:t,clearAlpha:this.renderer.getClearAlpha(),colorManagement:w.ColorManagement.enabled,toneMapping:this.renderer.toneMapping,toneMappingExposure:this.renderer.toneMappingExposure,type:this.renderer.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}break;case"requestScene":this.scenes.forEach(t=>{Ne(),Me(t),this.send({event:"addScene",target:"editor",data:ce(t)})}),this.scene!==void 0&&(this.renderer!==void 0&&(ae.renderer=this.renderer),Ne(),Me(this.scene),this.send({event:"setScene",target:"editor",data:ce(this.scene)}));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"addScene":this.dispatchEvent({type:"ToolEvents::addScene",value:e.data});break;case"refreshScene":this.dispatchEvent({type:"ToolEvents::refreshScene",value:e.data});break;case"removeScene":this.dispatchEvent({type:"ToolEvents::removeScene",value:e.data});break;case"setScene":this.dispatchEvent({type:"ToolEvents::setScene",value:e.data});break;case"addCamera":this.dispatchEvent({type:"ToolEvents::addCamera",value:e.data});break;case"removeCamera":this.dispatchEvent({type:"ToolEvents::removeCamera",value:e.data});break;case"addGroup":this.dispatchEvent({type:"ToolEvents::addGroup",value:e.data});break;case"removeGroup":this.dispatchEvent({type:"ToolEvents::removeGroup",value:e.data});break;case"addSpline":this.dispatchEvent({type:"ToolEvents::addSpline",value:e.data});break;case"addRenderer":this.dispatchEvent({type:"ToolEvents::addRenderer",value:e.data})}}messageHandler(e){const t=e.data;if(t.event==="updateObject"){this.onUpdateObject(t.data.uuid,t.data.key,t.data.value);return}else if(t.event==="createTexture"){this.onCreateTexture(t.data.uuid,t.data.key,t.data.value);return}else if(t.event==="requestSize"){t.target==="app"?this.send({event:"requestSize",target:"editor",data:{width:this.width,height:this.height}}):this.scenes.forEach(s=>{s.resize!==void 0&&s.resize(t.data.width,t.data.height)});return}t.target==="app"?this.handleApp(t):this.handleEditor(t)}addRT(e,t=!0,s){if(!this.renderer)return;let n;this.renderer instanceof w.WebGPURenderer?n=new w.RenderTarget(32,32,s):n=new w.WebGLRenderTarget(32,32,s),n.texture.name=e,this.renderTargets.set(e,n),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((r,a)=>{this.renderTargetsResize.get(a)&&r.setSize(e*s,t*s)});const n=!(this.renderer?.domElement instanceof OffscreenCanvas);this.renderer?.setSize(e,t,n)}set dpr(e){this.renderer?.setPixelRatio(de(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}}function xt(i){return i.title.search("<")>-1?d.jsx("button",{className:"svg",dangerouslySetInnerHTML:{__html:i.title}}):d.jsx("button",{children:i.title})}const qs=d.jsxs("svg",{className:"closeIcon",width:"14",height:"14",fill:"none",stroke:"#666666",strokeMiterlimit:"10",children:[d.jsx("circle",{cx:"7",cy:"7",r:"6"}),d.jsx("line",{x1:"4",y1:"4",x2:"10",y2:"10"}),d.jsx("line",{x1:"4",y1:"10",x2:"10",y2:"4"})]}),$s=d.jsx("svg",{className:"dragIcon",width:"14",height:"14",fill:"#666666",stroke:"none",children:d.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
30
+ `;class qi{worker;source;transfer;ctx;opts;_capturing=!1;_captured=0;_encoded=0;_pending=0;_lastFrameTime=-1/0;frames=new Map;constructor(e,t={}){this.source=e,this.transfer=document.createElement("canvas"),this.transfer.width=e.width,this.transfer.height=e.height,this.ctx=this.transfer.getContext("2d",{willReadFrequently:!0}),this.opts={format:t.format??"png",quality:t.quality??.92,prefix:t.prefix??"frame",padLength:t.padLength??5,maxQueue:t.maxQueue??32,fps:t.fps??30,onProgress:t.onProgress??(()=>{}),onError:t.onError??(r=>console.error("[ImageSequenceCapturer]",r))};const s=new Blob([Yi],{type:"application/javascript"}),n=URL.createObjectURL(s);this.worker=new Worker(n),URL.revokeObjectURL(n),this.worker.onmessage=({data:r})=>{r.type==="encoded"&&(this.frames.set(r.index,r.blob),this._pending--,this._encoded++,this.opts.onProgress(this._captured,this._encoded))},this.worker.onerror=r=>this.opts.onError(new Error(r.message))}get isCapturing(){return this._capturing}get framesCaptured(){return this._captured}get framesEncoded(){return this._encoded}get isIdle(){return this._pending===0}resize(){this.transfer.width=this.source.width,this.transfer.height=this.source.height}start(){this._capturing=!0,this._captured=0,this._encoded=0,this._pending=0,this._lastFrameTime=-1/0,this.frames.clear()}stop(){this._capturing=!1}captureFrame(){if(!this._capturing||this._pending>=this.opts.maxQueue)return!1;const e=performance.now();if(e-this._lastFrameTime<1e3/this.opts.fps)return!1;this._lastFrameTime=e,this.ctx.drawImage(this.source,0,0);const t=this._captured++;return this._pending++,createImageBitmap(this.transfer).then(s=>{this.worker.postMessage({type:"encode",bitmap:s,index:t,format:this.opts.format,quality:this.opts.quality},[s])}).catch(s=>{this._pending--,this.opts.onError(s)}),!0}flush(){return new Promise(e=>{const t=()=>this._pending===0?e():setTimeout(t,16);t()})}async download(){await this.flush();const e=this.opts.format==="jpeg"?"jpg":this.opts.format,s=[...this.frames.entries()].sort(([n],[r])=>n-r).map(([n,r])=>({name:`${this.opts.prefix}_${String(n).padStart(this.opts.padLength,"0")}.${e}`,blob:r}));if("showDirectoryPicker"in window)try{const n=await window.showDirectoryPicker({mode:"readwrite",startIn:"downloads"});await Promise.all(s.map(async({name:r,blob:a})=>{const c=await(await n.getFileHandle(r,{create:!0})).createWritable();await c.write(a),await c.close()}));return}catch(n){if(n.name==="AbortError")return}for(const{name:n,blob:r}of s){const a=URL.createObjectURL(r);Object.assign(document.createElement("a"),{href:a,download:n}).click(),URL.revokeObjectURL(a),await new Promise(c=>setTimeout(c,50))}}reset(){this._capturing=!1,this._captured=0,this._encoded=0,this._pending=0,this.frames.clear()}destroy(){this.reset(),this.worker.terminate()}}function de(i,e,t){return Math.min(e,Math.max(i,t))}function Xe(i,e,t){return(t-i)/(e-i)}function Re(i,e,t){return i*(1-t)+e*t}function $i(i,e,t,s,n){return Re(t,s,Xe(i,e,n))}function Zi(i,e){const t=i-e;return Math.sqrt(t*t)}function Ki(i,e,t,s){return Re(i,e,1-Math.exp(-t*s))}function X(i,e=1){return Number(i.toFixed(e))}function Xi(i,e,t,s){return Math.atan2(s-e,t-i)}function Qi(i,e,t,s){return i===e&&t===s}function Ji(i,e,t,s){return 1/(3*e*i*i+2*t*i+s)}function es(i,e,t,s,n){return e*(i*i*i)+t*(i*i)+s*i+n}function ts(i,e,t,s,n){const r=i*i;return e*(r*i)+t*r+s*i+n}function is(i,e,t,s,n){if(i<=0)return 0;if(i>=1)return 1;if(Qi(e,t,s,n))return i;const r=0,a=0,o=e,c=t,l=s,h=n,u=1,p=1,g=u-3*l+3*o-r,C=3*l-6*o+3*r,_=3*o-3*r,E=r,v=p-3*h+3*c-a,y=3*h-6*c+3*a,x=3*c-3*a,O=a;let S=i;for(let T=0;T<5;T++){const M=es(S,g,C,_,E);let U=Ji(S,g,C,_);U===1/0&&(U=i),S-=(M-i)*U,S=Math.min(Math.max(S,0),1)}return ts(S,v,y,x,O)}const Be=i=>Math.round(Math.min(1,Math.max(0,i))*255).toString(16).padStart(2,"0");function ss({r:i,g:e,b:t,a:s=1}){const n=`#${Be(i)}${Be(e)}${Be(t)}`;return s<1?`${n}${Be(s)}`:n}let ye;function ns(){const[i,e]=b.useState(ye);return b.useEffect(()=>{ye||import("@tomorrowevening/theatre-studio").then(t=>{ye=t.default,ye.initialize(),ye.ui.hide(),e(ye)})},[]),i}async function rs(){for(;!document.getElementById("theatrejs-studio-root");)await new Promise(s=>setTimeout(s,100));const i=document.getElementById("theatrejs-studio-root");if(i===null||i.shadowRoot===null)return;const e=i.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t!==null){try{const n=t.children[1].children[1];n.parentElement?.removeChild(n)}catch{}try{const s=t.children[3];s.style.top="0",s.style.right="300px"}catch{}}}function as(i,e,t,s){s.sheetObject(i,e,{transform:{position:{x:t.position.x,y:t.position.y,z:t.position.z},rotation:{x:t.rotation.x,y:t.rotation.y,z:t.rotation.z},scale:{x:t.scale.x,y:t.scale.y,z:t.scale.z},visible:t.visible}},n=>{const r=n.transform;t.position.copy(r.position),t.rotation.copy(r.rotation),t.scale.copy(r.scale),t.visible=r.visible})}const os=["allowOverride","alphaHash","alphaTest","alphaToCoverage","blendAlpha","blendColor","blendDst","blendDstAlpha","blendEquation","blendEquationAlpha","blendSrc","blendSrcAlpha","blending","clipIntersection","clipShadows","clipping","clippingPlanes","colorWrite","combine","defaultAttributeValues","defines","depthFunc","depthTest","depthWrite","dithering","extensions","fog","forceSinglePass","fragmentShader","glslVersion","id","index0AttributeName","index1AttributeName","index2AttributeName","index3AttributeName","index4AttributeName","isMaterial","lights","linewidth","name","needsUpdate","polygonOffset","polygonOffsetFactor","polygonOffsetUnits","precision","premultipliedAlpha","shadowSide","side","stencilFail","stencilFunc","stencilFuncMask","stencilRef","stencilWrite","stencilWriteMask","stencilZFail","stencilZPass","toneMapped","transparent","type","uniformsGroups","uniformsNeedUpdate","userData","uuid","version","vertexColors","vertexShader","visible","wireframe","wireframeLinewidth","wireframeLinecap","wireframeLinejoin"];function It(i){const e=typeof i;if(i===null||i.isTexture)return"texture";if(e==="boolean")return"boolean";if(e==="number")return"number";if(e==="string")return"string";if(e==="object"){if(i.isColor)return"color";if(i.isVector2)return"vector2";if(i.isVector3)return"vector3";if(i.isVector4)return"vector4";if(i.isMatrix2)return"matrix2";if(i.isMatrix3)return"matrix3";if(i.isMatrix4)return"matrix4";if(i.isEuler)return"euler";if(Array.isArray(i))return"array"}return"object"}function ii(i){const e=[];for(const s in i){const n=os.find(o=>o===s),r=s.indexOf("_")===0||s.indexOf("is")===0;if(!(n||r))if(s==="uniforms"){const o=i.uniforms;for(const c in o){const l=o[c].value,h=It(l);h==="array"||h==="object"||e.push({name:`uniforms.${c}.value`,type:h,value:l})}}else{const o=It(i[s]);e.push({name:s,type:o,value:i[s]})}}return e.filter(s=>s.type!=="array"&&s.type!=="object"&&s.type!=="texture")}function si(i){const e={},t={nudgeMultiplier:.01};return i.forEach(s=>{let n=s.value;switch(s.type){case"color":n=I.types.rgba({r:n.r,g:n.g,b:n.b,a:1});break;case"number":n=I.types.number(n,t);break;case"euler":case"vector3":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t),z:I.types.number(n.z,t)};break;case"vector2":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t)};break;case"vector4":n={x:I.types.number(n.x,t),y:I.types.number(n.y,t),z:I.types.number(n.z,t),w:I.types.number(n.w,t)};break;case"matrix2":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t)};break;case"matrix3":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t),4:I.types.number(n.elements[4],t),5:I.types.number(n.elements[5],t),6:I.types.number(n.elements[6],t),7:I.types.number(n.elements[7],t),8:I.types.number(n.elements[8],t)};break;case"matrix4":n={0:I.types.number(n.elements[0],t),1:I.types.number(n.elements[1],t),2:I.types.number(n.elements[2],t),3:I.types.number(n.elements[3],t),4:I.types.number(n.elements[4],t),5:I.types.number(n.elements[5],t),6:I.types.number(n.elements[6],t),7:I.types.number(n.elements[7],t),8:I.types.number(n.elements[8],t),9:I.types.number(n.elements[9],t),10:I.types.number(n.elements[10],t),11:I.types.number(n.elements[11],t),12:I.types.number(n.elements[12],t),13:I.types.number(n.elements[13],t),14:I.types.number(n.elements[14],t),15:I.types.number(n.elements[15],t)};break}if(s.name.includes(".")){const r=s.name.split(".");let a=e;for(let o=0;o<r.length-1;o++){const c=r[o];a[c]||(a[c]={}),a=a[c]}a[r[r.length-1]]=n}else e[s.name]=n}),e}function ni(i,e,t){e.forEach(s=>{if(i[s.name]!==void 0)switch(s.type){case"boolean":case"number":i[s.name]=t.material[s.name];break;case"color":case"euler":case"matrix2":case"matrix3":case"matrix4":case"vector2":case"vector3":case"vector4":i[s.name].copy(t.material[s.name]);break}})}function ls(i,e,t,s){if(!t.isMaterial)return;const n=ii(t),r=si(n);s.sheetObject(i,e,{material:r},a=>{ni(t,n,a)})}const Je=new m.BufferGeometry;Je.setAttribute("position",new m.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3));Je.setAttribute("normal",new m.Float32BufferAttribute([0,0,1,0,0,1],3));Je.setAttribute("uv",new m.Float32BufferAttribute([0,0,2,0,0,2],2));const cs=new m.OrthographicCamera(-.5,.5,.5,-.5,0,100),_t=i=>{i?.dispose()},bt=i=>{if(i)if(Array.isArray(i))i.forEach(e=>bt(e));else{for(const e in i){const t=i[e];t!==null&&t instanceof m.Texture&&_t(t)}if(i.isShaderMaterial===!0){const e=i;for(const t in e.uniforms){const s=e.uniforms[t];s.value!==null&&s.value instanceof m.Texture&&_t(s.value)}}i.dispose()}},Q=i=>{if(i){for(;i.children.length>0;){const e=i.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):Q(e)}if(i.parent&&i.parent.remove(i),i.isMesh){const e=i;e.geometry?.dispose(),bt(e.material)}i.dispose!==void 0&&i.dispose()}};exports.totalThreeObjects=0;const Ne=()=>{exports.totalThreeObjects=0},Me=i=>{if(!i)return;let e=i.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),i.parent!==null&&i.parent.uuid.length>0&&(e=`${i.parent.uuid}.${e}`),i.uuid=e,i.isMesh!==void 0){const t=i;if(Array.isArray(t.material))t.material.forEach((s,n)=>{s.uuid=`${e}.material.${n}`});else{const s=t.material;s.uuid=`${e}.material`}}i.children.forEach(t=>Me(t))};class ae{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 n=e.image;if(n!=null&&n.width>0){this.canvas.title=e.sourceFile;const r=this.canvas.width/n.width,a=this.renderToCanvas(e);this.context.drawImage(a,0,0,n.width*r,n.height*r)}}return e.repeat.copy(t),e.offset.copy(s),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new m.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new m.Scene,this.material=new m.MeshBasicMaterial;const t=new m.BufferGeometry;t.setAttribute("position",new m.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new m.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new m.Float32BufferAttribute([0,0,2,0,0,2],2));const s=new m.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=m.LinearSRGBColorSpace,e.colorSpace=m.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=s}return this.renderer.domElement}}function hs(i){return new Promise(e=>{const t=new m.ObjectLoader;t.parseAsync(i.scene).then(s=>{const n=new m.AnimationMixer(s);if(i.animations.length>0){const a=i.animations.map(c=>m.AnimationClip.parse(c));n.clipAction(a[0]).play(),n.getRoot().animations=i.animations,n.getRoot().mixer=n}const r=[];i.cameras&&i.cameras.length>0&&i.cameras.forEach(a=>{const o=t.parse(a);r.push(o)}),e({animations:i.animations,model:s,mixer:n,cameras:r})})})}const ds=(i,e,t,s)=>{i.setRenderTarget(s),i.clear(),i.render(e,t)};function ri(i,e,t,s){i.applyMatrix4(new m.Matrix4().makeTranslation(e,-t,-s))}function us(i){i.computeBoundingBox();const e=i.boundingBox,t=(e.max.x-e.min.x)/2,s=(e.max.y-e.min.y)/2;ri(i,t,s,0)}function ps(i,e,t){i.left=e/-2,i.right=e/2,i.top=t/2,i.bottom=t/-2,i.position.x=e/2,i.position.y=t/-2,i.updateProjectionMatrix()}function ms(i,e,t){const s=1.7777777777777777,n=e/t;let r=e,a=t;n>s?r=t*s:a=e/s,i.left=r/-2,i.right=r/2,i.top=a/2,i.bottom=a/-2,i.updateProjectionMatrix()}function fs(){let e="transferControlToOffscreen"in document.createElement("canvas");if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)){const s=navigator.userAgent.match(/version\/(\d+)/i);e=(s?parseInt(s[1]):0)>=17}return e}function gs(i,e,t=!0,s=!1){i.renderOrder=-e;const n=i.material;Array.isArray(n)?n.forEach(r=>{r.colorWrite=t,r.depthWrite=s,r.stencilWrite=!0,r.stencilRef=e,r.stencilFunc=m.AlwaysStencilFunc,r.stencilFail=m.ReplaceStencilOp,r.stencilZFail=m.ReplaceStencilOp,r.stencilZPass=m.ReplaceStencilOp}):(n.colorWrite=t,n.depthWrite=s,n.stencilWrite=!0,n.stencilRef=e,n.stencilFunc=m.AlwaysStencilFunc,n.stencilFail=m.ReplaceStencilOp,n.stencilZFail=m.ReplaceStencilOp,n.stencilZPass=m.ReplaceStencilOp)}function vs(i,e,t=!1){const s=i.material;Array.isArray(s)?s.forEach(n=>{n.stencilWrite=!0,n.stencilRef=e,n.stencilFunc=t?m.NotEqualStencilFunc:m.EqualStencilFunc,n.stencilFail=m.KeepStencilOp,n.stencilZFail=m.KeepStencilOp,n.stencilZPass=m.KeepStencilOp}):(s.stencilWrite=!0,s.stencilRef=e,s.stencilFunc=t?m.NotEqualStencilFunc:m.EqualStencilFunc,s.stencilFail=m.KeepStencilOp,s.stencilZFail=m.KeepStencilOp,s.stencilZPass=m.KeepStencilOp)}function _s(i){i.blending=m.NormalBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.SrcAlphaFactor,i.blendDst=m.OneMinusSrcAlphaFactor,i.needsUpdate=!0}function ys(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.SrcAlphaFactor,i.blendDst=m.OneFactor,i.needsUpdate=!0}function Cs(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.DstColorFactor,i.blendDst=m.OneMinusSrcAlphaFactor,i.needsUpdate=!0}function bs(i){i.blending=m.CustomBlending,i.blendEquation=m.AddEquation,i.blendSrc=m.OneMinusDstColorFactor,i.blendDst=m.OneFactor,i.needsUpdate=!0}let yt=[];function ai(i,e,t=!0){ae.renderer=e.renderer;const s=[];s.push({type:"boolean",prop:"Enabled",value:i.enabled});let n=(a,o)=>{console.log("Default Handle Pass:",a,o)};if(i.name==="EffectPass")i.effects.forEach(a=>{a.uniforms.size>0&&a.uniforms.forEach((o,c)=>{if(c==="map")return;const l=`${a.name.replace("Effect","")} ${c}`;if(o.value===null&&t)s.push({prop:c,title:l,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(o.value.isTexture&&t){const h=o.value,u=ae.renderToBlob(h);s.push({prop:c,title:l,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof o.value=="number"?s.push({prop:c,title:l,type:"number",value:o.value,step:.01}):typeof o.value=="string"?s.push({prop:c,title:l,type:"string",value:o.value}):typeof o.value=="boolean"&&s.push({prop:c,title:l,type:"boolean",value:o.value})})}),n=(a,o)=>{i.effects.forEach(c=>{c.uniforms.size>0&&c.uniforms.forEach((l,h)=>{h===a&&(l.value=o)})})};else if(i.name==="ShaderPass"){const a=i.fullscreenMaterial;for(const o in a.uniforms){if(o==="inputBuffer"||o==="map")continue;const c=a.uniforms[o],l=`${a.name.replace("Material","")} ${o}`;if(c.value===null&&t)s.push({title:l,prop:o,type:"image",value:{offset:[0,0],repeat:[1,1],src:""}});else if(c.value.isTexture&&t){const h=c.value,u=ae.renderToBlob(h);s.push({title:l,prop:o,type:"image",value:{offset:[h.offset.x,h.offset.y],repeat:[h.repeat.x,h.repeat.y],src:u}})}else typeof c.value=="number"?s.push({title:l,prop:o,type:"number",value:c.value,step:.01}):typeof c.value=="string"?s.push({title:l,prop:o,type:"string",value:c.value}):typeof c.value=="boolean"&&s.push({title:l,prop:o,type:"boolean",value:c.value})}n=(o,c)=>{const l=a.uniforms[o];l.value=c}}else return;const r=`${i.name}: ${i.scene.name}`;e.addGroup({title:r,items:s,onUpdate:(a,o)=>{a==="Enabled"?i.enabled=o:n(a,o)}}),yt.push(r)}function Es(i,e){i.passes.forEach(t=>{ai(t,e)})}function Ss(i){yt.forEach(e=>{i.removeGroup(e)}),yt=[]}function xs(i,e,t,s=1024){return new Promise(n=>{const r=e.aspect,a=e.fov,o=e.rotation.clone(),c=t.outputBuffer;e.aspect=1,e.fov=90,e.updateProjectionMatrix();const l=new m.WebGLRenderTarget(s,s,{format:m.RGBAFormat,depthBuffer:!0,stencilBuffer:!1});t.outputBuffer=l,Ce(i,l,e,"nx",t,s).then(()=>{Ce(i,l,e,"ny",t,s).then(()=>{Ce(i,l,e,"nz",t,s).then(()=>{Ce(i,l,e,"px",t,s).then(()=>{Ce(i,l,e,"py",t,s).then(()=>{Ce(i,l,e,"pz",t,s).then(()=>{e.aspect=r,e.fov=a,e.rotation.copy(o),e.updateMatrixWorld(),e.updateProjectionMatrix(),t.outputBuffer=c,l.dispose(),n()})})})})})})})}function Ce(i,e,t,s,n,r){return new Promise(a=>{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(),n.render();const c=new Uint8Array(r*r*4);i.readRenderTargetPixels(e,0,0,r,r,c);const l=document.createElement("canvas");l.width=l.height=r;const h=l.getContext("2d"),u=h.createImageData(r,r);u.data.set(c),h.putImageData(u,0,0);const p=document.createElement("canvas");p.width=p.height=r;const g=p.getContext("2d");g.translate(0,r),g.scale(1,-1),g.drawImage(l,0,0);const C=p.toDataURL("image/png"),_=document.createElement("a");_.href=C,_.download=`${t.name}_${s}.png`,document.body.appendChild(_),_.click(),_.remove(),a()})}const be=Et(["ctrlKey","metaKey","shiftKey","button","pointerId","pointerType","clientX","clientY","pageX","pageY"]),Os=Et(["clientX","clientY","deltaX","deltaY","deltaMode"]),ws=Et(["ctrlKey","metaKey","shiftKey","keyCode"]);function Ts(i,e){i.preventDefault(),Os(i,e)}function Ms(i){i.preventDefault()}function As(i,e,t){for(const s of e)t[s]=i[s]}function Et(i){return function(t,s){const n={type:t.type};As(t,i,n),s(n)}}function rt(i,e){const t=[],s={type:i.type,touches:t};for(let n=0;n<i.touches.length;++n){const r=i.touches[n];t.push({pageX:r.pageX,pageY:r.pageY})}e(s)}const Rs={37:!0,38:!0,39:!0,40:!0};function Ps(i,e){const{keyCode:t}=i;Rs[t]&&(i.preventDefault(),ws(i,e))}const Ds={contextmenu:Ms,mousedown:be,mousemove:be,mouseup:be,pointerdown:be,pointermove:be,pointerup:be,touchstart:rt,touchmove:rt,touchend:rt,wheel:Ts,keydown:Ps};let Is=0;class Ls{id;worker;constructor(e,t,s){this.id=Is++,this.worker=t;const n=a=>{this.worker.postMessage({type:"event",id:this.id,data:a})};t.postMessage({type:"makeProxy",id:this.id});for(const[a,o]of Object.entries(s))e.addEventListener(a,c=>{o(c,n)});function r(){n({type:"resize",left:0,top:0,width:innerWidth,height:innerHeight})}window.addEventListener("resize",r),r()}}class oi extends m.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=ze,e.stopPropagation=ze,this.dispatchEvent(e)}focus(){}getRootNode(){return this}}class Us{targets={};constructor(){this.handleEvent=this.handleEvent.bind(this)}makeProxy(e){const{id:t}=e,s=new oi;this.targets[t]=s}getProxy(e){return this.targets[e]}handleEvent(e){this.targets[e.id]?.handleEvent(e.data)}}class ks{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};onUpdateCallback;playing=!1;rafID=-1;constructor(e,t=!1){this.settings.dev=e,this.settings.editor=t}dispose(){this.pause(),this.components.forEach(e=>e.dispose()),this.components.clear()}detectSettings(){return new Promise(e=>{ti(this.settings.dev,this.settings.editor).then(t=>{this.settings=t,e()})})}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)};addComponent(e,t){this.components.set(e,t)}get debugEnabled(){return this.settings.dev}get isApp(){return!this.editor}set isApp(e){this.editor=!e}get editor(){return this.settings.editor}set editor(e){this.settings.editor=e}}class St{name;debug;editor;broadcastChannel;onMessageHandler;constructor(e,t=!1,s=!1){this.name=e,this.debug=t,this.editor=s,t&&(this.broadcastChannel=new BroadcastChannel(e),this.onMessageHandler=this.messageHandler.bind(this),this.broadcastChannel.addEventListener("message",this.onMessageHandler))}dispose(){this.broadcastChannel?.removeEventListener("message",this.onMessageHandler),this.broadcastChannel?.close()}send(e){if(this.editor&&e.target==="app"||!this.editor&&e.target==="editor")try{this.broadcastChannel?.postMessage(e)}catch(s){console.log("Hermes - Error sending message:"),console.log(s),console.log(e)}}messageHandler(e){const t=e.data;t.target==="app"?this.handleApp(t):this.handleEditor(t)}handleApp(e){}handleEditor(e){}}function Ns(i,e,t,s,n){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*s+i*i*i*n}function Fs(i,e,t){if(i.type!=="bezier"||i.handles.length!==4)throw new Error("Invalid keyframe data for Bézier interpolation.");const[s,n]=i.handles,r=(t-i.position)/(e.position-i.position);return Ns(r,i.value,i.value+s,e.value+n,e.value)}class js extends St{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;constructor(e=!1,t=!1){super("RemoteTheatre",e,t)}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}loadProject(e,t){return this.project=I.getProject(e,{state:t}),new Promise((s,n)=>{this.project?.ready.then(()=>{if(t){const r=t.sheetsById;for(const a in r)this.sheet(a)}s()}).catch(()=>n())})}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 n=this.sheets.get(s);return n!==void 0||(n=this.project?.sheet(e,t),this.sheets.set(s,n)),n}playSheet(e,t,s){return new Promise(n=>{this.sheet(e,s)?.sequence.play(t).then(r=>n(r)),this.send({event:"playSheet",target:"editor",data:{sheet:e,instance:s,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.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,n,r){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const a=this.sheet(e,r);if(a===void 0)return;const c=`${this.getSheetInstance(e,r)}_${t}`;let l=this.sheetObjects.get(c),h=s;l!==void 0&&(h={...s,...l.value}),l=a.object(t,h,{reconfigure:!0}),this.sheetObjects.set(c,l),this.sheetObjectCBs.set(c,n!==void 0?n:ze);function u(g,C,_){if(typeof _=="object")if(Qt(_))g[C]={r:_.r,g:_.g,b:_.b,a:_.a};else for(const E in _){const v=_[E];typeof v=="object"&&u(_,E,v)}}const p=l.onValuesChange(g=>{const C=this.sheetObjectCBs.get(c);if(this.editor){for(const _ in g){const E=g[_];typeof E=="object"&&u(g,_,E)}this.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:c,values:g}}),C&&C(g)}else C&&C(g)});return this.sheetObjectUnsubscribe.set(c,p),l}getSheetObjectKeyframes(e,t,s){const n=this.sheet(e);if(n===void 0)return[];const r=`${e}_${t}`,a=this.sheetObjects.get(r);return a===void 0?[]:n.sequence.__experimental_getKeyframes(a.props[s])}getSheetObjectVectors(e,t){const s=this.sheet(e);if(s===void 0)return[];const n=`${e}_${t}`,r=this.sheetObjects.get(n);if(r===void 0)return[];const a=[],o=s.sequence.__experimental_getKeyframes(r.props.x),c=s.sequence.__experimental_getKeyframes(r.props.y),l=s.sequence.__experimental_getKeyframes(r.props.z),h=new Set;return o.forEach(p=>h.add(p.position)),c.forEach(p=>h.add(p.position)),l.forEach(p=>h.add(p.position)),Array.from(h).sort((p,g)=>p-g).forEach(p=>{const g=(C,_)=>{const E=C.find((x,O)=>x.position<=_&&(C[O+1]?.position||1/0)>_),v=C.find(x=>x.position>_);if(!E)return v?.value||0;if(!v||E.position===_)return E.value;if(E.type==="bezier")return Fs(E,v,_);const y=(_-E.position)/(v.position-E.position);return E.value+y*(v.value-E.value)};a.push({position:p,x:g(o,p),y:g(c,p),z:g(l,p)})}),a}update(e){}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 r=`${t}_${s}`,a=this.sheetObjectUnsubscribe.get(r);a!==void 0&&(this.sheetObjects.delete(r),this.sheetObjectCBs.delete(r),this.sheetObjectUnsubscribe.delete(r),a())}handleApp(e){let t;switch(e.event){case"setSheet":t=this.sheets.get(e.data.sheet),t!==void 0?this.studio?.setSelection([t]):console.log(`Hermes - Can't set Sheet: ${e.data.sheet}`,t);break;case"setSheetObject":t=this.sheetObjects.get(`${e.data.sheet}_${e.data.key}`),t!==void 0?this.studio?.setSelection([t]):console.log(`Hermes - Can't set Sheet Object: ${e.data.sheet}, ${e.data.key}: ${e.data.sheet}_${e.data.key}`,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):console.log(`Hermes - Can't update Sheet Object: ${e.data.sheetObject}, ${e.data.sheet}`,t);break;case"updateTimeline":t=this.sheets.get(e.data.sheet),t!==void 0?t.sequence.position=e.data.position:console.log(`Hermes - Can't update sheet position: ${e.data.sheet}, ${e.data.position}`);break}}handleEditor(e){switch(e.event){case"playSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.play(e.data.value);break;case"pauseSheet":this.sheet(e.data.sheet,e.data.instance)?.sequence.pause();break}}getSheetNames(){const e=[];return this.sheets.forEach((t,s)=>{e.push(s)}),e}handleEditorApp(){if(this.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(n=>{n.length<1||n.forEach(r=>{let a=r.address.sheetId,o="setSheet",c={};switch(r.type){case"Theatre_Sheet_PublicAPI":o="setSheet",c={sheet:r.address.sheetId},this.activeSheet=this.sheets.get(r.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":o="setSheetObject",a+=`_${r.address.objectKey}`,c={id:a,sheet:r.address.sheetId,key:r.address.objectKey},this.activeSheet=this.sheets.get(r.address.sheetId);break}this.send({event:o,target:"app",data:c})})});let e=-1;const t=()=>{if(this.activeSheet!==void 0&&e!==this.activeSheet.sequence.position){e=this.activeSheet.sequence.position;const n=this.activeSheet;this.send({event:"updateTimeline",target:"app",data:{position:e,sheet:n.address.sheetId}})}},s=()=>{t(),requestAnimationFrame(s)};t(),s()}else this.studio?.ui.hide()}}function zs(i){if(i.name==="cameras")return"camera";if(i.name==="interactive")return"interactive";if(i.name==="lights")return"light";if(i.name==="ui")return"ui";if(i.name==="utils")return"utils";const e=i.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function ce(i){const e={name:i.name,type:i.type,uuid:i.uuid,children:[]};return i.children.forEach(t=>{e.children.push(ce(t))}),e}function Lt(i){return{src:i.image?.src??"",offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]}}const Ut={src:"",offset:[0,0],repeat:[1,1]};function Hs(i){const e={};for(const t in i){const s=i[t];if(s!==null&&typeof s=="object"&&Object.prototype.hasOwnProperty.call(s,"value")){const r=s.value;r==null?e[t]={value:Ut}:r.isTexture?e[t]={value:Lt(r)}:e[t]={value:r}}else s==null?e[t]=Ut:s.isTexture?e[t]=Lt(s):e[t]=s}return e}function Bs(i){switch(i){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Ee(i){const e={};for(const t in i){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||Bs(t))continue;const s=typeof i[t],n=i[t];switch(s){case"boolean":case"number":case"string":e[t]=n;break;case"object":if(n!==null)if(n.isTexture)e[t]={src:ae.renderToBlob(n),offset:[n.offset.x,n.offset.y],repeat:[n.repeat.x,n.repeat.y]};else if(n.isUniformNode){const r=n.value;e[t]={__isUniform:!0,value:r?.isTexture?{src:ae.renderToBlob(r),offset:[r.offset.x,r.offset.y],repeat:[r.repeat.x,r.repeat.y]}:r}}else t==="uniforms"?e[t]=Hs(n):t.search("Node")>-1||(e[t]=n);else t==="glslVersion"?e[t]="":t.search("Node")>-1||(e[t]={src:"",offset:[0,0],repeat:[1,1]});break}}return i.anisotropy!==void 0&&(e.anisotropy=i.anisotropy),i.clearcoat!==void 0&&(e.clearcoat=i.clearcoat),i.iridescence!==void 0&&(e.iridescence=i.iridescence),i.dispersion!==void 0&&(e.dispersion=i.dispersion),i.sheen!==void 0&&(e.sheen=i.sheen),i.transmission!==void 0&&(e.transmission=i.transmission),i.transmission!==void 0&&(e.transmission=i.transmission),e}function at(i){i.updateMatrix();const e={name:i.name,type:i.type,uuid:i.uuid,visible:i.visible,matrix:i.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};i.animations.forEach(s=>{e.animations.push({name:s.name,duration:s.duration,blendMode:s.blendMode})});const t=i.type.toLowerCase();if(t.search("mesh")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else if(t.search("points")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else if(t.search("line")>-1){const s=i;if(Array.isArray(s.material)){const n=[];s.material.forEach(r=>{n.push(Ee(r))}),e.material=n}else e.material=Ee(s.material)}else t.search("camera")>-1?i.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:i.fov,zoom:i.zoom,near:i.near,far:i.far,focus:i.focus,aspect:i.aspect,filmGauge:i.filmGauge,filmOffset:i.filmOffset}:i.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:i.zoom,near:i.near,far:i.far,left:i.left,right:i.right,top:i.top,bottom:i.bottom}):t.search("light")>-1&&(e.lightInfo={color:i.color,intensity:i.intensity,decay:i.decay,distance:i.distance,angle:i.angle,penumbra:i.penumbra,groundColor:i.groundColor,width:i.width,height:i.height});return e}function Vs(i,e){const t=e.split(".");switch(t.length){case 1:return i[t[0]];case 2:return i[t[0]][t[1]];case 3:return i[t[0]][t[1]][t[2]];case 4:return i[t[0]][t[1]][t[2]][t[3]];case 5:return i[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return i[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function Gs(i,e){for(const t in e)i[t]=e[t]}function V(i,e,t){if(i===void 0){console.log(`Hermes - Can't set props: ${e}`,t);return}const s=e.split("."),n=s.length;if(typeof t!="object")switch(n){case 1:i[s[0]]=t;break;case 2:i[s[0]][s[1]]=t;break;case 3:i[s[0]][s[1]][s[2]]=t;break;case 4:i[s[0]][s[1]][s[2]][s[3]]=t;break;case 5:i[s[0]][s[1]][s[2]][s[3]][s[4]]=t;break}else{let a;switch(n){case 1:a=i[s[0]];break;case 2:a=i[s[0]][s[1]];break;case 3:a=i[s[0]][s[1]][s[2]];break;case 4:a=i[s[0]][s[1]][s[2]][s[3]];break;case 5:a=i[s[0]][s[1]][s[2]][s[3]][s[4]];break}a!=null?Gs(a,t):console.log(`Hermes - Can't set props because target isn't found: ${e}`,t)}}function li(i){return new Promise((e,t)=>{const s=new Image;s.onload=()=>{const n=new m.Texture(s);n.wrapS=m.RepeatWrapping,n.wrapT=m.RepeatWrapping,n.needsUpdate=!0,e(n)},s.onerror=t,s.src=i})}var L=(i=>(i.CUSTOM="ToolEvents::custom",i.SELECT_DROPDOWN="ToolEvents::selectDropdown",i.DRAG_UPDATE="ToolEvents::dragUpdate",i.ADD_SCENE="ToolEvents::addScene",i.REFRESH_SCENE="ToolEvents::refreshScene",i.REMOVE_SCENE="ToolEvents::removeScene",i.SET_SCENE="ToolEvents::setScene",i.SET_OBJECT="ToolEvents::setObject",i.CLEAR_OBJECT="ToolEvents::clearObject",i.ADD_CAMERA="ToolEvents::addCamera",i.REMOVE_CAMERA="ToolEvents::removeCamera",i.ADD_GROUP="ToolEvents::addGroup",i.REMOVE_GROUP="ToolEvents::removeGroup",i.ADD_SPLINE="ToolEvents::addSpline",i.ADD_RENDERER="ToolEvents::addRenderer",i.UPDATE_RENDERER="ToolEvents::updateRenderer",i))(L||{});class Ws extends St{name;canvas=null;inputElement=null;scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;renderTargetsResize=new Map;groups=new Map;_listeners={};constructor(e,t=!1,s=!1){super("RemoteThree",t,s),this.name=e}dispose(){this.scenes.forEach(e=>{Q(e)}),this.scenes.clear(),this.scene&&Q(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}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 n=s[e];if(n!==void 0){const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const s=t[e.type];if(s!==void 0){const n={...e,target:this},r=s.slice(0);for(let a=0,o=r.length;a<o;a++)r[a].call(this,n)}}getObjectByUUID(e){const t=e.split(".")[0],s=this.scenes.get(t);if(s!==void 0)return s.getObjectByProperty("uuid",e)}getObject(e){if(!this.debug)return;this.renderer!==void 0&&(ae.renderer=this.renderer);const t=this.getObjectByUUID(e);t&&this.setObject(t)}setObject(e){this.renderer!==void 0&&(ae.renderer=this.renderer);const t=at(e);this.dispatchEvent({type:"ToolEvents::setObject",value:t})}requestMethod(e,t,s,n){const r=this.getObjectByUUID(e);if(r)try{n!==void 0?Vs(r,n)[t](s):r[t](s)}catch(a){console.log("Hermes - Error requesting method:",e,t,s),console.log(a)}}updateObject(e,t,s){this.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:s}})}createTexture(e,t,s){this.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:s}})}onUpdateObject(e,t,s){const n=this.getObjectByUUID(e);n&&V(n,t,s)}onCreateTexture(e,t,s){const n=this.getObjectByUUID(e);if(n){const r=a=>{const o=t.split(".");switch(o.length){case 1:n[o[0]]=a;break;case 2:n[o[0]][o[1]]=a;break;case 3:n[o[0]][o[1]][o[2]]=a;break;case 4:n[o[0]][o[1]][o[2]][o[3]]=a;break;case 5:n[o[0]][o[1]][o[2]][o[3]][o[4]]=a;break}n.material.needsUpdate=!0};s.src.length>0?li(s.src).then(a=>{a.offset.set(s.offset[0],s.offset[1]),a.repeat.set(s.repeat[0],s.repeat[1]),r(a)}):r(null)}}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,s){this.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:s})})}addSplineCurve(e){setTimeout(()=>{this.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}addSplineObject(e){setTimeout(()=>{this.send({event:"addSpline",target:"editor",data:JSON.stringify(e)})},1)}setRenderer(e,t=null){if(this.renderer=e,this.canvas=e.domElement,this.inputElement=t!==null?t:this.canvas,!this.debug)return;const s=`#${e.getClearColor(new w.Color).getHexString()}`;this.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:w.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure,type:e.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}updateRenderer(e){this.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.debug))return;Ne(),Me(e);const t=ce(e);this.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.debug)return;const t=this.scenes.get(e);if(t!==void 0){const s=ce(t);this.send({event:"refreshScene",target:"app",data:s})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.debug))return;const t=ce(e);this.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scene!==void 0&&this.scene.uuid.search(e)>-1?this.scene:(this.scenes.forEach((s,n)=>{e.search(n)>-1&&(t=s)}),t)}setScene(e){if(e===void 0||(this.scene=e,!this.debug))return;this.renderer!==void 0&&(ae.renderer=this.renderer),Ne(),Me(e);const t=ce(e);this.send({event:"setScene",target:"editor",data:t})}requestSize(){this.send({event:"requestSize",target:"app"})}requestRenderer(){this.send({event:"requestRenderer",target:"app"})}requestScene(){this.send({event:"requestScene",target:"app"})}addCamera(e){if(!this.debug)return;const t=at(e);this.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.debug)return;const t=at(e);this.send({event:"removeCamera",target:"editor",data:t})}handleApp(e){switch(e.event){case"refreshScene":this.send({event:"refreshScene",target:"editor",data:ce(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,w.ColorManagement.enabled=e.data.colorManagement);break;case"requestRenderer":if(this.renderer!==void 0){const t=`#${this.renderer.getClearColor(new w.Color).getHexString()}`;this.send({event:"addRenderer",target:"editor",data:{autoClear:this.renderer.autoClear,autoClearColor:this.renderer.autoClearColor,autoClearDepth:this.renderer.autoClearDepth,autoClearStencil:this.renderer.autoClearStencil,outputColorSpace:this.renderer.outputColorSpace,localClippingEnabled:this.renderer.localClippingEnabled,clearColor:t,clearAlpha:this.renderer.getClearAlpha(),colorManagement:w.ColorManagement.enabled,toneMapping:this.renderer.toneMapping,toneMappingExposure:this.renderer.toneMappingExposure,type:this.renderer.isWebGLRenderer?"WebGLRenderer":"WebGPURenderer"}})}break;case"requestScene":this.scenes.forEach(t=>{Ne(),Me(t),this.send({event:"addScene",target:"editor",data:ce(t)})}),this.scene!==void 0&&(this.renderer!==void 0&&(ae.renderer=this.renderer),Ne(),Me(this.scene),this.send({event:"setScene",target:"editor",data:ce(this.scene)}));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"addScene":this.dispatchEvent({type:"ToolEvents::addScene",value:e.data});break;case"refreshScene":this.dispatchEvent({type:"ToolEvents::refreshScene",value:e.data});break;case"removeScene":this.dispatchEvent({type:"ToolEvents::removeScene",value:e.data});break;case"setScene":this.dispatchEvent({type:"ToolEvents::setScene",value:e.data});break;case"addCamera":this.dispatchEvent({type:"ToolEvents::addCamera",value:e.data});break;case"removeCamera":this.dispatchEvent({type:"ToolEvents::removeCamera",value:e.data});break;case"addGroup":this.dispatchEvent({type:"ToolEvents::addGroup",value:e.data});break;case"removeGroup":this.dispatchEvent({type:"ToolEvents::removeGroup",value:e.data});break;case"addSpline":this.dispatchEvent({type:"ToolEvents::addSpline",value:e.data});break;case"addRenderer":this.dispatchEvent({type:"ToolEvents::addRenderer",value:e.data})}}messageHandler(e){const t=e.data;if(t.event==="updateObject"){this.onUpdateObject(t.data.uuid,t.data.key,t.data.value);return}else if(t.event==="createTexture"){this.onCreateTexture(t.data.uuid,t.data.key,t.data.value);return}else if(t.event==="requestSize"){t.target==="app"?this.send({event:"requestSize",target:"editor",data:{width:this.width,height:this.height}}):this.scenes.forEach(s=>{s.resize!==void 0&&s.resize(t.data.width,t.data.height)});return}t.target==="app"?this.handleApp(t):this.handleEditor(t)}addRT(e,t=!0,s){if(!this.renderer)return;let n;this.renderer instanceof w.WebGPURenderer?n=new w.RenderTarget(32,32,s):n=new w.WebGLRenderTarget(32,32,s),n.texture.name=e,this.renderTargets.set(e,n),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((r,a)=>{this.renderTargetsResize.get(a)&&r.setSize(e*s,t*s)});const n=!(this.renderer?.domElement instanceof OffscreenCanvas);this.renderer?.setSize(e,t,n)}set dpr(e){this.renderer?.setPixelRatio(de(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}}function xt(i){return i.title.search("<")>-1?d.jsx("button",{className:"svg",dangerouslySetInnerHTML:{__html:i.title}}):d.jsx("button",{children:i.title})}const Ys=d.jsxs("svg",{className:"closeIcon",width:"14",height:"14",fill:"none",stroke:"#666666",strokeMiterlimit:"10",children:[d.jsx("circle",{cx:"7",cy:"7",r:"6"}),d.jsx("line",{x1:"4",y1:"4",x2:"10",y2:"10"}),d.jsx("line",{x1:"4",y1:"10",x2:"10",y2:"4"})]}),qs=d.jsx("svg",{className:"dragIcon",width:"14",height:"14",fill:"#666666",stroke:"none",children:d.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
31
31
  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
32
- C11,8.22,10.74,8,10.43,8z`})});function ci(i){return d.jsx("li",{className:`reorder-item ${i.draggingIndex===i.index?"dragging":""}`,draggable:!0,onDragStart:()=>i.onDragStart(i.index),onDragOver:e=>{e.preventDefault(),i.onDragOver(i.index)},onDragEnd:i.onDragEnd,children:d.jsxs("div",{children:[$s,d.jsx("span",{children:i.title}),d.jsx("button",{className:"closeIcon",onClick:()=>i.onDelete(i.index),children:qs})]})})}function hi(i){const[e,t]=b.useState(!1),[s,n]=b.useState(i.options),[r,a]=b.useState(null),o=g=>{i.onDragComplete(g),n(g)},c=g=>{const C=[...s];C.splice(g,1),o(C)},l=g=>{a(g)},h=g=>{if(r===g||r===null)return;const C=[...s],_=C.splice(r,1)[0];C.splice(g,0,_),a(g),n(C)},u=()=>{i.onDragComplete(s),a(null)};let p="dropdown draggable";return i.subdropdown&&(p+=" subdropdown"),d.jsxs("div",{className:p,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[d.jsx(xt,{title:i.title}),d.jsx("ul",{className:"reorder-list",style:{display:e?"block":"none"},children:s.map((g,C)=>d.jsx(ci,{title:g,index:C,draggingIndex:r,onDelete:c,onDragStart:l,onDragOver:h,onDragEnd:u},g))})]})}function di(i){const[e,t]=b.useState(!1),s=[];i.options.map((r,a)=>{i.onSelect!==void 0&&(r.onSelect=i.onSelect),s.push(d.jsx(ui,{option:r},a))});let n="dropdown";return i.subdropdown&&(n+=" subdropdown"),d.jsxs("div",{className:n,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[d.jsx(xt,{title:i.title}),d.jsx("ul",{style:{visibility:e?"visible":"hidden"},children:s})]})}function ui(i){const{option:e}=i,[t,s]=b.useState("");let n;switch(e.type){case"draggable":n=d.jsx(hi,{title:e.title,options:e.value,onDragComplete:r=>{e.onDragComplete!==void 0&&e.onDragComplete(r)},subdropdown:!0});break;case"dropdown":n=d.jsx(di,{title:e.title,options:e.value,onSelect:e.onSelect,subdropdown:!0});break;case"option":n=d.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 d.jsx("li",{className:t===e.title?"selected":"",children:n},Y())}function Ae(i){const[e,t]=b.useState(i.open!==void 0?i.open:!1),[s,n]=b.useState(i.visible!==void 0?i.visible:!1),r=!e||i.children===void 0,a=()=>{i.three.dispatchEvent({type:L.REMOVE_SCENE,value:i.scene})};return d.jsxs("div",{className:`accordion ${r?"hide":""}`,children:[d.jsxs("button",{className:"toggle",onClick:()=>{const o=!e;i.onToggle!==void 0&&i.onToggle(o),t(o)},children:[d.jsx("p",{className:`status ${e?"open":""}`,children:"Toggle"}),d.jsx("p",{className:"label",children:He(i.label)})]}),i.onRefresh?d.jsxs(d.Fragment,{children:[d.jsx("button",{className:"visibility",style:{opacity:s?1:.25},onClick:()=>{const c=i.three.getScene(i.scene.uuid);if(c){const l=!c.visible;c.visible=l,n(l)}}}),d.jsx("button",{className:"refresh",onClick:i.onRefresh}),d.jsx("button",{className:"remove",onClick:a})]}):null,i.button,d.jsx("div",{className:e?"open":"",children:d.jsx("div",{children:i.children})})]})}function Ot(i){if(i.child===void 0)return console.log("Hermes - No child attached"),null;const e=b.useRef(null),[t,s]=b.useState(!1),n=i.child.children.length>0,r=[];return i.child.children.length>0&&i.child.children.map((a,o)=>{r.push(d.jsx(Ot,{child:a,three:i.three},o))}),b.useEffect(()=>{if(i.child){const a=i.child.uuid.split(".")[0],o=i.three.getScene(a);if(o!==null)try{const c=o.getObjectByProperty("uuid",i.child.uuid);c!==void 0?e.current.style.opacity=c.visible?"1":"0.25":console.log(`Hermes - Can't find child: ${i.child.uuid}`)}catch(c){console.log("Error looking for child:",c),console.log(i.child),console.log(i.three.scenes),console.log(o)}else console.log(`Hermes (ChildObject) - Can't find Scene: ${a} with child UUID: ${i.child.uuid}`,i.three.scenes,i.three.scene,o)}},[t]),d.jsxs("div",{className:"childObject",children:[d.jsxs("div",{className:"child",children:[n?d.jsx("button",{className:"status",style:{backgroundPositionX:t?"-14px":"2px"},onClick:()=>{s(!t)}}):null,d.jsx("button",{className:"name",style:{left:n?"20px":"5px"},onClick:()=>{i.child!==void 0?(i.three.getObject(i.child.uuid),!t&&n&&s(!0)):console.log("Hermes - No child attached...")},children:i.child.name.length>0?`${i.child.name} (${i.child.type})`:`${i.child.type}::${i.child.uuid}`}),d.jsx("button",{className:"visibility",ref:e,onClick:()=>{if(i.child){const a=i.three.getScene(i.child.uuid);if(a!==null){const o=a.getObjectByProperty("uuid",i.child.uuid);if(o!==void 0){const c="visible",l=!o.visible;e.current.style.opacity=l?"1":"0.25",i.three.updateObject(i.child.uuid,c,l),V(o,c,l)}else console.log(`Hermes - Couldn't find object: ${i.child.uuid}`,a)}else console.log(`Hermes - Couldn't find object in scene: ${i.child.uuid}, ${i.child.name}`)}}}),d.jsx("div",{className:`icon ${Hs(i.child)}`})]}),d.jsx("div",{className:t?"open":"",children:d.jsx("div",{className:"container",children:r})})]})}function $e(i){const e=[];return i.child?.children.map((t,s)=>{e.push(d.jsx(Ot,{child:t,scene:i.scene,three:i.three},s))}),d.jsx("div",{className:`scene ${i.class!==void 0?i.class:""}`,children:e})}function Fe(i){const[e,t]=b.useState(i.defaultValue);return b.useEffect(()=>{let s=!1,n=-1,r=0,a=i.defaultValue,o=!1;const c=g=>{o=g.ctrlKey},l=g=>{s=!0,r=Number(i.input.current?.value),n=g.clientX,document.addEventListener("mouseup",u,!1),document.addEventListener("mousemove",h,!1),document.addEventListener("contextmenu",u,!1)},h=g=>{if(!s)return;const C=i.step!==void 0?i.step:1,_=(g.clientX-n)*C*(o?10:1);a=Number((r+_).toFixed(4)),i.min!==void 0&&(a=Math.max(a,i.min)),i.max!==void 0&&(a=Math.min(a,i.max)),i.onChange!==void 0&&i.onChange(a),t(a)},u=()=>{s=!1,document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u)},p=g=>{const C=Number(g.target.value);i.onChange!==void 0&&i.onChange(C),t(C)};return i.label.current?.addEventListener("mousedown",l,!1),i.sliderRef!==void 0&&i.sliderRef.current?.addEventListener("input",p),document.addEventListener("keydown",c,!1),document.addEventListener("keyup",c,!1),()=>{i.label.current?.removeEventListener("mousedown",l),i.sliderRef!==void 0&&i.sliderRef.current?.removeEventListener("input",p),document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u),document.removeEventListener("keydown",c),document.addEventListener("keyup",c,!1)}},[]),e}function ve(i){const e=b.useRef(null),t=b.useRef(null),[s,n]=b.useState(i.value);return Fe({label:i.labelRef,input:e,sliderRef:t,defaultValue:s,min:i.min,max:i.max,step:i.step,onChange:r=>{n(r),i.onChange!==void 0&&i.onChange(i.prop,r)}}),d.jsxs(d.Fragment,{children:[i.type==="number"&&d.jsx("input",{alt:i.alt,className:i.className,ref:e,type:"number",value:s,min:i.min,max:i.max,step:i.step,disabled:i.disabled,name:Y(),onChange:r=>{if(n(r.target.value),r.target.value.length===0)return;const a=Number(r.target.value);isNaN(a)||i.onChange!==void 0&&i.onChange(i.prop,a)}}),i.type==="range"&&d.jsxs(d.Fragment,{children:[d.jsx("input",{type:"text",value:s.toString(),disabled:i.disabled,ref:e,className:"min",name:Y(),onChange:r=>{if(r.target.value.length===0)return;const a=Number(r.target.value);isNaN(a)||(n(a),i.onChange!==void 0&&i.onChange(i.prop,a))}}),d.jsx("input",{disabled:i.disabled,type:"range",value:s,min:i.min,max:i.max,step:i.step,ref:t,name:Y(),onChange:ze})]})]})}function Zs(i){const e=b.useRef(null),t=b.useRef(null),s=b.useRef(null),n=b.useRef(null),r=b.useRef(null),a=b.useRef(null),o=b.useRef(null),c=b.useRef(null),l=b.useRef(null),h=b.useRef(null),[u,p]=b.useState(i.value.x),[g,C]=b.useState(i.value.y),[_,E]=b.useState({min:Math.min(i.min,Math.min(i.value.x,i.value.y)),max:Math.max(i.max,Math.max(i.value.x,i.value.y))}),[v,y]=b.useState(!1);Fe({label:o,input:e,defaultValue:u,min:_.min,max:_.max,step:.01,onChange:A=>{p(A),i.onChange({target:{value:{x:A,y:g}}})}}),Fe({label:c,input:t,defaultValue:g,min:_.min,max:_.max,step:.01,onChange:A=>{C(A),i.onChange({target:{value:{x:u,y:A}}})}}),Fe({label:l,input:s,defaultValue:_.min,min:_.min-1,max:_.max+1,step:.01,onChange:A=>{E({min:A,max:_.max})}}),Fe({label:h,input:n,defaultValue:_.max,min:_.min-1,max:_.max+1,step:.01,onChange:A=>{E({min:_.min,max:A})}});function x(){v||(window.addEventListener("mousemove",S),window.addEventListener("mouseup",O),y(!0))}function O(){window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",O),y(!1)}function S(A){const j=r.current.getBoundingClientRect(),ee=de(0,99,A.clientX-j.left)/99,oe=1-de(0,99,A.clientY-j.top)/99,ue=X(Re(_.min,_.max,ee),3),_e=X(Re(_.min,_.max,oe),3);i.onChange({target:{value:{x:ue,y:_e}}}),p(ue),C(_e)}function T(){const A=Number(s.current.value);E({min:A,max:_.max}),u<A&&p(de(A,_.max,u)),g<A&&C(de(A,_.max,g))}function M(){const A=Number(n.current.value);E({min:_.min,max:A}),u>A&&p(de(_.min,A,u)),g>A&&C(de(_.min,A,g))}b.useEffect(()=>{a.current.style.left=`${Xe(_.min,_.max,u)*100}%`,a.current.style.top=`${(1-Xe(_.min,_.max,g))*100}%`},[_,u,g]);const U=i.step!==void 0?i.step:.01;return d.jsxs("div",{className:"vector2",children:[d.jsxs("div",{className:"fields",children:[d.jsxs("div",{children:[d.jsx("span",{ref:o,children:"X"}),d.jsx("input",{ref:e,type:"number",value:u,min:_.min,max:_.max,step:U,name:Y(),onChange:A=>{if(p(A.target.value),A.target.value.length===0)return;const j=Number(A.target.value);isNaN(j)||(i.onChange({target:{value:{x:j,y:g}}}),j<_.min&&E({min:j,max:_.max}))}})]}),d.jsxs("div",{children:[d.jsx("span",{ref:c,children:"Y"}),d.jsx("input",{ref:t,type:"number",value:g,min:_.min,max:_.max,step:U,name:Y(),onChange:A=>{if(C(A.target.value),A.target.value.length===0)return;const j=Number(A.target.value);isNaN(j)||(i.onChange({target:{value:{x:u,y:j}}}),j>_.max&&E({min:_.min,max:j}))}})]}),d.jsxs("div",{children:[d.jsx("span",{ref:l,children:"Min"}),d.jsx("input",{ref:s,type:"number",value:_.min,step:U,name:Y(),onChange:T})]}),d.jsxs("div",{children:[d.jsx("span",{ref:h,children:"Max"}),d.jsx("input",{ref:n,type:"number",value:_.max,step:U,name:Y(),onChange:M})]})]}),d.jsxs("div",{className:"input",ref:r,onMouseDown:x,onMouseUp:O,children:[d.jsx("div",{className:"x"}),d.jsx("div",{className:"y"}),d.jsx("div",{className:"pt",ref:a})]})]})}function kt(i){const e=i.value.x!==void 0&&i.value.y!==void 0&&i.value.z!==void 0,t=i.value.isEuler!==void 0,s=i.value.elements!==void 0,n=i.step!==void 0?i.step:.01,r=[];if(t){const a=b.useMemo(()=>i.value,[]);["_x","_y","_z"].forEach(c=>{const l=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("span",{ref:l,children:c.substring(1).toUpperCase()}),d.jsx(ve,{value:$.radToDeg(a[c]),type:"number",prop:c,step:.1,labelRef:l,onChange:(h,u)=>{a[h]=$.degToRad(u),i.onChange({target:{value:a}})}})]},c))})}else if(e){const a=b.useMemo(()=>i.value,[]),o=(l,h)=>{a[l]=h,i.onChange({target:{value:a}})};["x","y","z"].forEach(l=>{const h=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("label",{ref:h,children:l.toUpperCase()}),d.jsx(ve,{value:a[l],type:"number",prop:l,step:n,labelRef:h,onChange:o})]},l))})}else if(s){const a=b.useMemo(()=>i.value,[]),o=(c,l)=>{const h=Number(c);a.elements[h]=l,i.onChange({target:{value:a}})};for(let c=0;c<9;c++){const l=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("label",{ref:l,children:c+1}),d.jsx(ve,{value:a.elements[c],type:"number",prop:c.toString(),step:n,labelRef:l,onChange:o})]},c.toString()))}}return d.jsx("div",{className:"grid3",children:r},Math.random().toString())}function Ks(i){const e=i.value.x!==void 0,t=i.step!==void 0?i.step:.01,s=[];if(e){const n=b.useMemo(()=>i.value,[]),r=(o,c)=>{n[o]=c,i.onChange({target:{value:n}})};["x","y","z","w"].forEach(o=>{const c=b.useRef(null);s.push(d.jsxs("div",{children:[d.jsx("label",{ref:c,children:o.toUpperCase()}),d.jsx(ve,{value:n[o],type:"number",prop:o,step:t,labelRef:c,onChange:r})]},o))})}else{const n=b.useMemo(()=>i.value,[]),r=(a,o)=>{const c=Number(a);n.elements[c]=o,i.onChange({target:{value:n}})};for(let a=0;a<16;a++){const o=b.useRef(null);s.push(d.jsxs("div",{children:[d.jsx("span",{ref:o,children:a+1}),d.jsx(ve,{value:n.elements[a],type:"number",prop:a.toString(),step:t,labelRef:o,onChange:r})]},a.toString()))}}return d.jsx("div",{className:"grid4",children:s})}function Xs(i){return!(i==="defaultAttributeValues"||i==="forceSinglePass"||i==="linecap"||i==="linejoin"||i==="linewidth"||i==="normalMapType"||i==="precision"||i==="shadowSide"||i==="uniformsGroups"||i==="uniformsNeedUpdate"||i==="userData"||i==="version"||i==="wireframeLinecap"||i==="wireframeLinejoin"||i==="wireframeLinewidth"||i.slice(0,4)==="clip"||i.slice(0,7)==="polygon"||i.slice(0,7)==="stencil"||i.slice(0,2)==="is")}function Qs(i){switch(i){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 i}function et(i){switch(i){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 i}function pi(i){const e=i.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 Js(){const i=document.createElement("input");return i.type="file",new Promise((e,t)=>{i.addEventListener("change",function(){if(i.files===null)t();else{const s=i.files[0],n=new FileReader;n.onload=function(r){e(r.target.result)},n.readAsDataURL(s)}}),i.click()})}const en=[{title:"Front",value:m.FrontSide},{title:"Back",value:m.BackSide},{title:"Double",value:m.DoubleSide}],tn=[{title:"No Blending",value:m.NoBlending},{title:"Normal",value:m.NormalBlending},{title:"Additive",value:m.AdditiveBlending},{title:"Subtractive",value:m.SubtractiveBlending},{title:"Multiply",value:m.MultiplyBlending},{title:"Custom",value:m.CustomBlending}],sn=[{title:"Add",value:m.AddEquation},{title:"Subtract",value:m.SubtractEquation},{title:"Reverse Subtract",value:m.ReverseSubtractEquation},{title:"Min",value:m.MinEquation},{title:"Max",value:m.MaxEquation}],nn=[{title:"Zero",value:m.ZeroFactor},{title:"One",value:m.OneFactor},{title:"Src Color",value:m.SrcColorFactor},{title:"One Minus Src Color",value:m.OneMinusSrcColorFactor},{title:"Src Alpha",value:m.SrcAlphaFactor},{title:"One Minus Src Alpha",value:m.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:m.DstAlphaFactor},{title:"One Minus Dst Alpha",value:m.OneMinusDstAlphaFactor},{title:"Dst Color",value:m.DstColorFactor},{title:"One Minus Dst Color",value:m.OneMinusDstColorFactor},{title:"Src Alpha Saturate",value:m.SrcAlphaSaturateFactor},{title:"Constant Color",value:m.ConstantColorFactor},{title:"One Minus Constant Color",value:m.OneMinusConstantColorFactor},{title:"Constant Alpha",value:m.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:m.OneMinusConstantAlphaFactor}],rn=[{title:"Zero",value:m.ZeroFactor},{title:"One",value:m.OneFactor},{title:"Src Color",value:m.SrcColorFactor},{title:"One Minus Src Color",value:m.OneMinusSrcColorFactor},{title:"Src Alpha",value:m.SrcAlphaFactor},{title:"One Minus Src Alpha",value:m.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:m.DstAlphaFactor},{title:"One Minus Dst Alpha",value:m.OneMinusDstAlphaFactor},{title:"Dst Color",value:m.DstColorFactor},{title:"One Minus Dst Color",value:m.OneMinusDstColorFactor},{title:"Constant Color",value:m.ConstantColorFactor},{title:"One Minus Constant Color",value:m.OneMinusConstantColorFactor},{title:"Constant Alpha",value:m.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:m.OneMinusConstantAlphaFactor}];function Pe(i,e){i.needsUpdate=!0,i.type="option",i.options=e}function an(i,e,t,s){return{type:"boolean",title:et(i),prop:i,value:e,needsUpdate:!0,onChange:(n,r)=>{s.updateObject(t.uuid,`material.${i}`,r),s.updateObject(t.uuid,"material.needsUpdate",!0);const a=s.getScene(t.uuid);if(a!==null){const o=a.getObjectByProperty("uuid",t.uuid);V(o,`material.${i}`,r)}}}}function on(i,e,t,s){const n={type:"number",title:et(i),prop:i,value:e,min:void 0,max:void 0,step:.01,needsUpdate:!0,onChange:(r,a)=>{s.updateObject(t.uuid,`material.${i}`,a),s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const c=o.getObjectByProperty("uuid",t.uuid);V(c,`material.${i}`,a)}}};switch(i){case"blending":Pe(n,tn);break;case"blendDst":Pe(n,rn);break;case"blendEquation":Pe(n,sn);break;case"blendSrc":Pe(n,nn);break;case"side":Pe(n,en);break}return pi(i)&&(n.value=Number(e),n.type="range",n.min=Math.min(0,n.value),n.max=Math.max(1,n.value),n.step=.01),n}function ln(i,e,t,s){const n={type:"string",title:et(i),prop:i,value:e,needsUpdate:!0,onChange:(a,o)=>{s.updateObject(t.uuid,`material.${i}`,o),s.updateObject(t.uuid,"material.needsUpdate",!0);const c=s.getScene(t.uuid);if(c!==null){const l=c.getObjectByProperty("uuid",t.uuid);V(l,`material.${i}`,o)}},onKeyDown:a=>{}};return(i==="vertexShader"||i==="fragmentShader")&&(n.type="field",n.disabled=!1,n.latest=n.value,n.onChange=(a,o)=>{n.latest=o,s.updateObject(t.uuid,`material.${i}`,o);const c=s.getScene(t.uuid);if(c!==null){const l=c.getObjectByProperty("uuid",t.uuid);V(l,`material.${i}`,o)}},n.onKeyDown=a=>{if(a.key==="Enter"&&(a.altKey||a.metaKey)){s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const c=o.getObjectByProperty("uuid",t.uuid);V(c,"material.needsUpdate",!0)}}}),n}function cn(i){return i.x!==void 0&&i.y!==void 0&&i.z===void 0}function hn(i){return i.x!==void 0&&i.y!==void 0&&i.z!==void 0&&i.w===void 0}function dn(i){return i.x!==void 0&&i.y!==void 0&&i.z!==void 0&&i.w!==void 0}function Ct(i){i.sort((e,t)=>e.title<t.title?-1:e.title>t.title?1:0)}function Te(i,e,t,s,n="",r=!1){const a=et(i).split(".")[0].replaceAll("[","").replaceAll("]",""),o=n.length>0?`${n}.${i}`:i,c=typeof e;if(c==="object"&&e!==null&&e.__isUniform===!0)return Te(`${i}.value`,e.value,t,s,n,r);if(c==="boolean"||c==="string")return{title:a,prop:o,type:c,value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(c==="number"){const l={title:a,prop:o,type:"number",value:e,step:.01,disabled:r,onChange:(h,u)=>{s.updateObject(t.uuid,`material.${o}`,u);const p=s.getScene(t.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",t.uuid);V(g,`material.${o}`,u)}}};return pi(a)&&(l.type="range",l.min=0,l.max=1),l}else{if(e.isColor)return{title:a,prop:o,type:"color",value:e,disabled:r,onChange:(l,h)=>{const u=new m.Color(h);s.updateObject(t.uuid,`material.${o}`,u);const p=s.getScene(t.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",t.uuid);V(g,`material.${o}`,u)}}};if(Array.isArray(e)){const l=[];for(const h in e){const u=e[h],p=`[${h.toString()}]`;if(u.value!==void 0){const g=Te(`${p}.value`,u.value,t,s,o,r);g!==void 0&&l.push(g)}else{const g=Te(p,u,t,s,o,r);g!==void 0&&l.push(g)}}if(l.length>0)return Ct(l),{title:a,items:l}}else{if(cn(e))return{title:a,prop:o,type:"vector2",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(hn(e))return{title:a,prop:o,type:"grid3",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(dn(e))return{title:a,prop:o,type:"grid4",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(e.isEuler)return{title:a,prop:o,type:"euler",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(e.src!==void 0)return{title:a,type:"image",value:e,disabled:r,onChange:(l,h)=>{const u=Qs(i),p=n.length>0?`${n}.${u}`:u;s.createTexture(t.uuid,`material.${p}`,h);const g=s.getScene(t.uuid);if(g!==null){const C=g.getObjectByProperty("uuid",t.uuid);if(C!==void 0){const _=E=>{const v=C.material,y=p.split(".");switch(y.length){case 1:v[y[0]]=E;break;case 2:v[y[0]][y[1]]=E;break;case 3:v[y[0]][y[1]][y[2]]=E;break;case 4:v[y[0]][y[1]][y[2]][y[3]]=E;break;case 5:v[y[0]][y[1]][y[2]][y[3]][y[4]]=E;break}v.needsUpdate=!0};h.src.length>0?li(h.src).then(E=>{E.offset.set(h.offset[0],h.offset[1]),E.repeat.set(h.repeat[0],h.repeat[1]),_(E)}):_(null)}}}};if(e.elements!==void 0)return{title:a,prop:o,type:e.elements.length>9?"grid4":"grid3",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};{const l=[],h=i==="defines"||i==="extensions";try{for(const u in e){const p=e[u];if(p!==void 0)if(p.value!==void 0){const g=Te(`${u}.value`,p.value,t,s,o,h);g!==void 0&&l.push(g)}else{const g=Te(u,p,t,s,o,h);g!==void 0&&l.push(g)}}}catch{console.log("Hermes - Issue cycling through material object:",i,e)}if(l.length>0)return Ct(l),{title:a,items:l}}}}}function Nt(i,e,t){const s=[];for(const n in i){if(!Xs(n)||n.search("Node")>-1||i[n]instanceof w.ComputeNode)continue;const r=typeof i[n],a=i[n];if(r==="boolean")s.push(an(n,a,e,t));else if(r==="number")s.push(on(n,a,e,t));else if(r==="string")s.push(ln(n,a,e,t));else if(r==="object"){const o=Te(n,a,e,t);o!==void 0&&s.push(o)}else a!==void 0&&console.log("Hermes - Other Material Prop Type:",n,r,a)}return Ct(s),s.push({title:"Update Material",type:"button",onChange:()=>{t.updateObject(e.uuid,"material.needsUpdate",!0);const n=t.getScene(e.uuid);if(n!==null){const r=n.getObjectByProperty("uuid",e.uuid);V(r,"material.needsUpdate",!0)}}}),s}function un(i,e){function t(){return`${e.name}_material`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=i.material;if(Array.isArray(a)){const o=[],c=a.length;for(let l=0;l<c;l++)o.push(d.jsx(J,{three:e,title:`Material ${l}`,items:Nt(a[l],i,e)},`Material ${l}`));return d.jsx(d.Fragment,{children:o})}else return d.jsx(J,{three:e,title:"Material",items:Nt(a,i,e),expanded:n,onToggle:o=>{r(o)}})}const Ft="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 pn(i){const e=i.step!==void 0?i.step:.01,t=b.useRef(null),s=b.useRef(null),n=b.useRef(null),r=b.useRef(null),a=b.useRef(null),[o]=b.useState(i.value),[c,l]=b.useState(i.value.offset[0]),[h,u]=b.useState(i.value.offset[1]),[p,g]=b.useState(i.value.repeat[0]),[C,_]=b.useState(i.value.repeat[1]);function E(y,x,O,S,T){if(i.onChange!==void 0){const M=i.prop!==void 0?i.prop:i.title;i.onChange(M,{src:y,offset:[x,O],repeat:[S,T]})}}function v(y){const x=t.current.src,O=y.target.value;switch(y.target){case s.current:l(O),E(x,O,h,p,C);break;case n.current:u(O),E(x,c,O,p,C);break;case r.current:g(O),E(x,c,h,O,C);break;case a.current:_(O),E(x,c,h,p,O);break}}return d.jsxs("div",{className:"imageField",children:[d.jsx("img",{alt:i.title,ref:t,onClick:()=>{Js().then(y=>{t.current.src=y,E(y,c,h,p,C)})},src:o.src.length>0?o.src:Ft}),d.jsxs("div",{className:"fields",children:[d.jsxs("div",{children:[d.jsx("span",{children:"Offset:"}),d.jsx("input",{ref:s,type:"number",value:c,step:e,name:Y(),onChange:v}),d.jsx("input",{ref:n,type:"number",value:h,step:e,name:Y(),onChange:v})]}),d.jsxs("div",{children:[d.jsx("span",{children:"Repeat:"}),d.jsx("input",{ref:r,type:"number",value:p,step:e,name:Y(),onChange:v}),d.jsx("input",{ref:a,type:"number",value:C,step:e,name:Y(),onChange:v})]}),d.jsx("button",{onClick:()=>{E("",c,h,p,C),t.current.src=Ft},children:"Clear"})]})]})}function Ze(i){let e=i.value;e!==void 0&&(e.isColor!==void 0?e=vt(i.value):i.type==="color"&&(e=vt(new m.Color().setStyle(i.value,m.LinearSRGBColorSpace))));const[t,s]=b.useState(e),n=b.useRef(null),r=l=>{let h=l.target.value;if(i.type==="boolean")h=l.target.checked;else if(i.type==="option"&&(typeof i.value=="number"?h=Number(h):typeof i.value=="boolean"?h=!!h:typeof i.value=="object"&&(h=JSON.parse(h)),i.options!==void 0)){const u=i.options.length;for(let p=0;p<u&&i.options[p].value!==h;p++);}s(h),i.onChange!==void 0&&i.onChange(i.prop!==void 0?i.prop:i.title,h)},a={};i.disabled&&(a.opacity=.8);const o=i.type==="field"||i.type==="string"&&(t.length>100||t.search(`
33
- `)>-1),c=o||i.type==="image"||i.type==="vector2";return d.jsxs("div",{className:`field ${c?"block":""}`,style:a,children:[i.type!=="button"&&d.jsx("span",{ref:n,children:He(i.title)},"fieldLabel"),i.type==="string"&&!o&&d.jsx("input",{type:"text",disabled:i.disabled,onChange:r,value:t,name:Y()}),(i.type==="field"||i.type==="string"&&o)&&d.jsx("textarea",{cols:50,rows:10,disabled:i.disabled!==void 0?i.disabled:!0,onChange:r,onKeyDown:l=>{i.onKeyDown!==void 0&&i.onKeyDown(l)},value:t,name:Y()}),i.type==="boolean"&&d.jsx("input",{type:"checkbox",disabled:i.disabled,onChange:r,checked:t,name:Y()}),i.type==="number"&&d.jsx(ve,{value:t,type:i.type,prop:i.prop!==void 0?i.prop:i.title,min:i.min,max:i.max,step:i.step,disabled:i.disabled,labelRef:n,onChange:i.onChange}),i.type==="range"&&d.jsx(ve,{value:t,type:i.type,prop:i.prop!==void 0?i.prop:i.title,min:i.min,max:i.max,step:i.step,disabled:i.disabled,labelRef:n,onChange:i.onChange}),i.type==="color"&&d.jsxs(d.Fragment,{children:[d.jsx("input",{type:"text",value:t.toString(),onChange:r,disabled:i.disabled,className:"color",name:Y()}),d.jsx("input",{type:"color",value:t,onChange:r,disabled:i.disabled,name:Y()})]}),i.type==="button"&&d.jsx("button",{disabled:i.disabled,onClick:()=>{i.onChange!==void 0&&i.onChange(i.prop!==void 0?i.prop:i.title,!0)},children:i.title}),i.type==="image"&&d.jsx(pn,{title:i.title,prop:i.prop,value:i.value,onChange:i.onChange}),i.type==="option"&&d.jsx(d.Fragment,{children:d.jsx("select",{onChange:r,disabled:i.disabled,defaultValue:i.value,name:Y(),children:i.options?.map((l,h)=>d.jsx("option",{value:l.value,children:He(l.title)},h))})}),i.type==="vector2"&&d.jsx(Zs,{step:i.step,value:t,min:0,max:1,onChange:r}),i.type==="grid3"&&d.jsx(kt,{step:i.step,value:t,onChange:r}),i.type==="grid4"&&d.jsx(Ks,{step:i.step,value:t,onChange:r}),i.type==="euler"&&d.jsx(kt,{step:i.step,value:t,onChange:r})]})}function mn(i){return"items"in i}class J extends b.Component{subgroupNames=[];subgroupElements=[];valueOverrides=new Map;three;constructor(e){super(e),this.three=e.three,this.state={lastUpdated:Date.now()}}addGroup(e){const t=[];e.items.forEach(r=>{t.push({type:r.type,prop:r.prop,title:r.title!==void 0?r.title:r.prop,value:r.value,min:r.min,max:r.max,step:r.step,options:r.options,disabled:r.disabled,onChange:(a,o)=>{e.onUpdate(a,o)}})});const s=b.createRef(),n=d.jsx(J,{three:this.props.three,ref:s,title:e.title,expanded:e.expanded,items:t},e.title);return this.subgroupNames.push(e.title),this.subgroupElements.push(n),this.setState({lastUpdated:Date.now()}),s}removeGroup(e){const t=this.subgroupNames.length;for(let s=0;s<t;s++){const n=this.subgroupNames[s];if(e===n){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(mn(t))e.push(d.jsx(J,{three:this.props.three,title:He(t.title),items:t.items},t.title));else{const s=this.valueOverrides.get(t.title),n=s!==void 0?s:t.value;e.push(d.jsx(Ze,{title:t.title,prop:t.prop,value:n,type:t.type,min:t.min,max:t.max,step:t.step,disabled:t.disabled,options:t.options,onChange:(r,a)=>{t.onChange!==void 0&&(this.valueOverrides.delete(t.title),t.onChange(r,a))},onKeyDown:r=>{t.onKeyDown!==void 0&&t.onKeyDown(r)}},t.title))}}),this.subgroupElements.forEach(t=>e.push(t)),d.jsx(Ae,{three:this.props.three,label:this.props.title,open:this.props.expanded===!0,onToggle:t=>{this.props.onToggle&&this.props?.onToggle(t)},children:e})}}class k extends b.Component{static instance;static groups=[];static groupsRefs=[];static groupTitles=[];static three;constructor(e){super(e),this.state={lastUpdate:Date.now()},k.instance=this,k.three=e.three,e.three.addEventListener(L.ADD_GROUP,this.addGroup),e.three.addEventListener(L.REMOVE_GROUP,this.removeGroup)}componentWillUnmount(){this.props.three.removeEventListener(L.ADD_GROUP,this.addGroup),this.props.three.removeEventListener(L.REMOVE_GROUP,this.removeGroup)}render(){return d.jsx("div",{className:"customGroups",children:k.groups},this.state.lastUpdate)}addGroup=e=>{const t=JSON.parse(e.value),s=[];t.items.forEach(n=>{s.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,a)=>{this.props.three.updateGroup(t.title,r,a)}})}),k.groups.push(d.jsx(J,{three:this.props.three,title:t.title,items:s},t.title)),k.groupTitles.push(t.title),this.setState({lastUpdate:Date.now()})};removeGroup=e=>{const t=e.value,s=k.groupTitles.length;for(let n=0;n<s;n++)if(t===k.groupTitles[n]){k.groups.splice(n,1),k.groupTitles.splice(n,1),this.setState({lastUpdate:Date.now()});return}};static addEditorGroup(e){const t=k.groupTitles.length;for(let a=0;a<t;a++)if(k.groupTitles[a]===e.title)return k.groupsRefs[a];const s=[];e.items.forEach(a=>{s.push({type:a.type,prop:a.prop,title:a.title!==void 0?a.title:a.prop,value:a.value,min:a.min,max:a.max,step:a.step,options:a.options,disabled:a.disabled,onChange:(o,c)=>{e.onUpdate(o,c)}})}),e.subgroups&&e.subgroups.length>0&&e.subgroups.forEach(a=>{const o=[];a.items.forEach(c=>{o.push({type:c.type,prop:c.prop,title:c.title!==void 0?c.title:c.prop,value:c.value,min:c.min,max:c.max,step:c.step,options:c.options,disabled:c.disabled,onChange:(l,h)=>{a.onUpdate(l,h)}})}),s.push({three:k.three,title:a.title,expanded:a.expanded,items:o})});const n=b.createRef(),r=d.jsx(J,{three:k.three,ref:n,title:e.title,expanded:e.expanded,items:s},e.title);return k.groups.push(r),k.groupsRefs.push(n),k.groupTitles.push(e.title),setTimeout(()=>{k.instance.setState({lastUpdate:Date.now()})},0),n}static removeEditorGroup(e){const t=k.groupTitles.length;for(let s=0;s<t;s++)if(e===k.groupTitles[s]){k.groups.splice(s,1),k.groupTitles.splice(s,1),k.instance.setState({lastUpdate:Date.now()});return}}static removeAllGroups(){k.groups=[],k.groupTitles=[],k.groupsRefs=[],k.instance.setState({lastUpdate:Date.now()})}}function jt(i){switch(i){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 i}function fn(i,e){function t(){return`${e.name}_camera`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=[];if(i.perspectiveCameraInfo!==void 0)for(const o in i.perspectiveCameraInfo)a.push({title:jt(o),prop:o,type:"number",step:.01,value:i.perspectiveCameraInfo[o],onChange:(c,l)=>{e.updateObject(i.uuid,c,l),e.requestMethod(i.uuid,"updateProjectionMatrix");const h=e.getScene(i.uuid);if(h!==null){const u=h.getObjectByProperty("uuid",i.uuid);u!==void 0&&(V(u,c,l),u.updateProjectionMatrix())}}});else if(i.orthographicCameraInfo!==void 0)for(const o in i.orthographicCameraInfo)a.push({title:jt(o),prop:o,type:"number",step:.01,value:i.orthographicCameraInfo[o],onChange:(c,l)=>{e.updateObject(i.uuid,c,l),e.requestMethod(i.uuid,"updateProjectionMatrix");const h=e.getScene(i.uuid);if(h!==null){const u=h.getObjectByProperty("uuid",i.uuid);u!==void 0&&(V(u,c,l),u.updateProjectionMatrix())}}});return d.jsx(J,{three:e,title:"Camera",items:a,expanded:n,onToggle:o=>{r(o)}})}/*!
32
+ C11,8.22,10.74,8,10.43,8z`})});function ci(i){return d.jsx("li",{className:`reorder-item ${i.draggingIndex===i.index?"dragging":""}`,draggable:!0,onDragStart:()=>i.onDragStart(i.index),onDragOver:e=>{e.preventDefault(),i.onDragOver(i.index)},onDragEnd:i.onDragEnd,children:d.jsxs("div",{children:[qs,d.jsx("span",{children:i.title}),d.jsx("button",{className:"closeIcon",onClick:()=>i.onDelete(i.index),children:Ys})]})})}function hi(i){const[e,t]=b.useState(!1),[s,n]=b.useState(i.options),[r,a]=b.useState(null),o=g=>{i.onDragComplete(g),n(g)},c=g=>{const C=[...s];C.splice(g,1),o(C)},l=g=>{a(g)},h=g=>{if(r===g||r===null)return;const C=[...s],_=C.splice(r,1)[0];C.splice(g,0,_),a(g),n(C)},u=()=>{i.onDragComplete(s),a(null)};let p="dropdown draggable";return i.subdropdown&&(p+=" subdropdown"),d.jsxs("div",{className:p,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[d.jsx(xt,{title:i.title}),d.jsx("ul",{className:"reorder-list",style:{display:e?"block":"none"},children:s.map((g,C)=>d.jsx(ci,{title:g,index:C,draggingIndex:r,onDelete:c,onDragStart:l,onDragOver:h,onDragEnd:u},g))})]})}function di(i){const[e,t]=b.useState(!1),s=[];i.options.map((r,a)=>{i.onSelect!==void 0&&(r.onSelect=i.onSelect),s.push(d.jsx(ui,{option:r},a))});let n="dropdown";return i.subdropdown&&(n+=" subdropdown"),d.jsxs("div",{className:n,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),children:[d.jsx(xt,{title:i.title}),d.jsx("ul",{style:{visibility:e?"visible":"hidden"},children:s})]})}function ui(i){const{option:e}=i,[t,s]=b.useState("");let n;switch(e.type){case"draggable":n=d.jsx(hi,{title:e.title,options:e.value,onDragComplete:r=>{e.onDragComplete!==void 0&&e.onDragComplete(r)},subdropdown:!0});break;case"dropdown":n=d.jsx(di,{title:e.title,options:e.value,onSelect:e.onSelect,subdropdown:!0});break;case"option":n=d.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 d.jsx("li",{className:t===e.title?"selected":"",children:n},Y())}function Ae(i){const[e,t]=b.useState(i.open!==void 0?i.open:!1),[s,n]=b.useState(i.visible!==void 0?i.visible:!1),r=!e||i.children===void 0,a=()=>{i.three.dispatchEvent({type:L.REMOVE_SCENE,value:i.scene})};return d.jsxs("div",{className:`accordion ${r?"hide":""}`,children:[d.jsxs("button",{className:"toggle",onClick:()=>{const o=!e;i.onToggle!==void 0&&i.onToggle(o),t(o)},children:[d.jsx("p",{className:`status ${e?"open":""}`,children:"Toggle"}),d.jsx("p",{className:"label",children:He(i.label)})]}),i.onRefresh?d.jsxs(d.Fragment,{children:[d.jsx("button",{className:"visibility",style:{opacity:s?1:.25},onClick:()=>{const c=i.three.getScene(i.scene.uuid);if(c){const l=!c.visible;c.visible=l,n(l)}}}),d.jsx("button",{className:"refresh",onClick:i.onRefresh}),d.jsx("button",{className:"remove",onClick:a})]}):null,i.button,d.jsx("div",{className:e?"open":"",children:d.jsx("div",{children:i.children})})]})}function Ot(i){if(i.child===void 0)return console.log("Hermes - No child attached"),null;const e=b.useRef(null),[t,s]=b.useState(!1),n=i.child.children.length>0,r=[];return i.child.children.length>0&&i.child.children.map((a,o)=>{r.push(d.jsx(Ot,{child:a,three:i.three},o))}),b.useEffect(()=>{if(i.child){const a=i.child.uuid.split(".")[0],o=i.three.getScene(a);if(o!==null)try{const c=o.getObjectByProperty("uuid",i.child.uuid);c!==void 0?e.current.style.opacity=c.visible?"1":"0.25":console.log(`Hermes - Can't find child: ${i.child.uuid}`)}catch(c){console.log("Error looking for child:",c),console.log(i.child),console.log(i.three.scenes),console.log(o)}else console.log(`Hermes (ChildObject) - Can't find Scene: ${a} with child UUID: ${i.child.uuid}`,i.three.scenes,i.three.scene,o)}},[t]),d.jsxs("div",{className:"childObject",children:[d.jsxs("div",{className:"child",children:[n?d.jsx("button",{className:"status",style:{backgroundPositionX:t?"-14px":"2px"},onClick:()=>{s(!t)}}):null,d.jsx("button",{className:"name",style:{left:n?"20px":"5px"},onClick:()=>{i.child!==void 0?(i.three.getObject(i.child.uuid),!t&&n&&s(!0)):console.log("Hermes - No child attached...")},children:i.child.name.length>0?`${i.child.name} (${i.child.type})`:`${i.child.type}::${i.child.uuid}`}),d.jsx("button",{className:"visibility",ref:e,onClick:()=>{if(i.child){const a=i.three.getScene(i.child.uuid);if(a!==null){const o=a.getObjectByProperty("uuid",i.child.uuid);if(o!==void 0){const c="visible",l=!o.visible;e.current.style.opacity=l?"1":"0.25",i.three.updateObject(i.child.uuid,c,l),V(o,c,l)}else console.log(`Hermes - Couldn't find object: ${i.child.uuid}`,a)}else console.log(`Hermes - Couldn't find object in scene: ${i.child.uuid}, ${i.child.name}`)}}}),d.jsx("div",{className:`icon ${zs(i.child)}`})]}),d.jsx("div",{className:t?"open":"",children:d.jsx("div",{className:"container",children:r})})]})}function $e(i){const e=[];return i.child?.children.map((t,s)=>{e.push(d.jsx(Ot,{child:t,scene:i.scene,three:i.three},s))}),d.jsx("div",{className:`scene ${i.class!==void 0?i.class:""}`,children:e})}function Fe(i){const[e,t]=b.useState(i.defaultValue);return b.useEffect(()=>{let s=!1,n=-1,r=0,a=i.defaultValue,o=!1;const c=g=>{o=g.ctrlKey},l=g=>{s=!0,r=Number(i.input.current?.value),n=g.clientX,document.addEventListener("mouseup",u,!1),document.addEventListener("mousemove",h,!1),document.addEventListener("contextmenu",u,!1)},h=g=>{if(!s)return;const C=i.step!==void 0?i.step:1,_=(g.clientX-n)*C*(o?10:1);a=Number((r+_).toFixed(4)),i.min!==void 0&&(a=Math.max(a,i.min)),i.max!==void 0&&(a=Math.min(a,i.max)),i.onChange!==void 0&&i.onChange(a),t(a)},u=()=>{s=!1,document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u)},p=g=>{const C=Number(g.target.value);i.onChange!==void 0&&i.onChange(C),t(C)};return i.label.current?.addEventListener("mousedown",l,!1),i.sliderRef!==void 0&&i.sliderRef.current?.addEventListener("input",p),document.addEventListener("keydown",c,!1),document.addEventListener("keyup",c,!1),()=>{i.label.current?.removeEventListener("mousedown",l),i.sliderRef!==void 0&&i.sliderRef.current?.removeEventListener("input",p),document.removeEventListener("mouseup",u),document.removeEventListener("mousemove",h),document.removeEventListener("contextmenu",u),document.removeEventListener("keydown",c),document.addEventListener("keyup",c,!1)}},[]),e}function ve(i){const e=b.useRef(null),t=b.useRef(null),[s,n]=b.useState(i.value);return Fe({label:i.labelRef,input:e,sliderRef:t,defaultValue:s,min:i.min,max:i.max,step:i.step,onChange:r=>{n(r),i.onChange!==void 0&&i.onChange(i.prop,r)}}),d.jsxs(d.Fragment,{children:[i.type==="number"&&d.jsx("input",{alt:i.alt,className:i.className,ref:e,type:"number",value:s,min:i.min,max:i.max,step:i.step,disabled:i.disabled,name:Y(),onChange:r=>{if(n(r.target.value),r.target.value.length===0)return;const a=Number(r.target.value);isNaN(a)||i.onChange!==void 0&&i.onChange(i.prop,a)}}),i.type==="range"&&d.jsxs(d.Fragment,{children:[d.jsx("input",{type:"text",value:s.toString(),disabled:i.disabled,ref:e,className:"min",name:Y(),onChange:r=>{if(r.target.value.length===0)return;const a=Number(r.target.value);isNaN(a)||(n(a),i.onChange!==void 0&&i.onChange(i.prop,a))}}),d.jsx("input",{disabled:i.disabled,type:"range",value:s,min:i.min,max:i.max,step:i.step,ref:t,name:Y(),onChange:ze})]})]})}function $s(i){const e=b.useRef(null),t=b.useRef(null),s=b.useRef(null),n=b.useRef(null),r=b.useRef(null),a=b.useRef(null),o=b.useRef(null),c=b.useRef(null),l=b.useRef(null),h=b.useRef(null),[u,p]=b.useState(i.value.x),[g,C]=b.useState(i.value.y),[_,E]=b.useState({min:Math.min(i.min,Math.min(i.value.x,i.value.y)),max:Math.max(i.max,Math.max(i.value.x,i.value.y))}),[v,y]=b.useState(!1);Fe({label:o,input:e,defaultValue:u,min:_.min,max:_.max,step:.01,onChange:A=>{p(A),i.onChange({target:{value:{x:A,y:g}}})}}),Fe({label:c,input:t,defaultValue:g,min:_.min,max:_.max,step:.01,onChange:A=>{C(A),i.onChange({target:{value:{x:u,y:A}}})}}),Fe({label:l,input:s,defaultValue:_.min,min:_.min-1,max:_.max+1,step:.01,onChange:A=>{E({min:A,max:_.max})}}),Fe({label:h,input:n,defaultValue:_.max,min:_.min-1,max:_.max+1,step:.01,onChange:A=>{E({min:_.min,max:A})}});function x(){v||(window.addEventListener("mousemove",S),window.addEventListener("mouseup",O),y(!0))}function O(){window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",O),y(!1)}function S(A){const j=r.current.getBoundingClientRect(),ee=de(0,99,A.clientX-j.left)/99,oe=1-de(0,99,A.clientY-j.top)/99,ue=X(Re(_.min,_.max,ee),3),_e=X(Re(_.min,_.max,oe),3);i.onChange({target:{value:{x:ue,y:_e}}}),p(ue),C(_e)}function T(){const A=Number(s.current.value);E({min:A,max:_.max}),u<A&&p(de(A,_.max,u)),g<A&&C(de(A,_.max,g))}function M(){const A=Number(n.current.value);E({min:_.min,max:A}),u>A&&p(de(_.min,A,u)),g>A&&C(de(_.min,A,g))}b.useEffect(()=>{a.current.style.left=`${Xe(_.min,_.max,u)*100}%`,a.current.style.top=`${(1-Xe(_.min,_.max,g))*100}%`},[_,u,g]);const U=i.step!==void 0?i.step:.01;return d.jsxs("div",{className:"vector2",children:[d.jsxs("div",{className:"fields",children:[d.jsxs("div",{children:[d.jsx("span",{ref:o,children:"X"}),d.jsx("input",{ref:e,type:"number",value:u,min:_.min,max:_.max,step:U,name:Y(),onChange:A=>{if(p(A.target.value),A.target.value.length===0)return;const j=Number(A.target.value);isNaN(j)||(i.onChange({target:{value:{x:j,y:g}}}),j<_.min&&E({min:j,max:_.max}))}})]}),d.jsxs("div",{children:[d.jsx("span",{ref:c,children:"Y"}),d.jsx("input",{ref:t,type:"number",value:g,min:_.min,max:_.max,step:U,name:Y(),onChange:A=>{if(C(A.target.value),A.target.value.length===0)return;const j=Number(A.target.value);isNaN(j)||(i.onChange({target:{value:{x:u,y:j}}}),j>_.max&&E({min:_.min,max:j}))}})]}),d.jsxs("div",{children:[d.jsx("span",{ref:l,children:"Min"}),d.jsx("input",{ref:s,type:"number",value:_.min,step:U,name:Y(),onChange:T})]}),d.jsxs("div",{children:[d.jsx("span",{ref:h,children:"Max"}),d.jsx("input",{ref:n,type:"number",value:_.max,step:U,name:Y(),onChange:M})]})]}),d.jsxs("div",{className:"input",ref:r,onMouseDown:x,onMouseUp:O,children:[d.jsx("div",{className:"x"}),d.jsx("div",{className:"y"}),d.jsx("div",{className:"pt",ref:a})]})]})}function kt(i){const e=i.value.x!==void 0&&i.value.y!==void 0&&i.value.z!==void 0,t=i.value.isEuler!==void 0,s=i.value.elements!==void 0,n=i.step!==void 0?i.step:.01,r=[];if(t){const a=b.useMemo(()=>i.value,[]);["_x","_y","_z"].forEach(c=>{const l=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("span",{ref:l,children:c.substring(1).toUpperCase()}),d.jsx(ve,{value:$.radToDeg(a[c]),type:"number",prop:c,step:.1,labelRef:l,onChange:(h,u)=>{a[h]=$.degToRad(u),i.onChange({target:{value:a}})}})]},c))})}else if(e){const a=b.useMemo(()=>i.value,[]),o=(l,h)=>{a[l]=h,i.onChange({target:{value:a}})};["x","y","z"].forEach(l=>{const h=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("label",{ref:h,children:l.toUpperCase()}),d.jsx(ve,{value:a[l],type:"number",prop:l,step:n,labelRef:h,onChange:o})]},l))})}else if(s){const a=b.useMemo(()=>i.value,[]),o=(c,l)=>{const h=Number(c);a.elements[h]=l,i.onChange({target:{value:a}})};for(let c=0;c<9;c++){const l=b.useRef(null);r.push(d.jsxs("div",{children:[d.jsx("label",{ref:l,children:c+1}),d.jsx(ve,{value:a.elements[c],type:"number",prop:c.toString(),step:n,labelRef:l,onChange:o})]},c.toString()))}}return d.jsx("div",{className:"grid3",children:r},Math.random().toString())}function Zs(i){const e=i.value.x!==void 0,t=i.step!==void 0?i.step:.01,s=[];if(e){const n=b.useMemo(()=>i.value,[]),r=(o,c)=>{n[o]=c,i.onChange({target:{value:n}})};["x","y","z","w"].forEach(o=>{const c=b.useRef(null);s.push(d.jsxs("div",{children:[d.jsx("label",{ref:c,children:o.toUpperCase()}),d.jsx(ve,{value:n[o],type:"number",prop:o,step:t,labelRef:c,onChange:r})]},o))})}else{const n=b.useMemo(()=>i.value,[]),r=(a,o)=>{const c=Number(a);n.elements[c]=o,i.onChange({target:{value:n}})};for(let a=0;a<16;a++){const o=b.useRef(null);s.push(d.jsxs("div",{children:[d.jsx("span",{ref:o,children:a+1}),d.jsx(ve,{value:n.elements[a],type:"number",prop:a.toString(),step:t,labelRef:o,onChange:r})]},a.toString()))}}return d.jsx("div",{className:"grid4",children:s})}function Ks(i){return!(i==="defaultAttributeValues"||i==="forceSinglePass"||i==="linecap"||i==="linejoin"||i==="linewidth"||i==="normalMapType"||i==="precision"||i==="shadowSide"||i==="uniformsGroups"||i==="uniformsNeedUpdate"||i==="userData"||i==="version"||i==="wireframeLinecap"||i==="wireframeLinejoin"||i==="wireframeLinewidth"||i.slice(0,4)==="clip"||i.slice(0,7)==="polygon"||i.slice(0,7)==="stencil"||i.slice(0,2)==="is")}function Xs(i){switch(i){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 i}function et(i){switch(i){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 i}function pi(i){const e=i.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 Qs(){const i=document.createElement("input");return i.type="file",new Promise((e,t)=>{i.addEventListener("change",function(){if(i.files===null)t();else{const s=i.files[0],n=new FileReader;n.onload=function(r){e(r.target.result)},n.readAsDataURL(s)}}),i.click()})}const Js=[{title:"Front",value:m.FrontSide},{title:"Back",value:m.BackSide},{title:"Double",value:m.DoubleSide}],en=[{title:"No Blending",value:m.NoBlending},{title:"Normal",value:m.NormalBlending},{title:"Additive",value:m.AdditiveBlending},{title:"Subtractive",value:m.SubtractiveBlending},{title:"Multiply",value:m.MultiplyBlending},{title:"Custom",value:m.CustomBlending}],tn=[{title:"Add",value:m.AddEquation},{title:"Subtract",value:m.SubtractEquation},{title:"Reverse Subtract",value:m.ReverseSubtractEquation},{title:"Min",value:m.MinEquation},{title:"Max",value:m.MaxEquation}],sn=[{title:"Zero",value:m.ZeroFactor},{title:"One",value:m.OneFactor},{title:"Src Color",value:m.SrcColorFactor},{title:"One Minus Src Color",value:m.OneMinusSrcColorFactor},{title:"Src Alpha",value:m.SrcAlphaFactor},{title:"One Minus Src Alpha",value:m.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:m.DstAlphaFactor},{title:"One Minus Dst Alpha",value:m.OneMinusDstAlphaFactor},{title:"Dst Color",value:m.DstColorFactor},{title:"One Minus Dst Color",value:m.OneMinusDstColorFactor},{title:"Src Alpha Saturate",value:m.SrcAlphaSaturateFactor},{title:"Constant Color",value:m.ConstantColorFactor},{title:"One Minus Constant Color",value:m.OneMinusConstantColorFactor},{title:"Constant Alpha",value:m.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:m.OneMinusConstantAlphaFactor}],nn=[{title:"Zero",value:m.ZeroFactor},{title:"One",value:m.OneFactor},{title:"Src Color",value:m.SrcColorFactor},{title:"One Minus Src Color",value:m.OneMinusSrcColorFactor},{title:"Src Alpha",value:m.SrcAlphaFactor},{title:"One Minus Src Alpha",value:m.OneMinusSrcAlphaFactor},{title:"Dst Alpha",value:m.DstAlphaFactor},{title:"One Minus Dst Alpha",value:m.OneMinusDstAlphaFactor},{title:"Dst Color",value:m.DstColorFactor},{title:"One Minus Dst Color",value:m.OneMinusDstColorFactor},{title:"Constant Color",value:m.ConstantColorFactor},{title:"One Minus Constant Color",value:m.OneMinusConstantColorFactor},{title:"Constant Alpha",value:m.ConstantAlphaFactor},{title:"One Minus Constant Alpha",value:m.OneMinusConstantAlphaFactor}];function Pe(i,e){i.needsUpdate=!0,i.type="option",i.options=e}function rn(i,e,t,s){return{type:"boolean",title:et(i),prop:i,value:e,needsUpdate:!0,onChange:(n,r)=>{s.updateObject(t.uuid,`material.${i}`,r),s.updateObject(t.uuid,"material.needsUpdate",!0);const a=s.getScene(t.uuid);if(a!==null){const o=a.getObjectByProperty("uuid",t.uuid);V(o,`material.${i}`,r)}}}}function an(i,e,t,s){const n={type:"number",title:et(i),prop:i,value:e,min:void 0,max:void 0,step:.01,needsUpdate:!0,onChange:(r,a)=>{s.updateObject(t.uuid,`material.${i}`,a),s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const c=o.getObjectByProperty("uuid",t.uuid);V(c,`material.${i}`,a)}}};switch(i){case"blending":Pe(n,en);break;case"blendDst":Pe(n,nn);break;case"blendEquation":Pe(n,tn);break;case"blendSrc":Pe(n,sn);break;case"side":Pe(n,Js);break}return pi(i)&&(n.value=Number(e),n.type="range",n.min=Math.min(0,n.value),n.max=Math.max(1,n.value),n.step=.01),n}function on(i,e,t,s){const n={type:"string",title:et(i),prop:i,value:e,needsUpdate:!0,onChange:(a,o)=>{s.updateObject(t.uuid,`material.${i}`,o),s.updateObject(t.uuid,"material.needsUpdate",!0);const c=s.getScene(t.uuid);if(c!==null){const l=c.getObjectByProperty("uuid",t.uuid);V(l,`material.${i}`,o)}},onKeyDown:a=>{}};return(i==="vertexShader"||i==="fragmentShader")&&(n.type="field",n.disabled=!1,n.latest=n.value,n.onChange=(a,o)=>{n.latest=o,s.updateObject(t.uuid,`material.${i}`,o);const c=s.getScene(t.uuid);if(c!==null){const l=c.getObjectByProperty("uuid",t.uuid);V(l,`material.${i}`,o)}},n.onKeyDown=a=>{if(a.key==="Enter"&&(a.altKey||a.metaKey)){s.updateObject(t.uuid,"material.needsUpdate",!0);const o=s.getScene(t.uuid);if(o!==null){const c=o.getObjectByProperty("uuid",t.uuid);V(c,"material.needsUpdate",!0)}}}),n}function ln(i){return i.x!==void 0&&i.y!==void 0&&i.z===void 0}function cn(i){return i.x!==void 0&&i.y!==void 0&&i.z!==void 0&&i.w===void 0}function hn(i){return i.x!==void 0&&i.y!==void 0&&i.z!==void 0&&i.w!==void 0}function Ct(i){i.sort((e,t)=>e.title<t.title?-1:e.title>t.title?1:0)}function Te(i,e,t,s,n="",r=!1){const a=et(i).split(".")[0].replaceAll("[","").replaceAll("]",""),o=n.length>0?`${n}.${i}`:i,c=typeof e;if(c==="object"&&e!==null&&e.__isUniform===!0)return Te(`${i}.value`,e.value,t,s,n,r);if(c==="boolean"||c==="string")return{title:a,prop:o,type:c,value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(c==="number"){const l={title:a,prop:o,type:"number",value:e,step:.01,disabled:r,onChange:(h,u)=>{s.updateObject(t.uuid,`material.${o}`,u);const p=s.getScene(t.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",t.uuid);V(g,`material.${o}`,u)}}};return pi(a)&&(l.type="range",l.min=0,l.max=1),l}else{if(e.isColor)return{title:a,prop:o,type:"color",value:e,disabled:r,onChange:(l,h)=>{const u=new m.Color(h);s.updateObject(t.uuid,`material.${o}`,u);const p=s.getScene(t.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",t.uuid);V(g,`material.${o}`,u)}}};if(Array.isArray(e)){const l=[];for(const h in e){const u=e[h],p=`[${h.toString()}]`;if(u.value!==void 0){const g=Te(`${p}.value`,u.value,t,s,o,r);g!==void 0&&l.push(g)}else{const g=Te(p,u,t,s,o,r);g!==void 0&&l.push(g)}}if(l.length>0)return Ct(l),{title:a,items:l}}else{if(ln(e))return{title:a,prop:o,type:"vector2",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(cn(e))return{title:a,prop:o,type:"grid3",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(hn(e))return{title:a,prop:o,type:"grid4",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(e.isEuler)return{title:a,prop:o,type:"euler",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};if(e.src!==void 0)return{title:a,type:"image",value:e,disabled:r,onChange:(l,h)=>{const u=Xs(i),p=n.length>0?`${n}.${u}`:u;s.createTexture(t.uuid,`material.${p}`,h);const g=s.getScene(t.uuid);if(g!==null){const C=g.getObjectByProperty("uuid",t.uuid);if(C!==void 0){const _=E=>{const v=C.material,y=p.split(".");switch(y.length){case 1:v[y[0]]=E;break;case 2:v[y[0]][y[1]]=E;break;case 3:v[y[0]][y[1]][y[2]]=E;break;case 4:v[y[0]][y[1]][y[2]][y[3]]=E;break;case 5:v[y[0]][y[1]][y[2]][y[3]][y[4]]=E;break}v.needsUpdate=!0};h.src.length>0?li(h.src).then(E=>{E.offset.set(h.offset[0],h.offset[1]),E.repeat.set(h.repeat[0],h.repeat[1]),_(E)}):_(null)}}}};if(e.elements!==void 0)return{title:a,prop:o,type:e.elements.length>9?"grid4":"grid3",value:e,disabled:r,onChange:(l,h)=>{s.updateObject(t.uuid,`material.${o}`,h);const u=s.getScene(t.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",t.uuid);V(p,`material.${o}`,h)}}};{const l=[],h=i==="defines"||i==="extensions";try{for(const u in e){const p=e[u];if(p!==void 0)if(p.value!==void 0){const g=Te(`${u}.value`,p.value,t,s,o,h);g!==void 0&&l.push(g)}else{const g=Te(u,p,t,s,o,h);g!==void 0&&l.push(g)}}}catch{console.log("Hermes - Issue cycling through material object:",i,e)}if(l.length>0)return Ct(l),{title:a,items:l}}}}}function Nt(i,e,t){const s=[];for(const n in i){if(!Ks(n)||n.search("Node")>-1||i[n]instanceof w.ComputeNode)continue;const r=typeof i[n],a=i[n];if(r==="boolean")s.push(rn(n,a,e,t));else if(r==="number")s.push(an(n,a,e,t));else if(r==="string")s.push(on(n,a,e,t));else if(r==="object"){const o=Te(n,a,e,t);o!==void 0&&s.push(o)}else a!==void 0&&console.log("Hermes - Other Material Prop Type:",n,r,a)}return Ct(s),s.push({title:"Update Material",type:"button",onChange:()=>{t.updateObject(e.uuid,"material.needsUpdate",!0);const n=t.getScene(e.uuid);if(n!==null){const r=n.getObjectByProperty("uuid",e.uuid);V(r,"material.needsUpdate",!0)}}}),s}function dn(i,e){function t(){return`${e.name}_material`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=i.material;if(Array.isArray(a)){const o=[],c=a.length;for(let l=0;l<c;l++)o.push(d.jsx(J,{three:e,title:`Material ${l}`,items:Nt(a[l],i,e)},`Material ${l}`));return d.jsx(d.Fragment,{children:o})}else return d.jsx(J,{three:e,title:"Material",items:Nt(a,i,e),expanded:n,onToggle:o=>{r(o)}})}const Ft="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 un(i){const e=i.step!==void 0?i.step:.01,t=b.useRef(null),s=b.useRef(null),n=b.useRef(null),r=b.useRef(null),a=b.useRef(null),[o]=b.useState(i.value),[c,l]=b.useState(i.value.offset[0]),[h,u]=b.useState(i.value.offset[1]),[p,g]=b.useState(i.value.repeat[0]),[C,_]=b.useState(i.value.repeat[1]);function E(y,x,O,S,T){if(i.onChange!==void 0){const M=i.prop!==void 0?i.prop:i.title;i.onChange(M,{src:y,offset:[x,O],repeat:[S,T]})}}function v(y){const x=t.current.src,O=y.target.value;switch(y.target){case s.current:l(O),E(x,O,h,p,C);break;case n.current:u(O),E(x,c,O,p,C);break;case r.current:g(O),E(x,c,h,O,C);break;case a.current:_(O),E(x,c,h,p,O);break}}return d.jsxs("div",{className:"imageField",children:[d.jsx("img",{alt:i.title,ref:t,onClick:()=>{Qs().then(y=>{t.current.src=y,E(y,c,h,p,C)})},src:o.src.length>0?o.src:Ft}),d.jsxs("div",{className:"fields",children:[d.jsxs("div",{children:[d.jsx("span",{children:"Offset:"}),d.jsx("input",{ref:s,type:"number",value:c,step:e,name:Y(),onChange:v}),d.jsx("input",{ref:n,type:"number",value:h,step:e,name:Y(),onChange:v})]}),d.jsxs("div",{children:[d.jsx("span",{children:"Repeat:"}),d.jsx("input",{ref:r,type:"number",value:p,step:e,name:Y(),onChange:v}),d.jsx("input",{ref:a,type:"number",value:C,step:e,name:Y(),onChange:v})]}),d.jsx("button",{onClick:()=>{E("",c,h,p,C),t.current.src=Ft},children:"Clear"})]})]})}function Ze(i){let e=i.value;e!==void 0&&(e.isColor!==void 0?e=vt(i.value):i.type==="color"&&(e=vt(new m.Color().setStyle(i.value,m.LinearSRGBColorSpace))));const[t,s]=b.useState(e),n=b.useRef(null),r=l=>{let h=l.target.value;if(i.type==="boolean")h=l.target.checked;else if(i.type==="option"&&(typeof i.value=="number"?h=Number(h):typeof i.value=="boolean"?h=!!h:typeof i.value=="object"&&(h=JSON.parse(h)),i.options!==void 0)){const u=i.options.length;for(let p=0;p<u&&i.options[p].value!==h;p++);}s(h),i.onChange!==void 0&&i.onChange(i.prop!==void 0?i.prop:i.title,h)},a={};i.disabled&&(a.opacity=.8);const o=i.type==="field"||i.type==="string"&&(t.length>100||t.search(`
33
+ `)>-1),c=o||i.type==="image"||i.type==="vector2";return d.jsxs("div",{className:`field ${c?"block":""}`,style:a,children:[i.type!=="button"&&d.jsx("span",{ref:n,children:He(i.title)},"fieldLabel"),i.type==="string"&&!o&&d.jsx("input",{type:"text",disabled:i.disabled,onChange:r,value:t,name:Y()}),(i.type==="field"||i.type==="string"&&o)&&d.jsx("textarea",{cols:50,rows:10,disabled:i.disabled!==void 0?i.disabled:!0,onChange:r,onKeyDown:l=>{i.onKeyDown!==void 0&&i.onKeyDown(l)},value:t,name:Y()}),i.type==="boolean"&&d.jsx("input",{type:"checkbox",disabled:i.disabled,onChange:r,checked:t,name:Y()}),i.type==="number"&&d.jsx(ve,{value:t,type:i.type,prop:i.prop!==void 0?i.prop:i.title,min:i.min,max:i.max,step:i.step,disabled:i.disabled,labelRef:n,onChange:i.onChange}),i.type==="range"&&d.jsx(ve,{value:t,type:i.type,prop:i.prop!==void 0?i.prop:i.title,min:i.min,max:i.max,step:i.step,disabled:i.disabled,labelRef:n,onChange:i.onChange}),i.type==="color"&&d.jsxs(d.Fragment,{children:[d.jsx("input",{type:"text",value:t.toString(),onChange:r,disabled:i.disabled,className:"color",name:Y()}),d.jsx("input",{type:"color",value:t,onChange:r,disabled:i.disabled,name:Y()})]}),i.type==="button"&&d.jsx("button",{disabled:i.disabled,onClick:()=>{i.onChange!==void 0&&i.onChange(i.prop!==void 0?i.prop:i.title,!0)},children:i.title}),i.type==="image"&&d.jsx(un,{title:i.title,prop:i.prop,value:i.value,onChange:i.onChange}),i.type==="option"&&d.jsx(d.Fragment,{children:d.jsx("select",{onChange:r,disabled:i.disabled,defaultValue:i.value,name:Y(),children:i.options?.map((l,h)=>d.jsx("option",{value:l.value,children:He(l.title)},h))})}),i.type==="vector2"&&d.jsx($s,{step:i.step,value:t,min:0,max:1,onChange:r}),i.type==="grid3"&&d.jsx(kt,{step:i.step,value:t,onChange:r}),i.type==="grid4"&&d.jsx(Zs,{step:i.step,value:t,onChange:r}),i.type==="euler"&&d.jsx(kt,{step:i.step,value:t,onChange:r})]})}function pn(i){return"items"in i}class J extends b.Component{subgroupNames=[];subgroupElements=[];valueOverrides=new Map;three;constructor(e){super(e),this.three=e.three,this.state={lastUpdated:Date.now()}}addGroup(e){const t=[];e.items.forEach(r=>{t.push({type:r.type,prop:r.prop,title:r.title!==void 0?r.title:r.prop,value:r.value,min:r.min,max:r.max,step:r.step,options:r.options,disabled:r.disabled,onChange:(a,o)=>{e.onUpdate(a,o)}})});const s=b.createRef(),n=d.jsx(J,{three:this.props.three,ref:s,title:e.title,expanded:e.expanded,items:t},e.title);return this.subgroupNames.push(e.title),this.subgroupElements.push(n),this.setState({lastUpdated:Date.now()}),s}removeGroup(e){const t=this.subgroupNames.length;for(let s=0;s<t;s++){const n=this.subgroupNames[s];if(e===n){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(pn(t))e.push(d.jsx(J,{three:this.props.three,title:He(t.title),items:t.items},t.title));else{const s=this.valueOverrides.get(t.title),n=s!==void 0?s:t.value;e.push(d.jsx(Ze,{title:t.title,prop:t.prop,value:n,type:t.type,min:t.min,max:t.max,step:t.step,disabled:t.disabled,options:t.options,onChange:(r,a)=>{t.onChange!==void 0&&(this.valueOverrides.delete(t.title),t.onChange(r,a))},onKeyDown:r=>{t.onKeyDown!==void 0&&t.onKeyDown(r)}},t.title))}}),this.subgroupElements.forEach(t=>e.push(t)),d.jsx(Ae,{three:this.props.three,label:this.props.title,open:this.props.expanded===!0,onToggle:t=>{this.props.onToggle&&this.props?.onToggle(t)},children:e})}}class k extends b.Component{static instance;static groups=[];static groupsRefs=[];static groupTitles=[];static three;constructor(e){super(e),this.state={lastUpdate:Date.now()},k.instance=this,k.three=e.three,e.three.addEventListener(L.ADD_GROUP,this.addGroup),e.three.addEventListener(L.REMOVE_GROUP,this.removeGroup)}componentWillUnmount(){this.props.three.removeEventListener(L.ADD_GROUP,this.addGroup),this.props.three.removeEventListener(L.REMOVE_GROUP,this.removeGroup)}render(){return d.jsx("div",{className:"customGroups",children:k.groups},this.state.lastUpdate)}addGroup=e=>{const t=JSON.parse(e.value),s=[];t.items.forEach(n=>{s.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,a)=>{this.props.three.updateGroup(t.title,r,a)}})}),k.groups.push(d.jsx(J,{three:this.props.three,title:t.title,items:s},t.title)),k.groupTitles.push(t.title),this.setState({lastUpdate:Date.now()})};removeGroup=e=>{const t=e.value,s=k.groupTitles.length;for(let n=0;n<s;n++)if(t===k.groupTitles[n]){k.groups.splice(n,1),k.groupTitles.splice(n,1),this.setState({lastUpdate:Date.now()});return}};static addEditorGroup(e){const t=k.groupTitles.length;for(let a=0;a<t;a++)if(k.groupTitles[a]===e.title)return k.groupsRefs[a];const s=[];e.items.forEach(a=>{s.push({type:a.type,prop:a.prop,title:a.title!==void 0?a.title:a.prop,value:a.value,min:a.min,max:a.max,step:a.step,options:a.options,disabled:a.disabled,onChange:(o,c)=>{e.onUpdate(o,c)}})}),e.subgroups&&e.subgroups.length>0&&e.subgroups.forEach(a=>{const o=[];a.items.forEach(c=>{o.push({type:c.type,prop:c.prop,title:c.title!==void 0?c.title:c.prop,value:c.value,min:c.min,max:c.max,step:c.step,options:c.options,disabled:c.disabled,onChange:(l,h)=>{a.onUpdate(l,h)}})}),s.push({three:k.three,title:a.title,expanded:a.expanded,items:o})});const n=b.createRef(),r=d.jsx(J,{three:k.three,ref:n,title:e.title,expanded:e.expanded,items:s},e.title);return k.groups.push(r),k.groupsRefs.push(n),k.groupTitles.push(e.title),setTimeout(()=>{k.instance?.setState({lastUpdate:Date.now()})},0),n}static removeEditorGroup(e){const t=k.groupTitles.length;for(let s=0;s<t;s++)if(e===k.groupTitles[s]){k.groups.splice(s,1),k.groupTitles.splice(s,1),k.instance?.setState({lastUpdate:Date.now()});return}}static removeAllGroups(){k.groups=[],k.groupTitles=[],k.groupsRefs=[],k.instance?.setState({lastUpdate:Date.now()})}}function jt(i){switch(i){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 i}function mn(i,e){function t(){return`${e.name}_camera`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=[];if(i.perspectiveCameraInfo!==void 0)for(const o in i.perspectiveCameraInfo)a.push({title:jt(o),prop:o,type:"number",step:.01,value:i.perspectiveCameraInfo[o],onChange:(c,l)=>{e.updateObject(i.uuid,c,l),e.requestMethod(i.uuid,"updateProjectionMatrix");const h=e.getScene(i.uuid);if(h!==null){const u=h.getObjectByProperty("uuid",i.uuid);u!==void 0&&(V(u,c,l),u.updateProjectionMatrix())}}});else if(i.orthographicCameraInfo!==void 0)for(const o in i.orthographicCameraInfo)a.push({title:jt(o),prop:o,type:"number",step:.01,value:i.orthographicCameraInfo[o],onChange:(c,l)=>{e.updateObject(i.uuid,c,l),e.requestMethod(i.uuid,"updateProjectionMatrix");const h=e.getScene(i.uuid);if(h!==null){const u=h.getObjectByProperty("uuid",i.uuid);u!==void 0&&(V(u,c,l),u.updateProjectionMatrix())}}});return d.jsx(J,{three:e,title:"Camera",items:a,expanded:n,onToggle:o=>{r(o)}})}/*!
34
34
  * camera-controls
35
35
  * https://github.com/yomotsu/camera-controls
36
36
  * (c) 2017 @yomotsu
37
37
  * Released under the MIT License.
38
- */const H={LEFT:1,RIGHT:2,MIDDLE:4},f=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Se={NONE:0,IN:1,OUT:-1};function me(i){return i.isPerspectiveCamera}function he(i){return i.isOrthographicCamera}const xe=Math.PI*2,zt=Math.PI/2,mi=1e-5,De=Math.PI/180;function te(i,e,t){return Math.max(e,Math.min(t,i))}function z(i,e=mi){return Math.abs(i)<e}function F(i,e,t=mi){return z(i-e,t)}function Ht(i,e){return Math.round(i/e)*e}function Ie(i){return isFinite(i)?i:i<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Le(i){return Math.abs(i)<Number.MAX_VALUE?i:i*(1/0)}function Ve(i,e,t,s,n=1/0,r){s=Math.max(1e-4,s);const a=2/s,o=a*r,c=1/(1+o+.48*o*o+.235*o*o*o);let l=i-e;const h=e,u=n*s;l=te(l,-u,u),e=i-l;const p=(t.value+a*l)*r;t.value=(t.value-a*p)*c;let g=e+(l+p)*c;return h-i>0==g>h&&(g=h,t.value=(g-h)/r),g}function Bt(i,e,t,s,n=1/0,r,a){s=Math.max(1e-4,s);const o=2/s,c=o*r,l=1/(1+c+.48*c*c+.235*c*c*c);let h=e.x,u=e.y,p=e.z,g=i.x-h,C=i.y-u,_=i.z-p;const E=h,v=u,y=p,x=n*s,O=x*x,S=g*g+C*C+_*_;if(S>O){const pe=Math.sqrt(S);g=g/pe*x,C=C/pe*x,_=_/pe*x}h=i.x-g,u=i.y-C,p=i.z-_;const T=(t.x+o*g)*r,M=(t.y+o*C)*r,U=(t.z+o*_)*r;t.x=(t.x-o*T)*l,t.y=(t.y-o*M)*l,t.z=(t.z-o*U)*l,a.x=h+(g+T)*l,a.y=u+(C+M)*l,a.z=p+(_+U)*l;const A=E-i.x,j=v-i.y,ee=y-i.z,oe=a.x-E,ue=a.y-v,_e=a.z-y;return A*oe+j*ue+ee*_e>0&&(a.x=E,a.y=v,a.z=y,t.x=(a.x-E)/r,t.y=(a.y-v)/r,t.z=(a.z-y)/r),a}function ot(i,e){e.set(0,0),i.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=i.length,e.y/=i.length}function lt(i,e){return he(i)?(console.warn(`${e} is not supported in OrthographicCamera`),!0):!1}class gn{constructor(){this._listeners={}}addEventListener(e,t){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[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){const n=this._listeners[e];if(n!==void 0){const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}removeAllEventListeners(e){if(!e){this._listeners={};return}Array.isArray(this._listeners[e])&&(this._listeners[e].length=0)}dispatchEvent(e){const s=this._listeners[e.type];if(s!==void 0){e.target=this;const n=s.slice(0);for(let r=0,a=n.length;r<a;r++)n[r].call(this,e)}}}var ct;const vn="2.10.1",Ge=1/8,_n=/Mac/.test((ct=globalThis?.navigator)===null||ct===void 0?void 0:ct.platform);let P,Vt,We,ht,q,D,N,Oe,Ue,ie,se,fe,Gt,Wt,K,ke,we,Yt,dt,qt,ut,pt,Ye;class re extends gn{static install(e){P=e.THREE,Vt=Object.freeze(new P.Vector3(0,0,0)),We=Object.freeze(new P.Vector3(0,1,0)),ht=Object.freeze(new P.Vector3(0,0,1)),q=new P.Vector2,D=new P.Vector3,N=new P.Vector3,Oe=new P.Vector3,Ue=new P.Vector3,ie=new P.Vector3,se=new P.Vector3,fe=new P.Vector3,Gt=new P.Vector3,Wt=new P.Vector3,K=new P.Spherical,ke=new P.Spherical,we=new P.Box3,Yt=new P.Box3,dt=new P.Sphere,qt=new P.Quaternion,ut=new P.Quaternion,pt=new P.Matrix4,Ye=new P.Raycaster}static get ACTION(){return f}set verticalDragToForward(e){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(e,t){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=f.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Se.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new P.Vector3,this._focalOffsetVelocity=new P.Vector3,this._zoomVelocity={value:0},this._truckInternal=(v,y,x,O)=>{let S,T;if(me(this._camera)){const M=D.copy(this._camera.position).sub(this._target),U=this._camera.getEffectiveFOV()*De,A=M.length()*Math.tan(U*.5);S=this.truckSpeed*v*A/this._elementRect.height,T=this.truckSpeed*y*A/this._elementRect.height}else if(he(this._camera)){const M=this._camera;S=this.truckSpeed*v*(M.right-M.left)/M.zoom/this._elementRect.width,T=this.truckSpeed*y*(M.top-M.bottom)/M.zoom/this._elementRect.height}else return;O?(x?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(S,0,!0),this.forward(-T,!0)):x?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y+T,this._focalOffsetEnd.z,!0):this.truck(S,T,!0)},this._rotateInternal=(v,y)=>{const x=xe*this.azimuthRotateSpeed*v/this._elementRect.height,O=xe*this.polarRotateSpeed*y/this._elementRect.height;this.rotate(x,O,!0)},this._dollyInternal=(v,y,x)=>{const O=Math.pow(.95,-v*this.dollySpeed),S=this._sphericalEnd.radius,T=this._sphericalEnd.radius*O,M=te(T,this.minDistance,this.maxDistance),U=M-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(U,!0),this._dollyToNoClamp(M,!0)):this._dollyToNoClamp(M,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:M)-S,this._dollyControlCoord.set(y,x)),this._lastDollyDirection=Math.sign(-v)},this._zoomInternal=(v,y,x)=>{const O=Math.pow(.95,v*this.dollySpeed),S=this._zoom,T=this._zoom*O;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-S,this._dollyControlCoord.set(y,x))},typeof P>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new P.Quaternion().setFromUnitVectors(this._camera.up,We),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=f.NONE,this._target=new P.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new P.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new P.Spherical().setFromVector3(D.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new P.Vector3,new P.Vector3,new P.Vector3,new P.Vector3],this._updateNearPlaneCorners(),this._boundary=new P.Box3(new P.Vector3(-1/0,-1/0,-1/0),new P.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new P.Vector2,this.mouseButtons={left:f.ROTATE,middle:f.DOLLY,right:f.TRUCK,wheel:me(this._camera)?f.DOLLY:he(this._camera)?f.ZOOM:f.NONE},this.touches={one:f.TOUCH_ROTATE,two:me(this._camera)?f.TOUCH_DOLLY_TRUCK:he(this._camera)?f.TOUCH_ZOOM_TRUCK:f.NONE,three:f.TOUCH_TRUCK};const s=new P.Vector2,n=new P.Vector2,r=new P.Vector2,a=v=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),S=v.clientX/O.width,T=v.clientY/O.height;if(S<this._interactiveArea.left||S>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const y=v.pointerType!=="mouse"?null:(v.buttons&H.LEFT)===H.LEFT?H.LEFT:(v.buttons&H.MIDDLE)===H.MIDDLE?H.MIDDLE:(v.buttons&H.RIGHT)===H.RIGHT?H.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}if((v.buttons&H.LEFT)===H.LEFT&&this._lockedPointer)return;const x={pointerId:v.pointerId,clientX:v.clientX,clientY:v.clientY,deltaX:0,deltaY:0,mouseButton:y};this._activePointers.push(x),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),this._isDragging=!0,p(v)},o=v=>{v.cancelable&&v.preventDefault();const y=v.pointerId,x=this._lockedPointer||this._findPointerById(y);if(x){if(x.clientX=v.clientX,x.clientY=v.clientY,x.deltaX=v.movementX,x.deltaY=v.movementY,this._state=0,v.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(v.buttons&H.LEFT)===H.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(v.buttons&H.MIDDLE)===H.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(v.buttons&H.RIGHT)===H.RIGHT&&(this._state=this._state|this.mouseButtons.right);g()}},c=v=>{const y=this._findPointerById(v.pointerId);if(!(y&&y===this._lockedPointer)){if(y&&this._disposePointer(y),v.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=f.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=f.NONE;C()}};let l=-1;const h=v=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===f.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),M=v.clientX/T.width,U=v.clientY/T.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||U<this._interactiveArea.top||U>this._interactiveArea.bottom)return}if(v.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===f.ROTATE||this.mouseButtons.wheel===f.TRUCK){const T=performance.now();l-T<1e3&&this._getClientRect(this._elementRect),l=T}const y=_n?-1:-3,x=v.deltaMode===1||v.ctrlKey?v.deltaY/y:v.deltaY/(y*10),O=this.dollyToCursor?(v.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(v.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case f.ROTATE:{this._rotateInternal(v.deltaX,v.deltaY),this._isUserControllingRotate=!0;break}case f.TRUCK:{this._truckInternal(v.deltaX,v.deltaY,!1,!1),this._isUserControllingTruck=!0;break}case f.SCREEN_PAN:{this._truckInternal(v.deltaX,v.deltaY,!1,!0),this._isUserControllingTruck=!0;break}case f.OFFSET:{this._truckInternal(v.deltaX,v.deltaY,!0,!1),this._isUserControllingOffset=!0;break}case f.DOLLY:{this._dollyInternal(-x,O,S),this._isUserControllingDolly=!0;break}case f.ZOOM:{this._zoomInternal(-x,O,S),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},u=v=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===re.ACTION.NONE){const y=v instanceof PointerEvent?v.pointerId:0,x=this._findPointerById(y);x&&this._disposePointer(x),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c);return}v.preventDefault()}},p=v=>{if(!this._enabled)return;if(ot(this._activePointers,q),this._getClientRect(this._elementRect),s.copy(q),n.copy(q),this._activePointers.length>=2){const x=q.x-this._activePointers[1].clientX,O=q.y-this._activePointers[1].clientY,S=Math.sqrt(x*x+O*O);r.set(0,S);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;n.set(T,M)}if(this._state=0,!v)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in v&&v.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(v.buttons&H.LEFT)===H.LEFT&&(this._state=this._state|this.mouseButtons.left),(v.buttons&H.MIDDLE)===H.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(v.buttons&H.RIGHT)===H.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&f.ROTATE)===f.ROTATE||(this._state&f.TOUCH_ROTATE)===f.TOUCH_ROTATE||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&f.TRUCK)===f.TRUCK||(this._state&f.SCREEN_PAN)===f.SCREEN_PAN||(this._state&f.TOUCH_TRUCK)===f.TOUCH_TRUCK||(this._state&f.TOUCH_SCREEN_PAN)===f.TOUCH_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&f.DOLLY)===f.DOLLY||(this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&f.ZOOM)===f.ZOOM||(this._state&f.TOUCH_ZOOM)===f.TOUCH_ZOOM||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&f.OFFSET)===f.OFFSET||(this._state&f.TOUCH_OFFSET)===f.TOUCH_OFFSET||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},g=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ot(this._activePointers,q);const y=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,x=y?-y.deltaX:n.x-q.x,O=y?-y.deltaY:n.y-q.y;if(n.copy(q),((this._state&f.ROTATE)===f.ROTATE||(this._state&f.TOUCH_ROTATE)===f.TOUCH_ROTATE||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(x,O),this._isUserControllingRotate=!0),(this._state&f.DOLLY)===f.DOLLY||(this._state&f.ZOOM)===f.ZOOM){const S=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,M=this.dollyDragInverted?-1:1;(this._state&f.DOLLY)===f.DOLLY?(this._dollyInternal(M*O*Ge,S,T),this._isUserControllingDolly=!0):(this._zoomInternal(M*O*Ge,S,T),this._isUserControllingZoom=!0)}if((this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_ZOOM)===f.TOUCH_ZOOM||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE){const S=q.x-this._activePointers[1].clientX,T=q.y-this._activePointers[1].clientY,M=Math.sqrt(S*S+T*T),U=r.y-M;r.set(0,M);const A=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,j=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET?(this._dollyInternal(U*Ge,A,j),this._isUserControllingDolly=!0):(this._zoomInternal(U*Ge,A,j),this._isUserControllingZoom=!0)}((this._state&f.TRUCK)===f.TRUCK||(this._state&f.TOUCH_TRUCK)===f.TOUCH_TRUCK||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(x,O,!1,!1),this._isUserControllingTruck=!0),((this._state&f.SCREEN_PAN)===f.SCREEN_PAN||(this._state&f.TOUCH_SCREEN_PAN)===f.TOUCH_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN)&&(this._truckInternal(x,O,!1,!0),this._isUserControllingTruck=!0),((this._state&f.OFFSET)===f.OFFSET||(this._state&f.TOUCH_OFFSET)===f.TOUCH_OFFSET||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(x,O,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},C=()=>{ot(this._activePointers,q),n.copy(q),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",_),this._domElement.ownerDocument.addEventListener("pointerlockerror",E),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),p())},this.unlockPointer=()=>{var v,y,x;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(v=this._domElement)===null||v===void 0||v.ownerDocument.exitPointerLock(),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockchange",_),(x=this._domElement)===null||x===void 0||x.ownerDocument.removeEventListener("pointerlockerror",E),this.cancel()};const _=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},E=()=>{this.unlockPointer()};this._addAllEventListeners=v=>{this._domElement=v,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),this._domElement.addEventListener("pointercancel",c),this._domElement.addEventListener("wheel",h,{passive:!1}),this._domElement.addEventListener("contextmenu",u)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("pointercancel",c),this._domElement.removeEventListener("wheel",h,{passive:!1}),this._domElement.removeEventListener("contextmenu",u),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.removeEventListener("pointerlockchange",_),this._domElement.ownerDocument.removeEventListener("pointerlockerror",E))},this.cancel=()=>{this._state!==f.NONE&&(this._state=f.NONE,this._activePointers.length=0,C())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}set interactiveArea(e){this._interactiveArea.width=te(e.width,0,1),this._interactiveArea.height=te(e.height,0,1),this._interactiveArea.x=te(e.x,0,1-this._interactiveArea.width),this._interactiveArea.y=te(e.y,0,1-this._interactiveArea.height)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}rotate(e,t,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+t,s)}rotateAzimuthTo(e,t=!1){return this.rotateTo(e,this._sphericalEnd.phi,t)}rotatePolarTo(e,t=!1){return this.rotateTo(this._sphericalEnd.theta,e,t)}rotateTo(e,t,s=!1){this._isUserControllingRotate=!1;const n=te(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=te(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,t=!1){return this.dollyTo(this._sphericalEnd.radius-e,t)}dollyTo(e,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0,this._dollyToNoClamp(te(e,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(e,t=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const a=this._collisionTest(),o=F(a,this._spherical.radius);if(!(s>e)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(e,a)}else this._sphericalEnd.radius=e;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const r=!t||F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(e,t=!1){this._targetEnd.add(this._getCameraDirection(Ue).multiplyScalar(e)),t||this._target.copy(this._targetEnd);const s=!t||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(e,t=!1){return this.zoomTo(this._zoomEnd+e,t)}zoomTo(e,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=te(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const s=!t||F(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(e,t,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(e,t,s)}truck(e,t,s=!1){this._camera.updateMatrix(),ie.setFromMatrixColumn(this._camera.matrix,0),se.setFromMatrixColumn(this._camera.matrix,1),ie.multiplyScalar(e),se.multiplyScalar(-t);const n=D.copy(ie).add(se),r=N.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,t=!1){D.setFromMatrixColumn(this._camera.matrix,0),D.crossVectors(this._camera.up,D),D.multiplyScalar(e);const s=N.copy(this._targetEnd).add(D);return this.moveTo(s.x,s.y,s.z,t)}elevate(e,t=!1){return D.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+D.x,this._targetEnd.y+D.y,this._targetEnd.z+D.z,t)}moveTo(e,t,s,n=!1){this._isUserControllingTruck=!1;const r=D.set(e,t,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,n||this._target.copy(this._targetEnd);const a=!n||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,t,s,n=!1){const o=D.set(e,t,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(o.x,o.y,o.z,n)}fitToBox(e,t,{cover:s=!1,paddingLeft:n=0,paddingRight:r=0,paddingBottom:a=0,paddingTop:o=0}={}){const c=[],l=e.isBox3?we.copy(e):we.setFromObject(e);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=Ht(this._sphericalEnd.theta,zt),u=Ht(this._sphericalEnd.phi,zt);c.push(this.rotateTo(h,u,t));const p=D.setFromSpherical(this._sphericalEnd).normalize(),g=qt.setFromUnitVectors(p,ht),C=F(Math.abs(p.y),1);C&&g.multiply(ut.setFromAxisAngle(We,h)),g.multiply(this._yAxisUpSpaceInverse);const _=Yt.makeEmpty();N.copy(l.min).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setX(l.max.x).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setY(l.max.y).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setZ(l.min.z).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setZ(l.max.z).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setY(l.min.y).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setX(l.min.x).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).applyQuaternion(g),_.expandByPoint(N),_.min.x-=n,_.min.y-=a,_.max.x+=r,_.max.y+=o,g.setFromUnitVectors(ht,p),C&&g.premultiply(ut.invert()),g.premultiply(this._yAxisUpSpace);const E=_.getSize(D),v=_.getCenter(N).applyQuaternion(g);if(me(this._camera)){const y=this.getDistanceToFitBox(E.x,E.y,E.z,s);c.push(this.moveTo(v.x,v.y,v.z,t)),c.push(this.dollyTo(y,t)),c.push(this.setFocalOffset(0,0,0,t))}else if(he(this._camera)){const y=this._camera,x=y.right-y.left,O=y.top-y.bottom,S=s?Math.max(x/E.x,O/E.y):Math.min(x/E.x,O/E.y);c.push(this.moveTo(v.x,v.y,v.z,t)),c.push(this.zoomTo(S,t)),c.push(this.setFocalOffset(0,0,0,t))}return Promise.all(c)}fitToSphere(e,t){const s=[],r="isObject3D"in e?re.createBoundingSphere(e,dt):dt.copy(e);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,t)),me(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,t))}else if(he(this._camera)){const a=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,c=2*r.radius,l=Math.min(a/c,o/c);s.push(this.zoomTo(l,t))}return s.push(this.setFocalOffset(0,0,0,t)),Promise.all(s)}setLookAt(e,t,s,n,r,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0;const c=N.set(n,r,a),l=D.set(e,t,s);this._targetEnd.copy(c),this._sphericalEnd.setFromVector3(l.sub(c).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold)&&F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(e,t,s,n,r,a,o,c,l,h,u,p,g,C=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0;const _=D.set(n,r,a),E=N.set(e,t,s);K.setFromVector3(E.sub(_).applyQuaternion(this._yAxisUpSpace));const v=Oe.set(h,u,p),y=N.set(o,c,l);ke.setFromVector3(y.sub(v).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(_.lerp(v,g));const x=ke.theta-K.theta,O=ke.phi-K.phi,S=ke.radius-K.radius;this._sphericalEnd.set(K.radius+S*g,K.phi+O*g,K.theta+x*g),this.normalizeRotations(),this._needsUpdate=!0,C||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!C||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold)&&F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(e,t,s,n=!1){return this.setLookAt(e,t,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,n)}setTarget(e,t,s,n=!1){const r=this.getPosition(D),a=this.setLookAt(r.x,r.y,r.z,e,t,s,n);return this._sphericalEnd.phi=te(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,t,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,t,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||F(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&F(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&F(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,t,s){this._camera.updateMatrixWorld(),ie.setFromMatrixColumn(this._camera.matrixWorldInverse,0),se.setFromMatrixColumn(this._camera.matrixWorldInverse,1),fe.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=D.set(e,t,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);ie.multiplyScalar(a.x),se.multiplyScalar(a.y),fe.multiplyScalar(a.z),D.copy(ie).add(se).add(fe),D.z=D.z+r,this.dollyTo(r,!1),this.setFocalOffset(-D.x,D.y,-D.z,!1),this.moveTo(e,t,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,t,s,n){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new P.Vector4,typeof e=="number"?this._viewport.set(e,t,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,t,s,n=!1){if(lt(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/t,a=this._camera.getEffectiveFOV()*De,o=this._camera.aspect;return((n?r>o:r<o)?t:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(lt(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const t=this._camera.getEffectiveFOV()*De,s=Math.atan(Math.tan(t*.5)*this._camera.aspect)*2,n=1<this._camera.aspect?t:s;return e/Math.sin(n*.5)}getTarget(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).copy(t?this._targetEnd:this._target)}getPosition(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).setFromSpherical(t?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(t?this._targetEnd:this._target)}getSpherical(e,t=!0){return(e||new P.Spherical).copy(t?this._sphericalEnd:this._spherical)}getFocalOffset(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).copy(t?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%xe,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=xe),this._spherical.theta+=xe*Math.round((this._sphericalEnd.theta-this._spherical.theta)/xe)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(e=!1){if(!F(this._camera.up.x,this._cameraUp0.x)||!F(this._camera.up.y,this._cameraUp0.y)||!F(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(D);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const t=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(t)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,We),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const e=D.subVectors(this._target,this._camera.position).normalize(),t=N.crossVectors(e,this._camera.up);this._camera.up.crossVectors(t,e).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(D);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(e){const t=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,n=this._sphericalEnd.radius-this._spherical.radius,r=Gt.subVectors(this._targetEnd,this._target),a=Wt.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(z(t))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ve(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(z(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ve(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(z(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ve(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(z(r.x)&&z(r.y)&&z(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Bt(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(z(a.x)&&z(a.y)&&z(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Bt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(z(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ve(this._zoom,this._zoomEnd,this._zoomVelocity,u,1/0,e)}if(this.dollyToCursor){if(me(this._camera)&&this._changedDolly!==0){const u=this._spherical.radius-this._lastDistance,p=this._camera,g=this._getCameraDirection(Ue),C=D.copy(g).cross(p.up).normalize();C.lengthSq()===0&&(C.x=1);const _=N.crossVectors(C,g),E=this._sphericalEnd.radius*Math.tan(p.getEffectiveFOV()*De*.5),y=(this._sphericalEnd.radius-u-this._sphericalEnd.radius)/this._sphericalEnd.radius,x=Oe.copy(this._targetEnd).add(C.multiplyScalar(this._dollyControlCoord.x*E*p.aspect)).add(_.multiplyScalar(this._dollyControlCoord.y*E)),O=D.copy(this._targetEnd).lerp(x,y),S=this._lastDollyDirection===Se.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===Se.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(S||T)){this._sphericalEnd.radius-=u,this._spherical.radius-=u;const U=N.copy(g).multiplyScalar(-u);O.add(U)}this._boundary.clampPoint(O,O);const M=N.subVectors(O,this._targetEnd);this._targetEnd.copy(O),this._target.add(M),this._changedDolly-=u,z(this._changedDolly)&&(this._changedDolly=0)}else if(he(this._camera)&&this._changedZoom!==0){const u=this._zoom-this._lastZoom,p=this._camera,g=D.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(p.near+p.far)/(p.near-p.far)).unproject(p),C=N.set(0,0,-1).applyQuaternion(p.quaternion),_=Oe.copy(g).add(C.multiplyScalar(-g.dot(p.up))),v=-(this._zoom-u-this._zoom)/this._zoom,y=this._getCameraDirection(Ue),x=this._targetEnd.dot(y),O=D.copy(this._targetEnd).lerp(_,v),S=O.dot(y),T=y.multiplyScalar(S-x);O.sub(T),this._boundary.clampPoint(O,O);const M=N.subVectors(O,this._targetEnd);this._targetEnd.copy(O),this._target.add(M),this._changedZoom-=u,z(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const c=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,c),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!z(this._focalOffset.x)||!z(this._focalOffset.y)||!z(this._focalOffset.z))&&(ie.setFromMatrixColumn(this._camera.matrix,0),se.setFromMatrixColumn(this._camera.matrix,1),fe.setFromMatrixColumn(this._camera.matrix,2),ie.multiplyScalar(this._focalOffset.x),se.multiplyScalar(-this._focalOffset.y),fe.multiplyScalar(this._focalOffset.z),D.copy(ie).add(se).add(fe),this._camera.position.add(D),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),D.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),z(t,this.restThreshold)&&z(s,this.restThreshold)&&z(n,this.restThreshold)&&z(r.x,this.restThreshold)&&z(r.y,this.restThreshold)&&z(r.z,this.restThreshold)&&z(a.x,this.restThreshold)&&z(a.y,this.restThreshold)&&z(a.z,this.restThreshold)&&z(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:Ie(this.maxDistance),minZoom:this.minZoom,maxZoom:Ie(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Ie(this.maxPolarAngle),minAzimuthAngle:Ie(this.minAzimuthAngle),maxAzimuthAngle:Ie(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:D.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,t=!1){const s=JSON.parse(e);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=Le(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=Le(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=Le(s.maxPolarAngle),this.minAzimuthAngle=Le(s.minAzimuthAngle),this.maxAzimuthAngle=Le(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],t),K.setFromVector3(D.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(K.theta,K.phi,t),this.dollyTo(K.radius,t),this.zoomTo(s.zoom,t),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],t),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}e.setAttribute("data-camera-controls-version",vn),this._addAllEventListeners(e),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(e){return e.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(e){return this._getTargetDirection(e).negate()}_findPointerById(e){return this._activePointers.find(t=>t.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(t=>t.mouseButton===e)}_disposePointer(e){this._activePointers.splice(this._activePointers.indexOf(e),1)}_encloseToBoundary(e,t,s){const n=t.lengthSq();if(n===0)return e;const r=N.copy(t).add(e),o=this._boundary.clampPoint(r,Oe).sub(r),c=o.lengthSq();if(c===0)return e.add(t);if(c===n)return e;if(s===0)return e.add(t).add(o);{const l=1+s*c/t.dot(o);return e.add(N.copy(t).multiplyScalar(l)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(me(this._camera)){const e=this._camera,t=e.near,s=e.getEffectiveFOV()*De,n=Math.tan(s*.5)*t,r=n*e.aspect;this._nearPlaneCorners[0].set(-r,-n,0),this._nearPlaneCorners[1].set(r,-n,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(-r,n,0)}else if(he(this._camera)){const e=this._camera,t=1/e.zoom,s=e.left*t,n=e.right*t,r=e.top*t,a=e.bottom*t;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(n,r,0),this._nearPlaneCorners[2].set(n,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||lt(this._camera,"_collisionTest"))return e;const s=this._getTargetDirection(Ue);pt.lookAt(Vt,s,this._camera.up);for(let n=0;n<4;n++){const r=N.copy(this._nearPlaneCorners[n]);r.applyMatrix4(pt);const a=Oe.addVectors(this._target,r);Ye.set(a,s),Ye.far=this._spherical.radius+1;const o=Ye.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<e&&(e=o[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const t=this._domElement.getBoundingClientRect();return e.x=t.left,e.y=t.top,this._viewport?(e.x+=this._viewport.x,e.y+=t.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=t.width,e.height=t.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const s=()=>{this.removeEventListener("rest",s),t()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(e){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(e){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(e,t=new P.Sphere){const s=t,n=s.center;we.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&we.expandByObject(a)}),we.getCenter(n);let r=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a;if(!o.geometry)return;const c=o.geometry.clone();c.applyMatrix4(o.matrixWorld);const h=c.attributes.position;for(let u=0,p=h.count;u<p;u++)D.fromBufferAttribute(h,u),r=Math.max(r,n.distanceToSquared(D))}),s.radius=Math.sqrt(r),s}}const Qe=i=>{const[e,t]=b.useState(i.options[i.index]),s=()=>{i.onToggle(!i.open)},n=a=>{a!==e&&(i.onSelect(a),t(a)),i.onToggle(!1)},r=i.open?`${i.options.length*31-1}px`:"0px";return d.jsxs("div",{className:`dropdown ${i.up===!0?"up":""}`,children:[d.jsx("div",{className:"dropdown-toggle",onClick:s,children:`${i.title}: ${e}`}),d.jsx("ul",{className:"dropdown-menu",style:{height:r},children:i.options.map(a=>d.jsx("li",{onClick:()=>n(a),children:a},a))})]})},ge=b.forwardRef(function(e,t){const s=["Renderer","Depth","Normals","UVs","Wireframe"],[n,r]=b.useState("Renderer"),[a,o]=b.useState(!1),[c,l]=b.useState(!1),[h,u]=b.useState(!1);return d.jsxs("div",{className:`CameraWindow ${e.name}`,children:[d.jsx("div",{ref:t,className:"clickable",onClick:()=>{h&&u(!1)}}),d.jsxs("div",{className:"options",children:[e.camera!==null&&d.jsx(Qe,{title:"Camera",index:e.options.indexOf(e.camera.name),open:h,options:e.options,onSelect:e.onSelectCamera,onToggle:p=>{p&&c&&l(!1),u(p)},up:!0}),d.jsx(Qe,{title:"Mode",index:s.indexOf(n),open:c,options:s,onSelect:p=>{if(p===n)return;const g=p;e.onSelectRenderMode(g),r(g)},onToggle:p=>{p&&h&&u(!1),a&&o(!1),l(p)},up:!0})]})]})}),yn=`out vec3 worldPosition;
38
+ */const H={LEFT:1,RIGHT:2,MIDDLE:4},f=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,SCREEN_PAN:4,OFFSET:8,DOLLY:16,ZOOM:32,TOUCH_ROTATE:64,TOUCH_TRUCK:128,TOUCH_SCREEN_PAN:256,TOUCH_OFFSET:512,TOUCH_DOLLY:1024,TOUCH_ZOOM:2048,TOUCH_DOLLY_TRUCK:4096,TOUCH_DOLLY_SCREEN_PAN:8192,TOUCH_DOLLY_OFFSET:16384,TOUCH_DOLLY_ROTATE:32768,TOUCH_ZOOM_TRUCK:65536,TOUCH_ZOOM_OFFSET:131072,TOUCH_ZOOM_SCREEN_PAN:262144,TOUCH_ZOOM_ROTATE:524288}),Se={NONE:0,IN:1,OUT:-1};function me(i){return i.isPerspectiveCamera}function he(i){return i.isOrthographicCamera}const xe=Math.PI*2,zt=Math.PI/2,mi=1e-5,De=Math.PI/180;function te(i,e,t){return Math.max(e,Math.min(t,i))}function z(i,e=mi){return Math.abs(i)<e}function F(i,e,t=mi){return z(i-e,t)}function Ht(i,e){return Math.round(i/e)*e}function Ie(i){return isFinite(i)?i:i<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Le(i){return Math.abs(i)<Number.MAX_VALUE?i:i*(1/0)}function Ve(i,e,t,s,n=1/0,r){s=Math.max(1e-4,s);const a=2/s,o=a*r,c=1/(1+o+.48*o*o+.235*o*o*o);let l=i-e;const h=e,u=n*s;l=te(l,-u,u),e=i-l;const p=(t.value+a*l)*r;t.value=(t.value-a*p)*c;let g=e+(l+p)*c;return h-i>0==g>h&&(g=h,t.value=(g-h)/r),g}function Bt(i,e,t,s,n=1/0,r,a){s=Math.max(1e-4,s);const o=2/s,c=o*r,l=1/(1+c+.48*c*c+.235*c*c*c);let h=e.x,u=e.y,p=e.z,g=i.x-h,C=i.y-u,_=i.z-p;const E=h,v=u,y=p,x=n*s,O=x*x,S=g*g+C*C+_*_;if(S>O){const pe=Math.sqrt(S);g=g/pe*x,C=C/pe*x,_=_/pe*x}h=i.x-g,u=i.y-C,p=i.z-_;const T=(t.x+o*g)*r,M=(t.y+o*C)*r,U=(t.z+o*_)*r;t.x=(t.x-o*T)*l,t.y=(t.y-o*M)*l,t.z=(t.z-o*U)*l,a.x=h+(g+T)*l,a.y=u+(C+M)*l,a.z=p+(_+U)*l;const A=E-i.x,j=v-i.y,ee=y-i.z,oe=a.x-E,ue=a.y-v,_e=a.z-y;return A*oe+j*ue+ee*_e>0&&(a.x=E,a.y=v,a.z=y,t.x=(a.x-E)/r,t.y=(a.y-v)/r,t.z=(a.z-y)/r),a}function ot(i,e){e.set(0,0),i.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=i.length,e.y/=i.length}function lt(i,e){return he(i)?(console.warn(`${e} is not supported in OrthographicCamera`),!0):!1}class fn{constructor(){this._listeners={}}addEventListener(e,t){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[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){const n=this._listeners[e];if(n!==void 0){const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}removeAllEventListeners(e){if(!e){this._listeners={};return}Array.isArray(this._listeners[e])&&(this._listeners[e].length=0)}dispatchEvent(e){const s=this._listeners[e.type];if(s!==void 0){e.target=this;const n=s.slice(0);for(let r=0,a=n.length;r<a;r++)n[r].call(this,e)}}}var ct;const gn="2.10.1",Ge=1/8,vn=/Mac/.test((ct=globalThis?.navigator)===null||ct===void 0?void 0:ct.platform);let P,Vt,We,ht,q,D,N,Oe,Ue,ie,se,fe,Gt,Wt,K,ke,we,Yt,dt,qt,ut,pt,Ye;class re extends fn{static install(e){P=e.THREE,Vt=Object.freeze(new P.Vector3(0,0,0)),We=Object.freeze(new P.Vector3(0,1,0)),ht=Object.freeze(new P.Vector3(0,0,1)),q=new P.Vector2,D=new P.Vector3,N=new P.Vector3,Oe=new P.Vector3,Ue=new P.Vector3,ie=new P.Vector3,se=new P.Vector3,fe=new P.Vector3,Gt=new P.Vector3,Wt=new P.Vector3,K=new P.Spherical,ke=new P.Spherical,we=new P.Box3,Yt=new P.Box3,dt=new P.Sphere,qt=new P.Quaternion,ut=new P.Quaternion,pt=new P.Matrix4,Ye=new P.Raycaster}static get ACTION(){return f}set verticalDragToForward(e){console.warn("camera-controls: `verticalDragToForward` was removed. Use `mouseButtons.left = CameraControls.ACTION.SCREEN_PAN` instead.")}constructor(e,t){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=f.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Se.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new P.Vector3,this._focalOffsetVelocity=new P.Vector3,this._zoomVelocity={value:0},this._truckInternal=(v,y,x,O)=>{let S,T;if(me(this._camera)){const M=D.copy(this._camera.position).sub(this._target),U=this._camera.getEffectiveFOV()*De,A=M.length()*Math.tan(U*.5);S=this.truckSpeed*v*A/this._elementRect.height,T=this.truckSpeed*y*A/this._elementRect.height}else if(he(this._camera)){const M=this._camera;S=this.truckSpeed*v*(M.right-M.left)/M.zoom/this._elementRect.width,T=this.truckSpeed*y*(M.top-M.bottom)/M.zoom/this._elementRect.height}else return;O?(x?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(S,0,!0),this.forward(-T,!0)):x?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y+T,this._focalOffsetEnd.z,!0):this.truck(S,T,!0)},this._rotateInternal=(v,y)=>{const x=xe*this.azimuthRotateSpeed*v/this._elementRect.height,O=xe*this.polarRotateSpeed*y/this._elementRect.height;this.rotate(x,O,!0)},this._dollyInternal=(v,y,x)=>{const O=Math.pow(.95,-v*this.dollySpeed),S=this._sphericalEnd.radius,T=this._sphericalEnd.radius*O,M=te(T,this.minDistance,this.maxDistance),U=M-T;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(T,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(U,!0),this._dollyToNoClamp(M,!0)):this._dollyToNoClamp(M,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?T:M)-S,this._dollyControlCoord.set(y,x)),this._lastDollyDirection=Math.sign(-v)},this._zoomInternal=(v,y,x)=>{const O=Math.pow(.95,v*this.dollySpeed),S=this._zoom,T=this._zoom*O;this.zoomTo(T,!0),this.dollyToCursor&&(this._changedZoom+=T-S,this._dollyControlCoord.set(y,x))},typeof P>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new P.Quaternion().setFromUnitVectors(this._camera.up,We),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=f.NONE,this._target=new P.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new P.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new P.Spherical().setFromVector3(D.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new P.Vector3,new P.Vector3,new P.Vector3,new P.Vector3],this._updateNearPlaneCorners(),this._boundary=new P.Box3(new P.Vector3(-1/0,-1/0,-1/0),new P.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new P.Vector2,this.mouseButtons={left:f.ROTATE,middle:f.DOLLY,right:f.TRUCK,wheel:me(this._camera)?f.DOLLY:he(this._camera)?f.ZOOM:f.NONE},this.touches={one:f.TOUCH_ROTATE,two:me(this._camera)?f.TOUCH_DOLLY_TRUCK:he(this._camera)?f.TOUCH_ZOOM_TRUCK:f.NONE,three:f.TOUCH_TRUCK};const s=new P.Vector2,n=new P.Vector2,r=new P.Vector2,a=v=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),S=v.clientX/O.width,T=v.clientY/O.height;if(S<this._interactiveArea.left||S>this._interactiveArea.right||T<this._interactiveArea.top||T>this._interactiveArea.bottom)return}const y=v.pointerType!=="mouse"?null:(v.buttons&H.LEFT)===H.LEFT?H.LEFT:(v.buttons&H.MIDDLE)===H.MIDDLE?H.MIDDLE:(v.buttons&H.RIGHT)===H.RIGHT?H.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}if((v.buttons&H.LEFT)===H.LEFT&&this._lockedPointer)return;const x={pointerId:v.pointerId,clientX:v.clientX,clientY:v.clientY,deltaX:0,deltaY:0,mouseButton:y};this._activePointers.push(x),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),this._isDragging=!0,p(v)},o=v=>{v.cancelable&&v.preventDefault();const y=v.pointerId,x=this._lockedPointer||this._findPointerById(y);if(x){if(x.clientX=v.clientX,x.clientY=v.clientY,x.deltaX=v.movementX,x.deltaY=v.movementY,this._state=0,v.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(v.buttons&H.LEFT)===H.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(v.buttons&H.MIDDLE)===H.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(v.buttons&H.RIGHT)===H.RIGHT&&(this._state=this._state|this.mouseButtons.right);g()}},c=v=>{const y=this._findPointerById(v.pointerId);if(!(y&&y===this._lockedPointer)){if(y&&this._disposePointer(y),v.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=f.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=f.NONE;C()}};let l=-1;const h=v=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===f.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),M=v.clientX/T.width,U=v.clientY/T.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||U<this._interactiveArea.top||U>this._interactiveArea.bottom)return}if(v.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===f.ROTATE||this.mouseButtons.wheel===f.TRUCK){const T=performance.now();l-T<1e3&&this._getClientRect(this._elementRect),l=T}const y=vn?-1:-3,x=v.deltaMode===1||v.ctrlKey?v.deltaY/y:v.deltaY/(y*10),O=this.dollyToCursor?(v.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(v.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case f.ROTATE:{this._rotateInternal(v.deltaX,v.deltaY),this._isUserControllingRotate=!0;break}case f.TRUCK:{this._truckInternal(v.deltaX,v.deltaY,!1,!1),this._isUserControllingTruck=!0;break}case f.SCREEN_PAN:{this._truckInternal(v.deltaX,v.deltaY,!1,!0),this._isUserControllingTruck=!0;break}case f.OFFSET:{this._truckInternal(v.deltaX,v.deltaY,!0,!1),this._isUserControllingOffset=!0;break}case f.DOLLY:{this._dollyInternal(-x,O,S),this._isUserControllingDolly=!0;break}case f.ZOOM:{this._zoomInternal(-x,O,S),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},u=v=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===re.ACTION.NONE){const y=v instanceof PointerEvent?v.pointerId:0,x=this._findPointerById(y);x&&this._disposePointer(x),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c);return}v.preventDefault()}},p=v=>{if(!this._enabled)return;if(ot(this._activePointers,q),this._getClientRect(this._elementRect),s.copy(q),n.copy(q),this._activePointers.length>=2){const x=q.x-this._activePointers[1].clientX,O=q.y-this._activePointers[1].clientY,S=Math.sqrt(x*x+O*O);r.set(0,S);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;n.set(T,M)}if(this._state=0,!v)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in v&&v.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(v.buttons&H.LEFT)===H.LEFT&&(this._state=this._state|this.mouseButtons.left),(v.buttons&H.MIDDLE)===H.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(v.buttons&H.RIGHT)===H.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&f.ROTATE)===f.ROTATE||(this._state&f.TOUCH_ROTATE)===f.TOUCH_ROTATE||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&f.TRUCK)===f.TRUCK||(this._state&f.SCREEN_PAN)===f.SCREEN_PAN||(this._state&f.TOUCH_TRUCK)===f.TOUCH_TRUCK||(this._state&f.TOUCH_SCREEN_PAN)===f.TOUCH_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&f.DOLLY)===f.DOLLY||(this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&f.ZOOM)===f.ZOOM||(this._state&f.TOUCH_ZOOM)===f.TOUCH_ZOOM||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&f.OFFSET)===f.OFFSET||(this._state&f.TOUCH_OFFSET)===f.TOUCH_OFFSET||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},g=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ot(this._activePointers,q);const y=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,x=y?-y.deltaX:n.x-q.x,O=y?-y.deltaY:n.y-q.y;if(n.copy(q),((this._state&f.ROTATE)===f.ROTATE||(this._state&f.TOUCH_ROTATE)===f.TOUCH_ROTATE||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(x,O),this._isUserControllingRotate=!0),(this._state&f.DOLLY)===f.DOLLY||(this._state&f.ZOOM)===f.ZOOM){const S=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,M=this.dollyDragInverted?-1:1;(this._state&f.DOLLY)===f.DOLLY?(this._dollyInternal(M*O*Ge,S,T),this._isUserControllingDolly=!0):(this._zoomInternal(M*O*Ge,S,T),this._isUserControllingZoom=!0)}if((this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_ZOOM)===f.TOUCH_ZOOM||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_ZOOM_ROTATE)===f.TOUCH_ZOOM_ROTATE){const S=q.x-this._activePointers[1].clientX,T=q.y-this._activePointers[1].clientY,M=Math.sqrt(S*S+T*T),U=r.y-M;r.set(0,M);const A=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,j=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&f.TOUCH_DOLLY)===f.TOUCH_DOLLY||(this._state&f.TOUCH_DOLLY_ROTATE)===f.TOUCH_DOLLY_ROTATE||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET?(this._dollyInternal(U*Ge,A,j),this._isUserControllingDolly=!0):(this._zoomInternal(U*Ge,A,j),this._isUserControllingZoom=!0)}((this._state&f.TRUCK)===f.TRUCK||(this._state&f.TOUCH_TRUCK)===f.TOUCH_TRUCK||(this._state&f.TOUCH_DOLLY_TRUCK)===f.TOUCH_DOLLY_TRUCK||(this._state&f.TOUCH_ZOOM_TRUCK)===f.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(x,O,!1,!1),this._isUserControllingTruck=!0),((this._state&f.SCREEN_PAN)===f.SCREEN_PAN||(this._state&f.TOUCH_SCREEN_PAN)===f.TOUCH_SCREEN_PAN||(this._state&f.TOUCH_DOLLY_SCREEN_PAN)===f.TOUCH_DOLLY_SCREEN_PAN||(this._state&f.TOUCH_ZOOM_SCREEN_PAN)===f.TOUCH_ZOOM_SCREEN_PAN)&&(this._truckInternal(x,O,!1,!0),this._isUserControllingTruck=!0),((this._state&f.OFFSET)===f.OFFSET||(this._state&f.TOUCH_OFFSET)===f.TOUCH_OFFSET||(this._state&f.TOUCH_DOLLY_OFFSET)===f.TOUCH_DOLLY_OFFSET||(this._state&f.TOUCH_ZOOM_OFFSET)===f.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(x,O,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},C=()=>{ot(this._activePointers,q),n.copy(q),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",_),this._domElement.ownerDocument.addEventListener("pointerlockerror",E),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),p())},this.unlockPointer=()=>{var v,y,x;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(v=this._domElement)===null||v===void 0||v.ownerDocument.exitPointerLock(),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockchange",_),(x=this._domElement)===null||x===void 0||x.ownerDocument.removeEventListener("pointerlockerror",E),this.cancel()};const _=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},E=()=>{this.unlockPointer()};this._addAllEventListeners=v=>{this._domElement=v,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),this._domElement.addEventListener("pointercancel",c),this._domElement.addEventListener("wheel",h,{passive:!1}),this._domElement.addEventListener("contextmenu",u)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("pointercancel",c),this._domElement.removeEventListener("wheel",h,{passive:!1}),this._domElement.removeEventListener("contextmenu",u),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.removeEventListener("pointerlockchange",_),this._domElement.ownerDocument.removeEventListener("pointerlockerror",E))},this.cancel=()=>{this._state!==f.NONE&&(this._state=f.NONE,this._activePointers.length=0,C())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}set interactiveArea(e){this._interactiveArea.width=te(e.width,0,1),this._interactiveArea.height=te(e.height,0,1),this._interactiveArea.x=te(e.x,0,1-this._interactiveArea.width),this._interactiveArea.y=te(e.y,0,1-this._interactiveArea.height)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}rotate(e,t,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+t,s)}rotateAzimuthTo(e,t=!1){return this.rotateTo(e,this._sphericalEnd.phi,t)}rotatePolarTo(e,t=!1){return this.rotateTo(this._sphericalEnd.theta,e,t)}rotateTo(e,t,s=!1){this._isUserControllingRotate=!1;const n=te(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=te(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,t=!1){return this.dollyTo(this._sphericalEnd.radius-e,t)}dollyTo(e,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0,this._dollyToNoClamp(te(e,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(e,t=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const a=this._collisionTest(),o=F(a,this._spherical.radius);if(!(s>e)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(e,a)}else this._sphericalEnd.radius=e;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const r=!t||F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(e,t=!1){this._targetEnd.add(this._getCameraDirection(Ue).multiplyScalar(e)),t||this._target.copy(this._targetEnd);const s=!t||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(e,t=!1){return this.zoomTo(this._zoomEnd+e,t)}zoomTo(e,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=te(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const s=!t||F(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(e,t,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(e,t,s)}truck(e,t,s=!1){this._camera.updateMatrix(),ie.setFromMatrixColumn(this._camera.matrix,0),se.setFromMatrixColumn(this._camera.matrix,1),ie.multiplyScalar(e),se.multiplyScalar(-t);const n=D.copy(ie).add(se),r=N.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,t=!1){D.setFromMatrixColumn(this._camera.matrix,0),D.crossVectors(this._camera.up,D),D.multiplyScalar(e);const s=N.copy(this._targetEnd).add(D);return this.moveTo(s.x,s.y,s.z,t)}elevate(e,t=!1){return D.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+D.x,this._targetEnd.y+D.y,this._targetEnd.z+D.z,t)}moveTo(e,t,s,n=!1){this._isUserControllingTruck=!1;const r=D.set(e,t,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,n||this._target.copy(this._targetEnd);const a=!n||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,t,s,n=!1){const o=D.set(e,t,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(o.x,o.y,o.z,n)}fitToBox(e,t,{cover:s=!1,paddingLeft:n=0,paddingRight:r=0,paddingBottom:a=0,paddingTop:o=0}={}){const c=[],l=e.isBox3?we.copy(e):we.setFromObject(e);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=Ht(this._sphericalEnd.theta,zt),u=Ht(this._sphericalEnd.phi,zt);c.push(this.rotateTo(h,u,t));const p=D.setFromSpherical(this._sphericalEnd).normalize(),g=qt.setFromUnitVectors(p,ht),C=F(Math.abs(p.y),1);C&&g.multiply(ut.setFromAxisAngle(We,h)),g.multiply(this._yAxisUpSpaceInverse);const _=Yt.makeEmpty();N.copy(l.min).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setX(l.max.x).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setY(l.max.y).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setZ(l.min.z).applyQuaternion(g),_.expandByPoint(N),N.copy(l.min).setZ(l.max.z).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setY(l.min.y).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).setX(l.min.x).applyQuaternion(g),_.expandByPoint(N),N.copy(l.max).applyQuaternion(g),_.expandByPoint(N),_.min.x-=n,_.min.y-=a,_.max.x+=r,_.max.y+=o,g.setFromUnitVectors(ht,p),C&&g.premultiply(ut.invert()),g.premultiply(this._yAxisUpSpace);const E=_.getSize(D),v=_.getCenter(N).applyQuaternion(g);if(me(this._camera)){const y=this.getDistanceToFitBox(E.x,E.y,E.z,s);c.push(this.moveTo(v.x,v.y,v.z,t)),c.push(this.dollyTo(y,t)),c.push(this.setFocalOffset(0,0,0,t))}else if(he(this._camera)){const y=this._camera,x=y.right-y.left,O=y.top-y.bottom,S=s?Math.max(x/E.x,O/E.y):Math.min(x/E.x,O/E.y);c.push(this.moveTo(v.x,v.y,v.z,t)),c.push(this.zoomTo(S,t)),c.push(this.setFocalOffset(0,0,0,t))}return Promise.all(c)}fitToSphere(e,t){const s=[],r="isObject3D"in e?re.createBoundingSphere(e,dt):dt.copy(e);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,t)),me(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,t))}else if(he(this._camera)){const a=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,c=2*r.radius,l=Math.min(a/c,o/c);s.push(this.zoomTo(l,t))}return s.push(this.setFocalOffset(0,0,0,t)),Promise.all(s)}setLookAt(e,t,s,n,r,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0;const c=N.set(n,r,a),l=D.set(e,t,s);this._targetEnd.copy(c),this._sphericalEnd.setFromVector3(l.sub(c).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold)&&F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(e,t,s,n,r,a,o,c,l,h,u,p,g,C=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Se.NONE,this._changedDolly=0;const _=D.set(n,r,a),E=N.set(e,t,s);K.setFromVector3(E.sub(_).applyQuaternion(this._yAxisUpSpace));const v=Oe.set(h,u,p),y=N.set(o,c,l);ke.setFromVector3(y.sub(v).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(_.lerp(v,g));const x=ke.theta-K.theta,O=ke.phi-K.phi,S=ke.radius-K.radius;this._sphericalEnd.set(K.radius+S*g,K.phi+O*g,K.theta+x*g),this.normalizeRotations(),this._needsUpdate=!0,C||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const T=!C||F(this._target.x,this._targetEnd.x,this.restThreshold)&&F(this._target.y,this._targetEnd.y,this.restThreshold)&&F(this._target.z,this._targetEnd.z,this.restThreshold)&&F(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&F(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&F(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(T)}setPosition(e,t,s,n=!1){return this.setLookAt(e,t,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,n)}setTarget(e,t,s,n=!1){const r=this.getPosition(D),a=this.setLookAt(r.x,r.y,r.z,e,t,s,n);return this._sphericalEnd.phi=te(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,t,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,t,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||F(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&F(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&F(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,t,s){this._camera.updateMatrixWorld(),ie.setFromMatrixColumn(this._camera.matrixWorldInverse,0),se.setFromMatrixColumn(this._camera.matrixWorldInverse,1),fe.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=D.set(e,t,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);ie.multiplyScalar(a.x),se.multiplyScalar(a.y),fe.multiplyScalar(a.z),D.copy(ie).add(se).add(fe),D.z=D.z+r,this.dollyTo(r,!1),this.setFocalOffset(-D.x,D.y,-D.z,!1),this.moveTo(e,t,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,t,s,n){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new P.Vector4,typeof e=="number"?this._viewport.set(e,t,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,t,s,n=!1){if(lt(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/t,a=this._camera.getEffectiveFOV()*De,o=this._camera.aspect;return((n?r>o:r<o)?t:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(lt(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const t=this._camera.getEffectiveFOV()*De,s=Math.atan(Math.tan(t*.5)*this._camera.aspect)*2,n=1<this._camera.aspect?t:s;return e/Math.sin(n*.5)}getTarget(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).copy(t?this._targetEnd:this._target)}getPosition(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).setFromSpherical(t?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(t?this._targetEnd:this._target)}getSpherical(e,t=!0){return(e||new P.Spherical).copy(t?this._sphericalEnd:this._spherical)}getFocalOffset(e,t=!0){return(e&&e.isVector3?e:new P.Vector3).copy(t?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%xe,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=xe),this._spherical.theta+=xe*Math.round((this._sphericalEnd.theta-this._spherical.theta)/xe)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(e=!1){if(!F(this._camera.up.x,this._cameraUp0.x)||!F(this._camera.up.y,this._cameraUp0.y)||!F(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(D);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const t=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(t)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,We),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const e=D.subVectors(this._target,this._camera.position).normalize(),t=N.crossVectors(e,this._camera.up);this._camera.up.crossVectors(t,e).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(D);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(e){const t=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,n=this._sphericalEnd.radius-this._spherical.radius,r=Gt.subVectors(this._targetEnd,this._target),a=Wt.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(z(t))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ve(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(z(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ve(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(z(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ve(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(z(r.x)&&z(r.y)&&z(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Bt(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(z(a.x)&&z(a.y)&&z(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Bt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(z(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ve(this._zoom,this._zoomEnd,this._zoomVelocity,u,1/0,e)}if(this.dollyToCursor){if(me(this._camera)&&this._changedDolly!==0){const u=this._spherical.radius-this._lastDistance,p=this._camera,g=this._getCameraDirection(Ue),C=D.copy(g).cross(p.up).normalize();C.lengthSq()===0&&(C.x=1);const _=N.crossVectors(C,g),E=this._sphericalEnd.radius*Math.tan(p.getEffectiveFOV()*De*.5),y=(this._sphericalEnd.radius-u-this._sphericalEnd.radius)/this._sphericalEnd.radius,x=Oe.copy(this._targetEnd).add(C.multiplyScalar(this._dollyControlCoord.x*E*p.aspect)).add(_.multiplyScalar(this._dollyControlCoord.y*E)),O=D.copy(this._targetEnd).lerp(x,y),S=this._lastDollyDirection===Se.IN&&this._spherical.radius<=this.minDistance,T=this._lastDollyDirection===Se.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(S||T)){this._sphericalEnd.radius-=u,this._spherical.radius-=u;const U=N.copy(g).multiplyScalar(-u);O.add(U)}this._boundary.clampPoint(O,O);const M=N.subVectors(O,this._targetEnd);this._targetEnd.copy(O),this._target.add(M),this._changedDolly-=u,z(this._changedDolly)&&(this._changedDolly=0)}else if(he(this._camera)&&this._changedZoom!==0){const u=this._zoom-this._lastZoom,p=this._camera,g=D.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(p.near+p.far)/(p.near-p.far)).unproject(p),C=N.set(0,0,-1).applyQuaternion(p.quaternion),_=Oe.copy(g).add(C.multiplyScalar(-g.dot(p.up))),v=-(this._zoom-u-this._zoom)/this._zoom,y=this._getCameraDirection(Ue),x=this._targetEnd.dot(y),O=D.copy(this._targetEnd).lerp(_,v),S=O.dot(y),T=y.multiplyScalar(S-x);O.sub(T),this._boundary.clampPoint(O,O);const M=N.subVectors(O,this._targetEnd);this._targetEnd.copy(O),this._target.add(M),this._changedZoom-=u,z(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const c=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,c),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!z(this._focalOffset.x)||!z(this._focalOffset.y)||!z(this._focalOffset.z))&&(ie.setFromMatrixColumn(this._camera.matrix,0),se.setFromMatrixColumn(this._camera.matrix,1),fe.setFromMatrixColumn(this._camera.matrix,2),ie.multiplyScalar(this._focalOffset.x),se.multiplyScalar(-this._focalOffset.y),fe.multiplyScalar(this._focalOffset.z),D.copy(ie).add(se).add(fe),this._camera.position.add(D),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),D.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),z(t,this.restThreshold)&&z(s,this.restThreshold)&&z(n,this.restThreshold)&&z(r.x,this.restThreshold)&&z(r.y,this.restThreshold)&&z(r.z,this.restThreshold)&&z(a.x,this.restThreshold)&&z(a.y,this.restThreshold)&&z(a.z,this.restThreshold)&&z(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:Ie(this.maxDistance),minZoom:this.minZoom,maxZoom:Ie(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Ie(this.maxPolarAngle),minAzimuthAngle:Ie(this.minAzimuthAngle),maxAzimuthAngle:Ie(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:D.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,t=!1){const s=JSON.parse(e);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=Le(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=Le(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=Le(s.maxPolarAngle),this.minAzimuthAngle=Le(s.minAzimuthAngle),this.maxAzimuthAngle=Le(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],t),K.setFromVector3(D.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(K.theta,K.phi,t),this.dollyTo(K.radius,t),this.zoomTo(s.zoom,t),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],t),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}e.setAttribute("data-camera-controls-version",gn),this._addAllEventListeners(e),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(e){return e.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(e){return this._getTargetDirection(e).negate()}_findPointerById(e){return this._activePointers.find(t=>t.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(t=>t.mouseButton===e)}_disposePointer(e){this._activePointers.splice(this._activePointers.indexOf(e),1)}_encloseToBoundary(e,t,s){const n=t.lengthSq();if(n===0)return e;const r=N.copy(t).add(e),o=this._boundary.clampPoint(r,Oe).sub(r),c=o.lengthSq();if(c===0)return e.add(t);if(c===n)return e;if(s===0)return e.add(t).add(o);{const l=1+s*c/t.dot(o);return e.add(N.copy(t).multiplyScalar(l)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(me(this._camera)){const e=this._camera,t=e.near,s=e.getEffectiveFOV()*De,n=Math.tan(s*.5)*t,r=n*e.aspect;this._nearPlaneCorners[0].set(-r,-n,0),this._nearPlaneCorners[1].set(r,-n,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(-r,n,0)}else if(he(this._camera)){const e=this._camera,t=1/e.zoom,s=e.left*t,n=e.right*t,r=e.top*t,a=e.bottom*t;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(n,r,0),this._nearPlaneCorners[2].set(n,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||lt(this._camera,"_collisionTest"))return e;const s=this._getTargetDirection(Ue);pt.lookAt(Vt,s,this._camera.up);for(let n=0;n<4;n++){const r=N.copy(this._nearPlaneCorners[n]);r.applyMatrix4(pt);const a=Oe.addVectors(this._target,r);Ye.set(a,s),Ye.far=this._spherical.radius+1;const o=Ye.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<e&&(e=o[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const t=this._domElement.getBoundingClientRect();return e.x=t.left,e.y=t.top,this._viewport?(e.x+=this._viewport.x,e.y+=t.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=t.width,e.height=t.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const s=()=>{this.removeEventListener("rest",s),t()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(e){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(e){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(e,t=new P.Sphere){const s=t,n=s.center;we.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&we.expandByObject(a)}),we.getCenter(n);let r=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a;if(!o.geometry)return;const c=o.geometry.clone();c.applyMatrix4(o.matrixWorld);const h=c.attributes.position;for(let u=0,p=h.count;u<p;u++)D.fromBufferAttribute(h,u),r=Math.max(r,n.distanceToSquared(D))}),s.radius=Math.sqrt(r),s}}const Qe=i=>{const[e,t]=b.useState(i.options[i.index]),s=()=>{i.onToggle(!i.open)},n=a=>{a!==e&&(i.onSelect(a),t(a)),i.onToggle(!1)},r=i.open?`${i.options.length*31-1}px`:"0px";return d.jsxs("div",{className:`dropdown ${i.up===!0?"up":""}`,children:[d.jsx("div",{className:"dropdown-toggle",onClick:s,children:`${i.title}: ${e}`}),d.jsx("ul",{className:"dropdown-menu",style:{height:r},children:i.options.map(a=>d.jsx("li",{onClick:()=>n(a),children:a},a))})]})},ge=b.forwardRef(function(e,t){const s=["Renderer","Depth","Normals","UVs","Wireframe"],[n,r]=b.useState("Renderer"),[a,o]=b.useState(!1),[c,l]=b.useState(!1),[h,u]=b.useState(!1);return d.jsxs("div",{className:`CameraWindow ${e.name}`,children:[d.jsx("div",{ref:t,className:"clickable",onClick:()=>{h&&u(!1)}}),d.jsxs("div",{className:"options",children:[e.camera!==null&&d.jsx(Qe,{title:"Camera",index:e.options.indexOf(e.camera.name),open:h,options:e.options,onSelect:e.onSelectCamera,onToggle:p=>{p&&c&&l(!1),u(p)},up:!0}),d.jsx(Qe,{title:"Mode",index:s.indexOf(n),open:c,options:s,onSelect:p=>{if(p===n)return;const g=p;e.onSelectRenderMode(g),r(g)},onToggle:p=>{p&&h&&u(!1),a&&o(!1),l(p)},up:!0})]})]})}),_n=`out vec3 worldPosition;
39
39
  uniform float uDistance;
40
40
 
41
41
  void main() {
@@ -44,7 +44,7 @@ void main() {
44
44
  worldPosition.xz += cameraPosition.xz;
45
45
 
46
46
  gl_Position = projectionMatrix * modelViewMatrix * vec4(worldPosition, 1.0);
47
- }`,Cn=`out vec4 fragColor;
47
+ }`,yn=`out vec4 fragColor;
48
48
  in vec3 worldPosition;
49
49
  uniform float uDivisions;
50
50
  uniform float uScale;
@@ -112,7 +112,7 @@ void main() {
112
112
  fragColor.a = mix(fragColor.a, baseOpacity * uGridOpacity, nextGrid);
113
113
 
114
114
  if (fragColor.a <= minAlpha) discard;
115
- }`;class fi extends m.ShaderMaterial{constructor(e){super({extensions:{derivatives:!0},uniforms:{uScale:{value:e?.scale!==void 0?e?.scale:.1},uDivisions:{value:e?.divisions!==void 0?e?.divisions:10},uColor:{value:e?.color!==void 0?e?.color:new m.Color(16777215)},uDistance:{value:e?.distance!==void 0?e?.distance:1e4},uSubgridOpacity:{value:e?.subgridOpacity!==void 0?e?.subgridOpacity:.15},uGridOpacity:{value:e?.gridOpacity!==void 0?e?.gridOpacity:.25}},glslVersion:m.GLSL3,side:m.DoubleSide,transparent:!0,name:"InfiniteGrid",vertexShader:yn,fragmentShader:Cn})}get color(){return this.uniforms.uColor.value}set color(e){this.uniforms.uColor.value=e}get gridOpacity(){return this.uniforms.uGridOpacity.value}set gridOpacity(e){this.uniforms.uGridOpacity.value=e}get subgridOpacity(){return this.uniforms.uSubgridOpacity.value}set subgridOpacity(e){this.uniforms.uSubgridOpacity.value=e}}class gi extends m.Mesh{gridMaterial;constructor(e){const t=new fi(e);super(new m.PlaneGeometry,t),this.gridMaterial=t,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}class vi extends w.NodeMaterial{uScale;uDivisions;uColor;uDistance;uSubgridOpacity;uGridOpacity;constructor(e){super(),this.name="InfiniteGrid",this.side=w.DoubleSide,this.transparent=!0,this.uScale=R.uniform(e?.scale??.1),this.uDivisions=R.uniform(e?.divisions??10),this.uColor=R.uniform(e?.color??new w.Color(16777215)),this.uDistance=R.uniform(e?.distance??1e4),this.uSubgridOpacity=R.uniform(e?.subgridOpacity??.15),this.uGridOpacity=R.uniform(e?.gridOpacity??.25);const{uScale:t,uDivisions:s,uColor:n,uDistance:r,uSubgridOpacity:a,uGridOpacity:o}=this,c=R.varyingProperty("vec3","vWorldPosition");this.positionNode=R.Fn(()=>{const h=R.positionLocal.xzy.mul(r).add(R.vec3(R.cameraPosition.x,R.float(0),R.cameraPosition.z));return c.assign(h),h})();const l=R.Fn(([h])=>{const u=c.xz.div(h),p=R.fwidth(u),g=R.abs(R.fract(u.sub(.5)).sub(.5)).div(p).div(2),C=R.min(g.x,g.y);return R.float(1).sub(R.min(C,R.float(1)))});this.outputNode=R.Fn(()=>{const h=c,u=R.max(R.float(200),R.abs(R.cameraPosition.y.sub(h.y))),p=R.float(R.distance(R.cameraPosition,h)),g=R.log(u).div(R.log(s)),C=R.pow(s,R.floor(g)),_=C.mul(s),E=_.mul(s),v=l(C.mul(t)),y=l(_.mul(t)),x=l(E.mul(t)),O=u.sub(C).div(_.sub(C)),S=R.float(.3),T=R.max(O.sub(R.float(1)).add(S),R.float(0)).div(S),M=v.mul(R.pow(R.float(1).sub(R.min(p.div(r),R.float(1))),R.float(3))),U=R.float(.5),A=M.sub(T).mul(a),j=R.mix(A,M.mul(o).sub(T.mul(o.sub(a)).mul(U)),y),ee=R.float(R.mix(j,M.mul(o),x));return R.If(R.lessThanEqual(ee,R.float(1/127)),()=>{R.Discard()}),R.vec4(n,ee)})()}get color(){return this.uColor.value}set color(e){this.uColor.value=e}get gridOpacity(){return this.uGridOpacity.value}set gridOpacity(e){this.uGridOpacity.value=e}get subgridOpacity(){return this.uSubgridOpacity.value}set subgridOpacity(e){this.uSubgridOpacity.value=e}}class _i extends w.Mesh{gridMaterial;constructor(e){const t=new vi(e);super(new w.PlaneGeometry,t),this.gridMaterial=t,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}function mt(i){const[e,t]=b.useState(i.selected),s="toggle"+(e?" selected":"");return d.jsx("button",{className:s,onClick:()=>{const n=!e;t(n),i.onClick(n)},style:{backgroundImage:`url(${i.icon})`,backgroundPositionX:"center",backgroundPositionY:i.top!==void 0?`${i.top}px`:"center",backgroundSize:`${i.width!==void 0?`${i.width}px`:"26px"} ${i.height}px`}},i.name)}class yi extends Kt{constructor(){super();const e=je.remapClamp(je.linearDepth(),.1,.5,0,1).oneMinus();this.colorNode=je.vec4(e,e,e,1)}}class Ci extends Kt{constructor(){super(),this.colorNode=je.vec4(je.uv(),0,1)}}class W extends m.EventDispatcher{static DRAG_START="Transform::dragStart";static DRAG_END="Transform::dragEnd";static _instance;three;activeCamera;controls=new Map;visibility=new Map;setApp(e){this.three=e,this.three.addEventListener(L.SET_SCENE,this.setScene)}clear(){for(const e of this.controls.values()){e.detach(),e.disconnect();const t=e.getHelper();Q(t)}this.controls=new Map,this.visibility=new Map}add(e){let t=this.controls.get(e);if(t===void 0){const s=document.querySelector(".clickable");t=new zi.TransformControls(this.activeCamera,s),t.getHelper().name=e,t.setSize(.5),t.setSpace("local"),this.controls.set(e,t),this.visibility.set(e,!0),t.addEventListener("mouseDown",()=>{this.dispatchEvent({type:W.DRAG_START})}),t.addEventListener("mouseUp",()=>{this.dispatchEvent({type:W.DRAG_END})}),t.addEventListener("dragging-changed",n=>{G.instance?.toggleOrbitControls(n.value)})}return t}get(e){return this.controls.get(e)}remove(e){const t=this.get(e);return t===void 0?!1:(t.detach(),t.disconnect(),Q(t.getHelper()),this.controls.delete(e),!0)}enabled(e){this.controls.forEach(t=>{t.enabled=e})}updateCamera(e,t){this.activeCamera=e,this.controls.forEach(s=>{s.camera!==e&&(s.camera=e,e.getWorldPosition(s.cameraPosition),e.getWorldQuaternion(s.cameraQuaternion)),s.domElement!==t&&(s.disconnect(),s.domElement=t,s.connect(t))})}show(){this.controls.forEach(e=>{const t=e.getHelper(),s=this.visibility.get(t.name);s!==void 0&&(t.visible=s)})}hide(){this.controls.forEach(e=>{const t=e.getHelper();this.visibility.set(t.name,t.visible),t.visible=!1})}setScene=()=>{this.clear()};static get instance(){return W._instance||(W._instance=new W),W._instance}}const bn=new w.BoxGeometry,ft=new w.Vector2;class Ke extends w.Object3D{curve=new w.CatmullRomCurve3;line;draggable;curvePos;tension=.5;closed=!1;subdivide=50;curveType;offset=1;lineMaterial;_camera;_curvePercentage=0;_draggableScale=10;_transform;raycaster;draggedMat=new w.MeshBasicMaterial;parentGroup;group;constructor(e,t){const s=new w.Color($.lerp(.5,1,Math.random()),$.lerp(.5,1,Math.random()),$.lerp(.5,1,Math.random()));super(),this.name=e,this.lineMaterial=new w.LineBasicMaterial({color:s}),this.line=new w.Line(new w.BufferGeometry,this.lineMaterial),this.line.name="line",this.line.visible=!1,this.add(this.line),this._camera=t,this.curveType="catmullrom",this.draggedMat.color=s,this.draggable=new w.Object3D,this.draggable.name="draggablePoints",this.add(this.draggable),this.curvePos=new w.Mesh(new w.SphereGeometry(1.5),new w.MeshBasicMaterial({color:s})),this.curvePos.name="curvePos",this.curvePos.scale.setScalar(this._draggableScale),this.curvePos.visible=!1,this.add(this.curvePos),this.raycaster=new w.Raycaster,this.raycaster.params.Line.threshold=3,this.enable()}enable(){document.addEventListener("pointerdown",this.onMouseClick)}disable(){document.removeEventListener("pointerdown",this.onMouseClick)}dispose=()=>{this._transform&&(this._transform.removeEventListener("objectChange",this.updateSpline),W.instance.remove(this.name)),this.disable(),this.parentGroup.removeGroup(this.name)};hideTransform=()=>{this._transform?.detach()};exportSpline=()=>{const e=[];this.draggable.children.forEach(t=>{e.push([X(t.position.x,3),X(t.position.y,3),X(t.position.z,3)])}),Xt({name:this.name,points:e,tension:this.tension,closed:this.closed,subdivide:this.subdivide,type:this.curveType}),console.log("Spline copied!")};showPoints=(e=!0)=>{this.draggable.visible=e};addPoints=(e=[])=>{if(e.length>0){const t=e.length-1;for(let s=0;s<t;s++)this.addPoint(e[s],!1);this.addPoint(e[t])}};addPoint=(e,t=!0)=>{const s=this.draggable.children.length,n=new w.Mesh(bn,this.draggedMat);n.name=`point_${s}`,n.position.copy(e),n.scale.setScalar(this._draggableScale),this.draggable.add(n),this._transform?.attach(n);const r=this.points.length>1;return r&&t&&this.updateSpline(),this.line.visible=r,this.updateCurrentPoint(),n};addNextPt=()=>{const e=this.draggable.children.length,t=e>1?this.draggable.children[e-1].position.clone():new w.Vector3,s=this.addPoint(t);this.updateField(s.position)};removePoint=e=>{if(this._transform?.object===e){this._transform?.detach();const t=this.draggable.children[this.draggable.children.length-1];this._transform?.attach(t),this.updateField(t.position)}Q(e),this.updateSpline()};removePointAt=e=>{const t=this.draggable.children[e];this.removePoint(t)};removeSelectedPt=()=>{this._transform?.object!==void 0&&this.removePoint(this._transform?.object)};updateLastPoint(e){const t=this.draggable.children.length;t>0&&(this.draggable.children[t-1].position.copy(e),this.updateSpline())}updateSpline=()=>{this.points.length<2||(this.curve=new w.CatmullRomCurve3(this.points,this.closed,this.curveType,this.tension),this.line.geometry.dispose(),this.line.geometry=new w.BufferGeometry().setFromPoints(this.curve.getPoints(this.subdivide)),this.curvePos.position.copy(this.getPointAt(this._curvePercentage)))};updateField(e){this.group.current?.setField("Current Point",e)}onMouseClick=e=>{if(!G.instance||!G.instance.currentWindow||this._transform&&!this._transform.getHelper().visible)return;const s=G.instance.currentWindow.current.getBoundingClientRect();ft.x=(e.clientX-s.x)/s.width*2-1,ft.y=-((e.clientY-s.y)/s.height)*2+1,this.raycaster.setFromCamera(ft,this.camera);const n=this.raycaster.intersectObjects(this.draggable.children,!1);if(n.length>0){const r=n[0].object;r!==this._transform?.object&&(this._transform?.attach(r),this.updateField(r.position))}};getPointAt(e){return this.curve.points.length>1?this.curve.getPointAt(e):this.curve.points.length===1?this.curve.points[0]:new w.Vector3}getTangentAt(e){return this.curve.getTangentAt(e)}get points(){const e=[];return this.draggable.children.forEach(t=>{e.push(t.position)}),e}get total(){return this.draggable.children.length}get draggableScale(){return this._draggableScale}set draggableScale(e){this._draggableScale=e,this.draggable.children.forEach(t=>t.scale.setScalar(e)),this.curvePos.scale.setScalar(e)}get camera(){return this._camera}set camera(e){this._camera=e,this._transform!==void 0&&(this._transform.camera=e)}get curvePercentage(){return this._curvePercentage}set curvePercentage(e){this._curvePercentage=e,this.curvePos.position.copy(this.getPointAt(e))}updateCurrentPoint(){if(this._transform?.object&&this.group){const e=this._transform?.object;e.name.search("point")>-1&&this.updateField(e.position)}}onUpdateTransform=()=>{this.updateCurrentPoint(),this.updateSpline()};initDebug(e,t){const s=this.draggable.children;this.visible=t,this.parentGroup=e,this._transform=W.instance.add(this.name),this._transform.camera=this._camera,this._transform.addEventListener("objectChange",this.onUpdateTransform),s.length>0&&this._transform.attach(s[s.length-1]),G.instance?.helpersContainer.add(this._transform.getHelper());const n=s.length>0?s[s.length-1].position:{x:0,y:0,z:0};this.group=e.addGroup({title:this.name,expanded:t,items:[{prop:"Closed",type:"boolean",value:this.closed},{prop:"Visible",type:"boolean",value:this.visible},{prop:"Show Position",type:"boolean",value:this.curvePos.visible},{prop:"Show Points",type:"boolean",value:this.draggable.visible},{prop:"Color",type:"color",value:`#${this.draggedMat.color.getHexString()}`},{prop:"Curve",type:"option",options:[{title:"Catmullrom",value:"catmullrom"},{title:"Centripetal",value:"centripetal"},{title:"Chordal",value:"chordal"}]},{prop:"Draggable Scale",type:"range",min:.01,max:100,step:.01,value:this._draggableScale},{prop:"Subdivide",type:"range",min:1,max:1e3,step:1,value:this.subdivide},{prop:"Tension",type:"range",min:0,max:1,step:.01,value:this.tension},{prop:"New Pt Offset",type:"range",min:0,max:10,value:this.offset},{prop:"Curve At",type:"range",min:0,max:1,step:.01,value:0},{prop:"Toggle Transform",type:"button"},{prop:"Add Point",type:"button"},{prop:"Remove Point",type:"button"},{prop:"Export",type:"button"},{prop:"Delete",type:"button"},{prop:"Current Point",type:"grid3",value:n}],onUpdate:(r,a)=>{switch(r){case"Closed":this.closed=a,this.updateSpline();break;case"Visible":this.visible=a;break;case"Color":this.lineMaterial.color.setStyle(a),this.draggedMat.color.setStyle(a);break;case"Curve":this.curveType=a,this.updateSpline();break;case"Draggable Scale":this.draggableScale=a;break;case"Subdivide":this.subdivide=a,this.updateSpline();break;case"Tension":this.tension=a,this.updateSpline();break;case"New Pt Offset":this.offset=a;break;case"Curve At":this.curvePos.position.copy(this.getPointAt(a));break;case"Show Position":this.curvePos.visible=a;break;case"Show Points":this.draggable.visible=a;break;case"Toggle Transform":this._transform&&(this._transform.getHelper().visible=!this._transform.getHelper().visible);break;case"Add Point":this.addNextPt();break;case"Remove Point":this.removeSelectedPt();break;case"Export":this.exportSpline();break;case"Delete":this.parent.currentSpline=null,Q(this);break;case"Current Point":if(this.group.current&&this._transform?.object){const o=this._transform?.object;o.name.search("point")>-1&&(o.position.copy(a),this.updateSpline())}break}}}),this.draggable.children.forEach(r=>{this.debugPoint(r)})}debugPoint=e=>{e.name,e.visible=this.draggable.visible}}let qe=0;class bi extends m.Object3D{defaultScale=10;currentSpline=null;_camera;group=null;three;splineDataText="";constructor(e,t){super(),this.name="Spline Editor",this._camera=e,this.three=t,this.three.addEventListener(L.ADD_SPLINE,this.onAddSpline)}initDebug(){this.group=k.addEditorGroup({title:this.name,items:[{type:"field",prop:"Spline Data",value:"",disabled:!1},{type:"button",prop:"Import Spline"},{type:"button",prop:"New Spline"},{type:"boolean",prop:"Show Points",value:!0},{type:"boolean",prop:"Draw Mode",value:!1},{type:"boolean",prop:"Visible",value:this.visible},{type:"range",prop:"Default Scale",min:0,max:50,step:.01,value:this.defaultScale}],onUpdate:(e,t)=>{switch(e){case"New Spline":this.createSpline();break;case"Spline Data":this.splineDataText=t;break;case"Import Spline":this.createSplineFromJSON(JSON.parse(this.splineDataText));break;case"Show Points":this.showPoints(t);break;case"Visible":this.visible=t;break;case"Default Scale":this.defaultScale=t;break;case"Draw Mode":t?this.enableClickToDraw():this.disableClickToDraw();break}}})}dispose(){this.three.removeEventListener(L.ADD_SPLINE,this.onAddSpline),k.removeEditorGroup(this.name)}addSpline(e,t){e.draggableScale=this.defaultScale,e.hideTransform(),this.group?.current!==null&&e.initDebug(this.group.current,t),this.add(e),this.currentSpline=e}createSpline=(e=[])=>{const t=`Spline ${qe+1}`,s=new Ke(t,this._camera);return s.addPoints(e),this.addSpline(s,!0),qe++,s};createSplineFromArray=e=>{const t=[];return e.forEach(s=>{t.push(new m.Vector3(s[0],s[1],s[2]))}),this.createSpline(t)};createSplineFromCatmullRom=e=>this.createSpline(e.points);createSplineFromJSON=e=>{const t=[];e.points.forEach(n=>{t.push(new m.Vector3(n[0],n[1],n[2]))});const s=new Ke(e.name,this._camera);return s.closed=e.closed,s.subdivide=e.subdivide,s.tension=e.tension,s.type=e.type,s.addPoints(t),s.updateSpline(),this.addSpline(s,!1),s};showPoints=(e=!0)=>{this.children.forEach(t=>{t.showPoints(e)})};onAddSpline=e=>{const t=JSON.parse(e.value),s=t.name!==void 0?t.name:`Spline ${qe+1}`,n=new Ke(s,this.camera);t.tension!==void 0&&(n.tension=t.tension),t.closed!==void 0&&(n.closed=t.closed),t.subdivide!==void 0&&(n.subdivide=t.subdivide),t.type!==void 0&&(n.curveType=t.type);const r=[];t.points.forEach(a=>{r.push(new m.Vector3(a[0],a[1],a[2]))}),n.addPoints(r),this.addSpline(n,!1),qe++};isMouseDown=!1;enableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.addEventListener("mousedown",this.onClickCanvas),e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("mouseup",this.onMouseUp)})}disableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.removeEventListener("mousedown",this.onClickCanvas),e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("mouseup",this.onMouseUp)})}onClickCanvas=e=>{if(e.button!==0)return;if(this._camera.type!=="OrthographicCamera"){console.warn("Spline Editor - 3D Camera not supported in Draw Mode");return}const s=e.target.getBoundingClientRect(),n=(e.clientX-s.left)/s.width*2-1,r=-((e.clientY-s.top)/s.height)*2+1;if(G.instance){const o=new m.Raycaster;o.setFromCamera(new m.Vector2(n,r),this._camera);const c=o.intersectObjects(G.instance.helpersContainer.children,!0);for(let l=0;l<c.length;l++){const h=c[l];if(!(h.object.isLine||h.object.isTransformControlsPlane)&&h.object.isObject3D)return}}this.currentSpline===null&&(this.currentSpline=this.createSpline());const a=this.mouseToSplinePos(n,r,s.width,s.height);this.currentSpline?.addPoint(a),this.isMouseDown=!0};onMouseMove=e=>{if(!this.isMouseDown)return;const s=e.target.getBoundingClientRect(),n=(e.clientX-s.left)/s.width*2-1,r=-((e.clientY-s.top)/s.height)*2+1,a=this.mouseToSplinePos(n,r,s.width,s.height);this.currentSpline?.updateLastPoint(a),this.currentSpline?.updateField(a)};onMouseUp=()=>{this.isMouseDown=!1};mouseToSplinePos(e,t,s,n){const r=new m.Vector3,a=Math.PI/2,o=this._camera,c=o.zoom,l=o.rotation.x===-6123233995736766e-32&&o.rotation.y===0&&o.rotation.z===0,h=o.rotation.x===-Math.PI&&o.rotation.y===12246467991473532e-32&&o.rotation.z===Math.PI,u=o.rotation.x===-6162975822039155e-48&&o.rotation.y===-a&&o.rotation.z===0,p=o.rotation.x===-6162975822039155e-48&&o.rotation.y===a&&o.rotation.z===0,g=o.rotation.x===-1.5707953264174506&&o.rotation.y===0&&o.rotation.z===0,C=o.rotation.x===1.5707953264174506&&o.rotation.y===0&&o.rotation.z===0;let _=e,E=t;h||p?_*=-1:g&&(E*=-1);const v=s/2/c,y=n/2/c;if(this.currentSpline===null&&(this.currentSpline=this.createSpline()),l||h){const x=_*v+o.position.x,O=E*y+o.position.y;r.set(x,O,0)}else if(u||p){const x=_*v+o.position.z,O=E*y+o.position.y;r.set(0,O,x)}else if(g||C){const x=_*v+o.position.x,O=E*y+o.position.z;r.set(x,0,O)}return r}get camera(){return this._camera}set camera(e){this._camera=e,this.children.forEach(t=>{const s=t;s.camera=e})}}const $t=["Single","Side by Side","Stacked","Quad"],En="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC60lEQVRYhe2YT4hNcRTHP48xpmYaNAvRyEQxEhnKQljYsRm9/EmSyJiMFAsMZWNhJYoNIUVJ2VGiyb9ZzIpMpkQSahbGv9GMYWrM+1rc2zjvzvvdd+99rzdvMd+6de75nd+5387vnN/v/G5KEuWMKRNNIB8mCRaKiiL5qQb2ApuBuUAV0Ad0AJeB3sSeJRX6LJbULTf6JTUn9Z+KWMUpPyp/Avoa4CNQZ3Sj/lNpdL/xottR7AjOkHRUUpekN5I6JbVLavDH75lIfZN0UFKTpCWS0pJem/HeJBEMG6yV1ONYtgFJbZJ+GF1jDh+zJb03NuliEuwMkMo4yErS2RA/LcbuYVyCrm1mA7Dal/8Cu4FG4JD/HsTTkCy6a+SVMTPQuc1sBKb78nHghi+/A+YBxwL2lbhRY+ThuARdEVxu5JdGFvACr0otdoZ8Y4+Rn0Sn5sFFsMvI6YB9MzA1YJ8mN8k1wAHzfj4uQVdyrpI0aJL7oqTtkq4FiqPLyCOSbktqlbRL0jlJQ2b8QdwCUZ4qvhRStZL0XFK1pMd57CRvq5mfhKBriRfiFUMY6oD7eOdwPlQAN4G10dfWg+uouwXsiOssAj4AC+JMcEWwvnAuOTEr7gTXPmg34zagOwkbIIOXAo9CbDYBrcBXYN+4UUdy2sRflyS5zVNlfPX7ugpJW5V9nI7mmh+lYU0lCZ2B3TOnAVuAk0BTwC5nuhWro46KauBOQJch5OpRaoIW34GreGf+YZdRqS9NAj4Bp4ClQDvwOWxCqSM4ADQEdKE5XvbXzlITrAVe4TW+M6NMKDXBFLAMuAD0ACfIc7pMZBXXA2cY3/xmodQRHAL2A2+NLtj8ZiEKwUL/z2WMPAJcAVYALWSf8dZuDFGWeBHwKxm3sWYhiGG8Tfo6sA2vSfiSy4GrH3wGrDcfKSSKKf6v1E9yF0XK9Q1XBPuMXMw8HXTonQFwETwNzMFr64v1jzgFHIk9ybHEZYPJo65QlD3Bf2/Q/eaHPiSWAAAAAElFTkSuQmCC",Sn="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAETklEQVRYhe2YXYhVVRTHf3d0/JhyUrMpFbImM+whSa3Mynww+4AeIgiKoozooQ+KyMyXIAujF6OXqHyI6iEKKYgIP/owsjSFqCkprdDUTEcjbWZ0HHV+Pex1ucfb9Z57Z9REXHA4Z++99l7/s/ZZ/7X2KaiczNLwfwPIk9MA+yunNMAG4DHgV+BvoB3YFff2TPstYEyfrajVroI6Sr1GvahsbJC63HzZq04pmztSvU5tVRuqYRiYg78JeBR4HPg5ntdmxovz9wJfA3uAxuibDLQCA+IqynnAQuBuYCnwMLC1rx48U12U8cZqdWqMDcx4cI16qTpYbVKHqa+ovWUeHKsujn7VL9ULq2HI+wY7gVeBJdGeFu3J4ZUiy/cAXeHRRuAQsC/GC0B3eG4BcH/0tUV7czUAeVsMsBF4Kha9HZgCvAncAuwPnXHA0wFuGLANuDrGuoGDwFxgTqzzQ7RX5FrP2eLsdb76vnogtme6+nE8H1YPlQXHwbi3q9eqn0e7Tb25VrsF68vFY0lb1AGcDTwItGQ8tQM4AIwGmqP/EPAu8A0wElgJfFGzxTo8mKWXu9Rd4ZF96jvqjSbauEC9Sn1O3R463epLaku99voCsFXdkAH3kNpcQW+IiT/bQne3eufxBtioPqP2mKhioXpWzpxb1T8C5Ifh4ZptVoriRmAIKdrI3Lujf3bobAPeJpF0NVkKrAFuI9HTOBIxnxFrF4OgQKKr/dnJlQA+AcwABgOHA4zAamA5cE7orQL+zAEHiWI+A2bFC7aSguheYCgpqAphZz3wSB7AecCICv2TgH8oFRib4gVqka0k0h8CXAxMBW6ooDejFoCvA9OBQUAvKWM0kDz4XUZvNKXtyZMWUl7vBbaQXq457PeEziDgx/KJlQAuIPFdMcEXv5OdYWBP9M8k8VpnDQCvB4aTSrCNJB5cSdrW3tBpIJVnR0qdUTxAfdGUOVTnmwqEanNmqltC/9OgqePKg5eom8PgdvW+oJ9Kupera0O3U50TL3lcAaI+oHaF4R3qa6Z822wq0Saq89T1lmSxOrxeW/Xm4uGkiqQDmECKuKHxHW0HdpMiewSpvGqKeR8Ay0iBsYIjg6261PE2o9Q3Yqv+MqWxO9R1Hl12qs+q49Vlppy82pSr+5xJKsko4AXgHlJ0t5NIeg3wLXAlqZhtIUV8J6nmWwX8QiLjdhL5TwMWkY4R6/rrwYKlMr1Y321QZ/vfwBijPqm+rF4Wc7PjE9QllurGVeoV5gRNHsAm9fnMom3qrKPoTjKdMXaYyrFygEWQ72XWW24qhPu8xcUc2UU6O8wFPjmK7jhgPHAuMJGUGQ6U6WwE5sfzTXGvei7KA9hFOiR9D/wOfFVFt4dS2tpfRe83Ur7/CPiJakfOGgBCypubatArl2r8VfOax/LfzABKtePAzHO/5FgC7KBEzB2kOrDfUm8mOeFySv9+OyFyGmB/5aQH+C9BVKmVCNuMZgAAAABJRU5ErkJggg==",xn="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAQ0lEQVQ4jWP8////fwYqAxYozUhFM/8zkaKYWIWkGEq0b0ZdSjQY5i79TyWagRGaTUdzFEEw6lLqGzqwLoVVJ1StpwA9sBwbUqAh5gAAAABJRU5ErkJggg==";class G extends b.Component{static instance=null;scene;renderer;currentScene;scenes=new Map;cameras=new Map;controls=new Map;currentCamera;currentWindow;helpersContainer=new w.Group;grid;cameraHelpers=new Map;lightHelpers=new Map;interactionHelper=new w.AxesHelper(25);currentTransform;splineEditor;depthMaterial;normalsMaterial;uvMaterial;wireframeMaterial=new w.MeshBasicMaterial({opacity:.33,transparent:!0,wireframe:!0});playing=!1;rafID=-1;cameraControlsRafID=-1;width=0;height=0;tlCam=null;trCam=null;blCam=null;brCam=null;tlRender="Renderer";trRender="Renderer";blRender="Renderer";brRender="Renderer";cameraVisibility=!0;lightVisibility=!0;gridVisibility=!0;rendererReady=!1;selectedItem=void 0;cameraControlsStartTime=0;cameraControlsLastTime=0;debugCamera;raycaster=new w.Raycaster;pointer=new w.Vector2;cameraControls=void 0;canvasRef;containerRef;tlWindow;trWindow;blWindow;brWindow;editorCameras=["Top","Bottom","Left","Right","Front","Back","Orthographic","UI","Debug"];constructor(e){super(e),this.props.three.addEventListener(L.ADD_RENDERER,this.setupRenderer),this.scene=new w.Scene,this.scene.name=this.scene.uuid="",this.canvasRef=b.createRef(),this.containerRef=b.createRef(),this.tlWindow=b.createRef(),this.trWindow=b.createRef(),this.blWindow=b.createRef(),this.brWindow=b.createRef();const t=e.three.name,s=localStorage,n=s.getItem(`${t}_mode`);this.state={mode:n!==null?n:"Single",modeOpen:!1,renderModeOpen:!1,interactionMode:"Orbit",interactionModeOpen:!1,lastUpdate:Date.now()},s.setItem(`${t}_mode`,this.state.mode),s.setItem(`${t}_tlCam`,s.getItem(`${t}_tlCam`)!==null?s.getItem(`${t}_tlCam`):"Debug"),s.setItem(`${t}_trCam`,s.getItem(`${t}_trCam`)!==null?s.getItem(`${t}_trCam`):"Orthographic"),s.setItem(`${t}_blCam`,s.getItem(`${t}_blCam`)!==null?s.getItem(`${t}_blCam`):"Front"),s.setItem(`${t}_brCam`,s.getItem(`${t}_brCam`)!==null?s.getItem(`${t}_brCam`):"Top"),s.setItem(`${t}_tlRender`,s.getItem(`${t}_tlRender`)!==null?s.getItem(`${t}_tlRender`):"Renderer"),s.setItem(`${t}_trRender`,s.getItem(`${t}_trRender`)!==null?s.getItem(`${t}_trRender`):"Renderer"),s.setItem(`${t}_blRender`,s.getItem(`${t}_blRender`)!==null?s.getItem(`${t}_blRender`):"Renderer"),s.setItem(`${t}_brRender`,s.getItem(`${t}_brRender`)!==null?s.getItem(`${t}_brRender`):"Renderer");const r={Vector2:w.Vector2,Vector3:w.Vector3,Vector4:w.Vector4,Quaternion:w.Quaternion,Matrix4:w.Matrix4,Spherical:w.Spherical,Box3:w.Box3,Sphere:w.Sphere,Raycaster:w.Raycaster};re.install({THREE:r}),this.setupScene(),this.setupTools();const a=localStorage.getItem(this.expandedCameraVisibility);a!==null&&(this.cameraVisibility=a==="open"),this.saveExpandedCameraVisibility();const o=localStorage.getItem(this.expandedLightVisibility);o!==null&&(this.lightVisibility=o==="open"),this.saveExpandedLightVisibility();const c=localStorage.getItem(this.expandedGridVisibility);c!==null&&(this.gridVisibility=c==="open"),this.grid&&(this.grid.visible=this.gridVisibility),this.saveExpandedGridVisibility(),G.instance=this}componentDidMount(){this.enable(),this.assignControls(),this.resize(),this.play(),W.instance.setApp(this.props.three),W.instance.activeCamera=this.debugCamera,this.props.three.requestRenderer()}componentDidUpdate(e,t,s){t.mode!==this.state.mode&&(this.assignControls(),this.resize())}componentWillUnmount(){this.disable(),this.clear(),k.removeEditorGroup("View Settings")}render(){const e=[];return this.cameras.forEach((t,s)=>{e.push(s)}),d.jsxs("div",{className:"multiview",children:[d.jsx("canvas",{ref:this.canvasRef}),d.jsxs("div",{className:`cameras ${this.state.mode==="Single"||this.state.mode==="Stacked"?"single":""}`,ref:this.containerRef,children:[this.state.mode==="Single"&&d.jsx(d.Fragment,{children:d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}})}),(this.state.mode==="Side by Side"||this.state.mode==="Stacked")&&d.jsxs(d.Fragment,{children:[d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}}),d.jsx(ge,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:t=>{this.controls.get(this.trCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.trCam),this.trCam=s,localStorage.setItem(`${this.appID}_trCam`,s.name),this.createControls(s,this.trWindow.current))},onSelectRenderMode:t=>{this.trRender=t,localStorage.setItem(`${this.appID}_trRender`,t)}})]}),this.state.mode==="Quad"&&d.jsxs(d.Fragment,{children:[d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}}),d.jsx(ge,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:t=>{this.controls.get(this.trCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.trCam),this.trCam=s,localStorage.setItem(`${this.appID}_trCam`,s.name),this.createControls(s,this.trWindow.current))},onSelectRenderMode:t=>{this.trRender=t,localStorage.setItem(`${this.appID}_trRender`,t)}}),d.jsx(ge,{name:"bl",camera:this.blCam,options:e,ref:this.blWindow,onSelectCamera:t=>{this.controls.get(this.blCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.blCam),this.blCam=s,localStorage.setItem(`${this.appID}_blCam`,s.name),this.createControls(s,this.blWindow.current))},onSelectRenderMode:t=>{this.blRender=t,localStorage.setItem(`${this.appID}_blRender`,t)}}),d.jsx(ge,{name:"br",camera:this.brCam,options:e,ref:this.brWindow,onSelectCamera:t=>{this.controls.get(this.brCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.brCam),this.brCam=s,localStorage.setItem(`${this.appID}_brCam`,s.name),this.createControls(s,this.brWindow.current))},onSelectRenderMode:t=>{this.brRender=t,localStorage.setItem(`${this.appID}_brRender`,t)}})]})]}),d.jsxs("div",{className:"settings",children:[d.jsx(Qe,{title:"View",index:$t.indexOf(this.state.mode),options:$t,onSelect:t=>{t!==this.state.mode&&(this.killControls(),this.setState({mode:t}),localStorage.setItem(`${this.appID}_mode`,t))},open:this.state.modeOpen,onToggle:t=>{this.setState({modeOpen:t,renderModeOpen:!1,interactionModeOpen:!1})}}),d.jsx(Qe,{title:"Interact",index:this.state.interactionMode==="Orbit"?0:1,options:["Orbit Mode","Selection Mode"],onSelect:t=>{this.interactionHelper.visible=t==="Selection Mode",this.setState({interactionMode:this.interactionHelper.visible?"Selection":"Orbit"})},open:this.state.interactionModeOpen,onToggle:t=>{this.setState({modeOpen:!1,renderModeOpen:!1,interactionModeOpen:t})}}),d.jsx(mt,{name:"cameraHelper",icon:En,selected:this.cameraVisibility,height:24,top:2,onClick:t=>{if(this.cameraVisibility=t,this.saveExpandedCameraVisibility(),this.cameraHelpers.forEach(s=>{s.visible=t}),this.selectedItem!==void 0&&!t){const s=this.cameraHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=!0)}}}),d.jsx(mt,{name:"lightHelper",icon:Sn,selected:this.lightVisibility,height:24,top:4,onClick:t=>{if(this.lightVisibility=t,this.saveExpandedLightVisibility(),this.lightHelpers.forEach(s=>{s.visible=t}),this.selectedItem!==void 0&&!t&&this.selectedItem.isLight===!0){const s=this.lightHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=!0)}}}),d.jsx(mt,{name:"gridHelper",icon:xn,selected:this.gridVisibility,height:21,width:21,onClick:t=>{this.setGridVisibility(t)}})]},this.state.lastUpdate)]})}setupRenderer=e=>{const t=e.value;if(this.renderer){if(this.renderer instanceof m.WebGLRenderer&&t.type==="WebGLRenderer"||this.renderer instanceof w.WebGPURenderer&&t.type==="WebGPURenderer")return;this.renderer.dispose()}this.rendererReady=!1;const s=this.canvasRef.current;this.props.three.canvas=s,t.type==="WebGLRenderer"?(this.renderer=new m.WebGLRenderer({canvas:s,stencil:!1}),this.grid&&(this.scene.remove(this.grid),Q(this.grid)),this.grid=new gi,this.scene.add(this.grid),this.rendererReady=!0):t.type==="WebGPURenderer"&&(this.renderer=new w.WebGPURenderer({canvas:s,stencil:!1}),this.grid&&(this.scene.remove(this.grid),Q(this.grid)),this.grid=new _i,this.scene.add(this.grid)),this.renderer&&(this.renderer.autoClear=!1,this.renderer.shadowMap.enabled=!0,this.renderer.setClearColor(0),this.renderer.setPixelRatio(devicePixelRatio),this.renderer.setScissorTest(!0),this.resize(),this.props.three.renderer=this.renderer,this.depthMaterial?.dispose(),this.normalsMaterial?.dispose(),this.uvMaterial?.dispose(),this.depthMaterial=new yi,this.normalsMaterial=new w.MeshNormalNodeMaterial,this.uvMaterial=new Ci,t.type==="WebGPURenderer"?this.renderer.init().then(()=>{this.rendererReady=!0,this.props.three.requestScene()}):this.props.three.requestScene())};setupScene(){this.helpersContainer.name="helpers",this.scene.add(this.helpersContainer),this.interactionHelper.name="interactionHelper",this.interactionHelper.visible=!1,this.helpersContainer.add(this.interactionHelper);const e=(r,a)=>{const o=new w.OrthographicCamera(-100,100,100,-100,0,3e3);return o.name=r,o.position.copy(a),o.lookAt(0,0,0),this.cameras.set(r,o),o},t=1e3;e("Top",new w.Vector3(0,t,0)),e("Bottom",new w.Vector3(0,-t,0)),e("Left",new w.Vector3(-t,0,0)),e("Right",new w.Vector3(t,0,0)),e("Front",new w.Vector3(0,0,t)),e("Back",new w.Vector3(0,0,-t)),e("Orthographic",new w.Vector3(t,t,t)),e("UI",new w.Vector3),this.debugCamera=new w.PerspectiveCamera(60,1,.01,3e3),this.debugCamera.name="Debug",this.debugCamera.position.set(300,300,300),this.debugCamera.lookAt(0,0,0),this.cameras.set("Debug",this.debugCamera),this.currentCamera=this.debugCamera;const s=localStorage,n=this.props.three.name;this.tlCam=this.cameras.get(s.getItem(`${n}_tlCam`)),this.trCam=this.cameras.get(s.getItem(`${n}_trCam`)),this.blCam=this.cameras.get(s.getItem(`${n}_blCam`)),this.brCam=this.cameras.get(s.getItem(`${n}_brCam`)),this.tlCam===void 0&&(this.tlCam=this.cameras.get("Debug")),this.trCam===void 0&&(this.trCam=this.cameras.get("Orthographic")),this.blCam===void 0&&(this.blCam=this.cameras.get("Front")),this.brCam===void 0&&(this.brCam=this.cameras.get("Top")),k.addEditorGroup({title:"Editor",items:[{type:"button",prop:"Hide All Transforms"},{type:"button",prop:"Resize"}],onUpdate:(r,a)=>{switch(r){case"Hide All Transforms":W.instance.hide();break;case"Resize":this.resize();break}},subgroups:[{title:"Debug Camera",items:[{type:"range",prop:"Near",step:1e-4,min:.001,max:1e3,value:this.debugCamera.near},{type:"range",prop:"Far",step:.001,min:.001,max:1e4,value:this.debugCamera.far}],onUpdate:(r,a)=>{switch(r){case"Near":this.debugCamera.near=a,this.debugCamera.updateProjectionMatrix();break;case"Far":this.debugCamera.far=a,this.debugCamera.updateProjectionMatrix();break}}},{title:"Grid",items:[{type:"number",prop:"Position",value:0},{type:"color",prop:"Color",value:"#FFFFFF"},{type:"range",prop:"Grid Opacity",value:.25,min:0,max:1,step:.01},{type:"range",prop:"Subgrid Opacity",value:.15,min:0,max:1,step:.01}],onUpdate:(r,a)=>{switch(r){case"Position":this.grid&&(this.grid.position.y=a);break;case"Color":this.grid&&this.grid.color.setStyle(a);break;case"Grid Opacity":this.grid&&(this.grid.gridOpacity=a);break;case"Subgrid Opacity":this.grid&&(this.grid.subgridOpacity=a);break}}}]})}setupTools(){this.splineEditor=new bi(this.currentCamera,this.three),this.splineEditor.initDebug(),this.helpersContainer.add(this.splineEditor)}play(){this.playing=!0,this.onUpdate()}pause(){this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1}toggleOrbitControls(e){this.controls.forEach(t=>{t.enabled=!e})}clear(){this.three.dispatchEvent({type:L.CLEAR_OBJECT}),k.removeAllGroups(),this.clearLightHelpers(),this.clearControls(),this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),W.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=void 0,W.instance.clear(),this.cameras.forEach(e=>{this.editorCameras.indexOf(e.name)<0&&this.three.dispatchEvent({type:L.REMOVE_CAMERA,value:e})}),this.currentCamera=this.debugCamera,this.currentScene=void 0,this.scenes.forEach(e=>{this.three.dispatchEvent({type:L.REMOVE_SCENE,value:e})}),this.scenes.clear()}setGridVisibility(e){this.gridVisibility=e,this.saveExpandedGridVisibility(),this.grid&&(this.grid.visible=e)}update(){this.controls.forEach(e=>e.update()),this.cameraHelpers.forEach(e=>e.update()),this.lightHelpers.forEach(e=>{e.update!==void 0&&e.update()}),this.props.onSceneUpdate!==void 0&&this.currentScene!==void 0&&this.props.onSceneUpdate(this.currentScene)}draw(){if(this.rendererReady)switch(this.renderer&&this.renderer?.clear(),this.state.mode){case"Single":this.drawSingle();break;case"Side by Side":case"Stacked":this.drawDouble();break;case"Quad":this.drawQuad();break}}onUpdate=()=>{this.playing&&(this.update(),this.draw(),this.rafID=requestAnimationFrame(this.onUpdate))};enable(){const e=this.containerRef.current;e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("click",this.onClick),window.addEventListener("keydown",this.onKey),window.addEventListener("resize",this.resize),this.three.addEventListener(L.ADD_SCENE,this.addScene),this.three.addEventListener(L.SET_SCENE,this.sceneUpdate),this.three.addEventListener(L.REMOVE_SCENE,this.removeScene),this.three.addEventListener(L.ADD_CAMERA,this.addCamera),this.three.addEventListener(L.REMOVE_CAMERA,this.removeCamera),this.three.addEventListener(L.SET_OBJECT,this.onSetSelectedItem)}disable(){const e=this.containerRef.current;e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("click",this.onClick),window.removeEventListener("keydown",this.onKey),window.removeEventListener("resize",this.resize),this.three.removeEventListener(L.ADD_SCENE,this.addScene),this.three.removeEventListener(L.SET_SCENE,this.sceneUpdate),this.three.removeEventListener(L.REMOVE_SCENE,this.removeScene),this.three.removeEventListener(L.ADD_CAMERA,this.addCamera),this.three.removeEventListener(L.REMOVE_CAMERA,this.removeCamera),this.three.removeEventListener(L.SET_OBJECT,this.onSetSelectedItem)}resize=()=>{this.width=window.innerWidth-300,this.height=window.innerHeight,this.renderer?.setSize(this.width,this.height);const e=Math.floor(this.width/2),t=Math.floor(this.height/2);this.props.three.resize(this.width,this.height),this.props.onSceneResize!==void 0&&this.currentScene!==void 0&&this.props.onSceneResize(this.currentScene,this.width,this.height);let s=this.width,n=this.height;switch(this.state.mode){case"Side by Side":s=e,n=this.height;break;case"Stacked":s=this.width,n=t;break;case"Quad":s=e,n=t;break}const r=s/n;this.cameras.forEach(a=>{a instanceof w.OrthographicCamera?(a.left=s/-2,a.right=s/2,a.top=n/2,a.bottom=n/-2,a.name==="UI"&&(a.position.x=this.width/2,a.position.y=this.height/-2,a.position.z=100),a.updateProjectionMatrix()):a instanceof w.PerspectiveCamera&&(a.aspect=r,a.updateProjectionMatrix()),this.cameraHelpers.get(a.name)?.update()})};addScene=e=>{const t=this.props.scenes.get(e.value.name);if(t!==void 0){const s=this.scenes.get(e.value.name);if(s!==void 0){this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(s),this.props.three.scene=s;return}const n=new t;n.visible=!1,this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(n),this.props.three.scene=n,this.scenes.set(e.value.name,n),this.scene.add(n)}else console.log("Hermes - Scene not found:",e.value.name,this.props.scenes)};sceneUpdate=e=>{this.currentScene!==void 0&&(this.currentScene.visible=!1,this.clearLightHelpers());const t=this.scene.getObjectByName(e.value.name);t!==void 0&&(this.currentScene=t,this.currentScene.visible=!0,this.addLightHelpers(this.currentScene)),this.cameraHelpers.forEach((s,n)=>{const r=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",n)!==void 0;s.visible=this.cameraVisibility&&r})};removeScene=e=>{const t=e.value.name;this.scenes.delete(t);const s=this.scene.getObjectByName(t);s&&setTimeout(()=>{Q(s)},100),this.clearLightHelpers()};addCamera=e=>{const t=e.value,s=t.uuid,n=this.props.three.scene?.getObjectByProperty("uuid",t.uuid);if(n!==void 0){const r=n;this.cameras.set(s,r);const a=new w.CameraHelper(r),o=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",s)!==void 0;a.visible=this.cameraVisibility&&o,this.cameraHelpers.set(s,a),this.helpersContainer.add(a),this.setState({lastUpdate:Date.now()})}};removeCamera=e=>{const s=e.value.uuid,n=this.cameraHelpers.get(s);n!==void 0&&(this.helpersContainer.remove(n),n.dispose()),this.cameras.delete(s),this.setState({lastUpdate:Date.now()})};onMouseMove=e=>{const t=new w.Vector2;this.renderer?.getSize(t);const s=Math.min(e.clientX,t.x),n=Math.min(e.clientY,t.y);this.pointer.x=$.mapLinear(s,0,t.x,-1,1),this.pointer.y=$.mapLinear(n,0,t.y,1,-1);const r=t.x/2,a=t.y/2,o=()=>{s<r?this.pointer.x=$.mapLinear(s,0,r,-1,1):this.pointer.x=$.mapLinear(s,r,t.x,-1,1)},c=()=>{n<a?this.pointer.y=$.mapLinear(n,0,a,1,-1):this.pointer.y=$.mapLinear(n,a,t.y,1,-1)};switch(this.state.mode){case"Quad":o(),c();break;case"Side by Side":o();break;case"Stacked":c(),c();break}if(this.updateCamera(s,n,r,a),this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const l=this.raycaster.intersectObjects(this.currentScene.children);l.length>0&&this.interactionHelper.position.copy(l[0].point)};onClick=e=>{if(this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const t=new w.Vector2;if(this.renderer.getSize(t),e.clientX>=t.x)return;this.onMouseMove(e);const s=this.raycaster.intersectObjects(this.currentScene.children);s.length>0&&(this.props.three.getObject(s[0].object.uuid),this.interactionHelper.visible=!1,this.setState({interactionMode:"Orbit",lastUpdate:Date.now()}))};onKey=e=>{if(this.selectedItem!==void 0){if(e.ctrlKey){if(this.currentCamera.name==="UI")return;const t=this.controls.get(this.currentCamera.name);e.key==="0"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.selectedItem instanceof w.Mesh||this.selectedItem instanceof w.SkinnedMesh?(this.selectedItem.geometry.computeBoundingBox(),this.cameraControls.fitToBox(this.selectedItem.geometry.boundingBox,!0)):this.cameraControls.fitToSphere(this.selectedItem,!0),this.updateCameraControls(t,!0)):e.key==="1"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,Math.PI*.5,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(t)):e.key==="2"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,0,!0),this.cameraControls.moveTo(this.selectedItem.position.x,0,this.selectedItem.position.z,!0),this.updateCameraControls(t)):e.key==="3"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI/2,Math.PI/2,!0),this.cameraControls.moveTo(0,this.selectedItem.position.y,this.selectedItem.position.z,!0),this.updateCameraControls(t)):e.key==="4"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI,Math.PI/2,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(t)):e.key==="5"&&(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo($.degToRad(45),$.degToRad(45),!0),this.updateCameraControls(t))}else if(this.currentTransform!==void 0)switch(e.key){case"r":this.currentTransform.setMode("rotate");break;case"s":this.currentTransform.setMode("scale");break;case"t":this.currentTransform.setMode("translate");break;case"q":this.currentTransform.setSpace(this.currentTransform.space==="local"?"world":"local");break}}};onSetSelectedItem=e=>{this.selectedItem!==void 0&&this.updateSelectedItemHelper(!1),this.selectedItem=void 0;const t=e.value.uuid;if(this.scenes.forEach(s=>{t.search(s.uuid)>-1&&(this.selectedItem=s.getObjectByProperty("uuid",t))}),this.selectedItem===void 0){console.log(`Hermes - Can't find selected item: ${e.value.uuid}, ${e.value.name}`);return}this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),W.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=W.instance.add(e.value.name),this.currentTransform&&(this.currentTransform.attach(this.selectedItem),this.helpersContainer.add(this.currentTransform.getHelper()),this.currentTransform.addEventListener("objectChange",this.onUpdateTransform)),this.updateSelectedItemHelper(!0)};updateSelectedItemHelper(e){if(this.selectedItem!==void 0)if(this.cameraVisibility){if(this.selectedItem.isLight===!0&&!this.lightVisibility){const t=this.lightHelpers.get(this.selectedItem.name);t!==void 0&&(t.visible=e)}}else{const t=this.cameraHelpers.get(this.selectedItem.name);t!==void 0&&(t.visible=e)}}onUpdateTransform=()=>{this.selectedItem!==void 0&&(this.props.three.updateObject(this.selectedItem.uuid,"position",this.selectedItem.position),this.props.three.updateObject(this.selectedItem.uuid,"rotation",{x:this.selectedItem.rotation.x,y:this.selectedItem.rotation.y,z:this.selectedItem.rotation.z}),this.props.three.updateObject(this.selectedItem.uuid,"scale",this.selectedItem.scale),tt.instance.update())};clearLightHelpers=()=>{this.lightHelpers.forEach(e=>{this.helpersContainer.remove(e),e.dispose()}),this.lightHelpers.clear()};addLightHelpers=e=>{e.traverse(t=>{if(t.type.search("Light")>-1){let s;switch(t.type){case"DirectionalLight":s=new w.DirectionalLightHelper(t,100),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"HemisphereLight":s=new w.HemisphereLightHelper(t,250),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"RectAreaLight":s=new Fi.RectAreaLightHelper(t),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"PointLight":s=new w.PointLightHelper(t,100),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"SpotLight":s=new w.SpotLightHelper(t),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break}}})};createControls(e,t){const s=this.controls.get(e.name);if(s!==void 0&&s.dispose(),this.controls.delete(e.name),e.name==="UI")return;const n=new ji.OrbitControls(e,t);switch(n.enableDamping=!0,n.dampingFactor=.1,e.name){case"Top":case"Bottom":case"Left":case"Right":case"Front":case"Back":n.enableRotate=!1;break}this.controls.set(e.name,n)}clearCamera(e){const t=this.cameraHelpers.get(e.name);t!==void 0&&(this.helpersContainer.remove(t),t.dispose(),this.cameraHelpers.delete(e.name));const s=this.controls.get(e.name);s!==void 0&&(s.dispose(),this.controls.delete(e.name))}killControls(){this.controls.forEach((e,t)=>{e.dispose();const s=this.cameraHelpers.get(t);s!==void 0&&(this.helpersContainer.remove(s),s.dispose()),this.cameraHelpers.delete(t),this.controls.delete(t)}),this.controls.clear(),this.cameraHelpers.clear()}assignControls(){switch(this.state.mode){case"Single":this.createControls(this.tlCam,this.tlWindow.current);break;case"Side by Side":case"Stacked":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current);break;case"Quad":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current),this.createControls(this.blCam,this.blWindow.current),this.createControls(this.brCam,this.brWindow.current);break}}updateCamera=(e,t,s,n)=>{switch(this.state.mode){case"Quad":t<n?e<s?this.currentCamera=this.tlCam:this.currentCamera=this.trCam:e<s?this.currentCamera=this.blCam:this.currentCamera=this.brCam;break;case"Side by Side":e<s?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break;case"Single":this.currentCamera=this.tlCam;break;case"Stacked":t<n?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break}this.splineEditor.camera=this.currentCamera,this.raycaster.setFromCamera(this.pointer,this.currentCamera),this.currentCamera===this.tlCam?this.currentWindow=this.tlWindow:this.currentCamera===this.trCam?this.currentWindow=this.trWindow:this.currentCamera===this.blCam?this.currentWindow=this.blWindow:this.currentCamera===this.brCam&&(this.currentWindow=this.brWindow),W.instance.updateCamera(this.currentCamera,this.currentWindow.current)};updateCameraControls=(e,t=!1)=>{if(this.selectedItem===void 0)return;cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.cameraControls&&(this.cameraControls.smoothTime=.1);const s=.15;this.cameraControlsStartTime=performance.now(),this.cameraControlsLastTime=this.cameraControlsStartTime,this.selectedItem.getWorldPosition(e.target0);const n=()=>{const r=performance.now(),a=(r-this.cameraControlsLastTime)/1e3;this.cameraControlsLastTime=r,this.cameraControls&&this.cameraControls.update(a),t&&(e.target.lerp(e.target0,s),e.object.position.lerp(e.position0,s),e.object.zoom=Re(e.object.zoom,e.zoom0,s),e.object.updateProjectionMatrix(),e.dispatchEvent({type:"change"})),(r-this.cameraControlsStartTime)/1e3>=.5?(cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.clearControls()):this.cameraControlsRafID=requestAnimationFrame(n)};n()};clearControls=()=>{this.cameraControls!==void 0&&(this.cameraControls.disconnect(),this.cameraControls.dispose(),this.cameraControls=void 0)};saveExpandedCameraVisibility(){localStorage.setItem(this.expandedCameraVisibility,this.cameraVisibility?"open":"closed")}saveExpandedLightVisibility(){localStorage.setItem(this.expandedLightVisibility,this.lightVisibility?"open":"closed")}saveExpandedGridVisibility(){localStorage.setItem(this.expandedGridVisibility,this.gridVisibility?"open":"closed")}getSceneOverride(e){switch(e){case"Depth":return this.depthMaterial;case"Normals":return this.normalsMaterial;case"Renderer":return null;case"UVs":return this.uvMaterial;case"Wireframe":return this.wireframeMaterial}return null}drawTo(e,t,s,n,r,a){switch(r.name){case"Left":case"Right":this.grid&&(this.grid.rotation.z=Math.PI/2);break;case"Front":case"Back":this.grid&&(this.grid.rotation.x=Math.PI/2);break}this.scene.overrideMaterial=a,this.renderer&&(this.renderer?.setScissor(e,t,s,n),this.renderer?.setViewport(e,t,s,n),this.renderer?.render(this.scene,r)),this.grid&&this.grid.rotation.set(0,0,0)}drawSingle(){const e=this.getSceneOverride(this.tlRender);this.drawTo(0,0,this.width,this.height,this.tlCam,e)}drawDouble=()=>{const e=this.getSceneOverride(this.tlRender),t=this.getSceneOverride(this.trRender),s=Math.floor(this.width/2),n=Math.floor(this.height/2),r=this.renderer instanceof w.WebGPURenderer;if(this.state.mode==="Side by Side")this.drawTo(0,0,s,this.height,this.tlCam,e),this.drawTo(s,0,s,this.height,this.trCam,t);else{const a=this.height-n;r?(this.drawTo(0,0,this.width,n,this.tlCam,e),this.drawTo(0,a,this.width,n,this.trCam,t)):(this.drawTo(0,a,this.width,n,this.tlCam,e),this.drawTo(0,0,this.width,n,this.trCam,t))}};drawQuad=()=>{const e=this.renderer instanceof w.WebGPURenderer,t=this.getSceneOverride(this.tlRender),s=this.getSceneOverride(this.trRender),n=this.getSceneOverride(this.blRender),r=this.getSceneOverride(this.brRender),a=Math.floor(this.width/2),o=Math.floor(this.height/2),c=this.height-o;let l=0,h=e?0:this.height-o;l=0,this.drawTo(l,h,a,o,this.tlCam,t),l=a,this.drawTo(l,h,a,o,this.trCam,s),h=e?c:0,l=0,this.scene.overrideMaterial=n,this.drawTo(l,h,a,o,this.blCam,n),l=a,this.drawTo(l,h,a,o,this.brCam,r)};get appID(){return this.props.three.name}get mode(){return this.state.mode}get three(){return this.props.three}get expandedCameraVisibility(){return`${this.appID}_multiviewCameraVisibility`}get expandedLightVisibility(){return`${this.appID}_multiviewLightVisibility`}get expandedGridVisibility(){return`${this.appID}_multiviewGridVisibility`}}class tt extends b.Component{static instance;matrix=new m.Matrix4;position=new m.Vector3;rotation=new m.Euler;scale=new m.Vector3;open=!1;constructor(e){super(e);const t=localStorage.getItem(this.expandedName),s=t!==null?t==="open":!1;this.open=s,this.saveExpanded(),this.state={lastUpdated:0,expanded:s},this.matrix.elements=e.object.matrix,e.object.uuid.length>0&&(this.position.setFromMatrixPosition(this.matrix),this.rotation.setFromRotationMatrix(this.matrix),this.scale.setFromMatrixScale(this.matrix)),tt.instance=this}update(){if(G.instance){const e=G.instance.selectedItem;if(e===void 0)return;this.position.x=X(e.position.x,3),this.position.y=X(e.position.y,3),this.position.z=X(e.position.z,3),this.rotation.copy(e.rotation),this.scale.x=X(e.scale.x,3),this.scale.y=X(e.scale.y,3),this.scale.z=X(e.scale.z,3),this.setState({lastUpdated:Date.now()})}}render(){return d.jsx(J,{three:this.props.three,title:"Transform",expanded:this.open,items:[{title:"Position",prop:"position",type:"grid3",step:.1,value:this.position,onChange:this.updateTransform},{title:"Rotation",prop:"rotation",type:"euler",value:this.rotation,onChange:this.updateTransform},{title:"Scale",prop:"scale",type:"grid3",value:this.scale,onChange:this.updateTransform},{title:"Visible",prop:"visible",type:"boolean",value:this.props.object.visible,onChange:this.updateTransform}],onToggle:e=>{this.open=e,this.saveExpanded()}},this.state.lastUpdated)}updateTransform=(e,t)=>{const s=e==="rotation"?{x:t._x,y:t._y,z:t._z}:t;this.props.three.updateObject(this.props.object.uuid,e,s);const n=this.props.three.getScene(this.props.object.uuid);if(n){const r=n.getObjectByProperty("uuid",this.props.object.uuid);V(r,e,s)}};saveExpanded(){localStorage.setItem(this.expandedName,this.open?"open":"closed")}get expandedName(){return`${this.props.three.name}_transform`}}function Zt(i){switch(i){case"color":return"Color";case"intensity":return"Intensity";case"decay":return"Decay";case"distance":return"Distance";case"angle":return"Angle";case"penumbra":return"Penumbra";case"groundColor":return"Ground Color";case"width":return"Width";case"height":return"Height"}return i}function On(i,e){function t(){return`${e.name}_light`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=[];if(i.lightInfo!==void 0)for(const o in i.lightInfo){const c=i.lightInfo[o];c!==void 0&&(c.isColor!==void 0?a.push({title:Zt(o),prop:o,type:"color",value:c,onChange:(l,h)=>{const u=new m.Color(h);e.updateObject(i.uuid,l,u);const p=e.getScene(i.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",i.uuid);V(g,l,u)}}}):a.push({title:Zt(o),prop:o,type:typeof c,value:c,step:typeof c=="number"?.01:void 0,onChange:(l,h)=>{e.updateObject(i.uuid,l,h);const u=e.getScene(i.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",i.uuid);V(p,l,h)}}}))}return d.jsx(J,{three:e,title:"Light",items:a,expanded:n,onToggle:o=>{r(o)}})}function wn(i){const e=i.object,t=i.three;function s(){return`${t.name}_animation`}const n=localStorage.getItem(s()),r=n!==null?n==="open":!1;function a(p){localStorage.setItem(s(),p?"open":"closed")}const o=[],c=[];let l=0;e.animations.forEach(p=>{l=Math.max(l,p.duration),p.duration>0&&c.push({title:p.name,items:[{title:"Duration",type:"number",value:p.duration,disabled:!0},{title:"Blend Mode",type:"option",disabled:!0,options:[{title:"Normal",value:2500},{title:"Additive",value:2501}]}]})}),o.push({title:"Animations",items:c});let h;const u=t.getScene(e.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",e.uuid);if(p!==void 0){const g=p.mixer;if(g!==void 0){const _=[{title:"Time Scale",type:"range",value:g.timeScale,step:.01,min:-1,max:2,onChange:(E,v)=>{g.timeScale=v,t.updateObject(e.uuid,"mixer.timeScale",v)}}];_.push({title:"Stop All",type:"button",onChange:()=>{g.stopAllAction(),t.requestMethod(e.uuid,"stopAllAction",void 0,"mixer")}}),o.push({title:"Mixer",items:_}),h=new m.SkeletonHelper(p),G.instance?.scene.add(h)}}}return b.useEffect(()=>()=>{h!==void 0&&Q(h)},[]),d.jsx(J,{three:i.three,title:"Animation",items:o,expanded:r,onToggle:p=>{a(p)}})}const gt={name:"",uuid:"",type:"",visible:!1,matrix:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};function Ei(i){const[e,t]=b.useState(gt);b.useEffect(()=>{function a(c){t(c.value)}function o(){t(gt)}return i.three.addEventListener(L.CLEAR_OBJECT,o),i.three.addEventListener(L.SET_SCENE,o),i.three.addEventListener(L.SET_OBJECT,a),()=>{i.three.removeEventListener(L.CLEAR_OBJECT,o),i.three.removeEventListener(L.SET_SCENE,o),i.three.removeEventListener(L.SET_OBJECT,a)}},[]);const s=e.type.toLowerCase(),n=e.animations.length>0||e.mixer!==void 0,r=s.search("mesh")>-1||s.search("line")>-1||s.search("points")>-1;return d.jsx(Ae,{three:i.three,label:"Inspector",button:e.uuid.length>0?d.jsx("button",{className:"remove",onClick:()=>{W.instance.remove(e.name),t(gt)}}):void 0,children:d.jsx("div",{id:"Inspector",className:i.class,children:e.uuid.length>0&&d.jsxs(d.Fragment,{children:[d.jsxs(d.Fragment,{children:[d.jsx(Ze,{type:"string",title:"Name",prop:"name",value:e.name,disabled:!0}),d.jsx(Ze,{type:"string",title:"Type",prop:"type",value:e.type,disabled:!0}),d.jsx(Ze,{type:"string",title:"UUID",prop:"uuid",value:e.uuid,disabled:!0})]}),d.jsxs(d.Fragment,{children:[d.jsx(tt,{object:e,three:i.three}),n?d.jsx(wn,{object:e,three:i.three}):null,s.search("camera")>-1?fn(e,i.three):null,s.search("light")>-1?On(e,i.three):null,r?un(e,i.three):null]})]})})},"Inspector")}class Tn extends b.Component{autoClear=!0;autoClearColor=!0;autoClearDepth=!0;autoClearStencil=!0;outputColorSpace=m.SRGBColorSpace;localClippingEnabled=!1;clearColor=new m.Color(0);clearAlpha=1;toneMapping=m.NoToneMapping;toneMappingExposure=1;type="";constructor(e){super(e);const t=localStorage.getItem(this.expandedName),s=t!==null?t==="open":!1;if(this.state={expanded:s,lastUpdated:Date.now()},this.saveExpanded(s),G.instance){const n=G.instance.renderer;n&&(this.autoClear=n.autoClear,this.autoClearColor=n.autoClearColor,this.autoClearDepth=n.autoClearDepth,this.autoClearStencil=n.autoClearStencil,this.clearAlpha=n.getClearAlpha(),this.toneMapping=n.toneMapping,this.toneMappingExposure=n.toneMappingExposure,n instanceof m.WebGLRenderer&&(this.localClippingEnabled=n.localClippingEnabled,n.getClearColor(this.clearColor)))}this.props.three.addEventListener(L.ADD_RENDERER,this.onAddRenderer)}componentWillUnmount(){this.props.three.removeEventListener(L.ADD_RENDERER,this.onAddRenderer)}onAddRenderer=e=>{const t=e.value;if(this.autoClear=t.autoClear,this.autoClearColor=t.autoClearColor,this.autoClearDepth=t.autoClearDepth,this.autoClearStencil=t.autoClearStencil,this.outputColorSpace=t.outputColorSpace,this.localClippingEnabled=t.localClippingEnabled,this.clearAlpha=t.clearAlpha,this.type=t.type,this.toneMapping=t.toneMapping,this.toneMappingExposure=t.toneMappingExposure,this.clearColor.setStyle(t.clearColor,m.LinearSRGBColorSpace),m.ColorManagement.enabled=t.colorManagement,G.instance){const s=G.instance.renderer;s&&(s.autoClearColor=this.autoClearColor,s.outputColorSpace=this.outputColorSpace,s instanceof m.WebGLRenderer&&(s.localClippingEnabled=this.localClippingEnabled),s.toneMapping=this.toneMapping,s.toneMappingExposure=this.toneMappingExposure,s.setClearColor(t.clearColor,this.clearAlpha))}this.setState({lastUpdated:Date.now()})};render(){const e=()=>{if(G.instance){const t=G.instance.renderer;t&&(t.autoClearColor=this.autoClearColor,t.outputColorSpace=this.outputColorSpace,t instanceof m.WebGLRenderer&&(t.localClippingEnabled=this.localClippingEnabled),t.toneMapping=this.toneMapping,t.toneMappingExposure=this.toneMappingExposure,t.setClearColor(this.clearColor.getStyle(),this.clearAlpha),this.props.three.updateRenderer({autoClear:this.autoClear,autoClearColor:this.autoClearColor,autoClearDepth:this.autoClearDepth,autoClearStencil:this.autoClearStencil,outputColorSpace:this.outputColorSpace,localClippingEnabled:this.localClippingEnabled,clearAlpha:this.clearAlpha,clearColor:this.clearColor.getStyle(),colorManagement:m.ColorManagement.enabled,toneMapping:this.toneMapping,toneMappingExposure:this.toneMappingExposure}))}};return d.jsx(J,{three:this.props.three,title:"Renderer",expanded:this.state.expanded,items:[{type:"boolean",title:"Auto Clear",value:this.autoClear,onChange:(t,s)=>{this.autoClear=s}},{type:"boolean",title:"Auto Clear Color",value:this.autoClearColor,onChange:(t,s)=>{this.autoClearColor=s,e()}},{type:"boolean",title:"Auto Clear Depth",value:this.autoClearDepth,onChange:(t,s)=>{this.autoClearDepth=s,e()}},{type:"boolean",title:"Auto Clear Stencil",value:this.autoClearStencil,onChange:(t,s)=>{this.autoClearStencil=s,e()}},{type:"boolean",title:"Local Clipping",value:this.localClippingEnabled,onChange:(t,s)=>{this.localClippingEnabled=s,e()}},{type:"color",title:"Clear Color",value:`#${this.clearColor.getHexString()}`,onChange:(t,s)=>{this.clearColor.setStyle(s),e()}},{type:"range",title:"Clear Alpha",min:0,max:1,step:.01,value:this.clearAlpha,onChange:(t,s)=>{this.clearAlpha=s,e()}},{type:"boolean",title:"Color Management",value:m.ColorManagement.enabled,onChange:(t,s)=>{m.ColorManagement.enabled=s,e()}},{type:"option",title:"Color Space",value:this.outputColorSpace,options:[{title:"No Color Space",value:m.NoColorSpace},{title:"SRB Color Space",value:m.SRGBColorSpace},{title:"Linear SRB Color Space",value:m.LinearSRGBColorSpace}],onChange:(t,s)=>{this.outputColorSpace=s,e()}},{type:"option",title:"Tone Mapping",value:this.toneMapping,options:[{title:"None ",value:m.NoToneMapping},{title:"Linear ",value:m.LinearToneMapping},{title:"Reinhard",value:m.ReinhardToneMapping},{title:"Cineon ",value:m.CineonToneMapping},{title:"ACES Filmic",value:m.ACESFilmicToneMapping},{title:"AgX",value:m.AgXToneMapping},{title:"Neutral",value:m.NeutralToneMapping},{title:"Custom",value:m.CustomToneMapping}],onChange:(t,s)=>{this.toneMapping=s,e()}},{type:"range",title:"Tone Mapping Exposure",value:this.toneMappingExposure,min:0,max:2,step:.01,onChange:(t,s)=>{this.toneMappingExposure=s,e()}},{type:"string",title:"Type",value:this.type,disabled:!0},{type:"button",title:"Resize Scenes from Source",onChange:()=>{this.props.three.requestSize()}}],onToggle:t=>{this.setState({expanded:t}),this.saveExpanded(t)}},"renderer")}saveExpanded(e){localStorage.setItem(this.expandedName,e?"open":"closed")}get expandedName(){return`${this.props.three.name}_renderer`}}function Si(i){const[e]=b.useState([]),[t]=b.useState([]),[s,n]=b.useState(0),r=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid)return;e.push(h),t.push(d.jsx(Ae,{three:i.three,label:`Scene: ${h.name}`,scene:h,open:!1,visible:!1,onRefresh:()=>{i.three.refreshScene(h.name)},children:d.jsx($e,{child:h,scene:h,three:i.three})},h.name)),n(Date.now())},a=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid){e[u]=h,t[u]=d.jsx(Ae,{three:i.three,label:`Scene: ${h.name}`,scene:h,open:t[u].props.open,visible:t[u].props.visible,onRefresh:()=>{i.three.refreshScene(h.name)},children:d.jsx($e,{child:h,scene:h,three:i.three})},h.name),n(Date.now());return}},o=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid){e.splice(u,1),t.splice(u,1),n(Date.now());return}},c=l=>{const h=l.value.name;for(let u=0;u<e.length;u++){const p=e[u],g=p.name===h;t[u]=d.jsx(Ae,{three:i.three,label:`Scene: ${p.name}`,scene:p,open:g,visible:g,onRefresh:()=>{i.three.refreshScene(p.name)},children:d.jsx($e,{child:p,scene:p,three:i.three})},p.name)}n(Date.now())};return b.useEffect(()=>(i.three.addEventListener(L.ADD_SCENE,r),i.three.addEventListener(L.SET_SCENE,c),i.three.addEventListener(L.REFRESH_SCENE,a),i.three.addEventListener(L.REMOVE_SCENE,o),()=>{i.three.removeEventListener(L.ADD_SCENE,r),i.three.removeEventListener(L.SET_SCENE,c),i.three.removeEventListener(L.REFRESH_SCENE,a),i.three.removeEventListener(L.REMOVE_SCENE,o)}),[]),d.jsxs("div",{id:"SidePanel",children:[d.jsx("div",{className:"scenes",children:t},s),d.jsx(Ei,{three:i.three}),d.jsx(Tn,{three:i.three}),d.jsx(k,{three:i.three})]})}const wt=b.forwardRef((i,e)=>d.jsxs("div",{className:"editor",ref:e,style:i.style,children:[i.header&&d.jsx("div",{className:"header",children:i.header}),i.children,i.footer&&d.jsx("div",{className:"footer",children:i.footer})]}));wt.displayName="Editor";function xi(i){return d.jsxs(wt,{children:[d.jsx(G,{three:i.three,scenes:i.scenes,onSceneAdd:i.onSceneAdd,onSceneResize:i.onSceneResize,onSceneUpdate:i.onSceneUpdate}),d.jsx(Si,{three:i.three})]})}function Mn(i){const{app:e,scenes:t,onSceneAdd:s,onSceneUpdate:n,onSceneResize:r,onLoad:a,renderLoading:o=null,children:c}=i,[l,h]=b.useState(!1);if(b.useEffect(()=>{e.detectSettings().then(()=>{a?a(e).then(()=>h(!0)):h(!0)})},[]),!l)return d.jsx(d.Fragment,{children:o});const u=e.components.get("three");return e.editor?d.jsx(xi,{three:u,scenes:t,onSceneAdd:s,onSceneUpdate:n,onSceneResize:r}):d.jsx(d.Fragment,{children:c?.(e)})}const An=`#include <common>
115
+ }`;class fi extends m.ShaderMaterial{constructor(e){super({extensions:{derivatives:!0},uniforms:{uScale:{value:e?.scale!==void 0?e?.scale:.1},uDivisions:{value:e?.divisions!==void 0?e?.divisions:10},uColor:{value:e?.color!==void 0?e?.color:new m.Color(16777215)},uDistance:{value:e?.distance!==void 0?e?.distance:1e4},uSubgridOpacity:{value:e?.subgridOpacity!==void 0?e?.subgridOpacity:.15},uGridOpacity:{value:e?.gridOpacity!==void 0?e?.gridOpacity:.25}},glslVersion:m.GLSL3,side:m.DoubleSide,transparent:!0,name:"InfiniteGrid",vertexShader:_n,fragmentShader:yn})}get color(){return this.uniforms.uColor.value}set color(e){this.uniforms.uColor.value=e}get gridOpacity(){return this.uniforms.uGridOpacity.value}set gridOpacity(e){this.uniforms.uGridOpacity.value=e}get subgridOpacity(){return this.uniforms.uSubgridOpacity.value}set subgridOpacity(e){this.uniforms.uSubgridOpacity.value=e}}class gi extends m.Mesh{gridMaterial;constructor(e){const t=new fi(e);super(new m.PlaneGeometry,t),this.gridMaterial=t,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}class vi extends w.NodeMaterial{uScale;uDivisions;uColor;uDistance;uSubgridOpacity;uGridOpacity;constructor(e){super(),this.name="InfiniteGrid",this.side=w.DoubleSide,this.transparent=!0,this.uScale=R.uniform(e?.scale??.1),this.uDivisions=R.uniform(e?.divisions??10),this.uColor=R.uniform(e?.color??new w.Color(16777215)),this.uDistance=R.uniform(e?.distance??1e4),this.uSubgridOpacity=R.uniform(e?.subgridOpacity??.15),this.uGridOpacity=R.uniform(e?.gridOpacity??.25);const{uScale:t,uDivisions:s,uColor:n,uDistance:r,uSubgridOpacity:a,uGridOpacity:o}=this,c=R.varyingProperty("vec3","vWorldPosition");this.positionNode=R.Fn(()=>{const h=R.positionLocal.xzy.mul(r).add(R.vec3(R.cameraPosition.x,R.float(0),R.cameraPosition.z));return c.assign(h),h})();const l=R.Fn(([h])=>{const u=c.xz.div(h),p=R.fwidth(u),g=R.abs(R.fract(u.sub(.5)).sub(.5)).div(p).div(2),C=R.min(g.x,g.y);return R.float(1).sub(R.min(C,R.float(1)))});this.outputNode=R.Fn(()=>{const h=c,u=R.max(R.float(200),R.abs(R.cameraPosition.y.sub(h.y))),p=R.float(R.distance(R.cameraPosition,h)),g=R.log(u).div(R.log(s)),C=R.pow(s,R.floor(g)),_=C.mul(s),E=_.mul(s),v=l(C.mul(t)),y=l(_.mul(t)),x=l(E.mul(t)),O=u.sub(C).div(_.sub(C)),S=R.float(.3),T=R.max(O.sub(R.float(1)).add(S),R.float(0)).div(S),M=v.mul(R.pow(R.float(1).sub(R.min(p.div(r),R.float(1))),R.float(3))),U=R.float(.5),A=M.sub(T).mul(a),j=R.mix(A,M.mul(o).sub(T.mul(o.sub(a)).mul(U)),y),ee=R.float(R.mix(j,M.mul(o),x));return R.If(R.lessThanEqual(ee,R.float(1/127)),()=>{R.Discard()}),R.vec4(n,ee)})()}get color(){return this.uColor.value}set color(e){this.uColor.value=e}get gridOpacity(){return this.uGridOpacity.value}set gridOpacity(e){this.uGridOpacity.value=e}get subgridOpacity(){return this.uSubgridOpacity.value}set subgridOpacity(e){this.uSubgridOpacity.value=e}}class _i extends w.Mesh{gridMaterial;constructor(e){const t=new vi(e);super(new w.PlaneGeometry,t),this.gridMaterial=t,this.frustumCulled=!1,this.name="InfiniteGridHelper"}get color(){return this.gridMaterial.color}set color(e){this.gridMaterial.color=e}get gridOpacity(){return this.gridMaterial.gridOpacity}set gridOpacity(e){this.gridMaterial.gridOpacity=e}get subgridOpacity(){return this.gridMaterial.subgridOpacity}set subgridOpacity(e){this.gridMaterial.subgridOpacity=e}}function mt(i){const[e,t]=b.useState(i.selected),s="toggle"+(e?" selected":"");return d.jsx("button",{className:s,onClick:()=>{const n=!e;t(n),i.onClick(n)},style:{backgroundImage:`url(${i.icon})`,backgroundPositionX:"center",backgroundPositionY:i.top!==void 0?`${i.top}px`:"center",backgroundSize:`${i.width!==void 0?`${i.width}px`:"26px"} ${i.height}px`}},i.name)}class yi extends Kt{constructor(){super();const e=je.remapClamp(je.linearDepth(),.1,.5,0,1).oneMinus();this.colorNode=je.vec4(e,e,e,1)}}class Ci extends Kt{constructor(){super(),this.colorNode=je.vec4(je.uv(),0,1)}}class W extends m.EventDispatcher{static DRAG_START="Transform::dragStart";static DRAG_END="Transform::dragEnd";static _instance;three;activeCamera;controls=new Map;visibility=new Map;setApp(e){this.three=e,this.three.addEventListener(L.SET_SCENE,this.setScene)}clear(){for(const e of this.controls.values()){e.detach(),e.disconnect();const t=e.getHelper();Q(t)}this.controls=new Map,this.visibility=new Map}add(e){let t=this.controls.get(e);if(t===void 0){const s=document.querySelector(".clickable");t=new ji.TransformControls(this.activeCamera,s),t.getHelper().name=e,t.setSize(.5),t.setSpace("local"),this.controls.set(e,t),this.visibility.set(e,!0),t.addEventListener("mouseDown",()=>{this.dispatchEvent({type:W.DRAG_START})}),t.addEventListener("mouseUp",()=>{this.dispatchEvent({type:W.DRAG_END})}),t.addEventListener("dragging-changed",n=>{G.instance?.toggleOrbitControls(n.value)})}return t}get(e){return this.controls.get(e)}remove(e){const t=this.get(e);return t===void 0?!1:(t.detach(),t.disconnect(),Q(t.getHelper()),this.controls.delete(e),!0)}enabled(e){this.controls.forEach(t=>{t.enabled=e})}updateCamera(e,t){this.activeCamera=e,this.controls.forEach(s=>{s.camera!==e&&(s.camera=e,e.getWorldPosition(s.cameraPosition),e.getWorldQuaternion(s.cameraQuaternion)),s.domElement!==t&&(s.disconnect(),s.domElement=t,s.connect(t))})}show(){this.controls.forEach(e=>{const t=e.getHelper(),s=this.visibility.get(t.name);s!==void 0&&(t.visible=s)})}hide(){this.controls.forEach(e=>{const t=e.getHelper();this.visibility.set(t.name,t.visible),t.visible=!1})}setScene=()=>{this.clear()};static get instance(){return W._instance||(W._instance=new W),W._instance}}const Cn=new w.BoxGeometry,ft=new w.Vector2;class Ke extends w.Object3D{curve=new w.CatmullRomCurve3;line;draggable;curvePos;tension=.5;closed=!1;subdivide=50;curveType;offset=1;lineMaterial;_camera;_curvePercentage=0;_draggableScale=10;_transform;raycaster;draggedMat=new w.MeshBasicMaterial;parentGroup;group;constructor(e,t){const s=new w.Color($.lerp(.5,1,Math.random()),$.lerp(.5,1,Math.random()),$.lerp(.5,1,Math.random()));super(),this.name=e,this.lineMaterial=new w.LineBasicMaterial({color:s}),this.line=new w.Line(new w.BufferGeometry,this.lineMaterial),this.line.name="line",this.line.visible=!1,this.add(this.line),this._camera=t,this.curveType="catmullrom",this.draggedMat.color=s,this.draggable=new w.Object3D,this.draggable.name="draggablePoints",this.add(this.draggable),this.curvePos=new w.Mesh(new w.SphereGeometry(1.5),new w.MeshBasicMaterial({color:s})),this.curvePos.name="curvePos",this.curvePos.scale.setScalar(this._draggableScale),this.curvePos.visible=!1,this.add(this.curvePos),this.raycaster=new w.Raycaster,this.raycaster.params.Line.threshold=3,this.enable()}enable(){document.addEventListener("pointerdown",this.onMouseClick)}disable(){document.removeEventListener("pointerdown",this.onMouseClick)}dispose=()=>{this._transform&&(this._transform.removeEventListener("objectChange",this.updateSpline),W.instance.remove(this.name)),this.disable(),this.parentGroup.removeGroup(this.name)};hideTransform=()=>{this._transform?.detach()};exportSpline=()=>{const e=[];this.draggable.children.forEach(t=>{e.push([X(t.position.x,3),X(t.position.y,3),X(t.position.z,3)])}),Xt({name:this.name,points:e,tension:this.tension,closed:this.closed,subdivide:this.subdivide,type:this.curveType}),console.log("Spline copied!")};showPoints=(e=!0)=>{this.draggable.visible=e};addPoints=(e=[])=>{if(e.length>0){const t=e.length-1;for(let s=0;s<t;s++)this.addPoint(e[s],!1);this.addPoint(e[t])}};addPoint=(e,t=!0)=>{const s=this.draggable.children.length,n=new w.Mesh(Cn,this.draggedMat);n.name=`point_${s}`,n.position.copy(e),n.scale.setScalar(this._draggableScale),this.draggable.add(n),this._transform?.attach(n);const r=this.points.length>1;return r&&t&&this.updateSpline(),this.line.visible=r,this.updateCurrentPoint(),n};addNextPt=()=>{const e=this.draggable.children.length,t=e>1?this.draggable.children[e-1].position.clone():new w.Vector3,s=this.addPoint(t);this.updateField(s.position)};removePoint=e=>{if(this._transform?.object===e){this._transform?.detach();const t=this.draggable.children[this.draggable.children.length-1];this._transform?.attach(t),this.updateField(t.position)}Q(e),this.updateSpline()};removePointAt=e=>{const t=this.draggable.children[e];this.removePoint(t)};removeSelectedPt=()=>{this._transform?.object!==void 0&&this.removePoint(this._transform?.object)};updateLastPoint(e){const t=this.draggable.children.length;t>0&&(this.draggable.children[t-1].position.copy(e),this.updateSpline())}updateSpline=()=>{this.points.length<2||(this.curve=new w.CatmullRomCurve3(this.points,this.closed,this.curveType,this.tension),this.line.geometry.dispose(),this.line.geometry=new w.BufferGeometry().setFromPoints(this.curve.getPoints(this.subdivide)),this.curvePos.position.copy(this.getPointAt(this._curvePercentage)))};updateField(e){this.group.current?.setField("Current Point",e)}onMouseClick=e=>{if(!G.instance||!G.instance.currentWindow||this._transform&&!this._transform.getHelper().visible)return;const s=G.instance.currentWindow.current.getBoundingClientRect();ft.x=(e.clientX-s.x)/s.width*2-1,ft.y=-((e.clientY-s.y)/s.height)*2+1,this.raycaster.setFromCamera(ft,this.camera);const n=this.raycaster.intersectObjects(this.draggable.children,!1);if(n.length>0){const r=n[0].object;r!==this._transform?.object&&(this._transform?.attach(r),this.updateField(r.position))}};getPointAt(e){return this.curve.points.length>1?this.curve.getPointAt(e):this.curve.points.length===1?this.curve.points[0]:new w.Vector3}getTangentAt(e){return this.curve.getTangentAt(e)}get points(){const e=[];return this.draggable.children.forEach(t=>{e.push(t.position)}),e}get total(){return this.draggable.children.length}get draggableScale(){return this._draggableScale}set draggableScale(e){this._draggableScale=e,this.draggable.children.forEach(t=>t.scale.setScalar(e)),this.curvePos.scale.setScalar(e)}get camera(){return this._camera}set camera(e){this._camera=e,this._transform!==void 0&&(this._transform.camera=e)}get curvePercentage(){return this._curvePercentage}set curvePercentage(e){this._curvePercentage=e,this.curvePos.position.copy(this.getPointAt(e))}updateCurrentPoint(){if(this._transform?.object&&this.group){const e=this._transform?.object;e.name.search("point")>-1&&this.updateField(e.position)}}onUpdateTransform=()=>{this.updateCurrentPoint(),this.updateSpline()};initDebug(e,t){const s=this.draggable.children;this.visible=t,this.parentGroup=e,this._transform=W.instance.add(this.name),this._transform.camera=this._camera,this._transform.addEventListener("objectChange",this.onUpdateTransform),s.length>0&&this._transform.attach(s[s.length-1]),G.instance?.helpersContainer.add(this._transform.getHelper());const n=s.length>0?s[s.length-1].position:{x:0,y:0,z:0};this.group=e.addGroup({title:this.name,expanded:t,items:[{prop:"Closed",type:"boolean",value:this.closed},{prop:"Visible",type:"boolean",value:this.visible},{prop:"Show Position",type:"boolean",value:this.curvePos.visible},{prop:"Show Points",type:"boolean",value:this.draggable.visible},{prop:"Color",type:"color",value:`#${this.draggedMat.color.getHexString()}`},{prop:"Curve",type:"option",options:[{title:"Catmullrom",value:"catmullrom"},{title:"Centripetal",value:"centripetal"},{title:"Chordal",value:"chordal"}]},{prop:"Draggable Scale",type:"range",min:.01,max:100,step:.01,value:this._draggableScale},{prop:"Subdivide",type:"range",min:1,max:1e3,step:1,value:this.subdivide},{prop:"Tension",type:"range",min:0,max:1,step:.01,value:this.tension},{prop:"New Pt Offset",type:"range",min:0,max:10,value:this.offset},{prop:"Curve At",type:"range",min:0,max:1,step:.01,value:0},{prop:"Toggle Transform",type:"button"},{prop:"Add Point",type:"button"},{prop:"Remove Point",type:"button"},{prop:"Export",type:"button"},{prop:"Delete",type:"button"},{prop:"Current Point",type:"grid3",value:n}],onUpdate:(r,a)=>{switch(r){case"Closed":this.closed=a,this.updateSpline();break;case"Visible":this.visible=a;break;case"Color":this.lineMaterial.color.setStyle(a),this.draggedMat.color.setStyle(a);break;case"Curve":this.curveType=a,this.updateSpline();break;case"Draggable Scale":this.draggableScale=a;break;case"Subdivide":this.subdivide=a,this.updateSpline();break;case"Tension":this.tension=a,this.updateSpline();break;case"New Pt Offset":this.offset=a;break;case"Curve At":this.curvePos.position.copy(this.getPointAt(a));break;case"Show Position":this.curvePos.visible=a;break;case"Show Points":this.draggable.visible=a;break;case"Toggle Transform":this._transform&&(this._transform.getHelper().visible=!this._transform.getHelper().visible);break;case"Add Point":this.addNextPt();break;case"Remove Point":this.removeSelectedPt();break;case"Export":this.exportSpline();break;case"Delete":this.parent.currentSpline=null,Q(this);break;case"Current Point":if(this.group.current&&this._transform?.object){const o=this._transform?.object;o.name.search("point")>-1&&(o.position.copy(a),this.updateSpline())}break}}}),this.draggable.children.forEach(r=>{this.debugPoint(r)})}debugPoint=e=>{e.name,e.visible=this.draggable.visible}}let qe=0;class bi extends m.Object3D{defaultScale=10;currentSpline=null;_camera;group=null;three;splineDataText="";constructor(e,t){super(),this.name="Spline Editor",this._camera=e,this.three=t,this.three.addEventListener(L.ADD_SPLINE,this.onAddSpline)}initDebug(){this.group=k.addEditorGroup({title:this.name,items:[{type:"field",prop:"Spline Data",value:"",disabled:!1},{type:"button",prop:"Import Spline"},{type:"button",prop:"New Spline"},{type:"boolean",prop:"Show Points",value:!0},{type:"boolean",prop:"Draw Mode",value:!1},{type:"boolean",prop:"Visible",value:this.visible},{type:"range",prop:"Default Scale",min:0,max:50,step:.01,value:this.defaultScale}],onUpdate:(e,t)=>{switch(e){case"New Spline":this.createSpline();break;case"Spline Data":this.splineDataText=t;break;case"Import Spline":this.createSplineFromJSON(JSON.parse(this.splineDataText));break;case"Show Points":this.showPoints(t);break;case"Visible":this.visible=t;break;case"Default Scale":this.defaultScale=t;break;case"Draw Mode":t?this.enableClickToDraw():this.disableClickToDraw();break}}})}dispose(){this.three.removeEventListener(L.ADD_SPLINE,this.onAddSpline),k.removeEditorGroup(this.name)}addSpline(e,t){e.draggableScale=this.defaultScale,e.hideTransform(),this.group?.current!==null&&e.initDebug(this.group.current,t),this.add(e),this.currentSpline=e}createSpline=(e=[])=>{const t=`Spline ${qe+1}`,s=new Ke(t,this._camera);return s.addPoints(e),this.addSpline(s,!0),qe++,s};createSplineFromArray=e=>{const t=[];return e.forEach(s=>{t.push(new m.Vector3(s[0],s[1],s[2]))}),this.createSpline(t)};createSplineFromCatmullRom=e=>this.createSpline(e.points);createSplineFromJSON=e=>{const t=[];e.points.forEach(n=>{t.push(new m.Vector3(n[0],n[1],n[2]))});const s=new Ke(e.name,this._camera);return s.closed=e.closed,s.subdivide=e.subdivide,s.tension=e.tension,s.type=e.type,s.addPoints(t),s.updateSpline(),this.addSpline(s,!1),s};showPoints=(e=!0)=>{this.children.forEach(t=>{t.showPoints(e)})};onAddSpline=e=>{const t=JSON.parse(e.value),s=t.name!==void 0?t.name:`Spline ${qe+1}`,n=new Ke(s,this.camera);t.tension!==void 0&&(n.tension=t.tension),t.closed!==void 0&&(n.closed=t.closed),t.subdivide!==void 0&&(n.subdivide=t.subdivide),t.type!==void 0&&(n.curveType=t.type);const r=[];t.points.forEach(a=>{r.push(new m.Vector3(a[0],a[1],a[2]))}),n.addPoints(r),this.addSpline(n,!1),qe++};isMouseDown=!1;enableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.addEventListener("mousedown",this.onClickCanvas),e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("mouseup",this.onMouseUp)})}disableClickToDraw(){document.querySelectorAll(".clickable").forEach(e=>{e.removeEventListener("mousedown",this.onClickCanvas),e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("mouseup",this.onMouseUp)})}onClickCanvas=e=>{if(e.button!==0)return;if(this._camera.type!=="OrthographicCamera"){console.warn("Spline Editor - 3D Camera not supported in Draw Mode");return}const s=e.target.getBoundingClientRect(),n=(e.clientX-s.left)/s.width*2-1,r=-((e.clientY-s.top)/s.height)*2+1;if(G.instance){const o=new m.Raycaster;o.setFromCamera(new m.Vector2(n,r),this._camera);const c=o.intersectObjects(G.instance.helpersContainer.children,!0);for(let l=0;l<c.length;l++){const h=c[l];if(!(h.object.isLine||h.object.isTransformControlsPlane)&&h.object.isObject3D)return}}this.currentSpline===null&&(this.currentSpline=this.createSpline());const a=this.mouseToSplinePos(n,r,s.width,s.height);this.currentSpline?.addPoint(a),this.isMouseDown=!0};onMouseMove=e=>{if(!this.isMouseDown)return;const s=e.target.getBoundingClientRect(),n=(e.clientX-s.left)/s.width*2-1,r=-((e.clientY-s.top)/s.height)*2+1,a=this.mouseToSplinePos(n,r,s.width,s.height);this.currentSpline?.updateLastPoint(a),this.currentSpline?.updateField(a)};onMouseUp=()=>{this.isMouseDown=!1};mouseToSplinePos(e,t,s,n){const r=new m.Vector3,a=Math.PI/2,o=this._camera,c=o.zoom,l=o.rotation.x===-6123233995736766e-32&&o.rotation.y===0&&o.rotation.z===0,h=o.rotation.x===-Math.PI&&o.rotation.y===12246467991473532e-32&&o.rotation.z===Math.PI,u=o.rotation.x===-6162975822039155e-48&&o.rotation.y===-a&&o.rotation.z===0,p=o.rotation.x===-6162975822039155e-48&&o.rotation.y===a&&o.rotation.z===0,g=o.rotation.x===-1.5707953264174506&&o.rotation.y===0&&o.rotation.z===0,C=o.rotation.x===1.5707953264174506&&o.rotation.y===0&&o.rotation.z===0;let _=e,E=t;h||p?_*=-1:g&&(E*=-1);const v=s/2/c,y=n/2/c;if(this.currentSpline===null&&(this.currentSpline=this.createSpline()),l||h){const x=_*v+o.position.x,O=E*y+o.position.y;r.set(x,O,0)}else if(u||p){const x=_*v+o.position.z,O=E*y+o.position.y;r.set(0,O,x)}else if(g||C){const x=_*v+o.position.x,O=E*y+o.position.z;r.set(x,0,O)}return r}get camera(){return this._camera}set camera(e){this._camera=e,this.children.forEach(t=>{const s=t;s.camera=e})}}const $t=["Single","Side by Side","Stacked","Quad"],bn="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC60lEQVRYhe2YT4hNcRTHP48xpmYaNAvRyEQxEhnKQljYsRm9/EmSyJiMFAsMZWNhJYoNIUVJ2VGiyb9ZzIpMpkQSahbGv9GMYWrM+1rc2zjvzvvdd+99rzdvMd+6de75nd+5387vnN/v/G5KEuWMKRNNIB8mCRaKiiL5qQb2ApuBuUAV0Ad0AJeB3sSeJRX6LJbULTf6JTUn9Z+KWMUpPyp/Avoa4CNQZ3Sj/lNpdL/xottR7AjOkHRUUpekN5I6JbVLavDH75lIfZN0UFKTpCWS0pJem/HeJBEMG6yV1ONYtgFJbZJ+GF1jDh+zJb03NuliEuwMkMo4yErS2RA/LcbuYVyCrm1mA7Dal/8Cu4FG4JD/HsTTkCy6a+SVMTPQuc1sBKb78nHghi+/A+YBxwL2lbhRY+ThuARdEVxu5JdGFvACr0otdoZ8Y4+Rn0Sn5sFFsMvI6YB9MzA1YJ8mN8k1wAHzfj4uQVdyrpI0aJL7oqTtkq4FiqPLyCOSbktqlbRL0jlJQ2b8QdwCUZ4qvhRStZL0XFK1pMd57CRvq5mfhKBriRfiFUMY6oD7eOdwPlQAN4G10dfWg+uouwXsiOssAj4AC+JMcEWwvnAuOTEr7gTXPmg34zagOwkbIIOXAo9CbDYBrcBXYN+4UUdy2sRflyS5zVNlfPX7ugpJW5V9nI7mmh+lYU0lCZ2B3TOnAVuAk0BTwC5nuhWro46KauBOQJch5OpRaoIW34GreGf+YZdRqS9NAj4Bp4ClQDvwOWxCqSM4ADQEdKE5XvbXzlITrAVe4TW+M6NMKDXBFLAMuAD0ACfIc7pMZBXXA2cY3/xmodQRHAL2A2+NLtj8ZiEKwUL/z2WMPAJcAVYALWSf8dZuDFGWeBHwKxm3sWYhiGG8Tfo6sA2vSfiSy4GrH3wGrDcfKSSKKf6v1E9yF0XK9Q1XBPuMXMw8HXTonQFwETwNzMFr64v1jzgFHIk9ybHEZYPJo65QlD3Bf2/Q/eaHPiSWAAAAAElFTkSuQmCC",En="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAETklEQVRYhe2YXYhVVRTHf3d0/JhyUrMpFbImM+whSa3Mynww+4AeIgiKoozooQ+KyMyXIAujF6OXqHyI6iEKKYgIP/owsjSFqCkprdDUTEcjbWZ0HHV+Pex1ucfb9Z57Z9REXHA4Z++99l7/s/ZZ/7X2KaiczNLwfwPIk9MA+yunNMAG4DHgV+BvoB3YFff2TPstYEyfrajVroI6Sr1GvahsbJC63HzZq04pmztSvU5tVRuqYRiYg78JeBR4HPg5ntdmxovz9wJfA3uAxuibDLQCA+IqynnAQuBuYCnwMLC1rx48U12U8cZqdWqMDcx4cI16qTpYbVKHqa+ovWUeHKsujn7VL9ULq2HI+wY7gVeBJdGeFu3J4ZUiy/cAXeHRRuAQsC/GC0B3eG4BcH/0tUV7czUAeVsMsBF4Kha9HZgCvAncAuwPnXHA0wFuGLANuDrGuoGDwFxgTqzzQ7RX5FrP2eLsdb76vnogtme6+nE8H1YPlQXHwbi3q9eqn0e7Tb25VrsF68vFY0lb1AGcDTwItGQ8tQM4AIwGmqP/EPAu8A0wElgJfFGzxTo8mKWXu9Rd4ZF96jvqjSbauEC9Sn1O3R463epLaku99voCsFXdkAH3kNpcQW+IiT/bQne3eufxBtioPqP2mKhioXpWzpxb1T8C5Ifh4ZptVoriRmAIKdrI3Lujf3bobAPeJpF0NVkKrAFuI9HTOBIxnxFrF4OgQKKr/dnJlQA+AcwABgOHA4zAamA5cE7orQL+zAEHiWI+A2bFC7aSguheYCgpqAphZz3wSB7AecCICv2TgH8oFRib4gVqka0k0h8CXAxMBW6ooDejFoCvA9OBQUAvKWM0kDz4XUZvNKXtyZMWUl7vBbaQXq457PeEziDgx/KJlQAuIPFdMcEXv5OdYWBP9M8k8VpnDQCvB4aTSrCNJB5cSdrW3tBpIJVnR0qdUTxAfdGUOVTnmwqEanNmqltC/9OgqePKg5eom8PgdvW+oJ9Kupera0O3U50TL3lcAaI+oHaF4R3qa6Z822wq0Saq89T1lmSxOrxeW/Xm4uGkiqQDmECKuKHxHW0HdpMiewSpvGqKeR8Ay0iBsYIjg6261PE2o9Q3Yqv+MqWxO9R1Hl12qs+q49Vlppy82pSr+5xJKsko4AXgHlJ0t5NIeg3wLXAlqZhtIUV8J6nmWwX8QiLjdhL5TwMWkY4R6/rrwYKlMr1Y321QZ/vfwBijPqm+rF4Wc7PjE9QllurGVeoV5gRNHsAm9fnMom3qrKPoTjKdMXaYyrFygEWQ72XWW24qhPu8xcUc2UU6O8wFPjmK7jhgPHAuMJGUGQ6U6WwE5sfzTXGvei7KA9hFOiR9D/wOfFVFt4dS2tpfRe83Ur7/CPiJakfOGgBCypubatArl2r8VfOax/LfzABKtePAzHO/5FgC7KBEzB2kOrDfUm8mOeFySv9+OyFyGmB/5aQH+C9BVKmVCNuMZgAAAABJRU5ErkJggg==",Sn="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAQ0lEQVQ4jWP8////fwYqAxYozUhFM/8zkaKYWIWkGEq0b0ZdSjQY5i79TyWagRGaTUdzFEEw6lLqGzqwLoVVJ1StpwA9sBwbUqAh5gAAAABJRU5ErkJggg==";class G extends b.Component{static instance=null;scene;renderer;currentScene;scenes=new Map;cameras=new Map;controls=new Map;currentCamera;currentWindow;helpersContainer=new w.Group;grid;cameraHelpers=new Map;lightHelpers=new Map;interactionHelper=new w.AxesHelper(25);currentTransform;splineEditor;depthMaterial;normalsMaterial;uvMaterial;wireframeMaterial=new w.MeshBasicMaterial({opacity:.33,transparent:!0,wireframe:!0});playing=!1;rafID=-1;cameraControlsRafID=-1;width=0;height=0;tlCam=null;trCam=null;blCam=null;brCam=null;tlRender="Renderer";trRender="Renderer";blRender="Renderer";brRender="Renderer";cameraVisibility=!0;lightVisibility=!0;gridVisibility=!0;rendererReady=!1;selectedItem=void 0;cameraControlsStartTime=0;cameraControlsLastTime=0;debugCamera;raycaster=new w.Raycaster;pointer=new w.Vector2;cameraControls=void 0;canvasRef;containerRef;tlWindow;trWindow;blWindow;brWindow;editorCameras=["Top","Bottom","Left","Right","Front","Back","Orthographic","UI","Debug"];constructor(e){super(e),this.props.three.addEventListener(L.ADD_RENDERER,this.setupRenderer),this.scene=new w.Scene,this.scene.name=this.scene.uuid="",this.canvasRef=b.createRef(),this.containerRef=b.createRef(),this.tlWindow=b.createRef(),this.trWindow=b.createRef(),this.blWindow=b.createRef(),this.brWindow=b.createRef();const t=e.three.name,s=localStorage,n=s.getItem(`${t}_mode`);this.state={mode:n!==null?n:"Single",modeOpen:!1,renderModeOpen:!1,interactionMode:"Orbit",interactionModeOpen:!1,lastUpdate:Date.now()},s.setItem(`${t}_mode`,this.state.mode),s.setItem(`${t}_tlCam`,s.getItem(`${t}_tlCam`)!==null?s.getItem(`${t}_tlCam`):"Debug"),s.setItem(`${t}_trCam`,s.getItem(`${t}_trCam`)!==null?s.getItem(`${t}_trCam`):"Orthographic"),s.setItem(`${t}_blCam`,s.getItem(`${t}_blCam`)!==null?s.getItem(`${t}_blCam`):"Front"),s.setItem(`${t}_brCam`,s.getItem(`${t}_brCam`)!==null?s.getItem(`${t}_brCam`):"Top"),s.setItem(`${t}_tlRender`,s.getItem(`${t}_tlRender`)!==null?s.getItem(`${t}_tlRender`):"Renderer"),s.setItem(`${t}_trRender`,s.getItem(`${t}_trRender`)!==null?s.getItem(`${t}_trRender`):"Renderer"),s.setItem(`${t}_blRender`,s.getItem(`${t}_blRender`)!==null?s.getItem(`${t}_blRender`):"Renderer"),s.setItem(`${t}_brRender`,s.getItem(`${t}_brRender`)!==null?s.getItem(`${t}_brRender`):"Renderer");const r={Vector2:w.Vector2,Vector3:w.Vector3,Vector4:w.Vector4,Quaternion:w.Quaternion,Matrix4:w.Matrix4,Spherical:w.Spherical,Box3:w.Box3,Sphere:w.Sphere,Raycaster:w.Raycaster};re.install({THREE:r}),this.setupScene(),this.setupTools();const a=localStorage.getItem(this.expandedCameraVisibility);a!==null&&(this.cameraVisibility=a==="open"),this.saveExpandedCameraVisibility();const o=localStorage.getItem(this.expandedLightVisibility);o!==null&&(this.lightVisibility=o==="open"),this.saveExpandedLightVisibility();const c=localStorage.getItem(this.expandedGridVisibility);c!==null&&(this.gridVisibility=c==="open"),this.grid&&(this.grid.visible=this.gridVisibility),this.saveExpandedGridVisibility(),G.instance=this}componentDidMount(){this.enable(),this.assignControls(),this.resize(),this.play(),W.instance.setApp(this.props.three),W.instance.activeCamera=this.debugCamera,this.props.three.requestRenderer()}componentDidUpdate(e,t,s){t.mode!==this.state.mode&&(this.assignControls(),this.resize())}componentWillUnmount(){this.disable(),this.clear(),k.removeEditorGroup("View Settings")}render(){const e=[];return this.cameras.forEach((t,s)=>{e.push(s)}),d.jsxs("div",{className:"multiview",children:[d.jsx("canvas",{ref:this.canvasRef}),d.jsxs("div",{className:`cameras ${this.state.mode==="Single"||this.state.mode==="Stacked"?"single":""}`,ref:this.containerRef,children:[this.state.mode==="Single"&&d.jsx(d.Fragment,{children:d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}})}),(this.state.mode==="Side by Side"||this.state.mode==="Stacked")&&d.jsxs(d.Fragment,{children:[d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}}),d.jsx(ge,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:t=>{this.controls.get(this.trCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.trCam),this.trCam=s,localStorage.setItem(`${this.appID}_trCam`,s.name),this.createControls(s,this.trWindow.current))},onSelectRenderMode:t=>{this.trRender=t,localStorage.setItem(`${this.appID}_trRender`,t)}})]}),this.state.mode==="Quad"&&d.jsxs(d.Fragment,{children:[d.jsx(ge,{name:"tl",camera:this.tlCam,options:e,ref:this.tlWindow,onSelectCamera:t=>{this.controls.get(this.tlCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.tlCam),this.tlCam=s,localStorage.setItem(`${this.appID}_tlCam`,s.name),this.createControls(s,this.tlWindow.current))},onSelectRenderMode:t=>{this.tlRender=t,localStorage.setItem(`${this.appID}_tlRender`,t)}}),d.jsx(ge,{name:"tr",camera:this.trCam,options:e,ref:this.trWindow,onSelectCamera:t=>{this.controls.get(this.trCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.trCam),this.trCam=s,localStorage.setItem(`${this.appID}_trCam`,s.name),this.createControls(s,this.trWindow.current))},onSelectRenderMode:t=>{this.trRender=t,localStorage.setItem(`${this.appID}_trRender`,t)}}),d.jsx(ge,{name:"bl",camera:this.blCam,options:e,ref:this.blWindow,onSelectCamera:t=>{this.controls.get(this.blCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.blCam),this.blCam=s,localStorage.setItem(`${this.appID}_blCam`,s.name),this.createControls(s,this.blWindow.current))},onSelectRenderMode:t=>{this.blRender=t,localStorage.setItem(`${this.appID}_blRender`,t)}}),d.jsx(ge,{name:"br",camera:this.brCam,options:e,ref:this.brWindow,onSelectCamera:t=>{this.controls.get(this.brCam.name)?.dispose();const s=this.cameras.get(t);s!==void 0&&(this.clearCamera(this.brCam),this.brCam=s,localStorage.setItem(`${this.appID}_brCam`,s.name),this.createControls(s,this.brWindow.current))},onSelectRenderMode:t=>{this.brRender=t,localStorage.setItem(`${this.appID}_brRender`,t)}})]})]}),d.jsxs("div",{className:"settings",children:[d.jsx(Qe,{title:"View",index:$t.indexOf(this.state.mode),options:$t,onSelect:t=>{t!==this.state.mode&&(this.killControls(),this.setState({mode:t}),localStorage.setItem(`${this.appID}_mode`,t))},open:this.state.modeOpen,onToggle:t=>{this.setState({modeOpen:t,renderModeOpen:!1,interactionModeOpen:!1})}}),d.jsx(Qe,{title:"Interact",index:this.state.interactionMode==="Orbit"?0:1,options:["Orbit Mode","Selection Mode"],onSelect:t=>{this.interactionHelper.visible=t==="Selection Mode",this.setState({interactionMode:this.interactionHelper.visible?"Selection":"Orbit"})},open:this.state.interactionModeOpen,onToggle:t=>{this.setState({modeOpen:!1,renderModeOpen:!1,interactionModeOpen:t})}}),d.jsx(mt,{name:"cameraHelper",icon:bn,selected:this.cameraVisibility,height:24,top:2,onClick:t=>{if(this.cameraVisibility=t,this.saveExpandedCameraVisibility(),this.cameraHelpers.forEach(s=>{s.visible=t}),this.selectedItem!==void 0&&!t){const s=this.cameraHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=!0)}}}),d.jsx(mt,{name:"lightHelper",icon:En,selected:this.lightVisibility,height:24,top:4,onClick:t=>{if(this.lightVisibility=t,this.saveExpandedLightVisibility(),this.lightHelpers.forEach(s=>{s.visible=t}),this.selectedItem!==void 0&&!t&&this.selectedItem.isLight===!0){const s=this.lightHelpers.get(this.selectedItem.name);s!==void 0&&(s.visible=!0)}}}),d.jsx(mt,{name:"gridHelper",icon:Sn,selected:this.gridVisibility,height:21,width:21,onClick:t=>{this.setGridVisibility(t)}})]},this.state.lastUpdate)]})}setupRenderer=e=>{const t=e.value;if(this.renderer){if(this.renderer instanceof m.WebGLRenderer&&t.type==="WebGLRenderer"||this.renderer instanceof w.WebGPURenderer&&t.type==="WebGPURenderer")return;this.renderer.dispose()}this.rendererReady=!1;const s=this.canvasRef.current;this.props.three.canvas=s,t.type==="WebGLRenderer"?(this.renderer=new m.WebGLRenderer({canvas:s,stencil:!1}),this.grid&&(this.scene.remove(this.grid),Q(this.grid)),this.grid=new gi,this.scene.add(this.grid),this.rendererReady=!0):t.type==="WebGPURenderer"&&(this.renderer=new w.WebGPURenderer({canvas:s,stencil:!1}),this.grid&&(this.scene.remove(this.grid),Q(this.grid)),this.grid=new _i,this.scene.add(this.grid)),this.renderer&&(this.renderer.autoClear=!1,this.renderer.shadowMap.enabled=!0,this.renderer.setClearColor(0),this.renderer.setPixelRatio(devicePixelRatio),this.renderer.setScissorTest(!0),this.resize(),this.props.three.renderer=this.renderer,this.depthMaterial?.dispose(),this.normalsMaterial?.dispose(),this.uvMaterial?.dispose(),this.depthMaterial=new yi,this.normalsMaterial=new w.MeshNormalNodeMaterial,this.uvMaterial=new Ci,t.type==="WebGPURenderer"?this.renderer.init().then(()=>{this.rendererReady=!0,this.props.three.requestScene()}):this.props.three.requestScene())};setupScene(){this.helpersContainer.name="helpers",this.scene.add(this.helpersContainer),this.interactionHelper.name="interactionHelper",this.interactionHelper.visible=!1,this.helpersContainer.add(this.interactionHelper);const e=(r,a)=>{const o=new w.OrthographicCamera(-100,100,100,-100,0,3e3);return o.name=r,o.position.copy(a),o.lookAt(0,0,0),this.cameras.set(r,o),o},t=1e3;e("Top",new w.Vector3(0,t,0)),e("Bottom",new w.Vector3(0,-t,0)),e("Left",new w.Vector3(-t,0,0)),e("Right",new w.Vector3(t,0,0)),e("Front",new w.Vector3(0,0,t)),e("Back",new w.Vector3(0,0,-t)),e("Orthographic",new w.Vector3(t,t,t)),e("UI",new w.Vector3),this.debugCamera=new w.PerspectiveCamera(60,1,.01,3e3),this.debugCamera.name="Debug",this.debugCamera.position.set(300,300,300),this.debugCamera.lookAt(0,0,0),this.cameras.set("Debug",this.debugCamera),this.currentCamera=this.debugCamera;const s=localStorage,n=this.props.three.name;this.tlCam=this.cameras.get(s.getItem(`${n}_tlCam`)),this.trCam=this.cameras.get(s.getItem(`${n}_trCam`)),this.blCam=this.cameras.get(s.getItem(`${n}_blCam`)),this.brCam=this.cameras.get(s.getItem(`${n}_brCam`)),this.tlCam===void 0&&(this.tlCam=this.cameras.get("Debug")),this.trCam===void 0&&(this.trCam=this.cameras.get("Orthographic")),this.blCam===void 0&&(this.blCam=this.cameras.get("Front")),this.brCam===void 0&&(this.brCam=this.cameras.get("Top")),k.addEditorGroup({title:"Editor",items:[{type:"button",prop:"Hide All Transforms"},{type:"button",prop:"Resize"}],onUpdate:(r,a)=>{switch(r){case"Hide All Transforms":W.instance.hide();break;case"Resize":this.resize();break}},subgroups:[{title:"Debug Camera",items:[{type:"range",prop:"Near",step:1e-4,min:.001,max:1e3,value:this.debugCamera.near},{type:"range",prop:"Far",step:.001,min:.001,max:1e4,value:this.debugCamera.far}],onUpdate:(r,a)=>{switch(r){case"Near":this.debugCamera.near=a,this.debugCamera.updateProjectionMatrix();break;case"Far":this.debugCamera.far=a,this.debugCamera.updateProjectionMatrix();break}}},{title:"Grid",items:[{type:"number",prop:"Position",value:0},{type:"color",prop:"Color",value:"#FFFFFF"},{type:"range",prop:"Grid Opacity",value:.25,min:0,max:1,step:.01},{type:"range",prop:"Subgrid Opacity",value:.15,min:0,max:1,step:.01}],onUpdate:(r,a)=>{switch(r){case"Position":this.grid&&(this.grid.position.y=a);break;case"Color":this.grid&&this.grid.color.setStyle(a);break;case"Grid Opacity":this.grid&&(this.grid.gridOpacity=a);break;case"Subgrid Opacity":this.grid&&(this.grid.subgridOpacity=a);break}}}]})}setupTools(){this.splineEditor=new bi(this.currentCamera,this.three),this.splineEditor.initDebug(),this.helpersContainer.add(this.splineEditor)}play(){this.playing=!0,this.onUpdate()}pause(){this.playing=!1,cancelAnimationFrame(this.rafID),this.rafID=-1}toggleOrbitControls(e){this.controls.forEach(t=>{t.enabled=!e})}clear(){this.three.dispatchEvent({type:L.CLEAR_OBJECT}),k.removeAllGroups(),this.clearLightHelpers(),this.clearControls(),this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),W.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=void 0,W.instance.clear(),this.cameras.forEach(e=>{this.editorCameras.indexOf(e.name)<0&&this.three.dispatchEvent({type:L.REMOVE_CAMERA,value:e})}),this.currentCamera=this.debugCamera,this.currentScene=void 0,this.scenes.forEach(e=>{this.three.dispatchEvent({type:L.REMOVE_SCENE,value:e})}),this.scenes.clear()}setGridVisibility(e){this.gridVisibility=e,this.saveExpandedGridVisibility(),this.grid&&(this.grid.visible=e)}update(){this.controls.forEach(e=>e.update()),this.cameraHelpers.forEach(e=>e.update()),this.lightHelpers.forEach(e=>{e.update!==void 0&&e.update()}),this.props.onSceneUpdate!==void 0&&this.currentScene!==void 0&&this.props.onSceneUpdate(this.currentScene)}draw(){if(this.rendererReady)switch(this.renderer&&this.renderer?.clear(),this.state.mode){case"Single":this.drawSingle();break;case"Side by Side":case"Stacked":this.drawDouble();break;case"Quad":this.drawQuad();break}}onUpdate=()=>{this.playing&&(this.update(),this.draw(),this.rafID=requestAnimationFrame(this.onUpdate))};enable(){const e=this.containerRef.current;e.addEventListener("mousemove",this.onMouseMove),e.addEventListener("click",this.onClick),window.addEventListener("keydown",this.onKey),window.addEventListener("resize",this.resize),this.three.addEventListener(L.ADD_SCENE,this.addScene),this.three.addEventListener(L.SET_SCENE,this.sceneUpdate),this.three.addEventListener(L.REMOVE_SCENE,this.removeScene),this.three.addEventListener(L.ADD_CAMERA,this.addCamera),this.three.addEventListener(L.REMOVE_CAMERA,this.removeCamera),this.three.addEventListener(L.SET_OBJECT,this.onSetSelectedItem)}disable(){const e=this.containerRef.current;e.removeEventListener("mousemove",this.onMouseMove),e.removeEventListener("click",this.onClick),window.removeEventListener("keydown",this.onKey),window.removeEventListener("resize",this.resize),this.three.removeEventListener(L.ADD_SCENE,this.addScene),this.three.removeEventListener(L.SET_SCENE,this.sceneUpdate),this.three.removeEventListener(L.REMOVE_SCENE,this.removeScene),this.three.removeEventListener(L.ADD_CAMERA,this.addCamera),this.three.removeEventListener(L.REMOVE_CAMERA,this.removeCamera),this.three.removeEventListener(L.SET_OBJECT,this.onSetSelectedItem)}resize=()=>{this.width=window.innerWidth-300,this.height=window.innerHeight,this.renderer?.setSize(this.width,this.height);const e=Math.floor(this.width/2),t=Math.floor(this.height/2);this.props.three.resize(this.width,this.height),this.props.onSceneResize!==void 0&&this.currentScene!==void 0&&this.props.onSceneResize(this.currentScene,this.width,this.height);let s=this.width,n=this.height;switch(this.state.mode){case"Side by Side":s=e,n=this.height;break;case"Stacked":s=this.width,n=t;break;case"Quad":s=e,n=t;break}const r=s/n;this.cameras.forEach(a=>{a instanceof w.OrthographicCamera?(a.left=s/-2,a.right=s/2,a.top=n/2,a.bottom=n/-2,a.name==="UI"&&(a.position.x=this.width/2,a.position.y=this.height/-2,a.position.z=100),a.updateProjectionMatrix()):a instanceof w.PerspectiveCamera&&(a.aspect=r,a.updateProjectionMatrix()),this.cameraHelpers.get(a.name)?.update()})};addScene=e=>{const t=this.props.scenes.get(e.value.name);if(t!==void 0){const s=this.scenes.get(e.value.name);if(s!==void 0){this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(s),this.props.three.scene=s;return}const n=new t;n.visible=!1,this.props.onSceneAdd!==void 0&&this.props.onSceneAdd(n),this.props.three.scene=n,this.scenes.set(e.value.name,n),this.scene.add(n)}else console.log("Hermes - Scene not found:",e.value.name,this.props.scenes)};sceneUpdate=e=>{this.currentScene!==void 0&&(this.currentScene.visible=!1,this.clearLightHelpers());const t=this.scene.getObjectByName(e.value.name);t!==void 0&&(this.currentScene=t,this.currentScene.visible=!0,this.addLightHelpers(this.currentScene)),this.cameraHelpers.forEach((s,n)=>{const r=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",n)!==void 0;s.visible=this.cameraVisibility&&r})};removeScene=e=>{const t=e.value.name;this.scenes.delete(t);const s=this.scene.getObjectByName(t);s&&setTimeout(()=>{Q(s)},100),this.clearLightHelpers()};addCamera=e=>{const t=e.value,s=t.uuid,n=this.props.three.scene?.getObjectByProperty("uuid",t.uuid);if(n!==void 0){const r=n;this.cameras.set(s,r);const a=new w.CameraHelper(r),o=this.currentScene!==void 0&&this.currentScene.getObjectByProperty("uuid",s)!==void 0;a.visible=this.cameraVisibility&&o,this.cameraHelpers.set(s,a),this.helpersContainer.add(a),this.setState({lastUpdate:Date.now()})}};removeCamera=e=>{const s=e.value.uuid,n=this.cameraHelpers.get(s);n!==void 0&&(this.helpersContainer.remove(n),n.dispose()),this.cameras.delete(s),this.setState({lastUpdate:Date.now()})};onMouseMove=e=>{const t=new w.Vector2;this.renderer?.getSize(t);const s=Math.min(e.clientX,t.x),n=Math.min(e.clientY,t.y);this.pointer.x=$.mapLinear(s,0,t.x,-1,1),this.pointer.y=$.mapLinear(n,0,t.y,1,-1);const r=t.x/2,a=t.y/2,o=()=>{s<r?this.pointer.x=$.mapLinear(s,0,r,-1,1):this.pointer.x=$.mapLinear(s,r,t.x,-1,1)},c=()=>{n<a?this.pointer.y=$.mapLinear(n,0,a,1,-1):this.pointer.y=$.mapLinear(n,a,t.y,1,-1)};switch(this.state.mode){case"Quad":o(),c();break;case"Side by Side":o();break;case"Stacked":c(),c();break}if(this.updateCamera(s,n,r,a),this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const l=this.raycaster.intersectObjects(this.currentScene.children);l.length>0&&this.interactionHelper.position.copy(l[0].point)};onClick=e=>{if(this.state.interactionMode==="Orbit"||this.currentScene===void 0)return;const t=new w.Vector2;if(this.renderer.getSize(t),e.clientX>=t.x)return;this.onMouseMove(e);const s=this.raycaster.intersectObjects(this.currentScene.children);s.length>0&&(this.props.three.getObject(s[0].object.uuid),this.interactionHelper.visible=!1,this.setState({interactionMode:"Orbit",lastUpdate:Date.now()}))};onKey=e=>{if(this.selectedItem!==void 0){if(e.ctrlKey){if(this.currentCamera.name==="UI")return;const t=this.controls.get(this.currentCamera.name);e.key==="0"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.selectedItem instanceof w.Mesh||this.selectedItem instanceof w.SkinnedMesh?(this.selectedItem.geometry.computeBoundingBox(),this.cameraControls.fitToBox(this.selectedItem.geometry.boundingBox,!0)):this.cameraControls.fitToSphere(this.selectedItem,!0),this.updateCameraControls(t,!0)):e.key==="1"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,Math.PI*.5,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(t)):e.key==="2"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(0,0,!0),this.cameraControls.moveTo(this.selectedItem.position.x,0,this.selectedItem.position.z,!0),this.updateCameraControls(t)):e.key==="3"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI/2,Math.PI/2,!0),this.cameraControls.moveTo(0,this.selectedItem.position.y,this.selectedItem.position.z,!0),this.updateCameraControls(t)):e.key==="4"?(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo(Math.PI,Math.PI/2,!0),this.cameraControls.moveTo(this.selectedItem.position.x,this.selectedItem.position.y,0,!0),this.updateCameraControls(t)):e.key==="5"&&(e.preventDefault(),this.clearControls(),this.cameraControls=new re(this.currentCamera,this.currentWindow.current),this.cameraControls.rotateTo($.degToRad(45),$.degToRad(45),!0),this.updateCameraControls(t))}else if(this.currentTransform!==void 0)switch(e.key){case"r":this.currentTransform.setMode("rotate");break;case"s":this.currentTransform.setMode("scale");break;case"t":this.currentTransform.setMode("translate");break;case"q":this.currentTransform.setSpace(this.currentTransform.space==="local"?"world":"local");break}}};onSetSelectedItem=e=>{this.selectedItem!==void 0&&this.updateSelectedItemHelper(!1),this.selectedItem=void 0;const t=e.value.uuid;if(this.scenes.forEach(s=>{t.search(s.uuid)>-1&&(this.selectedItem=s.getObjectByProperty("uuid",t))}),this.selectedItem===void 0){console.log(`Hermes - Can't find selected item: ${e.value.uuid}, ${e.value.name}`);return}this.currentTransform!==void 0&&(this.currentTransform.removeEventListener("objectChange",this.onUpdateTransform),W.instance.remove(this.currentTransform.getHelper().name)),this.currentTransform=W.instance.add(e.value.name),this.currentTransform&&(this.currentTransform.attach(this.selectedItem),this.helpersContainer.add(this.currentTransform.getHelper()),this.currentTransform.addEventListener("objectChange",this.onUpdateTransform)),this.updateSelectedItemHelper(!0)};updateSelectedItemHelper(e){if(this.selectedItem!==void 0)if(this.cameraVisibility){if(this.selectedItem.isLight===!0&&!this.lightVisibility){const t=this.lightHelpers.get(this.selectedItem.name);t!==void 0&&(t.visible=e)}}else{const t=this.cameraHelpers.get(this.selectedItem.name);t!==void 0&&(t.visible=e)}}onUpdateTransform=()=>{this.selectedItem!==void 0&&(this.props.three.updateObject(this.selectedItem.uuid,"position",this.selectedItem.position),this.props.three.updateObject(this.selectedItem.uuid,"rotation",{x:this.selectedItem.rotation.x,y:this.selectedItem.rotation.y,z:this.selectedItem.rotation.z}),this.props.three.updateObject(this.selectedItem.uuid,"scale",this.selectedItem.scale),tt.instance.update())};clearLightHelpers=()=>{this.lightHelpers.forEach(e=>{this.helpersContainer.remove(e),e.dispose()}),this.lightHelpers.clear()};addLightHelpers=e=>{e.traverse(t=>{if(t.type.search("Light")>-1){let s;switch(t.type){case"DirectionalLight":s=new w.DirectionalLightHelper(t,100),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"HemisphereLight":s=new w.HemisphereLightHelper(t,250),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"RectAreaLight":s=new Ni.RectAreaLightHelper(t),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"PointLight":s=new w.PointLightHelper(t,100),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break;case"SpotLight":s=new w.SpotLightHelper(t),s.name=`${t.name}Helper`,s.visible=this.lightVisibility,this.lightHelpers.set(t.name,s),this.helpersContainer.add(s);break}}})};createControls(e,t){const s=this.controls.get(e.name);if(s!==void 0&&s.dispose(),this.controls.delete(e.name),e.name==="UI")return;const n=new Fi.OrbitControls(e,t);switch(n.enableDamping=!0,n.dampingFactor=.1,e.name){case"Top":case"Bottom":case"Left":case"Right":case"Front":case"Back":n.enableRotate=!1;break}this.controls.set(e.name,n)}clearCamera(e){const t=this.cameraHelpers.get(e.name);t!==void 0&&(this.helpersContainer.remove(t),t.dispose(),this.cameraHelpers.delete(e.name));const s=this.controls.get(e.name);s!==void 0&&(s.dispose(),this.controls.delete(e.name))}killControls(){this.controls.forEach((e,t)=>{e.dispose();const s=this.cameraHelpers.get(t);s!==void 0&&(this.helpersContainer.remove(s),s.dispose()),this.cameraHelpers.delete(t),this.controls.delete(t)}),this.controls.clear(),this.cameraHelpers.clear()}assignControls(){switch(this.state.mode){case"Single":this.createControls(this.tlCam,this.tlWindow.current);break;case"Side by Side":case"Stacked":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current);break;case"Quad":this.createControls(this.tlCam,this.tlWindow.current),this.createControls(this.trCam,this.trWindow.current),this.createControls(this.blCam,this.blWindow.current),this.createControls(this.brCam,this.brWindow.current);break}}updateCamera=(e,t,s,n)=>{switch(this.state.mode){case"Quad":t<n?e<s?this.currentCamera=this.tlCam:this.currentCamera=this.trCam:e<s?this.currentCamera=this.blCam:this.currentCamera=this.brCam;break;case"Side by Side":e<s?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break;case"Single":this.currentCamera=this.tlCam;break;case"Stacked":t<n?this.currentCamera=this.tlCam:this.currentCamera=this.trCam;break}this.splineEditor.camera=this.currentCamera,this.raycaster.setFromCamera(this.pointer,this.currentCamera),this.currentCamera===this.tlCam?this.currentWindow=this.tlWindow:this.currentCamera===this.trCam?this.currentWindow=this.trWindow:this.currentCamera===this.blCam?this.currentWindow=this.blWindow:this.currentCamera===this.brCam&&(this.currentWindow=this.brWindow),W.instance.updateCamera(this.currentCamera,this.currentWindow.current)};updateCameraControls=(e,t=!1)=>{if(this.selectedItem===void 0)return;cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.cameraControls&&(this.cameraControls.smoothTime=.1);const s=.15;this.cameraControlsStartTime=performance.now(),this.cameraControlsLastTime=this.cameraControlsStartTime,this.selectedItem.getWorldPosition(e.target0);const n=()=>{const r=performance.now(),a=(r-this.cameraControlsLastTime)/1e3;this.cameraControlsLastTime=r,this.cameraControls&&this.cameraControls.update(a),t&&(e.target.lerp(e.target0,s),e.object.position.lerp(e.position0,s),e.object.zoom=Re(e.object.zoom,e.zoom0,s),e.object.updateProjectionMatrix(),e.dispatchEvent({type:"change"})),(r-this.cameraControlsStartTime)/1e3>=.5?(cancelAnimationFrame(this.cameraControlsRafID),this.cameraControlsRafID=-1,this.clearControls()):this.cameraControlsRafID=requestAnimationFrame(n)};n()};clearControls=()=>{this.cameraControls!==void 0&&(this.cameraControls.disconnect(),this.cameraControls.dispose(),this.cameraControls=void 0)};saveExpandedCameraVisibility(){localStorage.setItem(this.expandedCameraVisibility,this.cameraVisibility?"open":"closed")}saveExpandedLightVisibility(){localStorage.setItem(this.expandedLightVisibility,this.lightVisibility?"open":"closed")}saveExpandedGridVisibility(){localStorage.setItem(this.expandedGridVisibility,this.gridVisibility?"open":"closed")}getSceneOverride(e){switch(e){case"Depth":return this.depthMaterial;case"Normals":return this.normalsMaterial;case"Renderer":return null;case"UVs":return this.uvMaterial;case"Wireframe":return this.wireframeMaterial}return null}drawTo(e,t,s,n,r,a){switch(r.name){case"Left":case"Right":this.grid&&(this.grid.rotation.z=Math.PI/2);break;case"Front":case"Back":this.grid&&(this.grid.rotation.x=Math.PI/2);break}this.scene.overrideMaterial=a,this.renderer&&(this.renderer?.setScissor(e,t,s,n),this.renderer?.setViewport(e,t,s,n),this.renderer?.render(this.scene,r)),this.grid&&this.grid.rotation.set(0,0,0)}drawSingle(){const e=this.getSceneOverride(this.tlRender);this.drawTo(0,0,this.width,this.height,this.tlCam,e)}drawDouble=()=>{const e=this.getSceneOverride(this.tlRender),t=this.getSceneOverride(this.trRender),s=Math.floor(this.width/2),n=Math.floor(this.height/2),r=this.renderer instanceof w.WebGPURenderer;if(this.state.mode==="Side by Side")this.drawTo(0,0,s,this.height,this.tlCam,e),this.drawTo(s,0,s,this.height,this.trCam,t);else{const a=this.height-n;r?(this.drawTo(0,0,this.width,n,this.tlCam,e),this.drawTo(0,a,this.width,n,this.trCam,t)):(this.drawTo(0,a,this.width,n,this.tlCam,e),this.drawTo(0,0,this.width,n,this.trCam,t))}};drawQuad=()=>{const e=this.renderer instanceof w.WebGPURenderer,t=this.getSceneOverride(this.tlRender),s=this.getSceneOverride(this.trRender),n=this.getSceneOverride(this.blRender),r=this.getSceneOverride(this.brRender),a=Math.floor(this.width/2),o=Math.floor(this.height/2),c=this.height-o;let l=0,h=e?0:this.height-o;l=0,this.drawTo(l,h,a,o,this.tlCam,t),l=a,this.drawTo(l,h,a,o,this.trCam,s),h=e?c:0,l=0,this.scene.overrideMaterial=n,this.drawTo(l,h,a,o,this.blCam,n),l=a,this.drawTo(l,h,a,o,this.brCam,r)};get appID(){return this.props.three.name}get mode(){return this.state.mode}get three(){return this.props.three}get expandedCameraVisibility(){return`${this.appID}_multiviewCameraVisibility`}get expandedLightVisibility(){return`${this.appID}_multiviewLightVisibility`}get expandedGridVisibility(){return`${this.appID}_multiviewGridVisibility`}}class tt extends b.Component{static instance;matrix=new m.Matrix4;position=new m.Vector3;rotation=new m.Euler;scale=new m.Vector3;open=!1;constructor(e){super(e);const t=localStorage.getItem(this.expandedName),s=t!==null?t==="open":!1;this.open=s,this.saveExpanded(),this.state={lastUpdated:0,expanded:s},this.matrix.elements=e.object.matrix,e.object.uuid.length>0&&(this.position.setFromMatrixPosition(this.matrix),this.rotation.setFromRotationMatrix(this.matrix),this.scale.setFromMatrixScale(this.matrix)),tt.instance=this}update(){if(G.instance){const e=G.instance.selectedItem;if(e===void 0)return;this.position.x=X(e.position.x,3),this.position.y=X(e.position.y,3),this.position.z=X(e.position.z,3),this.rotation.copy(e.rotation),this.scale.x=X(e.scale.x,3),this.scale.y=X(e.scale.y,3),this.scale.z=X(e.scale.z,3),this.setState({lastUpdated:Date.now()})}}render(){return d.jsx(J,{three:this.props.three,title:"Transform",expanded:this.open,items:[{title:"Position",prop:"position",type:"grid3",step:.1,value:this.position,onChange:this.updateTransform},{title:"Rotation",prop:"rotation",type:"euler",value:this.rotation,onChange:this.updateTransform},{title:"Scale",prop:"scale",type:"grid3",value:this.scale,onChange:this.updateTransform},{title:"Visible",prop:"visible",type:"boolean",value:this.props.object.visible,onChange:this.updateTransform}],onToggle:e=>{this.open=e,this.saveExpanded()}},this.state.lastUpdated)}updateTransform=(e,t)=>{const s=e==="rotation"?{x:t._x,y:t._y,z:t._z}:t;this.props.three.updateObject(this.props.object.uuid,e,s);const n=this.props.three.getScene(this.props.object.uuid);if(n){const r=n.getObjectByProperty("uuid",this.props.object.uuid);V(r,e,s)}};saveExpanded(){localStorage.setItem(this.expandedName,this.open?"open":"closed")}get expandedName(){return`${this.props.three.name}_transform`}}function Zt(i){switch(i){case"color":return"Color";case"intensity":return"Intensity";case"decay":return"Decay";case"distance":return"Distance";case"angle":return"Angle";case"penumbra":return"Penumbra";case"groundColor":return"Ground Color";case"width":return"Width";case"height":return"Height"}return i}function xn(i,e){function t(){return`${e.name}_light`}const s=localStorage.getItem(t()),n=s!==null?s==="open":!1;function r(o){localStorage.setItem(t(),o?"open":"closed")}const a=[];if(i.lightInfo!==void 0)for(const o in i.lightInfo){const c=i.lightInfo[o];c!==void 0&&(c.isColor!==void 0?a.push({title:Zt(o),prop:o,type:"color",value:c,onChange:(l,h)=>{const u=new m.Color(h);e.updateObject(i.uuid,l,u);const p=e.getScene(i.uuid);if(p!==null){const g=p.getObjectByProperty("uuid",i.uuid);V(g,l,u)}}}):a.push({title:Zt(o),prop:o,type:typeof c,value:c,step:typeof c=="number"?.01:void 0,onChange:(l,h)=>{e.updateObject(i.uuid,l,h);const u=e.getScene(i.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",i.uuid);V(p,l,h)}}}))}return d.jsx(J,{three:e,title:"Light",items:a,expanded:n,onToggle:o=>{r(o)}})}function On(i){const e=i.object,t=i.three;function s(){return`${t.name}_animation`}const n=localStorage.getItem(s()),r=n!==null?n==="open":!1;function a(p){localStorage.setItem(s(),p?"open":"closed")}const o=[],c=[];let l=0;e.animations.forEach(p=>{l=Math.max(l,p.duration),p.duration>0&&c.push({title:p.name,items:[{title:"Duration",type:"number",value:p.duration,disabled:!0},{title:"Blend Mode",type:"option",disabled:!0,options:[{title:"Normal",value:2500},{title:"Additive",value:2501}]}]})}),o.push({title:"Animations",items:c});let h;const u=t.getScene(e.uuid);if(u!==null){const p=u.getObjectByProperty("uuid",e.uuid);if(p!==void 0){const g=p.mixer;if(g!==void 0){const _=[{title:"Time Scale",type:"range",value:g.timeScale,step:.01,min:-1,max:2,onChange:(E,v)=>{g.timeScale=v,t.updateObject(e.uuid,"mixer.timeScale",v)}}];_.push({title:"Stop All",type:"button",onChange:()=>{g.stopAllAction(),t.requestMethod(e.uuid,"stopAllAction",void 0,"mixer")}}),o.push({title:"Mixer",items:_}),h=new m.SkeletonHelper(p),G.instance?.scene.add(h)}}}return b.useEffect(()=>()=>{h!==void 0&&Q(h)},[]),d.jsx(J,{three:i.three,title:"Animation",items:o,expanded:r,onToggle:p=>{a(p)}})}const gt={name:"",uuid:"",type:"",visible:!1,matrix:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};function Ei(i){const[e,t]=b.useState(gt);b.useEffect(()=>{function a(c){t(c.value)}function o(){t(gt)}return i.three.addEventListener(L.CLEAR_OBJECT,o),i.three.addEventListener(L.SET_SCENE,o),i.three.addEventListener(L.SET_OBJECT,a),()=>{i.three.removeEventListener(L.CLEAR_OBJECT,o),i.three.removeEventListener(L.SET_SCENE,o),i.three.removeEventListener(L.SET_OBJECT,a)}},[]);const s=e.type.toLowerCase(),n=e.animations.length>0||e.mixer!==void 0,r=s.search("mesh")>-1||s.search("line")>-1||s.search("points")>-1;return d.jsx(Ae,{three:i.three,label:"Inspector",button:e.uuid.length>0?d.jsx("button",{className:"remove",onClick:()=>{W.instance.remove(e.name),t(gt)}}):void 0,children:d.jsx("div",{id:"Inspector",className:i.class,children:e.uuid.length>0&&d.jsxs(d.Fragment,{children:[d.jsxs(d.Fragment,{children:[d.jsx(Ze,{type:"string",title:"Name",prop:"name",value:e.name,disabled:!0}),d.jsx(Ze,{type:"string",title:"Type",prop:"type",value:e.type,disabled:!0}),d.jsx(Ze,{type:"string",title:"UUID",prop:"uuid",value:e.uuid,disabled:!0})]}),d.jsxs(d.Fragment,{children:[d.jsx(tt,{object:e,three:i.three}),n?d.jsx(On,{object:e,three:i.three}):null,s.search("camera")>-1?mn(e,i.three):null,s.search("light")>-1?xn(e,i.three):null,r?dn(e,i.three):null]})]})})},"Inspector")}class wn extends b.Component{autoClear=!0;autoClearColor=!0;autoClearDepth=!0;autoClearStencil=!0;outputColorSpace=m.SRGBColorSpace;localClippingEnabled=!1;clearColor=new m.Color(0);clearAlpha=1;toneMapping=m.NoToneMapping;toneMappingExposure=1;type="";constructor(e){super(e);const t=localStorage.getItem(this.expandedName),s=t!==null?t==="open":!1;if(this.state={expanded:s,lastUpdated:Date.now()},this.saveExpanded(s),G.instance){const n=G.instance.renderer;n&&(this.autoClear=n.autoClear,this.autoClearColor=n.autoClearColor,this.autoClearDepth=n.autoClearDepth,this.autoClearStencil=n.autoClearStencil,this.clearAlpha=n.getClearAlpha(),this.toneMapping=n.toneMapping,this.toneMappingExposure=n.toneMappingExposure,n instanceof m.WebGLRenderer&&(this.localClippingEnabled=n.localClippingEnabled,n.getClearColor(this.clearColor)))}this.props.three.addEventListener(L.ADD_RENDERER,this.onAddRenderer)}componentWillUnmount(){this.props.three.removeEventListener(L.ADD_RENDERER,this.onAddRenderer)}onAddRenderer=e=>{const t=e.value;if(this.autoClear=t.autoClear,this.autoClearColor=t.autoClearColor,this.autoClearDepth=t.autoClearDepth,this.autoClearStencil=t.autoClearStencil,this.outputColorSpace=t.outputColorSpace,this.localClippingEnabled=t.localClippingEnabled,this.clearAlpha=t.clearAlpha,this.type=t.type,this.toneMapping=t.toneMapping,this.toneMappingExposure=t.toneMappingExposure,this.clearColor.setStyle(t.clearColor,m.LinearSRGBColorSpace),m.ColorManagement.enabled=t.colorManagement,G.instance){const s=G.instance.renderer;s&&(s.autoClearColor=this.autoClearColor,s.outputColorSpace=this.outputColorSpace,s instanceof m.WebGLRenderer&&(s.localClippingEnabled=this.localClippingEnabled),s.toneMapping=this.toneMapping,s.toneMappingExposure=this.toneMappingExposure,s.setClearColor(t.clearColor,this.clearAlpha))}this.setState({lastUpdated:Date.now()})};render(){const e=()=>{if(G.instance){const t=G.instance.renderer;t&&(t.autoClearColor=this.autoClearColor,t.outputColorSpace=this.outputColorSpace,t instanceof m.WebGLRenderer&&(t.localClippingEnabled=this.localClippingEnabled),t.toneMapping=this.toneMapping,t.toneMappingExposure=this.toneMappingExposure,t.setClearColor(this.clearColor.getStyle(),this.clearAlpha),this.props.three.updateRenderer({autoClear:this.autoClear,autoClearColor:this.autoClearColor,autoClearDepth:this.autoClearDepth,autoClearStencil:this.autoClearStencil,outputColorSpace:this.outputColorSpace,localClippingEnabled:this.localClippingEnabled,clearAlpha:this.clearAlpha,clearColor:this.clearColor.getStyle(),colorManagement:m.ColorManagement.enabled,toneMapping:this.toneMapping,toneMappingExposure:this.toneMappingExposure}))}};return d.jsx(J,{three:this.props.three,title:"Renderer",expanded:this.state.expanded,items:[{type:"boolean",title:"Auto Clear",value:this.autoClear,onChange:(t,s)=>{this.autoClear=s}},{type:"boolean",title:"Auto Clear Color",value:this.autoClearColor,onChange:(t,s)=>{this.autoClearColor=s,e()}},{type:"boolean",title:"Auto Clear Depth",value:this.autoClearDepth,onChange:(t,s)=>{this.autoClearDepth=s,e()}},{type:"boolean",title:"Auto Clear Stencil",value:this.autoClearStencil,onChange:(t,s)=>{this.autoClearStencil=s,e()}},{type:"boolean",title:"Local Clipping",value:this.localClippingEnabled,onChange:(t,s)=>{this.localClippingEnabled=s,e()}},{type:"color",title:"Clear Color",value:`#${this.clearColor.getHexString()}`,onChange:(t,s)=>{this.clearColor.setStyle(s),e()}},{type:"range",title:"Clear Alpha",min:0,max:1,step:.01,value:this.clearAlpha,onChange:(t,s)=>{this.clearAlpha=s,e()}},{type:"boolean",title:"Color Management",value:m.ColorManagement.enabled,onChange:(t,s)=>{m.ColorManagement.enabled=s,e()}},{type:"option",title:"Color Space",value:this.outputColorSpace,options:[{title:"No Color Space",value:m.NoColorSpace},{title:"SRB Color Space",value:m.SRGBColorSpace},{title:"Linear SRB Color Space",value:m.LinearSRGBColorSpace}],onChange:(t,s)=>{this.outputColorSpace=s,e()}},{type:"option",title:"Tone Mapping",value:this.toneMapping,options:[{title:"None ",value:m.NoToneMapping},{title:"Linear ",value:m.LinearToneMapping},{title:"Reinhard",value:m.ReinhardToneMapping},{title:"Cineon ",value:m.CineonToneMapping},{title:"ACES Filmic",value:m.ACESFilmicToneMapping},{title:"AgX",value:m.AgXToneMapping},{title:"Neutral",value:m.NeutralToneMapping},{title:"Custom",value:m.CustomToneMapping}],onChange:(t,s)=>{this.toneMapping=s,e()}},{type:"range",title:"Tone Mapping Exposure",value:this.toneMappingExposure,min:0,max:2,step:.01,onChange:(t,s)=>{this.toneMappingExposure=s,e()}},{type:"string",title:"Type",value:this.type,disabled:!0},{type:"button",title:"Resize Scenes from Source",onChange:()=>{this.props.three.requestSize()}}],onToggle:t=>{this.setState({expanded:t}),this.saveExpanded(t)}},"renderer")}saveExpanded(e){localStorage.setItem(this.expandedName,e?"open":"closed")}get expandedName(){return`${this.props.three.name}_renderer`}}function Si(i){const[e]=b.useState([]),[t]=b.useState([]),[s,n]=b.useState(0),r=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid)return;e.push(h),t.push(d.jsx(Ae,{three:i.three,label:`Scene: ${h.name}`,scene:h,open:!1,visible:!1,onRefresh:()=>{i.three.refreshScene(h.name)},children:d.jsx($e,{child:h,scene:h,three:i.three})},h.name)),n(Date.now())},a=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid){e[u]=h,t[u]=d.jsx(Ae,{three:i.three,label:`Scene: ${h.name}`,scene:h,open:t[u].props.open,visible:t[u].props.visible,onRefresh:()=>{i.three.refreshScene(h.name)},children:d.jsx($e,{child:h,scene:h,three:i.three})},h.name),n(Date.now());return}},o=l=>{const h=l.value;for(let u=0;u<e.length;u++)if(h.uuid===e[u].uuid){e.splice(u,1),t.splice(u,1),n(Date.now());return}},c=l=>{const h=l.value.name;for(let u=0;u<e.length;u++){const p=e[u],g=p.name===h;t[u]=d.jsx(Ae,{three:i.three,label:`Scene: ${p.name}`,scene:p,open:g,visible:g,onRefresh:()=>{i.three.refreshScene(p.name)},children:d.jsx($e,{child:p,scene:p,three:i.three})},p.name)}n(Date.now())};return b.useEffect(()=>(i.three.addEventListener(L.ADD_SCENE,r),i.three.addEventListener(L.SET_SCENE,c),i.three.addEventListener(L.REFRESH_SCENE,a),i.three.addEventListener(L.REMOVE_SCENE,o),()=>{i.three.removeEventListener(L.ADD_SCENE,r),i.three.removeEventListener(L.SET_SCENE,c),i.three.removeEventListener(L.REFRESH_SCENE,a),i.three.removeEventListener(L.REMOVE_SCENE,o)}),[]),d.jsxs("div",{id:"SidePanel",children:[d.jsx("div",{className:"scenes",children:t},s),d.jsx(Ei,{three:i.three}),d.jsx(wn,{three:i.three}),d.jsx(k,{three:i.three})]})}const wt=b.forwardRef((i,e)=>d.jsxs("div",{className:"editor",ref:e,style:i.style,children:[i.header&&d.jsx("div",{className:"header",children:i.header}),i.children,i.footer&&d.jsx("div",{className:"footer",children:i.footer})]}));wt.displayName="Editor";function Tn(i){return d.jsxs(wt,{children:[d.jsx(G,{three:i.three,scenes:i.scenes,onSceneAdd:i.onSceneAdd,onSceneResize:i.onSceneResize,onSceneUpdate:i.onSceneUpdate}),d.jsx(Si,{three:i.three})]})}function Mn(i){const{app:e,renderEditor:t,onLoad:s,renderLoading:n=null,children:r}=i,[a,o]=b.useState(!1);if(b.useEffect(()=>{e.detectSettings().then(()=>{s?s(e).then(()=>o(!0)):o(!0)})},[]),!a)return d.jsx(d.Fragment,{children:n});if(e.editor&&t){const c=e.components.get("three");return d.jsx(d.Fragment,{children:t(c)})}return d.jsx(d.Fragment,{children:r?.(e)})}const An=`#include <common>
116
116
  #include <batching_pars_vertex>
117
117
  #include <uv_pars_vertex>
118
118
  #include <color_pars_vertex>
@@ -152,4 +152,4 @@ void main() {
152
152
  #include <clipping_planes_fragment>
153
153
  if (opacity < 0.015) discard;
154
154
  gl_FragColor = vec4(vec3(vUv, 0.0), opacity);
155
- }`;class Pn extends m.ShaderMaterial{constructor(){super({defines:{USE_UV:""},uniforms:{opacity:{value:1}},vertexShader:An,fragmentShader:Rn,transparent:!0})}}exports.Accordion=Ae;exports.Application=Ns;exports.BaseRemote=St;exports.ChildObject=Ot;exports.ContainerObject=$e;exports.DepthNodeMaterial=yi;exports.Draggable=hi;exports.DraggableItem=ci;exports.Dropdown=di;exports.DropdownItem=ui;exports.Editor=wt;exports.ElementProxy=Us;exports.ElementProxyReceiver=oi;exports.ExportTexture=ae;exports.HermesApp=Mn;exports.ImageSequenceCapturer=$i;exports.InfiniteGridHelper=gi;exports.InfiniteGridHelperGPU=_i;exports.InfiniteGridMaterial=fi;exports.InfiniteGridNodeMaterial=vi;exports.Inspector=Ei;exports.MultiView=G;exports.NavButton=xt;exports.ProxyManager=ks;exports.RemoteTheatre=zs;exports.RemoteThree=Ys;exports.SidePanel=Si;exports.Spline=Ke;exports.SplineEditor=bi;exports.ThreeEditor=xi;exports.Transform=W;exports.UVMaterial=Pn;exports.UVNodeMaterial=Ci;exports.WebworkerEventHandlers=Is;exports.anchorGeometry=ri;exports.anchorGeometryTL=ps;exports.animateObjectMaterial=cs;exports.animateObjectTransform=os;exports.applyObjectMaterial=ni;exports.capitalize=He;exports.clamp=de;exports.clearComposerGroups=xs;exports.colorToHex=vt;exports.copyToClipboard=Xt;exports.createMask=vs;exports.cubicBezier=ss;exports.customizeTheatreElements=as;exports.damp=Xi;exports.defaultTheatreCallback=Hi;exports.detectMaxFrameRate=ei;exports.detectSettings=ti;exports.dispose=Q;exports.disposeMaterial=bt;exports.disposeTexture=_t;exports.distance=Ki;exports.generateCubemap=Os;exports.getAngle=Qi;exports.getObjectMaterialObject=si;exports.getObjectMaterialProps=ii;exports.hierarchyUUID=Me;exports.inspectComposer=Ss;exports.inspectComposerPass=ai;exports.isColor=Qt;exports.map=Zi;exports.mix=Re;exports.noop=ze;exports.normalize=Xe;exports.orthoCamera=hs;exports.parseModelLite=ds;exports.randomID=Y;exports.renderToTexture=us;exports.resetThreeObjects=Ne;exports.rgbaToHex=ns;exports.roundTo=X;exports.setMaterialBlendAdd=Cs;exports.setMaterialBlendMultiply=bs;exports.setMaterialBlendNormal=ys;exports.setMaterialBlendScreen=Es;exports.supportsOffscreenCanvas=gs;exports.triangle=Je;exports.updateCameraOrtho=ms;exports.updateCameraOrtho16x9=fs;exports.useMask=_s;exports.useStudio=rs;
155
+ }`;class Pn extends m.ShaderMaterial{constructor(){super({defines:{USE_UV:""},uniforms:{opacity:{value:1}},vertexShader:An,fragmentShader:Rn,transparent:!0})}}exports.Accordion=Ae;exports.Application=ks;exports.BaseRemote=St;exports.ChildObject=Ot;exports.ContainerObject=$e;exports.DepthNodeMaterial=yi;exports.Draggable=hi;exports.DraggableItem=ci;exports.Dropdown=di;exports.DropdownItem=ui;exports.Editor=wt;exports.ElementProxy=Ls;exports.ElementProxyReceiver=oi;exports.ExportTexture=ae;exports.HermesApp=Mn;exports.ImageSequenceCapturer=qi;exports.InfiniteGridHelper=gi;exports.InfiniteGridHelperGPU=_i;exports.InfiniteGridMaterial=fi;exports.InfiniteGridNodeMaterial=vi;exports.Inspector=Ei;exports.MultiView=G;exports.NavButton=xt;exports.ProxyManager=Us;exports.RemoteTheatre=js;exports.RemoteThree=Ws;exports.SidePanel=Si;exports.Spline=Ke;exports.SplineEditor=bi;exports.ThreeEditor=Tn;exports.Transform=W;exports.UVMaterial=Pn;exports.UVNodeMaterial=Ci;exports.WebworkerEventHandlers=Ds;exports.anchorGeometry=ri;exports.anchorGeometryTL=us;exports.animateObjectMaterial=ls;exports.animateObjectTransform=as;exports.applyObjectMaterial=ni;exports.capitalize=He;exports.clamp=de;exports.clearComposerGroups=Ss;exports.colorToHex=vt;exports.copyToClipboard=Xt;exports.createMask=gs;exports.cubicBezier=is;exports.customizeTheatreElements=rs;exports.damp=Ki;exports.defaultTheatreCallback=zi;exports.detectMaxFrameRate=ei;exports.detectSettings=ti;exports.dispose=Q;exports.disposeMaterial=bt;exports.disposeTexture=_t;exports.distance=Zi;exports.generateCubemap=xs;exports.getAngle=Xi;exports.getObjectMaterialObject=si;exports.getObjectMaterialProps=ii;exports.hierarchyUUID=Me;exports.inspectComposer=Es;exports.inspectComposerPass=ai;exports.isColor=Qt;exports.map=$i;exports.mix=Re;exports.noop=ze;exports.normalize=Xe;exports.orthoCamera=cs;exports.parseModelLite=hs;exports.randomID=Y;exports.renderToTexture=ds;exports.resetThreeObjects=Ne;exports.rgbaToHex=ss;exports.roundTo=X;exports.setMaterialBlendAdd=ys;exports.setMaterialBlendMultiply=Cs;exports.setMaterialBlendNormal=_s;exports.setMaterialBlendScreen=bs;exports.supportsOffscreenCanvas=fs;exports.triangle=Je;exports.updateCameraOrtho=ps;exports.updateCameraOrtho16x9=ms;exports.useMask=vs;exports.useStudio=ns;