three-live 0.0.0-stage → 1.1.0

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 (39) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +58 -2
  3. package/dist/index.d.ts +224 -0
  4. package/dist/three-author-engine.js +292 -0
  5. package/dist/three-author.cjs +292 -0
  6. package/dist/three-author.d.ts +224 -0
  7. package/dist/three-author.js +292 -0
  8. package/dist/three-convert.cjs +286 -0
  9. package/dist/three-convert.d.ts +224 -0
  10. package/dist/three-convert.js +286 -0
  11. package/dist/three-live-animation.cjs +36 -0
  12. package/dist/three-live-animation.d.ts +224 -0
  13. package/dist/three-live-animation.js +36 -0
  14. package/dist/three-live-animation.min.js +36 -0
  15. package/dist/three-live-element.cjs +217 -0
  16. package/dist/three-live-element.d.ts +224 -0
  17. package/dist/three-live-element.js +217 -0
  18. package/dist/three-live-extras.cjs +42 -0
  19. package/dist/three-live-extras.d.ts +224 -0
  20. package/dist/three-live-extras.js +42 -0
  21. package/dist/three-live-extras.min.js +42 -0
  22. package/dist/three-live-full.cjs +336 -0
  23. package/dist/three-live-full.js +336 -0
  24. package/dist/three-live-full.min.js +336 -0
  25. package/dist/three-live-sandbox.html +157 -0
  26. package/dist/three-live-viewer.cjs +217 -0
  27. package/dist/three-live-viewer.d.ts +224 -0
  28. package/dist/three-live-viewer.js +217 -0
  29. package/dist/three-live-viewer.min.js +217 -0
  30. package/dist/three-live.cjs +294 -0
  31. package/dist/three-live.js +294 -0
  32. package/dist/three-live.min.js +294 -0
  33. package/dist/three-view.cjs +217 -0
  34. package/dist/three-view.d.ts +224 -0
  35. package/dist/three-view.js +217 -0
  36. package/dist/three-xr.cjs +286 -0
  37. package/dist/three-xr.d.ts +224 -0
  38. package/dist/three-xr.js +286 -0
  39. package/package.json +81 -4
@@ -0,0 +1,292 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ function Ht(n,e,t){let r=[],i=new Map,s=[],c=[],m=[],u=new Map,o=b=>{let w=i.get(b);return w===void 0&&(w=r.length,r.push({op:b}),i.set(b,w)),w},a=b=>{let w=u.get(b);return w===void 0&&(w=m.length,m.push({id:b}),u.set(b,w)),w},h=(b,w={})=>s.push({declaration:o(b),...w})-1,l=(b,w,y)=>c.push({id:b,type:w,value:y})-1,p=b=>({node:b,socket:"value"}),f=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let b=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(b&&Array.isArray(b.nodes)){let w=Array.isArray(b.declarations)?b.declarations:[];for(let y of w)y?.op&&o(y.op);Array.isArray(b.variables)&&c.push(...b.variables);for(let y of b.events||[])y?.id&&a(y.id);for(let y of b.nodes){if(!y||typeof y!="object")continue;let R=y.op||(typeof y.declaration=="number"?w[y.declaration]?.op:"");s.push(R?{...y,declaration:o(R)}:{...y})}}}let T=(b,w,y="translation")=>y==="baseColorFactor"||y==="metallicFactor"||y==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${y}`:y==="emissiveFactor"||y==="alphaCutoff"?`/materials/${Math.max(0,w)}/${y}`:y==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${y}`,M=new Map;n.forEach((b,w)=>{typeof b?.name=="string"&&!M.has(b.name)&&M.set(b.name,w)});let A=(b,w)=>typeof b.target=="string"&&M.has(b.target)?M.get(b.target):typeof b.targetNode=="number"?b.targetNode:w,C=b=>{let w=n[b];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<n.length;b++){let w=n[b],y=w?.extras?.interactivity;if(!y||typeof y!="object")continue;let R=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,d=g=>{let S=Array.isArray(g)?g:[g],I=[];for(let D=0;D<S.length;D++){let v=S[D];if(!v||typeof v!="object")continue;let k=v.action||"interpolate",H=typeof v.duration=="number"?v.duration:.35;if(k==="toggleTransform"){let V=v.property==="rotation"||v.property==="scale"?v.property:"translation",O=V==="rotation"?w.rotation||[0,0,0,1]:V==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],L=`/nodes/${b}/${V}`,P=l(`__toggle_${b}_${D}`,"bool",!1),_=h("variable/get",{configuration:{variable:P}}),N=h("math/not",{values:{a:p(_)}}),U=h("variable/set",{configuration:{variable:P},values:{value:p(N)}}),B=h("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(v.to)?v.to:O},duration:{value:H}}}),F=h("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(v.from)?v.from:O},duration:{value:H}}});s[U].flows={out:{node:h("flow/branch",{values:{condition:p(_)},flows:{true:{node:B},false:{node:F}}})}},I.push(U)}else if(k==="interpolate"){let V=v.to??v.value;if(V===void 0)continue;let O={value:{value:V},duration:{value:H}};v.from!==void 0&&(O.from={value:v.from}),I.push(h("pointer/interpolate",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:T(A(v,b),C(A(v,b)),v.property)},values:O}))}else if(k==="setProperty"){if(v.value===void 0)continue;I.push(h("pointer/set",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:T(A(v,b),C(A(v,b)),v.property)},values:{value:{value:v.value}}}))}else if(k==="toggleVisibility"){let V=A(v,b),O=l(`__vis_${V}_${D}`,"bool",!0),L=h("variable/get",{configuration:{variable:O}}),P=h("math/not",{values:{a:p(L)}}),_=h("variable/set",{configuration:{variable:O},values:{value:p(P)}});s[_].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:p(L)}})}},I.push(_)}else if(k==="cycleMaterialColor"&&Array.isArray(v.colors)&&v.colors.length>0){let V=typeof v.duration=="number"?v.duration:.25,O=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,L=l(`__color_idx_${b}_${D}`,"int",0),P=h("variable/get",{configuration:{variable:L}}),_=h("math/add",{values:{a:p(P),b:{value:1}}}),N=h("math/rem",{values:{a:p(_),b:{value:v.colors.length}}}),U=h("variable/set",{configuration:{variable:L},values:{value:p(N)}}),B={};for(let F=0;F<v.colors.length;F++){let z=v.colors[F],Y=Array.isArray(z)&&z.length>=3?[z[0],z[1],z[2],z[3]??1]:[1,1,1,1];B[String(F)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Y},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:O},values:{value:{value:Y}}})}}s[U].flows={out:{node:h("flow/switch",{values:{selection:p(P)},flows:B})}},I.push(U)}else if(k==="playAnimation")I.push(h("animation/start",{configuration:{animation:v.animation??v.clip??0}}));else if(k==="stopAnimation")I.push(h("animation/stop"));else if(k==="sendEvent"){let V={};for(let[O,L]of Object.entries(v.values||{}))V[O]={value:L};I.push(h("event/send",{configuration:{event:a(String(v.event??v.id??"custom"))},values:V}))}}if(!I.length)return null;if(I.length===1)return I[0];let E={};return I.forEach((D,v)=>{E[String(v)]={node:D}}),h("flow/sequence",{flows:E})},x=(g,S,I)=>{let E=d(S);E!==null&&h(g,{...I?{configuration:I}:{},flows:{out:{node:E}}})};if(y.onSelect&&x("pointer/onSelect",y.onSelect,{nodeIndex:b}),y.onHoverIn&&x("pointer/onHoverIn",y.onHoverIn,{nodeIndex:b}),y.onHoverOut&&x("pointer/onHoverOut",y.onHoverOut,{nodeIndex:b}),y.onStart&&x("event/onStart",y.onStart),y.onReceive&&typeof y.onReceive=="object")for(let[g,S]of Object.entries(y.onReceive))x("event/receive",S,{event:a(g)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:m}],graph:0}:null}var Xt='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).',Gt="Security Error: client-side scripts require allow-client-scripts opt-in.";var ke="__THREE_LIVE_REGISTRY__";function ee(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ke]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ke,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ke]=e}}return n[ke]}var K=ee().plugins;function Wt(n){let e=ee().plugins;e.some(t=>t.name===n.name)||e.push(n)}function $t(){return ee().plugins}function j(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Yt(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Be(n,e,t,r){let[i,s,c]=e,[m,u,o]=r,[a,h,l]=t,p=i-a,f=s-h,T=c-l,M=Math.hypot(p,f,T);M<=1e-5?(p=0,f=0,T=1):(p/=M,f/=M,T/=M);let A=u*T-o*f,C=o*p-m*T,b=m*f-u*p;M=Math.hypot(A,C,b),M<=1e-5?(A=0,C=0,b=0):(A/=M,C/=M,b/=M);let w=f*b-T*C,y=T*A-p*b,R=p*C-f*A;return M=Math.hypot(w,y,R),M<=1e-5?(w=0,y=0,R=0):(w/=M,y/=M,R/=M),n[0]=A,n[1]=w,n[2]=p,n[3]=0,n[4]=C,n[5]=y,n[6]=f,n[7]=0,n[8]=b,n[9]=R,n[10]=T,n[11]=0,n[12]=-(A*i+C*s+b*c),n[13]=-(w*i+y*s+R*c),n[14]=-(p*i+f*s+T*c),n[15]=1,n}function te(n,e,t){let r=e[0],i=e[1],s=e[2],c=e[3],m=e[4],u=e[5],o=e[6],a=e[7],h=e[8],l=e[9],p=e[10],f=e[11],T=e[12],M=e[13],A=e[14],C=e[15],b=t[0],w=t[1],y=t[2],R=t[3];return n[0]=b*r+w*m+y*h+R*T,n[1]=b*i+w*u+y*l+R*M,n[2]=b*s+w*o+y*p+R*A,n[3]=b*c+w*a+y*f+R*C,b=t[4],w=t[5],y=t[6],R=t[7],n[4]=b*r+w*m+y*h+R*T,n[5]=b*i+w*u+y*l+R*M,n[6]=b*s+w*o+y*p+R*A,n[7]=b*c+w*a+y*f+R*C,b=t[8],w=t[9],y=t[10],R=t[11],n[8]=b*r+w*m+y*h+R*T,n[9]=b*i+w*u+y*l+R*M,n[10]=b*s+w*o+y*p+R*A,n[11]=b*c+w*a+y*f+R*C,b=t[12],w=t[13],y=t[14],R=t[15],n[12]=b*r+w*m+y*h+R*T,n[13]=b*i+w*u+y*l+R*M,n[14]=b*s+w*o+y*p+R*A,n[15]=b*c+w*a+y*f+R*C,n}function Oe(n,e,t,r){let i=e[0],s=e[1],c=e[2],m=e[3],u=i+i,o=s+s,a=c+c,h=i*u,l=i*o,p=i*a,f=s*o,T=s*a,M=c*a,A=m*u,C=m*o,b=m*a,w=r[0],y=r[1],R=r[2];return n[0]=(1-(f+M))*w,n[1]=(l+b)*w,n[2]=(p-C)*w,n[3]=0,n[4]=(l-b)*y,n[5]=(1-(h+M))*y,n[6]=(T+A)*y,n[7]=0,n[8]=(p+C)*R,n[9]=(T-A)*R,n[10]=(1-(h+f))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function re(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],c=e[5],m=e[6],u=e[8],o=e[9],a=e[10],h=a*c-m*o,l=-a*s+m*u,p=o*s-c*u,f=t*h+r*l+i*p;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*o)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*s)*f,n[6]=p*f,n[7]=(-o*t+r*u)*f,n[8]=(c*t-r*s)*f),n}function qt(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],c=e[4],m=e[5],u=e[6],o=e[7],a=e[8],h=e[9],l=e[10],p=e[11],f=e[12],T=e[13],M=e[14],A=e[15],C=t*m-r*c,b=t*u-i*c,w=t*o-s*c,y=r*u-i*m,R=r*o-s*m,d=i*o-s*u,x=a*T-h*f,g=a*M-l*f,S=a*A-p*f,I=h*M-l*T,E=h*A-p*T,D=l*A-p*M,v=C*D-b*E+w*I+y*S-R*g+d*x;return v?(v=1/v,n[0]=(m*D-u*E+o*I)*v,n[1]=(i*E-r*D-s*I)*v,n[2]=(T*d-M*R+A*y)*v,n[3]=(l*R-h*d-p*y)*v,n[4]=(u*S-c*D-o*g)*v,n[5]=(t*D-i*S+s*g)*v,n[6]=(M*w-f*d-A*b)*v,n[7]=(a*d-l*w+p*b)*v,n[8]=(c*E-m*S+o*x)*v,n[9]=(r*S-t*E-s*x)*v,n[10]=(f*R-T*w+A*C)*v,n[11]=(h*w-a*R-p*C)*v,n[12]=(m*g-c*I-u*x)*v,n[13]=(t*I-r*g+i*x)*v,n[14]=(T*b-f*y-M*C)*v,n[15]=(a*y-h*b+l*C)*v,n):null}function ot(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],c=i[1]*e+i[5]*t+i[9]*r+i[13],m=i[2]*e+i[6]*t+i[10]*r+i[14],u=i[3]*e+i[7]*t+i[11]*r+i[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=c*o,n[2]=m*o}function Kt(n,e,t,r,i,s,c,m,u,o,a,h,l,p,f,T,M=0){let A=o-c,C=a-m,b=h-u,w=l-c,y=p-m,R=f-u,d=i*R-s*y,x=s*w-r*R,g=r*y-i*w,S=A*d+C*x+b*g;if(S>-1e-7&&S<1e-7)return!1;let I=1/S,E=n-c,D=e-m,v=t-u,k=I*(E*d+D*x+v*g);if(k<-M||k>1+M)return!1;let H=D*b-v*C,V=v*A-E*b,O=E*C-D*A,L=I*(r*H+i*V+s*O);if(L<-M||k+L>1+M)return!1;let P=I*(w*H+y*V+R*O);if(P>1e-4&&P<T.distance){T.distance=P,T.point=[n+r*P,e+i*P,t+s*P];let _=C*R-b*y,N=b*w-A*R,U=A*y-C*w,B=Math.hypot(_,N,U)||1;return T.normal=[_/B,N/B,U/B],!0}return!1}function ze(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(j());if(t===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||s.has(a))return;s.add(a);let p=n.nodes[a];if(!p)return;let f=j();if(e&&e[a])f.set(e[a]);else if(p.matrix&&p.matrix.length===16)f.set(p.matrix);else{let M=p.translation||[0,0,0],A=p.rotation||[0,0,0,1],C=p.scale||[1,1,1];Oe(f,A,M,C)}let T=r[a];if(h?te(T,h,f):T.set(f),Array.isArray(p.children))for(let M of p.children)typeof M=="number"&&m(M,T,l+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)i.has(a)||u.push(a);for(let a of u)m(a,null);for(let a=0;a<t;a++)!i.has(a)&&!u.includes(a)&&m(a,null);return r}function Cn(n){return new TextDecoder().decode(n)}var Jt=ee().decoders;function In(n,e){Jt.set(n.toLowerCase(),e)}function De(n){return Jt.get(n.toLowerCase())}function Qt(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let l=t.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=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=s&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),p=t.getUint32(c+4,!0),f=c+8;if(f+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${f+l} bytes, buffer has ${e.byteLength}`);if(p===1313821514){let T=new Uint8Array(e,f,l),M=Cn(T);m=JSON.parse(M,(A,C)=>A==="__proto__"||A==="constructor"||A==="prototype"?void 0:C)}else p===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let o=m.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!De("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!De("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!De("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of K)l.onParseGLB?.(h);return h}function Ln(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function Ce(n){if(Ln(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return Qt(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var en=`#version 300 es
18
+ layout(location=0) in vec3 aPosition;
19
+ layout(location=1) in vec3 aNormal;
20
+ layout(location=2) in vec2 aUV;
21
+ uniform mat4 uMVP,uModel;
22
+ uniform mat3 uNormalMatrix;
23
+ uniform vec4 uUvTransform;
24
+ out vec3 vNormal,vWorldPos;
25
+ out vec2 vUV;
26
+ void main(){
27
+ vec3 rawN=uNormalMatrix*aNormal;
28
+ vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
29
+ vec4 world=uModel*vec4(aPosition,1.0);
30
+ vWorldPos=world.xyz;
31
+ vec2 scaleUV=uUvTransform.zw;
32
+ if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
+ vUV=aUV*scaleUV+uUvTransform.xy;
34
+ gl_Position=uMVP*vec4(aPosition,1.0);
35
+ }`,tn=`#version 300 es
36
+ precision highp float;
37
+ in vec3 vNormal,vWorldPos;
38
+ in vec2 vUV;
39
+ uniform vec4 uBaseColor;
40
+ uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
41
+ uniform vec2 uClearcoat;
42
+ uniform vec3 uCameraPos,uAmbientColor;
43
+ uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uXrDepthTex;
44
+ uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uXrDepthEnabled,uXrDepthFormat;
45
+ uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
46
+ uniform mat4 uXrDepthUVTransform;
47
+ uniform vec2 uViewportSize;
48
+ uniform int uToneMapping,uNumDirLights,uNumPointLights;
49
+ uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
50
+ out vec4 fragColor;
51
+
52
+ vec2 envBRDF(float r,float n){
53
+ vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
54
+ vec4 rv=r*c0+c1;
55
+ float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
56
+ return vec2(-1.04,1.04)*a+rv.zw;
57
+ }
58
+
59
+ vec3 F_SchlickRoughness(vec3 F0,float r,float n){
60
+ return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
61
+ }
62
+
63
+ vec3 getStudioRadiance(vec3 R,float r){
64
+ vec3 kd=normalize(vec3(0.0,1.0,0.35));
65
+ float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
66
+ vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
67
+ float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
68
+ float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
69
+ vec3 ag=mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5);
70
+ return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
71
+ }
72
+
73
+ vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D normalMap,float scale){
74
+ vec3 mapNormal=texture(normalMap,uv).xyz*2.0-1.0;
75
+ mapNormal.xy*=scale;
76
+ vec3 dp1=dFdx(vWorldPos);
77
+ vec3 dp2=dFdy(vWorldPos);
78
+ vec2 duv1=dFdx(uv);
79
+ vec2 duv2=dFdy(uv);
80
+ vec3 dp2perp=cross(dp2,N);
81
+ vec3 dp1perp=cross(N,dp1);
82
+ vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
83
+ vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
84
+ float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
85
+ return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
86
+ }
87
+
88
+ vec2 equirectangularUV(vec3 dir){
89
+ vec3 d=normalize(dir);
90
+ float u=atan(d.z,d.x)*0.15915494309+0.5;
91
+ float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
92
+ return vec2(u,1.0-v);
93
+ }
94
+
95
+ vec3 neutralToneMapping(vec3 color){
96
+ const float startCompression=0.76;
97
+ const float desaturation=0.15;
98
+ float x=min(color.r,min(color.g,color.b));
99
+ float offset=x<0.08?x-6.25*x*x:0.04;
100
+ color-=offset;
101
+ float peak=max(color.r,max(color.g,color.b));
102
+ if(peak<startCompression)return color;
103
+ const float d=1.0-startCompression;
104
+ float newPeak=1.0-d*d/(peak+d-startCompression);
105
+ color*=newPeak/peak;
106
+ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
107
+ return mix(color,newPeak*vec3(1.0),g);
108
+ }
109
+
110
+ vec3 applyToneMapping(vec3 color,int mode){
111
+ if(mode==0)return neutralToneMapping(color);
112
+ if(mode==1)return color/(color+vec3(1.0));
113
+ return color;
114
+ }
115
+
116
+ void main(){
117
+ vec4 base=uBaseColor;
118
+ if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
119
+ if(length(vNormal)<1e-4&&uHasTexture==1){
120
+ vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
121
+ fragColor=vec4(unlit,base.a);
122
+ return;
123
+ }
124
+ vec3 N=length(vNormal)<1e-4?normalize(cross(dFdx(vWorldPos),dFdy(vWorldPos))):normalize(vNormal);
125
+ if(!gl_FrontFacing)N=-N;
126
+ vec3 V=normalize(uCameraPos-vWorldPos);
127
+ if(uHasNormalTexture==1){
128
+ N=perturbNormal(N,V,vUV,uNormalTexture,uNormalScale);
129
+ }
130
+
131
+ float metallic=uMetallic;
132
+ float roughness=uRoughness;
133
+ if(uHasMetallicRoughnessTexture==1){
134
+ vec4 mr=texture(uMetallicRoughnessTexture,vUV);
135
+ roughness*=mr.g;
136
+ metallic*=mr.b;
137
+ }
138
+ roughness=clamp(roughness,0.04,1.0);
139
+ metallic=clamp(metallic,0.0,1.0);
140
+
141
+ float occ=1.0;
142
+ if(uHasOcclusionTexture==1){
143
+ occ=mix(1.0,texture(uOcclusionTexture,vUV).r,uOcclusionStrength);
144
+ }
145
+
146
+ float gloss=1.0-roughness;
147
+ float specExp=mix(16.0,256.0,gloss*gloss);
148
+ float specWeight=mix(0.22*gloss,1.0,metallic);
149
+ vec3 directLight=vec3(0.0);
150
+ for(int i=0;i<2;i++){
151
+ if(i>=uNumDirLights)break;
152
+ vec3 L=normalize(uDirLightDir[i]);
153
+ float NdotL=max(dot(N,L),0.0);
154
+ vec3 H=normalize(L+V);
155
+ float NoH=max(dot(N,H),0.0);
156
+ float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
157
+ directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
158
+ }
159
+ for(int i=0;i<2;i++){
160
+ if(i>=uNumPointLights)break;
161
+ vec3 toLight=uPointLightPos[i]-vWorldPos;
162
+ float dist=length(toLight);
163
+ vec3 L=toLight/max(dist,0.0001);
164
+ float atten=1.0/(1.0+0.09*dist+0.032*dist*dist);
165
+ float NdotL=max(dot(N,L),0.0);
166
+ vec3 H=normalize(L+V);
167
+ float NoH=max(dot(N,H),0.0);
168
+ float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
169
+ directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
170
+ }
171
+
172
+ vec3 R=reflect(-V,N);
173
+ float NoV=clamp(dot(N,V),0.001,1.0);
174
+ vec3 F0=mix(vec3(0.04),base.rgb,metallic);
175
+ vec3 F=F_SchlickRoughness(F0,roughness,NoV);
176
+ vec2 brdf=envBRDF(roughness,NoV);
177
+
178
+ vec3 specularIBL;
179
+ vec3 envDiffuse;
180
+ if(uHasEnvironmentMap==1){
181
+ specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
182
+ envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
183
+ }else{
184
+ specularIBL=getStudioRadiance(R,roughness)*(F*brdf.x+brdf.y);
185
+ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
186
+ }
187
+
188
+ vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
189
+ vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
190
+ vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
191
+ if(uClearcoat.x>0.0){
192
+ vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
193
+ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
194
+ }
195
+ color=applyToneMapping(color,uToneMapping);
196
+ float outAlpha=base.a;
197
+ if(uXrDepthEnabled==1){
198
+ vec2 normViewUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.0));
199
+ vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
200
+ vec4 depthSample=texture(uXrDepthTex,depthUV);
201
+ float realDepth=(uXrDepthFormat==1?depthSample.r:(depthSample.r+depthSample.a*256.0))*uXrRawValueToMeters;
202
+ float virtDepth=length(uCameraPos-vWorldPos);
203
+ if(realDepth>0.05&&virtDepth>realDepth){
204
+ float occAlpha=1.0-smoothstep(0.0,0.025,virtDepth-realDepth);
205
+ outAlpha*=occAlpha;
206
+ if(outAlpha<0.01)discard;
207
+ }
208
+ }
209
+ fragColor=vec4(color,outAlpha);
210
+ }`,Pn=`#version 300 es
211
+ layout(location=0) in vec3 aPosition;
212
+ uniform mat4 uMVP;
213
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Fn=`#version 300 es
214
+ precision highp float;
215
+ uniform vec4 uColorId;
216
+ out vec4 fragColor;
217
+ void main(){fragColor=uColorId;}`;function jt(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function ct(n,e,t){let r=jt(n,35633,e),i=jt(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let c=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${c}`)}return s}function ut(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var nn=["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","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize"];function Un(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function at(n,e,t,r,i,s,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],o=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,h;if(a===s)h=new Float32Array(t,o,m.count*s);else{h=new Float32Array(m.count*s);let p=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let T=0;T<m.count;T++){let M=f+T*a;for(let A=0;A<s;A++)h[T*s+A]=p[M+A]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var br=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),rn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Zt(n,e,t=rn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:s}=e,c=[],m=ze(i),u=[];if(Array.isArray(i.nodes))for(let x=0;x<i.nodes.length;x++){let g=i.nodes[x];g.mesh!==void 0&&i.meshes&&i.meshes[g.mesh]&&u.push({node:g,nodeIdx:x,meshIdx:g.mesh})}let o=u.length>0?u:(i.meshes||[]).map((x,g)=>({node:x,nodeIdx:-1,meshIdx:g})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let x=i.extensions.KHR_lights_punctual.lights;for(let g of x){let S=g.type==="directional"?"directional":g.type==="point"?"point":"ambient";a.push({type:S,color:g.color||[1,1,1],intensity:g.intensity!==void 0?g.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]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${i.textures.length}`);for(let x=0;x<i.textures.length;x++){let g=i.textures[x],S=i.images[g.source];if(S){let I=n.createTexture();if(n.bindTexture(3553,I),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),S.bufferView!==void 0){let E=i.bufferViews[S.bufferView],D=s.slice(E.byteOffset||0,(E.byteOffset||0)+E.byteLength),v=new Blob([D],{type:S.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(v).then(k=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,k),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(S.uri){let E=Un(S.uri);if(E){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,D),n.generateMipmap(3553),r?.()},D.src=E}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",S.uri)}h.push(I)}else h.push(null)}}let l=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0],f=0,T=0;for(let x=0;x<o.length;x++){let g=o[x],S=i.meshes[g.meshIdx],I=g.nodeIdx>=0?m[g.nodeIdx]:j(),E=new Float32Array(9);re(E,I);let D={name:g.node.name||S.name||`Mesh_${g.meshIdx}`,nodeIndex:g.nodeIdx,transform:I,normalMatrix:E,primitives:[],extras:g.node.extras||S.extras};for(let v of S.primitives||[]){if(v.extensions?.KHR_draco_mesh_compression){let $=De("draco");$&&$.decodePrimitive(i,v,s)}let k=[],H=n.createVertexArray();n.bindVertexArray(H);let V=i.accessors[v.attributes.POSITION],O=Number(V?.count??0);if(!Number.isFinite(O)||O<0||f+O>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=O,V?.min&&V?.max)for(let $=0;$<3;$++){let ie=I[12+$],Te=I[12+$];for(let he=0;he<3;he++){let Ue=I[he*4+$]*V.min[he],Ne=I[he*4+$]*V.max[he];ie+=Ue<Ne?Ue:Ne,Te+=Ue>Ne?Ue:Ne}ie<l[$]&&(l[$]=ie),Te>p[$]&&(p[$]=Te)}let L=at(n,i,s,v.attributes.POSITION,0,3,k);at(n,i,s,v.attributes.NORMAL,1,3,k),at(n,i,s,v.attributes.TEXCOORD_0,2,2,k);let P=0,_=5123,N=null;if(v.indices!==void 0){let $=i.accessors[v.indices],Te=(i.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(P=Number($.count??0),!Number.isFinite(P)||P<0||T+P>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=P,_=$.componentType===5125?5125||5125:5123||5123;let he=n.createBuffer();k.push(he),n.bindBuffer(34963,he),$.componentType===5125?(N=new Uint32Array(s,Te,$.count),n.bufferData(34963,N,35044)):(N=new Uint16Array(s,Te,$.count),n.bufferData(34963,N,35044))}else P=V.count;let U={};for(let $ of K)if($.onBuildPrimitiveVAO){let ie=$.onBuildPrimitiveVAO(n,H,v,i,s);ie&&(U[$.name]=ie)}n.bindVertexArray(null);let B=i.materials&&v.material!==void 0?i.materials[v.material]:null,F=en,z=tn,Y=!1;for(let $ of K)if($.onResolveShader){let ie=$.onResolveShader(v,B,F,z);ie&&(F=ie.vs,z=ie.fs,Y=!0)}let G=Y?ct(n,F,z):null,ae=G?ut(n,G,nn):null,Z=B?.pbrMetallicRoughness,Q=Z?.baseColorFactor||[.8,.8,.8,1],de=Z?.metallicFactor??.1,pe=Z?.roughnessFactor??.5,ce=B?.extensions?.KHR_materials_clearcoat,ne=ce?ce.clearcoatFactor??1:0,be=Math.max(.04,ce?.clearcoatRoughnessFactor??.04),ye=Z?.baseColorTexture!==void 0&&h[Z.baseColorTexture.index]?h[Z.baseColorTexture.index]:null,_e=Z?.metallicRoughnessTexture!==void 0&&h[Z.metallicRoughnessTexture.index]?h[Z.metallicRoughnessTexture.index]:null,Rn=B?.normalTexture!==void 0&&h[B.normalTexture.index]?h[B.normalTexture.index]:null,Sn=B?.normalTexture?.scale??1,An=B?.occlusionTexture!==void 0&&h[B.occlusionTexture.index]?h[B.occlusionTexture.index]:null,_n=B?.occlusionTexture?.strength??1,Dn=!!(B?.extensions?.KHR_materials_transmission||U.materials?.isTransmissive);D.primitives.push({vao:H,indexCount:P,indexType:_,baseColor:Q,metallic:de,roughness:pe,clearcoat:ne,clearcoatRoughness:be,positions:L,indices:N,texture:ye,metallicRoughnessTexture:_e,normalTexture:Rn,occlusionTexture:An,normalScale:Sn,occlusionStrength:_n,buffers:k,materialIndex:v.material,pluginData:U,customProgram:G,customUniforms:ae,isTransmissive:Dn})}c.push(D)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(p[0])||(p=[1,1,1]);let M=[(l[0]+p[0])/2,(l[1]+p[1])/2,(l[2]+p[2])/2],A=p[0]-l[0],C=p[1]-l[1],b=p[2]-l[2],w=Math.max(Math.hypot(A,C,b)/2,.5),y=[l[0],l[1],l[2]],R=[p[0],p[1],p[2]],d=e.animations;if(!d){for(let x of K)if(x.onParseGLB?.(e),e.animations){d=e.animations;break}}return d||(d=[]),{meshes:c,bounds:{center:M,radius:w,min:y,max:R},lights:a,animations:d,worldMatrices:m}}var Ve=class{constructor(e,t,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=j();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=j();this.viewMatrix=j();this.modelMatrix=j();this.mvpMatrix=j();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.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.xrDepthState={enabled:!1,texture:null,uvTransform:j(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),i=u}this.canvas=i,this.opts=s||{},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 m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.renderProg=ct(m,en,tn),this.pickProg=ct(m,Pn,Fn),this.uRender=ut(m,this.renderProg,nn),this.uPick=ut(m,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,t){In(e,t)}static getDecoder(e){return De(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 t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,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,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:s,animations:c,worldMatrices:m}=Zt(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of K)o.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(Qt(e))}loadModel(e){this.loadGLBData(Ce(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ce(e),{meshes:i}=Zt(this.gl,r,rn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],re(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),re(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],c=[],m=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&c.length<6){let h=u.position||[0,0,0];c.push(h[0],h[1],h[2]),m.push(o[0]*a,o[1]*a,o[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(t.uniform3fv(e.uPointLightPos,c),t.uniform3fv(e.uPointLightColor,m)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of K)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of K)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.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((t,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],c=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}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 t of K)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,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 t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,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 t=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(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*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,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}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,t){let r=j();te(r,this.projMatrix,this.viewMatrix);let[i,s,c]=e,m=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=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],t&&(m=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*c+r[12],l=r[1]*i+r[5]*s+r[9]*c+r[13],p=r[2]*i+r[6]*s+r[10]*c+r[14],f=r[3]*i+r[7]*s+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,M=l/f,A=p/f,C=this.canvas.getBoundingClientRect(),b=C.width||this.canvas.clientWidth||this.canvas.width||300,w=C.height||this.canvas.clientHeight||this.canvas.height||150,y=(T*.5+.5)*b,R=(-M*.5+.5)*w,d=T>=-1.1&&T<=1.1&&M>=-1.1&&M<=1.1&&A>=-1&&A<=1;if(d&&t){let x=this.customTarget||this.bounds.center,g=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),S=x[1]+this.currDistance*Math.sin(this.currPhi),I=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),E=[i-g,s-S,c-I];m*E[0]+u*E[1]+o*E[2]>.05&&(d=!1)}return{x:y,y:R,z:A,visible:d}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],m=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+s*m[0])*o,u[1]+=(-i*c[1]+s*m[1])*o,u[2]+=(-i*c[2]+s*m[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.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=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.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,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),u=i.height>0?Math.floor((t-i.top)*(c/i.height)):Math.floor(t);return this.performMeshPick(m,u,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300),m=j();te(m,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i){(this.pickFboWidth!==s||this.pickFboHeight!==c)&&this.resizePickingFbo(s,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let d=0;d<this.meshes.length;d++){let x=this.meshes[d];if(x.visible===!1||x.isPluginMesh)continue;let g=d+1,S=(g&255)/255,I=(g>>8&255)/255,E=(g>>16&255)/255;i.uniform4f(this.uPick.uColorId,S,I,E,1),te(this.modelMatrix,this.modelRootMatrix,x.transform),te(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let D of x.primitives)i.bindVertexArray(D.vao),i.drawElements(4,D.indexCount,D.indexType,0)}let y=new Uint8Array(4);i.readPixels(o,a,1,1,6408,5121,y),i.bindFramebuffer(36160,null);let R=y[0]+(y[1]<<8)+(y[2]<<16);R>0&&R<=this.meshes.length&&(u=[this.meshes[R-1]])}u.length===0&&(u=this.meshes.filter(y=>y.visible!==!1));let h=null,l=1/0,p=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,M=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=T[1]+this.currDistance*Math.sin(this.currPhi),C=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let y of u){te(this.modelMatrix,this.modelRootMatrix,y.transform),te(this.mvpMatrix,m,this.modelMatrix);let R=j();if(!qt(R,this.mvpMatrix))continue;let d=(o+.5)/s*2-1,x=(a+.5)/c*2-1,g=[0,0,0],S=[0,0,0];ot(g,d,x,-1,R),ot(S,d,x,1,R);let I=S[0]-g[0],E=S[1]-g[1],D=S[2]-g[2],v=Math.hypot(I,E,D)||1,k=I/v,H=E/v,V=D/v,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let _ of y.primitives){if(!_.positions)continue;let N=_.positions,U=_.indices,B=Math.floor(U?U.length/3:N.length/9);for(let F=0;F<B;F++){let z=U?U[F*3]:F*3,Y=U?U[F*3+1]:F*3+1,G=U?U[F*3+2]:F*3+2;Kt(g[0],g[1],g[2],k,H,V,N[z*3],N[z*3+1],N[z*3+2],N[Y*3],N[Y*3+1],N[Y*3+2],N[G*3],N[G*3+1],N[G*3+2],O,P)}}})(1e-4),isFinite(O.distance)){let P=O.point[0],_=O.point[1],N=O.point[2],U=this.modelMatrix,B=U[0]*P+U[4]*_+U[8]*N+U[12],F=U[1]*P+U[5]*_+U[9]*N+U[13],z=U[2]*P+U[6]*_+U[10]*N+U[14],Y=B-M,G=F-A,ae=z-C,Z=Math.hypot(Y,G,ae);if(Z<l){re(this.normalMatrix,this.modelMatrix);let Q=this.normalMatrix,de=O.normal[0],pe=O.normal[1],ce=O.normal[2],ne=Q[0]*de+Q[3]*pe+Q[6]*ce,be=Q[1]*de+Q[4]*pe+Q[7]*ce,ye=Q[2]*de+Q[5]*pe+Q[8]*ce,_e=Math.hypot(ne,be,ye)||1;ne/=_e,be/=_e,ye/=_e,ne*Y+be*G+ye*ae>0&&(ne=-ne,be=-be,ye=-ye),h=y,l=Math.round(Z*1e3)/1e3,p=[Math.round(B*1e3)/1e3,Math.round(F*1e3)/1e3,Math.round(z*1e3)/1e3],f=[Math.round(ne*1e3)/1e3,Math.round(be*1e3)/1e3,Math.round(ye*1e3)/1e3]}}}if(!h)return null;let w={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:p,normal:f,screenX:e,screenY:t};if(r){for(let y of K)y.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}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));(this.canvas.width!==r||this.canvas.height!==i)&&(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i))}start(){if(this.animFrameId!==null)return;this.lastTime=performance.now();let e=t=>{let r=Math.min((t-this.lastTime)/1e3,.1);this.lastTime=t,this.isVisible&&(this.resize(),this.update(r),this.render()),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),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let l of K)l.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let l of K)l.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;let r=(this.canvas.width||1)/(this.canvas.height||1),i=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):this.bounds.radius*20;Yt(this.projMatrix,this.fov,r,.1,i);let s=this.customTarget||this.bounds.center,c=s[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),m=s[1]+this.currDistance*Math.sin(this.currPhi),u=s[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Be(this.viewMatrix,[c,m,u],s,[0,1,0]),te(this.mvpMatrix,this.projMatrix,this.viewMatrix),re(this.normalMatrix,this.modelMatrix);let o=Math.round((this.currTheta*180/Math.PI%360+360)%360),a=Math.round(this.currPhi*180/Math.PI),h=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(o-this.lastReportedTheta)>=1||Math.abs(a-this.lastReportedPhi)>=1||Math.abs(h-this.lastReportedZoom)>=.02){this.lastReportedTheta=o,this.lastReportedPhi=a,this.lastReportedZoom=h;let l={theta:o,phi:a,zoom:h,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(l),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:l}))}}renderXRView(e,t,r,i){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let s=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,m=e?.transform?.position,u=m?[m.x,m.y,m.z]:[0,1.6,0];r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:s,projMatrix:c,eyePos:u,viewport:i,eye:e?.eye||"none",clear:e?.eye!=="right"})}render(e){let t=this.gl,r=this.canvas.width,i=this.canvas.height;e?.viewport?(t.viewport(e.viewport[0],e.viewport[1],e.viewport[2],e.viewport[3]),r=e.viewport[2],i=e.viewport[3]):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let s=j();te(s,e?.projMatrix??this.projMatrix,e?.viewMatrix??this.viewMatrix);let c=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,u=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),a=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let M of K)M.onBeforeDrawScene?.(this,t,s,[u,o,a],c);if(this.meshes.length===0&&this.backdropMeshes.length===0)return;let h=e?.eye||"none",l=!1,p=this.backdropMeshes.length,f=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,T=M=>{for(let A=0;A<f.length;A++){let C=f[A];if(C.visible===!1)continue;let b=this.selectedMeshName!==""&&C.name===this.selectedMeshName;A<p?this.modelMatrix.set(C.transform):te(this.modelMatrix,this.modelRootMatrix,C.transform),te(this.mvpMatrix,s,this.modelMatrix),re(C.normalMatrix,this.modelMatrix);let w=C.extras?.xr?.stereo||C.userData?.xr?.stereo,y=0,R=0,d=1,x=1;w==="sbs"?(d=.5,y=h==="right"?.5:0):w==="ou"&&(x=.5,R=h==="right"?.5:0);for(let g of C.primitives){let S=!!g.isTransmissive;if(!M&&S){l=!0;continue}if(M&&!S)continue;let I=g.customProgram||this.renderProg,E=g.customUniforms||this.uRender;t.useProgram(I),t.uniform1i(E.uToneMapping,c),t.uniform1f(E.uEnvIntensity,this.envIntensity),t.uniform3f(E.uCameraPos,u,o,a),t.uniform1f(E.uEmissive,b?1:0),t.uniformMatrix4fv(E.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(E.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(E.uNormalMatrix,!1,C.normalMatrix),E.uUvTransform&&t.uniform4f(E.uUvTransform,y,R,d,x),E.uViewportSize&&t.uniform2f(E.uViewportSize,Math.max(1,r),Math.max(1,i)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),E.uXrDepthTex&&t.uniform1i(E.uXrDepthTex,5),E.uXrDepthEnabled&&t.uniform1i(E.uXrDepthEnabled,1),E.uXrDepthFormat&&t.uniform1i(E.uXrDepthFormat,this.xrDepthState.format||0),E.uXrRawValueToMeters&&t.uniform1f(E.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),E.uXrDepthUVTransform&&t.uniformMatrix4fv(E.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):E.uXrDepthEnabled&&t.uniform1i(E.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(E.uEnvironmentMap,4),t.uniform1i(E.uHasEnvironmentMap,1)):t.uniform1i(E.uHasEnvironmentMap,0),this.bindLights(E);for(let D of K)D.onBeforeDrawPrimitive?.(t,I,g,C,this.worldMatrices||[],this.gltf);t.uniform4fv(E.uBaseColor,g.baseColor),t.uniform1f(E.uMetallic,g.metallic),t.uniform1f(E.uRoughness,g.roughness),E.uClearcoat&&t.uniform2f(E.uClearcoat,g.clearcoat??0,g.clearcoatRoughness??.04),g.texture?(t.activeTexture(33984),t.bindTexture(3553,g.texture),t.uniform1i(E.uBaseColorTexture,0),t.uniform1i(E.uHasTexture,1)):t.uniform1i(E.uHasTexture,0),g.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,g.metallicRoughnessTexture),t.uniform1i(E.uMetallicRoughnessTexture,1),t.uniform1i(E.uHasMetallicRoughnessTexture,1)):t.uniform1i(E.uHasMetallicRoughnessTexture,0),g.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,g.normalTexture),t.uniform1i(E.uNormalTexture,2),t.uniform1i(E.uHasNormalTexture,1),t.uniform1f(E.uNormalScale,g.normalScale)):t.uniform1i(E.uHasNormalTexture,0),g.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,g.occlusionTexture),t.uniform1i(E.uOcclusionTexture,3),t.uniform1i(E.uHasOcclusionTexture,1),t.uniform1f(E.uOcclusionStrength,g.occlusionStrength)):t.uniform1i(E.uHasOcclusionTexture,0),t.bindVertexArray(g.vao),t.drawElements(4,g.indexCount,g.indexType,0)}}};if(T(!1),l){for(let M of K)M.onBeforeTransmissivePass?.(t,this);T(!0)}for(let M of K)M.onAfterRender?.(t,this,s)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&t.deleteVertexArray(i.vao),i.buffers)for(let s of i.buffers)t.deleteBuffer(s);i.texture&&t.deleteTexture(i.texture),i.metallicRoughnessTexture&&t.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&t.deleteTexture(i.normalTexture),i.occlusionTexture&&t.deleteTexture(i.occlusionTexture),i.customProgram&&t.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 t of K)t.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()}};Ve.registerPlugin=Wt,Ve.getRegisteredPlugins=$t;function Nn(n){return n+3&-4}function kn(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function Ie(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],c=[],m=[],u=new Set,o=[],a=[],h=new Map,l=[];function p(d,x){let g=new Uint8Array(d.buffer,d.byteOffset,d.byteLength),S=Nn(g.byteLength),I=new Uint8Array(S);I.set(g),t.push(I);let E=i.length;return i.push({buffer:0,byteOffset:r,byteLength:g.byteLength,target:x}),r+=S,E}function f(d,x,g,S,I,E,D){let v=p(d,g),k=s.length,H={bufferView:v,byteOffset:0,componentType:S,count:I,type:x};return E&&(H.min=E),D&&(H.max=D),s.push(H),k}n.traverse(d=>{(d.isLight||d.color&&d.intensity!==void 0)&&l.push({type:d.type,color:[d.color.r,d.color.g,d.color.b],intensity:d.intensity,position:[d.position.x,d.position.y,d.position.z]})});let T=[];function M(d){let x={name:d.name||""},g=d.position,S=d.quaternion,I=d.scale;if((g.x||g.y||g.z)&&(x.translation=[g.x,g.y,g.z]),(S.x||S.y||S.z||S.w!==1)&&(x.rotation=[S.x,S.y,S.z,S.w]),(I.x!==1||I.y!==1||I.z!==1)&&(x.scale=[I.x,I.y,I.z]),d.userData&&Object.keys(d.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(d.userData,(D,v)=>{if(!(D==="__proto__"||D==="prototype"||D==="constructor"))return typeof v=="function"?void 0:v})),d.userData.xr)){let D=kn(d.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:D,ANDROID_xr_scenecore:D},ee().xrTraitSerializer?.gltfNode(x,d.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(d.geometry){let D=d.geometry,v=D.attributes.position;if(v&&v.count>0){let k=[1/0,1/0,1/0],H=[-1/0,-1/0,-1/0];for(let P=0;P<v.count;P++){let _=v.getX(P),N=v.getY(P),U=v.getZ(P);_<k[0]&&(k[0]=_),_>H[0]&&(H[0]=_),N<k[1]&&(k[1]=N),N>H[1]&&(H[1]=N),U<k[2]&&(k[2]=U),U>H[2]&&(H[2]=U)}let O={attributes:{POSITION:f(v.array,"VEC3",34962,5126,v.count,k,H)}};if(D.attributes.normal&&(O.attributes.NORMAL=f(D.attributes.normal.array,"VEC3",34962,5126,D.attributes.normal.count)),D.attributes.uv&&(O.attributes.TEXCOORD_0=f(D.attributes.uv.array,"VEC2",34962,5126,D.attributes.uv.count)),D.index){let P=D.index.array instanceof Uint32Array;O.indices=f(D.index.array,"SCALAR",34963,P?5125:5123,D.index.count)}if(d.material){let P=h.get(d.material);if(P===void 0){P=a.length,h.set(d.material,P);let _=d.material,N={name:_.name||"",pbrMetallicRoughness:{baseColorFactor:[_.color.r,_.color.g,_.color.b,_.opacity],metallicFactor:_.metalness,roughnessFactor:_.roughness},doubleSided:_.side===2||_.doubleSided};if(_.emissive&&(_.emissive.r>0||_.emissive.g>0||_.emissive.b>0)){let B=_.emissiveIntensity??1;N.emissiveFactor=[_.emissive.r*B,_.emissive.g*B,_.emissive.b*B]}let U={};_.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:_.clearcoat,clearcoatRoughnessFactor:_.clearcoatRoughness||0}),_.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:_.sheenColor?[_.sheenColor.r,_.sheenColor.g,_.sheenColor.b]:[1,1,1],sheenRoughnessFactor:_.sheenRoughness||0}),_.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:_.transmission}),_.thickness>0&&(U.KHR_materials_volume={thicknessFactor:_.thickness,attenuationDistance:_.attenuationDistance??1/0,attenuationColor:_.attenuationColor?[_.attenuationColor.r,_.attenuationColor.g,_.attenuationColor.b]:[1,1,1]}),_.ior!==void 0&&_.ior!==1.5&&(U.KHR_materials_ior={ior:_.ior}),_.dispersion>0&&(U.KHR_materials_dispersion={dispersion:_.dispersion}),_.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:_.iridescence,iridescenceIor:_.iridescenceIOR??1.3}),Object.keys(U).length>0&&(N.extensions=U),a.push(N)}O.material=P}let L=c.length;c.push({primitives:[O],name:d.name,...x.extras?{extras:x.extras}:{}}),x.mesh=L}}let E=m.length;if(m.push(x),o.push(d),d.children.length>0){x.children=[];for(let D of d.children)x.children.push(M(D))}return E}for(let d of n.children)T.push(M(d));let A=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),C=[];if(typeof A=="function"&&o.length>0){let d=e?.duration??4,x=e?.fps??15,g=Math.max(2,Math.round(d*x)+1),S=new Float32Array(g),I=o.map(L=>({px:L.position.x,py:L.position.y,pz:L.position.z,qx:L.quaternion.x,qy:L.quaternion.y,qz:L.quaternion.z,qw:L.quaternion.w,sx:L.scale.x,sy:L.scale.y,sz:L.scale.z})),E=o.map(()=>new Float32Array(g*3)),D=o.map(()=>new Float32Array(g*4)),v=o.map(()=>new Float32Array(g*3));for(let L=0;L<g;L++){let P=L/(g-1)*d;S[L]=P;try{A(P)}catch{}for(let _=0;_<o.length;_++){let N=o[_];E[_][L*3]=N.position.x,E[_][L*3+1]=N.position.y,E[_][L*3+2]=N.position.z,D[_][L*4]=N.quaternion.x,D[_][L*4+1]=N.quaternion.y,D[_][L*4+2]=N.quaternion.z,D[_][L*4+3]=N.quaternion.w,v[_][L*3]=N.scale.x,v[_][L*3+1]=N.scale.y,v[_][L*3+2]=N.scale.z}}for(let L=0;L<o.length;L++){let P=o[L],_=I[L];P.position.set(_.px,_.py,_.pz),P.quaternion.set(_.qx,_.qy,_.qz,_.qw),P.scale.set(_.sx,_.sy,_.sz)}n.updateMatrixWorld(!0);let k=null,H=()=>(k===null&&(k=f(S,"SCALAR",0,5126,g,[0],[d])),k),V=[],O=[];for(let L=0;L<o.length;L++){let P=I[L],_=!1,N=!1,U=!1;for(let B=0;B<g;B++)(Math.abs(E[L][B*3]-P.px)>1e-4||Math.abs(E[L][B*3+1]-P.py)>1e-4||Math.abs(E[L][B*3+2]-P.pz)>1e-4)&&(_=!0),(Math.abs(D[L][B*4]-P.qx)>1e-4||Math.abs(D[L][B*4+1]-P.qy)>1e-4||Math.abs(D[L][B*4+2]-P.qz)>1e-4||Math.abs(D[L][B*4+3]-P.qw)>1e-4)&&(N=!0),(Math.abs(v[L][B*3]-P.sx)>1e-4||Math.abs(v[L][B*3+1]-P.sy)>1e-4||Math.abs(v[L][B*3+2]-P.sz)>1e-4)&&(U=!0);if(_){let B=f(E[L],"VEC3",0,5126,g),F=V.length;V.push({input:H(),interpolation:"LINEAR",output:B}),O.push({sampler:F,target:{node:L,path:"translation"}})}if(N){let B=f(D[L],"VEC4",0,5126,g),F=V.length;V.push({input:H(),interpolation:"LINEAR",output:B}),O.push({sampler:F,target:{node:L,path:"rotation"}})}if(U){let B=f(v[L],"VEC3",0,5126,g),F=V.length;V.push({input:H(),interpolation:"LINEAR",output:B}),O.push({sampler:F,target:{node:L,path:"scale"}})}}O.length>0&&C.push({name:"ProceduralLoop",samplers:V,channels:O})}let b=Ht(m,c,n.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:a,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...C.length>0?{animations:C}:{},...b||u.size>0?{extensionsUsed:[...b?["KHR_interactivity"]:[],...u]}:{},...b?{extensions:{KHR_interactivity:b}}:{}},y=new Uint8Array(r),R=0;for(let d of t)y.set(d,R),R+=d.byteLength;return{gltf:w,bin:y.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function Xe(n){return new TextEncoder().encode(n)}function Ge(n,e){let{gltf:t,bin:r}=Ie(n,e),i=JSON.stringify(t),s=Xe(i),c=(4-s.byteLength%4)%4,m=s.byteLength+c,u=20+m+8+r.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let l=0;l<c;l++)o[20+s.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),o.set(new Uint8Array(r),h+8),o}function Bn(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let c=s.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let d=0;d<c;d++){let x=s.getX(d),g=s.getY(d),S=s.getZ(d);m[d*3]=u[0]*x+u[4]*g+u[8]*S+u[12],m[d*3+1]=u[1]*x+u[5]*g+u[9]*S+u[13],m[d*3+2]=u[2]*x+u[6]*g+u[10]*S+u[14]}let o;if(i.attributes.normal){let d=i.attributes.normal;o=new Float32Array(c*3);let x=new Float32Array(9);re(x,u);for(let g=0;g<c;g++){let S=d.getX(g),I=d.getY(g),E=d.getZ(g),D=x[0]*S+x[3]*I+x[6]*E,v=x[1]*S+x[4]*I+x[7]*E,k=x[2]*S+x[5]*I+x[8]*E,H=Math.hypot(D,v,k)||1;o[g*3]=D/H,o[g*3+1]=v/H,o[g*3+2]=k/H}}let a;if(i.attributes.uv){let d=i.attributes.uv;a=new Float32Array(c*2);for(let x=0;x<c;x++)a[x*2]=d.getX(x),a[x*2+1]=d.getY(x)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let d=0;d<c;d++)h[d]=d}let l="DefaultMaterial",p=[.8,.8,.8],f=.5,T=.1,M=0,A=0,C=1.5,b=1,w=[0,0,0];if(r.material){let d=r.material;l=d.name||`Material_${t.length}`,d.color&&(p=[d.color.r,d.color.g,d.color.b]),typeof d.roughness=="number"&&(f=d.roughness),typeof d.metalness=="number"&&(T=d.metalness),typeof d.clearcoat=="number"&&(M=d.clearcoat),typeof d.clearcoatRoughness=="number"&&(A=d.clearcoatRoughness),typeof d.ior=="number"&&(C=d.ior);let x=typeof d.opacity=="number"?d.opacity:1,g=typeof d.transmission=="number"?d.transmission:0;if(b=x*(1-g),d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let S=d.emissiveIntensity??1;w=[d.emissive.r*S,d.emissive.g*S,d.emissive.b*S]}}let y,R=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof R=="function"){let d=e?.duration??4,x=e?.fps??4,g=Math.max(2,Math.round(d*x)+1),S=[],I=[],E=[],D=[],v=[r.position.x,r.position.y,r.position.z],k=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],H=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let O=0;O<g;O++){let L=O/(g-1)*d;S.push(L);try{R(L)}catch{}I.push([r.position.x,r.position.y,r.position.z]),E.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),D.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-v[0])>1e-4||Math.abs(r.position.y-v[1])>1e-4||Math.abs(r.position.z-v[2])>1e-4||Math.abs(r.quaternion.x-k[0])>1e-4||Math.abs(r.quaternion.y-k[1])>1e-4||Math.abs(r.quaternion.z-k[2])>1e-4||Math.abs(r.quaternion.w-k[3])>1e-4||Math.abs(r.scale.x-H[0])>1e-4)&&(V=!0)}r.position.set(v[0],v[1],v[2]),r.quaternion.set(k[0],k[1],k[2],k[3]),r.scale.set(H[0],H[1],H[2]),V&&(y={times:S,translations:I,rotations:E,scales:D})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:o,uvs:a,materialName:l,color:p,roughness:f,metallic:T,clearcoat:M,clearcoatRoughness:A,ior:C,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:y})}}),t}function an(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),s=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(p){let f=s[p];if(!f)throw new Error(`Accessor ${p} not found`);let T=c[f.bufferView||0],M=(T.byteOffset||0)+(f.byteOffset||0),A=T.byteLength||0,C=i.slice(M,M+A);return{acc:f,buffer:C}}let h=new Map;if(o.length>0){let p=ze(t);for(let f=0;f<p.length;f++)h.set(f,p[f])}function l(p,f,T,M){let A=u[p];if(!A)return;let C=new Float32Array(9);re(C,f);for(let b=0;b<(A.primitives||[]).length;b++){let w=A.primitives[b],y=w.attributes?.POSITION;if(y===void 0)continue;let{acc:R,buffer:d}=a(y),x=new Float32Array(d,0,R.count*3),g=new Float32Array(x.length);for(let F=0;F<R.count;F++){let z=x[F*3],Y=x[F*3+1],G=x[F*3+2];g[F*3]=f[0]*z+f[4]*Y+f[8]*G+f[12],g[F*3+1]=f[1]*z+f[5]*Y+f[9]*G+f[13],g[F*3+2]=f[2]*z+f[6]*Y+f[10]*G+f[14]}let S,I=w.attributes?.NORMAL;if(I!==void 0){let{acc:F,buffer:z}=a(I),Y=new Float32Array(z,0,F.count*3);S=new Float32Array(Y.length);for(let G=0;G<F.count;G++){let ae=Y[G*3],Z=Y[G*3+1],Q=Y[G*3+2],de=C[0]*ae+C[3]*Z+C[6]*Q,pe=C[1]*ae+C[4]*Z+C[7]*Q,ce=C[2]*ae+C[5]*Z+C[8]*Q,ne=Math.hypot(de,pe,ce)||1;S[G*3]=de/ne,S[G*3+1]=pe/ne,S[G*3+2]=ce/ne}}let E,D=w.attributes?.TEXCOORD_0;if(D!==void 0){let{acc:F,buffer:z}=a(D);E=new Float32Array(z,0,F.count*2)}let v;if(w.indices!==void 0){let{acc:F,buffer:z}=a(w.indices);F.componentType===5125?v=new Uint32Array(z,0,F.count):v=new Uint16Array(z,0,F.count);let Y=R.count;for(let G of v)if(G>=Y)throw new Error(`SecurityError: Index buffer value (${G}) out of vertex bounds [0, ${Y}).`)}else{let F=R.count;v=F>65535?new Uint32Array(F):new Uint16Array(F);for(let z=0;z<F;z++)v[z]=z}let k="DefaultMaterial",H=[.8,.8,.8],V=.5,O=.1,L=0,P=0,_=1.5,N=1,U=[0,0,0];if(w.material!==void 0&&m[w.material]){let F=m[w.material];k=F.name||`Material_${w.material}`;let z=F.pbrMetallicRoughness||{},Y=1;Array.isArray(z.baseColorFactor)&&(H=[z.baseColorFactor[0],z.baseColorFactor[1],z.baseColorFactor[2]],typeof z.baseColorFactor[3]=="number"&&(Y=z.baseColorFactor[3])),typeof z.roughnessFactor=="number"&&(V=z.roughnessFactor),typeof z.metallicFactor=="number"&&(O=z.metallicFactor),Array.isArray(F.emissiveFactor)&&F.emissiveFactor.length>=3&&(U=[F.emissiveFactor[0],F.emissiveFactor[1],F.emissiveFactor[2]]);let G=F.extensions||{};G.KHR_materials_clearcoat&&(L=G.KHR_materials_clearcoat.clearcoatFactor??0,P=G.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),G.KHR_materials_ior&&typeof G.KHR_materials_ior.ior=="number"&&(_=G.KHR_materials_ior.ior);let ae=G.KHR_materials_transmission?.transmissionFactor??0;N=Y*(1-ae)}let B=(A.primitives||[]).length>1?`${T}_p${b}`:T;e.push({name:B,positions:g,indices:v,normals:S,uvs:E,materialName:k,color:H,roughness:V,metallic:O,clearcoat:L,clearcoatRoughness:P,ior:_,opacity:N,emissiveColor:U,xrTraits:M?.xr||A.extras?.xr})}}if(o.length>0)for(let p=0;p<o.length;p++){let f=o[p];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(p)||j(),M=f.name||u[f.mesh].name||`Node_${p}`;l(f.mesh,T,M,f.extras)}}else{let p=j();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,p,T,u[f].extras)}}return e}function lt(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function sn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function X(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function on(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${X(n[r*3])}, ${X(n[r*3+1])}, ${X(n[r*3+2])})`;return t.join(", ")}function On(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${X(n[r*2])}, ${X(1-n[r*2+1])})`;return t.join(", ")}function zn(n){return Array.from(n).join(", ")}function ht(n){let e=new Map;for(let u of n){let o=lt(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{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 t=0,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
218
+ endTimeCode = ${X(t)}
219
+ timeCodesPerSecond = 1.0
220
+ `);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
221
+ uniform token preliminary:planeAnchoring:alignment = "${r}"
222
+ `);let c=`#usda 1.0
223
+ (
224
+ defaultPrim = "Root"
225
+ metersPerUnit = 1.0
226
+ upAxis = "Y"
227
+ ${i})
228
+
229
+ def Xform "Root" (
230
+ kind = "component"
231
+ )
232
+ {
233
+ ${s}def Scope "Materials"
234
+ {
235
+ `;for(let[u,o]of e.entries()){let[a,h,l]=o.color,[p,f,T]=o.emissiveColor,M="";o.clearcoat>0&&(M+=`float inputs:clearcoat = ${X(o.clearcoat)}
236
+ `,M+=`float inputs:clearcoatRoughness = ${X(o.clearcoatRoughness)}
237
+ `),o.ior!==1.5&&(M+=`float inputs:ior = ${X(o.ior)}
238
+ `),o.opacity<1&&(M+=`float inputs:opacity = ${X(o.opacity)}
239
+ `),(p>0||f>0||T>0)&&(M+=`color3f inputs:emissiveColor = (${X(p)}, ${X(f)}, ${X(T)})
240
+ `),c+=`def Material "${u}"
241
+ {
242
+ def Shader "PBRShader"
243
+ {
244
+ uniform token info:id = "UsdPreviewSurface"
245
+ color3f inputs:diffuseColor = (${X(a)}, ${X(h)}, ${X(l)})
246
+ float inputs:metallic = ${X(o.metallic)}
247
+ float inputs:roughness = ${X(o.roughness)}
248
+ ${M}token outputs:surface
249
+ }
250
+ token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
251
+ }
252
+ `}c+=`}
253
+ def Scope "Meshes"
254
+ {
255
+ `;let m=new Set;for(let u=0;u<n.length;u++){let o=n[u],a=o.positions.length/3,h=1/0,l=1/0,p=1/0,f=-1/0,T=-1/0,M=-1/0;for(let d=0;d<a;d++){let x=o.positions[d*3],g=o.positions[d*3+1],S=o.positions[d*3+2];x<h&&(h=x),x>f&&(f=x),g<l&&(l=g),g>T&&(T=g),S<p&&(p=S),S>M&&(M=S)}isFinite(h)||(h=l=p=-1,f=T=M=1);let A=Math.floor(o.indices.length/3),C=lt(o.materialName,"DefaultMaterial"),b=lt(o.name,`Mesh_${u}`);m.has(b)&&(b=`${b}_${u}`),m.add(b);let w=A>0?A===1?"3":"3, ".repeat(A-1)+"3":"",y=o.xrTraits,R="";if(y){let d=[];y.physics&&y.physics!=="none"&&d.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let x=ee().xrTraitSerializer?.usdLines(y,sn)??[];if(!x.length)for(let g of["grab","billboard","follow","anchor","physics"]){let S=g==="follow"&&typeof y.follow=="object"?y.follow.mode??"head":y[g];S!==void 0&&x.push(`string ${g} = "${sn(S)}"`)}x.length>0&&d.push(`customData = {
256
+ dictionary xr = {
257
+ ${x.join(`
258
+ `)}
259
+ }
260
+ }`),d.length>0&&(R=` (
261
+ ${d.join(`
262
+ `)}
263
+ )`)}if(c+=`def Mesh "${b}"${R}
264
+ {
265
+ `,y?.physics&&y.physics!=="none"){let d=y.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
266
+ bool physics:kinematicEnabled = ${d}
267
+ bool physics:collisionEnabled = true
268
+ `}if(o.timeSamples&&o.timeSamples.times.length>0){let d=o.timeSamples,x=d.times.map((I,E)=>{let D=d.translations?.[E]||[0,0,0];return`${X(I)}: (${X(D[0])}, ${X(D[1])}, ${X(D[2])})`}).join(", "),g=d.times.map((I,E)=>{let D=d.rotations?.[E]||[0,0,0,1];return`${X(I)}: (${X(D[3])}, ${X(D[0])}, ${X(D[1])}, ${X(D[2])})`}).join(", "),S=d.times.map((I,E)=>{let D=d.scales?.[E]||[1,1,1];return`${X(I)}: (${X(D[0])}, ${X(D[1])}, ${X(D[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${x} }
269
+ quatf xformOp:orient.timeSamples = { ${g} }
270
+ double3 xformOp:scale.timeSamples = { ${S} }
271
+ uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
272
+ `}c+=`float3[] extent = [(${X(h)}, ${X(l)}, ${X(p)}), (${X(f)}, ${X(T)}, ${X(M)})]
273
+ int[] faceVertexCounts = [${w}]
274
+ int[] faceVertexIndices = [${zn(o.indices)}]
275
+ point3f[] points = [${on(o.positions)}]
276
+ `,o.normals&&o.normals.length===o.positions.length&&(c+=`normal3f[] normals = [${on(o.normals)}] (
277
+ interpolation = "vertex"
278
+ )
279
+ `),o.uvs&&o.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${On(o.uvs,a)}] (
280
+ interpolation = "vertex"
281
+ )
282
+ `),c+=`rel material:binding = </Root/Materials/${C}>
283
+ }
284
+ `}return c+=`}
285
+ }
286
+ `,c}function Vn(n,e){if(n&&typeof n.traverse=="function"){let i=Bn(n,e);return ht(i)}let t=Ce(n),r=an(t);return ht(r)}var He=null;function Hn(n){if(!He){He=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;He[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=He[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function cn(n){let e=[],t=0,r=[];for(let a of n){let h=Xe(a.filename),l=Hn(a.data),p=a.data.length,f=30+h.length,T=t+f,M=0,A=T%64;A!==0&&(M=64-A);let C=new Uint8Array(f+M),b=new DataView(C.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,l,!0),b.setUint32(18,p,!0),b.setUint32(22,p,!0),b.setUint16(26,h.length,!0),b.setUint16(28,M,!0),C.set(h,30),M>0&&C.fill(0,30+h.length),e.push({offset:t,size:p,crc:l,filenameBytes:h,entry:a}),r.push(C),r.push(a.data),t+=C.length+a.data.length}let i=t;for(let a of e){let h=new Uint8Array(46+a.filenameBytes.length),l=new DataView(h.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),h.set(a.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,c=new Uint8Array(22),m=new DataView(c.buffer);m.setUint32(0,101010256,!0),m.setUint16(4,0,!0),m.setUint16(6,0,!0),m.setUint16(8,e.length,!0),m.setUint16(10,e.length,!0),m.setUint32(12,s,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),o=0;for(let a of r)u.set(a,o),o+=a.length;return u}function Le(n){let e=Vn(n),t=Xe(e);return cn([{filename:"model.usda",data:t}])}function mt(n){let e=Ce(n),t=an(e),r=ht(t),i=Xe(r);return cn([{filename:"model.usda",data:i}])}function un(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Le(n):mt(n)}var dt=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(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}},q=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(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,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.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 t=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=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-s*m,this.y=s*c-r*u,this.z=r*m-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 t=this.x,r=this.y,i=this.z,s=e.elements,c=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*c,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*c,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*c,this}},pt=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},Ye=class n{constructor(e=0,t=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),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,t,r,i=this.order){return this._x=Number(e),this._y=Number(t),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 n(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},qe=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),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,t,r,i){return this._x=Number(e),this._y=Number(t),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 n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(s/2),o=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(s/2);return this._x=o*m*u+c*a*h,this._y=c*a*u-o*m*h,this._z=c*m*h+o*a*u,this._w=c*m*u-o*a*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/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,t){let r=e.x,i=e.y,s=e.z,c=e.w,m=t.x,u=t.y,o=t.z,a=t.w;return this._x=r*a+c*m+i*o-s*u,this._y=i*a+c*u+s*m-r*o,this._z=s*a+c*o+r*u-i*m,this._w=c*a-r*m-i*u-s*o,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},we=class n{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 n;return e.copy(this),e}compose(e,t,r){return Oe(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return te(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Be(this.elements,[e.x,e.y,e.z],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let t=new q(0,0,0),r=new q(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},bt=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 re(this.elements,e.elements),this}},ue=class n{constructor(e,t,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(t!==void 0&&r!==void 0?this.setRGB(e,t,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let t=parseInt(e.slice(1),16);this.setHex(t)}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 t=Math.floor(e);return this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,this}setRGB(e,t,r){return this.r=Number(e),this.g=Number(t),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 n(this.r,this.g,this.b)}},Xn={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},W=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;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/t)}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,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},yt=class extends W{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},gt=class extends W{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},xt=class extends W{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},se=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof W)this.index=e;else if(Array.isArray(e)){let t=0;for(let i=0;i<e.length;i++)e[i]>t&&(t=e[i]);let r=t>65535?new Uint32Array(e):new Uint16Array(e);this.index=new W(r,1)}else e&&e.buffer&&(this.index=new W(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new q,s=new q,c=new q,m=new q,u=new q;if(this.index){let o=this.index.array;for(let a=0;a<o.length;a+=3){let h=o[a],l=o[a+1],p=o[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(p),e.getY(p),e.getZ(p)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let f of[h,l,p])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let o=0;o<t;o+=3){i.set(e.getX(o),e.getY(o),e.getZ(o)),s.set(e.getX(o+1),e.getY(o+1),e.getZ(o+1)),c.set(e.getX(o+2),e.getY(o+2),e.getZ(o+2)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let a=0;a<3;a++)r[(o+a)*3]=m.x,r[(o+a)*3+1]=m.y,r[(o+a)*3+2]=m.z}for(let o=0;o<t;o++){let a=r[o*3],h=r[o*3+1],l=r[o*3+2],p=Math.hypot(a,h,l)||1;r[o*3]=a/p,r[o*3+1]=h/p,r[o*3+2]=l/p}return this.setAttribute("normal",new W(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new W(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new W(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new W(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},Ke=class extends se{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,c=r/2,m=[-i,-s,c,i,-s,c,i,s,c,-i,s,c,i,-s,-c,-i,-s,-c,-i,s,-c,i,s,-c,-i,s,c,i,s,c,i,s,-c,-i,s,-c,-i,-s,-c,i,-s,-c,i,-s,c,-i,-s,c,i,-s,c,i,-s,-c,i,s,-c,i,s,c,-i,-s,-c,-i,-s,c,-i,s,c,-i,s,-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],o=[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 h=0;h<6;h++){let l=h*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},vt=class extends se{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-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],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},je=class extends se{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=[],h=o/r;for(let l=0;l<=t;l++){let p=l/t,f=p*Math.PI*2,T=h*Math.PI,M=-e*Math.cos(f)*Math.sin(T),A=e*Math.cos(T),C=e*Math.sin(f)*Math.sin(T);i.push(M,A,C);let b=Math.hypot(M,A,C)||1;s.push(M/b,A/b,C/b),c.push(p,1-h),a.push(i.length/3-1)}u.push(a)}for(let o=0;o<r;o++)for(let a=0;a<t;a++){let h=u[o][a+1],l=u[o][a],p=u[o+1][a],f=u[o+1][a+1];o!==0&&m.push(h,l,f),o!==r-1&&m.push(l,p,f)}this.setAttribute("position",new W(new Float32Array(i),3)),this.setAttribute("normal",new W(new Float32Array(s),3)),this.setAttribute("uv",new W(new Float32Array(c),2)),this.setIndex(m)}},xe=class extends se{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[],o=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,p=a===0?o:-o;for(let f=0;f<=i;f++){let T=f/i,M=T*Math.PI*2,A=Math.sin(M),C=Math.cos(M);s.push(l*A,p,l*C),c.push(A,0,C),m.push(T,1-h)}}for(let a=0;a<i;a++){let h=a,l=a+i+1,p=a+i+2,f=a+1;u.push(h,l,f,l,p,f)}if(e>0){let a=s.length/3;s.push(0,o,0),c.push(0,1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let p=l/i*Math.PI*2,f=Math.sin(p),T=Math.cos(p);s.push(e*f,o,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(a,h+l,h+l+1)}if(t>0){let a=s.length/3;s.push(0,-o,0),c.push(0,-1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let p=l/i*Math.PI*2,f=Math.sin(p),T=Math.cos(p);s.push(t*f,-o,t*T),c.push(0,-1,0),m.push(T*.5+.5,1-(f*.5+.5))}for(let l=0;l<i;l++)u.push(a,h+l+1,h+l)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Tt=class extends xe{constructor(e=1,t=1,r=16){super(0,e,t,r)}},wt=class extends se{constructor(e=1,t=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=o/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,p=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),T=t*Math.sin(a);s.push(p,f,T);let M=e*Math.cos(l),A=e*Math.sin(l),C=p-M,b=f-A,w=T,y=Math.hypot(C,b,w)||1;c.push(C/y,b/y,w/y),m.push(h/i,o/r)}}for(let o=1;o<=r;o++)for(let a=1;a<=i;a++){let h=(i+1)*o+a-1,l=(i+1)*(o-1)+a-1,p=(i+1)*(o-1)+a,f=(i+1)*o+a;u.push(h,l,f,l,p,f)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Et=class extends se{constructor(e=1,t=.4,r=64,i=8,s=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);let m=[],u=[],o=[],a=[],h=new q,l=new q,p=new q,f=new q,T=new q;function M(b,w){let y=Math.cos(w),R=Math.sin(w),d=c/s*w,x=e*(2+Math.cos(d))*.5;b.set(x*y,x*R,e*Math.sin(d)*.5)}let A=[];for(let b=0;b<=i;++b){let w=b/i*Math.PI*2;A.push(-t*Math.cos(w),t*Math.sin(w),b/i)}for(let b=0;b<=r;++b){let w=b/r,y=w*s*Math.PI*2;M(h,y),M(l,y+.01),p.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(p,f).normalize(),f.crossVectors(T,p).normalize();for(let R=0;R<=i;++R){let d=R*3,x=A[d],g=A[d+1],S=A[d+2],I=x*f.x+g*T.x,E=x*f.y+g*T.y,D=x*f.z+g*T.z;m.push(h.x+I,h.y+E,h.z+D);let v=Math.hypot(I,E,D)||1;u.push(I/v,E/v,D/v),o.push(w,S)}}let C=i+1;for(let b=1;b<=r;b++){let w=C*(b-1),y=w+C;for(let R=1;R<=i;R++){let d=w+(R-1),x=y+(R-1),g=y+R,S=w+R;a.push(d,x,S,x,g,S)}}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},Ze=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(){}},Mt=class{load(e,t){let r=new Ze(e);return t?.(r),r}};function J(n,e){return n!==void 0?Number(n):e}function ft(n,e){return n!==void 0?!!n:e}var fe=class{constructor(e={}){this.name=e.name||"",this.color=new ue(e.color!==void 0?e.color:16777215),this.emissive=new ue(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=J(e.emissiveIntensity,1),this.roughness=J(e.roughness,.5),this.metalness=J(e.metalness,.1),this.opacity=J(e.opacity,1),this.transparent=ft(e.transparent,!1),this.wireframe=ft(e.wireframe,!1),this.side=J(e.side,2),this.doubleSided=ft(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=J(e.clearcoat,0),this.clearcoatRoughness=J(e.clearcoatRoughness,0),this.sheen=J(e.sheen,0),this.sheenColor=new ue(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=J(e.sheenRoughness,0),this.transmission=J(e.transmission,0),this.thickness=J(e.thickness,0),this.attenuationColor=new ue(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=J(e.attenuationDistance,1/0),this.ior=J(e.ior,1.5),this.dispersion=J(e.dispersion,0),this.iridescence=J(e.iridescence,0),this.iridescenceIOR=J(e.iridescenceIOR,1.3)}dispose(){}},Ee=class extends fe{},Rt=class extends fe{},St=class extends fe{},At=class extends fe{},_t=class extends fe{},le=class n{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 q,this.rotation=new Ye,this.quaternion=new qe,this.scale=new q(1,1,1),this.matrix=new we,this.matrixWorld=new we,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,t=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(t,r,i)})}add(...e){for(let t of e)t&&t instanceof n&&(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t));return this}remove(...e){for(let t of e){let r=this.children.indexOf(t);r!==-1&&(t.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let t of this.children)t.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 t of this.children)t.updateMatrixWorld(e)}lookAt(e,t,r){let i=typeof e=="object"?e:new q(e,t,r);this.updateMatrixWorld(!0);let s=new we;s.lookAt(this.position,i,new q(0,1,0));let c=s.elements,m=c[0],u=c[4],o=c[8],a=c[1],h=c[5],l=c[9],p=c[2],f=c[6],T=c[10],M=m+h+T;if(M>0){let A=.5/Math.sqrt(M+1);this.quaternion.set((f-l)*A,(o-p)*A,(a-u)*A,.25/A)}}},Dt=class extends le{},Fe=class extends le{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof se?t:t?(oe("unsupported geometry","BoxGeometry"),new Ke(.5,.5,.5)):new se,this.material=i instanceof fe?i:i?(oe("unsupported material","MeshStandardMaterial"),new Ee({color:13421772})):new Ee}},Me=class extends le{constructor(e=16777215,t=1){super(),this.color=new ue(e),this.intensity=Number(t),this.type="directional"}},Je=class extends Me{constructor(e,t){super(e,t),this.type="ambient"}},Ct=class extends Me{constructor(t,r){super(t,r);this.target=new le;this.type="directional"}},Qe=class extends Me{constructor(t,r,i=0,s=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=s}},et=class extends le{},It=class extends et{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new q(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},tt=class extends le{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return me.validate(this),Ie(this)}toGLB(){return me.validate(this),Ge(this)}toUSDZ(){return me.validate(this),Le(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Fe){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},bn=Ie,yn=Ge,Gn=Le;var me=class{static validate(e){let t=0,r=0,i=0,s=new Set,c=(u,o,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${o}). Found: ${a}`)},m=(u,o)=>{if(!Number.isFinite(o))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(o)}), which cannot be bounds-checked.`);return o};e.traverse(u=>{if(u instanceof Fe){i++,i>1e3&&c("MESHES",1e3,i);let o=u.geometry;if(o){let a=0;if(o.attributes.position&&(a=m("vertex",o.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),o.index){let h=m("index",o.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=o.index.array;if(l&&a>0){let p=Math.min(h,l.length);for(let f=0;f<p;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=a)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&s.add(a.map),a.normalMap&&s.add(a.normalMap),a.roughnessMap&&s.add(a.roughnessMap)}}}),s.size>16&&c("TEXTURES",16,s.size);for(let u of s){let o=u,a=o.image,h=Number(a?.width??o.width??0)||0,l=Number(a?.height??o.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Lt=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 t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new ue(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){me.validate(e);let i=(s,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(s,c):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),c={};for(let[m,u]of s.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let s=bn(e),c=yn(e),m=(s.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:m,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.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 ln(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Pt=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=ln(),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 t=ln();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Wn(){}var We=new Proxy(Wn,{get:(n,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:We},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>We,construct:()=>We}),hn=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function Ae(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function ve(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Ae());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 mn,Pe;function $n(n){if(!ve(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Pe===void 0||mn!==t){mn=t;try{Pe=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!ve(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Pe=null}}return Pe?Pe.createScriptURL(n):n}function Sr(n){ee().sandboxEngineSrc=n}function gn(){let n=ee().sandboxEngineSrc;if(n)return n;if(hn)return hn;try{if(typeof document>"u")return null;let e=Ae(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&ve(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Yn(){let n=gn();if(!n)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(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ae()).href}function Ar(n){ee().sandboxIframeSrc=n}function qn(){let n=ee().sandboxIframeSrc;if(n)return n;let e=gn();if(!e||!ve(e))return null;let t=new URL(e,Ae());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Kn(){let n=qn();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ae()).href}function _r(n){ee().allowClientScripts=n}function jn(){return!!ee().allowClientScripts}function Zn(n){if(!ve(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ae()).href}var Jn=["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 Qn(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,s=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(y){m({type:"ERROR",nonce:t,message:String(y)})}let o=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let y=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let R={createScriptURL:function(x){if(x!==r&&(!i||x!==i))throw new TypeError("Disallowed worker importScripts URL");return x}};s&&(R.createScript=function(x){return String(x)});let d=e.trustedTypes.createPolicy("three-live#worker-boot",R);y=d.createScriptURL(r),i&&(a=d.createScriptURL(i)),s&&typeof d.createScript=="function"&&(h=d.createScript.bind(d))}catch{}o(y)}catch(y){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: '+(y&&y.message||y));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 y=0;y<c.length;y++){let R=c[y],d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d[R]}catch{}try{Object.defineProperty(d,R,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}}let p=Object.freeze({now:function(){return Date.now()}}),f=e;for(;f&&f!==Object.prototype;){if(f!==e)try{delete f.performance}catch{}try{Object.defineProperty(f,"performance",{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],M=!1;function A(y,R){if(y.type==="3D_MODEL_READY"){if(M)return;M=!0}y.nonce=t,R&&R.length?m(y,R):m(y)}let C=function(y,R){if(!y||T.indexOf(y.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");A(y,R)},b=e;for(;b&&b!==Object.prototype;){if(b===e||Object.prototype.hasOwnProperty.call(b,"postMessage"))try{Object.defineProperty(b,"postMessage",{value:C,writable:!1,configurable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}let w=!1;e.onmessage=function(y){let R=y&&y.data;if(!(!R||R.nonce!==t)&&!(R.type!=="EXECUTE"&&R.type!=="EXECUTE_URL")&&!w){w=!0;try{let d=new l.Scene,x=new l.PerspectiveCamera(60,1,.1,1e3),g=new l.WebGLRenderer({isSandboxed:!0});if(R.type==="EXECUTE_URL"){if(!i||R.scriptUrl!==i||typeof o!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let S=a||i,I=o;if(o=null,a=null,e.THREE=l,e.scene=d,e.camera=x,e.renderer=g,I(S),typeof e.__THREE_LIVE_SCENE__=="function"){let E=e.__THREE_LIVE_SCENE__(l,d,x,g);E&&typeof E.toGLB=="function"&&(d=E)}else e.scene&&typeof e.scene.toGLB=="function"&&(d=e.scene)}else{if(!s){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let S=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
287
+ return (function () {
288
+ `+R.script+`
289
+ })();
290
+ })`)):new Function("THREE","scene","camera","renderer",`return (function () {
291
+ `+R.script+`
292
+ })();`);h=null;let I=S(l,d,x,g);I&&typeof I.toGLB=="function"&&(d=I)}if(!M){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(d);let S=d.toGLB(),I=S instanceof ArrayBuffer?S:S.buffer.slice(S.byteOffset,S.byteOffset+S.byteLength);A({type:"3D_MODEL_READY",glbBuffer:I},[I])}m({type:"DONE",nonce:t})}catch(d){u(d&&d.message||d)}}},m({type:"READY",nonce:t})}function xn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:Jn};return`'use strict';(${Qn.toString()})(${JSON.stringify(s)});`}function vn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var ge=0;function Tn(){try{let n=new Uint32Array(4);return globalThis.crypto?.getRandomValues(n),Array.from(n,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function er(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var tr=1024,nr=256;function fn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function wn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,tr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!fn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let c=Object.create(null),m=i;for(let u of s){if(u.length>nr||u==="__proto__"||u==="constructor"||u==="prototype")return null;let o=m[u];if(!fn(o))return null;c[u]=o}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function rr(n){let e=er(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function En(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function ir(n,e,t,r){let i=Tn(),s=xn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.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=t,ge++;let m=!1,u=!1,o={modelDispatched:!1},a,h=()=>{if(m||u)return;let T=c.contentWindow;!T||typeof T.postMessage!="function"||(u=!0,T.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},l=()=>{},p=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let M=T.data;if(M&&typeof M=="object"&&M.type==="IFRAME_READY"){h();return}let A=wn(M,i);A&&En(A,r,l,o)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",p),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{m||(l(),vn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",p),c.onload=()=>{h()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){l();let T=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(T),T}return f.appendChild(c),{terminate:l}}function dn(n,e,t,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(ge>=32)return r(`SecurityError: ${ge} 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=Yn()}catch(l){let p=l instanceof Error?l.message:String(l);return r(p,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=Kn()}catch(p){let f=p instanceof Error?p.message:String(p);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(ir(n,i,l,t))}catch(p){return Promise.reject(p)}}let s=Tn(),c=xn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),p=URL.createObjectURL(l);try{let f=$n(p);m=new Worker(f)}finally{URL.revokeObjectURL(p)}}catch(l){let p=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${p}`,"Security Error: Failed to start Worker sandbox.")}ge++;let u=!1,o={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),m.terminate())};return a=setTimeout(()=>{u||(h(),vn(t))},3e3),m.onmessage=l=>{let p=wn(l.data,s);p&&En(p,t,h,o)},m.onerror=l=>{h(),t.onError?.(new Error(`Worker execution error: ${l.message}`))},n.kind==="url"?m.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):m.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function pn(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var sr={execute(n,e,t,r){let i=(m,u)=>{let o=new Error(m);return t.onError?.(o),u&&t.onToast?.(u),Promise.reject(o)},s=pn(e,i);if(s)return s;try{rr(n)}catch(m){let u=m instanceof Error?m.message:String(m);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??jn()?dn({kind:"script",script:n},e,t,i):i(Xt,Gt)},executeUrl(n,e,t){let r=(c,m)=>{let u=new Error(c);return t.onError?.(u),m&&t.onToast?.(m),Promise.reject(u)},i=pn(e,r);if(i)return i;let s;try{s=Zn(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return dn({kind:"url",scriptUrl:s},e,t,r)}},nt=new Set;function oe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;nt.has(t)||(nt.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function or(){return Array.from(nt)}function ar(){nt.clear()}var rt=class extends Ee{constructor(e={}){oe("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},cr=rt,Re=class extends je{constructor(e=1,t=0,r="PolyhedronGeometry"){oe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ft=class extends Re{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Ut=class extends Re{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Nt=class extends Re{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},kt=class extends Re{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Bt=class extends xe{constructor(e=1,t=1,r=4,i=8){oe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},Ot=class extends xe{constructor(e=.5,t=1,r=16){oe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},zt=class extends xe{constructor(e=1,t=16){oe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Vt=class extends Qe{constructor(t,r,i=0,s=Math.PI/3,c=0,m=2){oe("SpotLight","PointLight");super(t,r,i,m);this.target=new le;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=c}},it=class extends Je{constructor(e,t,r){oe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new ue(t??4473924)}},ur=it,Mn={Vector2:dt,Vector3:q,Vector4:pt,Euler:Ye,Quaternion:qe,Matrix4:we,Matrix3:bt,Color:ue,MathUtils:Xn,BufferAttribute:W,Float32BufferAttribute:yt,Uint16BufferAttribute:gt,Uint32BufferAttribute:xt,BufferGeometry:se,BoxGeometry:Ke,PlaneGeometry:vt,SphereGeometry:je,CylinderGeometry:xe,ConeGeometry:Tt,TorusGeometry:wt,TorusKnotGeometry:Et,IcosahedronGeometry:Ft,OctahedronGeometry:Ut,DodecahedronGeometry:Nt,TetrahedronGeometry:kt,CapsuleGeometry:Bt,RingGeometry:Ot,CircleGeometry:zt,Texture:Ze,TextureLoader:Mt,Material:fe,MeshStandardMaterial:Ee,MeshBasicMaterial:Rt,MeshLambertMaterial:St,MeshPhongMaterial:At,MeshPhysicalMaterial:_t,ShaderMaterial:rt,RawShaderMaterial:cr,Object3D:le,Group:Dt,Mesh:Fe,Light:Me,AmbientLight:Je,DirectionalLight:Ct,PointLight:Qe,SpotLight:Vt,HemisphereLight:it,RectAreaLight:ur,Camera:et,PerspectiveCamera:It,Scene:tt,WebGLRenderer:Lt,Clock:Pt,SceneQuotaValidator:me,exportSceneToCanvas3D:bn,exportSceneToGLB:yn,exportSceneToUSDZ:Gn,generateUSDZ:un,glbToUSDZ:mt,sceneToCanvas3D:Ie,sceneToGLB:Ge,sceneToUSDZ:Le,authorScriptRunner:sr,getAuthorWarnings:or,clearAuthorWarnings:ar};Object.freeze(me);Object.freeze(me.prototype);Object.freeze(tt.prototype);Object.freeze(Mn);var st=new Proxy(Mn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&oe(`THREE.${e}`,"no-op proxy"),We),set:(n,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(n,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(n,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),$e={name:"three_author",THREE:st},Dr=$e,Se=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Se.THREE>"u"&&(Se.THREE=st);typeof Se.requestAnimationFrame!="function"&&(Se.requestAnimationFrame=()=>(oe("requestAnimationFrame","single-frame static evaluation"),0));typeof Se.cancelAnimationFrame!="function"&&(Se.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=st,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=$e,n.ThreeLivePlugins.three_author=$e,n.ThreeLivePlugins["three-author"]=$e}var Cr=st;export{Je as AmbientLight,Ke as BoxGeometry,W as BufferAttribute,se as BufferGeometry,et as Camera,Bt as CapsuleGeometry,zt as CircleGeometry,Pt as Clock,ue as Color,Tt as ConeGeometry,xe as CylinderGeometry,Ct as DirectionalLight,Nt as DodecahedronGeometry,Ye as Euler,yt as Float32BufferAttribute,Dt as Group,it as HemisphereLight,Ft as IcosahedronGeometry,Me as Light,fe as Material,Xn as MathUtils,bt as Matrix3,we as Matrix4,Fe as Mesh,Rt as MeshBasicMaterial,St as MeshLambertMaterial,At as MeshPhongMaterial,_t as MeshPhysicalMaterial,Ee as MeshStandardMaterial,le as Object3D,Ut as OctahedronGeometry,It as PerspectiveCamera,vt as PlaneGeometry,Qe as PointLight,Re as PolyhedronFallbackGeometry,qe as Quaternion,cr as RawShaderMaterial,ur as RectAreaLight,Ot as RingGeometry,tt as Scene,me as SceneQuotaValidator,rt as ShaderMaterial,je as SphereGeometry,Vt as SpotLight,st as THREE,kt as TetrahedronGeometry,Ze as Texture,Mt as TextureLoader,wt as TorusGeometry,Et as TorusKnotGeometry,gt as Uint16BufferAttribute,xt as Uint32BufferAttribute,dt as Vector2,q as Vector3,pt as Vector4,Lt as WebGLRenderer,sr as authorScriptRunner,xn as buildSandboxWorkerSource,ar as clearAuthorWarnings,Cr as default,bn as exportSceneToCanvas3D,yn as exportSceneToGLB,Gn as exportSceneToUSDZ,un as generateUSDZ,jn as getAllowClientScripts,or as getAuthorWarnings,gn as getSandboxEngineSrc,qn as getSandboxIframeSrc,mt as glbToUSDZ,ve as isAllowedSandboxEngineUrl,We as noopProxy,Ie as sceneToCanvas3D,Ge as sceneToGLB,Le as sceneToUSDZ,_r as setAllowClientScripts,Sr as setSandboxEngineSrc,Ar as setSandboxIframeSrc,$e as threeAuthorPlugin,Dr as threeMicroPlugin,$n as toTrustedWorkerScriptURL,wn as validateSandboxWorkerMessage,oe as warnUnsupported};