three-live 1.2.1 → 1.2.2

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.
Files changed (44) hide show
  1. package/README.md +6 -1
  2. package/dist/index.d.ts +65 -2
  3. package/dist/three-author-engine.js +66 -41
  4. package/dist/three-author.cjs +63 -39
  5. package/dist/three-author.d.ts +65 -2
  6. package/dist/three-author.js +63 -39
  7. package/dist/three-convert.cjs +61 -37
  8. package/dist/three-convert.d.ts +65 -2
  9. package/dist/three-convert.js +61 -37
  10. package/dist/three-live-animation.cjs +7 -7
  11. package/dist/three-live-animation.d.ts +65 -2
  12. package/dist/three-live-animation.js +7 -7
  13. package/dist/three-live-animation.min.js +7 -7
  14. package/dist/three-live-cad.cjs +18 -0
  15. package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +65 -2
  16. package/dist/three-live-cad.js +18 -0
  17. package/dist/three-live-cad.min.js +18 -0
  18. package/dist/three-live-element.cjs +29 -5
  19. package/dist/three-live-element.d.ts +65 -2
  20. package/dist/three-live-element.js +29 -5
  21. package/dist/three-live-full.cjs +159 -56
  22. package/dist/three-live-full.js +159 -56
  23. package/dist/three-live-full.min.js +159 -56
  24. package/dist/three-live-studio.cjs +120 -0
  25. package/dist/three-live-studio.d.ts +509 -0
  26. package/dist/three-live-studio.js +120 -0
  27. package/dist/three-live-studio.min.js +120 -0
  28. package/dist/three-live-viewer.cjs +29 -5
  29. package/dist/three-live-viewer.d.ts +65 -2
  30. package/dist/three-live-viewer.js +29 -5
  31. package/dist/three-live-viewer.min.js +29 -5
  32. package/dist/three-live.cjs +66 -42
  33. package/dist/three-live.js +66 -42
  34. package/dist/three-live.min.js +66 -42
  35. package/dist/three-view.cjs +29 -5
  36. package/dist/three-view.d.ts +65 -2
  37. package/dist/three-view.js +29 -5
  38. package/dist/three-xr.cjs +65 -41
  39. package/dist/three-xr.d.ts +65 -2
  40. package/dist/three-xr.js +65 -41
  41. package/package.json +10 -5
  42. package/dist/three-live-extras.cjs +0 -42
  43. package/dist/three-live-extras.js +0 -42
  44. package/dist/three-live-extras.min.js +0 -42
@@ -14,7 +14,8 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- "use strict";var ThreeEngine=(()=>{var Wt=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var hr=(t,e)=>{for(var n in e)Wt(t,n,{get:e[n],enumerable:!0})},mr=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ur(e))!lr.call(t,i)&&i!==n&&Wt(t,i,{get:()=>e[i],enumerable:!(r=cr(e,i))||r.enumerable});return t};var dr=t=>mr(Wt({},"__esModule",{value:!0}),t);var Di={};hr(Di,{AmbientLight:()=>Ze,BoxGeometry:()=>je,BufferAttribute:()=>G,BufferGeometry:()=>ue,Camera:()=>Qe,CapsuleGeometry:()=>Vt,CircleGeometry:()=>Xt,Clock:()=>Nt,Color:()=>me,ConeGeometry:()=>St,CylinderGeometry:()=>Re,DirectionalLight:()=>Lt,DodecahedronGeometry:()=>zt,Euler:()=>$e,Float32BufferAttribute:()=>vt,Group:()=>Pt,HemisphereLight:()=>tt,IcosahedronGeometry:()=>Ft,Light:()=>Me,Material:()=>de,MathUtils:()=>Xn,Matrix3:()=>xt,Matrix4:()=>be,Mesh:()=>ke,MeshBasicMaterial:()=>_t,MeshLambertMaterial:()=>Ct,MeshPhongMaterial:()=>Dt,MeshPhysicalMaterial:()=>It,MeshStandardMaterial:()=>_e,Object3D:()=>oe,OctahedronGeometry:()=>Ot,PerspectiveCamera:()=>Fe,PlaneGeometry:()=>Et,PointLight:()=>Je,PolyhedronFallbackGeometry:()=>De,Quaternion:()=>Ye,RawShaderMaterial:()=>Qn,RectAreaLight:()=>er,RingGeometry:()=>Ht,Scene:()=>Ce,SceneQuotaValidator:()=>fe,ShaderMaterial:()=>et,SphereGeometry:()=>qe,SpotLight:()=>Gt,THREE:()=>nt,TetrahedronGeometry:()=>Bt,Texture:()=>Ke,TextureLoader:()=>At,TorusGeometry:()=>Rt,TorusKnotGeometry:()=>Mt,Uint16BufferAttribute:()=>Tt,Uint32BufferAttribute:()=>wt,Vector2:()=>yt,Vector3:()=>J,Vector4:()=>gt,WebGLRenderer:()=>Ut,authorScriptRunner:()=>Zn,buildSandboxWorkerSource:()=>hn,clearAuthorWarnings:()=>dn,default:()=>Ci,exportSceneToCanvas3D:()=>cn,exportSceneToGLB:()=>un,exportSceneToUSDZ:()=>Gn,generateUSDZ:()=>Jt,getAllowClientScripts:()=>Yn,getAuthorWarnings:()=>Jn,getSandboxEngineSrc:()=>ln,getSandboxIframeSrc:()=>$n,glbToUSDZ:()=>dt,isAllowedSandboxEngineUrl:()=>Ae,noopProxy:()=>Ne,sceneToCanvas3D:()=>Le,sceneToGLB:()=>He,sceneToUSDZ:()=>Ue,setAllowClientScripts:()=>xi,setSandboxEngineSrc:()=>pi,setSandboxIframeSrc:()=>yi,threeAuthorPlugin:()=>We,threeMicroPlugin:()=>_i,toTrustedWorkerScriptURL:()=>Wn,validateSandboxWorkerMessage:()=>mn,warnUnsupported:()=>se});function ot(t,e,n){let r=[],i=new Map,o=[],c=[],h=[],u=new Map,s=y=>{let w=i.get(y);return w===void 0&&(w=r.length,r.push({op:y}),i.set(y,w)),w},a=y=>{let w=u.get(y);return w===void 0&&(w=h.length,h.push({id:y}),u.set(y,w)),w},m=(y,w={})=>o.push({declaration:s(y),...w})-1,l=(y,w,b)=>c.push({id:y,type:w,value:b})-1,f=y=>({node:y,socket:"value"}),d=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(d&&typeof d=="object"){let y=Array.isArray(d.graphs)?d.graphs[d.graph??0]:d;if(y&&Array.isArray(y.nodes)){let w=Array.isArray(y.declarations)?y.declarations:[];for(let b of w)b?.op&&s(b.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let b of y.events||[])b?.id&&a(b.id);for(let b of y.nodes){if(!b||typeof b!="object")continue;let R=b.op||(typeof b.declaration=="number"?w[b.declaration]?.op:"");o.push(R?{...b,declaration:s(R)}:{...b})}}}let S=(y,w,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,w)}/${b}`:b==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${b}`,A=new Map;t.forEach((y,w)=>{typeof y?.name=="string"&&!A.has(y.name)&&A.set(y.name,w)});let M=(y,w)=>typeof y.target=="string"&&A.has(y.target)?A.get(y.target):typeof y.targetNode=="number"?y.targetNode:w,P=y=>{let w=t[y];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<t.length;y++){let w=t[y],b=w?.extras?.interactivity;if(!b||typeof b!="object")continue;let R=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,p=v=>{let _=Array.isArray(v)?v:[v],D=[];for(let T=0;T<_.length;T++){let x=_[T];if(!x||typeof x!="object")continue;let L=x.action||"interpolate",I=typeof x.duration=="number"?x.duration:.35;if(L==="toggleTransform"){let H=x.property==="rotation"||x.property==="scale"?x.property:"translation",k=H==="rotation"?w.rotation||[0,0,0,1]:H==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],U=`/nodes/${y}/${H}`,N=l(`__toggle_${y}_${T}`,"bool",!1),C=m("variable/get",{configuration:{variable:N}}),O=m("math/not",{values:{a:f(C)}}),F=m("variable/set",{configuration:{variable:N},values:{value:f(O)}}),V=m("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.to)?x.to:k},duration:{value:I}}}),z=m("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.from)?x.from:k},duration:{value:I}}});o[F].flows={out:{node:m("flow/branch",{values:{condition:f(C)},flows:{true:{node:V},false:{node:z}}})}},D.push(F)}else if(L==="interpolate"){let H=x.to??x.value;if(H===void 0)continue;let k={value:{value:H},duration:{value:I}};x.from!==void 0&&(k.from={value:x.from}),D.push(m("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(M(x,y),P(M(x,y)),x.property)},values:k}))}else if(L==="setProperty"){if(x.value===void 0)continue;D.push(m("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(M(x,y),P(M(x,y)),x.property)},values:{value:{value:x.value}}}))}else if(L==="toggleVisibility"){let H=M(x,y),k=l(`__vis_${H}_${T}`,"bool",!0),U=m("variable/get",{configuration:{variable:k}}),N=m("math/not",{values:{a:f(U)}}),C=m("variable/set",{configuration:{variable:k},values:{value:f(N)}});o[C].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${H}/extensions/KHR_node_visibility/visible`},values:{value:f(U)}})}},D.push(C)}else if(L==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let H=typeof x.duration=="number"?x.duration:.25,k=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,U=l(`__color_idx_${y}_${T}`,"int",0),N=m("variable/get",{configuration:{variable:U}}),C=m("math/add",{values:{a:f(N),b:{value:1}}}),O=m("math/rem",{values:{a:f(C),b:{value:x.colors.length}}}),F=m("variable/set",{configuration:{variable:U},values:{value:f(O)}}),V={};for(let z=0;z<x.colors.length;z++){let X=x.colors[z],Y=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];V[String(z)]={node:H>0?m("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Y},duration:{value:H}}}):m("pointer/set",{configuration:{pointer:k},values:{value:{value:Y}}})}}o[F].flows={out:{node:m("flow/switch",{values:{selection:f(N)},flows:V})}},D.push(F)}else if(L==="playAnimation")D.push(m("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(L==="stopAnimation")D.push(m("animation/stop"));else if(L==="sendEvent"){let H={};for(let[k,U]of Object.entries(x.values||{}))H[k]={value:U};D.push(m("event/send",{configuration:{event:a(String(x.event??x.id??"custom"))},values:H}))}}if(!D.length)return null;if(D.length===1)return D[0];let g={};return D.forEach((T,x)=>{g[String(x)]={node:T}}),m("flow/sequence",{flows:g})},E=(v,_,D)=>{let g=p(_);g!==null&&m(v,{...D?{configuration:D}:{},flows:{out:{node:g}}})};if(b.onSelect&&E("pointer/onSelect",b.onSelect,{nodeIndex:y}),b.onHoverIn&&E("pointer/onHoverIn",b.onHoverIn,{nodeIndex:y}),b.onHoverOut&&E("pointer/onHoverOut",b.onHoverOut,{nodeIndex:y}),b.onStart&&E("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[v,_]of Object.entries(b.onReceive))E("event/receive",_,{event:a(v)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:c,events:h}],graph:0}:null}var fn='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',pn="Security Error: client-side scripts require allow-client-scripts opt-in.";var st="__THREE_LIVE_REGISTRY__";function Q(){let t=typeof globalThis<"u"?globalThis:{};if(!t[st]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,st,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[st]=e}}return t[st]}var ee=Q().plugins;function bn(t){let e=Q().plugins;e.some(n=>n.name===t.name)||e.push(t)}function yn(){return Q().plugins}function Z(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function at(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let c=1/(r-i);return t[10]=(i+r)*c,t[14]=2*i*r*c,t}function Pe(t,e,n,r){let[i,o,c]=e,[h,u,s]=r,[a,m,l]=n,f=i-a,d=o-m,S=c-l,A=Math.hypot(f,d,S);A<=1e-5?(f=0,d=0,S=1):(f/=A,d/=A,S/=A);let M=u*S-s*d,P=s*f-h*S,y=h*d-u*f;A=Math.hypot(M,P,y),A<=1e-5?(M=0,P=0,y=0):(M/=A,P/=A,y/=A);let w=d*y-S*P,b=S*M-f*y,R=f*P-d*M;return A=Math.hypot(w,b,R),A<=1e-5?(w=0,b=0,R=0):(w/=A,b/=A,R/=A),t[0]=M,t[1]=w,t[2]=f,t[3]=0,t[4]=P,t[5]=b,t[6]=d,t[7]=0,t[8]=y,t[9]=R,t[10]=S,t[11]=0,t[12]=-(M*i+P*o+y*c),t[13]=-(w*i+b*o+R*c),t[14]=-(f*i+d*o+S*c),t[15]=1,t}function ie(t,e,n){let r=e[0],i=e[1],o=e[2],c=e[3],h=e[4],u=e[5],s=e[6],a=e[7],m=e[8],l=e[9],f=e[10],d=e[11],S=e[12],A=e[13],M=e[14],P=e[15],y=n[0],w=n[1],b=n[2],R=n[3];return t[0]=y*r+w*h+b*m+R*S,t[1]=y*i+w*u+b*l+R*A,t[2]=y*o+w*s+b*f+R*M,t[3]=y*c+w*a+b*d+R*P,y=n[4],w=n[5],b=n[6],R=n[7],t[4]=y*r+w*h+b*m+R*S,t[5]=y*i+w*u+b*l+R*A,t[6]=y*o+w*s+b*f+R*M,t[7]=y*c+w*a+b*d+R*P,y=n[8],w=n[9],b=n[10],R=n[11],t[8]=y*r+w*h+b*m+R*S,t[9]=y*i+w*u+b*l+R*A,t[10]=y*o+w*s+b*f+R*M,t[11]=y*c+w*a+b*d+R*P,y=n[12],w=n[13],b=n[14],R=n[15],t[12]=y*r+w*h+b*m+R*S,t[13]=y*i+w*u+b*l+R*A,t[14]=y*o+w*s+b*f+R*M,t[15]=y*c+w*a+b*d+R*P,t}function ct(t,e,n,r){let i=e[0],o=e[1],c=e[2],h=e[3],u=i+i,s=o+o,a=c+c,m=i*u,l=i*s,f=i*a,d=o*s,S=o*a,A=c*a,M=h*u,P=h*s,y=h*a,w=r[0],b=r[1],R=r[2];return t[0]=(1-(d+A))*w,t[1]=(l+y)*w,t[2]=(f-P)*w,t[3]=0,t[4]=(l-y)*b,t[5]=(1-(m+A))*b,t[6]=(S+M)*b,t[7]=0,t[8]=(f+P)*R,t[9]=(S-M)*R,t[10]=(1-(m+d))*R,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ce(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],c=e[5],h=e[6],u=e[8],s=e[9],a=e[10],m=a*c-h*s,l=-a*o+h*u,f=s*o-c*u,d=n*m+r*l+i*f;return d&&(d=1/d,t[0]=m*d,t[1]=(-a*r+i*s)*d,t[2]=(h*r-i*c)*d,t[3]=l*d,t[4]=(a*n-i*u)*d,t[5]=(-h*n+i*o)*d,t[6]=f*d,t[7]=(-s*n+r*u)*d,t[8]=(c*n-r*o)*d),t}function gn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],c=e[4],h=e[5],u=e[6],s=e[7],a=e[8],m=e[9],l=e[10],f=e[11],d=e[12],S=e[13],A=e[14],M=e[15],P=n*h-r*c,y=n*u-i*c,w=n*s-o*c,b=r*u-i*h,R=r*s-o*h,p=i*s-o*u,E=a*S-m*d,v=a*A-l*d,_=a*M-f*d,D=m*A-l*S,g=m*M-f*S,T=l*M-f*A,x=P*T-y*g+w*D+b*_-R*v+p*E;return x?(x=1/x,t[0]=(h*T-u*g+s*D)*x,t[1]=(i*g-r*T-o*D)*x,t[2]=(S*p-A*R+M*b)*x,t[3]=(l*R-m*p-f*b)*x,t[4]=(u*_-c*T-s*v)*x,t[5]=(n*T-i*_+o*v)*x,t[6]=(A*w-d*p-M*y)*x,t[7]=(a*p-l*w+f*y)*x,t[8]=(c*g-h*_+s*E)*x,t[9]=(r*_-n*g-o*E)*x,t[10]=(d*R-S*w+M*P)*x,t[11]=(m*w-a*R-f*P)*x,t[12]=(h*v-c*D-u*E)*x,t[13]=(n*D-r*v+i*E)*x,t[14]=(S*y-d*b-A*P)*x,t[15]=(a*b-m*y+l*P)*x,t):null}function $t(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],c=i[1]*e+i[5]*n+i[9]*r+i[13],h=i[2]*e+i[6]*n+i[10]*r+i[14],u=i[3]*e+i[7]*n+i[11]*r+i[15],s=u!==0?1/u:1;t[0]=o*s,t[1]=c*s,t[2]=h*s}function xn(t,e,n,r,i,o,c,h,u,s,a,m,l,f,d,S,A=0){let M=s-c,P=a-h,y=m-u,w=l-c,b=f-h,R=d-u,p=i*R-o*b,E=o*w-r*R,v=r*b-i*w,_=M*p+P*E+y*v;if(_>-1e-7&&_<1e-7)return!1;let D=1/_,g=t-c,T=e-h,x=n-u,L=D*(g*p+T*E+x*v);if(L<-A||L>1+A)return!1;let I=T*y-x*P,H=x*M-g*y,k=g*P-T*M,U=D*(r*I+i*H+o*k);if(U<-A||L+U>1+A)return!1;let N=D*(w*I+b*H+R*k);if(N>1e-4&&N<S.distance){S.distance=N,S.point=[t+r*N,e+i*N,n+o*N];let C=P*R-y*b,O=y*w-M*R,F=M*b-P*w,V=Math.hypot(C,O,F)||1;return S.normal=[C/V,O/V,F/V],!0}return!1}function ut(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let a=0;a<n;a++)r.push(Z());if(n===0)return r;let i=new Set;for(let a of t.nodes)if(Array.isArray(a.children))for(let m of a.children)i.add(m);let o=new Set,c=128,h=(a,m,l=0)=>{if(l>c||a<0||a>=n||o.has(a))return;o.add(a);let f=t.nodes[a];if(!f)return;let d=Z();if(e&&e[a])d.set(e[a]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let A=f.translation||[0,0,0],M=f.rotation||[0,0,0,1],P=f.scale||[1,1,1];ct(d,M,A,P)}let S=r[a];if(m?ie(S,m,d):S.set(d),Array.isArray(f.children))for(let A of f.children)typeof A=="number"&&h(A,S,l+1)},u=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))u.push(...s.nodes);else for(let a=0;a<n;a++)i.has(a)||u.push(a);for(let a of u)h(a,null);for(let a=0;a<n;a++)!i.has(a)&&!u.includes(a)&&h(a,null);return r}function fr(t){return new TextDecoder().decode(t)}var En=Q().decoders;function pr(t,e){En.set(t.toLowerCase(),e)}function Be(t){return En.get(t.toLowerCase())}function Sn(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let l=n.getUint8(0);throw l===123||l===32||l===10||l===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),c=12,h=null,u=null;for(;c+8<=o&&c+8<=e.byteLength;){let l=n.getUint32(c,!0),f=n.getUint32(c+4,!0),d=c+8;if(d+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+l} bytes, buffer has ${e.byteLength}`);if(f===1313821514){let S=new Uint8Array(e,d,l),A=fr(S);h=JSON.parse(A,(M,P)=>M==="__proto__"||M==="constructor"||M==="prototype"?void 0:P)}else f===5130562&&(u=e.slice(d,d+l));c=d+l}if(!h)throw new Error("Missing JSON chunk in GLB");let s=h.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!Be("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!Be("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!Be("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),m={gltf:h,bin:a,animations:[]};for(let l of ee)l.onParseGLB?.(m);return m}function br(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function Ve(t){if(br(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Sn(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Rn=`#version 300 es
17
+ "use strict";var ThreeEngine=(()=>{var zn=Object.defineProperty;var mi=Object.getOwnPropertyDescriptor;var fi=Object.getOwnPropertyNames;var di=Object.prototype.hasOwnProperty;var pi=(t,e)=>{for(var n in e)zn(t,n,{get:e[n],enumerable:!0})},bi=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fi(e))!di.call(t,i)&&i!==n&&zn(t,i,{get:()=>e[i],enumerable:!(r=mi(e,i))||r.enumerable});return t};var yi=t=>bi(zn({},"__esModule",{value:!0}),t);var Vo={};pi(Vo,{AmbientLight:()=>Yt,BoxGeometry:()=>Ht,BufferAttribute:()=>pe,BufferGeometry:()=>Xe,Camera:()=>Kt,CapsuleGeometry:()=>Ln,CircleGeometry:()=>Fn,Clock:()=>_n,Color:()=>$e,ConeGeometry:()=>yn,CylinderGeometry:()=>lt,DirectionalLight:()=>En,DodecahedronGeometry:()=>kn,Euler:()=>Bt,Float32BufferAttribute:()=>fn,Group:()=>An,HemisphereLight:()=>Zt,IcosahedronGeometry:()=>In,InstancedMesh:()=>kt,Light:()=>mt,MAX_INSTANCES_PER_MESH:()=>$t,Material:()=>We,MathUtils:()=>Zr,Matrix3:()=>mn,Matrix4:()=>Je,Mesh:()=>yt,MeshBasicMaterial:()=>Tn,MeshLambertMaterial:()=>Mn,MeshPhongMaterial:()=>wn,MeshPhysicalMaterial:()=>Sn,MeshStandardMaterial:()=>ht,Object3D:()=>Ge,OctahedronGeometry:()=>Dn,PerspectiveCamera:()=>Pt,PlaneGeometry:()=>bn,PointLight:()=>jt,PolyhedronFallbackGeometry:()=>xt,Quaternion:()=>Gt,RawShaderMaterial:()=>ai,RectAreaLight:()=>ci,RingGeometry:()=>Nn,Scene:()=>gt,SceneQuotaValidator:()=>qe,ShaderMaterial:()=>qt,SphereGeometry:()=>Xt,SpotLight:()=>On,THREE:()=>et,TetrahedronGeometry:()=>Pn,Texture:()=>Wt,TextureLoader:()=>vn,TorusGeometry:()=>gn,TorusKnotGeometry:()=>xn,Uint16BufferAttribute:()=>dn,Uint32BufferAttribute:()=>pn,Vector2:()=>ln,Vector3:()=>Ce,Vector4:()=>hn,WebGLRenderer:()=>Rn,authorScriptRunner:()=>oi,buildSandboxWorkerSource:()=>sr,clearAuthorWarnings:()=>cr,default:()=>zo,exportSceneToCanvas3D:()=>rr,exportSceneToGLB:()=>ir,exportSceneToUSDZ:()=>Qr,generateUSDZ:()=>Yn,getAllowClientScripts:()=>ti,getAuthorWarnings:()=>si,getSandboxEngineSrc:()=>or,getSandboxIframeSrc:()=>ei,glbToUSDZ:()=>sn,isAllowedSandboxEngineUrl:()=>ft,noopProxy:()=>Dt,sceneToCanvas3D:()=>Ct,sceneToGLB:()=>Ft,sceneToUSDZ:()=>It,setAllowClientScripts:()=>Co,setSandboxEngineSrc:()=>Ao,setSandboxIframeSrc:()=>Ro,threeAuthorPlugin:()=>Vt,threeMicroPlugin:()=>Uo,toTrustedWorkerScriptURL:()=>Jr,validateSandboxWorkerMessage:()=>ar,warnUnsupported:()=>He});function Qt(t,e,n){let r=[],i=new Map,o=[],s=[],h=[],c=new Map,a=T=>{let S=i.get(T);return S===void 0&&(S=r.length,r.push({op:T}),i.set(T,S)),S},u=T=>{let S=c.get(T);return S===void 0&&(S=h.length,h.push({id:T}),c.set(T,S)),S},f=(T,S={})=>o.push({declaration:a(T),...S})-1,m=(T,S,R)=>s.push({id:T,type:S,value:R})-1,d=T=>({node:T,socket:"value"}),y=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(y&&typeof y=="object"){let T=Array.isArray(y.graphs)?y.graphs[y.graph??0]:y;if(T&&Array.isArray(T.nodes)){let S=Array.isArray(T.declarations)?T.declarations:[];for(let R of S)R?.op&&a(R.op);Array.isArray(T.variables)&&s.push(...T.variables);for(let R of T.events||[])R?.id&&u(R.id);for(let R of T.nodes){if(!R||typeof R!="object")continue;let I=R.op||(typeof R.declaration=="number"?S[R.declaration]?.op:"");o.push(I?{...R,declaration:a(I)}:{...R})}}}let b=(T,S,R="translation")=>R==="baseColorFactor"||R==="metallicFactor"||R==="roughnessFactor"?`/materials/${Math.max(0,S)}/pbrMetallicRoughness/${R}`:R==="emissiveFactor"||R==="alphaCutoff"?`/materials/${Math.max(0,S)}/${R}`:R==="visible"?`/nodes/${T}/extensions/KHR_node_visibility/visible`:`/nodes/${T}/${R}`,M=new Map;t.forEach((T,S)=>{typeof T?.name=="string"&&!M.has(T.name)&&M.set(T.name,S)});let N=(T,S)=>typeof T.target=="string"&&M.has(T.target)?M.get(T.target):typeof T.targetNode=="number"?T.targetNode:S,G=T=>{let S=t[T];return(typeof S?.mesh=="number"?e[S.mesh]?.primitives?.[0]?.material:0)??0};for(let T=0;T<t.length;T++){let S=t[T],R=S?.extras?.interactivity;if(!R||typeof R!="object")continue;let I=(typeof S.mesh=="number"?e[S.mesh]?.primitives?.[0]?.material:0)??0,U=w=>{let E=Array.isArray(w)?w:[w],p=[];for(let l=0;l<E.length;l++){let g=E[l];if(!g||typeof g!="object")continue;let L=g.action||"interpolate",D=typeof g.duration=="number"?g.duration:.35;if(L==="toggleTransform"){let H=g.property==="rotation"||g.property==="scale"?g.property:"translation",X=H==="rotation"?S.rotation||[0,0,0,1]:H==="scale"?S.scale||[1,1,1]:S.translation||[0,0,0],K=`/nodes/${T}/${H}`,Z=m(`__toggle_${T}_${l}`,"bool",!1),O=f("variable/get",{configuration:{variable:Z}}),J=f("math/not",{values:{a:d(O)}}),q=f("variable/set",{configuration:{variable:Z},values:{value:d(J)}}),Q=f("pointer/interpolate",{configuration:{pointer:K},values:{value:{value:Array.isArray(g.to)?g.to:X},duration:{value:D}}}),se=f("pointer/interpolate",{configuration:{pointer:K},values:{value:{value:Array.isArray(g.from)?g.from:X},duration:{value:D}}});o[q].flows={out:{node:f("flow/branch",{values:{condition:d(O)},flows:{true:{node:Q},false:{node:se}}})}},p.push(q)}else if(L==="interpolate"){let H=g.to??g.value;if(H===void 0)continue;let X={value:{value:H},duration:{value:D}};g.from!==void 0&&(X.from={value:g.from}),p.push(f("pointer/interpolate",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:b(N(g,T),G(N(g,T)),g.property)},values:X}))}else if(L==="setProperty"){if(g.value===void 0)continue;p.push(f("pointer/set",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:b(N(g,T),G(N(g,T)),g.property)},values:{value:{value:g.value}}}))}else if(L==="toggleVisibility"){let H=N(g,T),X=m(`__vis_${H}_${l}`,"bool",!0),K=f("variable/get",{configuration:{variable:X}}),Z=f("math/not",{values:{a:d(K)}}),O=f("variable/set",{configuration:{variable:X},values:{value:d(Z)}});o[O].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${H}/extensions/KHR_node_visibility/visible`},values:{value:d(K)}})}},p.push(O)}else if(L==="cycleMaterialColor"&&Array.isArray(g.colors)&&g.colors.length>0){let H=typeof g.duration=="number"?g.duration:.25,X=`/materials/${Math.max(0,I)}/pbrMetallicRoughness/baseColorFactor`,K=m(`__color_idx_${T}_${l}`,"int",0),Z=f("variable/get",{configuration:{variable:K}}),O=f("math/add",{values:{a:d(Z),b:{value:1}}}),J=f("math/rem",{values:{a:d(O),b:{value:g.colors.length}}}),q=f("variable/set",{configuration:{variable:K},values:{value:d(J)}}),Q={};for(let se=0;se<g.colors.length;se++){let B=g.colors[se],$=Array.isArray(B)&&B.length>=3?[B[0],B[1],B[2],B[3]??1]:[1,1,1,1];Q[String(se)]={node:H>0?f("pointer/interpolate",{configuration:{pointer:X},values:{value:{value:$},duration:{value:H}}}):f("pointer/set",{configuration:{pointer:X},values:{value:{value:$}}})}}o[q].flows={out:{node:f("flow/switch",{values:{selection:d(Z)},flows:Q})}},p.push(q)}else if(L==="playAnimation")p.push(f("animation/start",{configuration:{animation:g.animation??g.clip??0}}));else if(L==="stopAnimation")p.push(f("animation/stop"));else if(L==="sendEvent"){let H={};for(let[X,K]of Object.entries(g.values||{}))H[X]={value:K};p.push(f("event/send",{configuration:{event:u(String(g.event??g.id??"custom"))},values:H}))}}if(!p.length)return null;if(p.length===1)return p[0];let k={};return p.forEach((l,g)=>{k[String(g)]={node:l}}),f("flow/sequence",{flows:k})},_=(w,E,p)=>{let k=U(E);k!==null&&f(w,{...p?{configuration:p}:{},flows:{out:{node:k}}})};if(R.onSelect&&_("pointer/onSelect",R.onSelect,{nodeIndex:T}),R.onHoverIn&&_("pointer/onHoverIn",R.onHoverIn,{nodeIndex:T}),R.onHoverOut&&_("pointer/onHoverOut",R.onHoverOut,{nodeIndex:T}),R.onStart&&_("event/onStart",R.onStart),R.onReceive&&typeof R.onReceive=="object")for(let[w,E]of Object.entries(R.onReceive))_("event/receive",E,{event:u(w)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:s,events:h}],graph:0}:null}var Tr='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',Mr="Security Error: client-side scripts require allow-client-scripts opt-in.";var Jt="__THREE_LIVE_REGISTRY__";function Ae(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Jt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Jt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Jt]=e}}return t[Jt]}var ke=Ae().plugins;function wr(t){let e=Ae().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function Sr(){return Ae().plugins}function Ar(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,s=t.Color,h=t.BufferAttribute,c=t.BufferGeometry,a=t.Material,u=t.MeshStandardMaterial,f=t.Mesh,m=8192,d=512,y=128;class b{constructor(x){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(x)&&x.length>0&&this.fromPoints(x)}fromPoints(x){if(!x.length)return this;this.moveTo(x[0].x,x[0].y);for(let v=1;v<x.length;v++)this.lineTo(x[v].x,x[v].y);return this}moveTo(x,v){let C=Number(x)||0,P=Number(v)||0;return this.currentPoint.set(C,P),this.segments.push({type:"move",pts:[C,P]}),this}lineTo(x,v){let C=Number(x)||0,P=Number(v)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(C,P),this.segments.push({type:"line",pts:[C,P]}),this}quadraticCurveTo(x,v,C,P){let F=this.currentPoint.x,z=this.currentPoint.y,V=Number(x)||0,te=Number(v)||0,W=Number(C)||0,ee=Number(P)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[F,z]}),this.currentPoint.set(W,ee),this.segments.push({type:"quad",pts:[F,z,V,te,W,ee]}),this}bezierCurveTo(x,v,C,P,F,z){let V=this.currentPoint.x,te=this.currentPoint.y,W=Number(x)||0,ee=Number(v)||0,Y=Number(C)||0,j=Number(P)||0,oe=Number(F)||0,ne=Number(z)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[V,te]}),this.currentPoint.set(oe,ne),this.segments.push({type:"cubic",pts:[V,te,W,ee,Y,j,oe,ne]}),this}absarc(x,v,C,P,F,z=!1){return this.absellipse(x,v,C,C,P,F,z,0)}arc(x,v,C,P,F,z=!1){return this.absarc(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(v)||0),C,P,F,z)}absellipse(x,v,C,P,F,z,V=!1,te=0){let W=Number(x)||0,ee=Number(v)||0,Y=Math.max(0,Number(C)||0),j=Math.max(0,Number(P)||0),oe=Number(F)||0,ne=Number(z)||0,ce=V?1:0,ue=Number(te)||0;this.segments.push({type:"arc",pts:[W,ee,Y,j,oe,ne,ce,ue]});let he=Math.cos(ue),de=Math.sin(ue),be=Y*Math.cos(ne),fe=j*Math.sin(ne);return this.currentPoint.set(W+be*he-fe*de,ee+be*de+fe*he),this}ellipse(x,v,C,P,F,z,V=!1,te=0){return this.absellipse(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(v)||0),C,P,F,z,V,te)}closePath(){if(this.segments.length>0){let x=this.segments[0],v=0,C=0;if(x.type==="arc"){let P=x.pts[0],F=x.pts[1],z=x.pts[2],V=x.pts[3],te=x.pts[4],W=x.pts[7],ee=Math.cos(W),Y=Math.sin(W),j=z*Math.cos(te),oe=V*Math.sin(te);v=P+j*ee-oe*Y,C=F+j*Y+oe*ee}else v=x.pts[0],C=x.pts[1];Math.hypot(this.currentPoint.x-v,this.currentPoint.y-C)>1e-6&&this.lineTo(v,C)}return this}getPoints(x=12){let v=Math.max(1,Math.min(128,Math.floor(Number(x)||12))),C=[],P=(F,z)=>{if(C.length>0){let V=C[C.length-1];if(Math.hypot(V.x-F,V.y-z)<1e-6)return}C.push(new n(F,z))};for(let F of this.segments){let z=F.pts;if(F.type==="move"||F.type==="line")P(z[0],z[1]);else if(F.type==="quad"){let V=z[0],te=z[1],W=z[2],ee=z[3],Y=z[4],j=z[5];P(V,te);for(let oe=1;oe<=v;oe++){let ne=oe/v,ce=1-ne;P(ce*ce*V+2*ce*ne*W+ne*ne*Y,ce*ce*te+2*ce*ne*ee+ne*ne*j)}}else if(F.type==="cubic"){let V=z[0],te=z[1],W=z[2],ee=z[3],Y=z[4],j=z[5],oe=z[6],ne=z[7];P(V,te);for(let ce=1;ce<=v;ce++){let ue=ce/v,he=1-ue,de=he*he,be=ue*ue;P(de*he*V+3*de*ue*W+3*he*be*Y+be*ue*oe,de*he*te+3*de*ue*ee+3*he*be*j+be*ue*ne)}}else if(F.type==="arc"){let V=z[0],te=z[1],W=z[2],ee=z[3],Y=z[4],j=z[5],oe=z[6]!==0,ne=z[7],ce=Math.PI*2,ue=j-Y,he=Math.abs(ue)<1e-9;for(;ue<0;)ue+=ce;for(;ue>ce;)ue-=ce;ue<1e-9&&(ue=he?0:ce),oe&&!he&&(ue=ue===ce?-ce:ue-ce);let de=Math.cos(ne),be=Math.sin(ne),fe=Math.max(2,v);for(let le=0;le<=fe;le++){let ge=le/fe,Te=Y+ge*ue,ye=W*Math.cos(Te),ve=ee*Math.sin(Te);P(V+ye*de-ve*be,te+ye*be+ve*de)}}}if(C.length>2){let F=C[0],z=C[C.length-1];Math.hypot(F.x-z.x,F.y-z.y)<1e-6&&C.pop()}return C}getSpacedPoints(x=12){return this.getPoints(x)}}class M extends b{constructor(x){super(x),this.holes=[]}extractPoints(x=12){return{shape:this.getPoints(x),holes:this.holes.map(v=>v.getPoints(x))}}}function N(A){let x=0,v=A.length;for(let C=0,P=v-1;C<v;P=C++)x+=A[P].x*A[C].y-A[C].x*A[P].y;return x*.5}function G(A,x,v,C,P,F,z,V){let te=z-v,W=V-C,ee=P-v,Y=F-C,j=A-v,oe=x-C,ne=te*te+W*W,ce=te*ee+W*Y,ue=te*j+W*oe,he=ee*ee+Y*Y,de=ee*j+Y*oe,be=ne*he-ce*ce;if(Math.abs(be)<1e-12)return!1;let fe=1/be,le=(he*ue-ce*de)*fe,ge=(ne*de-ce*ue)*fe;return le>=-1e-7&&ge>=-1e-7&&le+ge<=1+1e-7}function T(A,x){let v=A.slice();N(v)<0&&v.reverse();let C=v.map(z=>new n(z.x,z.y)),P=v.map((z,V)=>V),F=[];for(let z of x){if(!z||z.length<3)continue;let V=z.slice();N(V)>0&&V.reverse();let te=[],W=-1/0,ee=0;for(let Y=0;Y<V.length;Y++){let j=V[Y],oe=C.length;C.push(new n(j.x,j.y)),te.push(oe),j.x>W&&(W=j.x,ee=Y)}F.push({pts:V,indices:te,maxX:W,maxIdx:ee})}F.sort((z,V)=>V.maxX-z.maxX);for(let z of F){let V=z.pts[z.maxIdx].x,te=z.pts[z.maxIdx].y,W=0,ee=1/0;for(let j=0;j<P.length;j++){let oe=C[P[j]],ne=Math.hypot(oe.x-V,oe.y-te)+(oe.x>=V?0:1e3);ne<ee&&(ee=ne,W=j)}let Y=[];for(let j=0;j<=W;j++)Y.push(P[j]);for(let j=0;j<=z.indices.length;j++){let oe=z.indices[(z.maxIdx+j)%z.indices.length];Y.push(oe)}for(let j=W;j<P.length;j++)Y.push(P[j]);P=Y}return{merged:P.map(z=>C[z]),mergedIndices:P,allVertices:C}}function S(A,x){let v=[],C=A.slice();if(C.length<3)return v;let P=C.length*C.length+64,F=0;for(;C.length>2&&P-- >0;){let z=C.length,V=C[(F+z-1)%z],te=C[F%z],W=C[(F+1)%z],ee=x[V],Y=x[te],j=x[W];if((Y.x-ee.x)*(j.y-ee.y)-(Y.y-ee.y)*(j.x-ee.x)>1e-9){let ne=!0;for(let ce=0;ce<z;ce++){let ue=C[ce];if(ue===V||ue===te||ue===W)continue;let he=x[ue];if(!(Math.hypot(he.x-ee.x,he.y-ee.y)<1e-6||Math.hypot(he.x-Y.x,he.y-Y.y)<1e-6||Math.hypot(he.x-j.x,he.y-j.y)<1e-6)&&G(he.x,he.y,ee.x,ee.y,Y.x,Y.y,j.x,j.y)){ne=!1;break}}if(ne){v.push([V,te,W]),C.splice(F%z,1),F=0;continue}}F++,F>=z*2&&(v.push([V,te,W]),C.splice(F%z,1),F=0)}return v}class R extends c{constructor(x=new M,v=12){super();let C=Array.isArray(x)?x:[x],P=[],F=[],z=[],V=[];for(let te of C){if(!(te instanceof b))continue;let W=te instanceof M?te.extractPoints(v):{shape:te.getPoints(v),holes:[]};if(W.shape.length<3)continue;let{mergedIndices:ee,allVertices:Y}=T(W.shape,W.holes),j=S(ee,Y),oe=P.length/3,ne=1/0,ce=1/0,ue=-1/0,he=-1/0;for(let fe of Y)fe.x<ne&&(ne=fe.x),fe.y<ce&&(ce=fe.y),fe.x>ue&&(ue=fe.x),fe.y>he&&(he=fe.y);let de=Math.max(1e-6,ue-ne),be=Math.max(1e-6,he-ce);for(let fe of Y)P.push(fe.x,fe.y,0),F.push(0,0,1),z.push((fe.x-ne)/de,(fe.y-ce)/be);for(let[fe,le,ge]of j)V.push(oe+fe,oe+le,oe+ge)}this.setAttribute("position",new h(new Float32Array(P),3)),this.setAttribute("normal",new h(new Float32Array(F),3)),this.setAttribute("uv",new h(new Float32Array(z),2)),this.setIndex(V)}}function I(A){let x=A.length,v=[];for(let C=0;C<x;C++){let P=A[(C+x-1)%x],F=A[C],z=A[(C+1)%x],V=F.x-P.x,te=F.y-P.y,W=Math.hypot(V,te)||1;V/=W,te/=W;let ee=z.x-F.x,Y=z.y-F.y,j=Math.hypot(ee,Y)||1;ee/=j,Y/=j;let oe=te,ne=-V,ce=Y,ue=-ee,he=oe+ce,de=ne+ue,be=Math.hypot(he,de);if(be>1e-6){he/=be,de/=be;let fe=Math.max(.35,he*oe+de*ne);v.push(new n(he/fe,de/fe))}else v.push(new n(oe,ne))}return v}class U extends c{constructor(x=new M,v={}){super();let C=Array.isArray(x)?x:[x],P=Math.max(1,Math.min(64,Math.floor(Number(v.curveSegments??12)))),F=Number.isFinite(Number(v.depth??v.amount))?Number(v.depth??v.amount):1,z=Math.max(1,Math.min(32,Math.floor(Number(v.steps??1)))),V=!!(v.bevelEnabled??!1),te=V?Math.max(0,Number(v.bevelThickness??.06)):0,W=V?Math.max(0,Number(v.bevelSize??te*.8)):0,ee=V?Number(v.bevelOffset??0):0,Y=V?Math.max(1,Math.min(8,Math.floor(Number(v.bevelSegments??2)))):0,j=[],oe=[],ne=[],ce=[];for(let ue of C){if(!(ue instanceof b))continue;let he=ue instanceof M?ue.extractPoints(P):{shape:ue.getPoints(P),holes:[]};if(he.shape.length<3)continue;let de=he.shape.slice();N(de)<0&&de.reverse();let be=[];for(let me of he.holes){if(me.length<3)continue;let Me=me.slice();N(Me)>0&&Me.reverse(),be.push(Me)}let{mergedIndices:fe,allVertices:le}=T(de,be),ge=S(fe,le),Te=[de,...be],ye=[];for(let me of Te){let Me=I(me);for(let we of Me)ye.push(we)}let ve=1/0,Re=1/0,Le=-1/0,Fe=-1/0;for(let me of le)me.x<ve&&(ve=me.x),me.y<Re&&(Re=me.y),me.x>Le&&(Le=me.x),me.y>Fe&&(Fe=me.y);let Ve=Math.max(1e-6,Le-ve),Ye=Math.max(1e-6,Fe-Re),vt=-te,Tt=F+te,tt=j.length/3;for(let me=0;me<le.length;me++){let Me=le[me],we=ye[me]??new n(0,0),Ie=Me.x+we.x*ee,De=Me.y+we.y*ee;j.push(Ie,De,vt),oe.push(0,0,-1),ne.push((Ie-ve)/Ve,(De-Re)/Ye)}for(let[me,Me,we]of ge)ce.push(tt+me,tt+we,tt+Me);let nt=j.length/3;for(let me=0;me<le.length;me++){let Me=le[me],we=ye[me]??new n(0,0),Ie=Me.x+we.x*ee,De=Me.y+we.y*ee;j.push(Ie,De,Tt),oe.push(0,0,1),ne.push((Ie-ve)/Ve,(De-Re)/Ye)}for(let[me,Me,we]of ge)ce.push(nt+me,nt+Me,nt+we);let Oe=[];if(V&&Y>0)for(let me=0;me<Y;me++){let we=me/Y*Math.PI/2;Oe.push({z:-te*Math.cos(we),expand:ee+W*Math.sin(we)})}for(let me=0;me<=z;me++){let Me=me/z;Oe.push({z:Me*F,expand:ee+W})}if(V&&Y>0)for(let me=1;me<=Y;me++){let we=me/Y*Math.PI/2;Oe.push({z:F+te*Math.sin(we),expand:ee+W*Math.cos(we)})}let je=0;for(let me of Te){let Me=me.length;for(let we=0;we<Oe.length-1;we++){let Ie=Oe[we],De=Oe[we+1];for(let Ue=0;Ue<Me;Ue++){let Ze=(Ue+1)%Me,rt=me[Ue],it=me[Ze],ot=ye[je+Ue],st=ye[je+Ze],at=rt.x+ot.x*Ie.expand,ct=rt.y+ot.y*Ie.expand,dt=it.x+st.x*Ie.expand,Qe=it.y+st.y*Ie.expand,li=it.x+st.x*De.expand,hi=it.y+st.y*De.expand,ur=rt.x+ot.x*De.expand,lr=rt.y+ot.y*De.expand,hr=dt-at,mr=Qe-ct,fr=0,dr=ur-at,pr=lr-ct,br=De.z-Ie.z,Mt=mr*br-fr*pr,wt=fr*dr-hr*br,St=hr*pr-mr*dr,Un=Math.hypot(Mt,wt,St)||1;Mt/=Un,wt/=Un,St/=Un;let At=j.length/3;j.push(at,ct,Ie.z,dt,Qe,Ie.z,li,hi,De.z,ur,lr,De.z),oe.push(Mt,wt,St,Mt,wt,St,Mt,wt,St,Mt,wt,St);let yr=Ue/Me,gr=(Ue+1)/Me,xr=we/(Oe.length-1),vr=(we+1)/(Oe.length-1);ne.push(yr,xr,gr,xr,gr,vr,yr,vr),ce.push(At,At+1,At+2,At,At+2,At+3)}}je+=Me}}this.setAttribute("position",new h(new Float32Array(j),3)),this.setAttribute("normal",new h(new Float32Array(oe),3)),this.setAttribute("uv",new h(new Float32Array(ne),2)),this.setIndex(ce)}}function _(A){return{x:A.x,y:A.y,z:A.z,nx:A.nx,ny:A.ny,nz:A.nz,u:A.u,v:A.v}}function w(A){return{x:A.x,y:A.y,z:A.z,nx:-A.nx,ny:-A.ny,nz:-A.nz,u:A.u,v:A.v}}function E(A,x,v){let C=A.nx+(x.nx-A.nx)*v,P=A.ny+(x.ny-A.ny)*v,F=A.nz+(x.nz-A.nz)*v,z=Math.hypot(C,P,F)||1;return{x:A.x+(x.x-A.x)*v,y:A.y+(x.y-A.y)*v,z:A.z+(x.z-A.z)*v,nx:C/z,ny:P/z,nz:F/z,u:A.u+(x.u-A.u)*v,v:A.v+(x.v-A.v)*v}}function p(A){if(A.length<3)return null;let x=A[0],v=A[1],C=A[2],P=v.x-x.x,F=v.y-x.y,z=v.z-x.z,V=C.x-x.x,te=C.y-x.y,W=C.z-x.z,ee=F*W-z*te,Y=z*V-P*W,j=P*te-F*V,oe=Math.hypot(ee,Y,j);if(oe<1e-9)return null;ee/=oe,Y/=oe,j/=oe;let ne=ee*x.x+Y*x.y+j*x.z;return{vertices:A,nx:ee,ny:Y,nz:j,w:ne}}function k(A){A.vertices.reverse();for(let x=0;x<A.vertices.length;x++)A.vertices[x]=w(A.vertices[x]);A.nx=-A.nx,A.ny=-A.ny,A.nz=-A.nz,A.w=-A.w}let l=1e-5,g=0,L=1,D=2,H=3;function X(A,x,v,C,P,F,z,V,te){let W=0,ee=[];for(let Y=0;Y<P.vertices.length;Y++){let j=P.vertices[Y],oe=A*j.x+x*j.y+v*j.z-C,ne=oe<-l?D:oe>l?L:g;W|=ne,ee.push(ne)}switch(W){case g:{A*P.nx+x*P.ny+v*P.nz>0?F.push(P):z.push(P);break}case L:V.push(P);break;case D:te.push(P);break;case H:{let Y=[],j=[],oe=P.vertices.length;for(let ne=0;ne<oe;ne++){let ce=(ne+1)%oe,ue=ee[ne],he=ee[ce],de=P.vertices[ne],be=P.vertices[ce];if(ue!==D&&Y.push(de),ue!==L&&j.push(ue!==D?_(de):de),(ue|he)===H){let fe=be.x-de.x,le=be.y-de.y,ge=be.z-de.z,Te=A*fe+x*le+v*ge,ye=Math.abs(Te)>1e-12?(C-(A*de.x+x*de.y+v*de.z))/Te:.5,ve=E(de,be,Math.max(0,Math.min(1,ye)));Y.push(ve),j.push(_(ve))}}if(Y.length>=3){let ne=p(Y);ne&&V.push(ne)}if(j.length>=3){let ne=p(j);ne&&te.push(ne)}break}default:break}}class K{constructor(x,v=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,x&&x.length>0&&this.build(x,v)}invert(){for(let v=0;v<this.polygons.length;v++)k(this.polygons[v]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let x=this.front;this.front=this.back,this.back=x}clipPolygons(x,v=0){if(!this.hasPlane||x.length===0||v>=d)return x.slice();let C=[],P=[];for(let F=0;F<x.length;F++)X(this.nx,this.ny,this.nz,this.w,x[F],C,P,C,P);return this.front&&C.length>0&&(C=this.front.clipPolygons(C,v+1)),this.back?P=P.length>0?this.back.clipPolygons(P,v+1):[]:P=[],C.concat(P)}clipTo(x,v=0){this.polygons.length>0&&(this.polygons=x.clipPolygons(this.polygons,0)),v<d&&(this.front&&this.front.clipTo(x,v+1),this.back&&this.back.clipTo(x,v+1))}allPolygons(x=[]){for(let v=0;v<this.polygons.length;v++)x.push(this.polygons[v]);return this.front&&this.front.allPolygons(x),this.back&&this.back.allPolygons(x),x}build(x,v=0){if(!x.length)return;if(!this.hasPlane){let F=x[0];this.nx=F.nx,this.ny=F.ny,this.nz=F.nz,this.w=F.w,this.hasPlane=!0}if(v>=d){for(let F=0;F<x.length;F++)this.polygons.push(x[F]);return}let C=[],P=[];for(let F=0;F<x.length;F++)X(this.nx,this.ny,this.nz,this.w,x[F],this.polygons,this.polygons,C,P);C.length>0&&(this.front||(this.front=new K),this.front.build(C,v+1)),P.length>0&&(this.back||(this.back=new K),this.back.build(P,v+1))}}function Z(A,x){let v=A.attributes.position;if(!v||v.count===0)return[];let C=A.attributes.normal,P=A.attributes.uv,F=A.index?A.index.array:null,z=Math.floor(F?F.length/3:v.count/3);if(z>m)throw new RangeError(`SecurityError: CSG input triangle count (${z}) exceeds MAX_CSG_TRIANGLES (${m})`);let V=x?x.elements:null,te=V?V[0]*(V[5]*V[10]-V[9]*V[6])-V[4]*(V[1]*V[10]-V[9]*V[2])+V[8]*(V[1]*V[6]-V[5]*V[2])<0:!1,W=Y=>{let j=v.getX(Y),oe=v.getY(Y),ne=v.getZ(Y),ce=C?C.getX(Y):0,ue=C?C.getY(Y):0,he=C?C.getZ(Y):1;if(V){let fe=V[0]*j+V[4]*oe+V[8]*ne+V[12],le=V[1]*j+V[5]*oe+V[9]*ne+V[13],ge=V[2]*j+V[6]*oe+V[10]*ne+V[14];j=fe,oe=le,ne=ge;let Te=V[0]*ce+V[4]*ue+V[8]*he,ye=V[1]*ce+V[5]*ue+V[9]*he,ve=V[2]*ce+V[6]*ue+V[10]*he,Re=Math.hypot(Te,ye,ve)||1;ce=Te/Re,ue=ye/Re,he=ve/Re}let de=P?P.getX(Y):0,be=P?P.getY(Y):0;return{x:j,y:oe,z:ne,nx:ce,ny:ue,nz:he,u:de,v:be}},ee=[];for(let Y=0;Y<z;Y++){let j=F?F[Y*3]:Y*3,oe=F?F[Y*3+1]:Y*3+1,ne=F?F[Y*3+2]:Y*3+2,ce=p(te?[W(j),W(ne),W(oe)]:[W(j),W(oe),W(ne)]);ce&&ee.push(ce)}return ee}function O(A){let x=[],v=[],C=[],P=[];for(let z of A){let V=z.vertices;if(V.length<3)continue;let te=x.length/3;for(let W of V)x.push(W.x,W.y,W.z),v.push(z.nx,z.ny,z.nz),C.push(W.u,W.v);for(let W=1;W<V.length-1;W++)P.push(te,te+W,te+W+1)}let F=new c;return F.setAttribute("position",new h(new Float32Array(x),3)),F.setAttribute("normal",new h(new Float32Array(v),3)),F.setAttribute("uv",new h(new Float32Array(C),2)),F.setIndex(P),F}function J(A,x,v){if(A.length+x.length>m)throw new RangeError(`SecurityError: Combined CSG triangle count (${A.length+x.length}) exceeds MAX_CSG_TRIANGLES (${m})`);if(A.length===0)return v==="union"?x:[];if(x.length===0)return v==="intersect"?[]:A;let C=new K(A),P=new K(x);return v==="union"?(C.clipTo(P),P.clipTo(C),P.invert(),P.clipTo(C),P.invert(),C.build(P.allPolygons()),C.allPolygons()):v==="subtract"?(C.invert(),C.clipTo(P),P.clipTo(C),P.invert(),P.clipTo(C),P.invert(),C.build(P.allPolygons()),C.invert(),C.allPolygons()):(C.invert(),P.clipTo(C),P.invert(),C.clipTo(P),P.clipTo(C),C.build(P.allPolygons()),C.invert(),C.allPolygons())}function q(A,x,v,C=null,P=null){let F=Z(A,C),z=Z(x,P);return O(J(F,z,v))}function Q(A,x,v){let C=A instanceof f||!!A?.isMesh,P=x instanceof f||!!x?.isMesh,F=C?A.geometry:A,z=P?x.geometry:x,V=null;if(P)if(x.updateMatrix(),C){A.updateMatrix();let Y=new o().makeScale(1/(A.scale.x||1),1/(A.scale.y||1),1/(A.scale.z||1)),j=Math.hypot(A.quaternion.x,A.quaternion.y,A.quaternion.z,A.quaternion.w)||1,oe=new o().compose(new r(0,0,0),new i(-A.quaternion.x/j,-A.quaternion.y/j,-A.quaternion.z/j,A.quaternion.w/j),new r(1,1,1)),ne=new o().makeTranslation(-A.position.x,-A.position.y,-A.position.z);V=Y.multiply(oe).multiply(ne).multiply(x.matrix)}else V=x.matrix;let te=q(F,z,v,null,V),W=C?A.material:new u,ee=new f(te,W);return C&&(ee.position.copy(A.position),ee.quaternion.copy(A.quaternion),ee.scale.copy(A.scale),ee.name=A.name),ee}let se={toGeometry:q,subtract(A,x){return Q(A,x,"subtract")},union(A,x){return Q(A,x,"union")},intersect(A,x){return Q(A,x,"intersect")}},B={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class $ extends c{constructor(x="",v={}){super();let C=String(x??"").slice(0,y),P=Math.max(.005,Math.min(100,Number(v.size??.2))),F=!!(v.bevelEnabled??!1),z=F?Math.max(0,Math.min(2,Number(v.bevelThickness??P*.04))):0,V=F?Math.max(0,Math.min(2,Number(v.bevelSize??P*.03))):0,te=Math.max(.001,Math.min(20,Number(v.depth??v.height??P*.2)))+z*2,W=P*.085+V,ee=P*.68,Y=P*.82,j=[],oe=[],ne=[],ce=[],ue=(be,fe,le,ge,Te,ye,ve)=>{let Re=le-be,Le=ge-fe,Fe=Math.hypot(Re,Le),Ve=1,Ye=0;Fe>1e-6&&(Ve=Re/Fe,Ye=Le/Fe);let vt=-Ye*Te,Tt=Ve*Te,tt=Ve*Te*.6,nt=Ye*Te*.6,Oe=be-tt+vt,je=fe-nt+Tt,me=be-tt-vt,Me=fe-nt-Tt,we=le+tt-vt,Ie=ge+nt-Tt,De=le+tt+vt,Ue=ge+nt+Tt,Ze=(rt,it,ot,st,at,ct,dt)=>{let Qe=j.length/3;j.push(rt[0],rt[1],rt[2],it[0],it[1],it[2],ot[0],ot[1],ot[2],st[0],st[1],st[2]),oe.push(at,ct,dt,at,ct,dt,at,ct,dt,at,ct,dt),ne.push(0,0,1,0,1,1,0,1),ce.push(Qe,Qe+1,Qe+2,Qe,Qe+2,Qe+3)};Ze([Oe,je,ve],[me,Me,ve],[we,Ie,ve],[De,Ue,ve],0,0,1),Ze([me,Me,ye],[Oe,je,ye],[De,Ue,ye],[we,Ie,ye],0,0,-1),Ze([Oe,je,ye],[me,Me,ye],[me,Me,ve],[Oe,je,ve],-Ve,-Ye,0),Ze([we,Ie,ye],[De,Ue,ye],[De,Ue,ve],[we,Ie,ve],Ve,Ye,0),Ze([me,Me,ye],[we,Ie,ye],[we,Ie,ve],[me,Me,ve],-Ye,Ve,0),Ze([De,Ue,ye],[Oe,je,ye],[Oe,je,ve],[De,Ue,ve],Ye,-Ve,0)},he=0,de=0;for(let be=0;be<C.length;be++){let fe=C[be];if(fe===`
18
+ `){he=0,de-=P*1.35;continue}if(fe===" "){he+=Y*.75;continue}let le=fe.toUpperCase(),ge=fe!==le&&fe>="a"&&fe<="z",Te=B[le]??B["?"],ye=ge?P*.76:P,ve=ge?ee*.88:ee;for(let Re of Te)for(let Le=0;Le<Re.length-1;Le++){let Fe=Re[Le],Ve=Re[Le+1];ue(he+Fe[0]*ve,de+Fe[1]*ye,he+Ve[0]*ve,de+Ve[1]*ye,W,-te*.5,te*.5)}he+=ge?Y*.88:Y}this.setAttribute("position",new h(new Float32Array(j),3)),this.setAttribute("normal",new h(new Float32Array(oe),3)),this.setAttribute("uv",new h(new Float32Array(ne),2)),this.setIndex(ce),v.center!==!1?this.center():this.computeBoundingBox()}}function ae(A){if(!A)return;let x=A,v=A.userData?.xr?.text;if(v!=null&&v!==!1){let P=x.geometry?.attributes?.position;if(!P||P.count===0){let F="",z=.08,V=.015,te;if(typeof v=="string"||typeof v=="number")F=String(v);else if(typeof v=="object"){let W=v;F=String(W.text??W.value??""),W.size!==void 0&&(z=Number(W.size)||.08),(W.depth!==void 0||W.height!==void 0)&&(V=Number(W.depth??W.height)||z*.2),(typeof W.color=="string"||typeof W.color=="number")&&(te=W.color)}F.trim().length>0&&(x.geometry=new $(F,{size:z,depth:V}),x.material instanceof a?te!==void 0&&A.userData._autoTextColorApplied!==!0&&(x.material.color=new s(te),A.userData._autoTextColorApplied=!0):x.material=new u({color:te??16317180}))}}let C=A.userData?.csg;if(C&&typeof C=="object"&&A.userData._csgApplied!==!0&&x.geometry instanceof c&&x.geometry.attributes.position?.count>0){A.userData._csgApplied=!0;let P=Array.isArray(C)?C:[C];for(let F of P){if(!F||typeof F!="object")continue;let z=F,V=String(z.op??z.operation??"subtract"),te=V==="union"||V==="intersect"?V:"subtract",W=z.target??z.mesh??z.geometry;if(W instanceof f||W instanceof c){let ee=te==="union"?se.union(x,W):te==="intersect"?se.intersect(x,W):se.subtract(x,W);x.geometry=ee.geometry}}}}let ie={Path:b,Shape:M,ShapeGeometry:R,ExtrudeGeometry:U,TextGeometry:$,CSG:se,MAX_CSG_TRIANGLES:m,MAX_BSP_DEPTH:d,MAX_TEXT_GEOMETRY_CHARS:y,materializeDeclarativeGeometry:ae};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,ie),e.materializeDeclarativeGeometry=ae),ie}function Vn(t,e){function n(c,a,u,f){let m=typeof c=="number"?c:Number(c);return Number.isFinite(m)?Math.max(a,Math.min(u,m)):f}function r(c,a){let f=c[0]*a[0]+c[1]*a[1]+c[2]*a[2]+1;if(f<1e-6){if(Math.abs(c[0])>Math.abs(c[2])){let N=Math.hypot(c[1],c[0])||1;return[-c[1]/N,c[0]/N,0,0]}let M=Math.hypot(c[2],c[1])||1;return[0,-c[2]/M,c[1]/M,0]}let m=c[1]*a[2]-c[2]*a[1],d=c[2]*a[0]-c[0]*a[2],y=c[0]*a[1]-c[1]*a[0],b=Math.hypot(m,d,y,f)||1;return[m/b,d/b,y/b,f/b]}function i(c,a,u,f,m){let d=a[0]-c[0],y=a[1]-c[1],b=a[2]-c[2],M=Math.hypot(d,y,b),N=u[0]-a[0],G=u[1]-a[1],T=u[2]-a[2],S=Math.hypot(N,G,T);if(M<1e-6||S<1e-6)return{rootPos:[c[0],c[1],c[2]],midPos:[a[0],a[1],a[2]],effectorPos:[u[0],u[1],u[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let R=[d/M,y/M,b/M],I=[N/S,G/S,T/S],U=f[0]-c[0],_=f[1]-c[1],w=f[2]-c[2],E=Math.hypot(U,_,w),p=E>1e-6?[U/E,_/E,w/E]:R,k=Math.abs(M-S)+1e-5,l=Math.max(k,M+S-1e-5),g=Math.max(k,Math.min(l,E>1e-6?E:k)),L=n((M*M+g*g-S*S)/(2*M*g),-1,1,1),D=Math.sqrt(Math.max(0,1-L*L)),H=m?m[0]-c[0]:d,X=m?m[1]-c[1]:y,K=m?m[2]-c[2]:b,Z=H*p[0]+X*p[1]+K*p[2],O=H-p[0]*Z,J=X-p[1]*Z,q=K-p[2]*Z,Q=Math.hypot(O,J,q);if(Q<=1e-6){let F=Math.abs(p[1])<.99?0:1,z=Math.abs(p[1])<.99?1:0,V=0;O=p[1]*V-p[2]*z,J=p[2]*F-p[0]*V,q=p[0]*z-p[1]*F,Q=Math.hypot(O,J,q)||1}let se=[O/Q,J/Q,q/Q],B=[c[0]+p[0]*(M*L)+se[0]*(M*D),c[1]+p[1]*(M*L)+se[1]*(M*D),c[2]+p[2]*(M*L)+se[2]*(M*D)],$=[c[0]+p[0]*g,c[1]+p[1]*g,c[2]+p[2]*g],ae=$[0]-B[0],ie=$[1]-B[1],A=$[2]-B[2],x=Math.hypot(ae,ie,A),v=x>1e-6?[ae/x,ie/x,A/x]:p,C=[B[0]+v[0]*S,B[1]+v[1]*S,B[2]+v[2]*S],P=[(B[0]-c[0])/M,(B[1]-c[1])/M,(B[2]-c[2])/M];return{rootPos:[c[0],c[1],c[2]],midPos:B,effectorPos:C,rootRotation:r(R,P),midRotation:r(I,v)}}function o(c,a,u=8,f=.001){let m=c.length;if(m<2)return{positions:c.map(E=>[E[0],E[1],E[2]]),rotations:[],iterations:0};let d=c.map(E=>[E[0],E[1],E[2]]),y=[],b=[],M=0;for(let E=0;E<m-1;E++){let p=d[E+1][0]-d[E][0],k=d[E+1][1]-d[E][1],l=d[E+1][2]-d[E][2],g=Math.hypot(p,k,l);y.push(g),M+=g,b.push(g>1e-6?[p/g,k/g,l/g]:[0,1,0])}let N=[d[0][0],d[0][1],d[0][2]],G=Math.round(n(u,1,32,8)),T=n(f,1e-5,.1,.001),S=a[0]-N[0],R=a[1]-N[1],I=a[2]-N[2],U=Math.hypot(S,R,I),_=0;if(U>=M&&M>1e-6){let E=U>1e-6?[S/U,R/U,I/U]:b[0];d[0]=[N[0],N[1],N[2]];for(let p=0;p<m-1;p++){let k=y[p];d[p+1]=[d[p][0]+E[0]*k,d[p][1]+E[1]*k,d[p][2]+E[2]*k]}_=1}else for(let E=1;E<=G;E++){let p=d[m-1];if(Math.hypot(p[0]-a[0],p[1]-a[1],p[2]-a[2])<=T)break;_=E,d[m-1]=[a[0],a[1],a[2]];for(let l=m-2;l>=0;l--){let g=d[l][0]-d[l+1][0],L=d[l][1]-d[l+1][1],D=d[l][2]-d[l+1][2],H=Math.hypot(g,L,D),X=y[l];if(H>1e-6){let K=X/H;d[l]=[d[l+1][0]+g*K,d[l+1][1]+L*K,d[l+1][2]+D*K]}else{let K=b[l];d[l]=[d[l+1][0]-K[0]*X,d[l+1][1]-K[1]*X,d[l+1][2]-K[2]*X]}}d[0]=[N[0],N[1],N[2]];for(let l=0;l<m-1;l++){let g=d[l+1][0]-d[l][0],L=d[l+1][1]-d[l][1],D=d[l+1][2]-d[l][2],H=Math.hypot(g,L,D),X=y[l];if(H>1e-6){let K=X/H;d[l+1]=[d[l][0]+g*K,d[l][1]+L*K,d[l][2]+D*K]}else{let K=b[l];d[l+1]=[d[l][0]+K[0]*X,d[l][1]+K[1]*X,d[l][2]+K[2]*X]}}}let w=[];for(let E=0;E<m-1;E++){let p=d[E+1][0]-d[E][0],k=d[E+1][1]-d[E][1],l=d[E+1][2]-d[E][2],g=Math.hypot(p,k,l),L=g>1e-6?[p/g,k/g,l/g]:b[E];w.push(r(b[E],L))}return{positions:d,rotations:w,iterations:_}}function s(c){if(!c||typeof c!="object"||Array.isArray(c))return null;let a=c;if(a.enabled===!1)return null;let u=S=>{if(typeof S!="string")return;let R=S.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(R)?R:void 0},f=S=>Array.isArray(S)&&S.length===3&&typeof S[0]=="number"&&Number.isFinite(S[0])&&typeof S[1]=="number"&&Number.isFinite(S[1])&&typeof S[2]=="number"&&Number.isFinite(S[2]),m=u(a.root),d=u(a.effector);if(!m||!d)return null;let y=u(a.mid),b=a.target,M;if(f(b))M=[n(b[0],-1e3,1e3,0),n(b[1],-1e3,1e3,0),n(b[2],-1e3,1e3,0)];else{let S=u(b);if(!S)return null;M=S}let N=a.pole,G=f(N)?[n(N[0],-1e3,1e3,0),n(N[1],-1e3,1e3,0),n(N[2],-1e3,1e3,0)]:void 0,T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||y?"two-bone":"fabrik";return{root:m,...y?{mid:y}:{},effector:d,target:M,...G?{pole:G}:{},solver:T,iterations:Math.round(n(a.iterations,1,32,8)),tolerance:n(a.tolerance,1e-5,.1,.001),weight:n(a.weight,0,1,1)}}let h=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:s});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=h),{clampNum:n,parseIKTrait:s,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:h}}var Et=Vn(),$o=Et.clampNum,Yo=Et.parseIKTrait,jo=Et.quatFromUnitVectors,Ko=Et.solveTwoBoneIK,qo=Et.solveFABRIK,Zo=Et.IKSolver;function Ee(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function en(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let s=1/(r-i);return t[10]=(i+r)*s,t[14]=2*i*r*s,t}function Rt(t,e,n,r){let[i,o,s]=e,[h,c,a]=r,[u,f,m]=n,d=i-u,y=o-f,b=s-m,M=Math.hypot(d,y,b);M<=1e-5?(d=0,y=0,b=1):(d/=M,y/=M,b/=M);let N=c*b-a*y,G=a*d-h*b,T=h*y-c*d;M=Math.hypot(N,G,T),M<=1e-5?(N=0,G=0,T=0):(N/=M,G/=M,T/=M);let S=y*T-b*G,R=b*N-d*T,I=d*G-y*N;return M=Math.hypot(S,R,I),M<=1e-5?(S=0,R=0,I=0):(S/=M,R/=M,I/=M),t[0]=N,t[1]=S,t[2]=d,t[3]=0,t[4]=G,t[5]=R,t[6]=y,t[7]=0,t[8]=T,t[9]=I,t[10]=b,t[11]=0,t[12]=-(N*i+G*o+T*s),t[13]=-(S*i+R*o+I*s),t[14]=-(d*i+y*o+b*s),t[15]=1,t}function _e(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],h=e[4],c=e[5],a=e[6],u=e[7],f=e[8],m=e[9],d=e[10],y=e[11],b=e[12],M=e[13],N=e[14],G=e[15],T=n[0],S=n[1],R=n[2],I=n[3];return t[0]=T*r+S*h+R*f+I*b,t[1]=T*i+S*c+R*m+I*M,t[2]=T*o+S*a+R*d+I*N,t[3]=T*s+S*u+R*y+I*G,T=n[4],S=n[5],R=n[6],I=n[7],t[4]=T*r+S*h+R*f+I*b,t[5]=T*i+S*c+R*m+I*M,t[6]=T*o+S*a+R*d+I*N,t[7]=T*s+S*u+R*y+I*G,T=n[8],S=n[9],R=n[10],I=n[11],t[8]=T*r+S*h+R*f+I*b,t[9]=T*i+S*c+R*m+I*M,t[10]=T*o+S*a+R*d+I*N,t[11]=T*s+S*u+R*y+I*G,T=n[12],S=n[13],R=n[14],I=n[15],t[12]=T*r+S*h+R*f+I*b,t[13]=T*i+S*c+R*m+I*M,t[14]=T*o+S*a+R*d+I*N,t[15]=T*s+S*u+R*y+I*G,t}function pt(t,e,n,r){let i=e[0],o=e[1],s=e[2],h=e[3],c=i+i,a=o+o,u=s+s,f=i*c,m=i*a,d=i*u,y=o*a,b=o*u,M=s*u,N=h*c,G=h*a,T=h*u,S=r[0],R=r[1],I=r[2];return t[0]=(1-(y+M))*S,t[1]=(m+T)*S,t[2]=(d-G)*S,t[3]=0,t[4]=(m-T)*R,t[5]=(1-(f+M))*R,t[6]=(b+N)*R,t[7]=0,t[8]=(d+G)*I,t[9]=(b-N)*I,t[10]=(1-(f+y))*I,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ze(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],h=e[6],c=e[8],a=e[9],u=e[10],f=u*s-h*a,m=-u*o+h*c,d=a*o-s*c,y=n*f+r*m+i*d;return y&&(y=1/y,t[0]=f*y,t[1]=m*y,t[2]=d*y,t[3]=(-u*r+i*a)*y,t[4]=(u*n-i*c)*y,t[5]=(-a*n+r*c)*y,t[6]=(h*r-i*s)*y,t[7]=(-h*n+i*o)*y,t[8]=(s*n-r*o)*y),t}function Er(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],h=e[5],c=e[6],a=e[7],u=e[8],f=e[9],m=e[10],d=e[11],y=e[12],b=e[13],M=e[14],N=e[15],G=n*h-r*s,T=n*c-i*s,S=n*a-o*s,R=r*c-i*h,I=r*a-o*h,U=i*a-o*c,_=u*b-f*y,w=u*M-m*y,E=u*N-d*y,p=f*M-m*b,k=f*N-d*b,l=m*N-d*M,g=G*l-T*k+S*p+R*E-I*w+U*_;return g?(g=1/g,t[0]=(h*l-c*k+a*p)*g,t[1]=(i*k-r*l-o*p)*g,t[2]=(b*U-M*I+N*R)*g,t[3]=(m*I-f*U-d*R)*g,t[4]=(c*E-s*l-a*w)*g,t[5]=(n*l-i*E+o*w)*g,t[6]=(M*S-y*U-N*T)*g,t[7]=(u*U-m*S+d*T)*g,t[8]=(s*k-h*E+a*_)*g,t[9]=(r*E-n*k-o*_)*g,t[10]=(y*I-b*S+N*G)*g,t[11]=(f*S-u*I-d*G)*g,t[12]=(h*w-s*p-c*_)*g,t[13]=(n*p-r*w+i*_)*g,t[14]=(b*T-y*R-M*G)*g,t[15]=(u*R-f*T+m*G)*g,t):null}function Bn(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],s=i[1]*e+i[5]*n+i[9]*r+i[13],h=i[2]*e+i[6]*n+i[10]*r+i[14],c=i[3]*e+i[7]*n+i[11]*r+i[15],a=c!==0?1/c:1;t[0]=o*a,t[1]=s*a,t[2]=h*a}function Rr(t,e,n,r,i,o,s,h,c,a,u,f,m,d,y,b,M=0){let N=a-s,G=u-h,T=f-c,S=m-s,R=d-h,I=y-c,U=i*I-o*R,_=o*S-r*I,w=r*R-i*S,E=N*U+G*_+T*w;if(E>-1e-7&&E<1e-7)return!1;let p=1/E,k=t-s,l=e-h,g=n-c,L=p*(k*U+l*_+g*w);if(L<-M||L>1+M)return!1;let D=l*T-g*G,H=g*N-k*T,X=k*G-l*N,K=p*(r*D+i*H+o*X);if(K<-M||L+K>1+M)return!1;let Z=p*(S*D+R*H+I*X);if(Z>1e-4&&Z<b.distance){b.distance=Z,b.point=[t+r*Z,e+i*Z,n+o*Z];let O=G*I-T*R,J=T*S-N*I,q=N*R-G*S,Q=Math.hypot(O,J,q)||1;return b.normal=[O/Q,J/Q,q/Q],!0}return!1}function tn(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(Ee());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let f of u.children)i.add(f);let o=new Set,s=128,h=(u,f,m=0)=>{if(m>s||u<0||u>=n||o.has(u))return;o.add(u);let d=t.nodes[u];if(!d)return;let y=Ee();if(e&&e[u])y.set(e[u]);else if(d.matrix&&d.matrix.length===16)y.set(d.matrix);else{let M=d.translation||[0,0,0],N=d.rotation||[0,0,0,1],G=d.scale||[1,1,1];pt(y,N,M,G)}let b=r[u];if(f?_e(b,f,y):b.set(y),Array.isArray(d.children))for(let M of d.children)typeof M=="number"&&h(M,b,m+1)},c=[],a=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(a&&Array.isArray(a.nodes))c.push(...a.nodes);else for(let u=0;u<n;u++)i.has(u)||c.push(u);for(let u of c)h(u,null);for(let u=0;u<n;u++)!i.has(u)&&!c.includes(u)&&h(u,null);return r}function gi(t){return new TextDecoder().decode(t)}var Dr=Ae().decoders;function xi(t,e){Dr.set(t.toLowerCase(),e)}function _t(t){return Dr.get(t.toLowerCase())}function kr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let m=n.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),s=12,h=null,c=null;for(;s+8<=o&&s+8<=e.byteLength;){let m=n.getUint32(s,!0),d=n.getUint32(s+4,!0),y=s+8;if(y+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${y+m} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let b=new Uint8Array(e,y,m),M=gi(b);h=JSON.parse(M,(N,G)=>N==="__proto__"||N==="constructor"||N==="prototype"?void 0:G)}else d===5130562&&(c=e.slice(y,y+m));s=y+m}if(!h)throw new Error("Missing JSON chunk in GLB");let a=h.extensionsRequired||[];if(a.includes("KHR_draco_mesh_compression")&&!_t("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(a.includes("EXT_meshopt_compression")&&!_t("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(a.includes("KHR_texture_basisu")&&!_t("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=c||new ArrayBuffer(0),f={gltf:h,bin:u,animations:[]};for(let m of ke)m.onParseGLB?.(f);return f}function vi(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function Ti(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function Nt(t){if(Ti(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return kr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Pr=`#version 300 es
18
19
  layout(location=0) in vec3 aPosition;
19
20
  layout(location=1) in vec3 aNormal;
20
21
  layout(location=2) in vec2 aUV;
@@ -32,7 +33,7 @@ vec2 scaleUV=uUvTransform.zw;
32
33
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
34
  vUV=aUV*scaleUV+uUvTransform.xy;
34
35
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,yr=`#version 300 es
36
+ }`,Mi=`#version 300 es
36
37
  precision highp float;
37
38
  in vec3 vNormal,vWorldPos;
38
39
  in vec2 vUV;
@@ -108,9 +109,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
108
109
  return mix(color,newPeak*vec3(1.0),g);
109
110
  }
110
111
 
112
+ vec3 acesToneMapping(vec3 color){
113
+ color*=0.6;
114
+ return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
115
+ }
116
+
117
+ vec3 agxToneMapping(vec3 color){
118
+ color=max(color,vec3(0.0));
119
+ vec3 inset=vec3(
120
+ 0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
121
+ 0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
122
+ 0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
123
+ vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
124
+ vec3 x2=ev*ev;
125
+ vec3 x4=x2*x2;
126
+ vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
127
+ vec3 outset=vec3(
128
+ 1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
129
+ -0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
130
+ -0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
131
+ return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
132
+ }
133
+
111
134
  vec3 applyToneMapping(vec3 color,int mode){
112
135
  if(mode==0)return neutralToneMapping(color);
113
136
  if(mode==1)return color/(color+vec3(1.0));
137
+ if(mode==3)return acesToneMapping(color);
138
+ if(mode==4)return agxToneMapping(color);
114
139
  return color;
115
140
  }
116
141
 
@@ -198,19 +223,19 @@ color=applyToneMapping(color,uToneMapping);
198
223
  float outAlpha=base.a;
199
224
  /*XRD_O*/
200
225
  fragColor=vec4(color,outAlpha);
201
- }`,gr=`#version 300 es
226
+ }`;var wi=`#version 300 es
202
227
  layout(location=0) in vec3 aPosition;
203
228
  uniform mat4 uMVP;
204
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,xr=`#version 300 es
229
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Si=`#version 300 es
205
230
  precision highp float;
206
231
  uniform vec4 uColorId;
207
232
  out vec4 fragColor;
208
- void main(){fragColor=uColorId;}`;function vn(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function jt(t,e,n){let r=vn(t,35633,e),i=vn(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let c=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${c}`)}return o}function qt(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var Tn=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function Mn(){let t=Q().xrDepthShader;return{fs:yr.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Tn,...t.uniformNames]:Tn}}function vr(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Yt(t,e,n,r,i,o,c){if(r===void 0||!e.accessors?.[r])return null;let h=e.accessors[r],u=e.bufferViews[h.bufferView],s=(u.byteOffset||0)+(h.byteOffset||0),a=u.byteStride&&u.byteStride>o*4?u.byteStride>>2:o,m;if(a===o)m=new Float32Array(n,s,h.count*o);else{m=new Float32Array(h.count*o);let f=new Float32Array(n,u.byteOffset||0,Math.floor(u.byteLength/4)),d=(h.byteOffset||0)>>2;for(let S=0;S<h.count;S++){let A=d+S*a;for(let M=0;M<o;M++)m[S*o+M]=f[A+M]}}let l=t.createBuffer();return c.push(l),t.bindBuffer(34962,l),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var Oi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),An=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function wn(t,e,n=An,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,c=[],h=ut(i),u=[];if(Array.isArray(i.nodes))for(let E=0;E<i.nodes.length;E++){let v=i.nodes[E];v.mesh!==void 0&&i.meshes&&i.meshes[v.mesh]&&u.push({node:v,nodeIdx:E,meshIdx:v.mesh})}let s=u.length>0?u:(i.meshes||[]).map((E,v)=>({node:E,nodeIdx:-1,meshIdx:v})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let E=i.extensions.KHR_lights_punctual.lights;for(let v of E){let _=v.type==="directional"?"directional":v.type==="point"?"point":"ambient";a.push({type:_,color:v.color||[1,1,1],intensity:v.intensity!==void 0?v.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),s.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${s.length}`);let m=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let E=0;E<i.textures.length;E++){let v=i.textures[E],_=i.images[v.source];if(_){let D=t.createTexture();if(t.bindTexture(3553,D),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),_.bufferView!==void 0){let g=i.bufferViews[_.bufferView],T=o.slice(g.byteOffset||0,(g.byteOffset||0)+g.byteLength),x=new Blob([T],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(L=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,L),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let g=vr(_.uri);if(g){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,T),t.generateMipmap(3553),r?.()},T.src=g}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}m.push(D)}else m.push(null)}}let l=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],d=0,S=0;for(let E=0;E<s.length;E++){let v=s[E],_=i.meshes[v.meshIdx],D=v.nodeIdx>=0?h[v.nodeIdx]:Z(),g=new Float32Array(9);ce(g,D);let T={name:v.node.name||_.name||`Mesh_${v.meshIdx}`,nodeIndex:v.nodeIdx,transform:D,normalMatrix:g,primitives:[],extras:v.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let j=Be("draco");j&&j.decodePrimitive(i,x,o)}let L=[],I=t.createVertexArray();t.bindVertexArray(I);let H=i.accessors[x.attributes.POSITION],k=Number(H?.count??0);if(!Number.isFinite(k)||k<0||d+k>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(d+=k,H?.min&&H?.max)for(let j=0;j<3;j++){let le=D[12+j],Ie=D[12+j];for(let pe=0;pe<3;pe++){let rt=D[pe*4+j]*H.min[pe],it=D[pe*4+j]*H.max[pe];le+=rt<it?rt:it,Ie+=rt>it?rt:it}le<l[j]&&(l[j]=le),Ie>f[j]&&(f[j]=Ie)}let U=Yt(t,i,o,x.attributes.POSITION,0,3,L);Yt(t,i,o,x.attributes.NORMAL,1,3,L),Yt(t,i,o,x.attributes.TEXCOORD_0,2,2,L);let N=0,C=5123,O=null;if(x.indices!==void 0){let j=i.accessors[x.indices],Ie=(i.bufferViews[j.bufferView].byteOffset||0)+(j.byteOffset||0);if(N=Number(j.count??0),!Number.isFinite(N)||N<0||S+N>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);S+=N,C=j.componentType===5125?5125||5125:5123||5123;let pe=t.createBuffer();L.push(pe),t.bindBuffer(34963,pe),j.componentType===5125?(O=new Uint32Array(o,Ie,j.count),t.bufferData(34963,O,35044)):(O=new Uint16Array(o,Ie,j.count),t.bufferData(34963,O,35044))}else N=H.count;let F={};for(let j of ee)if(j.onBuildPrimitiveVAO){let le=j.onBuildPrimitiveVAO(t,I,x,i,o);le&&(F[j.name]=le)}t.bindVertexArray(null);let V=i.materials&&x.material!==void 0?i.materials[x.material]:null,z=Mn(),X=Rn,Y=z.fs,$=!1;for(let j of ee)if(j.onResolveShader){let le=j.onResolveShader(x,V,X,Y);le&&(X=le.vs,Y=le.fs,$=!0)}let ae=$?jt(t,X,Y):null,ye=ae?qt(t,ae,z.uniforms):null,K=V?.pbrMetallicRoughness,ge=K?.baseColorFactor||[.8,.8,.8,1],xe=K?.metallicFactor??.1,ve=K?.roughnessFactor??.5,re=V?.extensions?.KHR_materials_clearcoat,Te=re?re.clearcoatFactor??1:0,we=Math.max(.04,re?.clearcoatRoughnessFactor??.04),ze=K?.baseColorTexture!==void 0&&m[K.baseColorTexture.index]?m[K.baseColorTexture.index]:null,nr=K?.metallicRoughnessTexture!==void 0&&m[K.metallicRoughnessTexture.index]?m[K.metallicRoughnessTexture.index]:null,rr=V?.normalTexture!==void 0&&m[V.normalTexture.index]?m[V.normalTexture.index]:null,ir=V?.normalTexture?.scale??1,or=V?.occlusionTexture!==void 0&&m[V.occlusionTexture.index]?m[V.occlusionTexture.index]:null,sr=V?.occlusionTexture?.strength??1,ar=!!(V?.extensions?.KHR_materials_transmission||F.materials?.isTransmissive);T.primitives.push({vao:I,indexCount:N,indexType:C,baseColor:ge,metallic:xe,roughness:ve,clearcoat:Te,clearcoatRoughness:we,positions:U,indices:O,texture:ze,metallicRoughnessTexture:nr,normalTexture:rr,occlusionTexture:or,normalScale:ir,occlusionStrength:sr,buffers:L,materialIndex:x.material,pluginData:F,customProgram:ae,customUniforms:ye,isTransmissive:ar})}c.push(T)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let A=[(l[0]+f[0])/2,(l[1]+f[1])/2,(l[2]+f[2])/2],M=f[0]-l[0],P=f[1]-l[1],y=f[2]-l[2],w=Math.max(Math.hypot(M,P,y)/2,.5),b=[l[0],l[1],l[2]],R=[f[0],f[1],f[2]],p=e.animations;if(!p){for(let E of ee)if(E.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:c,bounds:{center:A,radius:w,min:b,max:R},lights:a,animations:p,worldMatrices:h}}var lt=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=Z();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=Z();this.viewMatrix=Z();this.modelMatrix=Z();this.mvpMatrix=Z();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:Z(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let s=e.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",e.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let h=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h;let u=Mn();this.renderProg=jt(h,Rn,u.fs),this.pickProg=jt(h,gr,xr),this.uRender=qt(h,this.renderProg,u.uniforms),this.uPick=qt(h,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){pr(e,n)}static getDecoder(e){return Be(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:c,worldMatrices:h}=wn(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=c||[],this.worldMatrices=h||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let s of e.gltf.nodes)this.initialNodeTransforms.push({t:s.translation?[s.translation[0],s.translation[1],s.translation[2]]:[0,0,0],r:s.rotation?[s.rotation[0],s.rotation[1],s.rotation[2],s.rotation[3]]:[0,0,0,1],s:s.scale?[s.scale[0],s.scale[1],s.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let s of ee)s.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Sn(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Ve(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ve(e),{meshes:i}=wn(this.gl,r,An,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],ce(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),ce(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],c=[],h=[];for(let u of this.lights){let s=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[s[0]*a,s[1]*a,s[2]*a];else if(u.type==="directional"&&i.length<6){let m=u.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(s[0]*a,s[1]*a,s[2]*a)}else if(u.type==="point"&&c.length<6){let m=u.position||[0,0,0];c.push(m[0],m[1],m[2]),h.push(s[0]*a,s[1]*a,s[2]*a)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(n.uniform3fv(e.uPointLightPos,c),n.uniform3fv(e.uPointLightColor,h)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ee)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ee)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],c=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],h=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,u=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:c,metallicFactor:h,roughnessFactor:u,setBaseColorFactor:a=>{let m=[a[0],a[1],a[2],a[3]??1];s.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let l of i)l.baseColor=m;this.render()},setMetallicFactor:a=>{s.metallicFactor=a,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=a);for(let m of i)m.metallic=a;this.render()},setRoughnessFactor:a=>{s.roughnessFactor=a,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=a);for(let m of i)m.roughness=a;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:s}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of ee)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,n){let r=Z();ie(r,this.projMatrix,this.viewMatrix);let[i,o,c]=e,h=n?n[0]:0,u=n?n[1]:0,s=n?n[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],o=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],n&&(h=a[0]*n[0]+a[4]*n[1]+a[8]*n[2],u=a[1]*n[0]+a[5]*n[1]+a[9]*n[2],s=a[2]*n[0]+a[6]*n[1]+a[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*c+r[12],l=r[1]*i+r[5]*o+r[9]*c+r[13],f=r[2]*i+r[6]*o+r[10]*c+r[14],d=r[3]*i+r[7]*o+r[11]*c+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let S=m/d,A=l/d,M=f/d,P=this.canvas.getBoundingClientRect(),y=P.width||this.canvas.clientWidth||this.canvas.width||300,w=P.height||this.canvas.clientHeight||this.canvas.height||150,b=(S*.5+.5)*y,R=(-A*.5+.5)*w,p=S>=-1.1&&S<=1.1&&A>=-1.1&&A<=1.1&&M>=-1&&M<=1;if(p&&n){let E=this.customTarget||this.bounds.center,v=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=E[1]+this.currDistance*Math.sin(this.currPhi),D=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=[i-v,o-_,c-D];h*g[0]+u*g[1]+s*g[2]>.05&&(p=!1)}return{x:b,y:R,z:M,visible:p}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+o*h[0])*s,u[1]+=(-i*c[1]+o*h[1])*s,u[2]+=(-i*c[2]+o*h[2])*s,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,c=r.height||300,h=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),u=i.height>0?Math.floor((n-i.top)*(c/i.height)):Math.floor(n);return this.performMeshPick(h,u,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let h=Z();ie(h,this.projMatrix,this.viewMatrix);let u=[],s=Math.max(0,Math.min(o-1,e)),a=Math.max(0,Math.min(c-1,c-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==c)&&this.resizePickingFbo(o,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let p=0;p<this.meshes.length;p++){let E=this.meshes[p];if(E.visible===!1||E.isPluginMesh)continue;let v=p+1,_=(v&255)/255,D=(v>>8&255)/255,g=(v>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,D,g,1),ie(this.modelMatrix,this.modelRootMatrix,E.transform),ie(this.mvpMatrix,h,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let T of E.primitives)i.bindVertexArray(T.vao),i.drawElements(4,T.indexCount,T.indexType,0)}let b=new Uint8Array(4);i.readPixels(s,a,1,1,6408,5121,b),i.bindFramebuffer(36160,null);let R=b[0]+(b[1]<<8)+(b[2]<<16);R>0&&R<=this.meshes.length&&(u=[this.meshes[R-1]])}u.length===0&&(u=this.meshes.filter(b=>b.visible!==!1));let m=null,l=1/0,f=[0,0,0],d=[0,1,0],S=this.customTarget||this.bounds.center,A=S[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),M=S[1]+this.currDistance*Math.sin(this.currPhi),P=S[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let b of u){ie(this.modelMatrix,this.modelRootMatrix,b.transform),ie(this.mvpMatrix,h,this.modelMatrix);let R=Z();if(!gn(R,this.mvpMatrix))continue;let p=(s+.5)/o*2-1,E=(a+.5)/c*2-1,v=[0,0,0],_=[0,0,0];$t(v,p,E,-1,R),$t(_,p,E,1,R);let D=_[0]-v[0],g=_[1]-v[1],T=_[2]-v[2],x=Math.hypot(D,g,T)||1,L=D/x,I=g/x,H=T/x,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((N=>{for(let C of b.primitives){if(!C.positions)continue;let O=C.positions,F=C.indices,V=Math.floor(F?F.length/3:O.length/9);for(let z=0;z<V;z++){let X=F?F[z*3]:z*3,Y=F?F[z*3+1]:z*3+1,$=F?F[z*3+2]:z*3+2;xn(v[0],v[1],v[2],L,I,H,O[X*3],O[X*3+1],O[X*3+2],O[Y*3],O[Y*3+1],O[Y*3+2],O[$*3],O[$*3+1],O[$*3+2],k,N)}}})(1e-4),isFinite(k.distance)){let N=k.point[0],C=k.point[1],O=k.point[2],F=this.modelMatrix,V=F[0]*N+F[4]*C+F[8]*O+F[12],z=F[1]*N+F[5]*C+F[9]*O+F[13],X=F[2]*N+F[6]*C+F[10]*O+F[14],Y=V-A,$=z-M,ae=X-P,ye=Math.hypot(Y,$,ae);if(ye<l){ce(this.normalMatrix,this.modelMatrix);let K=this.normalMatrix,ge=k.normal[0],xe=k.normal[1],ve=k.normal[2],re=K[0]*ge+K[3]*xe+K[6]*ve,Te=K[1]*ge+K[4]*xe+K[7]*ve,we=K[2]*ge+K[5]*xe+K[8]*ve,ze=Math.hypot(re,Te,we)||1;re/=ze,Te/=ze,we/=ze,re*Y+Te*$+we*ae>0&&(re=-re,Te=-Te,we=-we),m=b,l=Math.round(ye*1e3)/1e3,f=[Math.round(V*1e3)/1e3,Math.round(z*1e3)/1e3,Math.round(X*1e3)/1e3],d=[Math.round(re*1e3)/1e3,Math.round(Te*1e3)/1e3,Math.round(we*1e3)/1e3]}}}if(!m)return null;let w={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:l,hitPoint:f,normal:d,screenX:e,screenY:n};if(r){for(let b of ee)b.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,c=i?Math.max(1,n-r):r,h=(o+.5)/c*2-1;return Math.floor((h*.5+1)*.5*n)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);at(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Pe(this.viewMatrix,[i,o,c],r,[0,1,0]),ie(this.mvpMatrix,this.projMatrix,this.viewMatrix),ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of ee)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of ee)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of ee)c.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let c of ee)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let c={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,n,r,i,o=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let h=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,s=e?.transform?.position,a=s?[s.x,s.y,s.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:h,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),b=Math.max(1,this.canvas.height||1),R=Math.max(1,Math.floor(w*.5)),p=Math.max(1,w-R),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,_=v[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=v[1]+this.currDistance*Math.sin(this.currPhi),g=v[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),T=Math.cos(this.currTheta),x=-Math.sin(this.currTheta),L=.032,I=Z(),H=Z(),k=[_-T*L,D,g-x*L],U=[v[0]-T*L*.25,v[1],v[2]-x*L*.25];at(I,this.fov,R/b,.1,E),Pe(H,k,U,[0,1,0]);let N=Z(),C=Z(),O=[_+T*L,D,g+x*L],F=[v[0]+T*L*.25,v[1],v[2]+x*L*.25];at(N,this.fov,p/b,.1,E),Pe(C,O,F,[0,1,0]),this.render({viewMatrix:H,projMatrix:I,eyePos:k,viewport:[0,0,R,b],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:C,projMatrix:N,eyePos:O,viewport:[R,0,p,b],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,b);return}let n=this.gl,r=0,i=0,o=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],c=e.viewport[3],n.viewport(r,i,o,c)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let h=Z(),u=e?.viewMatrix??this.viewMatrix;ie(h,e?.projMatrix??this.projMatrix,u);let s=Q().xrDepthShader,a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),f=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),d=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let w of ee)w.onBeforeDrawScene?.(this,n,h,[l,f,d],a);let S=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let A=e?.eye||"none",M=!1,P=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=w=>{for(let b=0;b<P.length;b++){let R=P[b];if(R.visible===!1)continue;let p=this.selectedMeshName!==""&&R.name===this.selectedMeshName;b<S||R.worldSpace===!0||R.name==="__xr_reticle__"?this.modelMatrix.set(R.transform):ie(this.modelMatrix,this.modelRootMatrix,R.transform),ie(this.mvpMatrix,h,this.modelMatrix),ce(R.normalMatrix,this.modelMatrix);let E=R.extras?.xr?.stereo||R.userData?.xr?.stereo,v=0,_=0,D=1,g=1;E==="sbs"?(D=.5,v=A==="right"?.5:0):E==="ou"&&(g=.5,_=A==="right"?.5:0);for(let T of R.primitives){let x=!!T.isTransmissive;if(!w&&x){M=!0;continue}if(w&&!x)continue;let L=T.customProgram||this.renderProg,I=T.customUniforms||this.uRender;n.useProgram(L),n.uniform1i(I.uToneMapping,a),n.uniform1f(I.uEnvIntensity,this.envIntensity),n.uniform3f(I.uCameraPos,l,f,d),n.uniform1f(I.uEmissive,p?1:0),n.uniformMatrix4fv(I.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(I.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(I.uNormalMatrix,!1,R.normalMatrix),I.uUvTransform&&n.uniform4f(I.uUvTransform,v,_,D,g),I.uViewportSize&&n.uniform2f(I.uViewportSize,Math.max(1,o),Math.max(1,c)),s?.bind(n,I,this.xrDepthState,u,[r,i,Math.max(1,o),Math.max(1,c)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(I.uEnvironmentMap,4),n.uniform1i(I.uHasEnvironmentMap,1)):n.uniform1i(I.uHasEnvironmentMap,0),this.bindLights(I),I.uSectionEnabled&&n.uniform1i(I.uSectionEnabled,0);for(let H of ee)H.onBeforeDrawPrimitive?.(n,L,T,R,this.worldMatrices||[],this.gltf);n.uniform4fv(I.uBaseColor,T.baseColor),n.uniform1f(I.uMetallic,T.metallic),n.uniform1f(I.uRoughness,T.roughness),I.uClearcoat&&n.uniform2f(I.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(n.activeTexture(33984),n.bindTexture(3553,T.texture),n.uniform1i(I.uBaseColorTexture,0),n.uniform1i(I.uHasTexture,1)):n.uniform1i(I.uHasTexture,0),T.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,T.metallicRoughnessTexture),n.uniform1i(I.uMetallicRoughnessTexture,1),n.uniform1i(I.uHasMetallicRoughnessTexture,1)):n.uniform1i(I.uHasMetallicRoughnessTexture,0),T.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,T.normalTexture),n.uniform1i(I.uNormalTexture,2),n.uniform1i(I.uHasNormalTexture,1),n.uniform1f(I.uNormalScale,T.normalScale)):n.uniform1i(I.uHasNormalTexture,0),T.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,T.occlusionTexture),n.uniform1i(I.uOcclusionTexture,3),n.uniform1i(I.uHasOcclusionTexture,1),n.uniform1f(I.uOcclusionStrength,T.occlusionStrength)):n.uniform1i(I.uHasOcclusionTexture,0),n.bindVertexArray(T.vao),n.drawElements(4,T.indexCount,T.indexType,0)}}};if(y(!1),M){for(let w of ee)w.onBeforeTransmissivePass?.(n,this);y(!0)}for(let w of ee)w.onAfterRender?.(n,this,h)}disposeMeshListGpuResources(e){let n=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&n.deleteVertexArray(i.vao),i.buffers)for(let o of i.buffers)n.deleteBuffer(o);i.texture&&n.deleteTexture(i.texture),i.metallicRoughnessTexture&&n.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&n.deleteTexture(i.normalTexture),i.occlusionTexture&&n.deleteTexture(i.occlusionTexture),i.customProgram&&n.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ee)n.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};lt.registerPlugin=bn,lt.getRegisteredPlugins=yn;function Tr(t){return t+3&-4}function wr(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function Le(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],c=[],h=[],u=new Set,s=[],a=[],m=new Map,l=[];function f(p,E){let v=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),_=Tr(v.byteLength),D=new Uint8Array(_);D.set(v),n.push(D);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:v.byteLength,target:E}),r+=_,g}function d(p,E,v,_,D,g,T){let x=f(p,v),L=o.length,I={bufferView:x,byteOffset:0,componentType:_,count:D,type:E};return g&&(I.min=g),T&&(I.max=T),o.push(I),L}t.traverse(p=>{(p.isLight||p.color&&p.intensity!==void 0)&&l.push({type:p.type,color:[p.color.r,p.color.g,p.color.b],intensity:p.intensity,position:[p.position.x,p.position.y,p.position.z]})});let S=[];function A(p){let E={name:p.name||""},v=p.position,_=p.quaternion,D=p.scale;if((v.x||v.y||v.z)&&(E.translation=[v.x,v.y,v.z]),(_.x||_.y||_.z||_.w!==1)&&(E.rotation=[_.x,_.y,_.z,_.w]),(D.x!==1||D.y!==1||D.z!==1)&&(E.scale=[D.x,D.y,D.z]),p.userData&&Object.keys(p.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(p.userData,(T,x)=>{if(!(T==="__proto__"||T==="prototype"||T==="constructor"))return typeof x=="function"?void 0:x})),p.userData.xr)){let T=wr(p.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:T,ANDROID_xr_scenecore:T},Q().xrTraitSerializer?.gltfNode(E,p.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(p.geometry){let T=p.geometry,x=T.attributes.position;if(x&&x.count>0){let L=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0];for(let N=0;N<x.count;N++){let C=x.getX(N),O=x.getY(N),F=x.getZ(N);C<L[0]&&(L[0]=C),C>I[0]&&(I[0]=C),O<L[1]&&(L[1]=O),O>I[1]&&(I[1]=O),F<L[2]&&(L[2]=F),F>I[2]&&(I[2]=F)}let k={attributes:{POSITION:d(x.array,"VEC3",34962,5126,x.count,L,I)}};if(T.attributes.normal&&(k.attributes.NORMAL=d(T.attributes.normal.array,"VEC3",34962,5126,T.attributes.normal.count)),T.attributes.uv&&(k.attributes.TEXCOORD_0=d(T.attributes.uv.array,"VEC2",34962,5126,T.attributes.uv.count)),T.index){let N=T.index.array instanceof Uint32Array;k.indices=d(T.index.array,"SCALAR",34963,N?5125:5123,T.index.count)}if(p.material){let N=m.get(p.material);if(N===void 0){N=a.length,m.set(p.material,N);let C=p.material,O={name:C.name||"",pbrMetallicRoughness:{baseColorFactor:[C.color.r,C.color.g,C.color.b,C.opacity],metallicFactor:C.metalness,roughnessFactor:C.roughness},doubleSided:C.side===2||C.doubleSided};if(C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0)){let V=C.emissiveIntensity??1;O.emissiveFactor=[C.emissive.r*V,C.emissive.g*V,C.emissive.b*V]}let F={};C.clearcoat>0&&(F.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen>0&&(F.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission>0&&(F.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness>0&&(F.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(F.KHR_materials_ior={ior:C.ior}),C.dispersion>0&&(F.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence>0&&(F.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3}),Object.keys(F).length>0&&(O.extensions=F),a.push(O)}k.material=N}let U=c.length;c.push({primitives:[k],name:p.name,...E.extras?{extras:E.extras}:{}}),E.mesh=U}}let g=h.length;if(h.push(E),s.push(p),p.children.length>0){E.children=[];for(let T of p.children)E.children.push(A(T))}return g}for(let p of t.children)S.push(A(p));let M=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof M=="function"&&s.length>0){let p=e?.duration??4,E=e?.fps??15,v=Math.max(2,Math.round(p*E)+1),_=new Float32Array(v),D=s.map(U=>({px:U.position.x,py:U.position.y,pz:U.position.z,qx:U.quaternion.x,qy:U.quaternion.y,qz:U.quaternion.z,qw:U.quaternion.w,sx:U.scale.x,sy:U.scale.y,sz:U.scale.z})),g=s.map(()=>new Float32Array(v*3)),T=s.map(()=>new Float32Array(v*4)),x=s.map(()=>new Float32Array(v*3));for(let U=0;U<v;U++){let N=U/(v-1)*p;_[U]=N;try{M(N)}catch{}for(let C=0;C<s.length;C++){let O=s[C];g[C][U*3]=O.position.x,g[C][U*3+1]=O.position.y,g[C][U*3+2]=O.position.z,T[C][U*4]=O.quaternion.x,T[C][U*4+1]=O.quaternion.y,T[C][U*4+2]=O.quaternion.z,T[C][U*4+3]=O.quaternion.w,x[C][U*3]=O.scale.x,x[C][U*3+1]=O.scale.y,x[C][U*3+2]=O.scale.z}}for(let U=0;U<s.length;U++){let N=s[U],C=D[U];N.position.set(C.px,C.py,C.pz),N.quaternion.set(C.qx,C.qy,C.qz,C.qw),N.scale.set(C.sx,C.sy,C.sz)}t.updateMatrixWorld(!0);let L=null,I=()=>(L===null&&(L=d(_,"SCALAR",0,5126,v,[0],[p])),L),H=[],k=[];for(let U=0;U<s.length;U++){let N=D[U],C=!1,O=!1,F=!1;for(let V=0;V<v;V++)(Math.abs(g[U][V*3]-N.px)>1e-4||Math.abs(g[U][V*3+1]-N.py)>1e-4||Math.abs(g[U][V*3+2]-N.pz)>1e-4)&&(C=!0),(Math.abs(T[U][V*4]-N.qx)>1e-4||Math.abs(T[U][V*4+1]-N.qy)>1e-4||Math.abs(T[U][V*4+2]-N.qz)>1e-4||Math.abs(T[U][V*4+3]-N.qw)>1e-4)&&(O=!0),(Math.abs(x[U][V*3]-N.sx)>1e-4||Math.abs(x[U][V*3+1]-N.sy)>1e-4||Math.abs(x[U][V*3+2]-N.sz)>1e-4)&&(F=!0);if(C){let V=d(g[U],"VEC3",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"translation"}})}if(O){let V=d(T[U],"VEC4",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"rotation"}})}if(F){let V=d(x[U],"VEC3",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"scale"}})}}k.length>0&&P.push({name:"ProceduralLoop",samplers:H,channels:k})}let y=ot(h,c,t.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:S}],scene:0,nodes:h,meshes:c,materials:a,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},b=new Uint8Array(r),R=0;for(let p of n)b.set(p,R),R+=p.byteLength;return{gltf:w,bin:b.buffer,lights:l,environmentIntensity:t.environmentIntensity}}function mt(t){return new TextEncoder().encode(t)}function He(t,e){let{gltf:n,bin:r}=Le(t,e),i=JSON.stringify(n),o=mt(i),c=(4-o.byteLength%4)%4,h=o.byteLength+c,u=20+h+8+r.byteLength,s=new Uint8Array(u),a=new DataView(s.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,h,!0),a.setUint32(16,1313821514,!0),s.set(o,20);for(let l=0;l<c;l++)s[20+o.byteLength+l]=32;let m=20+h;return a.setUint32(m,r.byteLength,!0),a.setUint32(m+4,5130562,!0),s.set(new Uint8Array(r),m+8),s}function Er(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let c=o.count,h=new Float32Array(c*3),u=r.matrixWorld.elements;for(let p=0;p<c;p++){let E=o.getX(p),v=o.getY(p),_=o.getZ(p);h[p*3]=u[0]*E+u[4]*v+u[8]*_+u[12],h[p*3+1]=u[1]*E+u[5]*v+u[9]*_+u[13],h[p*3+2]=u[2]*E+u[6]*v+u[10]*_+u[14]}let s;if(i.attributes.normal){let p=i.attributes.normal;s=new Float32Array(c*3);let E=new Float32Array(9);ce(E,u);for(let v=0;v<c;v++){let _=p.getX(v),D=p.getY(v),g=p.getZ(v),T=E[0]*_+E[3]*D+E[6]*g,x=E[1]*_+E[4]*D+E[7]*g,L=E[2]*_+E[5]*D+E[8]*g,I=Math.hypot(T,x,L)||1;s[v*3]=T/I,s[v*3+1]=x/I,s[v*3+2]=L/I}}let a;if(i.attributes.uv){let p=i.attributes.uv;a=new Float32Array(c*2);for(let E=0;E<c;E++)a[E*2]=p.getX(E),a[E*2+1]=p.getY(E)}let m;if(i.index)m=i.index.array;else{m=c>65535?new Uint32Array(c):new Uint16Array(c);for(let p=0;p<c;p++)m[p]=p}let l="DefaultMaterial",f=[.8,.8,.8],d=.5,S=.1,A=0,M=0,P=1.5,y=1,w=[0,0,0];if(r.material){let p=r.material;l=p.name||`Material_${n.length}`,p.color&&(f=[p.color.r,p.color.g,p.color.b]),typeof p.roughness=="number"&&(d=p.roughness),typeof p.metalness=="number"&&(S=p.metalness),typeof p.clearcoat=="number"&&(A=p.clearcoat),typeof p.clearcoatRoughness=="number"&&(M=p.clearcoatRoughness),typeof p.ior=="number"&&(P=p.ior);let E=typeof p.opacity=="number"?p.opacity:1,v=typeof p.transmission=="number"?p.transmission:0;if(y=E*(1-v),p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let _=p.emissiveIntensity??1;w=[p.emissive.r*_,p.emissive.g*_,p.emissive.b*_]}}let b,R=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof R=="function"){let p=e?.duration??4,E=e?.fps??4,v=Math.max(2,Math.round(p*E)+1),_=[],D=[],g=[],T=[],x=[r.position.x,r.position.y,r.position.z],L=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],I=[r.scale.x,r.scale.y,r.scale.z],H=!1;for(let k=0;k<v;k++){let U=k/(v-1)*p;_.push(U);try{R(U)}catch{}D.push([r.position.x,r.position.y,r.position.z]),g.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),T.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-x[0])>1e-4||Math.abs(r.position.y-x[1])>1e-4||Math.abs(r.position.z-x[2])>1e-4||Math.abs(r.quaternion.x-L[0])>1e-4||Math.abs(r.quaternion.y-L[1])>1e-4||Math.abs(r.quaternion.z-L[2])>1e-4||Math.abs(r.quaternion.w-L[3])>1e-4||Math.abs(r.scale.x-I[0])>1e-4)&&(H=!0)}r.position.set(x[0],x[1],x[2]),r.quaternion.set(L[0],L[1],L[2],L[3]),r.scale.set(I[0],I[1],I[2]),H&&(b={times:_,translations:D,rotations:g,scales:T})}n.push({name:r.name||`Mesh_${n.length}`,positions:h,indices:m,normals:s,uvs:a,materialName:l,color:f,roughness:d,metallic:S,clearcoat:A,clearcoatRoughness:M,ior:P,opacity:y,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:b})}}),n}function Dn(t){let e=[],n=t.gltf,r=t.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=n.accessors||[],c=n.bufferViews||[],h=n.materials||[],u=n.meshes||[],s=n.nodes||[];function a(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let S=c[d.bufferView||0],A=(S.byteOffset||0)+(d.byteOffset||0),M=S.byteLength||0,P=i.slice(A,A+M);return{acc:d,buffer:P}}let m=new Map;if(s.length>0){let f=ut(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function l(f,d,S,A){let M=u[f];if(!M)return;let P=new Float32Array(9);ce(P,d);for(let y=0;y<(M.primitives||[]).length;y++){let w=M.primitives[y],b=w.attributes?.POSITION;if(b===void 0)continue;let{acc:R,buffer:p}=a(b),E=new Float32Array(p,0,R.count*3),v=new Float32Array(E.length);for(let z=0;z<R.count;z++){let X=E[z*3],Y=E[z*3+1],$=E[z*3+2];v[z*3]=d[0]*X+d[4]*Y+d[8]*$+d[12],v[z*3+1]=d[1]*X+d[5]*Y+d[9]*$+d[13],v[z*3+2]=d[2]*X+d[6]*Y+d[10]*$+d[14]}let _,D=w.attributes?.NORMAL;if(D!==void 0){let{acc:z,buffer:X}=a(D),Y=new Float32Array(X,0,z.count*3);_=new Float32Array(Y.length);for(let $=0;$<z.count;$++){let ae=Y[$*3],ye=Y[$*3+1],K=Y[$*3+2],ge=P[0]*ae+P[3]*ye+P[6]*K,xe=P[1]*ae+P[4]*ye+P[7]*K,ve=P[2]*ae+P[5]*ye+P[8]*K,re=Math.hypot(ge,xe,ve)||1;_[$*3]=ge/re,_[$*3+1]=xe/re,_[$*3+2]=ve/re}}let g,T=w.attributes?.TEXCOORD_0;if(T!==void 0){let{acc:z,buffer:X}=a(T);g=new Float32Array(X,0,z.count*2)}let x;if(w.indices!==void 0){let{acc:z,buffer:X}=a(w.indices);z.componentType===5125?x=new Uint32Array(X,0,z.count):x=new Uint16Array(X,0,z.count);let Y=R.count;for(let $ of x)if($>=Y)throw new Error(`SecurityError: Index buffer value (${$}) out of vertex bounds [0, ${Y}).`)}else{let z=R.count;x=z>65535?new Uint32Array(z):new Uint16Array(z);for(let X=0;X<z;X++)x[X]=X}let L="DefaultMaterial",I=[.8,.8,.8],H=.5,k=.1,U=0,N=0,C=1.5,O=1,F=[0,0,0];if(w.material!==void 0&&h[w.material]){let z=h[w.material];L=z.name||`Material_${w.material}`;let X=z.pbrMetallicRoughness||{},Y=1;Array.isArray(X.baseColorFactor)&&(I=[X.baseColorFactor[0],X.baseColorFactor[1],X.baseColorFactor[2]],typeof X.baseColorFactor[3]=="number"&&(Y=X.baseColorFactor[3])),typeof X.roughnessFactor=="number"&&(H=X.roughnessFactor),typeof X.metallicFactor=="number"&&(k=X.metallicFactor),Array.isArray(z.emissiveFactor)&&z.emissiveFactor.length>=3&&(F=[z.emissiveFactor[0],z.emissiveFactor[1],z.emissiveFactor[2]]);let $=z.extensions||{};$.KHR_materials_clearcoat&&(U=$.KHR_materials_clearcoat.clearcoatFactor??0,N=$.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),$.KHR_materials_ior&&typeof $.KHR_materials_ior.ior=="number"&&(C=$.KHR_materials_ior.ior);let ae=$.KHR_materials_transmission?.transmissionFactor??0;O=Y*(1-ae)}let V=(M.primitives||[]).length>1?`${S}_p${y}`:S;e.push({name:V,positions:v,indices:x,normals:_,uvs:g,materialName:L,color:I,roughness:H,metallic:k,clearcoat:U,clearcoatRoughness:N,ior:C,opacity:O,emissiveColor:F,xrTraits:A?.xr||M.extras?.xr})}}if(s.length>0)for(let f=0;f<s.length;f++){let d=s[f];if(d.mesh!==void 0&&d.mesh<u.length){let S=m.get(f)||Z(),A=d.name||u[d.mesh].name||`Node_${f}`;l(d.mesh,S,A,d.extras)}}else{let f=Z();for(let d=0;d<u.length;d++){let S=u[d].name||`Mesh_${d}`;l(d,f,S,u[d].extras)}}return e}function Kt(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function _n(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function W(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function Cn(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${W(t[r*3])}, ${W(t[r*3+1])}, ${W(t[r*3+2])})`;return n.join(", ")}function Sr(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${W(t[r*2])}, ${W(1-t[r*2+1])})`;return n.join(", ")}function Rr(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function Zt(t){let e=new Map;for(let u of t){let s=Kt(u.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let n=0,r=null;for(let u of t){if(u.timeSamples&&u.timeSamples.times.length>0){let s=u.timeSamples.times[u.timeSamples.times.length-1];s>n&&(n=s)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
209
- endTimeCode = ${W(n)}
233
+ void main(){fragColor=uColorId;}`;function _r(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Hn(t,e,n){let r=_r(t,35633,e),i=_r(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let s=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${s}`)}return o}function Xn(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var Cr=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function Lr(){let t=Ae().xrDepthShader;return{fs:Mi.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Cr,...t.uniformNames]:Cr}}function Ai(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Gn(t,e,n,r,i,o,s){if(r===void 0||!e.accessors?.[r])return null;let h=e.accessors[r],c=e.bufferViews[h.bufferView],a=(c.byteOffset||0)+(h.byteOffset||0),u=c.byteStride&&c.byteStride>o*4?c.byteStride>>2:o,f;if(u===o)f=new Float32Array(n,a,h.count*o);else{f=new Float32Array(h.count*o);let d=new Float32Array(n,c.byteOffset||0,Math.floor(c.byteLength/4)),y=(h.byteOffset||0)>>2;for(let b=0;b<h.count;b++){let M=y+b*u;for(let N=0;N<o;N++)f[b*o+N]=d[M+N]}}let m=t.createBuffer();return s.push(m),t.bindBuffer(34962,m),t.bufferData(34962,f,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),f}var ns=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Nr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ir(t,e,n=Nr,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i}=e,o=_t("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(i,e);let s=e.bin,h=[],c=[],a=i.extensions?.KHR_materials_variants;if(a&&Array.isArray(a.variants))for(let p of a.variants)p&&typeof p.name=="string"&&c.push(p.name);let u=tn(i),f=[];if(Array.isArray(i.nodes))for(let p=0;p<i.nodes.length;p++){let k=i.nodes[p];k.mesh!==void 0&&i.meshes&&i.meshes[k.mesh]&&f.push({node:k,nodeIdx:p,meshIdx:k.mesh})}let m=f.length>0?f:(i.meshes||[]).map((p,k)=>({node:p,nodeIdx:-1,meshIdx:k})),d=[];if(Array.isArray(e.lights)&&e.lights.length>0)d.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let p=i.extensions.KHR_lights_punctual.lights;for(let k of p){let l=k.type==="directional"?"directional":k.type==="point"?"point":"ambient";d.push({type:l,color:k.color||[1,1,1],intensity:k.intensity!==void 0?k.intensity:1})}}if(d.length===0&&(d.push({type:"ambient",color:[1,1,1],intensity:.35}),d.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),m.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${m.length}`);let y=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let p=0;p<i.textures.length;p++){let k=i.textures[p],l=i.images[k.source];if(l){let g=t.createTexture();if(t.bindTexture(3553,g),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),l.bufferView!==void 0){let L=i.bufferViews[l.bufferView],D=s.slice(L.byteOffset||0,(L.byteOffset||0)+L.byteLength),H=new Blob([D],{type:l.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(H).then(X=>{t.bindTexture(3553,g),t.texImage2D(3553,0,6408,6408,5121,X),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(l.uri){let L=Ai(l.uri);if(L){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{t.bindTexture(3553,g),t.texImage2D(3553,0,6408,6408,5121,D),t.generateMipmap(3553),r?.()},D.src=L}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",l.uri)}y.push(g)}else y.push(null)}}let b=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],N=0,G=0;for(let p=0;p<m.length;p++){let k=m[p],l=i.meshes[k.meshIdx],g=k.nodeIdx>=0?u[k.nodeIdx]:Ee(),L=new Float32Array(9);ze(L,g);let D={name:k.node.name||l.name||`Mesh_${k.meshIdx}`,nodeIndex:k.nodeIdx,transform:g,normalMatrix:L,primitives:[],extras:k.node.extras||l.extras},H=k.node?.extensions?.EXT_mesh_gpu_instancing;if(H&&H.attributes&&typeof H.attributes=="object"){let X=H.attributes,K=X.TRANSLATION!==void 0?i.accessors?.[X.TRANSLATION]:null,Z=X.ROTATION!==void 0?i.accessors?.[X.ROTATION]:null,O=X.SCALE!==void 0?i.accessors?.[X.SCALE]:null,J=X._COLOR_0!==void 0?i.accessors?.[X._COLOR_0]:null,q=Number(K?.count??Z?.count??O?.count??0);if(!Number.isFinite(q)||q<0||q>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${q}`);if(q>0){let Q=(v,C)=>{if(!v||v.bufferView===void 0||!i.bufferViews?.[v.bufferView])return null;let F=(i.bufferViews[v.bufferView].byteOffset||0)+(v.byteOffset||0);return vi(s,F,q*C)},se=Q(K,3),B=Q(Z,4),$=Q(O,3),ae=J?.type==="VEC4"?4:3,ie=Q(J,ae),A=new Float32Array(q*16),x=Ee();for(let v=0;v<q;v++){let C=se?[se[v*3],se[v*3+1],se[v*3+2]]:[0,0,0],P=B?[B[v*4],B[v*4+1],B[v*4+2],B[v*4+3]]:[0,0,0,1],F=$?[$[v*3],$[v*3+1],$[v*3+2]]:[1,1,1];pt(x,P,C,F),A.set(x,v*16)}if(D.instanceMatrices=A,ie){let v=new Float32Array(q*3);for(let C=0;C<q;C++)v[C*3]=ie[C*ae],v[C*3+1]=ie[C*ae+1],v[C*3+2]=ie[C*ae+2];D.instanceColors=v}}}for(let X of l.primitives||[]){if(X.extensions?.KHR_draco_mesh_compression){let le=_t("draco");le&&le.decodePrimitive(i,X,s)}let K=[],Z=t.createVertexArray();t.bindVertexArray(Z);let O=i.accessors[X.attributes.POSITION],J=Number(O?.count??0);if(!Number.isFinite(J)||J<0||N+J>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(N+=J,O?.min&&O?.max){let le=ge=>{for(let Te=0;Te<3;Te++){let ye=ge[12+Te],ve=ge[12+Te];for(let Re=0;Re<3;Re++){let Le=ge[Re*4+Te]*O.min[Re],Fe=ge[Re*4+Te]*O.max[Re];ye+=Le<Fe?Le:Fe,ve+=Le>Fe?Le:Fe}ye<b[Te]&&(b[Te]=ye),ve>M[Te]&&(M[Te]=ve)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let ge=D.instanceMatrices.length>>4,Te=Ee();for(let ye=0;ye<ge;ye++){let ve=D.instanceMatrices.subarray(ye*16,ye*16+16);_e(Te,g,ve),le(Te)}}else le(g)}let q=Gn(t,i,s,X.attributes.POSITION,0,3,K);Gn(t,i,s,X.attributes.NORMAL,1,3,K),Gn(t,i,s,X.attributes.TEXCOORD_0,2,2,K);let Q=0,se=5123,B=null;if(X.indices!==void 0){let le=i.accessors[X.indices],Te=(i.bufferViews[le.bufferView].byteOffset||0)+(le.byteOffset||0);if(Q=Number(le.count??0),!Number.isFinite(Q)||Q<0||G+Q>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);G+=Q,se=le.componentType===5125?5125||5125:5123||5123;let ye=t.createBuffer();K.push(ye),t.bindBuffer(34963,ye),le.componentType===5125?(B=new Uint32Array(s,Te,le.count),t.bufferData(34963,B,35044)):(B=new Uint16Array(s,Te,le.count),t.bufferData(34963,B,35044))}else Q=O.count;let $={};for(let le of ke)if(le.onBuildPrimitiveVAO){let ge=le.onBuildPrimitiveVAO(t,Z,X,i,s);ge&&($[le.name]=ge)}t.bindVertexArray(null);let ae=i.materials&&X.material!==void 0?i.materials[X.material]:null,ie=Lr(),A=Pr,x=ie.fs,v=!1;for(let le of ke)if(le.onResolveShader){let ge=le.onResolveShader(X,ae,A,x);ge&&(A=ge.vs,x=ge.fs,v=!0)}let C=v?Hn(t,A,x):null,P=C?Xn(t,C,ie.uniforms):null,F=ae?.pbrMetallicRoughness,z=F?.baseColorFactor||[.8,.8,.8,1],V=F?.metallicFactor??.1,te=F?.roughnessFactor??.5,W=ae?.extensions?.KHR_materials_clearcoat,ee=W?W.clearcoatFactor??1:0,Y=Math.max(.04,W?.clearcoatRoughnessFactor??.04),j=F?.baseColorTexture!==void 0&&y[F.baseColorTexture.index]?y[F.baseColorTexture.index]:null,oe=F?.metallicRoughnessTexture!==void 0&&y[F.metallicRoughnessTexture.index]?y[F.metallicRoughnessTexture.index]:null,ne=ae?.normalTexture!==void 0&&y[ae.normalTexture.index]?y[ae.normalTexture.index]:null,ce=ae?.normalTexture?.scale??1,ue=ae?.occlusionTexture!==void 0&&y[ae.occlusionTexture.index]?y[ae.occlusionTexture.index]:null,he=ae?.occlusionTexture?.strength??1,de=!!(ae?.extensions?.KHR_materials_transmission||$.materials?.isTransmissive),be=X.extensions?.KHR_materials_variants?.mappings,fe=Array.isArray(be)?be.filter(le=>le&&typeof le.material=="number"&&Array.isArray(le.variants)).map(le=>({material:le.material|0,variants:le.variants.map(ge=>Number(ge)|0)})):void 0;D.primitives.push({vao:Z,indexCount:Q,indexType:se,baseColor:z,metallic:V,roughness:te,clearcoat:ee,clearcoatRoughness:Y,positions:q,indices:B,texture:j,metallicRoughnessTexture:oe,normalTexture:ne,occlusionTexture:ue,normalScale:ce,occlusionStrength:he,buffers:K,materialIndex:X.material,defaultMaterialIndex:X.material,variantMappings:fe,pluginData:$,customProgram:C,customUniforms:P,isTransmissive:de})}h.push(D)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let T=[(b[0]+M[0])/2,(b[1]+M[1])/2,(b[2]+M[2])/2],S=M[0]-b[0],R=M[1]-b[1],I=M[2]-b[2],U=Math.max(Math.hypot(S,R,I)/2,.5),_=[b[0],b[1],b[2]],w=[M[0],M[1],M[2]],E=e.animations;if(!E){for(let p of ke)if(p.onParseGLB?.(e),e.animations){E=e.animations;break}}return E||(E=[]),{meshes:h,bounds:{center:T,radius:U,min:_,max:w},lights:d,animations:E,worldMatrices:u,gpuTextures:y,availableVariants:c}}var nn=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=Ee();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=Ee();this.viewMatrix=Ee();this.modelMatrix=Ee();this.mvpMatrix=Ee();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:Ee(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let h=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h;let c=Lr();this.renderProg=Hn(h,Pr,c.fs),this.pickProg=Hn(h,wi,Si),this.uRender=Xn(h,this.renderProg,c.uniforms),this.uPick=Xn(h,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){xi(e,n)}static getDecoder(e){return _t(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:s,worldMatrices:h,gpuTextures:c,availableVariants:a}=Ir(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=s||[],this.worldMatrices=h||[],this.gpuTextures=c||[],this.availableVariants=a||[],this.gltf=e.gltf,this.activeVariantName&&this.applyVariantMaterial(this.activeVariantName),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of ke)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(kr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Nt(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Nt(e),{meshes:i}=Ir(this.gl,r,Nr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],ze(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),ze(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],s=[],h=[];for(let c of this.lights){let a=c.color||[1,1,1],u=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")r=[a[0]*u,a[1]*u,a[2]*u];else if(c.type==="directional"&&i.length<6){let f=c.direction||[.5,1,.8];i.push(f[0],f[1],f[2]),o.push(a[0]*u,a[1]*u,a[2]*u)}else if(c.type==="point"&&s.length<6){let f=c.position||[0,0,0];s.push(f[0],f[1],f[2]),h.push(a[0]*u,a[1]*u,a[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(n.uniform3fv(e.uPointLightPos,s),n.uniform3fv(e.uPointLightColor,h)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ke)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ke)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(f=>f.materialIndex===r||e.length===1&&f.materialIndex===void 0)),o=i[0],s=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],h=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,c=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:s,metallicFactor:h,roughnessFactor:c,setBaseColorFactor:u=>{let f=[u[0],u[1],u[2],u[3]??1];a.baseColorFactor=f,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=f);for(let m of i)m.baseColor=f;this.render()},setMetallicFactor:u=>{a.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let f of i)f.metallic=u;this.render()},setRoughnessFactor:u=>{a.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let f of i)f.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let n=this.applyVariantMaterial(e);return n&&this.gl&&this.render(),n}applyVariantMaterial(e){let n=e===null||e===""||e==="default",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let s of o.primitives){let h=s.defaultMaterialIndex;if(!n&&Array.isArray(s.variantMappings)){for(let f of s.variantMappings)if(Array.isArray(f.variants)&&f.variants.includes(r)){h=f.material;break}}if(h===void 0||!i[h]){s.materialIndex=void 0,s.baseColor=[.8,.8,.8,1],s.metallic=.1,s.roughness=.5,s.clearcoat=0,s.clearcoatRoughness=.04,s.texture=null,s.metallicRoughnessTexture=null,s.normalTexture=null,s.normalScale=1,s.occlusionTexture=null,s.occlusionStrength=1,s.isTransmissive=!1;continue}let c=i[h];s.materialIndex=h;let a=c.pbrMetallicRoughness;s.baseColor=a?.baseColorFactor?[a.baseColorFactor[0],a.baseColorFactor[1],a.baseColorFactor[2],a.baseColorFactor[3]??1]:[.8,.8,.8,1],s.metallic=a?.metallicFactor??.1,s.roughness=a?.roughnessFactor??.5;let u=c.extensions?.KHR_materials_clearcoat;s.clearcoat=u?u.clearcoatFactor??1:0,s.clearcoatRoughness=Math.max(.04,u?.clearcoatRoughnessFactor??.04),s.texture=a?.baseColorTexture!==void 0&&this.gpuTextures[a.baseColorTexture.index]?this.gpuTextures[a.baseColorTexture.index]:null,s.metallicRoughnessTexture=a?.metallicRoughnessTexture!==void 0&&this.gpuTextures[a.metallicRoughnessTexture.index]?this.gpuTextures[a.metallicRoughnessTexture.index]:null,s.normalTexture=c.normalTexture!==void 0&&this.gpuTextures[c.normalTexture.index]?this.gpuTextures[c.normalTexture.index]:null,s.normalScale=c.normalTexture?.scale??1,s.occlusionTexture=c.occlusionTexture!==void 0&&this.gpuTextures[c.occlusionTexture.index]?this.gpuTextures[c.occlusionTexture.index]:null,s.occlusionStrength=c.occlusionTexture?.strength??1,s.isTransmissive=!!(c.extensions?.KHR_materials_transmission||s.pluginData?.materials?.isTransmissive)}return!0}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of ke)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,n){let r=Ee();_e(r,this.projMatrix,this.viewMatrix);let[i,o,s]=e,h=n?n[0]:0,c=n?n[1]:0,a=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(h=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],c=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],a=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let f=r[0]*i+r[4]*o+r[8]*s+r[12],m=r[1]*i+r[5]*o+r[9]*s+r[13],d=r[2]*i+r[6]*o+r[10]*s+r[14],y=r[3]*i+r[7]*o+r[11]*s+r[15];if(y<=1e-4)return{x:0,y:0,z:1,visible:!1};let b=f/y,M=m/y,N=d/y,G=this.canvas.getBoundingClientRect(),T=G.width||this.canvas.clientWidth||this.canvas.width||300,S=G.height||this.canvas.clientHeight||this.canvas.height||150,R=(b*.5+.5)*T,I=(-M*.5+.5)*S,U=b>=-1.1&&b<=1.1&&M>=-1.1&&M<=1.1&&N>=-1&&N<=1;if(U&&n){let _=this.customTarget||this.bounds.center,w=_[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),E=_[1]+this.currDistance*Math.sin(this.currPhi),p=_[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),k=[i-w,o-E,s-p];h*k[0]+c*k[1]+a*k[2]>.05&&(U=!1)}return{x:R,y:I,z:N,visible:U}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let s=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],a=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-i*s[0]+o*h[0])*a,c[1]+=(-i*s[1]+o*h[1])*a,c[2]+=(-i*s[2]+o*h[2])*a,this.customTarget=c}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,s=r.height||300,h=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),c=i.height>0?Math.floor((n-i.top)*(s/i.height)):Math.floor(n);return this.performMeshPick(h,c,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let h=Ee();_e(h,this.projMatrix,this.viewMatrix);let c=[],a=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(s-1,s-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==s)&&this.resizePickingFbo(o,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let _=0;_<this.meshes.length;_++){let w=this.meshes[_];if(w.visible===!1||w.isPluginMesh)continue;let E=_+1,p=(E&255)/255,k=(E>>8&255)/255,l=(E>>16&255)/255;i.uniform4f(this.uPick.uColorId,p,k,l,1),_e(this.modelMatrix,this.modelRootMatrix,w.transform);let g=w.instanceMatrices;if(g&&g.length>=16){let L=g.length>>4,D=Ee();for(let H of w.primitives){i.bindVertexArray(H.vao);for(let X=0;X<L;X++)_e(D,this.modelMatrix,g.subarray(X*16,X*16+16)),_e(this.mvpMatrix,h,D),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),H.indices?i.drawElements(4,H.indexCount,H.indexType,0):i.drawArrays(4,0,H.indexCount)}}else{_e(this.mvpMatrix,h,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of w.primitives)i.bindVertexArray(L.vao),L.indices?i.drawElements(4,L.indexCount,L.indexType,0):i.drawArrays(4,0,L.indexCount)}}let I=new Uint8Array(4);i.readPixels(a,u,1,1,6408,5121,I),i.bindFramebuffer(36160,null);let U=I[0]+(I[1]<<8)+(I[2]<<16);U>0&&U<=this.meshes.length&&(c=[this.meshes[U-1]])}c.length===0&&(c=this.meshes.filter(I=>I.visible!==!1));let f=null,m=1/0,d=[0,0,0],y=[0,1,0],b=this.customTarget||this.bounds.center,M=b[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),N=b[1]+this.currDistance*Math.sin(this.currPhi),G=b[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),T=Ee();for(let I of c){_e(T,this.modelRootMatrix,I.transform);let U=I.instanceMatrices,_=U&&U.length>=16?U.length>>4:1;for(let w=0;w<_;w++){U&&U.length>=16?_e(this.modelMatrix,T,U.subarray(w*16,w*16+16)):this.modelMatrix.set(T),_e(this.mvpMatrix,h,this.modelMatrix);let E=Ee();if(!Er(E,this.mvpMatrix))continue;let p=(a+.5)/o*2-1,k=(u+.5)/s*2-1,l=[0,0,0],g=[0,0,0];Bn(l,p,k,-1,E),Bn(g,p,k,1,E);let L=g[0]-l[0],D=g[1]-l[1],H=g[2]-l[2],X=Math.hypot(L,D,H)||1,K=L/X,Z=D/X,O=H/X,J={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Q=>{for(let se of I.primitives){if(!se.positions)continue;let B=se.positions,$=se.indices,ae=Math.floor($?$.length/3:B.length/9);for(let ie=0;ie<ae;ie++){let A=$?$[ie*3]:ie*3,x=$?$[ie*3+1]:ie*3+1,v=$?$[ie*3+2]:ie*3+2;Rr(l[0],l[1],l[2],K,Z,O,B[A*3],B[A*3+1],B[A*3+2],B[x*3],B[x*3+1],B[x*3+2],B[v*3],B[v*3+1],B[v*3+2],J,Q)}}})(1e-4),isFinite(J.distance)){let Q=J.point[0],se=J.point[1],B=J.point[2],$=this.modelMatrix,ae=$[0]*Q+$[4]*se+$[8]*B+$[12],ie=$[1]*Q+$[5]*se+$[9]*B+$[13],A=$[2]*Q+$[6]*se+$[10]*B+$[14],x=ae-M,v=ie-N,C=A-G,P=Math.hypot(x,v,C);if(P<m){ze(this.normalMatrix,this.modelMatrix);let F=this.normalMatrix,z=J.normal[0],V=J.normal[1],te=J.normal[2],W=F[0]*z+F[3]*V+F[6]*te,ee=F[1]*z+F[4]*V+F[7]*te,Y=F[2]*z+F[5]*V+F[8]*te,j=Math.hypot(W,ee,Y)||1;W/=j,ee/=j,Y/=j,W*x+ee*v+Y*C>0&&(W=-W,ee=-ee,Y=-Y),f=I,m=Math.round(P*1e3)/1e3,d=[Math.round(ae*1e3)/1e3,Math.round(ie*1e3)/1e3,Math.round(A*1e3)/1e3],y=[Math.round(W*1e3)/1e3,Math.round(ee*1e3)/1e3,Math.round(Y*1e3)/1e3]}}}}if(!f)return null;let R={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:m,hitPoint:d,normal:y,screenX:e,screenY:n};if(r){for(let I of ke)I.onMeshSelect?.(this,R);this.opts.onMeshClick&&this.opts.onMeshClick(R),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:R}))}return R}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,s=i?Math.max(1,n-r):r,h=(o+.5)/s*2-1;return Math.floor((h*.5+1)*.5*n)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);en(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),s=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Rt(this.viewMatrix,[i,o,s],r,[0,1,0]),_e(this.mvpMatrix,this.projMatrix,this.viewMatrix),ze(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of ke)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of ke)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of ke)s.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of ke)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let s={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,n,r,i,o=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let h=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,u=a?[a.x,a.y,a.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:h,projMatrix:c,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let S=Math.max(2,this.canvas.width||2),R=Math.max(1,this.canvas.height||1),I=Math.max(1,Math.floor(S*.5)),U=Math.max(1,S-I),_=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),w=this.customTarget||this.bounds.center,E=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),p=w[1]+this.currDistance*Math.sin(this.currPhi),k=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),l=Math.cos(this.currTheta),g=-Math.sin(this.currTheta),L=.032,D=Ee(),H=Ee(),X=[E-l*L,p,k-g*L],K=[w[0]-l*L*.25,w[1],w[2]-g*L*.25];en(D,this.fov,I/R,.1,_),Rt(H,X,K,[0,1,0]);let Z=Ee(),O=Ee(),J=[E+l*L,p,k+g*L],q=[w[0]+l*L*.25,w[1],w[2]+g*L*.25];en(Z,this.fov,U/R,.1,_),Rt(O,J,q,[0,1,0]),this.render({viewMatrix:H,projMatrix:D,eyePos:X,viewport:[0,0,I,R],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:O,projMatrix:Z,eyePos:J,viewport:[I,0,U,R],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,S,R);return}let n=this.gl,r=0,i=0,o=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],s=e.viewport[3],n.viewport(r,i,o,s)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let h=Ee(),c=e?.viewMatrix??this.viewMatrix;_e(h,e?.projMatrix??this.projMatrix,c);let a=Ae().xrDepthShader,u=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:this.toneMapping==="aces"?3:this.toneMapping==="agx"?4:0,f=this.customTarget||this.bounds.center,m=e?e.eyePos[0]:f[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),d=e?e.eyePos[1]:f[1]+this.currDistance*Math.sin(this.currPhi),y=e?e.eyePos[2]:f[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let S of ke)S.onBeforeDrawScene?.(this,n,h,[m,d,y],u);let b=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&b===0)return;let M=e?.eye||"none",N=!1,G=b>0?[...this.backdropMeshes,...this.meshes]:this.meshes,T=S=>{for(let R=0;R<G.length;R++){let I=G[R];if(I.visible===!1)continue;let U=this.selectedMeshName!==""&&I.name===this.selectedMeshName;R<b||I.worldSpace===!0||I.name==="__xr_reticle__"?this.modelMatrix.set(I.transform):_e(this.modelMatrix,this.modelRootMatrix,I.transform),_e(this.mvpMatrix,h,this.modelMatrix),ze(I.normalMatrix,this.modelMatrix);let _=I.extras?.xr?.stereo||I.userData?.xr?.stereo,w=0,E=0,p=1,k=1;_==="sbs"?(p=.5,w=M==="right"?.5:0):_==="ou"&&(k=.5,E=M==="right"?.5:0);for(let l of I.primitives){let g=!!l.isTransmissive;if(!S&&g){N=!0;continue}if(S&&!g)continue;let L=l.customProgram||this.renderProg,D=l.customUniforms||this.uRender;n.useProgram(L),n.uniform1i(D.uToneMapping,u),n.uniform1f(D.uEnvIntensity,this.envIntensity),n.uniform3f(D.uCameraPos,m,d,y),n.uniform1f(D.uEmissive,U?1:0),n.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(D.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(D.uNormalMatrix,!1,I.normalMatrix),D.uUvTransform&&n.uniform4f(D.uUvTransform,w,E,p,k),D.uViewportSize&&n.uniform2f(D.uViewportSize,Math.max(1,o),Math.max(1,s)),a?.bind(n,D,this.xrDepthState,c,[r,i,Math.max(1,o),Math.max(1,s)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(D.uEnvironmentMap,4),n.uniform1i(D.uHasEnvironmentMap,1)):n.uniform1i(D.uHasEnvironmentMap,0),this.bindLights(D),D.uSectionEnabled&&n.uniform1i(D.uSectionEnabled,0);for(let X of ke)X.onBeforeDrawPrimitive?.(n,L,l,I,this.worldMatrices||[],this.gltf);n.uniform4fv(D.uBaseColor,l.baseColor),n.uniform1f(D.uMetallic,l.metallic),n.uniform1f(D.uRoughness,l.roughness),D.uClearcoat&&n.uniform2f(D.uClearcoat,l.clearcoat??0,l.clearcoatRoughness??.04),l.texture?(n.activeTexture(33984),n.bindTexture(3553,l.texture),n.uniform1i(D.uBaseColorTexture,0),n.uniform1i(D.uHasTexture,1)):n.uniform1i(D.uHasTexture,0),l.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,l.metallicRoughnessTexture),n.uniform1i(D.uMetallicRoughnessTexture,1),n.uniform1i(D.uHasMetallicRoughnessTexture,1)):n.uniform1i(D.uHasMetallicRoughnessTexture,0),l.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,l.normalTexture),n.uniform1i(D.uNormalTexture,2),n.uniform1i(D.uHasNormalTexture,1),n.uniform1f(D.uNormalScale,l.normalScale)):n.uniform1i(D.uHasNormalTexture,0),l.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,l.occlusionTexture),n.uniform1i(D.uOcclusionTexture,3),n.uniform1i(D.uHasOcclusionTexture,1),n.uniform1f(D.uOcclusionStrength,l.occlusionStrength)):n.uniform1i(D.uHasOcclusionTexture,0),n.bindVertexArray(l.vao);let H=I.instanceMatrices;if(H&&H.length>=16){let X=H.length>>4,K=I.instanceColors,Z=Ee(),O=new Float32Array(9),J=[l.baseColor[0],l.baseColor[1],l.baseColor[2],l.baseColor[3]];for(let q=0;q<X;q++)_e(Z,this.modelMatrix,H.subarray(q*16,q*16+16)),_e(this.mvpMatrix,h,Z),ze(O,Z),n.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(D.uModel,!1,Z),n.uniformMatrix3fv(D.uNormalMatrix,!1,O),K&&(J[0]=l.baseColor[0]*K[q*3],J[1]=l.baseColor[1]*K[q*3+1],J[2]=l.baseColor[2]*K[q*3+2],J[3]=l.baseColor[3],n.uniform4fv(D.uBaseColor,J)),l.indices?n.drawElements(4,l.indexCount,l.indexType,0):n.drawArrays(4,0,l.indexCount)}else l.indices?n.drawElements(4,l.indexCount,l.indexType,0):n.drawArrays(4,0,l.indexCount)}}};if(T(!1),N){for(let S of ke)S.onBeforeTransmissivePass?.(n,this);T(!0)}for(let S of ke)S.onAfterRender?.(n,this,h)}disposeMeshListGpuResources(e,n){let r=this.gl,i=new Set,o=s=>{s&&!i.has(s)&&(i.add(s),r.deleteTexture(s))};for(let s of e)for(let h of s.primitives){if(h.vao&&r.deleteVertexArray(h.vao),h.buffers)for(let c of h.buffers)r.deleteBuffer(c);o(h.texture),o(h.metallicRoughnessTexture),o(h.normalTexture),o(h.occlusionTexture),h.customProgram&&r.deleteProgram(h.customProgram)}if(n)for(let s of n)o(s)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ke)n.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};nn.registerPlugin=wr,nn.getRegisteredPlugins=Sr;function Ei(t){return t+3&-4}function Ri(t,e=0){let n=(O,J)=>typeof O=="number"&&Number.isFinite(O)?O:J,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),s=n(t[e+0],1),h=n(t[e+1],0),c=n(t[e+2],0),a=n(t[e+4],0),u=n(t[e+5],1),f=n(t[e+6],0),m=n(t[e+8],0),d=n(t[e+9],0),y=n(t[e+10],1),b=Math.hypot(s,h,c),M=Math.hypot(a,u,f),N=Math.hypot(m,d,y);s*(u*y-d*f)-a*(h*y-d*c)+m*(h*f-u*c)<0&&(b=-b);let T=Math.abs(b)>1e-8?1/b:0,S=Math.abs(M)>1e-8?1/M:0,R=Math.abs(N)>1e-8?1/N:0,I=s*T,U=h*T,_=c*T,w=a*S,E=u*S,p=f*S,k=m*R,l=d*R,g=y*R,L=I+E+g,D=0,H=0,X=0,K=1;if(L>0){let O=.5/Math.sqrt(L+1);K=.25/O,D=(p-l)*O,H=(k-_)*O,X=(U-w)*O}else if(I>E&&I>g){let O=2*Math.sqrt(Math.max(0,1+I-E-g));O>1e-8&&(K=(p-l)/O,D=.25*O,H=(w+U)/O,X=(k+_)/O)}else if(E>g){let O=2*Math.sqrt(Math.max(0,1+E-I-g));O>1e-8&&(K=(k-_)/O,D=(w+U)/O,H=.25*O,X=(p+l)/O)}else{let O=2*Math.sqrt(Math.max(0,1+g-I-E));O>1e-8&&(K=(U-w)/O,D=(k+_)/O,H=(p+l)/O,X=.25*O)}let Z=Math.hypot(D,H,X,K);return Z>1e-8&&Number.isFinite(Z)?(D/=Z,H/=Z,X/=Z,K/=Z):(D=0,H=0,X=0,K=1),{t:[r,i,o],r:[D,H,X,K],s:[b,M,N]}}function _i(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function Ct(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],s=[],h=[],c=new Set,a=[],u=[],f=new Map,m=[],d=[];function y(w){let E=f.get(w);if(E!==void 0)return E;E=u.length,f.set(w,E);let p=w,k=p.color?.r??.8,l=p.color?.g??.8,g=p.color?.b??.8,L=p.opacity??1,D={name:p.name||"",pbrMetallicRoughness:{baseColorFactor:[k,l,g,L],metallicFactor:p.metalness??.1,roughnessFactor:p.roughness??.5},doubleSided:p.side===2||!!p.doubleSided};if(p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let X=p.emissiveIntensity??1;D.emissiveFactor=[p.emissive.r*X,p.emissive.g*X,p.emissive.b*X]}let H={};return p.clearcoat&&p.clearcoat>0&&(H.KHR_materials_clearcoat={clearcoatFactor:p.clearcoat,clearcoatRoughnessFactor:p.clearcoatRoughness||0}),p.sheen&&p.sheen>0&&(H.KHR_materials_sheen={sheenColorFactor:p.sheenColor?[p.sheenColor.r,p.sheenColor.g,p.sheenColor.b]:[1,1,1],sheenRoughnessFactor:p.sheenRoughness||0}),p.transmission&&p.transmission>0&&(H.KHR_materials_transmission={transmissionFactor:p.transmission}),p.thickness&&p.thickness>0&&(H.KHR_materials_volume={thicknessFactor:p.thickness,attenuationDistance:p.attenuationDistance??1/0,attenuationColor:p.attenuationColor?[p.attenuationColor.r,p.attenuationColor.g,p.attenuationColor.b]:[1,1,1]}),p.ior!==void 0&&p.ior!==1.5&&(H.KHR_materials_ior={ior:p.ior}),p.dispersion&&p.dispersion>0&&(H.KHR_materials_dispersion={dispersion:p.dispersion}),p.iridescence&&p.iridescence>0&&(H.KHR_materials_iridescence={iridescenceFactor:p.iridescence,iridescenceIor:p.iridescenceIOR??1.3}),Object.keys(H).length>0&&(D.extensions=H),u.push(D),E}function b(w,E){let p=new Uint8Array(w.buffer,w.byteOffset,w.byteLength),k=Ei(p.byteLength),l=new Uint8Array(k);l.set(p),n.push(l);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:p.byteLength,target:E}),r+=k,g}function M(w,E,p,k,l,g,L){let D=b(w,p),H=o.length,X={bufferView:D,byteOffset:0,componentType:k,count:l,type:E};return g&&(X.min=g),L&&(X.max=L),o.push(X),H}t.traverse(w=>{(w.isLight||w.color&&w.intensity!==void 0)&&d.push({type:w.type,color:[w.color.r,w.color.g,w.color.b],intensity:w.intensity,position:[w.position.x,w.position.y,w.position.z]})});let N=[];function G(w){let E={name:w.name||""},p=w.position,k=w.quaternion,l=w.scale;if((p.x||p.y||p.z)&&(E.translation=[p.x,p.y,p.z]),(k.x||k.y||k.z||k.w!==1)&&(E.rotation=[k.x,k.y,k.z,k.w]),(l.x!==1||l.y!==1||l.z!==1)&&(E.scale=[l.x,l.y,l.z]),w.userData&&Object.keys(w.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(w.userData,(L,D)=>{if(!(L==="__proto__"||L==="prototype"||L==="constructor"))return typeof D=="function"?void 0:D})),w.userData.xr)){let L=_i(w.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:L,ANDROID_xr_scenecore:L},Ae().xrTraitSerializer?.gltfNode(E,w.userData.xr),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(w.geometry){let L=w.geometry,D=L.attributes.position;if(D&&D.count>0){let H=[1/0,1/0,1/0],X=[-1/0,-1/0,-1/0];for(let Q=0;Q<D.count;Q++){let se=D.getX(Q),B=D.getY(Q),$=D.getZ(Q);se<H[0]&&(H[0]=se),se>X[0]&&(X[0]=se),B<H[1]&&(H[1]=B),B>X[1]&&(X[1]=B),$<H[2]&&(H[2]=$),$>X[2]&&(X[2]=$)}let Z={attributes:{POSITION:M(D.array,"VEC3",34962,5126,D.count,H,X)}};if(L.attributes.normal&&(Z.attributes.NORMAL=M(L.attributes.normal.array,"VEC3",34962,5126,L.attributes.normal.count)),L.attributes.uv&&(Z.attributes.TEXCOORD_0=M(L.attributes.uv.array,"VEC2",34962,5126,L.attributes.uv.count)),L.index){let Q=L.index.array instanceof Uint32Array;Z.indices=M(L.index.array,"SCALAR",34963,Q?5125:5123,L.index.count)}w.material&&(Z.material=y(w.material));let O=w.userData?.variants;if(O&&typeof O=="object"){let Q=new Map;for(let se of Object.keys(O)){if(!se||se==="__proto__"||se==="constructor"||se==="prototype")continue;let B=O[se];if(!B||typeof B!="object")continue;let $=m.indexOf(se);if($===-1&&m.length<256&&($=m.length,m.push(se)),$===-1)continue;let ae=y(B),ie=Q.get(ae);ie||(ie=[],Q.set(ae,ie)),ie.push($)}if(Q.size>0){let se=[];for(let[B,$]of Q.entries())se.push({material:B,variants:$});Z.extensions={...Z.extensions||{},KHR_materials_variants:{mappings:se}},c.add("KHR_materials_variants")}}let J=w;if(J.isInstancedMesh&&typeof J.count=="number"&&J.count>0&&J.instanceMatrix?.array){let Q=Math.min(1e4,Math.floor(J.count)),se=J.instanceMatrix.array,B=new Float32Array(Q*3),$=new Float32Array(Q*4),ae=new Float32Array(Q*3);for(let A=0;A<Q;A++){let{t:x,r:v,s:C}=Ri(se,A*16);B[A*3]=x[0],B[A*3+1]=x[1],B[A*3+2]=x[2],$[A*4]=v[0],$[A*4+1]=v[1],$[A*4+2]=v[2],$[A*4+3]=v[3],ae[A*3]=C[0],ae[A*3+1]=C[1],ae[A*3+2]=C[2]}let ie={TRANSLATION:M(B,"VEC3",0,5126,Q),ROTATION:M($,"VEC4",0,5126,Q),SCALE:M(ae,"VEC3",0,5126,Q)};if(J.instanceColor?.array&&J.instanceColor.array.length>=Q*3){let A=new Float32Array(J.instanceColor.array.subarray(0,Q*3));ie._COLOR_0=M(A,"VEC3",0,5126,Q)}E.extensions={...E.extensions||{},EXT_mesh_gpu_instancing:{attributes:ie}},c.add("EXT_mesh_gpu_instancing")}let q=s.length;s.push({primitives:[Z],name:w.name,...E.extras?{extras:E.extras}:{}}),E.mesh=q}}let g=h.length;if(h.push(E),a.push(w),w.children.length>0){E.children=[];for(let L of w.children)E.children.push(G(L))}return g}for(let w of t.children)N.push(G(w));let T=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),S=[];if(typeof T=="function"&&a.length>0){let w=e?.duration??4,E=e?.fps??15,p=Math.max(2,Math.round(w*E)+1),k=new Float32Array(p),l=a.map(O=>({px:O.position.x,py:O.position.y,pz:O.position.z,qx:O.quaternion.x,qy:O.quaternion.y,qz:O.quaternion.z,qw:O.quaternion.w,sx:O.scale.x,sy:O.scale.y,sz:O.scale.z})),g=a.map(()=>new Float32Array(p*3)),L=a.map(()=>new Float32Array(p*4)),D=a.map(()=>new Float32Array(p*3));for(let O=0;O<p;O++){let J=O/(p-1)*w;k[O]=J;try{T(J)}catch{}for(let q=0;q<a.length;q++){let Q=a[q];g[q][O*3]=Q.position.x,g[q][O*3+1]=Q.position.y,g[q][O*3+2]=Q.position.z,L[q][O*4]=Q.quaternion.x,L[q][O*4+1]=Q.quaternion.y,L[q][O*4+2]=Q.quaternion.z,L[q][O*4+3]=Q.quaternion.w,D[q][O*3]=Q.scale.x,D[q][O*3+1]=Q.scale.y,D[q][O*3+2]=Q.scale.z}}for(let O=0;O<a.length;O++){let J=a[O],q=l[O];J.position.set(q.px,q.py,q.pz),J.quaternion.set(q.qx,q.qy,q.qz,q.qw),J.scale.set(q.sx,q.sy,q.sz)}t.updateMatrixWorld(!0);let H=null,X=()=>(H===null&&(H=M(k,"SCALAR",0,5126,p,[0],[w])),H),K=[],Z=[];for(let O=0;O<a.length;O++){let J=l[O],q=!1,Q=!1,se=!1;for(let B=0;B<p;B++)(Math.abs(g[O][B*3]-J.px)>1e-4||Math.abs(g[O][B*3+1]-J.py)>1e-4||Math.abs(g[O][B*3+2]-J.pz)>1e-4)&&(q=!0),(Math.abs(L[O][B*4]-J.qx)>1e-4||Math.abs(L[O][B*4+1]-J.qy)>1e-4||Math.abs(L[O][B*4+2]-J.qz)>1e-4||Math.abs(L[O][B*4+3]-J.qw)>1e-4)&&(Q=!0),(Math.abs(D[O][B*3]-J.sx)>1e-4||Math.abs(D[O][B*3+1]-J.sy)>1e-4||Math.abs(D[O][B*3+2]-J.sz)>1e-4)&&(se=!0);if(q){let B=M(g[O],"VEC3",0,5126,p),$=K.length;K.push({input:X(),interpolation:"LINEAR",output:B}),Z.push({sampler:$,target:{node:O,path:"translation"}})}if(Q){let B=M(L[O],"VEC4",0,5126,p),$=K.length;K.push({input:X(),interpolation:"LINEAR",output:B}),Z.push({sampler:$,target:{node:O,path:"rotation"}})}if(se){let B=M(D[O],"VEC3",0,5126,p),$=K.length;K.push({input:X(),interpolation:"LINEAR",output:B}),Z.push({sampler:$,target:{node:O,path:"scale"}})}}Z.length>0&&S.push({name:"ProceduralLoop",samplers:K,channels:Z})}let R=Qt(h,s,t.userData),I={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:N}],scene:0,nodes:h,meshes:s,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...S.length>0?{animations:S}:{},...R||c.size>0?{extensionsUsed:[...R?["KHR_interactivity"]:[],...c]}:{},...R||m.length>0?{extensions:{...R?{KHR_interactivity:R}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(w=>({name:w}))}}:{}}}:{}},U=new Uint8Array(r),_=0;for(let w of n)U.set(w,_),_+=w.byteLength;return{gltf:I,bin:U.buffer,lights:d,environmentIntensity:t.environmentIntensity}}function on(t){return new TextEncoder().encode(t)}function Ft(t,e){let{gltf:n,bin:r}=Ct(t,e),i=JSON.stringify(n),o=on(i),s=(4-o.byteLength%4)%4,h=o.byteLength+s,c=20+h+8+r.byteLength,a=new Uint8Array(c),u=new DataView(a.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,c,!0),u.setUint32(12,h,!0),u.setUint32(16,1313821514,!0),a.set(o,20);for(let m=0;m<s;m++)a[20+o.byteLength+m]=32;let f=20+h;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),a.set(new Uint8Array(r),f+8),a}function Ci(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let s=o.count,h=new Float32Array(s*3),c=r.matrixWorld.elements;for(let _=0;_<s;_++){let w=o.getX(_),E=o.getY(_),p=o.getZ(_);h[_*3]=c[0]*w+c[4]*E+c[8]*p+c[12],h[_*3+1]=c[1]*w+c[5]*E+c[9]*p+c[13],h[_*3+2]=c[2]*w+c[6]*E+c[10]*p+c[14]}let a;if(i.attributes.normal){let _=i.attributes.normal;a=new Float32Array(s*3);let w=new Float32Array(9);ze(w,c);for(let E=0;E<s;E++){let p=_.getX(E),k=_.getY(E),l=_.getZ(E),g=w[0]*p+w[3]*k+w[6]*l,L=w[1]*p+w[4]*k+w[7]*l,D=w[2]*p+w[5]*k+w[8]*l,H=Math.hypot(g,L,D)||1;a[E*3]=g/H,a[E*3+1]=L/H,a[E*3+2]=D/H}}let u;if(i.attributes.uv){let _=i.attributes.uv;u=new Float32Array(s*2);for(let w=0;w<s;w++)u[w*2]=_.getX(w),u[w*2+1]=_.getY(w)}let f;if(i.index)f=i.index.array;else{f=s>65535?new Uint32Array(s):new Uint16Array(s);for(let _=0;_<s;_++)f[_]=_}let m="DefaultMaterial",d=[.8,.8,.8],y=.5,b=.1,M=0,N=0,G=1.5,T=1,S=[0,0,0];if(r.material){let _=r.material;m=_.name||`Material_${n.length}`,_.color&&(d=[_.color.r,_.color.g,_.color.b]),typeof _.roughness=="number"&&(y=_.roughness),typeof _.metalness=="number"&&(b=_.metalness),typeof _.clearcoat=="number"&&(M=_.clearcoat),typeof _.clearcoatRoughness=="number"&&(N=_.clearcoatRoughness),typeof _.ior=="number"&&(G=_.ior);let w=typeof _.opacity=="number"?_.opacity:1,E=typeof _.transmission=="number"?_.transmission:0;if(T=w*(1-E),_.emissive&&(_.emissive.r>0||_.emissive.g>0||_.emissive.b>0)){let p=_.emissiveIntensity??1;S=[_.emissive.r*p,_.emissive.g*p,_.emissive.b*p]}}let R,I=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof I=="function"){let _=e?.duration??4,w=e?.fps??4,E=Math.max(2,Math.round(_*w)+1),p=[],k=[],l=[],g=[],L=[r.position.x,r.position.y,r.position.z],D=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],H=[r.scale.x,r.scale.y,r.scale.z],X=!1;for(let K=0;K<E;K++){let Z=K/(E-1)*_;p.push(Z);try{I(Z)}catch{}k.push([r.position.x,r.position.y,r.position.z]),l.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),g.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-L[0])>1e-4||Math.abs(r.position.y-L[1])>1e-4||Math.abs(r.position.z-L[2])>1e-4||Math.abs(r.quaternion.x-D[0])>1e-4||Math.abs(r.quaternion.y-D[1])>1e-4||Math.abs(r.quaternion.z-D[2])>1e-4||Math.abs(r.quaternion.w-D[3])>1e-4||Math.abs(r.scale.x-H[0])>1e-4)&&(X=!0)}r.position.set(L[0],L[1],L[2]),r.quaternion.set(D[0],D[1],D[2],D[3]),r.scale.set(H[0],H[1],H[2]),X&&(R={times:p,translations:k,rotations:l,scales:g})}let U=r;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let _=Math.min(1e3,Math.floor(U.count)),w=U.instanceMatrix.array,E=U.instanceColor?.array,p=r.name||`Mesh_${n.length}`,k=new Float32Array(16),l=new Float32Array(9);for(let g=0;g<_;g++){let L=w.subarray(g*16,(g+1)*16);_e(k,c,L);let D=new Float32Array(s*3);for(let Z=0;Z<s;Z++){let O=o.getX(Z),J=o.getY(Z),q=o.getZ(Z);D[Z*3]=k[0]*O+k[4]*J+k[8]*q+k[12],D[Z*3+1]=k[1]*O+k[5]*J+k[9]*q+k[13],D[Z*3+2]=k[2]*O+k[6]*J+k[10]*q+k[14]}let H;if(i.attributes.normal){let Z=i.attributes.normal;H=new Float32Array(s*3),ze(l,k);for(let O=0;O<s;O++){let J=Z.getX(O),q=Z.getY(O),Q=Z.getZ(O),se=l[0]*J+l[3]*q+l[6]*Q,B=l[1]*J+l[4]*q+l[7]*Q,$=l[2]*J+l[5]*q+l[8]*Q,ae=Math.hypot(se,B,$)||1;H[O*3]=se/ae,H[O*3+1]=B/ae,H[O*3+2]=$/ae}}let X=d,K=m;E&&E.length>=(g+1)*3&&(X=[d[0]*E[g*3],d[1]*E[g*3+1],d[2]*E[g*3+2]],K=`${m}_inst_${g}`),n.push({name:`${p}_${g}`,positions:D,indices:f,normals:H,uvs:u,materialName:K,color:X,roughness:y,metallic:b,clearcoat:M,clearcoatRoughness:N,ior:G,opacity:T,emissiveColor:S,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:h,indices:f,normals:a,uvs:u,materialName:m,color:d,roughness:y,metallic:b,clearcoat:M,clearcoatRoughness:N,ior:G,opacity:T,emissiveColor:S,xrTraits:r.userData?.xr,timeSamples:R})}}),n}function Ur(t){let e=[],n=t.gltf,r=Ae().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,t);let i=t.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=n.accessors||[],h=n.bufferViews||[],c=n.materials||[],a=n.meshes||[],u=n.nodes||[];function f(y){let b=s[y];if(!b)throw new Error(`Accessor ${y} not found`);let M=h[b.bufferView||0],N=(M.byteOffset||0)+(b.byteOffset||0),G=M.byteLength||0,T=o.slice(N,N+G);return{acc:b,buffer:T}}let m=new Map;if(u.length>0){let y=tn(n);for(let b=0;b<y.length;b++)m.set(b,y[b])}function d(y,b,M,N){let G=a[y];if(!G)return;let T=new Float32Array(9);ze(T,b);for(let S=0;S<(G.primitives||[]).length;S++){let R=G.primitives[S],I=R.attributes?.POSITION;if(I===void 0)continue;let{acc:U,buffer:_}=f(I),w=new Float32Array(_,0,U.count*3),E=new Float32Array(w.length);for(let B=0;B<U.count;B++){let $=w[B*3],ae=w[B*3+1],ie=w[B*3+2];E[B*3]=b[0]*$+b[4]*ae+b[8]*ie+b[12],E[B*3+1]=b[1]*$+b[5]*ae+b[9]*ie+b[13],E[B*3+2]=b[2]*$+b[6]*ae+b[10]*ie+b[14]}let p,k=R.attributes?.NORMAL;if(k!==void 0){let{acc:B,buffer:$}=f(k),ae=new Float32Array($,0,B.count*3);p=new Float32Array(ae.length);for(let ie=0;ie<B.count;ie++){let A=ae[ie*3],x=ae[ie*3+1],v=ae[ie*3+2],C=T[0]*A+T[3]*x+T[6]*v,P=T[1]*A+T[4]*x+T[7]*v,F=T[2]*A+T[5]*x+T[8]*v,z=Math.hypot(C,P,F)||1;p[ie*3]=C/z,p[ie*3+1]=P/z,p[ie*3+2]=F/z}}let l,g=R.attributes?.TEXCOORD_0;if(g!==void 0){let{acc:B,buffer:$}=f(g);l=new Float32Array($,0,B.count*2)}let L;if(R.indices!==void 0){let{acc:B,buffer:$}=f(R.indices);B.componentType===5125?L=new Uint32Array($,0,B.count):L=new Uint16Array($,0,B.count);let ae=U.count;for(let ie of L)if(ie>=ae)throw new Error(`SecurityError: Index buffer value (${ie}) out of vertex bounds [0, ${ae}).`)}else{let B=U.count;L=B>65535?new Uint32Array(B):new Uint16Array(B);for(let $=0;$<B;$++)L[$]=$}let D="DefaultMaterial",H=[.8,.8,.8],X=.5,K=.1,Z=0,O=0,J=1.5,q=1,Q=[0,0,0];if(R.material!==void 0&&c[R.material]){let B=c[R.material];D=B.name||`Material_${R.material}`;let $=B.pbrMetallicRoughness||{},ae=1;Array.isArray($.baseColorFactor)&&(H=[$.baseColorFactor[0],$.baseColorFactor[1],$.baseColorFactor[2]],typeof $.baseColorFactor[3]=="number"&&(ae=$.baseColorFactor[3])),typeof $.roughnessFactor=="number"&&(X=$.roughnessFactor),typeof $.metallicFactor=="number"&&(K=$.metallicFactor),Array.isArray(B.emissiveFactor)&&B.emissiveFactor.length>=3&&(Q=[B.emissiveFactor[0],B.emissiveFactor[1],B.emissiveFactor[2]]);let ie=B.extensions||{};ie.KHR_materials_clearcoat&&(Z=ie.KHR_materials_clearcoat.clearcoatFactor??0,O=ie.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),ie.KHR_materials_ior&&typeof ie.KHR_materials_ior.ior=="number"&&(J=ie.KHR_materials_ior.ior);let A=ie.KHR_materials_transmission?.transmissionFactor??0;q=ae*(1-A)}let se=(G.primitives||[]).length>1?`${M}_p${S}`:M;e.push({name:se,positions:E,indices:L,normals:p,uvs:l,materialName:D,color:H,roughness:X,metallic:K,clearcoat:Z,clearcoatRoughness:O,ior:J,opacity:q,emissiveColor:Q,xrTraits:N?.xr||G.extras?.xr})}}if(u.length>0)for(let y=0;y<u.length;y++){let b=u[y];if(b.mesh!==void 0&&b.mesh<a.length){let M=m.get(y)||Ee(),N=b.name||a[b.mesh].name||`Node_${y}`,G=b.extensions?.EXT_mesh_gpu_instancing?.attributes;if(G&&typeof G=="object"){let T=G.TRANSLATION,S=G.ROTATION,R=G.SCALE,I=T!==void 0?(()=>{let{acc:E,buffer:p}=f(T);return new Float32Array(p,0,E.count*3)})():null,U=S!==void 0?(()=>{let{acc:E,buffer:p}=f(S);return new Float32Array(p,0,E.count*4)})():null,_=R!==void 0?(()=>{let{acc:E,buffer:p}=f(R);return new Float32Array(p,0,E.count*3)})():null,w=Math.min(1e3,I?I.length/3:U?U.length/4:_?_.length/3:0);if(w>0){let E=new Float32Array(16),p=new Float32Array(16);for(let k=0;k<w;k++){let l=I?[I[k*3],I[k*3+1],I[k*3+2]]:[0,0,0],g=U?[U[k*4],U[k*4+1],U[k*4+2],U[k*4+3]]:[0,0,0,1],L=_?[_[k*3],_[k*3+1],_[k*3+2]]:[1,1,1];pt(E,g,l,L),_e(p,M,E),d(b.mesh,p,`${N}_${k}`,b.extras)}continue}}d(b.mesh,M,N,b.extras)}}else{let y=Ee();for(let b=0;b<a.length;b++){let M=a[b].name||`Mesh_${b}`;d(b,y,M,a[b].extras)}}return e}function Wn(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function Fr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function xe(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function Or(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${xe(t[r*3])}, ${xe(t[r*3+1])}, ${xe(t[r*3+2])})`;return n.join(", ")}function Ii(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${xe(t[r*2])}, ${xe(1-t[r*2+1])})`;return n.join(", ")}function Di(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function $n(t){let e=new Map;for(let c of t){let a=Wn(c.materialName,"DefaultMaterial");e.has(a)||e.set(a,{color:c.color||[.8,.8,.8],roughness:c.roughness??.5,metallic:c.metallic??0,clearcoat:c.clearcoat??0,clearcoatRoughness:c.clearcoatRoughness??0,ior:c.ior??1.5,opacity:c.opacity??1,emissiveColor:c.emissiveColor||[0,0,0]})}let n=0,r=null;for(let c of t){if(c.timeSamples&&c.timeSamples.times.length>0){let a=c.timeSamples.times[c.timeSamples.times.length-1];a>n&&(n=a)}c.xrTraits?.anchor&&!r&&(r=c.xrTraits.anchor==="vertical"||c.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
234
+ endTimeCode = ${xe(n)}
210
235
  timeCodesPerSecond = 1.0
211
236
  `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
212
237
  uniform token preliminary:planeAnchoring:alignment = "${r}"
213
- `);let c=`#usda 1.0
238
+ `);let s=`#usda 1.0
214
239
  (
215
240
  defaultPrim = "Root"
216
241
  metersPerUnit = 1.0
@@ -223,61 +248,61 @@ kind = "component"
223
248
  {
224
249
  ${o}def Scope "Materials"
225
250
  {
226
- `;for(let[u,s]of e.entries()){let[a,m,l]=s.color,[f,d,S]=s.emissiveColor,A="";s.clearcoat>0&&(A+=`float inputs:clearcoat = ${W(s.clearcoat)}
227
- `,A+=`float inputs:clearcoatRoughness = ${W(s.clearcoatRoughness)}
228
- `),s.ior!==1.5&&(A+=`float inputs:ior = ${W(s.ior)}
229
- `),s.opacity<1&&(A+=`float inputs:opacity = ${W(s.opacity)}
230
- `),(f>0||d>0||S>0)&&(A+=`color3f inputs:emissiveColor = (${W(f)}, ${W(d)}, ${W(S)})
231
- `),c+=`def Material "${u}"
251
+ `;for(let[c,a]of e.entries()){let[u,f,m]=a.color,[d,y,b]=a.emissiveColor,M="";a.clearcoat>0&&(M+=`float inputs:clearcoat = ${xe(a.clearcoat)}
252
+ `,M+=`float inputs:clearcoatRoughness = ${xe(a.clearcoatRoughness)}
253
+ `),a.ior!==1.5&&(M+=`float inputs:ior = ${xe(a.ior)}
254
+ `),a.opacity<1&&(M+=`float inputs:opacity = ${xe(a.opacity)}
255
+ `),(d>0||y>0||b>0)&&(M+=`color3f inputs:emissiveColor = (${xe(d)}, ${xe(y)}, ${xe(b)})
256
+ `),s+=`def Material "${c}"
232
257
  {
233
258
  def Shader "PBRShader"
234
259
  {
235
260
  uniform token info:id = "UsdPreviewSurface"
236
- color3f inputs:diffuseColor = (${W(a)}, ${W(m)}, ${W(l)})
237
- float inputs:metallic = ${W(s.metallic)}
238
- float inputs:roughness = ${W(s.roughness)}
239
- ${A}token outputs:surface
261
+ color3f inputs:diffuseColor = (${xe(u)}, ${xe(f)}, ${xe(m)})
262
+ float inputs:metallic = ${xe(a.metallic)}
263
+ float inputs:roughness = ${xe(a.roughness)}
264
+ ${M}token outputs:surface
240
265
  }
241
- token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
266
+ token outputs:surface.connect = </Root/Materials/${c}/PBRShader.outputs:surface>
242
267
  }
243
- `}c+=`}
268
+ `}s+=`}
244
269
  def Scope "Meshes"
245
270
  {
246
- `;let h=new Set;for(let u=0;u<t.length;u++){let s=t[u],a=s.positions.length/3,m=1/0,l=1/0,f=1/0,d=-1/0,S=-1/0,A=-1/0;for(let p=0;p<a;p++){let E=s.positions[p*3],v=s.positions[p*3+1],_=s.positions[p*3+2];E<m&&(m=E),E>d&&(d=E),v<l&&(l=v),v>S&&(S=v),_<f&&(f=_),_>A&&(A=_)}isFinite(m)||(m=l=f=-1,d=S=A=1);let M=Math.floor(s.indices.length/3),P=Kt(s.materialName,"DefaultMaterial"),y=Kt(s.name,`Mesh_${u}`);h.has(y)&&(y=`${y}_${u}`),h.add(y);let w=M>0?M===1?"3":"3, ".repeat(M-1)+"3":"",b=s.xrTraits,R="";if(b){let p=[];b.physics&&b.physics!=="none"&&p.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let E=Q().xrTraitSerializer?.usdLines(b,_n)??[];if(!E.length)for(let v of["grab","billboard","follow","anchor","physics"]){let _=v==="follow"&&typeof b.follow=="object"?b.follow.mode??"head":b[v];_!==void 0&&E.push(`string ${v} = "${_n(_)}"`)}E.length>0&&p.push(`customData = {
271
+ `;let h=new Set;for(let c=0;c<t.length;c++){let a=t[c],u=a.positions.length/3,f=1/0,m=1/0,d=1/0,y=-1/0,b=-1/0,M=-1/0;for(let U=0;U<u;U++){let _=a.positions[U*3],w=a.positions[U*3+1],E=a.positions[U*3+2];_<f&&(f=_),_>y&&(y=_),w<m&&(m=w),w>b&&(b=w),E<d&&(d=E),E>M&&(M=E)}isFinite(f)||(f=m=d=-1,y=b=M=1);let N=Math.floor(a.indices.length/3),G=Wn(a.materialName,"DefaultMaterial"),T=Wn(a.name,`Mesh_${c}`);h.has(T)&&(T=`${T}_${c}`),h.add(T);let S=N>0?N===1?"3":"3, ".repeat(N-1)+"3":"",R=a.xrTraits,I="";if(R){let U=[];R.physics&&R.physics!=="none"&&U.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let _=Ae().xrTraitSerializer?.usdLines(R,Fr)??[];if(!_.length)for(let w of["grab","billboard","follow","anchor","physics"]){let E=w==="follow"&&typeof R.follow=="object"?R.follow.mode??"head":R[w];E!==void 0&&_.push(`string ${w} = "${Fr(E)}"`)}_.length>0&&U.push(`customData = {
247
272
  dictionary xr = {
248
- ${E.join(`
273
+ ${_.join(`
249
274
  `)}
250
275
  }
251
- }`),p.length>0&&(R=` (
252
- ${p.join(`
276
+ }`),U.length>0&&(I=` (
277
+ ${U.join(`
253
278
  `)}
254
- )`)}if(c+=`def Mesh "${y}"${R}
279
+ )`)}if(s+=`def Mesh "${T}"${I}
255
280
  {
256
- `,b?.physics&&b.physics!=="none"){let p=b.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
257
- bool physics:kinematicEnabled = ${p}
281
+ `,R?.physics&&R.physics!=="none"){let U=R.physics==="static"?"true":"false";s+=`bool physics:rigidBodyEnabled = true
282
+ bool physics:kinematicEnabled = ${U}
258
283
  bool physics:collisionEnabled = true
259
- `}if(s.timeSamples&&s.timeSamples.times.length>0){let p=s.timeSamples,E=p.times.map((D,g)=>{let T=p.translations?.[g]||[0,0,0];return`${W(D)}: (${W(T[0])}, ${W(T[1])}, ${W(T[2])})`}).join(", "),v=p.times.map((D,g)=>{let T=p.rotations?.[g]||[0,0,0,1];return`${W(D)}: (${W(T[3])}, ${W(T[0])}, ${W(T[1])}, ${W(T[2])})`}).join(", "),_=p.times.map((D,g)=>{let T=p.scales?.[g]||[1,1,1];return`${W(D)}: (${W(T[0])}, ${W(T[1])}, ${W(T[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${E} }
260
- quatf xformOp:orient.timeSamples = { ${v} }
261
- double3 xformOp:scale.timeSamples = { ${_} }
284
+ `}if(a.timeSamples&&a.timeSamples.times.length>0){let U=a.timeSamples,_=U.times.map((p,k)=>{let l=U.translations?.[k]||[0,0,0];return`${xe(p)}: (${xe(l[0])}, ${xe(l[1])}, ${xe(l[2])})`}).join(", "),w=U.times.map((p,k)=>{let l=U.rotations?.[k]||[0,0,0,1];return`${xe(p)}: (${xe(l[3])}, ${xe(l[0])}, ${xe(l[1])}, ${xe(l[2])})`}).join(", "),E=U.times.map((p,k)=>{let l=U.scales?.[k]||[1,1,1];return`${xe(p)}: (${xe(l[0])}, ${xe(l[1])}, ${xe(l[2])})`}).join(", ");s+=`double3 xformOp:translate.timeSamples = { ${_} }
285
+ quatf xformOp:orient.timeSamples = { ${w} }
286
+ double3 xformOp:scale.timeSamples = { ${E} }
262
287
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
263
- `}c+=`float3[] extent = [(${W(m)}, ${W(l)}, ${W(f)}), (${W(d)}, ${W(S)}, ${W(A)})]
264
- int[] faceVertexCounts = [${w}]
265
- int[] faceVertexIndices = [${Rr(s.indices)}]
266
- point3f[] points = [${Cn(s.positions)}]
267
- `,s.normals&&s.normals.length===s.positions.length&&(c+=`normal3f[] normals = [${Cn(s.normals)}] (
288
+ `}s+=`float3[] extent = [(${xe(f)}, ${xe(m)}, ${xe(d)}), (${xe(y)}, ${xe(b)}, ${xe(M)})]
289
+ int[] faceVertexCounts = [${S}]
290
+ int[] faceVertexIndices = [${Di(a.indices)}]
291
+ point3f[] points = [${Or(a.positions)}]
292
+ `,a.normals&&a.normals.length===a.positions.length&&(s+=`normal3f[] normals = [${Or(a.normals)}] (
268
293
  interpolation = "vertex"
269
294
  )
270
- `),s.uvs&&s.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${Sr(s.uvs,a)}] (
295
+ `),a.uvs&&a.uvs.length===u*2&&(s+=`texCoord2f[] primvars:st = [${Ii(a.uvs,u)}] (
271
296
  interpolation = "vertex"
272
297
  )
273
- `),c+=`rel material:binding = </Root/Materials/${P}>
298
+ `),s+=`rel material:binding = </Root/Materials/${G}>
274
299
  }
275
- `}return c+=`}
300
+ `}return s+=`}
276
301
  }
277
- `,c}function Mr(t,e){if(t&&typeof t.traverse=="function"){let i=Er(t,e);return Zt(i)}let n=Ve(t),r=Dn(n);return Zt(r)}var ht=null;function Ar(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!ht){ht=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;ht[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=ht[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function In(t){{let a=globalThis.__three_live_native_build_usdz_zip__;if(typeof a=="function")return a(t)}let e=[],n=0,r=[];for(let a of t){let m=mt(a.filename),l=Ar(a.data),f=a.data.length,d=30+m.length,S=n+d,A=0,M=S%64;M!==0&&(A=64-M);let P=new Uint8Array(d+A),y=new DataView(P.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,l,!0),y.setUint32(18,f,!0),y.setUint32(22,f,!0),y.setUint16(26,m.length,!0),y.setUint16(28,A,!0),P.set(m,30),A>0&&P.fill(0,30+m.length),e.push({offset:n,size:f,crc:l,filenameBytes:m,entry:a}),r.push(P),r.push(a.data),n+=P.length+a.data.length}let i=n;for(let a of e){let m=new Uint8Array(46+a.filenameBytes.length),l=new DataView(m.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),m.set(a.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,c=new Uint8Array(22),h=new DataView(c.buffer);h.setUint32(0,101010256,!0),h.setUint16(4,0,!0),h.setUint16(6,0,!0),h.setUint16(8,e.length,!0),h.setUint16(10,e.length,!0),h.setUint32(12,o,!0),h.setUint32(16,i,!0),h.setUint16(20,0,!0),r.push(c),n+=22;let u=new Uint8Array(n),s=0;for(let a of r)u.set(a,s),s+=a.length;return u}function Ue(t){let e=Mr(t),n=mt(e);return In([{filename:"model.usda",data:n}])}function dt(t){let e=Ve(t),n=Dn(e),r=Zt(n),i=mt(r);return In([{filename:"model.usda",data:i}])}function Jt(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ue(t):dt(t)}function B(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ee(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function q(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function he(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function _r(t){let e=q(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:B(e.distance,.1,10,r?.15:1),deadzoneDeg:B(e.deadzoneDeg,0,90,r?0:15),stiffness:B(e.stiffness,.5,40,6),height:B(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function Cr(t){let e=q(t);if(!e)return null;let n=e.target;return{target:Ee(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:B(e.radius,.01,50,.5),speed:B(e.speed,-20,20,.5),height:B(e.height,-10,10,0),phase:B(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Dr(t){if(!t)return null;let e=q(t)??{},n=B(e.minScale,.001,1e3,.1),r=B(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var Ir=2e3,Pr={rain:600,snow:400,sparks:300,confetti:300};function Lr(t){let e=q(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=c=>B(c,.05,50,2),o=Ee(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(B(e.count,1,Ir,Pr[n])),area:o,speed:B(e.speed,.05,10,1)}}var Ur=4e3;function Nr(t){if(!t)return null;let e=q(t)??{};return{prompt:he(e.prompt,Ur)??"What is this?",holdMs:B(e.holdMs,100,5e3,600)}}function kr(t){if(!t)return null;let e=q(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function en(t){let e=he(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Fr(t){if(typeof t=="string"){let r=en(t);return r?{src:r,refDistance:1,loop:!1}:null}let e=q(t),n=en(e?.src);return!e||!n?null:{src:n,refDistance:B(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function ft(t,e){let n=he(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var Or=new Set(["m","cm","mm","in","ft-in","auto"]),Pn=["x","y","z"];function zr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&Or.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(h=>typeof h=="string"):typeof i=="string"?i.split(""):[]),c=Pn.filter(h=>o.has(h));return{enabled:!0,unit:r,axes:c.length>0?c:[...Pn],color:ft(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var Br=new Set(["none","floor","wall","ceiling","any"]);function Vr(t){if(!t)return null;let e=q(t)??{},n=e.grid,r=c=>B(c,.001,100,.1),i=Ee(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:B(e.angleDeg,0,180,0),surface:typeof o=="string"&&Br.has(o)?o:"none",socketTag:he(e.socketTag,128)??"",radius:B(e.radius,.01,2,.15)}}function Hr(t){if(typeof t=="string"){let r=he(t,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=q(t),n=he(e?.tag,128);return!e||!n?null:{tag:n,radius:B(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:ft(e.highlightColor,"#22c55e")}}function Xr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(B(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function Gr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(Ee(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:B(e?.distance,0,10,.35),layer:Math.round(B(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var tn=new Set(["__proto__","constructor","prototype"]);function Wr(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||tn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function Qt(t){let e=q(t);if(!e||e.persist===!1)return null;let n=Wr(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function $r(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}var Ln=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),Yr=new Set(["capsule","cylindrical","spherical"]),Xe=[];function Un(t){Xe.includes(t)||Xe.push(t)}function pt(t){let e=q(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=v=>n.includes(v),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let c=e.scale??e.scalable;if(c||r("scale")){let v=q(c)??{},_=B(v.min,.001,1e3,.05);i.scale={min:_,max:B(v.max,_,1e3,Math.max(_,5))},i.scalable=!0}let h=e.billboard;typeof h=="string"&&Yr.has(h)?i.billboard=h:(h===!0||r("billboard"))&&(i.billboard="capsule");let u=e.follow,s=typeof u=="string"?u:q(u)?.mode;if(typeof u=="string"?u:q(u)?.lazy===!1)i.follow=s==="hand-left"||s==="hand-right"?s:"head";else{let v=_r(u);v&&(i.follow=v)}let a=e.anchor;if(typeof a=="string"&&Ln.has(a))i.anchor=a;else{let _=q(a)?.target;typeof _=="string"&&Ln.has(_)&&(i.anchor=_);let D=Qt(a)??Qt(e.anchorPersist);D&&(i.anchorPersist=D)}if(!i.anchorPersist){let v=Qt(e.anchorPersist);v&&(i.anchorPersist=v)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let m=Cr(e.orbit);m&&(i.orbit=m);let l=Dr(e.handles);l&&(i.handles=l);let f=Lr(e.particles);f&&(i.particles=f);let d=Nr(e.holdToAsk);d&&(i.holdToAsk=d);let S=kr(e.worldUnderstanding);S&&(i.worldUnderstanding=S);let A=en(e.splatUrl);A&&(i.splatUrl=A);let M=he(e.spatialSlot);M&&(i.spatialSlot=M);let P=Fr(e.audio);P&&(i.audio=P);let y=zr(e.dimensions);y&&(i.dimensions=y);let w=Vr(e.snapTo);w&&(i.snapTo=w);let b=Hr(e.snapSocket);b&&(i.snapSocket=b);let R=Xr(e.gaze);R&&(i.gaze=R);let p=Gr(e.explode);p&&(i.explode=p);let E=$r(e.navigable);E&&(i.navigable=E),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let v of Xe)v.normalize(e,i);return Object.keys(i).length>0?i:null}function nn(t){let e={};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat={url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of Xe)n.sceneCore(t,e);return e}function jr(t){let e={},n=(r,i)=>{for(let[o,c]of Object.entries(i)){let h=r+o[0].toUpperCase()+o.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[h]=c:Ee(c)&&(e[h]=[c[0],c[1],c[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Xe)r.usd(t,n,e);return e}function qr(t,e){let n=pt(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:rn(n),ANDROID_xr_scenecore:nn(n)}}function rn(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function Kr(t,e){let n=pt(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(jr(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function Nn(){try{Object.defineProperty(Q(),"xrTraitSerializer",{value:Object.freeze({gltfNode:qr,usdLines:Kr}),writable:!1,configurable:!1,enumerable:!0})}catch{}}function sn(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!tn.has(e)?e:void 0}function bt(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var Zr=["third-person","first-person","top-down","fixed"],Jr=["idle","walk","run","jump"];function Qr(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=B(e.radius,.05,5,.35),r=q(e.clips)??{},i={};for(let o of Jr){let c=he(r[o],128);c&&(i[o]=c)}return{speed:B(e.speed,.1,20,4),runMultiplier:B(e.runMultiplier,1,4,1.6),jumpVelocity:B(e.jumpVelocity,0,30,5.5),gravity:B(e.gravity,0,50,15),radius:n,height:B(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:bt(e.cameraMode,Zr,"third-person"),cameraDistance:B(e.cameraDistance,.5,50,3.5),cameraHeight:B(e.cameraHeight,-10,50,1.8),clips:i}}var ei=["patrol","chase","flee","wander","follow"],ti=32,on="user";function ni(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=bt(e.mode,ei,"wander"),r=e.target,i=r==="camera"||r===on?on:he(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=on);let o=h=>B(h,-1e4,1e4,0),c=Array.isArray(e.waypoints)?e.waypoints.filter(Ee).slice(0,ti).map(h=>[o(h[0]),o(h[1]),o(h[2])]):[];return{mode:n,target:i,speed:B(e.speed,.1,20,2),turnSpeed:B(e.turnSpeed,.1,50,6),sightRadius:B(e.sightRadius,0,100,6),stopDistance:B(e.stopDistance,.01,10,.6),separationRadius:B(e.separationRadius,0,10,.8),waypoints:c,loopWaypoints:e.loopWaypoints!==!1}}function ri(t){if(!t)return null;let e=q(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=B(e.max,1,1e6,100);return{max:n,current:B(e.current,0,n,n),group:sn(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(B(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:B(e.scoreValue,-1e6,1e6,0),contactAmount:B(e.contactAmount,0,1e6,0)}}var ii=16;function oi(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=bt(e.shape,["box","sphere"],"box"),r=e.size,i=m=>B(m,.01,1e3,1),o=Ee(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],c=B(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),h=e.watchGroups,u=[...new Set((Array.isArray(h)?h:h===void 0?[]:[h]).map(sn).filter(m=>m!==void 0))].slice(0,ii),s={shape:n,size:o,radius:c,watchGroups:u},a=ft(e.color,"");return a?{...s,color:a}:s}var si=32;function ai(t){let e=q(t)??(typeof t=="string"?{template:t}:null),n=he(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:B(e.intervalSec,.05,3600,3),maxActive:Math.round(B(e.maxActive,1,si,8)),totalCount:Math.round(B(e.totalCount,0,1e4,0)),spawnRadius:B(e.spawnRadius,0,100,0)}}var ci=["pickup","checkpoint","time-bonus","restore","key"];function ui(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=bt(e.type,ci,"pickup"),r=n==="pickup";return{type:n,amount:B(e.amount??e.points,-1e6,1e6,10),tag:sn(e.tag)??"",radius:B(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(B(e.order,0,1e3,0)),spinSpeed:B(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:B(e.bobAmplitude,0,5,r?.08:0),respawnSec:B(e.respawnSec,0,3600,0)}}var li=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],hi=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function mi(t){let e=q(t);if(!e)return null;let n={};for(let r of hi){let i=e[r];typeof i=="string"&&li.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:B(e.pitchJitter,0,.5,.08),volume:B(e.volume,0,1,1),spatial:e.spatial!==!1}}var di={normalize(t,e){let n=Qr(t.character);n&&(e.character=n);let r=ni(t.agent);r&&(e.agent=r);let i=ri(t.integrity);i&&(e.integrity=i);let o=oi(t.zone);o&&(e.zone=o);let c=ai(t.spawner);c&&(e.spawner=c);let h=ui(t.objective);h&&(e.objective=h);let u=mi(t.audioCues);u&&(e.audioCues=u),t.collidable===!0&&(e.collidable=!0)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(n=>[...n])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.collidable&&(n.collidable=!0)}};function kn(){Un(di)}var yt=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},J=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,c=n.x,h=n.y,u=n.z;return this.x=i*u-o*h,this.y=o*c-r*u,this.z=r*h-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,c=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*c,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*c,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*c,this}},gt=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},$e=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Ye=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,c=Math.cos(r/2),h=Math.cos(i/2),u=Math.cos(o/2),s=Math.sin(r/2),a=Math.sin(i/2),m=Math.sin(o/2);return this._x=s*h*u+c*a*m,this._y=c*a*u-s*h*m,this._z=c*h*m+s*a*u,this._w=c*h*u-s*a*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,c=e.w,h=n.x,u=n.y,s=n.z,a=n.w;return this._x=r*a+c*h+i*s-o*u,this._y=i*a+c*u+o*h-r*s,this._z=o*a+c*s+r*u-i*h,this._w=c*a-r*h-i*u-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},be=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,r){return ct(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return ie(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return Pe(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new J(0,0,0),r=new J(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},xt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return ce(this.elements,e.elements),this}},me=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Xn={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},G=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},vt=class extends G{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Tt=class extends G{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},wt=class extends G{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},ue=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof G)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new G(r,1)}else e&&e.buffer&&(this.index=new G(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new J,o=new J,c=new J,h=new J,u=new J;if(this.index){let s=this.index.array;for(let a=0;a<s.length;a+=3){let m=s[a],l=s[a+1],f=s[a+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(f),e.getY(f),e.getZ(f)),h.subVectors(c,o),u.subVectors(i,o),h.cross(u).normalize();for(let d of[m,l,f])r[d*3]+=h.x,r[d*3+1]+=h.y,r[d*3+2]+=h.z}}else for(let s=0;s<n;s+=3){i.set(e.getX(s),e.getY(s),e.getZ(s)),o.set(e.getX(s+1),e.getY(s+1),e.getZ(s+1)),c.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),h.subVectors(c,o),u.subVectors(i,o),h.cross(u).normalize();for(let a=0;a<3;a++)r[(s+a)*3]=h.x,r[(s+a)*3+1]=h.y,r[(s+a)*3+2]=h.z}for(let s=0;s<n;s++){let a=r[s*3],m=r[s*3+1],l=r[s*3+2],f=Math.hypot(a,m,l)||1;r[s*3]=a/f,r[s*3+1]=m/f,r[s*3+2]=l/f}return this.setAttribute("normal",new G(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new G(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new G(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new G(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},je=class extends ue{constructor(e=1,n=1,r=1){super();{let m=globalThis.__three_live_native_box__;if(typeof m=="function"){let l=m(e,n,r);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let i=e/2,o=n/2,c=r/2,h=[-i,-o,c,i,-o,c,i,o,c,-i,o,c,i,-o,-c,-i,-o,-c,-i,o,-c,i,o,-c,-i,o,c,i,o,c,i,o,-c,-i,o,-c,-i,-o,-c,i,-o,-c,i,-o,c,-i,-o,c,i,-o,c,i,-o,-c,i,o,-c,i,o,c,-i,-o,-c,-i,-o,c,-i,o,c,-i,o,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],s=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let m=0;m<6;m++){let l=m*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new G(new Float32Array(h),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),2)),this.setIndex(a)}},Et=class extends ue{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],h=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},qe=class extends ue{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let s=globalThis.__three_live_native_sphere__;if(typeof s=="function"){let a=s(e,n,r);this.setAttribute("position",new G(a.positions,3)),this.setAttribute("normal",new G(a.normals,3)),this.setAttribute("uv",new G(a.uvs,2)),this.setIndex(a.indices);return}}let i=[],o=[],c=[],h=[],u=[];for(let s=0;s<=r;s++){let a=[],m=s/r;for(let l=0;l<=n;l++){let f=l/n,d=f*Math.PI*2,S=m*Math.PI,A=-e*Math.cos(d)*Math.sin(S),M=e*Math.cos(S),P=e*Math.sin(d)*Math.sin(S);i.push(A,M,P);let y=Math.hypot(A,M,P)||1;o.push(A/y,M/y,P/y),c.push(f,1-m),a.push(i.length/3-1)}u.push(a)}for(let s=0;s<r;s++)for(let a=0;a<n;a++){let m=u[s][a+1],l=u[s][a],f=u[s+1][a],d=u[s+1][a+1];s!==0&&h.push(m,l,d),s!==r-1&&h.push(l,f,d)}this.setAttribute("position",new G(new Float32Array(i),3)),this.setAttribute("normal",new G(new Float32Array(o),3)),this.setAttribute("uv",new G(new Float32Array(c),2)),this.setIndex(h)}},Re=class extends ue{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let a=globalThis.__three_live_native_cylinder__;if(typeof a=="function"){let m=a(e,n,r,i);this.setAttribute("position",new G(m.positions,3)),this.setAttribute("normal",new G(m.normals,3)),this.setAttribute("uv",new G(m.uvs,2)),this.setIndex(m.indices);return}}let o=[],c=[],h=[],u=[],s=r/2;for(let a=0;a<=1;a++){let m=a,l=a===0?e:n,f=a===0?s:-s;for(let d=0;d<=i;d++){let S=d/i,A=S*Math.PI*2,M=Math.sin(A),P=Math.cos(A);o.push(l*M,f,l*P),c.push(M,0,P),h.push(S,1-m)}}for(let a=0;a<i;a++){let m=a,l=a+i+1,f=a+i+2,d=a+1;u.push(m,l,d,l,f,d)}if(e>0){let a=o.length/3;o.push(0,s,0),c.push(0,1,0),h.push(.5,.5);let m=o.length/3;for(let l=0;l<=i;l++){let f=l/i*Math.PI*2,d=Math.sin(f),S=Math.cos(f);o.push(e*d,s,e*S),c.push(0,1,0),h.push(S*.5+.5,d*.5+.5)}for(let l=0;l<i;l++)u.push(a,m+l,m+l+1)}if(n>0){let a=o.length/3;o.push(0,-s,0),c.push(0,-1,0),h.push(.5,.5);let m=o.length/3;for(let l=0;l<=i;l++){let f=l/i*Math.PI*2,d=Math.sin(f),S=Math.cos(f);o.push(n*d,-s,n*S),c.push(0,-1,0),h.push(S*.5+.5,1-(d*.5+.5))}for(let l=0;l<i;l++)u.push(a,m+l+1,m+l)}this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},St=class extends Re{constructor(e=1,n=1,r=16){super(0,e,n,r)}},Rt=class extends ue{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],c=[],h=[],u=[];for(let s=0;s<=r;s++){let a=s/r*Math.PI*2;for(let m=0;m<=i;m++){let l=m/i*Math.PI*2,f=(e+n*Math.cos(a))*Math.cos(l),d=(e+n*Math.cos(a))*Math.sin(l),S=n*Math.sin(a);o.push(f,d,S);let A=e*Math.cos(l),M=e*Math.sin(l),P=f-A,y=d-M,w=S,b=Math.hypot(P,y,w)||1;c.push(P/b,y/b,w/b),h.push(m/i,s/r)}}for(let s=1;s<=r;s++)for(let a=1;a<=i;a++){let m=(i+1)*s+a-1,l=(i+1)*(s-1)+a-1,f=(i+1)*(s-1)+a,d=(i+1)*s+a;u.push(m,l,d,l,f,d)}this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},Mt=class extends ue{constructor(e=1,n=.4,r=64,i=8,o=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let y=globalThis.__three_live_native_torus_knot__;if(typeof y=="function"){let w=y(e,n,r,i,o,c);this.setAttribute("position",new G(w.positions,3)),this.setAttribute("normal",new G(w.normals,3)),this.setAttribute("uv",new G(w.uvs,2)),this.setIndex(w.indices);return}}let h=[],u=[],s=[],a=[],m=new J,l=new J,f=new J,d=new J,S=new J;function A(y,w){let b=Math.cos(w),R=Math.sin(w),p=c/o*w,E=e*(2+Math.cos(p))*.5;y.set(E*b,E*R,e*Math.sin(p)*.5)}let M=[];for(let y=0;y<=i;++y){let w=y/i*Math.PI*2;M.push(-n*Math.cos(w),n*Math.sin(w),y/i)}for(let y=0;y<=r;++y){let w=y/r,b=w*o*Math.PI*2;A(m,b),A(l,b+.01),f.subVectors(l,m).normalize(),d.addVectors(m,l).normalize(),S.crossVectors(f,d).normalize(),d.crossVectors(S,f).normalize();for(let R=0;R<=i;++R){let p=R*3,E=M[p],v=M[p+1],_=M[p+2],D=E*d.x+v*S.x,g=E*d.y+v*S.y,T=E*d.z+v*S.z;h.push(m.x+D,m.y+g,m.z+T);let x=Math.hypot(D,g,T)||1;u.push(D/x,g/x,T/x),s.push(w,_)}}let P=i+1;for(let y=1;y<=r;y++){let w=P*(y-1),b=w+P;for(let R=1;R<=i;R++){let p=w+(R-1),E=b+(R-1),v=b+R,_=w+R;a.push(p,E,_,E,v,_)}}this.setAttribute("position",new G(new Float32Array(h),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),2)),this.setIndex(a)}},Ke=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},At=class{load(e,n){let r=new Ke(e);return n?.(r),r}};function ne(t,e){return t!==void 0?Number(t):e}function an(t,e){return t!==void 0?!!t:e}var de=class{constructor(e={}){this.name=e.name||"",this.color=new me(e.color!==void 0?e.color:16777215),this.emissive=new me(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ne(e.emissiveIntensity,1),this.roughness=ne(e.roughness,.5),this.metalness=ne(e.metalness,.1),this.opacity=ne(e.opacity,1),this.transparent=an(e.transparent,!1),this.wireframe=an(e.wireframe,!1),this.side=ne(e.side,2),this.doubleSided=an(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ne(e.clearcoat,0),this.clearcoatRoughness=ne(e.clearcoatRoughness,0),this.sheen=ne(e.sheen,0),this.sheenColor=new me(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ne(e.sheenRoughness,0),this.transmission=ne(e.transmission,0),this.thickness=ne(e.thickness,0),this.attenuationColor=new me(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ne(e.attenuationDistance,1/0),this.ior=ne(e.ior,1.5),this.dispersion=ne(e.dispersion,0),this.iridescence=ne(e.iridescence,0),this.iridescenceIOR=ne(e.iridescenceIOR,1.3)}dispose(){}},_e=class extends de{},_t=class extends de{},Ct=class extends de{},Dt=class extends de{},It=class extends de{},oe=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new J,this.rotation=new $e,this.quaternion=new Ye,this.scale=new J(1,1,1),this.matrix=new be,this.matrixWorld=new be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new J(e,n,r);this.updateMatrixWorld(!0);let o=new be;o.lookAt(this.position,i,new J(0,1,0));let c=o.elements,h=c[0],u=c[4],s=c[8],a=c[1],m=c[5],l=c[9],f=c[2],d=c[6],S=c[10],A=h+m+S;if(A>0){let M=.5/Math.sqrt(A+1);this.quaternion.set((d-l)*M,(s-f)*M,(a-u)*M,.25/M)}}},Pt=class extends oe{},ke=class extends oe{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof ue?n:n?(se("unsupported geometry","BoxGeometry"),new je(.5,.5,.5)):new ue,this.material=i instanceof de?i:i?(se("unsupported material","MeshStandardMaterial"),new _e({color:13421772})):new _e}},Me=class extends oe{constructor(e=16777215,n=1){super(),this.color=new me(e),this.intensity=Number(n),this.type="directional"}},Ze=class extends Me{constructor(e,n){super(e,n),this.type="ambient"}},Lt=class extends Me{constructor(n,r){super(n,r);this.target=new oe;this.type="directional"}},Je=class extends Me{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},Qe=class extends oe{},Fe=class extends Qe{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new J(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Ce=class extends oe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return fe.validate(this),Le(this)}toGLB(){return fe.validate(this),He(this)}toUSDZ(){return fe.validate(this),Ue(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof ke){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},cn=Le,un=He,Gn=Ue;var fe=class{static validate(e){let n=0,r=0,i=0,o=new Set,c=(u,s,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${s}). Found: ${a}`)},h=(u,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(u=>{if(u instanceof ke){i++,i>1e3&&c("MESHES",1e3,i);let s=u.geometry;if(s){let a=0;if(s.attributes.position&&(a=h("vertex",s.attributes.position.count),n+=a,n>1e5&&c("VERTICES",1e5,n)),s.index){let m=h("index",s.index.count);r+=m,r>3e5&&c("INDICES",3e5,r);let l=s.index.array;if(l&&a>0){let f=Math.min(m,l.length);for(let d=0;d<f;d++){let S=l[d];if(!Number.isFinite(S)||S<0||S>=a)throw new Error(`SecurityError: Index buffer value (${String(S)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&o.add(a.map),a.normalMap&&o.add(a.normalMap),a.roughnessMap&&o.add(a.roughnessMap)}}}),o.size>16&&c("TEXTURES",16,o.size);for(let u of o){let s=u,a=s.image,m=Number(a?.width??s.width??0)||0,l=Number(a?.height??s.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(l)||m>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(m,l))}}},Ut=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new me(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){fe.validate(e);let i=(o,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(o,c):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),c={};for(let[h,u]of o.entries())c[h]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let o=cn(e),c=un(e),h=(o.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:h,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Fn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Nt=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Fn(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Fn();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function fi(){}var Ne=new Proxy(fi,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:Ne},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ne,construct:()=>Ne}),On=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function Oe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ae(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Oe());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var zn,Ge;function Wn(t){if(!Ae(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Ge===void 0||zn!==n){zn=n;try{Ge=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Ae(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Ge=null}}return Ge?Ge.createScriptURL(t):t}function pi(t){Q().sandboxEngineSrc=t}function ln(){let t=Q().sandboxEngineSrc;if(t)return t;if(On)return On;try{if(typeof document>"u")return null;let e=Oe(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Ae(i,{requireSameOrigin:!0}))return i}}catch{}return null}function bi(){let t=ln();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Ae(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}function yi(t){Q().sandboxIframeSrc=t}function $n(){let t=Q().sandboxIframeSrc;if(t)return t;let e=ln();if(!e||!Ae(e))return null;let n=new URL(e,Oe());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function gi(){let t=$n();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Ae(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}function xi(t){Q().allowClientScripts=t}function Yn(){return!!Q().allowClientScripts}function vi(t){if(!Ae(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}var Ti=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function wi(t){let e=self,n=t.nonce,r=t.engineSrc,i=t.allowedScriptUrl,o=t.allowClientScripts,c=t.revoked,h=e.postMessage.bind(e);function u(b){h({type:"ERROR",nonce:n,message:String(b)})}let s=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,m=null;try{let b=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let R={createScriptURL:function(E){if(E!==r&&(!i||E!==i))throw new TypeError("Disallowed worker importScripts URL");return E}};o&&(R.createScript=function(E){return String(E)});let p=e.trustedTypes.createPolicy("three-live#worker-boot",R);b=p.createScriptURL(r),i&&(a=p.createScriptURL(i)),o&&typeof p.createScript=="function"&&(m=p.createScript.bind(p))}catch{}s(b)}catch(b){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(b&&b.message||b));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let b=0;b<c.length;b++){let R=c[b],p=e;for(;p&&p!==Object.prototype;){if(p!==e)try{delete p[R]}catch{}try{Object.defineProperty(p,R,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}}let f=Object.freeze({now:function(){return Date.now()}}),d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:f,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let S=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],A=!1;function M(b,R){if(b.type==="3D_MODEL_READY"){if(A)return;A=!0}b.nonce=n,R&&R.length?h(b,R):h(b)}let P=function(b,R){if(!b||S.indexOf(b.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+S.join(", ")+").");M(b,R)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:P,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let w=!1;e.onmessage=function(b){let R=b&&b.data;if(!(!R||R.nonce!==n)&&!(R.type!=="EXECUTE"&&R.type!=="EXECUTE_URL")&&!w){w=!0;try{let p=new l.Scene,E=new l.PerspectiveCamera(60,1,.1,1e3),v=new l.WebGLRenderer({isSandboxed:!0});if(R.type==="EXECUTE_URL"){if(!i||R.scriptUrl!==i||typeof s!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=a||i,D=s;if(s=null,a=null,e.THREE=l,e.scene=p,e.camera=E,e.renderer=v,D(_),typeof e.__THREE_LIVE_SCENE__=="function"){let g=e.__THREE_LIVE_SCENE__(l,p,E,v);g&&typeof g.toGLB=="function"&&(p=g)}else e.scene&&typeof e.scene.toGLB=="function"&&(p=e.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
302
+ `,s}function ki(t,e){if(t&&typeof t.traverse=="function"){let i=Ci(t,e);return $n(i)}let n=Nt(t),r=Ur(n);return $n(r)}var rn=null;function Pi(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!rn){rn=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;rn[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=rn[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function zr(t){{let u=globalThis.__three_live_native_build_usdz_zip__;if(typeof u=="function")return u(t)}let e=[],n=0,r=[];for(let u of t){let f=on(u.filename),m=Pi(u.data),d=u.data.length,y=30+f.length,b=n+y,M=0,N=b%64;N!==0&&(M=64-N);let G=new Uint8Array(y+M),T=new DataView(G.buffer);T.setUint32(0,67324752,!0),T.setUint16(4,20,!0),T.setUint16(6,0,!0),T.setUint16(8,0,!0),T.setUint16(10,0,!0),T.setUint16(12,0,!0),T.setUint32(14,m,!0),T.setUint32(18,d,!0),T.setUint32(22,d,!0),T.setUint16(26,f.length,!0),T.setUint16(28,M,!0),G.set(f,30),M>0&&G.fill(0,30+f.length),e.push({offset:n,size:d,crc:m,filenameBytes:f,entry:u}),r.push(G),r.push(u.data),n+=G.length+u.data.length}let i=n;for(let u of e){let f=new Uint8Array(46+u.filenameBytes.length),m=new DataView(f.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint16(14,0,!0),m.setUint32(16,u.crc,!0),m.setUint32(20,u.size,!0),m.setUint32(24,u.size,!0),m.setUint16(28,u.filenameBytes.length,!0),m.setUint16(30,0,!0),m.setUint16(32,0,!0),m.setUint16(34,0,!0),m.setUint16(36,0,!0),m.setUint32(38,0,!0),m.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),n+=f.length}let o=n-i,s=new Uint8Array(22),h=new DataView(s.buffer);h.setUint32(0,101010256,!0),h.setUint16(4,0,!0),h.setUint16(6,0,!0),h.setUint16(8,e.length,!0),h.setUint16(10,e.length,!0),h.setUint32(12,o,!0),h.setUint32(16,i,!0),h.setUint16(20,0,!0),r.push(s),n+=22;let c=new Uint8Array(n),a=0;for(let u of r)c.set(u,a),a+=u.length;return c}function It(t){let e=ki(t),n=on(e);return zr([{filename:"model.usda",data:n}])}function sn(t){let e=Nt(t),n=Ur(e),r=$n(n),i=on(r);return zr([{filename:"model.usda",data:i}])}function Yn(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?It(t):sn(t)}function re(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ke(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Se(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Be(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Li(t){let e=Se(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:re(e.distance,.1,10,r?.15:1),deadzoneDeg:re(e.deadzoneDeg,0,90,r?0:15),stiffness:re(e.stiffness,.5,40,6),height:re(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function Ni(t){let e=Se(t);if(!e)return null;let n=e.target;return{target:Ke(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:re(e.radius,.01,50,.5),speed:re(e.speed,-20,20,.5),height:re(e.height,-10,10,0),phase:re(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Fi(t){if(!t)return null;let e=Se(t)??{},n=re(e.minScale,.001,1e3,.1),r=re(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var Oi=2e3,Ui={rain:600,snow:400,sparks:300,confetti:300};function zi(t){let e=Se(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=s=>re(s,.05,50,2),o=Ke(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(re(e.count,1,Oi,Ui[n])),area:o,speed:re(e.speed,.05,10,1)}}var Vi=4e3;function Bi(t){if(!t)return null;let e=Se(t)??{};return{prompt:Be(e.prompt,Vi)??"What is this?",holdMs:re(e.holdMs,100,5e3,600)}}function Gi(t){if(!t)return null;let e=Se(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function Kn(t){let e=Be(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Hi(t){if(typeof t=="string"){let r=Kn(t);return r?{src:r,refDistance:1,loop:!1}:null}let e=Se(t),n=Kn(e?.src);return!e||!n?null:{src:n,refDistance:re(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function bt(t,e){let n=Be(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var Xi=new Set(["m","cm","mm","in","ft-in","auto"]),Vr=["x","y","z"];function Wi(t){if(!t)return null;let e=Se(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&Xi.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(h=>typeof h=="string"):typeof i=="string"?i.split(""):[]),s=Vr.filter(h=>o.has(h));return{enabled:!0,unit:r,axes:s.length>0?s:[...Vr],color:bt(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var $i=new Set(["none","floor","wall","ceiling","any"]);function Yi(t){if(!t)return null;let e=Se(t)??{},n=e.grid,r=s=>re(s,.001,100,.1),i=Ke(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:re(e.angleDeg,0,180,0),surface:typeof o=="string"&&$i.has(o)?o:"none",socketTag:Be(e.socketTag,128)??"",radius:re(e.radius,.01,2,.15)}}function ji(t){if(typeof t=="string"){let r=Be(t,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=Se(t),n=Be(e?.tag,128);return!e||!n?null:{tag:n,radius:re(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:bt(e.highlightColor,"#22c55e")}}function Ki(t){if(!t)return null;let e=Se(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(re(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function qi(t){if(!t)return null;let e=Se(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(Ke(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:re(e?.distance,0,10,.35),layer:Math.round(re(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var qn=new Set(["__proto__","constructor","prototype"]);function Ot(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||qn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function jn(t){let e=Se(t);if(!e||e.persist===!1)return null;let n=Ot(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function Zi(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function Qi(t){if(typeof t=="string"){let s=Be(t,256);return s?{text:s,size:.12,depth:.02,color:"#ffffff"}:null}let e=Se(t);if(!e)return null;let n=Be(e.text??e.value,256);if(!n)return null;let r=re(e.size,.005,10,.12),i=re(e.depth??e.height,.001,5,r*.2),o=bt(e.color,"#ffffff");return{text:n,size:r,depth:i,color:o}}function Ji(t){if(t===!1||t===null||t===void 0)return null;if(typeof t=="number")return!Number.isFinite(t)||t<=0?null:{enabled:!0,strength:re(t,0,5,.35),threshold:.8,radius:.5};if(t===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let e=Se(t);if(!e||e.enabled===!1)return null;let n=re(e.strength??e.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:re(e.threshold,0,4,.8),radius:re(e.radius,0,2,.5)}}function eo(t){if(!t)return null;if(typeof t=="string")return{enabled:!0,color:bt(t,"#38bdf8"),thickness:3,pulse:!1};if(t===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let e=Se(t);return!e||e.enabled===!1?null:{enabled:!0,color:bt(e.color,"#38bdf8"),thickness:re(e.thickness??e.width,.5,20,3),pulse:e.pulse===!0}}function to(t){let e=Se(t);if(!e||e.enabled===!1)return null;let n=Ot(e.root),r=Ot(e.effector);if(!n||!r)return null;let i=Ot(e.mid),o=e.target,s;if(Ke(o))s=[re(o[0],-1e3,1e3,0),re(o[1],-1e3,1e3,0),re(o[2],-1e3,1e3,0)];else{let u=Ot(o);if(!u)return null;s=u}let h=e.pole,c=Ke(h)?[re(h[0],-1e3,1e3,0),re(h[1],-1e3,1e3,0),re(h[2],-1e3,1e3,0)]:void 0,a=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||i?"two-bone":"fabrik";return{root:n,...i?{mid:i}:{},effector:r,target:s,...c?{pole:c}:{},solver:a,iterations:Math.round(re(e.iterations,1,32,8)),tolerance:re(e.tolerance,1e-5,.1,.001),weight:re(e.weight,0,1,1)}}var Br=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),no=new Set(["capsule","cylindrical","spherical"]),Ut=[];function Gr(t){Ut.includes(t)||Ut.push(t)}function an(t){let e=Se(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=l=>n.includes(l),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let s=e.scale??e.scalable;if(s||r("scale")){let l=Se(s)??{},g=re(l.min,.001,1e3,.05);i.scale={min:g,max:re(l.max,g,1e3,Math.max(g,5))},i.scalable=!0}let h=e.billboard;typeof h=="string"&&no.has(h)?i.billboard=h:(h===!0||r("billboard"))&&(i.billboard="capsule");let c=e.follow,a=typeof c=="string"?c:Se(c)?.mode;if(typeof c=="string"?c:Se(c)?.lazy===!1)i.follow=a==="hand-left"||a==="hand-right"?a:"head";else{let l=Li(c);l&&(i.follow=l)}let u=e.anchor;if(typeof u=="string"&&Br.has(u))i.anchor=u;else{let g=Se(u)?.target;typeof g=="string"&&Br.has(g)&&(i.anchor=g);let L=jn(u)??jn(e.anchorPersist);L&&(i.anchorPersist=L)}if(!i.anchorPersist){let l=jn(e.anchorPersist);l&&(i.anchorPersist=l)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let f=Ni(e.orbit);f&&(i.orbit=f);let m=Fi(e.handles);m&&(i.handles=m);let d=zi(e.particles);d&&(i.particles=d);let y=Bi(e.holdToAsk);y&&(i.holdToAsk=y);let b=Gi(e.worldUnderstanding);b&&(i.worldUnderstanding=b);let M=Kn(e.splatUrl);M&&(i.splatUrl=M),(e.splatQuality==="high"||e.splatQuality==="standard")&&(i.splatQuality=e.splatQuality);let N=Be(e.spatialSlot);N&&(i.spatialSlot=N);let G=Hi(e.audio);G&&(i.audio=G);let T=Wi(e.dimensions);T&&(i.dimensions=T);let S=Yi(e.snapTo);S&&(i.snapTo=S);let R=ji(e.snapSocket);R&&(i.snapSocket=R);let I=Ki(e.gaze);I&&(i.gaze=I);let U=qi(e.explode);U&&(i.explode=U);let _=Zi(e.navigable);_&&(i.navigable=_);let w=Qi(e.text);w&&(i.text=w);let E=Ji(e.bloom);E&&(i.bloom=E);let p=eo(e.outline);p&&(i.outline=p);let k=to(e.ik);k&&(i.ik=k),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let l of Ut)l.normalize(e,i);return Object.keys(i).length>0?i:null}function Zn(t){let e={};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat=t.splatQuality?{url:t.splatUrl,quality:t.splatQuality}:{url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),t.text&&(e.text3d={...t.text}),t.bloom&&(e.bloom={...t.bloom}),t.outline&&(e.outline={...t.outline}),t.ik&&(e.ik={...t.ik,...Array.isArray(t.ik.target)?{target:[...t.ik.target]}:{},...t.ik.pole?{pole:[...t.ik.pole]}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of Ut)n.sceneCore(t,e);return e}function ro(t){let e={},n=(r,i)=>{for(let[o,s]of Object.entries(i)){let h=r+o[0].toUpperCase()+o.slice(1);typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[h]=s:Ke(s)&&(e[h]=[s[0],s[1],s[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&n("text",t.text),t.bloom&&n("bloom",t.bloom),t.outline&&n("outline",t.outline),t.ik&&n("ik",t.ik),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Ut)r.usd(t,n,e);return e}function io(t,e){let n=an(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:Qn(n),ANDROID_xr_scenecore:Zn(n)}}function Qn(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function oo(t,e){let n=an(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(ro(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(s=>Number.isFinite(s))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function Hr(){try{Object.defineProperty(Ae(),"xrTraitSerializer",{value:Object.freeze({gltfNode:io,usdLines:oo}),writable:!1,configurable:!1,enumerable:!0})}catch{}}function er(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!qn.has(e)?e:void 0}function cn(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var so=["third-person","first-person","top-down","fixed"],ao=["idle","walk","run","jump"];function co(t){if(!t)return null;let e=Se(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=re(e.radius,.05,5,.35),r=Se(e.clips)??{},i={};for(let o of ao){let s=Be(r[o],128);s&&(i[o]=s)}return{speed:re(e.speed,.1,20,4),runMultiplier:re(e.runMultiplier,1,4,1.6),jumpVelocity:re(e.jumpVelocity,0,30,5.5),gravity:re(e.gravity,0,50,15),radius:n,height:re(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:cn(e.cameraMode,so,"third-person"),cameraDistance:re(e.cameraDistance,.5,50,3.5),cameraHeight:re(e.cameraHeight,-10,50,1.8),clips:i}}var uo=["patrol","chase","flee","wander","follow"],lo=32,Jn="user";function ho(t){if(!t)return null;let e=Se(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=cn(e.mode,uo,"wander"),r=e.target,i=r==="camera"||r===Jn?Jn:Be(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=Jn);let o=h=>re(h,-1e4,1e4,0),s=Array.isArray(e.waypoints)?e.waypoints.filter(Ke).slice(0,lo).map(h=>[o(h[0]),o(h[1]),o(h[2])]):[];return{mode:n,target:i,speed:re(e.speed,.1,20,2),turnSpeed:re(e.turnSpeed,.1,50,6),sightRadius:re(e.sightRadius,0,100,6),stopDistance:re(e.stopDistance,.01,10,.6),separationRadius:re(e.separationRadius,0,10,.8),waypoints:s,loopWaypoints:e.loopWaypoints!==!1}}function mo(t){if(!t)return null;let e=Se(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=re(e.max,1,1e6,100);return{max:n,current:re(e.current,0,n,n),group:er(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(re(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:re(e.scoreValue,-1e6,1e6,0),contactAmount:re(e.contactAmount,0,1e6,0)}}var fo=16;function po(t){if(!t)return null;let e=Se(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=cn(e.shape,["box","sphere"],"box"),r=e.size,i=f=>re(f,.01,1e3,1),o=Ke(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],s=re(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),h=e.watchGroups,c=[...new Set((Array.isArray(h)?h:h===void 0?[]:[h]).map(er).filter(f=>f!==void 0))].slice(0,fo),a={shape:n,size:o,radius:s,watchGroups:c},u=bt(e.color,"");return u?{...a,color:u}:a}var bo=32;function yo(t){let e=Se(t)??(typeof t=="string"?{template:t}:null),n=Be(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:re(e.intervalSec,.05,3600,3),maxActive:Math.round(re(e.maxActive,1,bo,8)),totalCount:Math.round(re(e.totalCount,0,1e4,0)),spawnRadius:re(e.spawnRadius,0,100,0)}}var go=["pickup","checkpoint","time-bonus","restore","key"];function xo(t){if(!t)return null;let e=Se(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=cn(e.type,go,"pickup"),r=n==="pickup";return{type:n,amount:re(e.amount??e.points,-1e6,1e6,10),tag:er(e.tag)??"",radius:re(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(re(e.order,0,1e3,0)),spinSpeed:re(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:re(e.bobAmplitude,0,5,r?.08:0),respawnSec:re(e.respawnSec,0,3600,0)}}var vo=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],To=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function Mo(t){let e=Se(t);if(!e)return null;let n={};for(let r of To){let i=e[r];typeof i=="string"&&vo.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:re(e.pitchJitter,0,.5,.08),volume:re(e.volume,0,1,1),spatial:e.spatial!==!1}}var wo={normalize(t,e){let n=co(t.character);n&&(e.character=n);let r=ho(t.agent);r&&(e.agent=r);let i=mo(t.integrity);i&&(e.integrity=i);let o=po(t.zone);o&&(e.zone=o);let s=yo(t.spawner);s&&(e.spawner=s);let h=xo(t.objective);h&&(e.objective=h);let c=Mo(t.audioCues);c&&(e.audioCues=c),t.collidable===!0&&(e.collidable=!0)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(n=>[...n])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.collidable&&(n.collidable=!0)}};function Xr(){Gr(wo)}var ln=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},Ce=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,s=n.x,h=n.y,c=n.z;return this.x=i*c-o*h,this.y=o*s-r*c,this.z=r*h-i*s,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,s=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*s,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*s,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*s,this}},hn=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},Bt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Gt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,s=Math.cos(r/2),h=Math.cos(i/2),c=Math.cos(o/2),a=Math.sin(r/2),u=Math.sin(i/2),f=Math.sin(o/2);return this._x=a*h*c+s*u*f,this._y=s*u*c-a*h*f,this._z=s*h*f+a*u*c,this._w=s*h*c-a*u*f,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,s=e.w,h=n.x,c=n.y,a=n.z,u=n.w;return this._x=r*u+s*h+i*a-o*c,this._y=i*u+s*c+o*h-r*a,this._z=o*u+s*a+r*c-i*h,this._w=s*u-r*h-i*c-o*a,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Je=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,r){return pt(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return _e(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return Rt(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new Ce(0,0,0),r=new Ce(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},mn=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return ze(this.elements,e.elements),this}},$e=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Zr={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},pe=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},fn=class extends pe{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},dn=class extends pe{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},pn=class extends pe{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Xe=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof pe)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new pe(r,1)}else e&&e.buffer&&(this.index=new pe(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new Ce,o=new Ce,s=new Ce,h=new Ce,c=new Ce;if(this.index){let a=this.index.array;for(let u=0;u<a.length;u+=3){let f=a[u],m=a[u+1],d=a[u+2];i.set(e.getX(f),e.getY(f),e.getZ(f)),o.set(e.getX(m),e.getY(m),e.getZ(m)),s.set(e.getX(d),e.getY(d),e.getZ(d)),h.subVectors(s,o),c.subVectors(i,o),h.cross(c).normalize();for(let y of[f,m,d])r[y*3]+=h.x,r[y*3+1]+=h.y,r[y*3+2]+=h.z}}else for(let a=0;a<n;a+=3){i.set(e.getX(a),e.getY(a),e.getZ(a)),o.set(e.getX(a+1),e.getY(a+1),e.getZ(a+1)),s.set(e.getX(a+2),e.getY(a+2),e.getZ(a+2)),h.subVectors(s,o),c.subVectors(i,o),h.cross(c).normalize();for(let u=0;u<3;u++)r[(a+u)*3]=h.x,r[(a+u)*3+1]=h.y,r[(a+u)*3+2]=h.z}for(let a=0;a<n;a++){let u=r[a*3],f=r[a*3+1],m=r[a*3+2],d=Math.hypot(u,f,m)||1;r[a*3]=u/d,r[a*3+1]=f/d,r[a*3+2]=m/d}return this.setAttribute("normal",new pe(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new pe(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new pe(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new pe(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new Ce(1/0,1/0,1/0),r=new Ce(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),s=e.getY(i),h=e.getZ(i);o<n.x&&(n.x=o),s<n.y&&(n.y=s),h<n.z&&(n.z=h),o>r.x&&(r.x=o),s>r.y&&(r.y=s),h>r.z&&(r.z=h)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),n=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let s=0;s<o.count;s++)o.setXYZ(s,o.getX(s)-n,o.getY(s)-r,o.getZ(s)-i);this.computeBoundingBox()}return this}dispose(){}},Ht=class extends Xe{constructor(e=1,n=1,r=1){super();{let f=globalThis.__three_live_native_box__;if(typeof f=="function"){let m=f(e,n,r);this.setFromBuffers(m.positions,m.normals,m.uvs,m.indices);return}}let i=e/2,o=n/2,s=r/2,h=[-i,-o,s,i,-o,s,i,o,s,-i,o,s,i,-o,-s,-i,-o,-s,-i,o,-s,i,o,-s,-i,o,s,i,o,s,i,o,-s,-i,o,-s,-i,-o,-s,i,-o,-s,i,-o,s,-i,-o,s,i,-o,s,i,-o,-s,i,o,-s,i,o,s,-i,-o,-s,-i,-o,s,-i,o,s,-i,o,-s],c=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],a=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],u=[];for(let f=0;f<6;f++){let m=f*4;u.push(m,m+1,m+2,m,m+2,m+3)}this.setAttribute("position",new pe(new Float32Array(h),3)),this.setAttribute("normal",new pe(new Float32Array(c),3)),this.setAttribute("uv",new pe(new Float32Array(a),2)),this.setIndex(u)}},bn=class extends Xe{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],s=[0,0,1,0,0,1,0,0,1,0,0,1],h=[0,1,1,1,0,0,1,0],c=[0,2,1,2,3,1];this.setAttribute("position",new pe(new Float32Array(o),3)),this.setAttribute("normal",new pe(new Float32Array(s),3)),this.setAttribute("uv",new pe(new Float32Array(h),2)),this.setIndex(c)}},Xt=class extends Xe{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let a=globalThis.__three_live_native_sphere__;if(typeof a=="function"){let u=a(e,n,r);this.setAttribute("position",new pe(u.positions,3)),this.setAttribute("normal",new pe(u.normals,3)),this.setAttribute("uv",new pe(u.uvs,2)),this.setIndex(u.indices);return}}let i=[],o=[],s=[],h=[],c=[];for(let a=0;a<=r;a++){let u=[],f=a/r;for(let m=0;m<=n;m++){let d=m/n,y=d*Math.PI*2,b=f*Math.PI,M=-e*Math.cos(y)*Math.sin(b),N=e*Math.cos(b),G=e*Math.sin(y)*Math.sin(b);i.push(M,N,G);let T=Math.hypot(M,N,G)||1;o.push(M/T,N/T,G/T),s.push(d,1-f),u.push(i.length/3-1)}c.push(u)}for(let a=0;a<r;a++)for(let u=0;u<n;u++){let f=c[a][u+1],m=c[a][u],d=c[a+1][u],y=c[a+1][u+1];a!==0&&h.push(f,m,y),a!==r-1&&h.push(m,d,y)}this.setAttribute("position",new pe(new Float32Array(i),3)),this.setAttribute("normal",new pe(new Float32Array(o),3)),this.setAttribute("uv",new pe(new Float32Array(s),2)),this.setIndex(h)}},lt=class extends Xe{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let u=globalThis.__three_live_native_cylinder__;if(typeof u=="function"){let f=u(e,n,r,i);this.setAttribute("position",new pe(f.positions,3)),this.setAttribute("normal",new pe(f.normals,3)),this.setAttribute("uv",new pe(f.uvs,2)),this.setIndex(f.indices);return}}let o=[],s=[],h=[],c=[],a=r/2;for(let u=0;u<=1;u++){let f=u,m=u===0?e:n,d=u===0?a:-a;for(let y=0;y<=i;y++){let b=y/i,M=b*Math.PI*2,N=Math.sin(M),G=Math.cos(M);o.push(m*N,d,m*G),s.push(N,0,G),h.push(b,1-f)}}for(let u=0;u<i;u++){let f=u,m=u+i+1,d=u+i+2,y=u+1;c.push(f,m,y,m,d,y)}if(e>0){let u=o.length/3;o.push(0,a,0),s.push(0,1,0),h.push(.5,.5);let f=o.length/3;for(let m=0;m<=i;m++){let d=m/i*Math.PI*2,y=Math.sin(d),b=Math.cos(d);o.push(e*y,a,e*b),s.push(0,1,0),h.push(b*.5+.5,y*.5+.5)}for(let m=0;m<i;m++)c.push(u,f+m,f+m+1)}if(n>0){let u=o.length/3;o.push(0,-a,0),s.push(0,-1,0),h.push(.5,.5);let f=o.length/3;for(let m=0;m<=i;m++){let d=m/i*Math.PI*2,y=Math.sin(d),b=Math.cos(d);o.push(n*y,-a,n*b),s.push(0,-1,0),h.push(b*.5+.5,1-(y*.5+.5))}for(let m=0;m<i;m++)c.push(u,f+m+1,f+m)}this.setAttribute("position",new pe(new Float32Array(o),3)),this.setAttribute("normal",new pe(new Float32Array(s),3)),this.setAttribute("uv",new pe(new Float32Array(h),2)),this.setIndex(c)}},yn=class extends lt{constructor(e=1,n=1,r=16){super(0,e,n,r)}},gn=class extends Xe{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],s=[],h=[],c=[];for(let a=0;a<=r;a++){let u=a/r*Math.PI*2;for(let f=0;f<=i;f++){let m=f/i*Math.PI*2,d=(e+n*Math.cos(u))*Math.cos(m),y=(e+n*Math.cos(u))*Math.sin(m),b=n*Math.sin(u);o.push(d,y,b);let M=e*Math.cos(m),N=e*Math.sin(m),G=d-M,T=y-N,S=b,R=Math.hypot(G,T,S)||1;s.push(G/R,T/R,S/R),h.push(f/i,a/r)}}for(let a=1;a<=r;a++)for(let u=1;u<=i;u++){let f=(i+1)*a+u-1,m=(i+1)*(a-1)+u-1,d=(i+1)*(a-1)+u,y=(i+1)*a+u;c.push(f,m,y,m,d,y)}this.setAttribute("position",new pe(new Float32Array(o),3)),this.setAttribute("normal",new pe(new Float32Array(s),3)),this.setAttribute("uv",new pe(new Float32Array(h),2)),this.setIndex(c)}},xn=class extends Xe{constructor(e=1,n=.4,r=64,i=8,o=2,s=3){super(),r=Math.floor(r),i=Math.floor(i);{let T=globalThis.__three_live_native_torus_knot__;if(typeof T=="function"){let S=T(e,n,r,i,o,s);this.setAttribute("position",new pe(S.positions,3)),this.setAttribute("normal",new pe(S.normals,3)),this.setAttribute("uv",new pe(S.uvs,2)),this.setIndex(S.indices);return}}let h=[],c=[],a=[],u=[],f=new Ce,m=new Ce,d=new Ce,y=new Ce,b=new Ce;function M(T,S){let R=Math.cos(S),I=Math.sin(S),U=s/o*S,_=e*(2+Math.cos(U))*.5;T.set(_*R,_*I,e*Math.sin(U)*.5)}let N=[];for(let T=0;T<=i;++T){let S=T/i*Math.PI*2;N.push(-n*Math.cos(S),n*Math.sin(S),T/i)}for(let T=0;T<=r;++T){let S=T/r,R=S*o*Math.PI*2;M(f,R),M(m,R+.01),d.subVectors(m,f).normalize(),y.addVectors(f,m).normalize(),b.crossVectors(d,y).normalize(),y.crossVectors(b,d).normalize();for(let I=0;I<=i;++I){let U=I*3,_=N[U],w=N[U+1],E=N[U+2],p=_*y.x+w*b.x,k=_*y.y+w*b.y,l=_*y.z+w*b.z;h.push(f.x+p,f.y+k,f.z+l);let g=Math.hypot(p,k,l)||1;c.push(p/g,k/g,l/g),a.push(S,E)}}let G=i+1;for(let T=1;T<=r;T++){let S=G*(T-1),R=S+G;for(let I=1;I<=i;I++){let U=S+(I-1),_=R+(I-1),w=R+I,E=S+I;u.push(U,_,E,_,w,E)}}this.setAttribute("position",new pe(new Float32Array(h),3)),this.setAttribute("normal",new pe(new Float32Array(c),3)),this.setAttribute("uv",new pe(new Float32Array(a),2)),this.setIndex(u)}},Wt=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},vn=class{load(e,n){let r=new Wt(e);return n?.(r),r}};function Ne(t,e){return t!==void 0?Number(t):e}function tr(t,e){return t!==void 0?!!t:e}var We=class{constructor(e={}){this.name=e.name||"",this.color=new $e(e.color!==void 0?e.color:16777215),this.emissive=new $e(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Ne(e.emissiveIntensity,1),this.roughness=Ne(e.roughness,.5),this.metalness=Ne(e.metalness,.1),this.opacity=Ne(e.opacity,1),this.transparent=tr(e.transparent,!1),this.wireframe=tr(e.wireframe,!1),this.side=Ne(e.side,2),this.doubleSided=tr(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Ne(e.clearcoat,0),this.clearcoatRoughness=Ne(e.clearcoatRoughness,0),this.sheen=Ne(e.sheen,0),this.sheenColor=new $e(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Ne(e.sheenRoughness,0),this.transmission=Ne(e.transmission,0),this.thickness=Ne(e.thickness,0),this.attenuationColor=new $e(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Ne(e.attenuationDistance,1/0),this.ior=Ne(e.ior,1.5),this.dispersion=Ne(e.dispersion,0),this.iridescence=Ne(e.iridescence,0),this.iridescenceIOR=Ne(e.iridescenceIOR,1.3)}dispose(){}},ht=class extends We{},Tn=class extends We{},Mn=class extends We{},wn=class extends We{},Sn=class extends We{},Ge=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new Ce,this.rotation=new Bt,this.quaternion=new Gt,this.scale=new Ce(1,1,1),this.matrix=new Je,this.matrixWorld=new Je,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){nr(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new Ce(e,n,r);this.updateMatrixWorld(!0);let o=new Je;o.lookAt(this.position,i,new Ce(0,1,0));let s=o.elements,h=s[0],c=s[4],a=s[8],u=s[1],f=s[5],m=s[9],d=s[2],y=s[6],b=s[10],M=h+f+b;if(M>0){let N=.5/Math.sqrt(M+1);this.quaternion.set((y-m)*N,(a-d)*N,(u-c)*N,.25/N)}}},An=class extends Ge{},yt=class extends Ge{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Xe?n:n?(He("unsupported geometry","BoxGeometry"),new Ht(.5,.5,.5)):new Xe,this.material=i instanceof We?i:i?(He("unsupported material","MeshStandardMaterial"),new ht({color:13421772})):new ht}};function nr(t){let e=Ae().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var $t=1e4,kt=class extends yt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>$t)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${$t})`);this.count=Math.floor(o);let s=new Float32Array(this.count*16);for(let h=0;h<this.count;h++){let c=h*16;s[c]=1,s[c+5]=1,s[c+10]=1,s[c+15]=1}this.instanceMatrix=new pe(s,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let h=0;h<16;h++){let c=Number(r.elements[h]);o[s+h]=Number.isFinite(c)?c:h%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let h=0;h<16;h++)r.elements[h]=o[s+h]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let h=new Float32Array(this.count*3);h.fill(1),this.instanceColor=new pe(h,3)}let o=this.instanceColor.array,s=i*3;o[s]=Number.isFinite(r.r)?r.r:1,o[s+1]=Number.isFinite(r.g)?r.g:1,o[s+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,s=i*3;r.setRGB(o[s],o[s+1],o[s+2])}dispose(){}},mt=class extends Ge{constructor(e=16777215,n=1){super(),this.color=new $e(e),this.intensity=Number(n),this.type="directional"}},Yt=class extends mt{constructor(e,n){super(e,n),this.type="ambient"}},En=class extends mt{constructor(n,r){super(n,r);this.target=new Ge;this.type="directional"}},jt=class extends mt{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},Kt=class extends Ge{},Pt=class extends Kt{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Ce(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},gt=class extends Ge{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return qe.validate(this),Ct(this)}toGLB(){return qe.validate(this),Ft(this)}toUSDZ(){return qe.validate(this),It(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof yt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},rr=Ct,ir=Ft,Qr=It;var qe=class{static validate(e){let n=0,r=0,i=0,o=new Set,s=(c,a,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${c} (${a}). Found: ${u}`)},h=(c,a)=>{if(!Number.isFinite(a))throw new Error(`SecurityError: Scene reports a non-finite ${c} count (${String(a)}), which cannot be bounds-checked.`);return a};e.traverse(c=>{if(nr(c),c instanceof yt||c.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),c instanceof kt){let u=h("instance",c.count);(u<0||u>$t)&&s("INSTANCES",$t,u)}let a=c.geometry;if(a){let u=0;if(a.attributes.position&&(u=h("vertex",a.attributes.position.count),n+=u,n>1e5&&s("VERTICES",1e5,n)),a.index){let f=h("index",a.index.count);r+=f,r>3e5&&s("INDICES",3e5,r);let m=a.index.array;if(m&&u>0){let d=Math.min(f,m.length);for(let y=0;y<d;y++){let b=m[y];if(!Number.isFinite(b)||b<0||b>=u)throw new Error(`SecurityError: Index buffer value (${String(b)}) out of vertex bounds [0, ${u}).`)}}}}if(c.material){let u=c.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&s("TEXTURES",16,o.size);for(let c of o){let a=c,u=a.image,f=Number(u?.width??a.width??0)||0,m=Number(u?.height??a.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(m)||f>2048||m>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(f,m))}}},Rn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new $e(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){qe.validate(e);let i=(o,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(o,s):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),s={};for(let[h,c]of o.entries())s[h]=Array.from(c);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let o=rr(e),s=ir(e),h=(o.lights||[]).map(c=>({type:c.type,color:c.color,intensity:c.intensity,position:c.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:h,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Wr(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var _n=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Wr(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Wr();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function So(){}var Dt=new Proxy(So,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:Dt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Dt,construct:()=>Dt}),$r=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function Lt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function ft(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Lt());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Yr,zt;function Jr(t){if(!ft(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(zt===void 0||Yr!==n){Yr=n;try{zt=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!ft(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{zt=null}}return zt?zt.createScriptURL(t):t}function Ao(t){Ae().sandboxEngineSrc=t}function or(){let t=Ae().sandboxEngineSrc;if(t)return t;if($r)return $r;try{if(typeof document>"u")return null;let e=Lt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&ft(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Eo(){let t=or();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!ft(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Lt()).href}function Ro(t){Ae().sandboxIframeSrc=t}function ei(){let t=Ae().sandboxIframeSrc;if(t)return t;let e=or();if(!e||!ft(e))return null;let n=new URL(e,Lt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function _o(){let t=ei();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!ft(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Lt()).href}function Co(t){Ae().allowClientScripts=t}function ti(){return!!Ae().allowClientScripts}function Io(t){if(!ft(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Lt()).href}var Do=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function ko(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,s=t.allowClientScripts,h=t.revoked,c=n.postMessage.bind(n);function a(I){c({type:"ERROR",nonce:r,message:String(I)})}let u=typeof n.importScripts=="function"?n.importScripts.bind(n):null,f=o,m=null;try{let I=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let U={createScriptURL:function(w){if(w!==i&&(!o||w!==o))throw new TypeError("Disallowed worker importScripts URL");return w}};s&&(U.createScript=function(w){return String(w)});let _=n.trustedTypes.createPolicy("three-live#worker-boot",U);I=_.createScriptURL(i),o&&(f=_.createScriptURL(o)),s&&typeof _.createScript=="function"&&(m=_.createScript.bind(_))}catch{}u(I)}catch(I){a('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(I&&I.message||I));return}let d=n.THREE;if(!d||typeof d.Scene!="function"){a('Sandbox loaded "'+i+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(e)){let I=n.__THREE_LIVE_REGISTRY__;for(let U=0;U<e.length;U++)if(typeof e[U]=="function")try{e[U](d,I)}catch{}}for(let I=0;I<h.length;I++){let U=h[I],_=n;for(;_&&_!==Object.prototype;){if(_!==n)try{delete _[U]}catch{}try{Object.defineProperty(_,U,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{_=Object.getPrototypeOf(_)}catch{break}}}let y=Object.freeze({now:function(){return Date.now()}}),b=n;for(;b&&b!==Object.prototype;){if(b!==n)try{delete b.performance}catch{}try{Object.defineProperty(b,"performance",{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}let M=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],N=!1;function G(I,U){if(I.type==="3D_MODEL_READY"){if(N)return;N=!0}I.nonce=r,U&&U.length?c(I,U):c(I)}let T=function(I,U){if(!I||M.indexOf(I.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+M.join(", ")+").");G(I,U)},S=n;for(;S&&S!==Object.prototype;){if(S===n||Object.prototype.hasOwnProperty.call(S,"postMessage"))try{Object.defineProperty(S,"postMessage",{value:T,writable:!1,configurable:!1})}catch{}try{S=Object.getPrototypeOf(S)}catch{break}}let R=!1;n.onmessage=function(I){let U=I&&I.data;if(!(!U||U.nonce!==r)&&!(U.type!=="EXECUTE"&&U.type!=="EXECUTE_URL")&&!R){R=!0;try{let _=new d.Scene,w=new d.PerspectiveCamera(60,1,.1,1e3),E=new d.WebGLRenderer({isSandboxed:!0});if(U.type==="EXECUTE_URL"){if(!o||U.scriptUrl!==o||typeof u!="function"){a("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let p=f||o,k=u;if(u=null,f=null,n.THREE=d,n.scene=_,n.camera=w,n.renderer=E,k(p),typeof n.__THREE_LIVE_SCENE__=="function"){let l=n.__THREE_LIVE_SCENE__(d,_,w,E);l&&typeof l.toGLB=="function"&&(_=l)}else n.scene&&typeof n.scene.toGLB=="function"&&(_=n.scene)}else{if(!s){a("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let p=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
278
303
  return (function () {
279
- `+R.script+`
304
+ `+U.script+`
280
305
  })();
281
306
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
282
- `+R.script+`
283
- })();`);m=null;let D=_(l,p,E,v);D&&typeof D.toGLB=="function"&&(p=D)}if(!A){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(p);let _=p.toGLB(),D=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);M({type:"3D_MODEL_READY",glbBuffer:D},[D])}h({type:"DONE",nonce:n})}catch(p){u(p&&p.message||p)}}},h({type:"READY",nonce:n})}function hn(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Ti};return`'use strict';(${wi.toString()})(${JSON.stringify(o)});`}function jn(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var Se=0;function qn(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ei(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Si=1024,Ri=256;function Bn(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function mn(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Si)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Bn(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let c=Object.create(null),h=i;for(let u of o){if(u.length>Ri||u==="__proto__"||u==="constructor"||u==="prototype")return null;let s=h[u];if(!Bn(s))return null;c[u]=s}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Mi(t){let e=Ei(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Kn(t,e,n,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Ai(t,e,n,r){let i=qn(),o=hn(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=n,Se++;let h=!1,u=!1,s={modelDispatched:!1},a,m=()=>{if(h||u)return;let S=c.contentWindow;!S||typeof S.postMessage!="function"||(u=!0,S.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},l=()=>{},f=S=>{if(h||!c.contentWindow||S.source!==c.contentWindow)return;let A=S.data;if(A&&typeof A=="object"&&A.type==="IFRAME_READY"){m();return}let M=mn(A,i);M&&Kn(M,r,l,s)};l=()=>{h||(h=!0,a!==void 0&&clearTimeout(a),Se=Math.max(0,Se-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",f),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{h||(l(),jn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),c.onload=()=>{m()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let d=document.body||document.documentElement;if(!d||typeof d.appendChild!="function"){l();let S=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(S),S}return d.appendChild(c),{terminate:l}}function Vn(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Se>=32)return r(`SecurityError: ${Se} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=bi()}catch(l){let f=l instanceof Error?l.message:String(l);return r(f,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=gi()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Ai(t,i,l,n))}catch(f){return Promise.reject(f)}}let o=qn(),c=hn(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),h;try{let l=new Blob([c],{type:"application/javascript"}),f=URL.createObjectURL(l);try{let d=Wn(f);h=new Worker(d)}finally{URL.revokeObjectURL(f)}}catch(l){let f=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${f}`,"Security Error: Failed to start Worker sandbox.")}Se++;let u=!1,s={modelDispatched:!1},a,m=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),Se=Math.max(0,Se-1),h.terminate())};return a=setTimeout(()=>{u||(m(),jn(n))},3e3),h.onmessage=l=>{let f=mn(l.data,o);f&&Kn(f,n,m,s)},h.onerror=l=>{m(),n.onError?.(new Error(`Worker execution error: ${l.message}`))},t.kind==="url"?h.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):h.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function Hn(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Zn={execute(t,e,n,r){let i=(h,u)=>{let s=new Error(h);return n.onError?.(s),u&&n.onToast?.(u),Promise.reject(s)},o=Hn(e,i);if(o)return o;try{Mi(t)}catch(h){let u=h instanceof Error?h.message:String(h);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Yn()?Vn({kind:"script",script:t},e,n,i):i(fn,pn)},executeUrl(t,e,n){let r=(c,h)=>{let u=new Error(c);return n.onError?.(u),h&&n.onToast?.(h),Promise.reject(u)},i=Hn(e,r);if(i)return i;let o;try{o=vi(t)}catch(c){let h=c instanceof Error?c.message:String(c);return r(h,"Security Error: disallowed scene script URL.")}return Vn({kind:"url",scriptUrl:o},e,n,r)}},kt=new Set;function se(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;kt.has(n)||(kt.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Jn(){return Array.from(kt)}function dn(){kt.clear()}var et=class extends _e{constructor(e={}){se("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},Qn=et,De=class extends qe{constructor(e=1,n=0,r="PolyhedronGeometry"){se(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Ft=class extends De{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Ot=class extends De{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},zt=class extends De{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},Bt=class extends De{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},Vt=class extends Re{constructor(e=1,n=1,r=4,i=8){se("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Ht=class extends Re{constructor(e=.5,n=1,r=16){se("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},Xt=class extends Re{constructor(e=1,n=16){se("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Gt=class extends Je{constructor(n,r,i=0,o=Math.PI/3,c=0,h=2){se("SpotLight","PointLight");super(n,r,i,h);this.target=new oe;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=c}},tt=class extends Ze{constructor(e,n,r){se("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new me(n??4473924)}},er=tt,tr={Vector2:yt,Vector3:J,Vector4:gt,Euler:$e,Quaternion:Ye,Matrix4:be,Matrix3:xt,Color:me,MathUtils:Xn,BufferAttribute:G,Float32BufferAttribute:vt,Uint16BufferAttribute:Tt,Uint32BufferAttribute:wt,BufferGeometry:ue,BoxGeometry:je,PlaneGeometry:Et,SphereGeometry:qe,CylinderGeometry:Re,ConeGeometry:St,TorusGeometry:Rt,TorusKnotGeometry:Mt,IcosahedronGeometry:Ft,OctahedronGeometry:Ot,DodecahedronGeometry:zt,TetrahedronGeometry:Bt,CapsuleGeometry:Vt,RingGeometry:Ht,CircleGeometry:Xt,Texture:Ke,TextureLoader:At,Material:de,MeshStandardMaterial:_e,MeshBasicMaterial:_t,MeshLambertMaterial:Ct,MeshPhongMaterial:Dt,MeshPhysicalMaterial:It,ShaderMaterial:et,RawShaderMaterial:Qn,Object3D:oe,Group:Pt,Mesh:ke,Light:Me,AmbientLight:Ze,DirectionalLight:Lt,PointLight:Je,SpotLight:Gt,HemisphereLight:tt,RectAreaLight:er,Camera:Qe,PerspectiveCamera:Fe,Scene:Ce,WebGLRenderer:Ut,Clock:Nt,SceneQuotaValidator:fe,exportSceneToCanvas3D:cn,exportSceneToGLB:un,exportSceneToUSDZ:Gn,generateUSDZ:Jt,glbToUSDZ:dt,sceneToCanvas3D:Le,sceneToGLB:He,sceneToUSDZ:Ue,authorScriptRunner:Zn,getAuthorWarnings:Jn,clearAuthorWarnings:dn};Object.freeze(fe);Object.freeze(fe.prototype);Object.freeze(Ce.prototype);Object.freeze(tr);var nt=new Proxy(tr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&se(`THREE.${e}`,"no-op proxy"),Ne),set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),We={name:"three_author",THREE:nt},_i=We,te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof te.THREE>"u"&&(te.THREE=nt);typeof te.requestAnimationFrame!="function"&&(te.requestAnimationFrame=()=>(se("requestAnimationFrame","single-frame static evaluation"),0));typeof te.cancelAnimationFrame!="function"&&(te.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=nt,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=We,t.ThreeLivePlugins.three_author=We,t.ThreeLivePlugins["three-author"]=We}{Nn(),kn();let t=new Ce,e=new Fe(45,1,.1,1e3);e.position.set(0,2,5),te.scene=t,te.camera=e,typeof te.window>"u"&&(te.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof te.document>"u"&&(te.document={createElement:()=>({getContext:()=>Ne,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(te,"__three_live_reset_scene__",{value:function(){dn(),t=new Ce,e=new Fe(45,1,.1,1e3),e.position.set(0,2,5),te.scene=t,te.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let s=2e4,a=new Set,m=(l,f)=>{if(--s<0||f>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(typeof l!="object"||a.has(l))return;a.add(l);let d;if(Array.isArray(l)){d=[];for(let S of l)d.push(m(S,f+1)??null)}else{d={};for(let S of Object.keys(l)){if(S==="__proto__"||S==="prototype"||S==="constructor")continue;let A=m(l[S],f+1);A!==void 0&&(d[S]=A)}}return a.delete(l),d};try{return m(u,0)??null}catch{return null}},i=15*1024,o=1e3*4,c=function(u){let s=pt(u);if(!s)return{};let a=JSON.stringify({...u,...s});return a.length>i&&(se(`userData.xr larger than ${i} characters`,"canonical XR traits only"),a=JSON.stringify(s)),{xr_normalized_json:a,xr_scenecore_json:JSON.stringify(nn(s)),xr_hubs_json:JSON.stringify(rn(s))}};Object.defineProperty(te,"__three_live_extract_scene_raw__",{value:function(){let u=[],s=[],a=[],m=[];function l(g){if(!g)return null;let T=m.indexOf(g);if(T===-1){m.push(g);let x="";g.map&&(typeof g.map=="string"?x=g.map:g.map.source?x=g.map.source:g.map.image&&(x=g.map.image)),s.push({name:g.name||`Material_${s.length}`,base_color:[g.color.r,g.color.g,g.color.b,g.opacity!==void 0?g.opacity:1],metallic:g.metalness!==void 0?g.metalness:.1,roughness:g.roughness!==void 0?g.roughness:.5,double_sided:g.side===2||g.doubleSided,base_color_texture:x||null,clearcoat:g.clearcoat||0,clearcoat_roughness:g.clearcoatRoughness||0,transmission:g.transmission||0,ior:g.ior!==void 0?g.ior:1.5,thickness:g.thickness||0}),T=s.length-1}return T}let f=(g,T)=>typeof g=="number"&&Number.isFinite(g)?g:T,d=[],S=[],A=!1,M=te.scene||t,P=new be().compose({x:f(M.position?.x,0),y:f(M.position?.y,0),z:f(M.position?.z,0)},{x:f(M.quaternion?.x,0),y:f(M.quaternion?.y,0),z:f(M.quaternion?.z,0),w:f(M.quaternion?.w,1)},{x:f(M.scale?.x,1),y:f(M.scale?.y,1),z:f(M.scale?.z,1)}),y=new Set([M]);{let g=new Set([M]),T=Array.isArray(M.children)?[...M.children]:[],x=0;for(;T.length>0&&x<=o;){let L=T.pop();if(!(!(L instanceof oe)||g.has(L))&&(g.add(L),x++,Array.isArray(L.children)))for(let I of L.children)T.push(I)}if(x>o)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let w=[],b=(g,T)=>{let x=Array.isArray(g.children)?g.children:[];for(let L=x.length-1;L>=0;L--)w.push([x[L],T])};b(M,-1);let R=g=>{let T=[];for(let L=g;L>=0&&T.length<=d.length;L=d[L].parent)T.push(L);let x=P.clone();for(let L=T.length-1;L>=0;L--){let I=d[T[L]];x.multiply(new be().compose({x:I.translation[0],y:I.translation[1],z:I.translation[2]},{x:I.rotation[0],y:I.rotation[1],z:I.rotation[2],w:I.rotation[3]},{x:I.scale[0],y:I.scale[1],z:I.scale[2]}))}return x};for(;w.length>0;){let[g,T]=w.pop();if(!(g instanceof oe)||y.has(g))continue;y.add(g);let x=[f(g.position?.x,0),f(g.position?.y,0),f(g.position?.z,0)],L=[f(g.quaternion?.x,0),f(g.quaternion?.y,0),f(g.quaternion?.z,0),f(g.quaternion?.w,1)],I=[f(g.scale?.x,1),f(g.scale?.y,1),f(g.scale?.z,1)],H=-1,k=g.geometry,U=k?.attributes?.position;U&&U.array&&U.count>0&&(H=u.length,u.push({name:g.name||`Mesh_${u.length}`,raw_positions:U.array,raw_normals:k.attributes.normal?k.attributes.normal.array:null,raw_uvs:k.attributes.uv?k.attributes.uv.array:null,raw_indices:k.index?k.index.array:null,vertex_count:U.count,material_index:l(g.material instanceof de?g.material:null)}));let N=r(g.userData?.xr),C=!!g.userData?.xr&&N!==null,O=d.length;d.push({name:typeof g.name=="string"?g.name.slice(0,1024):"",parent:T,translation:x,rotation:L,scale:I,mesh:H,xr_traits_json:C?JSON.stringify(N):null,...C?c(N):{}});let F=r(g.userData?.interactivity);if(S.push(F),F&&(A=!0),d.length>o)break;if(g instanceof Me){let V=R(O).elements;a.push({light_type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[f(V[12],0),f(V[13],0),f(V[14],0)]})}b(g,O)}let p=(g,T)=>g.every((x,L)=>x===T[L]),E=r({interactivity:M.userData?.interactivity,gltfExtensions:{KHR_interactivity:M.userData?.gltfExtensions?.KHR_interactivity}}),v=!!(E?.interactivity??E?.gltfExtensions?.KHR_interactivity),_=null;(A||v)&&(_=ot(d.map((g,T)=>({name:g.name,...g.mesh>=0?{mesh:g.mesh}:{},...p(g.translation,[0,0,0])?{}:{translation:g.translation},...p(g.rotation,[0,0,0,1])?{}:{rotation:g.rotation},...p(g.scale,[1,1,1])?{}:{scale:g.scale},extras:S[T]?{interactivity:S[T]}:void 0})),u.map(g=>({primitives:[{material:g.material_index??0}]})),E??void 0));let D=te.camera||e;return{meshes:u,nodes:d,materials:s,lights:a,interactivity_json:_?JSON.stringify(_):null,camera:{fov:D.fov||45,position:D.position?[D.position.x,D.position.y,D.position.z]:[0,2,5],target:D.target?[D.target.x,D.target.y,D.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Ci=nt;return dr(Di);})();
307
+ `+U.script+`
308
+ })();`);m=null;let k=p(d,_,w,E);k&&typeof k.toGLB=="function"&&(_=k)}if(!N){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(_);let p=_.toGLB(),k=p instanceof ArrayBuffer?p:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);G({type:"3D_MODEL_READY",glbBuffer:k},[k])}c({type:"DONE",nonce:r})}catch(_){a(_&&_.message||_)}}},c({type:"READY",nonce:r})}function sr(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Do},s=(Ae().workerExtensionInstallers??[]).map(h=>`(${h.toString()})`).join(",");return`'use strict';(${ko.toString()})(${JSON.stringify(o)},[${s}]);`}function ni(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var ut=0;function ri(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Po(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Lo=1024,No=256;function jr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function ar(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Lo)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!jr(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let s=Object.create(null),h=i;for(let c of o){if(c.length>No||c==="__proto__"||c==="constructor"||c==="prototype")return null;let a=h[c];if(!jr(a))return null;s[c]=a}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Fo(t){let e=Po(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function ii(t,e,n,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Oo(t,e,n,r){let i=ri(),o=sr(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.display="none",s.src=n,ut++;let h=!1,c=!1,a={modelDispatched:!1},u,f=()=>{if(h||c)return;let b=s.contentWindow;!b||typeof b.postMessage!="function"||(c=!0,b.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},m=()=>{},d=b=>{if(h||!s.contentWindow||b.source!==s.contentWindow)return;let M=b.data;if(M&&typeof M=="object"&&M.type==="IFRAME_READY"){f();return}let N=ar(M,i);N&&ii(N,r,m,a)};m=()=>{h||(h=!0,u!==void 0&&clearTimeout(u),ut=Math.max(0,ut-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof s.remove=="function"?s.remove():s.parentNode&&s.parentNode.removeChild(s))},u=setTimeout(()=>{h||(m(),ni(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),s.onload=()=>{f()},s.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let y=document.body||document.documentElement;if(!y||typeof y.appendChild!="function"){m();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return y.appendChild(s),{terminate:m}}function Kr(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ut>=32)return r(`SecurityError: ${ut} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=Eo()}catch(m){let d=m instanceof Error?m.message:String(m);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let m;try{m=_o()}catch(d){let y=d instanceof Error?d.message:String(d);return r(y,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Oo(t,i,m,n))}catch(d){return Promise.reject(d)}}let o=ri(),s=sr(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),h;try{let m=new Blob([s],{type:"application/javascript"}),d=URL.createObjectURL(m);try{let y=Jr(d);h=new Worker(y)}finally{URL.revokeObjectURL(d)}}catch(m){let d=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}ut++;let c=!1,a={modelDispatched:!1},u,f=()=>{c||(c=!0,u!==void 0&&clearTimeout(u),ut=Math.max(0,ut-1),h.terminate())};return u=setTimeout(()=>{c||(f(),ni(n))},3e3),h.onmessage=m=>{let d=ar(m.data,o);d&&ii(d,n,f,a)},h.onerror=m=>{f(),n.onError?.(new Error(`Worker execution error: ${m.message}`))},t.kind==="url"?h.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):h.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:f})}function qr(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var oi={execute(t,e,n,r){let i=(h,c)=>{let a=new Error(h);return n.onError?.(a),c&&n.onToast?.(c),Promise.reject(a)},o=qr(e,i);if(o)return o;try{Fo(t)}catch(h){let c=h instanceof Error?h.message:String(h);return i(c,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??ti()?Kr({kind:"script",script:t},e,n,i):i(Tr,Mr)},executeUrl(t,e,n){let r=(s,h)=>{let c=new Error(s);return n.onError?.(c),h&&n.onToast?.(h),Promise.reject(c)},i=qr(e,r);if(i)return i;let o;try{o=Io(t)}catch(s){let h=s instanceof Error?s.message:String(s);return r(h,"Security Error: disallowed scene script URL.")}return Kr({kind:"url",scriptUrl:o},e,n,r)}},Cn=new Set;function He(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;Cn.has(n)||(Cn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function si(){return Array.from(Cn)}function cr(){Cn.clear()}var qt=class extends ht{constructor(e={}){He("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},ai=qt,xt=class extends Xt{constructor(e=1,n=0,r="PolyhedronGeometry"){He(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},In=class extends xt{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Dn=class extends xt{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},kn=class extends xt{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},Pn=class extends xt{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},Ln=class extends lt{constructor(e=1,n=1,r=4,i=8){He("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Nn=class extends lt{constructor(e=.5,n=1,r=16){He("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},Fn=class extends lt{constructor(e=1,n=16){He("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},On=class extends jt{constructor(n,r,i=0,o=Math.PI/3,s=0,h=2){He("SpotLight","PointLight");super(n,r,i,h);this.target=new Ge;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=s}},Zt=class extends Yt{constructor(e,n,r){He("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new $e(n??4473924)}},ci=Zt,ui={Vector2:ln,Vector3:Ce,Vector4:hn,Euler:Bt,Quaternion:Gt,Matrix4:Je,Matrix3:mn,Color:$e,MathUtils:Zr,BufferAttribute:pe,Float32BufferAttribute:fn,Uint16BufferAttribute:dn,Uint32BufferAttribute:pn,BufferGeometry:Xe,BoxGeometry:Ht,PlaneGeometry:bn,SphereGeometry:Xt,CylinderGeometry:lt,ConeGeometry:yn,TorusGeometry:gn,TorusKnotGeometry:xn,IcosahedronGeometry:In,OctahedronGeometry:Dn,DodecahedronGeometry:kn,TetrahedronGeometry:Pn,CapsuleGeometry:Ln,RingGeometry:Nn,CircleGeometry:Fn,Texture:Wt,TextureLoader:vn,Material:We,MeshStandardMaterial:ht,MeshBasicMaterial:Tn,MeshLambertMaterial:Mn,MeshPhongMaterial:wn,MeshPhysicalMaterial:Sn,ShaderMaterial:qt,RawShaderMaterial:ai,Object3D:Ge,Group:An,Mesh:yt,InstancedMesh:kt,Light:mt,AmbientLight:Yt,DirectionalLight:En,PointLight:jt,SpotLight:On,HemisphereLight:Zt,RectAreaLight:ci,Camera:Kt,PerspectiveCamera:Pt,Scene:gt,WebGLRenderer:Rn,Clock:_n,SceneQuotaValidator:qe,exportSceneToCanvas3D:rr,exportSceneToGLB:ir,exportSceneToUSDZ:Qr,generateUSDZ:Yn,glbToUSDZ:sn,sceneToCanvas3D:Ct,sceneToGLB:Ft,sceneToUSDZ:It,authorScriptRunner:oi,getAuthorWarnings:si,clearAuthorWarnings:cr};Object.freeze(qe);Object.freeze(qe.prototype);Object.freeze(gt.prototype);Object.freeze(ui);var et=new Proxy(ui,{get:(t,e)=>{if(e in t)return t[e];let n=Ae().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&He(`THREE.${e}`,"no-op proxy"),Dt)},has:(t,e)=>{if(e in t)return!0;let n=Ae().authorNamespace;return!!(n&&typeof e=="string"&&e in n)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),un=Ae();un.threeNamespace=et;if(un.workerExtensionInstallers)for(let t of un.workerExtensionInstallers)t(et,un);var Vt={name:"three_author",THREE:et},Uo=Vt,Pe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Pe.THREE>"u"&&(Pe.THREE=et);typeof Pe.requestAnimationFrame!="function"&&(Pe.requestAnimationFrame=()=>(He("requestAnimationFrame","single-frame static evaluation"),0));typeof Pe.cancelAnimationFrame!="function"&&(Pe.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=et,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=Vt,t.ThreeLivePlugins.three_author=Vt,t.ThreeLivePlugins["three-author"]=Vt}{Hr(),Xr(),Ar(et,Ae()),Vn(et,Ae());let t=new gt,e=new Pt(45,1,.1,1e3);e.position.set(0,2,5),Pe.scene=t,Pe.camera=e,typeof Pe.window>"u"&&(Pe.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Pe.document>"u"&&(Pe.document={createElement:()=>({getContext:()=>Dt,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Pe,"__three_live_reset_scene__",{value:function(){cr(),t=new gt,e=new Pt(45,1,.1,1e3),e.position.set(0,2,5),Pe.scene=t,Pe.camera=e},writable:!1,configurable:!1});let r=function(c){if(c==null)return null;let a=2e4,u=new Set,f=(m,d)=>{if(--a<0||d>32)return;if(m===null||typeof m=="string"||typeof m=="boolean")return m;if(typeof m=="number")return Number.isFinite(m)?m:void 0;if(typeof m!="object"||u.has(m))return;u.add(m);let y;if(Array.isArray(m)){y=[];for(let b of m)y.push(f(b,d+1)??null)}else{y={};for(let b of Object.keys(m)){if(b==="__proto__"||b==="prototype"||b==="constructor")continue;let M=f(m[b],d+1);M!==void 0&&(y[b]=M)}}return u.delete(m),y};try{return f(c,0)??null}catch{return null}},i=15*1024,o=1e3*4,s=function(c){let a=an(c);if(!a)return{};let u=JSON.stringify({...c,...a});return u.length>i&&(He(`userData.xr larger than ${i} characters`,"canonical XR traits only"),u=JSON.stringify(a)),{xr_normalized_json:u,xr_scenecore_json:JSON.stringify(Zn(a)),xr_hubs_json:JSON.stringify(Qn(a))}};Object.defineProperty(Pe,"__three_live_extract_scene_raw__",{value:function(){let c=[],a=[],u=[],f=[];function m(l){if(!l)return null;let g=f.indexOf(l);if(g===-1){f.push(l);let L="";l.map&&(typeof l.map=="string"?L=l.map:l.map.source?L=l.map.source:l.map.image&&(L=l.map.image)),a.push({name:l.name||`Material_${a.length}`,base_color:[l.color.r,l.color.g,l.color.b,l.opacity!==void 0?l.opacity:1],metallic:l.metalness!==void 0?l.metalness:.1,roughness:l.roughness!==void 0?l.roughness:.5,double_sided:l.side===2||l.doubleSided,base_color_texture:L||null,clearcoat:l.clearcoat||0,clearcoat_roughness:l.clearcoatRoughness||0,transmission:l.transmission||0,ior:l.ior!==void 0?l.ior:1.5,thickness:l.thickness||0}),g=a.length-1}return g}let d=(l,g)=>typeof l=="number"&&Number.isFinite(l)?l:g,y=[],b=[],M=[],N=!1,G=Pe.scene||t,T=new Je().compose({x:d(G.position?.x,0),y:d(G.position?.y,0),z:d(G.position?.z,0)},{x:d(G.quaternion?.x,0),y:d(G.quaternion?.y,0),z:d(G.quaternion?.z,0),w:d(G.quaternion?.w,1)},{x:d(G.scale?.x,1),y:d(G.scale?.y,1),z:d(G.scale?.z,1)}),S=new Set([G]);{let l=new Set([G]),g=Array.isArray(G.children)?[...G.children]:[],L=0;for(;g.length>0&&L<=o;){let D=g.pop();if(!(!(D instanceof Ge)||l.has(D))&&(l.add(D),L++,Array.isArray(D.children)))for(let H of D.children)g.push(H)}if(L>o)return{meshes:[],nodes:new Array(L),materials:[],lights:[]}}let R=[],I=(l,g)=>{let L=Array.isArray(l.children)?l.children:[];for(let D=L.length-1;D>=0;D--)R.push([L[D],g])};I(G,-1);let U=l=>{let g=[];for(let D=l;D>=0&&g.length<=y.length;D=y[D].parent)g.push(D);let L=T.clone();for(let D=g.length-1;D>=0;D--){let H=y[g[D]];L.multiply(new Je().compose({x:H.translation[0],y:H.translation[1],z:H.translation[2]},{x:H.rotation[0],y:H.rotation[1],z:H.rotation[2],w:H.rotation[3]},{x:H.scale[0],y:H.scale[1],z:H.scale[2]}))}return L};for(;R.length>0;){let[l,g]=R.pop();if(!(l instanceof Ge)||S.has(l))continue;S.add(l);let L=[d(l.position?.x,0),d(l.position?.y,0),d(l.position?.z,0)],D=[d(l.quaternion?.x,0),d(l.quaternion?.y,0),d(l.quaternion?.z,0),d(l.quaternion?.w,1)],H=[d(l.scale?.x,1),d(l.scale?.y,1),d(l.scale?.z,1)];nr(l);let X=-1,K=l.geometry,Z=K?.attributes?.position;if(Z&&Z.array&&Z.count>0){X=c.length;let B=null,$=l.userData?.variants;if($&&typeof $=="object"){let ae=new Map;for(let ie of Object.keys($)){if(!ie||ie==="__proto__"||ie==="constructor"||ie==="prototype")continue;let A=$[ie],x=A instanceof We?A:A&&typeof A=="object"?new ht(A):null;if(!x)continue;let v=b.indexOf(ie);if(v===-1&&b.length<256&&(v=b.length,b.push(ie)),v===-1)continue;let C=m(x);if(C!==null){let P=ae.get(C);P||(P=[],ae.set(C,P)),P.push(v)}}if(ae.size>0){let ie=[];for(let[A,x]of ae.entries())ie.push({material:A,variants:x});B=JSON.stringify({mappings:ie})}}c.push({name:l.name||`Mesh_${c.length}`,raw_positions:Z.array,raw_normals:K.attributes.normal?K.attributes.normal.array:null,raw_uvs:K.attributes.uv?K.attributes.uv.array:null,raw_indices:K.index?K.index.array:null,vertex_count:Z.count,material_index:m(l.material instanceof We?l.material:null),variant_mappings_json:B})}let O=r(l.userData?.xr),J=!!l.userData?.xr&&O!==null,q=y.length,Q=l instanceof kt&&l.count>0&&l.instanceMatrix?.array;y.push({name:typeof l.name=="string"?l.name.slice(0,1024):"",parent:g,translation:L,rotation:D,scale:H,mesh:X,xr_traits_json:J?JSON.stringify(O):null,...J?s(O):{},...Q?{instance_matrices:l.instanceMatrix.array.subarray(0,l.count*16),instance_colors:l.instanceColor?.array?l.instanceColor.array.subarray(0,l.count*3):null}:{}});let se=r(l.userData?.interactivity);if(M.push(se),se&&(N=!0),y.length>o)break;if(l instanceof mt){let B=U(q).elements;u.push({light_type:l.type,color:[l.color.r,l.color.g,l.color.b],intensity:l.intensity,position:[d(B[12],0),d(B[13],0),d(B[14],0)]})}I(l,q)}let _=(l,g)=>l.every((L,D)=>L===g[D]),w=r({interactivity:G.userData?.interactivity,gltfExtensions:{KHR_interactivity:G.userData?.gltfExtensions?.KHR_interactivity}}),E=!!(w?.interactivity??w?.gltfExtensions?.KHR_interactivity),p=null;(N||E)&&(p=Qt(y.map((l,g)=>({name:l.name,...l.mesh>=0?{mesh:l.mesh}:{},..._(l.translation,[0,0,0])?{}:{translation:l.translation},..._(l.rotation,[0,0,0,1])?{}:{rotation:l.rotation},..._(l.scale,[1,1,1])?{}:{scale:l.scale},extras:M[g]?{interactivity:M[g]}:void 0})),c.map(l=>({primitives:[{material:l.material_index??0}]})),w??void 0));let k=Pe.camera||e;return{meshes:c,nodes:y,materials:a,lights:u,interactivity_json:p?JSON.stringify(p):null,variants_json:b.length>0?JSON.stringify({variants:b.map(l=>({name:l}))}):null,camera:{fov:k.fov||45,position:k.position?[k.position.x,k.position.y,k.position.z]:[0,2,5],target:k.target?[k.target.x,k.target.y,k.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var zo=et;return yi(Vo);})();