three-live 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +37 -0
  3. package/dist/three-author-engine.js +112 -61
  4. package/dist/three-author.cjs +110 -59
  5. package/dist/three-author.d.ts +37 -0
  6. package/dist/three-author.js +109 -58
  7. package/dist/three-convert.cjs +106 -59
  8. package/dist/three-convert.d.ts +37 -0
  9. package/dist/three-convert.js +105 -58
  10. package/dist/three-live-animation.cjs +8 -9
  11. package/dist/three-live-animation.d.ts +37 -0
  12. package/dist/three-live-animation.js +7 -8
  13. package/dist/three-live-animation.min.js +6 -7
  14. package/dist/three-live-cad.cjs +3 -4
  15. package/dist/three-live-cad.d.ts +37 -0
  16. package/dist/three-live-cad.js +2 -3
  17. package/dist/three-live-cad.min.js +3 -4
  18. package/dist/three-live-cli.js +231 -0
  19. package/dist/three-live-element.cjs +17 -20
  20. package/dist/three-live-element.d.ts +37 -0
  21. package/dist/three-live-element.js +16 -19
  22. package/dist/three-live-full.cjs +138 -87
  23. package/dist/three-live-full.js +137 -86
  24. package/dist/three-live-full.min.js +138 -87
  25. package/dist/three-live-studio.cjs +19 -20
  26. package/dist/three-live-studio.d.ts +37 -0
  27. package/dist/three-live-studio.js +18 -19
  28. package/dist/three-live-studio.min.js +18 -19
  29. package/dist/three-live-viewer.cjs +17 -20
  30. package/dist/three-live-viewer.d.ts +37 -0
  31. package/dist/three-live-viewer.js +16 -19
  32. package/dist/three-live-viewer.min.js +17 -20
  33. package/dist/three-live.cjs +115 -64
  34. package/dist/three-live.js +113 -62
  35. package/dist/three-live.min.js +115 -64
  36. package/dist/three-view.cjs +17 -20
  37. package/dist/three-view.d.ts +37 -0
  38. package/dist/three-view.js +16 -19
  39. package/dist/three-xr.cjs +105 -58
  40. package/dist/three-xr.d.ts +37 -0
  41. package/dist/three-xr.js +104 -57
  42. package/package.json +25 -1
@@ -1,4 +1,4 @@
1
- /**
1
+ "use strict";/**
2
2
  * @license
3
3
  * Copyright 2026 Google LLC
4
4
  *
@@ -13,8 +13,7 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */
17
- "use strict";var Gt=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var qn=Object.getOwnPropertyNames;var Zn=Object.prototype.hasOwnProperty;var Jn=(n,e)=>{for(var t in e)Gt(n,t,{get:e[t],enumerable:!0})},Qn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of qn(e))!Zn.call(n,i)&&i!==t&&Gt(n,i,{get:()=>e[i],enumerable:!(r=Kn(e,i))||r.enumerable});return n};var er=n=>Qn(Gt({},"__esModule",{value:!0}),n);var Ur={};Jn(Ur,{AmbientLight:()=>Ke,BoxGeometry:()=>Xe,BufferAttribute:()=>le,BufferGeometry:()=>he,Camera:()=>Ze,CapsuleGeometry:()=>Ot,CircleGeometry:()=>Vt,Clock:()=>Lt,Color:()=>de,ConeGeometry:()=>vt,CylinderGeometry:()=>Me,DirectionalLight:()=>Ct,DodecahedronGeometry:()=>kt,Euler:()=>Ge,Float32BufferAttribute:()=>bt,Group:()=>At,HemisphereLight:()=>et,IcosahedronGeometry:()=>Pt,InstancedMesh:()=>je,Light:()=>Se,MAX_INSTANCES_PER_MESH:()=>Ye,Material:()=>ye,MathUtils:()=>Pn,Matrix3:()=>pt,Matrix4:()=>Ee,Mesh:()=>_e,MeshBasicMaterial:()=>Et,MeshLambertMaterial:()=>Rt,MeshPhongMaterial:()=>_t,MeshPhysicalMaterial:()=>St,MeshStandardMaterial:()=>Re,Object3D:()=>pe,OctahedronGeometry:()=>Ft,PerspectiveCamera:()=>It,PlaneGeometry:()=>xt,PointLight:()=>qe,PolyhedronFallbackGeometry:()=>Ae,Quaternion:()=>He,RawShaderMaterial:()=>$n,RectAreaLight:()=>Yn,RingGeometry:()=>Bt,Scene:()=>Je,SceneQuotaValidator:()=>be,ShaderMaterial:()=>Qe,SphereGeometry:()=>We,SpotLight:()=>zt,THREE:()=>Ce,TetrahedronGeometry:()=>Ut,Texture:()=>$e,TextureLoader:()=>wt,TorusGeometry:()=>Mt,TorusKnotGeometry:()=>Tt,Uint16BufferAttribute:()=>yt,Uint32BufferAttribute:()=>gt,Vector2:()=>ft,Vector3:()=>te,Vector4:()=>dt,WebGLRenderer:()=>Dt,authorScriptRunner:()=>Hn,buildSandboxWorkerSource:()=>nn,clearAuthorWarnings:()=>Wn,default:()=>kr,exportSceneToCanvas3D:()=>Qt,exportSceneToGLB:()=>en,exportSceneToUSDZ:()=>kn,generateUSDZ:()=>Zt,getAllowClientScripts:()=>Bn,getAuthorWarnings:()=>Xn,getSandboxEngineSrc:()=>tn,getSandboxIframeSrc:()=>On,glbToUSDZ:()=>mt,isAllowedSandboxEngineUrl:()=>Te,noopProxy:()=>Ve,sceneToCanvas3D:()=>Ne,sceneToGLB:()=>Oe,sceneToUSDZ:()=>Pe,setAllowClientScripts:()=>_r,setSandboxEngineSrc:()=>Tr,setSandboxIframeSrc:()=>Er,threeAuthorPlugin:()=>ze,threeMicroPlugin:()=>Fr,toTrustedWorkerScriptURL:()=>Un,validateSandboxWorkerMessage:()=>rn,warnUnsupported:()=>fe});module.exports=er(Ur);function sn(n,e,t){let r=[],i=new Map,s=[],o=[],l=[],a=new Map,u=f=>{let E=i.get(f);return E===void 0&&(E=r.length,r.push({op:f}),i.set(f,E)),E},c=f=>{let E=a.get(f);return E===void 0&&(E=l.length,l.push({id:f}),a.set(f,E)),E},h=(f,E={})=>s.push({declaration:u(f),...E})-1,m=(f,E,x)=>o.push({id:f,type:E,value:x})-1,b=f=>({node:f,socket:"value"}),g=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(g&&typeof g=="object"){let f=Array.isArray(g.graphs)?g.graphs[g.graph??0]:g;if(f&&Array.isArray(f.nodes)){let E=Array.isArray(f.declarations)?f.declarations:[];for(let x of E)x?.op&&u(x.op);Array.isArray(f.variables)&&o.push(...f.variables);for(let x of f.events||[])x?.id&&c(x.id);for(let x of f.nodes){if(!x||typeof x!="object")continue;let _=x.op||(typeof x.declaration=="number"?E[x.declaration]?.op:"");s.push(_?{...x,declaration:u(_)}:{...x})}}}let d=(f,E,x="translation")=>x==="baseColorFactor"||x==="metallicFactor"||x==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${x}`:x==="emissiveFactor"||x==="alphaCutoff"?`/materials/${Math.max(0,E)}/${x}`:x==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${x}`,w=new Map;n.forEach((f,E)=>{typeof f?.name=="string"&&!w.has(f.name)&&w.set(f.name,E)});let C=(f,E)=>typeof f.target=="string"&&w.has(f.target)?w.get(f.target):typeof f.targetNode=="number"?f.targetNode:E,N=f=>{let E=n[f];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let E=n[f],x=E?.extras?.interactivity;if(!x||typeof x!="object")continue;let _=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,D=M=>{let I=Array.isArray(M)?M:[M],p=[];for(let A=0;A<I.length;A++){let T=I[A];if(!T||typeof T!="object")continue;let R=T.action||"interpolate",F=typeof T.duration=="number"?T.duration:.35;if(R==="toggleTransform"){let P=T.property==="rotation"||T.property==="scale"?T.property:"translation",B=P==="rotation"?E.rotation||[0,0,0,1]:P==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],k=`/nodes/${f}/${P}`,O=m(`__toggle_${f}_${A}`,"bool",!1),S=h("variable/get",{configuration:{variable:O}}),G=h("math/not",{values:{a:b(S)}}),z=h("variable/set",{configuration:{variable:O},values:{value:b(G)}}),U=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(T.to)?T.to:B},duration:{value:F}}}),H=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(T.from)?T.from:B},duration:{value:F}}});s[z].flows={out:{node:h("flow/branch",{values:{condition:b(S)},flows:{true:{node:U},false:{node:H}}})}},p.push(z)}else if(R==="interpolate"){let P=T.to??T.value;if(P===void 0)continue;let B={value:{value:P},duration:{value:F}};T.from!==void 0&&(B.from={value:T.from}),p.push(h("pointer/interpolate",{configuration:{pointer:typeof T.pointer=="string"?T.pointer:d(C(T,f),N(C(T,f)),T.property)},values:B}))}else if(R==="setProperty"){if(T.value===void 0)continue;p.push(h("pointer/set",{configuration:{pointer:typeof T.pointer=="string"?T.pointer:d(C(T,f),N(C(T,f)),T.property)},values:{value:{value:T.value}}}))}else if(R==="toggleVisibility"){let P=C(T,f),B=m(`__vis_${P}_${A}`,"bool",!0),k=h("variable/get",{configuration:{variable:B}}),O=h("math/not",{values:{a:b(k)}}),S=h("variable/set",{configuration:{variable:B},values:{value:b(O)}});s[S].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${P}/extensions/KHR_node_visibility/visible`},values:{value:b(k)}})}},p.push(S)}else if(R==="cycleMaterialColor"&&Array.isArray(T.colors)&&T.colors.length>0){let P=typeof T.duration=="number"?T.duration:.25,B=`/materials/${Math.max(0,_)}/pbrMetallicRoughness/baseColorFactor`,k=m(`__color_idx_${f}_${A}`,"int",0),O=h("variable/get",{configuration:{variable:k}}),S=h("math/add",{values:{a:b(O),b:{value:1}}}),G=h("math/rem",{values:{a:b(S),b:{value:T.colors.length}}}),z=h("variable/set",{configuration:{variable:k},values:{value:b(G)}}),U={};for(let H=0;H<T.colors.length;H++){let L=T.colors[H],V=Array.isArray(L)&&L.length>=3?[L[0],L[1],L[2],L[3]??1]:[1,1,1,1];U[String(H)]={node:P>0?h("pointer/interpolate",{configuration:{pointer:B},values:{value:{value:V},duration:{value:P}}}):h("pointer/set",{configuration:{pointer:B},values:{value:{value:V}}})}}s[z].flows={out:{node:h("flow/switch",{values:{selection:b(O)},flows:U})}},p.push(z)}else if(R==="playAnimation")p.push(h("animation/start",{configuration:{animation:T.animation??T.clip??0}}));else if(R==="stopAnimation")p.push(h("animation/stop"));else if(R==="sendEvent"){let P={};for(let[B,k]of Object.entries(T.values||{}))P[B]={value:k};p.push(h("event/send",{configuration:{event:c(String(T.event??T.id??"custom"))},values:P}))}}if(!p.length)return null;if(p.length===1)return p[0];let y={};return p.forEach((A,T)=>{y[String(T)]={node:A}}),h("flow/sequence",{flows:y})},v=(M,I,p)=>{let y=D(I);y!==null&&h(M,{...p?{configuration:p}:{},flows:{out:{node:y}}})};if(x.onSelect&&v("pointer/onSelect",x.onSelect,{nodeIndex:f}),x.onHoverIn&&v("pointer/onHoverIn",x.onHoverIn,{nodeIndex:f}),x.onHoverOut&&v("pointer/onHoverOut",x.onHoverOut,{nodeIndex:f}),x.onStart&&v("event/onStart",x.onStart),x.onReceive&&typeof x.onReceive=="object")for(let[M,I]of Object.entries(x.onReceive))v("event/receive",I,{event:c(M)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:o,events:l}],graph:0}:null}var on='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).',an="Security Error: client-side scripts require allow-client-scripts opt-in.";var rt="__THREE_LIVE_REGISTRY__";function Q(){let n=typeof globalThis<"u"?globalThis:{};if(!n[rt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,rt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[rt]=e}}return n[rt]}var ie=Q().plugins;function cn(n){let e=Q().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function un(){return Q().plugins}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function it(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 o=1/(r-i);return n[10]=(i+r)*o,n[14]=2*i*r*o,n}function De(n,e,t,r){let[i,s,o]=e,[l,a,u]=r,[c,h,m]=t,b=i-c,g=s-h,d=o-m,w=Math.hypot(b,g,d);w<=1e-5?(b=0,g=0,d=1):(b/=w,g/=w,d/=w);let C=a*d-u*g,N=u*b-l*d,f=l*g-a*b;w=Math.hypot(C,N,f),w<=1e-5?(C=0,N=0,f=0):(C/=w,N/=w,f/=w);let E=g*f-d*N,x=d*C-b*f,_=b*N-g*C;return w=Math.hypot(E,x,_),w<=1e-5?(E=0,x=0,_=0):(E/=w,x/=w,_/=w),n[0]=C,n[1]=E,n[2]=b,n[3]=0,n[4]=N,n[5]=x,n[6]=g,n[7]=0,n[8]=f,n[9]=_,n[10]=d,n[11]=0,n[12]=-(C*i+N*s+f*o),n[13]=-(E*i+x*s+_*o),n[14]=-(b*i+g*s+d*o),n[15]=1,n}function ee(n,e,t){let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],a=e[5],u=e[6],c=e[7],h=e[8],m=e[9],b=e[10],g=e[11],d=e[12],w=e[13],C=e[14],N=e[15],f=t[0],E=t[1],x=t[2],_=t[3];return n[0]=f*r+E*l+x*h+_*d,n[1]=f*i+E*a+x*m+_*w,n[2]=f*s+E*u+x*b+_*C,n[3]=f*o+E*c+x*g+_*N,f=t[4],E=t[5],x=t[6],_=t[7],n[4]=f*r+E*l+x*h+_*d,n[5]=f*i+E*a+x*m+_*w,n[6]=f*s+E*u+x*b+_*C,n[7]=f*o+E*c+x*g+_*N,f=t[8],E=t[9],x=t[10],_=t[11],n[8]=f*r+E*l+x*h+_*d,n[9]=f*i+E*a+x*m+_*w,n[10]=f*s+E*u+x*b+_*C,n[11]=f*o+E*c+x*g+_*N,f=t[12],E=t[13],x=t[14],_=t[15],n[12]=f*r+E*l+x*h+_*d,n[13]=f*i+E*a+x*m+_*w,n[14]=f*s+E*u+x*b+_*C,n[15]=f*o+E*c+x*g+_*N,n}function we(n,e,t,r){let i=e[0],s=e[1],o=e[2],l=e[3],a=i+i,u=s+s,c=o+o,h=i*a,m=i*u,b=i*c,g=s*u,d=s*c,w=o*c,C=l*a,N=l*u,f=l*c,E=r[0],x=r[1],_=r[2];return n[0]=(1-(g+w))*E,n[1]=(m+f)*E,n[2]=(b-N)*E,n[3]=0,n[4]=(m-f)*x,n[5]=(1-(h+w))*x,n[6]=(d+C)*x,n[7]=0,n[8]=(b+N)*_,n[9]=(d-C)*_,n[10]=(1-(h+g))*_,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function me(n,e,t=0){let r=e[0],i=e[1],s=e[2],o=e[4],l=e[5],a=e[6],u=e[8],c=e[9],h=e[10],m=h*l-a*c,b=-h*o+a*u,g=c*o-l*u,d=r*m+i*b+s*g;return!d||t>0&&(!Number.isFinite(d)||Math.abs(d)<=t)||(d=1/d,n[0]=m*d,n[1]=b*d,n[2]=g*d,n[3]=(-h*i+s*c)*d,n[4]=(h*r-s*u)*d,n[5]=(-c*r+i*u)*d,n[6]=(a*i-s*l)*d,n[7]=(-a*r+s*o)*d,n[8]=(l*r-i*o)*d),n}function ln(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],l=e[5],a=e[6],u=e[7],c=e[8],h=e[9],m=e[10],b=e[11],g=e[12],d=e[13],w=e[14],C=e[15],N=t*l-r*o,f=t*a-i*o,E=t*u-s*o,x=r*a-i*l,_=r*u-s*l,D=i*u-s*a,v=c*d-h*g,M=c*w-m*g,I=c*C-b*g,p=h*w-m*d,y=h*C-b*d,A=m*C-b*w,T=N*A-f*y+E*p+x*I-_*M+D*v;return T?(T=1/T,n[0]=(l*A-a*y+u*p)*T,n[1]=(i*y-r*A-s*p)*T,n[2]=(d*D-w*_+C*x)*T,n[3]=(m*_-h*D-b*x)*T,n[4]=(a*I-o*A-u*M)*T,n[5]=(t*A-i*I+s*M)*T,n[6]=(w*E-g*D-C*f)*T,n[7]=(c*D-m*E+b*f)*T,n[8]=(o*y-l*I+u*v)*T,n[9]=(r*I-t*y-s*v)*T,n[10]=(g*_-d*E+C*N)*T,n[11]=(h*E-c*_-b*N)*T,n[12]=(l*M-o*p-a*v)*T,n[13]=(t*p-r*M+i*v)*T,n[14]=(d*f-g*x-w*N)*T,n[15]=(c*x-h*f+m*N)*T,n):null}function Ht(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],o=i[1]*e+i[5]*t+i[9]*r+i[13],l=i[2]*e+i[6]*t+i[10]*r+i[14],a=i[3]*e+i[7]*t+i[11]*r+i[15],u=a!==0?1/a:1;n[0]=s*u,n[1]=o*u,n[2]=l*u}function mn(n,e,t,r,i,s,o,l,a,u,c,h,m,b,g,d,w=0){let C=u-o,N=c-l,f=h-a,E=m-o,x=b-l,_=g-a,D=i*_-s*x,v=s*E-r*_,M=r*x-i*E,I=C*D+N*v+f*M;if(I>-1e-7&&I<1e-7)return!1;let p=1/I,y=n-o,A=e-l,T=t-a,R=p*(y*D+A*v+T*M);if(R<-w||R>1+w)return!1;let F=A*f-T*N,P=T*C-y*f,B=y*N-A*C,k=p*(r*F+i*P+s*B);if(k<-w||R+k>1+w)return!1;let O=p*(E*F+x*P+_*B);if(O>1e-4&&O<d.distance){d.distance=O,d.point=[n+r*O,e+i*O,t+s*O];let S=N*_-f*x,G=f*E-C*_,z=C*x-N*E,U=Math.hypot(S,G,z)||1;return d.normal=[S/U,G/U,z/U],!0}return!1}function st(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let c=0;c<t;c++)r.push(J());if(t===0)return r;let i=new Set;for(let c of n.nodes)if(Array.isArray(c.children))for(let h of c.children)i.add(h);let s=new Set,o=128,l=(c,h,m=0)=>{if(m>o||c<0||c>=t||s.has(c))return;s.add(c);let b=n.nodes[c];if(!b)return;let g=J();if(e&&e[c])g.set(e[c]);else if(b.matrix&&b.matrix.length===16)g.set(b.matrix);else{let w=b.translation||[0,0,0],C=b.rotation||[0,0,0,1],N=b.scale||[1,1,1];we(g,C,w,N)}let d=r[c];if(h?ee(d,h,g):d.set(g),Array.isArray(b.children))for(let w of b.children)typeof w=="number"&&l(w,d,m+1)},a=[],u=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let c=0;c<t;c++)i.has(c)||a.push(c);for(let c of a)l(c,null);for(let c=0;c<t;c++)!i.has(c)&&!a.includes(c)&&l(c,null);return r}function ot(n,e,t,r=!0){let i=[],s=null;try{for(let[o,l]of[[35633,e],[35632,t]]){let a=n.createShader(o);if(!a){if(r)throw new Error("Shader allocation failed");return null}if(i.push(a),n.shaderSource(a,l),n.compileShader(a),n.getShaderParameter&&!n.getShaderParameter(a,35713)){if(r)throw new Error(`Shader compile error: ${n.getShaderInfoLog(a)}`);return null}}if(s=n.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let o of i)n.attachShader(s,o);if(n.linkProgram(s),n.getProgramParameter&&!n.getProgramParameter(s,35714)){let o=r?n.getProgramInfoLog(s):null;if(n.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${o}`);return null}return s}finally{for(let o of i)s&&n.detachShader?.(s,o),n.deleteShader?.(o)}}var tr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Xt(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let o=t.componentType??5126,l=tr[o];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let a=l*r,u=i.byteStride&&i.byteStride>0?i.byteStride:a,c=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||u<a||c+(s-1)*u+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&u===a&&c%4===0)return new Float32Array(e,c,s*r);let h=new DataView(e),m=t.normalized===!0,b=new Float32Array(s*r);for(let g=0;g<s;g++){let d=c+g*u;for(let w=0;w<r;w++){let C=d+w*l,N;switch(o){case 5126:N=h.getFloat32(C,!0);break;case 5120:N=h.getInt8(C),m&&(N=Math.max(N/127,-1));break;case 5121:N=h.getUint8(C),m&&(N/=255);break;case 5122:N=h.getInt16(C,!0),m&&(N=Math.max(N/32767,-1));break;case 5123:N=h.getUint16(C,!0),m&&(N/=65535);break;default:N=h.getUint32(C,!0),m&&(N/=4294967295)}b[g*r+w]=N}}return b}function hn(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,l=Math.cos(o),a=Math.sin(o),u=(Number.isFinite(i)?i:1)*l,c=(Number.isFinite(i)?i:1)*a,h=-(Number.isFinite(s)?s:1)*a,m=(Number.isFinite(s)?s:1)*l;for(let b=0;b+1<n.length;b+=2){let g=n[b],d=n[b+1];n[b]=u*g+c*d+t,n[b+1]=h*g+m*d+r}}var pn=["neutral","reinhard","none","aces","agx"];function Yt(n){let e=String(n??"").trim().toLowerCase();return pn.includes(e)?e:"neutral"}function nr(n){return pn.indexOf(Yt(n))}function rr(n){return new TextDecoder().decode(n)}var bn=Q().decoders;function ir(n,e){bn.set(n.toLowerCase(),e)}function Le(n){return bn.get(n.toLowerCase())}function yn(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 m=t.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),o=12,l=null,a=null;for(;o+8<=s&&o+8<=e.byteLength;){let m=t.getUint32(o,!0),b=t.getUint32(o+4,!0),g=o+8;if(g+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${g+m} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let d=new Uint8Array(e,g,m),w=rr(d);l=JSON.parse(w,(C,N)=>C==="__proto__"||C==="constructor"||C==="prototype"?void 0:N)}else b===5130562&&(a=e.slice(g,g+m));o=g+m}if(!l)throw new Error("Missing JSON chunk in GLB");let u=l.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!Le("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(m)&&!Le("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!Le("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=a||new ArrayBuffer(0),h={gltf:l,bin:c,animations:[]};for(let m of ie)m.onParseGLB?.(h);return h}function sr(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 Ue(n){if(sr(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return yn(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var gn=`#version 300 es
16
+ */var wn=Object.defineProperty,Vr=Object.getOwnPropertyDescriptor,zr=Object.getOwnPropertyNames,Gr=Object.prototype.hasOwnProperty,Hr=(e,t)=>{for(var i in t)wn(e,i,{get:t[i],enumerable:!0})},$r=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of zr(t))!Gr.call(e,s)&&s!==i&&wn(e,s,{get:()=>t[s],enumerable:!(r=Vr(t,s))||r.enumerable});return e},Xr=e=>$r(wn({},"__esModule",{value:!0}),e),Di={};Hr(Di,{AmbientLight:()=>ht,BoxGeometry:()=>at,BufferAttribute:()=>ge,BufferGeometry:()=>de,Camera:()=>dt,CapsuleGeometry:()=>dn,CatmullRomCurve3:()=>Yt,CircleGeometry:()=>pn,Clock:()=>cn,Color:()=>we,ConeGeometry:()=>Ht,CubicBezierCurve3:()=>Kt,Curve3:()=>Fe,CylinderGeometry:()=>ct,DataTexture:()=>Zt,DirectionalLight:()=>sn,DodecahedronGeometry:()=>fn,EdgesGeometry:()=>yn,Euler:()=>ot,Float32BufferAttribute:()=>Ot,Group:()=>rn,HemisphereLight:()=>xt,IcosahedronGeometry:()=>hn,InstancedMesh:()=>mt,LatheGeometry:()=>ut,Light:()=>Ge,Line:()=>Ve,LineBasicMaterial:()=>Je,LineCurve3:()=>Wt,LineDashedMaterial:()=>bn,LineLoop:()=>xn,LineSegments:()=>vn,MAX_INSTANCES_PER_MESH:()=>lt,Material:()=>Me,MathUtils:()=>Tr,Matrix3:()=>Ut,Matrix4:()=>Be,Mesh:()=>Ie,MeshBasicMaterial:()=>Qt,MeshLambertMaterial:()=>en,MeshPhongMaterial:()=>tn,MeshPhysicalMaterial:()=>nn,MeshStandardMaterial:()=>ze,Object3D:()=>Ae,OctahedronGeometry:()=>mn,PerspectiveCamera:()=>on,PlaneGeometry:()=>zt,PointLight:()=>ft,Points:()=>Mn,PointsMaterial:()=>yt,PolyhedronFallbackGeometry:()=>wi,PolyhedronGeometry:()=>ke,QuadraticBezierCurve3:()=>jt,Quaternion:()=>Ye,RawShaderMaterial:()=>Fr,RectAreaLight:()=>Or,RingGeometry:()=>gt,Scene:()=>pt,SceneQuotaValidator:()=>De,ShaderMaterial:()=>bt,SphereGeometry:()=>Gt,SpotLight:()=>Tn,THREE:()=>$e,TetrahedronGeometry:()=>ln,Texture:()=>qe,TextureLoader:()=>Jt,TorusGeometry:()=>$t,TorusKnotGeometry:()=>Xt,TubeGeometry:()=>qt,Uint16BufferAttribute:()=>Bt,Uint32BufferAttribute:()=>Vt,Vector2:()=>Se,Vector3:()=>ee,Vector4:()=>kt,WebGLRenderer:()=>an,WireframeGeometry:()=>gn,authorScriptRunner:()=>Nr,buildSandboxWorkerSource:()=>Bn,clearAuthorWarnings:()=>Pr,default:()=>Ci,exportSceneToCanvas3D:()=>Fn,exportSceneToGLB:()=>kn,exportSceneToUSDZ:()=>wr,generateUSDZ:()=>Ln,getAllowClientScripts:()=>Rr,getAuthorWarnings:()=>Lr,getSandboxEngineSrc:()=>Un,getSandboxIframeSrc:()=>Er,glbToUSDZ:()=>It,isAllowedSandboxEngineUrl:()=>Ze,noopProxy:()=>it,sceneToCanvas3D:()=>Ke,sceneToGLB:()=>tt,sceneToUSDZ:()=>nt,setAllowClientScripts:()=>bi,setSandboxEngineSrc:()=>hi,setSandboxIframeSrc:()=>di,threeAuthorPlugin:()=>st,threeMicroPlugin:()=>Ri,toTrustedWorkerScriptURL:()=>Ar,validateSandboxWorkerMessage:()=>Vn,warnUnsupported:()=>He}),module.exports=Xr(Di);function zn(e,t,i){let r=[],s=new Map,n=[],a=[],o=[],l=new Map,h=c=>{let m=s.get(c);return m===void 0&&(m=r.length,r.push({op:c}),s.set(c,m)),m},u=c=>{let m=l.get(c);return m===void 0&&(m=o.length,o.push({id:c}),l.set(c,m)),m},f=(c,m={})=>n.push({declaration:h(c),...m})-1,g=(c,m,v)=>a.push({id:c,type:m,value:v})-1,w=c=>({node:c,socket:"value"}),p=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let c=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(c&&Array.isArray(c.nodes)){let m=Array.isArray(c.declarations)?c.declarations:[];for(let v of m)v?.op&&h(v.op);Array.isArray(c.variables)&&a.push(...c.variables);for(let v of c.events||[])v?.id&&u(v.id);for(let v of c.nodes){if(!v||typeof v!="object")continue;let S=v.op||(typeof v.declaration=="number"?m[v.declaration]?.op:"");n.push(S?{...v,declaration:h(S)}:{...v})}}}let b=(c,m,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,m)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,m)}/${v}`:v==="visible"?`/nodes/${c}/extensions/KHR_node_visibility/visible`:`/nodes/${c}/${v}`,T=new Map;e.forEach((c,m)=>{typeof c?.name=="string"&&!T.has(c.name)&&T.set(c.name,m)});let x=(c,m)=>typeof c.target=="string"&&T.has(c.target)?T.get(c.target):typeof c.targetNode=="number"?c.targetNode:m,M=c=>{let m=e[c];return(typeof m?.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0};for(let c=0;c<e.length;c++){let m=e[c],v=m?.extras?.interactivity;if(!v||typeof v!="object")continue;let S=(typeof m.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0,D=P=>{let N=Array.isArray(P)?P:[P],C=[];for(let E=0;E<N.length;E++){let y=N[E];if(!y||typeof y!="object")continue;let F=y.action||"interpolate",z=typeof y.duration=="number"?y.duration:.35;if(F==="toggleTransform"){let A=y.property==="rotation"||y.property==="scale"?y.property:"translation",_=A==="rotation"?m.rotation||[0,0,0,1]:A==="scale"?m.scale||[1,1,1]:m.translation||[0,0,0],d=`/nodes/${c}/${A}`,R=g(`__toggle_${c}_${E}`,"bool",!1),G=f("variable/get",{configuration:{variable:R}}),H=f("math/not",{values:{a:w(G)}}),B=f("variable/set",{configuration:{variable:R},values:{value:w(H)}}),Z=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.to)?y.to:_},duration:{value:z}}}),k=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.from)?y.from:_},duration:{value:z}}});n[B].flows={out:{node:f("flow/branch",{values:{condition:w(G)},flows:{true:{node:Z},false:{node:k}}})}},C.push(B)}else if(F==="interpolate"){let A=y.to??y.value;if(A===void 0)continue;let _={value:{value:A},duration:{value:z}};y.from!==void 0&&(_.from={value:y.from}),C.push(f("pointer/interpolate",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:_}))}else if(F==="setProperty"){if(y.value===void 0)continue;C.push(f("pointer/set",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:{value:{value:y.value}}}))}else if(F==="toggleVisibility"){let A=x(y,c),_=g(`__vis_${A}_${E}`,"bool",!0),d=f("variable/get",{configuration:{variable:_}}),R=f("math/not",{values:{a:w(d)}}),G=f("variable/set",{configuration:{variable:_},values:{value:w(R)}});n[G].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:w(d)}})}},C.push(G)}else if(F==="cycleMaterialColor"&&Array.isArray(y.colors)&&y.colors.length>0){let A=typeof y.duration=="number"?y.duration:.25,_=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,d=g(`__color_idx_${c}_${E}`,"int",0),R=f("variable/get",{configuration:{variable:d}}),G=f("math/add",{values:{a:w(R),b:{value:1}}}),H=f("math/rem",{values:{a:w(G),b:{value:y.colors.length}}}),B=f("variable/set",{configuration:{variable:d},values:{value:w(H)}}),Z={};for(let k=0;k<y.colors.length;k++){let Y=y.colors[k],ie=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];Z[String(k)]={node:A>0?f("pointer/interpolate",{configuration:{pointer:_},values:{value:{value:ie},duration:{value:A}}}):f("pointer/set",{configuration:{pointer:_},values:{value:{value:ie}}})}}n[B].flows={out:{node:f("flow/switch",{values:{selection:w(R)},flows:Z})}},C.push(B)}else if(F==="playAnimation")C.push(f("animation/start",{configuration:{animation:y.animation??y.clip??0}}));else if(F==="stopAnimation")C.push(f("animation/stop"));else if(F==="sendEvent"){let A={};for(let[_,d]of Object.entries(y.values||{}))A[_]={value:d};C.push(f("event/send",{configuration:{event:u(String(y.event??y.id??"custom"))},values:A}))}}if(!C.length)return null;if(C.length===1)return C[0];let L={};return C.forEach((E,y)=>{L[String(y)]={node:E}}),f("flow/sequence",{flows:L})},I=(P,N,C)=>{let L=D(N);L!==null&&f(P,{...C?{configuration:C}:{},flows:{out:{node:L}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:c}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:c}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:c}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[P,N]of Object.entries(v.onReceive))I("event/receive",N,{event:u(P)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:a,events:o}],graph:0}:null}var Gn='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).',Hn="Security Error: client-side scripts require allow-client-scripts opt-in.",vt="__THREE_LIVE_REGISTRY__";function le(){let e=typeof globalThis<"u"?globalThis:{};if(!e[vt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,vt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[vt]=t}}return e[vt]}var pe=le().plugins;function $n(e){let t=le().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function Xn(){return le().plugins}function he(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Mt(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let a=1/(r-s);return e[10]=(s+r)*a,e[14]=2*s*r*a,e}function We(e,t,i,r){let[s,n,a]=t,[o,l,h]=r,[u,f,g]=i,w=s-u,p=n-f,b=a-g,T=Math.hypot(w,p,b);T<=1e-5?(w=0,p=0,b=1):(w/=T,p/=T,b/=T);let x=l*b-h*p,M=h*w-o*b,c=o*p-l*w;T=Math.hypot(x,M,c),T<=1e-5?(x=0,M=0,c=0):(x/=T,M/=T,c/=T);let m=p*c-b*M,v=b*x-w*c,S=w*M-p*x;return T=Math.hypot(m,v,S),T<=1e-5?(m=0,v=0,S=0):(m/=T,v/=T,S/=T),e[0]=x,e[1]=m,e[2]=w,e[3]=0,e[4]=M,e[5]=v,e[6]=p,e[7]=0,e[8]=c,e[9]=S,e[10]=b,e[11]=0,e[12]=-(x*s+M*n+c*a),e[13]=-(m*s+v*n+S*a),e[14]=-(w*s+p*n+b*a),e[15]=1,e}function be(e,t,i){let r=t[0],s=t[1],n=t[2],a=t[3],o=t[4],l=t[5],h=t[6],u=t[7],f=t[8],g=t[9],w=t[10],p=t[11],b=t[12],T=t[13],x=t[14],M=t[15],c=i[0],m=i[1],v=i[2],S=i[3];return e[0]=c*r+m*o+v*f+S*b,e[1]=c*s+m*l+v*g+S*T,e[2]=c*n+m*h+v*w+S*x,e[3]=c*a+m*u+v*p+S*M,c=i[4],m=i[5],v=i[6],S=i[7],e[4]=c*r+m*o+v*f+S*b,e[5]=c*s+m*l+v*g+S*T,e[6]=c*n+m*h+v*w+S*x,e[7]=c*a+m*u+v*p+S*M,c=i[8],m=i[9],v=i[10],S=i[11],e[8]=c*r+m*o+v*f+S*b,e[9]=c*s+m*l+v*g+S*T,e[10]=c*n+m*h+v*w+S*x,e[11]=c*a+m*u+v*p+S*M,c=i[12],m=i[13],v=i[14],S=i[15],e[12]=c*r+m*o+v*f+S*b,e[13]=c*s+m*l+v*g+S*T,e[14]=c*n+m*h+v*w+S*x,e[15]=c*a+m*u+v*p+S*M,e}function Qe(e,t,i,r){let s=t[0],n=t[1],a=t[2],o=t[3],l=s+s,h=n+n,u=a+a,f=s*l,g=s*h,w=s*u,p=n*h,b=n*u,T=a*u,x=o*l,M=o*h,c=o*u,m=r[0],v=r[1],S=r[2];return e[0]=(1-(p+T))*m,e[1]=(g+c)*m,e[2]=(w-M)*m,e[3]=0,e[4]=(g-c)*v,e[5]=(1-(f+T))*v,e[6]=(b+x)*v,e[7]=0,e[8]=(w+M)*S,e[9]=(b-x)*S,e[10]=(1-(f+p))*S,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Ce(e,t,i=0){let r=t[0],s=t[1],n=t[2],a=t[4],o=t[5],l=t[6],h=t[8],u=t[9],f=t[10],g=f*o-l*u,w=-f*a+l*h,p=u*a-o*h,b=r*g+s*w+n*p;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=g*b,e[1]=w*b,e[2]=p*b,e[3]=(-f*s+n*u)*b,e[4]=(f*r-n*h)*b,e[5]=(-u*r+s*h)*b,e[6]=(l*s-n*o)*b,e[7]=(-l*r+n*a)*b,e[8]=(o*r-s*a)*b),e}function Wn(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],a=t[4],o=t[5],l=t[6],h=t[7],u=t[8],f=t[9],g=t[10],w=t[11],p=t[12],b=t[13],T=t[14],x=t[15],M=i*o-r*a,c=i*l-s*a,m=i*h-n*a,v=r*l-s*o,S=r*h-n*o,D=s*h-n*l,I=u*b-f*p,P=u*T-g*p,N=u*x-w*p,C=f*T-g*b,L=f*x-w*b,E=g*x-w*T,y=M*E-c*L+m*C+v*N-S*P+D*I;return y?(y=1/y,e[0]=(o*E-l*L+h*C)*y,e[1]=(s*L-r*E-n*C)*y,e[2]=(b*D-T*S+x*v)*y,e[3]=(g*S-f*D-w*v)*y,e[4]=(l*N-a*E-h*P)*y,e[5]=(i*E-s*N+n*P)*y,e[6]=(T*m-p*D-x*c)*y,e[7]=(u*D-g*m+w*c)*y,e[8]=(a*L-o*N+h*I)*y,e[9]=(r*N-i*L-n*I)*y,e[10]=(p*S-b*m+x*M)*y,e[11]=(f*m-u*S-w*M)*y,e[12]=(o*P-a*C-l*I)*y,e[13]=(i*C-r*P+s*I)*y,e[14]=(b*c-p*v-T*M)*y,e[15]=(u*v-f*c+g*M)*y,e):null}function An(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],a=s[1]*t+s[5]*i+s[9]*r+s[13],o=s[2]*t+s[6]*i+s[10]*r+s[14],l=s[3]*t+s[7]*i+s[11]*r+s[15],h=l!==0?1/l:1;e[0]=n*h,e[1]=a*h,e[2]=o*h}function jn(e,t,i,r,s,n,a,o,l,h,u,f,g,w,p,b,T=0){let x=h-a,M=u-o,c=f-l,m=g-a,v=w-o,S=p-l,D=s*S-n*v,I=n*m-r*S,P=r*v-s*m,N=x*D+M*I+c*P;if(N>-1e-7&&N<1e-7)return!1;let C=1/N,L=e-a,E=t-o,y=i-l,F=C*(L*D+E*I+y*P);if(F<-T||F>1+T)return!1;let z=E*c-y*M,A=y*x-L*c,_=L*M-E*x,d=C*(r*z+s*A+n*_);if(d<-T||F+d>1+T)return!1;let R=C*(m*z+v*A+S*_);if(R>1e-4&&R<b.distance){b.distance=R,b.point=[e+r*R,t+s*R,i+n*R];let G=M*S-c*v,H=c*m-x*S,B=x*v-M*m,Z=Math.hypot(G,H,B)||1;return b.normal=[G/Z,H/Z,B/Z],!0}return!1}function Kn(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let u=0;u<i;u++)r.push(he());if(i===0)return r;let s=new Set;for(let u of e.nodes)if(Array.isArray(u.children))for(let f of u.children)s.add(f);let n=new Set,a=128,o=(u,f,g=0)=>{if(g>a||u<0||u>=i||n.has(u))return;n.add(u);let w=e.nodes[u];if(!w)return;let p=he();if(t&&t[u])p.set(t[u]);else if(w.matrix&&w.matrix.length===16)p.set(w.matrix);else{let T=w.translation||[0,0,0],x=w.rotation||[0,0,0,1],M=w.scale||[1,1,1];Qe(p,x,T,M)}let b=r[u];if(f?be(b,f,p):b.set(p),Array.isArray(w.children))for(let T of w.children)typeof T=="number"&&o(T,b,g+1)},l=[],h=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(h&&Array.isArray(h.nodes))l.push(...h.nodes);else for(let u=0;u<i;u++)s.has(u)||l.push(u);for(let u of l)o(u,null);for(let u=0;u<i;u++)!s.has(u)&&!l.includes(u)&&o(u,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function En(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let a=i.componentType??5126,o=Wr[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,h=s.byteStride&&s.byteStride>0?s.byteStride:l,u=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(u)||u<0||h<l||u+(n-1)*h+l>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&h===l&&u%4===0)return new Float32Array(t,u,n*r);let f=new DataView(t),g=i.normalized===!0,w=new Float32Array(n*r);for(let p=0;p<n;p++){let b=u+p*h;for(let T=0;T<r;T++){let x=b+T*o,M;switch(a){case 5126:M=f.getFloat32(x,!0);break;case 5120:M=f.getInt8(x),g&&(M=Math.max(M/127,-1));break;case 5121:M=f.getUint8(x),g&&(M/=255);break;case 5122:M=f.getInt16(x,!0),g&&(M=Math.max(M/32767,-1));break;case 5123:M=f.getUint16(x,!0),g&&(M/=65535);break;default:M=f.getUint32(x,!0),g&&(M/=4294967295)}w[p*r+T]=M}}return w}function Yn(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),a=Number(t.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),h=(Number.isFinite(s)?s:1)*o,u=(Number.isFinite(s)?s:1)*l,f=-(Number.isFinite(n)?n:1)*l,g=(Number.isFinite(n)?n:1)*o;for(let w=0;w+1<e.length;w+=2){let p=e[w],b=e[w+1];e[w]=h*p+u*b+i,e[w+1]=f*p+g*b+r}}function Tt(e,t,i,r=!0){let s=[],n=null;try{for(let[a,o]of[[35633,t],[35632,i]]){let l=e.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(s.push(l),e.shaderSource(l,o),e.compileShader(l),e.getShaderParameter&&!e.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(l)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let a of s)e.attachShader(n,a);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let a=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${a}`);return null}return n}finally{for(let a of s)n&&e.detachShader?.(n,a),e.deleteShader?.(a)}}var Jn=["neutral","reinhard","none","aces","agx"];function Dn(e){let t=String(e??"").trim().toLowerCase();return Jn.includes(t)?t:"neutral"}function jr(e){return Jn.indexOf(Dn(e))}function Kr(e){return new TextDecoder().decode(e)}var Qn=le().decoders;function Yr(e,t){Qn.set(e.toLowerCase(),t)}function je(e){return Qn.get(e.toLowerCase())}function er(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let g=i.getUint8(0);throw g===123||g===32||g===10||g===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 s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=n&&a+8<=t.byteLength;){let g=i.getUint32(a,!0),w=i.getUint32(a+4,!0),p=a+8;if(p+g>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+g} bytes, buffer has ${t.byteLength}`);if(w===1313821514){let b=new Uint8Array(t,p,g),T=Kr(b);o=JSON.parse(T,(x,M)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:M)}else w===5130562&&(l=t.slice(p,p+g));a=p+g}if(!o)throw new Error("Missing JSON chunk in GLB");let h=o.extensionsRequired||[];if(h.includes("KHR_draco_mesh_compression")&&!je("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let g of["EXT_meshopt_compression","KHR_meshopt_compression"])if(h.includes(g)&&!je("meshopt"))throw new Error(`Model requires ${g}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(h.includes("KHR_texture_basisu")&&!je("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=l||new ArrayBuffer(0),f={gltf:o,bin:u,animations:[]};for(let g of pe)g.onParseGLB?.(f);return f}function qr(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function wt(e){if(qr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return er(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var tr=`#version 300 es
18
17
  layout(location=0) in vec3 aPos;
19
18
  layout(location=3) in vec3 aOff;
20
19
  layout(location=1) in vec3 aNormal;
@@ -49,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
49
48
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
50
49
  vUV=aUV*scaleUV+uUvTransform.xy;
51
50
  gl_Position=uMVP*vec4(aPosition,1.0);
52
- }`,or=`#version 300 es
51
+ }`,Zr=`#version 300 es
53
52
  precision highp float;
54
53
  in vec3 vNormal,vWorldPos;
55
54
  in vec2 vUV;
@@ -66,7 +65,8 @@ uniform float uNormalScale,uOcclusionStrength;
66
65
  uniform vec2 uViewportSize;
67
66
  uniform vec4 uSectionPlane;
68
67
  uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
69
- uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
68
+ uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
69
+ uniform vec2 uPointLightSpotCone[2];
70
70
  out vec4 fragColor;
71
71
 
72
72
  vec2 envBRDF(float r,float n){
@@ -157,6 +157,11 @@ if(mode==4)return agxToneMapping(color);
157
157
  return color;
158
158
  }
159
159
 
160
+ vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 base,float specExp,float specWeight){
161
+ float NoH=max(dot(N,normalize(L+V)),0.0);
162
+ return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
163
+ }
164
+
160
165
  void main(){
161
166
  if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
162
167
  vec4 base=uBaseColor;
@@ -194,24 +199,16 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
194
199
  vec3 directLight=vec3(0.0);
195
200
  for(int i=0;i<2;i++){
196
201
  if(i>=uNumDirLights)break;
197
- vec3 L=normalize(uDirLightDir[i]);
198
- float NdotL=max(dot(N,L),0.0);
199
- vec3 H=normalize(L+V);
200
- float NoH=max(dot(N,H),0.0);
201
- float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
202
- directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
202
+ directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i];
203
203
  }
204
204
  for(int i=0;i<2;i++){
205
205
  if(i>=uNumPointLights)break;
206
206
  vec3 toLight=uPointLightPos[i]-vWorldPos;
207
207
  float dist=length(toLight);
208
208
  vec3 L=toLight/max(dist,0.0001);
209
- float atten=1.0/(1.0+0.09*dist+0.032*dist*dist);
210
- float NdotL=max(dot(N,L),0.0);
211
- vec3 H=normalize(L+V);
212
- float NoH=max(dot(N,H),0.0);
213
- float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
214
- directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
209
+ float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
210
+ spotAtt*=spotAtt;
211
+ directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist);
215
212
  }
216
213
 
217
214
  vec3 R=reflect(-V,N);
@@ -242,86 +239,140 @@ color=applyToneMapping(color,uToneMapping);
242
239
  float outAlpha=base.a;
243
240
  /*XRD_O*/
244
241
  fragColor=vec4(color,outAlpha);
245
- }`;var ar=`#version 300 es
242
+ }`,Jr=`#version 300 es
246
243
  layout(location=0) in vec3 aPosition;
247
244
  uniform mat4 uMVP;
248
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,cr=`#version 300 es
245
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Qr=`#version 300 es
249
246
  precision highp float;
250
247
  uniform vec4 uColorId;
251
248
  out vec4 fragColor;
252
- void main(){fragColor=uColorId;}`;function jt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var fn=["uMVP","uModel","uInstanced","uViewProj","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","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function xn(){let n=Q().xrDepthShader;return{fs:or.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...fn,...n.uniformNames]:fn}}function ur(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 Wt(n,e,t,r,i,s,o,l){if(r===void 0||!e.accessors?.[r])return null;let a=Xt(e,t,e.accessors[r],s);if(!a)return null;l&&(a=a.slice(),hn(a,l));let u=n.createBuffer();return o.push(u),n.bindBuffer(34962,u),n.bufferData(34962,a,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),a}function $t(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function vn(n,e,t){let r=xn(),i=gn,s=r.fs,o=!1;for(let a of ie)if(a.onResolveShader){let u=a.onResolveShader(e,t,i,s);u&&(i=u.vs,s=u.fs,o=!0)}let l=o?ot(n,i,s):null;return{program:l,uniforms:l?jt(n,l,r.uniforms):null}}function lr(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,o=new Float32Array(i*20);for(let a=0;a<i;a++)o.set(r.subarray(a*16,a*16+16),a*20),o[a*20+16]=s?s[a*3]:1,o[a*20+17]=s?s[a*3+1]:1,o[a*20+18]=s?s[a*3+2]:1,o[a*20+19]=1;let l=n.createBuffer();t.push(l),n.bindBuffer(34962,l),n.bufferData(34962,o,35044);for(let a=0;a<5;a++)n.enableVertexAttribArray(8+a),n.vertexAttribPointer(8+a,4,5126,!1,80,a*16),n.vertexAttribDivisor(8+a,1);return!0}function mr(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Kr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Mn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function at(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function Tn(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function wn(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let o of s.primitives){if(o.vao&&n.deleteVertexArray(o.vao),o.buffers)for(let a of o.buffers)n.deleteBuffer(a);i(o.texture),i(o.metallicRoughnessTexture),i(o.normalTexture),i(o.occlusionTexture);let l=new Set;o.customProgram&&l.add(o.customProgram);for(let a of o.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)n.deleteProgram(a)}if(t)for(let s of t)i(s)}function dn(n,e,t=Mn,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return hr(n,e,t,r,i)}catch(s){let o=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;wn(n,o,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let l of i.buffers)n.deleteBuffer(l);throw s}}function hr(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,o=Le("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(s,e);let l=e.bin,a=[];i.meshes=a;let u=[],c=s.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((y,A)=>{u.push(typeof y?.name=="string"&&y.name?y.name:`Variant_${A}`)});let h=st(s),m=[];if(Array.isArray(s.nodes))for(let y=0;y<s.nodes.length;y++){let A=s.nodes[y];A.mesh!==void 0&&s.meshes&&s.meshes[A.mesh]&&m.push({node:A,nodeIdx:y,meshIdx:A.mesh})}let b=m.length>0?m:(s.meshes||[]).map((y,A)=>({node:y,nodeIdx:-1,meshIdx:A})),g=[];if(Array.isArray(e.lights)&&e.lights.length>0)g.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let y=s.extensions.KHR_lights_punctual.lights;for(let A of y){let T=A.type==="directional"?"directional":A.type==="point"?"point":"ambient";g.push({type:T,color:A.color||[1,1,1],intensity:A.intensity!==void 0?A.intensity:1})}}if(g.length===0&&(g.push({type:"ambient",color:[1,1,1],intensity:.35}),g.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),b.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${b.length}`);let d=[];if(i.gpuTextures=d,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let y=0;y<s.textures.length;y++){let A=s.textures[y],T=s.images[A.source];if(T){let R=n.createTexture();if(n.bindTexture(3553,R),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),T.bufferView!==void 0){let F=s.bufferViews[T.bufferView],P=l.slice(F.byteOffset||0,(F.byteOffset||0)+F.byteLength),B=new Blob([P],{type:T.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(B).then(k=>{n.bindTexture(3553,R),n.texImage2D(3553,0,6408,6408,5121,k),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(T.uri){let F=ur(T.uri);if(F){let P=new Image;P.crossOrigin="anonymous",P.referrerPolicy="no-referrer",P.onload=()=>{n.bindTexture(3553,R),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()},P.src=F}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",T.uri)}d.push(R)}else d.push(null)}}let w=[1/0,1/0,1/0],C=[-1/0,-1/0,-1/0],N=0,f=0;for(let y=0;y<b.length;y++){let A=b[y],T=s.meshes[A.meshIdx],R=A.nodeIdx>=0?h[A.nodeIdx]:J(),F=new Float32Array(9);me(F,R);let P={name:A.node.name||T.name||`Mesh_${A.meshIdx}`,nodeIndex:A.nodeIdx,transform:R,normalMatrix:F,primitives:[],extras:A.node.extras||T.extras};i.mesh=P;let B=A.node?.extensions?.EXT_mesh_gpu_instancing;if(B&&B.attributes&&typeof B.attributes=="object"){let k=B.attributes,O=k.TRANSLATION!==void 0?s.accessors?.[k.TRANSLATION]:null,S=k.ROTATION!==void 0?s.accessors?.[k.ROTATION]:null,G=k.SCALE!==void 0?s.accessors?.[k.SCALE]:null,z=k._COLOR_0!==void 0?s.accessors?.[k._COLOR_0]:null,U=Number(O?.count??S?.count??G?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let H=($,q)=>{if(!$||$.bufferView===void 0||!s.bufferViews?.[$.bufferView])return null;let se=$.componentType??5126,ce=ne=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${ne})`),null);if(se!==5120&&se!==5121&&se!==5122&&se!==5123&&se!==5126)return ce(`componentType ${se}`);if(!(Number($.count)>=U))return ce(`count ${$.count} < ${U}`);let K=null;try{K=Xt(s,l,{...$,count:U},q)}catch{return ce("out of bounds")}return!K||!K.every(Number.isFinite)?ce("non-finite value"):K},L=H(O,3),V=H(S,4),X=H(G,3),W=z?.type==="VEC4"?4:3,Y=H(z,W),re=new Float32Array(U*16),ae=J();for(let $=0;$<U;$++){let q=L?[L[$*3],L[$*3+1],L[$*3+2]]:[0,0,0],se=V?[V[$*4],V[$*4+1],V[$*4+2],V[$*4+3]]:[0,0,0,1],ce=X?[X[$*3],X[$*3+1],X[$*3+2]]:[1,1,1];we(ae,se,q,ce),re.set(ae,$*16)}if(P.instanceMatrices=re,Y){let $=new Float32Array(U*3);for(let q=0;q<U;q++)$[q*3]=Y[q*W],$[q*3+1]=Y[q*W+1],$[q*3+2]=Y[q*W+2];P.instanceColors=$}}}for(let k of T.primitives||[]){if(k.extensions?.KHR_draco_mesh_compression){let K=Le("draco");K&&K.decodePrimitive(s,k,l)}let O=[],S=n.createVertexArray();i.vao=S,i.buffers=O,n.bindVertexArray(S);let G=lr(n,P,O),z=s.accessors[k.attributes.POSITION],U=Number(z?.count??0);if(!Number.isFinite(U)||U<0||N+U>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(N+=U,z?.min&&z?.max){let K=ne=>{for(let Z=0;Z<3;Z++){let oe=ne[12+Z],ge=ne[12+Z];for(let Ie=0;Ie<3;Ie++){let tt=ne[Ie*4+Z]*z.min[Ie],nt=ne[Ie*4+Z]*z.max[Ie];oe+=tt<nt?tt:nt,ge+=tt>nt?tt:nt}oe<w[Z]&&(w[Z]=oe),ge>C[Z]&&(C[Z]=ge)}};if(P.instanceMatrices&&P.instanceMatrices.length>=16){let ne=P.instanceMatrices.length>>4,Z=J();for(let oe=0;oe<ne;oe++){let ge=P.instanceMatrices.subarray(oe*16,oe*16+16);ee(Z,R,ge),K(Z)}}else K(R)}let H=Wt(n,s,l,k.attributes.POSITION,0,3,O);Wt(n,s,l,k.attributes.NORMAL,1,3,O),Wt(n,s,l,k.attributes.TEXCOORD_0,2,2,O,mr(s,k));let L=0,V=5123,X=null;if(k.indices!==void 0){let K=s.accessors[k.indices],Z=(s.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(L=Number(K.count??0),!Number.isFinite(L)||L<0||f+L>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);f+=L,V=K.componentType===5125?5125||5125:5123||5123;let oe=n.createBuffer();O.push(oe),n.bindBuffer(34963,oe),K.componentType===5125?(X=new Uint32Array(l,Z,K.count),n.bufferData(34963,X,35044)):K.componentType===5121?(X=Uint16Array.from(new Uint8Array(l,Z,K.count)),n.bufferData(34963,X,35044)):(X=Z%2===0?new Uint16Array(l,Z,K.count):new Uint16Array(l.slice(Z,Z+K.count*2)),n.bufferData(34963,X,35044))}else L=z.count;let W={};for(let K of ie)if(K.onBuildPrimitiveVAO){let ne=K.onBuildPrimitiveVAO(n,S,k,s,l);ne&&(W[K.name]=ne)}n.bindVertexArray(null);let Y=s.materials&&k.material!==void 0?s.materials[k.material]:null,{program:re,uniforms:ae}=vn(n,k,Y),$=Tn(Y,d),q=!!(Y?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),se=k.extensions?.KHR_materials_variants?.mappings,ce=Array.isArray(se)?se.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(ne=>Number(ne)|0)})):void 0;P.primitives.push({vao:S,instanced:G,indexCount:L,indexType:V,...$,positions:H,indices:X,buffers:O,materialIndex:k.material,defaultMaterialIndex:k.material,variantMappings:ce,primitiveDef:k,programCache:new Map([[k.material??-1,{program:re,uniforms:ae}]]),pluginData:W,customProgram:re,customUniforms:ae,isTransmissive:q})}a.push(P)}isFinite(w[0])||(w=[-1,-1,-1]),isFinite(C[0])||(C=[1,1,1]);let E=[(w[0]+C[0])/2,(w[1]+C[1])/2,(w[2]+C[2])/2],x=C[0]-w[0],_=C[1]-w[1],D=C[2]-w[2],v=Math.max(Math.hypot(x,_,D)/2,.5),M=[w[0],w[1],w[2]],I=[C[0],C[1],C[2]],p=e.animations;if(!p){for(let y of ie)if(y.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:a,bounds:{center:E,radius:v,min:M,max:I},lights:g,animations:p,worldMatrices:h,gpuTextures:d,availableVariants:u}}function ke(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var ct=class{constructor(e,t,r){this.supportsInstanceOffsets=!0;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.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.activeViewMatrix=null;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.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;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 a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(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.exposure=$t(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=Yt(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){ir(e,t)}static getDecoder(e){return Le(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=xn();this.renderProg=ot(e,gn,t.fs),this.pickProg=ot(e,ar,cr),this.uRender=jt(e,this.renderProg,t.uniforms),this.uPick=jt(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ie)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}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){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:o,worldMatrices:l,gpuTextures:a,availableVariants:u}=dn(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=o||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=u||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of ie)m.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 c=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;c!==void 0&&(this.exposure=$t(c));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||0)),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(yn(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Ue(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ue(e),{meshes:i}=dn(this.gl,r,Mn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],me(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),me(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],o=[],l=[];for(let a of this.lights){let u=a.color||[1,1,1],c=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[u[0]*c,u[1]*c,u[2]*c];else if(a.type==="directional"&&i.length<6){let h=a.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(u[0]*c,u[1]*c,u[2]*c)}else if(a.type==="point"&&o.length<6){let h=a.position||[0,0,0];o.push(h[0],h[1],h[2]),l.push(u[0]*c,u[1]*c,u[2]*c)}}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,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=$t(e)}getExposure(){return this.exposure}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=Yt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ie)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ie)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(c=>c.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],o=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:o,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:c=>{let h=[c[0],c[1],c[2],c[3]??1];u.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let m of i)m.baseColor=h;this.render()},setMetallicFactor:c=>{u.metallicFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=c);for(let h of i)h.metallic=c;this.render()},setRoughnessFactor:c=>{u.roughnessFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=c);for(let h of i)h.roughness=c;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:u}})}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)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let s of this.meshes)for(let o of s.primitives){let l=o.defaultMaterialIndex;if(!t&&Array.isArray(o.variantMappings)){for(let u of o.variantMappings)if(Array.isArray(u.variants)&&u.variants.includes(r)){l=u.material;break}}let a=l!==void 0?i[l]:void 0;o.materialIndex=a?l:void 0,Object.assign(o,Tn(a,this.gpuTextures)),this.applyPrimitiveProgram(o,o.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=vn(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of ie)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();ee(r,this.projMatrix,this.viewMatrix);let[i,s,o]=e,l=t?t[0]:0,a=t?t[1]:0,u=t?t[2]:0,c=this.modelRootMatrix;c&&(i=c[0]*e[0]+c[4]*e[1]+c[8]*e[2]+c[12],s=c[1]*e[0]+c[5]*e[1]+c[9]*e[2]+c[13],o=c[2]*e[0]+c[6]*e[1]+c[10]*e[2]+c[14],t&&(l=c[0]*t[0]+c[4]*t[1]+c[8]*t[2],a=c[1]*t[0]+c[5]*t[1]+c[9]*t[2],u=c[2]*t[0]+c[6]*t[1]+c[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*o+r[12],m=r[1]*i+r[5]*s+r[9]*o+r[13],b=r[2]*i+r[6]*s+r[10]*o+r[14],g=r[3]*i+r[7]*s+r[11]*o+r[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let d=h/g,w=m/g,C=b/g,N=this.canvas.getBoundingClientRect(),f=N.width||this.canvas.clientWidth||this.canvas.width||300,E=N.height||this.canvas.clientHeight||this.canvas.height||150,x=(d*.5+.5)*f,_=(-w*.5+.5)*E,D=d>=-1.1&&d<=1.1&&w>=-1.1&&w<=1.1&&C>=-1&&C<=1;if(D&&t){let[v,M,I]=ke(this),p=[i-v,s-M,o-I];l*p[0]+a*p[1]+u*p[2]>.05&&(D=!1)}return{x,y:_,z:C,visible:D}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}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 o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*o[0]+s*l[0])*u,a[1]+=(-i*o[1]+s*l[1])*u,a[2]+=(-i*o[2]+s*l[2])*u,this.customTarget=a}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.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),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,o=r.height||300,l=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),a=i.height>0?Math.floor((t-i.top)*(o/i.height)):Math.floor(t);return this.performMeshPick(l,a,!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),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let l=J();ee(l,this.projMatrix,this.viewMatrix);let a=[],u=Math.max(0,Math.min(s-1,e)),c=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==o)&&this.resizePickingFbo(s,o),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,o),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 v=this.meshes[D];if(v.visible===!1||v.isPluginMesh)continue;let M=D+1,I=(M&255)/255,p=(M>>8&255)/255,y=(M>>16&255)/255;i.uniform4f(this.uPick.uColorId,I,p,y,1),ee(this.modelMatrix,this.modelRootMatrix,v.transform);let A=v.instanceMatrices;if(A&&A.length>=16){let T=A.length>>4,R=J();for(let F of v.primitives){i.bindVertexArray(F.vao);for(let P=0;P<T;P++)ee(R,this.modelMatrix,A.subarray(P*16,P*16+16)),ee(this.mvpMatrix,l,R),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),at(i,F)}}else{ee(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let T of v.primitives)i.bindVertexArray(T.vao),at(i,T)}}let x=new Uint8Array(4);i.readPixels(u,c,1,1,6408,5121,x),i.bindFramebuffer(36160,null);let _=x[0]+(x[1]<<8)+(x[2]<<16);_>0&&_<=this.meshes.length&&(a=[this.meshes[_-1]])}a.length===0&&(a=this.meshes.filter(x=>x.visible!==!1));let h=null,m=1/0,b=[0,0,0],g=[0,1,0],[d,w,C]=ke(this),N=J();for(let x of a){ee(N,this.modelRootMatrix,x.transform);let _=x.instanceMatrices,D=_&&_.length>=16?_.length>>4:1;for(let v=0;v<D;v++){_&&_.length>=16?ee(this.modelMatrix,N,_.subarray(v*16,v*16+16)):this.modelMatrix.set(N),ee(this.mvpMatrix,l,this.modelMatrix);let M=J();if(!ln(M,this.mvpMatrix))continue;let I=(u+.5)/s*2-1,p=(c+.5)/o*2-1,y=[0,0,0],A=[0,0,0];Ht(y,I,p,-1,M),Ht(A,I,p,1,M);let T=A[0]-y[0],R=A[1]-y[1],F=A[2]-y[2],P=Math.hypot(T,R,F)||1,B=T/P,k=R/P,O=F/P,S={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((z=>{for(let U of x.primitives){if(!U.positions)continue;let H=U.positions,L=U.indices,V=Math.floor(L?L.length/3:H.length/9);for(let X=0;X<V;X++){let W=L?L[X*3]:X*3,Y=L?L[X*3+1]:X*3+1,re=L?L[X*3+2]:X*3+2;mn(y[0],y[1],y[2],B,k,O,H[W*3],H[W*3+1],H[W*3+2],H[Y*3],H[Y*3+1],H[Y*3+2],H[re*3],H[re*3+1],H[re*3+2],S,z)}}})(1e-4),isFinite(S.distance)){let z=S.point[0],U=S.point[1],H=S.point[2],L=this.modelMatrix,V=L[0]*z+L[4]*U+L[8]*H+L[12],X=L[1]*z+L[5]*U+L[9]*H+L[13],W=L[2]*z+L[6]*U+L[10]*H+L[14],Y=V-d,re=X-w,ae=W-C,$=Math.hypot(Y,re,ae);if($<m){me(this.normalMatrix,this.modelMatrix);let q=this.normalMatrix,se=S.normal[0],ce=S.normal[1],K=S.normal[2],ne=q[0]*se+q[3]*ce+q[6]*K,Z=q[1]*se+q[4]*ce+q[7]*K,oe=q[2]*se+q[5]*ce+q[8]*K,ge=Math.hypot(ne,Z,oe)||1;ne/=ge,Z/=ge,oe/=ge,ne*Y+Z*re+oe*ae>0&&(ne=-ne,Z=-Z,oe=-oe),h=x,m=Math.round($*1e3)/1e3,b=[Math.round(V*1e3)/1e3,Math.round(X*1e3)/1e3,Math.round(W*1e3)/1e3],g=[Math.round(ne*1e3)/1e3,Math.round(Z*1e3)/1e3,Math.round(oe*1e3)/1e3]}}}}if(!h)return null;let E={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:m,hitPoint:b,normal:g,screenX:e,screenY:t};if(r){for(let x of ie)x.onMeshSelect?.(this,E);this.opts.onMeshClick&&this.opts.onMeshClick(E),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:E}))}return E}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,o=i?Math.max(1,t-r):r,l=(s+.5)/o*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);it(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;De(this.viewMatrix,ke(this),r,[0,1,0]),ee(this.mvpMatrix,this.projMatrix,this.viewMatrix),me(this.normalMatrix,this.modelMatrix)}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),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of ie)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of ie)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),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 o of ie)o.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 o of ie)o.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let o={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,r,i,s=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,c=u?[u.x,u.y,u.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:a,eyePos:c,viewport:i,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let f=Math.max(2,this.canvas.width||2),E=Math.max(1,this.canvas.height||1),x=Math.max(1,Math.floor(f*.5)),_=Math.max(1,f-x),D=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,[M,I,p]=ke(this),y=Math.cos(this.currTheta),A=-Math.sin(this.currTheta),T=.032,R=J(),F=J(),P=[M-y*T,I,p-A*T],B=[v[0]-y*T*.25,v[1],v[2]-A*T*.25];it(R,this.fov,x/E,.1,D),De(F,P,B,[0,1,0]);let k=J(),O=J(),S=[M+y*T,I,p+A*T],G=[v[0]+y*T*.25,v[1],v[2]+A*T*.25];it(k,this.fov,_/E,.1,D),De(O,S,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:R,eyePos:P,viewport:[0,0,x,E],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:O,projMatrix:k,eyePos:S,viewport:[x,0,_,E],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,f,E);return}let t=this.gl,r=0,i=0,s=this.canvas.width,o=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],o=e.viewport[3],t.viewport(r,i,s,o)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let l=J(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,ee(l,e?.projMatrix??this.projMatrix,a);let u=Q().xrDepthShader,c=nr(this.toneMapping),[h,m,b]=e?e.eyePos:ke(this);for(let f of ie)f.onBeforeDrawScene?.(this,t,l,[h,m,b],c);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let d=e?.eye||"none",w=!1,C=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,N=f=>{for(let E=0;E<C.length;E++){let x=C[E];if(x.visible===!1)continue;let _=this.selectedMeshName!==""&&x.name===this.selectedMeshName;E<g||x.worldSpace===!0||x.name==="__xr_reticle__"?this.modelMatrix.set(x.transform):ee(this.modelMatrix,this.modelRootMatrix,x.transform),ee(this.mvpMatrix,l,this.modelMatrix),me(x.normalMatrix,this.modelMatrix);let D=x.extras?.xr?.stereo||x.userData?.xr?.stereo,v=0,M=0,I=1,p=1;D==="sbs"?(I=.5,v=d==="right"?.5:0):D==="ou"&&(p=.5,M=d==="right"?.5:0);for(let y of x.primitives){let A=!!y.isTransmissive;if(!f&&A){w=!0;continue}if(f&&!A)continue;let T=y.customProgram||this.renderProg,R=y.customUniforms||this.uRender;t.useProgram(T),t.vertexAttrib3f(3,0,0,0),R.uInstanced&&t.uniform1i(R.uInstanced,0),t.uniform1i(R.uToneMapping,c),t.uniform1f(R.uEnvIntensity,this.envIntensity),R.uExposure&&t.uniform1f(R.uExposure,this.exposure),t.uniform3f(R.uCameraPos,h,m,b),t.uniform1f(R.uEmissive,_?1:0),t.uniformMatrix4fv(R.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(R.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(R.uNormalMatrix,!1,x.normalMatrix),R.uUvTransform&&t.uniform4f(R.uUvTransform,v,M,I,p),R.uViewportSize&&t.uniform2f(R.uViewportSize,Math.max(1,s),Math.max(1,o)),u?.bind(t,R,this.xrDepthState,a,[r,i,Math.max(1,s),Math.max(1,o)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(R.uEnvironmentMap,4),t.uniform1i(R.uHasEnvironmentMap,1)):t.uniform1i(R.uHasEnvironmentMap,0),this.bindLights(R),R.uSectionEnabled&&t.uniform1i(R.uSectionEnabled,0);for(let P of ie)P.onBeforeDrawPrimitive?.(t,T,y,x,this.worldMatrices||[],this.gltf);t.uniform4fv(R.uBaseColor,y.baseColor),t.uniform1f(R.uMetallic,y.metallic),t.uniform1f(R.uRoughness,y.roughness),R.uClearcoat&&t.uniform2f(R.uClearcoat,y.clearcoat??0,y.clearcoatRoughness??.04),y.texture?(t.activeTexture(33984),t.bindTexture(3553,y.texture),t.uniform1i(R.uBaseColorTexture,0),t.uniform1i(R.uHasTexture,1)):t.uniform1i(R.uHasTexture,0),y.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,y.metallicRoughnessTexture),t.uniform1i(R.uMetallicRoughnessTexture,1),t.uniform1i(R.uHasMetallicRoughnessTexture,1)):t.uniform1i(R.uHasMetallicRoughnessTexture,0),y.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,y.normalTexture),t.uniform1i(R.uNormalTexture,2),t.uniform1i(R.uHasNormalTexture,1),t.uniform1f(R.uNormalScale,y.normalScale)):t.uniform1i(R.uHasNormalTexture,0),y.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,y.occlusionTexture),t.uniform1i(R.uOcclusionTexture,3),t.uniform1i(R.uHasOcclusionTexture,1),t.uniform1f(R.uOcclusionStrength,y.occlusionStrength)):t.uniform1i(R.uHasOcclusionTexture,0),t.bindVertexArray(y.vao);let F=x.instanceMatrices;if(y.instanceCount!==void 0)t.drawElementsInstanced(4,y.indexCount,y.indexType,0,y.instanceCount);else if(F&&F.length>=16&&y.instanced&&R.uInstanced&&R.uViewProj){let P=F.length>>4;t.uniform1i(R.uInstanced,1),t.uniformMatrix4fv(R.uViewProj,!1,l),y.indices?t.drawElementsInstanced(4,y.indexCount,y.indexType,0,P):t.drawArraysInstanced(4,0,y.indexCount,P),t.uniform1i(R.uInstanced,0)}else if(F&&F.length>=16){let P=F.length>>4,B=x.instanceColors,k=J(),O=new Float32Array(9),S=[y.baseColor[0],y.baseColor[1],y.baseColor[2],y.baseColor[3]];for(let G=0;G<P;G++)ee(k,this.modelMatrix,F.subarray(G*16,G*16+16)),ee(this.mvpMatrix,l,k),me(O,k),t.uniformMatrix4fv(R.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(R.uModel,!1,k),t.uniformMatrix3fv(R.uNormalMatrix,!1,O),B&&(S[0]=y.baseColor[0]*B[G*3],S[1]=y.baseColor[1]*B[G*3+1],S[2]=y.baseColor[2]*B[G*3+2],S[3]=y.baseColor[3],t.uniform4fv(R.uBaseColor,S)),at(t,y)}else at(t,y)}}};if(N(!1),w){for(let f of ie)f.onBeforeTransmissivePass?.(t,this);N(!0)}for(let f of ie)f.onAfterRender?.(t,this,l,e?.eye??"none",[r,i,s,o],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){wn(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of ie)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()}};ct.registerPlugin=cn,ct.getRegisteredPlugins=un;function fr(n){return n+3&-4}function dr(n,e=0){let t=(S,G)=>typeof S=="number"&&Number.isFinite(S)?S:G,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),o=t(n[e+0],1),l=t(n[e+1],0),a=t(n[e+2],0),u=t(n[e+4],0),c=t(n[e+5],1),h=t(n[e+6],0),m=t(n[e+8],0),b=t(n[e+9],0),g=t(n[e+10],1),d=Math.hypot(o,l,a),w=Math.hypot(u,c,h),C=Math.hypot(m,b,g);o*(c*g-b*h)-u*(l*g-b*a)+m*(l*h-c*a)<0&&(d=-d);let f=Math.abs(d)>1e-8?1/d:0,E=Math.abs(w)>1e-8?1/w:0,x=Math.abs(C)>1e-8?1/C:0,_=o*f,D=l*f,v=a*f,M=u*E,I=c*E,p=h*E,y=m*x,A=b*x,T=g*x,R=_+I+T,F=0,P=0,B=0,k=1;if(R>0){let S=.5/Math.sqrt(R+1);k=.25/S,F=(p-A)*S,P=(y-v)*S,B=(D-M)*S}else if(_>I&&_>T){let S=2*Math.sqrt(Math.max(0,1+_-I-T));S>1e-8&&(k=(p-A)/S,F=.25*S,P=(M+D)/S,B=(y+v)/S)}else if(I>T){let S=2*Math.sqrt(Math.max(0,1+I-_-T));S>1e-8&&(k=(y-v)/S,F=(M+D)/S,P=.25*S,B=(p+A)/S)}else{let S=2*Math.sqrt(Math.max(0,1+T-_-I));S>1e-8&&(k=(D-M)/S,F=(y+v)/S,P=(p+A)/S,B=.25*S)}let O=Math.hypot(F,P,B,k);return O>1e-8&&Number.isFinite(O)?(F/=O,P/=O,B/=O,k/=O):(F=0,P=0,B=0,k=1),{t:[r,i,s],r:[F,P,B,k],s:[d,w,C]}}function pr(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 Ne(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],o=[],l=[],a=new Set,u=[],c=[],h=new Map,m=[],b=[];function g(M){let I=h.get(M);if(I!==void 0)return I;I=c.length,h.set(M,I);let p=M,y=p.color?.r??.8,A=p.color?.g??.8,T=p.color?.b??.8,R=p.opacity??1,F={name:p.name||"",pbrMetallicRoughness:{baseColorFactor:[y,A,T,R],metallicFactor:p.metalness??.1,roughnessFactor:p.roughness??.5},doubleSided:p.side===2||!!p.doubleSided};if(p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let B=p.emissiveIntensity??1;F.emissiveFactor=[p.emissive.r*B,p.emissive.g*B,p.emissive.b*B]}let P={};return p.clearcoat&&p.clearcoat>0&&(P.KHR_materials_clearcoat={clearcoatFactor:p.clearcoat,clearcoatRoughnessFactor:p.clearcoatRoughness||0}),p.sheen&&p.sheen>0&&(P.KHR_materials_sheen={sheenColorFactor:p.sheenColor?[p.sheenColor.r,p.sheenColor.g,p.sheenColor.b]:[1,1,1],sheenRoughnessFactor:p.sheenRoughness||0}),p.transmission&&p.transmission>0&&(P.KHR_materials_transmission={transmissionFactor:p.transmission}),p.thickness&&p.thickness>0&&(P.KHR_materials_volume={thicknessFactor:p.thickness,attenuationDistance:p.attenuationDistance??1/0,attenuationColor:p.attenuationColor?[p.attenuationColor.r,p.attenuationColor.g,p.attenuationColor.b]:[1,1,1]}),p.ior!==void 0&&p.ior!==1.5&&(P.KHR_materials_ior={ior:p.ior}),p.dispersion&&p.dispersion>0&&(P.KHR_materials_dispersion={dispersion:p.dispersion}),p.iridescence&&p.iridescence>0&&(P.KHR_materials_iridescence={iridescenceFactor:p.iridescence,iridescenceIor:p.iridescenceIOR??1.3}),Object.keys(P).length>0&&(F.extensions=P),c.push(F),I}function d(M,I){let p=new Uint8Array(M.buffer,M.byteOffset,M.byteLength),y=fr(p.byteLength),A=new Uint8Array(y);A.set(p),t.push(A);let T=i.length;return i.push({buffer:0,byteOffset:r,byteLength:p.byteLength,target:I}),r+=y,T}function w(M,I,p,y,A,T,R){let F=d(M,p),P=s.length,B={bufferView:F,byteOffset:0,componentType:y,count:A,type:I};return T&&(B.min=T),R&&(B.max=R),s.push(B),P}n.traverse(M=>{(M.isLight||M.color&&M.intensity!==void 0)&&b.push({type:M.type,color:[M.color.r,M.color.g,M.color.b],intensity:M.intensity,position:[M.position.x,M.position.y,M.position.z]})});let C=[];function N(M){let I={name:M.name||""},p=M.position,y=M.quaternion,A=M.scale;if((p.x||p.y||p.z)&&(I.translation=[p.x,p.y,p.z]),(y.x||y.y||y.z||y.w!==1)&&(I.rotation=[y.x,y.y,y.z,y.w]),(A.x!==1||A.y!==1||A.z!==1)&&(I.scale=[A.x,A.y,A.z]),M.userData&&Object.keys(M.userData).length>0&&(I.extras=JSON.parse(JSON.stringify(M.userData,(R,F)=>{if(!(R==="__proto__"||R==="prototype"||R==="constructor"))return typeof F=="function"?void 0:F})),M.userData.xr)){let R=pr(M.userData.xr);I.extensions={...I.extensions||{},MOZ_hubs_components:R,ANDROID_xr_scenecore:R},Q().xrTraitSerializer?.gltfNode(I,M.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(M.geometry){let R=M.geometry,F=R.attributes.position;if(F&&F.count>0){let P=[1/0,1/0,1/0],B=[-1/0,-1/0,-1/0];for(let U=0;U<F.count;U++){let H=F.getX(U),L=F.getY(U),V=F.getZ(U);H<P[0]&&(P[0]=H),H>B[0]&&(B[0]=H),L<P[1]&&(P[1]=L),L>B[1]&&(B[1]=L),V<P[2]&&(P[2]=V),V>B[2]&&(B[2]=V)}let O={attributes:{POSITION:w(F.array,"VEC3",34962,5126,F.count,P,B)}};if(R.attributes.normal&&(O.attributes.NORMAL=w(R.attributes.normal.array,"VEC3",34962,5126,R.attributes.normal.count)),R.attributes.uv&&(O.attributes.TEXCOORD_0=w(R.attributes.uv.array,"VEC2",34962,5126,R.attributes.uv.count)),R.index){let U=R.index.array instanceof Uint32Array;O.indices=w(R.index.array,"SCALAR",34963,U?5125:5123,R.index.count)}M.material&&(O.material=g(M.material));let S=M.userData?.variants;if(S&&typeof S=="object"){let U=new Map;for(let H of Object.keys(S)){if(!H||H==="__proto__"||H==="constructor"||H==="prototype")continue;let L=S[H];if(!L||typeof L!="object")continue;let V=m.indexOf(H);if(V===-1&&m.length<256&&(V=m.length,m.push(H)),V===-1)continue;let X=g(L),W=U.get(X);W||(W=[],U.set(X,W)),W.push(V)}if(U.size>0){let H=[];for(let[L,V]of U.entries())H.push({material:L,variants:V});O.extensions={...O.extensions||{},KHR_materials_variants:{mappings:H}},a.add("KHR_materials_variants")}}let G=M;if(G.isInstancedMesh&&typeof G.count=="number"&&G.count>0&&G.instanceMatrix?.array){let U=Math.min(1e4,Math.floor(G.count)),H=G.instanceMatrix.array,L=new Float32Array(U*3),V=new Float32Array(U*4),X=new Float32Array(U*3);for(let Y=0;Y<U;Y++){let{t:re,r:ae,s:$}=dr(H,Y*16);L[Y*3]=re[0],L[Y*3+1]=re[1],L[Y*3+2]=re[2],V[Y*4]=ae[0],V[Y*4+1]=ae[1],V[Y*4+2]=ae[2],V[Y*4+3]=ae[3],X[Y*3]=$[0],X[Y*3+1]=$[1],X[Y*3+2]=$[2]}let W={TRANSLATION:w(L,"VEC3",0,5126,U),ROTATION:w(V,"VEC4",0,5126,U),SCALE:w(X,"VEC3",0,5126,U)};if(G.instanceColor?.array&&G.instanceColor.array.length>=U*3){let Y=new Float32Array(G.instanceColor.array.subarray(0,U*3));W._COLOR_0=w(Y,"VEC3",0,5126,U)}I.extensions={...I.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},a.add("EXT_mesh_gpu_instancing")}let z=o.length;o.push({primitives:[O],name:M.name,...I.extras?{extras:I.extras}:{}}),I.mesh=z}}let T=l.length;if(l.push(I),u.push(M),M.children.length>0){I.children=[];for(let R of M.children)I.children.push(N(R))}return T}for(let M of n.children)C.push(N(M));let f=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),E=[];if(typeof f=="function"&&u.length>0){let M=e?.duration??4,I=e?.fps??15,p=Math.max(2,Math.round(M*I)+1),y=new Float32Array(p),A=u.map(S=>({px:S.position.x,py:S.position.y,pz:S.position.z,qx:S.quaternion.x,qy:S.quaternion.y,qz:S.quaternion.z,qw:S.quaternion.w,sx:S.scale.x,sy:S.scale.y,sz:S.scale.z})),T=u.map(()=>new Float32Array(p*3)),R=u.map(()=>new Float32Array(p*4)),F=u.map(()=>new Float32Array(p*3));for(let S=0;S<p;S++){let G=S/(p-1)*M;y[S]=G;try{f(G)}catch{}for(let z=0;z<u.length;z++){let U=u[z];T[z][S*3]=U.position.x,T[z][S*3+1]=U.position.y,T[z][S*3+2]=U.position.z,R[z][S*4]=U.quaternion.x,R[z][S*4+1]=U.quaternion.y,R[z][S*4+2]=U.quaternion.z,R[z][S*4+3]=U.quaternion.w,F[z][S*3]=U.scale.x,F[z][S*3+1]=U.scale.y,F[z][S*3+2]=U.scale.z}}for(let S=0;S<u.length;S++){let G=u[S],z=A[S];G.position.set(z.px,z.py,z.pz),G.quaternion.set(z.qx,z.qy,z.qz,z.qw),G.scale.set(z.sx,z.sy,z.sz)}n.updateMatrixWorld(!0);let P=null,B=()=>(P===null&&(P=w(y,"SCALAR",0,5126,p,[0],[M])),P),k=[],O=[];for(let S=0;S<u.length;S++){let G=A[S],z=!1,U=!1,H=!1;for(let L=0;L<p;L++)(Math.abs(T[S][L*3]-G.px)>1e-4||Math.abs(T[S][L*3+1]-G.py)>1e-4||Math.abs(T[S][L*3+2]-G.pz)>1e-4)&&(z=!0),(Math.abs(R[S][L*4]-G.qx)>1e-4||Math.abs(R[S][L*4+1]-G.qy)>1e-4||Math.abs(R[S][L*4+2]-G.qz)>1e-4||Math.abs(R[S][L*4+3]-G.qw)>1e-4)&&(U=!0),(Math.abs(F[S][L*3]-G.sx)>1e-4||Math.abs(F[S][L*3+1]-G.sy)>1e-4||Math.abs(F[S][L*3+2]-G.sz)>1e-4)&&(H=!0);if(z){let L=w(T[S],"VEC3",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"translation"}})}if(U){let L=w(R[S],"VEC4",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"rotation"}})}if(H){let L=w(F[S],"VEC3",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"scale"}})}}O.length>0&&E.push({name:"ProceduralLoop",samplers:k,channels:O})}let x=sn(l,o,n.userData),_={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:C}],scene:0,nodes:l,meshes:o,materials:c,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...x||a.size>0?{extensionsUsed:[...x?["KHR_interactivity"]:[],...a]}:{},...x||m.length>0?{extensions:{...x?{KHR_interactivity:x}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(M=>({name:M}))}}:{}}}:{}},D=new Uint8Array(r),v=0;for(let M of t)D.set(M,v),v+=M.byteLength;return{gltf:_,bin:D.buffer,lights:b,environmentIntensity:n.environmentIntensity}}function lt(n){return new TextEncoder().encode(n)}function Oe(n,e){let{gltf:t,bin:r}=Ne(n,e),i=JSON.stringify(t),s=lt(i),o=(4-s.byteLength%4)%4,l=s.byteLength+o,a=20+l+8+r.byteLength,u=new Uint8Array(a),c=new DataView(u.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,a,!0),c.setUint32(12,l,!0),c.setUint32(16,1313821514,!0),u.set(s,20);for(let m=0;m<o;m++)u[20+s.byteLength+m]=32;let h=20+l;return c.setUint32(h,r.byteLength,!0),c.setUint32(h+4,5130562,!0),u.set(new Uint8Array(r),h+8),u}function br(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 o=s.count,l=new Float32Array(o*3),a=r.matrixWorld.elements;for(let v=0;v<o;v++){let M=s.getX(v),I=s.getY(v),p=s.getZ(v);l[v*3]=a[0]*M+a[4]*I+a[8]*p+a[12],l[v*3+1]=a[1]*M+a[5]*I+a[9]*p+a[13],l[v*3+2]=a[2]*M+a[6]*I+a[10]*p+a[14]}let u;if(i.attributes.normal){let v=i.attributes.normal;u=new Float32Array(o*3);let M=new Float32Array(9);me(M,a);for(let I=0;I<o;I++){let p=v.getX(I),y=v.getY(I),A=v.getZ(I),T=M[0]*p+M[3]*y+M[6]*A,R=M[1]*p+M[4]*y+M[7]*A,F=M[2]*p+M[5]*y+M[8]*A,P=Math.hypot(T,R,F)||1;u[I*3]=T/P,u[I*3+1]=R/P,u[I*3+2]=F/P}}let c;if(i.attributes.uv){let v=i.attributes.uv;c=new Float32Array(o*2);for(let M=0;M<o;M++)c[M*2]=v.getX(M),c[M*2+1]=v.getY(M)}let h;if(i.index)h=i.index.array;else{h=o>65535?new Uint32Array(o):new Uint16Array(o);for(let v=0;v<o;v++)h[v]=v}let m="DefaultMaterial",b=[.8,.8,.8],g=.5,d=.1,w=0,C=0,N=1.5,f=1,E=[0,0,0];if(r.material){let v=r.material;m=v.name||`Material_${t.length}`,v.color&&(b=[v.color.r,v.color.g,v.color.b]),typeof v.roughness=="number"&&(g=v.roughness),typeof v.metalness=="number"&&(d=v.metalness),typeof v.clearcoat=="number"&&(w=v.clearcoat),typeof v.clearcoatRoughness=="number"&&(C=v.clearcoatRoughness),typeof v.ior=="number"&&(N=v.ior);let M=typeof v.opacity=="number"?v.opacity:1,I=typeof v.transmission=="number"?v.transmission:0;if(f=M*(1-I),v.emissive&&(v.emissive.r>0||v.emissive.g>0||v.emissive.b>0)){let p=v.emissiveIntensity??1;E=[v.emissive.r*p,v.emissive.g*p,v.emissive.b*p]}}let x,_=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 _=="function"){let v=e?.duration??4,M=e?.fps??4,I=Math.max(2,Math.round(v*M)+1),p=[],y=[],A=[],T=[],R=[r.position.x,r.position.y,r.position.z],F=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],P=[r.scale.x,r.scale.y,r.scale.z],B=!1;for(let k=0;k<I;k++){let O=k/(I-1)*v;p.push(O);try{_(O)}catch{}y.push([r.position.x,r.position.y,r.position.z]),A.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),T.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-R[0])>1e-4||Math.abs(r.position.y-R[1])>1e-4||Math.abs(r.position.z-R[2])>1e-4||Math.abs(r.quaternion.x-F[0])>1e-4||Math.abs(r.quaternion.y-F[1])>1e-4||Math.abs(r.quaternion.z-F[2])>1e-4||Math.abs(r.quaternion.w-F[3])>1e-4||Math.abs(r.scale.x-P[0])>1e-4)&&(B=!0)}r.position.set(R[0],R[1],R[2]),r.quaternion.set(F[0],F[1],F[2],F[3]),r.scale.set(P[0],P[1],P[2]),B&&(x={times:p,translations:y,rotations:A,scales:T})}let D=r;if(D.isInstancedMesh&&typeof D.count=="number"&&D.count>0&&D.instanceMatrix?.array){let v=Math.min(1e3,Math.floor(D.count)),M=D.instanceMatrix.array,I=D.instanceColor?.array,p=r.name||`Mesh_${t.length}`,y=new Float32Array(16),A=new Float32Array(9);for(let T=0;T<v;T++){let R=M.subarray(T*16,(T+1)*16);ee(y,a,R);let F=new Float32Array(o*3);for(let O=0;O<o;O++){let S=s.getX(O),G=s.getY(O),z=s.getZ(O);F[O*3]=y[0]*S+y[4]*G+y[8]*z+y[12],F[O*3+1]=y[1]*S+y[5]*G+y[9]*z+y[13],F[O*3+2]=y[2]*S+y[6]*G+y[10]*z+y[14]}let P;if(i.attributes.normal){let O=i.attributes.normal;P=new Float32Array(o*3),me(A,y);for(let S=0;S<o;S++){let G=O.getX(S),z=O.getY(S),U=O.getZ(S),H=A[0]*G+A[3]*z+A[6]*U,L=A[1]*G+A[4]*z+A[7]*U,V=A[2]*G+A[5]*z+A[8]*U,X=Math.hypot(H,L,V)||1;P[S*3]=H/X,P[S*3+1]=L/X,P[S*3+2]=V/X}}let B=b,k=m;I&&I.length>=(T+1)*3&&(B=[b[0]*I[T*3],b[1]*I[T*3+1],b[2]*I[T*3+2]],k=`${m}_inst_${T}`),t.push({name:`${p}_${T}`,positions:F,indices:h,normals:P,uvs:c,materialName:k,color:B,roughness:g,metallic:d,clearcoat:w,clearcoatRoughness:C,ior:N,opacity:f,emissiveColor:E,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:l,indices:h,normals:u,uvs:c,materialName:m,color:b,roughness:g,metallic:d,clearcoat:w,clearcoatRoughness:C,ior:N,opacity:f,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:x})}}),t}function _n(n){let e=[],t=n.gltf,r=Q().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),o=t.accessors||[],l=t.bufferViews||[],a=t.materials||[],u=t.meshes||[],c=t.nodes||[];function h(g){let d=o[g];if(!d)throw new Error(`Accessor ${g} not found`);let w=l[d.bufferView||0],C=(w.byteOffset||0)+(d.byteOffset||0),N=w.byteLength||0,f=s.slice(C,C+N);return{acc:d,buffer:f}}let m=new Map;if(c.length>0){let g=st(t);for(let d=0;d<g.length;d++)m.set(d,g[d])}function b(g,d,w,C){let N=u[g];if(!N)return;let f=new Float32Array(9);me(f,d);for(let E=0;E<(N.primitives||[]).length;E++){let x=N.primitives[E],_=x.attributes?.POSITION;if(_===void 0)continue;let{acc:D,buffer:v}=h(_),M=new Float32Array(v,0,D.count*3),I=new Float32Array(M.length);for(let L=0;L<D.count;L++){let V=M[L*3],X=M[L*3+1],W=M[L*3+2];I[L*3]=d[0]*V+d[4]*X+d[8]*W+d[12],I[L*3+1]=d[1]*V+d[5]*X+d[9]*W+d[13],I[L*3+2]=d[2]*V+d[6]*X+d[10]*W+d[14]}let p,y=x.attributes?.NORMAL;if(y!==void 0){let{acc:L,buffer:V}=h(y),X=new Float32Array(V,0,L.count*3);p=new Float32Array(X.length);for(let W=0;W<L.count;W++){let Y=X[W*3],re=X[W*3+1],ae=X[W*3+2],$=f[0]*Y+f[3]*re+f[6]*ae,q=f[1]*Y+f[4]*re+f[7]*ae,se=f[2]*Y+f[5]*re+f[8]*ae,ce=Math.hypot($,q,se)||1;p[W*3]=$/ce,p[W*3+1]=q/ce,p[W*3+2]=se/ce}}let A,T=x.attributes?.TEXCOORD_0;if(T!==void 0){let{acc:L,buffer:V}=h(T);A=new Float32Array(V,0,L.count*2)}let R;if(x.indices!==void 0){let{acc:L,buffer:V}=h(x.indices);L.componentType===5125?R=new Uint32Array(V,0,L.count):R=new Uint16Array(V,0,L.count);let X=D.count;for(let W of R)if(W>=X)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${X}).`)}else{let L=D.count;R=L>65535?new Uint32Array(L):new Uint16Array(L);for(let V=0;V<L;V++)R[V]=V}let F="DefaultMaterial",P=[.8,.8,.8],B=.5,k=.1,O=0,S=0,G=1.5,z=1,U=[0,0,0];if(x.material!==void 0&&a[x.material]){let L=a[x.material];F=L.name||`Material_${x.material}`;let V=L.pbrMetallicRoughness||{},X=1;Array.isArray(V.baseColorFactor)&&(P=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&(X=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(B=V.roughnessFactor),typeof V.metallicFactor=="number"&&(k=V.metallicFactor),Array.isArray(L.emissiveFactor)&&L.emissiveFactor.length>=3&&(U=[L.emissiveFactor[0],L.emissiveFactor[1],L.emissiveFactor[2]]);let W=L.extensions||{};W.KHR_materials_clearcoat&&(O=W.KHR_materials_clearcoat.clearcoatFactor??0,S=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(G=W.KHR_materials_ior.ior);let Y=W.KHR_materials_transmission?.transmissionFactor??0;z=X*(1-Y)}let H=(N.primitives||[]).length>1?`${w}_p${E}`:w;e.push({name:H,positions:I,indices:R,normals:p,uvs:A,materialName:F,color:P,roughness:B,metallic:k,clearcoat:O,clearcoatRoughness:S,ior:G,opacity:z,emissiveColor:U,xrTraits:C?.xr||N.extras?.xr})}}if(c.length>0)for(let g=0;g<c.length;g++){let d=c[g];if(d.mesh!==void 0&&d.mesh<u.length){let w=m.get(g)||J(),C=d.name||u[d.mesh].name||`Node_${g}`,N=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(N&&typeof N=="object"){let f=N.TRANSLATION,E=N.ROTATION,x=N.SCALE,_=f!==void 0?(()=>{let{acc:I,buffer:p}=h(f);return new Float32Array(p,0,I.count*3)})():null,D=E!==void 0?(()=>{let{acc:I,buffer:p}=h(E);return new Float32Array(p,0,I.count*4)})():null,v=x!==void 0?(()=>{let{acc:I,buffer:p}=h(x);return new Float32Array(p,0,I.count*3)})():null,M=Math.min(1e3,_?_.length/3:D?D.length/4:v?v.length/3:0);if(M>0){let I=new Float32Array(16),p=new Float32Array(16);for(let y=0;y<M;y++){let A=_?[_[y*3],_[y*3+1],_[y*3+2]]:[0,0,0],T=D?[D[y*4],D[y*4+1],D[y*4+2],D[y*4+3]]:[0,0,0,1],R=v?[v[y*3],v[y*3+1],v[y*3+2]]:[1,1,1];we(I,T,A,R),ee(p,w,I),b(d.mesh,p,`${C}_${y}`,d.extras)}continue}}b(d.mesh,w,C,d.extras)}}else{let g=J();for(let d=0;d<u.length;d++){let w=u[d].name||`Mesh_${d}`;b(d,g,w,u[d].extras)}}return e}function Kt(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 En(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function j(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 Rn(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*3])}, ${j(n[r*3+1])}, ${j(n[r*3+2])})`;return t.join(", ")}function yr(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*2])}, ${j(1-n[r*2+1])})`;return t.join(", ")}function gr(n){return Array.from(n).join(", ")}function qt(n){let e=new Map;for(let a of n){let u=Kt(a.materialName,"DefaultMaterial");e.has(u)||e.set(u,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let t=0,r=null;for(let a of n){if(a.timeSamples&&a.timeSamples.times.length>0){let u=a.timeSamples.times[a.timeSamples.times.length-1];u>t&&(t=u)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
253
- endTimeCode = ${j(t)}
249
+ void main(){fragColor=uColorId;}`;function In(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var qn=["uMVP","uModel","uInstanced","uViewProj","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","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function nr(){let e=le().xrDepthShader;return{fs:Zr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...qn,...e.uniformNames]:qn}}function ei(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Rn(e,t,i,r,s,n,a,o){if(r===void 0||!t.accessors?.[r])return null;let l=En(t,i,t.accessors[r],n);if(!l)return null;o&&(l=l.slice(),Yn(l,o));let h=e.createBuffer();return a.push(h),e.bindBuffer(34962,h),e.bufferData(34962,l,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),l}function Cn(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function rr(e,t,i){let r=nr(),s=tr,n=r.fs,a=!1;for(let l of pe)if(l.onResolveShader){let h=l.onResolveShader(t,i,s,n);h&&(s=h.vs,n=h.fs,a=!0)}let o=a?Tt(e,s,n):null;return{program:o,uniforms:o?In(e,o,r.uniforms):null}}function ti(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,a=new Float32Array(s*20);for(let l=0;l<s;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=n?n[l*3]:1,a[l*20+17]=n?n[l*3+1]:1,a[l*20+18]=n?n[l*3+2]:1,a[l*20+19]=1;let o=e.createBuffer();i.push(o),e.bindBuffer(34962,o),e.bufferData(34962,a,35044);for(let l=0;l<5;l++)e.enableVertexAttribArray(8+l),e.vertexAttribPointer(8+l,4,5126,!1,80,l*16),e.vertexAttribDivisor(8+l,1);return!0}function ni(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Gi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ir=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function _t(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function sr(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=a=>a!==void 0&&t[a.index]?t[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function or(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let a of n.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)e.deleteBuffer(l);s(a.texture),s(a.metallicRoughnessTexture),s(a.normalTexture),s(a.occlusionTexture);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)e.deleteProgram(l)}if(i)for(let n of i)s(n)}function Zn(e,t,i=ir,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ri(e,t,i,r,s)}catch(n){let a=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;or(e,a,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let o of s.buffers)e.deleteBuffer(o);throw n}}function ri(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,a=je("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(n,t);let o=t.bin,l=[];s.meshes=l;let h=[],u=n.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((E,y)=>{h.push(typeof E?.name=="string"&&E.name?E.name:`Variant_${y}`)});let f=Kn(n),g=[];if(Array.isArray(n.nodes))for(let E=0;E<n.nodes.length;E++){let y=n.nodes[E];y.mesh!==void 0&&n.meshes&&n.meshes[y.mesh]&&g.push({node:y,nodeIdx:E,meshIdx:y.mesh})}let w=g.length>0?g:(n.meshes||[]).map((E,y)=>({node:E,nodeIdx:-1,meshIdx:y})),p=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let E of b)p.push({...E,type:E.type||E.light_type||"point",innerConeAngle:E.innerConeAngle??E.inner_cone_angle,outerConeAngle:E.outerConeAngle??E.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let E=n.extensions.KHR_lights_punctual.lights;for(let y of E){let F=y.type==="directional"?"directional":y.type==="point"?"point":y.type==="spot"?"spot":"ambient";p.push({type:F,color:y.color||[1,1,1],intensity:y.intensity!==void 0?y.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),w.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${w.length}`);let T=[];if(s.gpuTextures=T,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let E=0;E<n.textures.length;E++){let y=n.textures[E],F=n.images[y.source];if(F){let z=e.createTexture();e.bindTexture(3553,z),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let A=_=>{e.bindTexture(3553,z),e.texImage2D(3553,0,6408,6408,5121,_),e.generateMipmap(3553),r?.()};if(F.bufferView!==void 0){let _=n.bufferViews[F.bufferView],d=_.byteOffset||0,R=new Blob([o.slice(d,d+_.byteLength)],{type:F.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(R).then(A).catch(()=>{})}else if(F.uri){let _=ei(F.uri);if(_){let d=new Image;d.crossOrigin="anonymous",d.referrerPolicy="no-referrer",d.onload=()=>A(d),d.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",F.uri)}T.push(z)}else T.push(null)}}let x=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],c=0,m=0;for(let E=0;E<w.length;E++){let y=w[E],F=n.meshes[y.meshIdx],z=y.nodeIdx>=0?f[y.nodeIdx]:he(),A=new Float32Array(9);Ce(A,z);let _={name:y.node.name||F.name||`Mesh_${y.meshIdx}`,nodeIndex:y.nodeIdx,transform:z,normalMatrix:A,primitives:[],extras:y.node.extras||F.extras,...y.node?.visible===!1||y.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=_;let d=y.node?.extensions?.EXT_mesh_gpu_instancing;if(d&&d.attributes&&typeof d.attributes=="object"){let R=d.attributes,G=R.TRANSLATION!==void 0?n.accessors?.[R.TRANSLATION]:null,H=R.ROTATION!==void 0?n.accessors?.[R.ROTATION]:null,B=R.SCALE!==void 0?n.accessors?.[R.SCALE]:null,Z=R._COLOR_0!==void 0?n.accessors?.[R._COLOR_0]:null,k=Number(G?.count??H?.count??B?.count??0);if(!Number.isFinite(k)||k<0||k>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${k}`);if(k>0){let Y=(U,$)=>{if(!U||U.bufferView===void 0||!n.bufferViews?.[U.bufferView])return null;let j=U.componentType??5126,q=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(j!==5120&&j!==5121&&j!==5122&&j!==5123&&j!==5126)return q(`componentType ${j}`);if(!(Number(U.count)>=k))return q(`count ${U.count} < ${k}`);let K=null;try{K=En(n,o,{...U,count:k},$)}catch{return q("out of bounds")}return!K||!K.every(Number.isFinite)?q("non-finite value"):K},ie=Y(G,3),re=Y(H,4),O=Y(B,3),J=Z?.type==="VEC4"?4:3,V=Y(Z,J),W=new Float32Array(k*16),X=he();for(let U=0;U<k;U++){let $=ie?[ie[U*3],ie[U*3+1],ie[U*3+2]]:[0,0,0],j=re?[re[U*4],re[U*4+1],re[U*4+2],re[U*4+3]]:[0,0,0,1],q=O?[O[U*3],O[U*3+1],O[U*3+2]]:[1,1,1];Qe(X,j,$,q),W.set(X,U*16)}if(_.instanceMatrices=W,V){let U=new Float32Array(k*3);for(let $=0;$<k;$++)U[$*3]=V[$*J],U[$*3+1]=V[$*J+1],U[$*3+2]=V[$*J+2];_.instanceColors=U}}}for(let R of F.primitives||[]){if(R.extensions?.KHR_draco_mesh_compression){let K=je("draco");K&&K.decodePrimitive(n,R,o)}let G=[],H=e.createVertexArray();s.vao=H,s.buffers=G,e.bindVertexArray(H);let B=ti(e,_,G),Z=n.accessors[R.attributes.POSITION],k=Number(Z?.count??0);if(!Number.isFinite(k)||k<0||c+k>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(c+=k,Z?.min&&Z?.max){let K=Q=>{for(let te=0;te<3;te++){let fe=Q[12+te],se=Q[12+te];for(let ae=0;ae<3;ae++){let oe=Q[ae*4+te]*Z.min[ae],ce=Q[ae*4+te]*Z.max[ae];fe+=oe<ce?oe:ce,se+=oe>ce?oe:ce}fe<x[te]&&(x[te]=fe),se>M[te]&&(M[te]=se)}};if(_.instanceMatrices&&_.instanceMatrices.length>=16){let Q=_.instanceMatrices.length>>4,te=he();for(let fe=0;fe<Q;fe++){let se=_.instanceMatrices.subarray(fe*16,fe*16+16);be(te,z,se),K(te)}}else K(z)}let Y=Rn(e,n,o,R.attributes.POSITION,0,3,G);Rn(e,n,o,R.attributes.NORMAL,1,3,G),Rn(e,n,o,R.attributes.TEXCOORD_0,2,2,G,ni(n,R));let ie=0,re=5123,O=null;if(R.indices!==void 0){let K=n.accessors[R.indices],Q=(n.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(ie=Number(K.count??0),!Number.isFinite(ie)||ie<0||m+ie>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);m+=ie,re=K.componentType===5125?5125:5123;let te=e.createBuffer();G.push(te),e.bindBuffer(34963,te),K.componentType===5125?O=new Uint32Array(o,Q,K.count):K.componentType===5121?O=Uint16Array.from(new Uint8Array(o,Q,K.count)):O=Q%2===0?new Uint16Array(o,Q,K.count):new Uint16Array(o.slice(Q,Q+K.count*2)),e.bufferData(34963,O,35044)}else ie=Z.count;let J={};for(let K of pe)if(K.onBuildPrimitiveVAO){let Q=K.onBuildPrimitiveVAO(e,H,R,n,o);Q&&(J[K.name]=Q)}e.bindVertexArray(null);let V=n.materials&&R.material!==void 0?n.materials[R.material]:null,{program:W,uniforms:X}=rr(e,R,V),U=sr(V,T),$=!!(V?.extensions?.KHR_materials_transmission||J.materials?.isTransmissive),j=R.extensions?.KHR_materials_variants?.mappings,q=Array.isArray(j)?j.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(Q=>Number(Q)|0)})):void 0;_.primitives.push({vao:H,instanced:B,indexCount:ie,indexType:re,...U,positions:Y,indices:O,buffers:G,materialIndex:R.material,defaultMaterialIndex:R.material,variantMappings:q,primitiveDef:R,programCache:new Map([[R.material??-1,{program:W,uniforms:X}]]),pluginData:J,customProgram:W,customUniforms:X,isTransmissive:$})}l.push(_)}isFinite(x[0])||(x=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let v=[(x[0]+M[0])/2,(x[1]+M[1])/2,(x[2]+M[2])/2],S=M[0]-x[0],D=M[1]-x[1],I=M[2]-x[2],P=Math.max(Math.hypot(S,D,I)/2,.5),N=[x[0],x[1],x[2]],C=[M[0],M[1],M[2]],L=t.animations;if(!L){for(let E of pe)if(E.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:l,bounds:{center:v,radius:P,min:N,max:C},lights:p,animations:L,worldMatrices:f,gpuTextures:T,availableVariants:h}}function et(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var St=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=he(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=he(),this.viewMatrix=he(),this.activeViewMatrix=null,this.modelMatrix=he(),this.mvpMatrix=he(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:he(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),r=o}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(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.exposure=Cn(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=Dn(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let a=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!a)throw new Error("WebGL2 not supported");this.gl=a,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Yr(e,t)}static getDecoder(e){return je(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=nr();this.renderProg=Tt(e,tr,t.fs),this.pickProg=Tt(e,Jr,Qr),this.uRender=In(e,this.renderProg,t.uniforms),this.uPick=In(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of pe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}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),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),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 i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:a,gpuTextures:o,availableVariants:l}=Zn(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of pe)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let h=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;h!==void 0&&(this.exposure=Cn(h));let u=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u)||0)),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(er(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of pe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(wt(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=wt(e),{meshes:r}=Zn(this.gl,i,ir,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Ce(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Ce(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],a=[],o=[],l=[];for(let h of this.lights){let u=h.color||[1,1,1],f=h.intensity!==void 0?h.intensity:1;if(h.type==="ambient")i=[u[0]*f,u[1]*f,u[2]*f];else if(h.type==="directional"&&r.length<6){let g=h.direction||[.5,1,.8];r.push(g[0],g[1],g[2]),s.push(u[0]*f,u[1]*f,u[2]*f)}else if((h.type==="point"||h.type==="spot")&&n.length<6){let g=h.position||[0,0,0];if(n.push(g[0],g[1],g[2]),a.push(u[0]*f,u[1]*f,u[2]*f),h.type==="spot"){let w=h.direction||[0,-1,0],p=Math.max(.01,Math.min(Math.PI/2,h.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(p-1e-4,h.innerConeAngle??0));o.push(w[0],w[1],w[2]),l.push(Math.cos(b),Math.cos(p))}else o.push(0,-1,0),l.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,a),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Cn(e)}getExposure(){return this.exposure}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=Dn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of pe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of pe)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,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.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,i)=>{let r=this.meshes.flatMap(h=>h.primitives.filter(u=>u.materialIndex===i||e.length===1&&u.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:n,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:h=>{let u=[h[0],h[1],h[2],h[3]??1];l.baseColorFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=u);for(let f of r)f.baseColor=u;this.render()},setMetallicFactor:h=>{l.metallicFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=h);for(let u of r)u.metallic=h;this.render()},setRoughnessFactor:h=>{l.roughnessFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);for(let u of r)u.roughness=h;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.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)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let a=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let l of n.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;n.materialIndex=o?a:void 0,Object.assign(n,sr(o,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=rr(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of pe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],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,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){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),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);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 i=he();be(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,a=t?t[0]:0,o=t?t[1]:0,l=t?t[2]:0,h=this.modelRootMatrix;h&&(r=h[0]*e[0]+h[4]*e[1]+h[8]*e[2]+h[12],s=h[1]*e[0]+h[5]*e[1]+h[9]*e[2]+h[13],n=h[2]*e[0]+h[6]*e[1]+h[10]*e[2]+h[14],t&&(a=h[0]*t[0]+h[4]*t[1]+h[8]*t[2],o=h[1]*t[0]+h[5]*t[1]+h[9]*t[2],l=h[2]*t[0]+h[6]*t[1]+h[10]*t[2]));let u=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],g=i[2]*r+i[6]*s+i[10]*n+i[14],w=i[3]*r+i[7]*s+i[11]*n+i[15];if(w<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=u/w,b=f/w,T=g/w,x=this.canvas.getBoundingClientRect(),M=x.width||this.canvas.clientWidth||this.canvas.width||300,c=x.height||this.canvas.clientHeight||this.canvas.height||150,m=(p*.5+.5)*M,v=(-b*.5+.5)*c,S=p>=-1.1&&p<=1.1&&b>=-1.1&&b<=1.1&&T>=-1&&T<=1;if(S&&t){let[D,I,P]=et(this),N=[r-D,s-I,n-P];a*N[0]+o*N[1]+l*N[2]>.05&&(S=!1)}return{x:m,y:v,z:T,visible:S}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],h=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-s*a[0]+n*o[0])*h,l[1]+=(-s*a[1]+n*o[1])*h,l[2]+=(-s*a[2]+n*o[2])*h,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.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=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,a=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),o=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(a,o,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let a=he();be(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(s-1,e)),h=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let S=this.meshes[v];if(S.visible===!1||S.isPluginMesh)continue;let D=v+1,I=(D&255)/255,P=(D>>8&255)/255,N=(D>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,P,N,1),be(this.modelMatrix,this.modelRootMatrix,S.transform);let C=S.instanceMatrices;if(C&&C.length>=16){let L=C.length>>4,E=he();for(let y of S.primitives){r.bindVertexArray(y.vao);for(let F=0;F<L;F++)be(E,this.modelMatrix,C.subarray(F*16,F*16+16)),be(this.mvpMatrix,a,E),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),_t(r,y)}}else{be(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of S.primitives)r.bindVertexArray(L.vao),_t(r,L)}}let c=new Uint8Array(4);r.readPixels(l,h,1,1,6408,5121,c),r.bindFramebuffer(36160,null);let m=c[0]+(c[1]<<8)+(c[2]<<16);m>0&&m<=this.meshes.length&&(o=[this.meshes[m-1]])}o.length===0&&(o=this.meshes.filter(c=>c.visible!==!1));let u=null,f=1/0,g=[0,0,0],w=[0,1,0],[p,b,T]=et(this),x=he();for(let c of o){be(x,this.modelRootMatrix,c.transform);let m=c.instanceMatrices,v=m&&m.length>=16?m.length>>4:1;for(let S=0;S<v;S++){m&&m.length>=16?be(this.modelMatrix,x,m.subarray(S*16,S*16+16)):this.modelMatrix.set(x),be(this.mvpMatrix,a,this.modelMatrix);let D=he();if(!Wn(D,this.mvpMatrix))continue;let I=(l+.5)/s*2-1,P=(h+.5)/n*2-1,N=[0,0,0],C=[0,0,0];An(N,I,P,-1,D),An(C,I,P,1,D);let L=C[0]-N[0],E=C[1]-N[1],y=C[2]-N[2],F=Math.hypot(L,E,y)||1,z=L/F,A=E/F,_=y/F,d={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((R=>{for(let G of c.primitives){if(!G.positions)continue;let H=G.positions,B=G.indices,Z=Math.floor(B?B.length/3:H.length/9);for(let k=0;k<Z;k++){let Y=B?B[k*3]:k*3,ie=B?B[k*3+1]:k*3+1,re=B?B[k*3+2]:k*3+2;jn(N[0],N[1],N[2],z,A,_,H[Y*3],H[Y*3+1],H[Y*3+2],H[ie*3],H[ie*3+1],H[ie*3+2],H[re*3],H[re*3+1],H[re*3+2],d,R)}}})(1e-4),isFinite(d.distance)){let R=d.point[0],G=d.point[1],H=d.point[2],B=this.modelMatrix,Z=B[0]*R+B[4]*G+B[8]*H+B[12],k=B[1]*R+B[5]*G+B[9]*H+B[13],Y=B[2]*R+B[6]*G+B[10]*H+B[14],ie=Z-p,re=k-b,O=Y-T,J=Math.hypot(ie,re,O);if(J<f){Ce(this.normalMatrix,this.modelMatrix);let V=this.normalMatrix,W=d.normal[0],X=d.normal[1],U=d.normal[2],$=V[0]*W+V[3]*X+V[6]*U,j=V[1]*W+V[4]*X+V[7]*U,q=V[2]*W+V[5]*X+V[8]*U,K=Math.hypot($,j,q)||1;$/=K,j/=K,q/=K,$*ie+j*re+q*O>0&&($=-$,j=-j,q=-q),u=c,f=Math.round(J*1e3)/1e3,g=[Math.round(Z*1e3)/1e3,Math.round(k*1e3)/1e3,Math.round(Y*1e3)/1e3],w=[Math.round($*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(q*1e3)/1e3]}}}}if(!u)return null;let M={meshIndex:this.meshes.indexOf(u),meshName:u.name,nodeIndex:u.nodeIndex,distance:f,hitPoint:g,normal:w,screenX:e,screenY:t};if(i){for(let c of pe)c.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,a=(s+.5)/n*2-1;return Math.floor((a*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Mt(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;We(this.viewMatrix,et(this),i,[0,1,0]),be(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of pe)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of pe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=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]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of pe)n.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 n of pe)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let a=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,h=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:a,projMatrix:o,eyePos:h,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let M=Math.max(2,this.canvas.width||2),c=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(M*.5)),v=Math.max(1,M-m),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),D=this.customTarget||this.bounds.center,[I,P,N]=et(this),C=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),E=.032,y=he(),F=he(),z=[I-C*E,P,N-L*E],A=[D[0]-C*E*.25,D[1],D[2]-L*E*.25];Mt(y,this.fov,m/c,.1,S),We(F,z,A,[0,1,0]);let _=he(),d=he(),R=[I+C*E,P,N+L*E],G=[D[0]+C*E*.25,D[1],D[2]+L*E*.25];Mt(_,this.fov,v/c,.1,S),We(d,R,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:y,eyePos:z,viewport:[0,0,m,c],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:d,projMatrix:_,eyePos:R,viewport:[m,0,v,c],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,M,c);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let a=he(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,be(a,e?.projMatrix??this.projMatrix,o);let l=le().xrDepthShader,h=jr(this.toneMapping),[u,f,g]=e?e.eyePos:et(this);for(let M of pe)M.onBeforeDrawScene?.(this,t,a,[u,f,g],h);let w=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&w===0)return;let p=e?.eye||"none",b=!1,T=w>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=M=>{for(let c=0;c<T.length;c++){let m=T[c];if(m.visible===!1)continue;let v=this.selectedMeshName!==""&&m.name===this.selectedMeshName;c<w||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):be(this.modelMatrix,this.modelRootMatrix,m.transform),be(this.mvpMatrix,a,this.modelMatrix),Ce(m.normalMatrix,this.modelMatrix);let S=m.extras?.xr?.stereo||m.userData?.xr?.stereo,D=0,I=0,P=1,N=1;S==="sbs"?(P=.5,D=p==="right"?.5:0):S==="ou"&&(N=.5,I=p==="right"?.5:0);for(let C of m.primitives){let L=!!C.isTransmissive;if(!M&&L){b=!0;continue}if(M&&!L)continue;let E=C.customProgram||this.renderProg,y=C.customUniforms||this.uRender;t.useProgram(E),t.vertexAttrib3f(3,0,0,0),y.uInstanced&&t.uniform1i(y.uInstanced,0),t.uniform1i(y.uToneMapping,h),t.uniform1f(y.uEnvIntensity,this.envIntensity),y.uExposure&&t.uniform1f(y.uExposure,this.exposure),t.uniform3f(y.uCameraPos,u,f,g),t.uniform1f(y.uEmissive,v?1:0),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(y.uNormalMatrix,!1,m.normalMatrix),y.uUvTransform&&t.uniform4f(y.uUvTransform,D,I,P,N),y.uViewportSize&&t.uniform2f(y.uViewportSize,Math.max(1,s),Math.max(1,n)),l?.bind(t,y,this.xrDepthState,o,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(y.uEnvironmentMap,4),t.uniform1i(y.uHasEnvironmentMap,1)):t.uniform1i(y.uHasEnvironmentMap,0),this.bindLights(y),y.uSectionEnabled&&t.uniform1i(y.uSectionEnabled,0);for(let z of pe)z.onBeforeDrawPrimitive?.(t,E,C,m,this.worldMatrices||[],this.gltf);t.uniform4fv(y.uBaseColor,C.baseColor),t.uniform1f(y.uMetallic,C.metallic),t.uniform1f(y.uRoughness,C.roughness),y.uClearcoat&&t.uniform2f(y.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(t.activeTexture(33984),t.bindTexture(3553,C.texture),t.uniform1i(y.uBaseColorTexture,0),t.uniform1i(y.uHasTexture,1)):t.uniform1i(y.uHasTexture,0),C.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,C.metallicRoughnessTexture),t.uniform1i(y.uMetallicRoughnessTexture,1),t.uniform1i(y.uHasMetallicRoughnessTexture,1)):t.uniform1i(y.uHasMetallicRoughnessTexture,0),C.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,C.normalTexture),t.uniform1i(y.uNormalTexture,2),t.uniform1i(y.uHasNormalTexture,1),t.uniform1f(y.uNormalScale,C.normalScale)):t.uniform1i(y.uHasNormalTexture,0),C.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,C.occlusionTexture),t.uniform1i(y.uOcclusionTexture,3),t.uniform1i(y.uHasOcclusionTexture,1),t.uniform1f(y.uOcclusionStrength,C.occlusionStrength)):t.uniform1i(y.uHasOcclusionTexture,0),t.bindVertexArray(C.vao);let F=m.instanceMatrices;if(C.instanceCount!==void 0)t.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(F&&F.length>=16&&C.instanced&&y.uInstanced&&y.uViewProj){let z=F.length>>4;t.uniform1i(y.uInstanced,1),t.uniformMatrix4fv(y.uViewProj,!1,a),C.indices?t.drawElementsInstanced(4,C.indexCount,C.indexType,0,z):t.drawArraysInstanced(4,0,C.indexCount,z),t.uniform1i(y.uInstanced,0)}else if(F&&F.length>=16){let z=F.length>>4,A=m.instanceColors,_=he(),d=new Float32Array(9),R=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let G=0;G<z;G++)be(_,this.modelMatrix,F.subarray(G*16,G*16+16)),be(this.mvpMatrix,a,_),Ce(d,_),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,_),t.uniformMatrix3fv(y.uNormalMatrix,!1,d),A&&(R[0]=C.baseColor[0]*A[G*3],R[1]=C.baseColor[1]*A[G*3+1],R[2]=C.baseColor[2]*A[G*3+2],R[3]=C.baseColor[3],t.uniform4fv(y.uBaseColor,R)),_t(t,C)}else _t(t,C)}}};if(x(!1),b){for(let M of pe)M.onBeforeTransmissivePass?.(t,this);x(!0)}for(let M of pe)M.onAfterRender?.(t,this,a,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){or(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of pe)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()}};St.registerPlugin=$n,St.getRegisteredPlugins=Xn;function ii(e){return e+3&-4}var ne=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function cr(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ur(e,t=0){let[i,r,s,,n,a,o,,l,h,u,,f,g,w]=Array.from({length:15},(d,R)=>ne(e[t+R],R%5===0?1:0)),p=Math.hypot(i,r,s),b=Math.hypot(n,a,o),T=Math.hypot(l,h,u);i*(a*u-h*o)-n*(r*u-h*s)+l*(r*o-a*s)<0&&(p=-p);let x=Math.abs(p)>1e-8?1/p:0,M=Math.abs(b)>1e-8?1/b:0,c=Math.abs(T)>1e-8?1/T:0,m=i*x,v=r*x,S=s*x,D=n*M,I=a*M,P=o*M,N=l*c,C=h*c,L=u*c,E=m+I+L,y=0,F=0,z=0,A=1;if(E>0){let d=.5/Math.sqrt(E+1);A=.25/d,y=(P-C)*d,F=(N-S)*d,z=(v-D)*d}else if(m>I&&m>L){let d=2*Math.sqrt(Math.max(0,1+m-I-L));d>1e-8&&(A=(P-C)/d,y=.25*d,F=(D+v)/d,z=(N+S)/d)}else if(I>L){let d=2*Math.sqrt(Math.max(0,1+I-m-L));d>1e-8&&(A=(N-S)/d,y=(D+v)/d,F=.25*d,z=(P+C)/d)}else{let d=2*Math.sqrt(Math.max(0,1+L-m-I));d>1e-8&&(A=(v-D)/d,y=(N+S)/d,F=(P+C)/d,z=.25*d)}let _=Math.hypot(y,F,z,A);return _>1e-8&&Number.isFinite(_)?(y/=_,F/=_,z/=_,A/=_):(y=0,F=0,z=0,A=1),{t:[f,g,w],r:[y,F,z,A],s:[p,b,T]}}function si(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Ue=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function lr(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:Ue(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Ke(e,t){return mr(e,t)[0]}function mr(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],a=[],o=[],l=new Set,h=[],u=[],f=new Map,g=[],w=[],p=[],b=new Map,T=[],x=[];function M(A){let _=f.get(A);if(_!==void 0)return _;_=u.length,f.set(A,_);let d=A,R=d.color?.r??1,G=d.color?.g??1,H=d.color?.b??1,B=d.opacity??1,Z={baseColorFactor:[R,G,H,B],metallicFactor:d.metalness??0,roughnessFactor:d.roughness??.5},k={},Y=$=>{if(!$)return;let j=(typeof $=="string"?$:typeof $.source=="string"?$.source:typeof $.image=="string"?$.image:"").trim();if(!j||/[\x00-\x1f\x7f\\]|\.\./.test(j)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(j)||!j.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(j)))return;let q=b.get(j);if(q===void 0){let K=g.length;g.push({uri:j}),w.length===0&&w.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),q=p.length,p.push({sampler:0,source:K}),b.set(j,q)}return{index:q}},ie=Y(d.map);ie&&(Z.baseColorTexture=ie);let re=Y(d.roughnessMap||d.metalnessMap);re&&(Z.metallicRoughnessTexture=re);let O=d.map?.avgColor;Array.isArray(O)&&O.length>=3&&(k.avgColor=[O[0],O[1],O[2]]);let J=Y(d.normalMap),V=Y(d.emissiveMap),W=Y(d.aoMap),X={name:d.name||"",pbrMetallicRoughness:Z,doubleSided:d.side===2||!!d.doubleSided,...J?{normalTexture:J}:{},...V?{emissiveTexture:V}:{},...W?{occlusionTexture:W}:{},...Object.keys(k).length>0?{extras:k}:{}};if(d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let $=d.emissiveIntensity??1;X.emissiveFactor=[d.emissive.r*$,d.emissive.g*$,d.emissive.b*$]}let U={};return d.clearcoat&&d.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:d.clearcoat,clearcoatRoughnessFactor:d.clearcoatRoughness||0}),d.sheen&&d.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:d.sheenColor?[d.sheenColor.r,d.sheenColor.g,d.sheenColor.b]:[1,1,1],sheenRoughnessFactor:d.sheenRoughness||0}),d.transmission&&d.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:d.transmission}),d.thickness&&d.thickness>0&&(U.KHR_materials_volume={thicknessFactor:d.thickness,attenuationDistance:d.attenuationDistance??1/0,attenuationColor:d.attenuationColor?[d.attenuationColor.r,d.attenuationColor.g,d.attenuationColor.b]:[1,1,1]}),d.ior!==void 0&&d.ior!==1.5&&(U.KHR_materials_ior={ior:d.ior}),d.dispersion&&d.dispersion>0&&(U.KHR_materials_dispersion={dispersion:d.dispersion}),d.iridescence&&d.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:d.iridescence,iridescenceIor:d.iridescenceIOR??1.3}),Object.keys(U).length>0&&(X.extensions=U),u.push(X),_}function c(A,_){let d=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),R=ii(d.byteLength),G=new Uint8Array(R);G.set(d),i.push(G);let H=s.length;return s.push({buffer:0,byteOffset:r,byteLength:d.byteLength,target:_}),r+=R,H}function m(A,_,d,R,G,H,B){let Z=c(A,d),k=n.length,Y={bufferView:Z,byteOffset:0,componentType:R,count:G,type:_};return H&&(Y.min=H),B&&(Y.max=B),n.push(Y),k}e.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let _=A.matrixWorld?.elements,d=ne(_?_[12]:A.position?.x,0),R=ne(_?_[13]:A.position?.y,0),G=ne(_?_[14]:A.position?.z,0),H=A.target,B=H?.parent?H?.matrixWorld?.elements:void 0,Z=ne(B?B[12]:H?.position?.x,0),k=ne(B?B[13]:H?.position?.y,0),Y=ne(B?B[14]:H?.position?.z,0),ie=Z-d,re=k-R,O=Y-G,J=Math.hypot(ie,re,O),V=Math.max(.01,Math.min(Math.PI/2,ne(A.angle,Math.PI/3))),W=Math.max(0,Math.min(1,ne(A.penumbra,0)));x.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[d,R,G],...A.type==="spot"?{direction:J>1e-6?[ie/J,re/J,O/J]:[0,-1,0],outerConeAngle:V,innerConeAngle:Math.max(0,V*(1-W)),range:Math.max(0,ne(A.distance,0))}:A.type==="point"?{range:Math.max(0,ne(A.distance,0))}:{}})}});let v=[],S=new Set([e]),D=[];if(Array.isArray(e.children))for(let A=e.children.length-1;A>=0;A--)D.push({obj:e.children[A],parentKids:v});for(;D.length>0;){let{obj:A,parentKids:_}=D.pop();if(!A||typeof A!="object"||S.has(A))continue;S.add(A),A._bakeAuthorGeometry?.(),le().materializeDeclarativeGeometry?.(A);let d=!!(A.userData&&(A.userData.xr&&typeof A.userData.xr=="object"&&Object.keys(A.userData.xr).length>0||A.userData.interactivity&&typeof A.userData.interactivity=="object"&&Object.keys(A.userData.interactivity).length>0)),R={name:A.name||(d?`Node_${o.length}`:"")},G=ne(A.position?.x,0),H=ne(A.position?.y,0),B=ne(A.position?.z,0),Z=ne(A.quaternion?.x,0),k=ne(A.quaternion?.y,0),Y=ne(A.quaternion?.z,0),ie=ne(A.quaternion?.w,1),re=ne(A.scale?.x,1),O=ne(A.scale?.y,1),J=ne(A.scale?.z,1);if((G||H||B)&&(R.translation=[G,H,B]),(Z||k||Y||ie!==1)&&(R.rotation=[Z,k,Y,ie]),(re!==1||O!==1||J!==1)&&(R.scale=[re,O,J]),A.visible===!1&&(R.extensions={...R.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(R.extras=JSON.parse(JSON.stringify(A.userData,(X,U)=>{if(!(X==="__proto__"||X==="prototype"||X==="constructor"))return typeof U=="function"?void 0:U})),A.userData.xr)){let X=si(A.userData.xr);R.extensions={...R.extensions||{},MOZ_hubs_components:X,ANDROID_xr_scenecore:X},le().xrTraitSerializer?.gltfNode(R,A.userData.xr),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let X=A.geometry,U=X.attributes.position;if(U&&U.count>0){let $=[1/0,1/0,1/0],j=[-1/0,-1/0,-1/0];for(let se=0;se<U.count;se++){let ae=U.getX(se),oe=U.getY(se),ce=U.getZ(se);ae<$[0]&&($[0]=ae),ae>j[0]&&(j[0]=ae),oe<$[1]&&($[1]=oe),oe>j[1]&&(j[1]=oe),ce<$[2]&&($[2]=ce),ce>j[2]&&(j[2]=ce)}let q={attributes:{POSITION:m(U.array,"VEC3",34962,5126,U.count,$,j)}};if(X.attributes.normal&&(q.attributes.NORMAL=m(X.attributes.normal.array,"VEC3",34962,5126,X.attributes.normal.count)),X.attributes.uv&&(q.attributes.TEXCOORD_0=m(X.attributes.uv.array,"VEC2",34962,5126,X.attributes.uv.count)),X.index){let se=X.index.array instanceof Uint32Array;q.indices=m(X.index.array,"SCALAR",34963,se?5125:5123,X.index.count)}let K=Array.isArray(A.material)?A.material[0]:A.material;K&&(q.material=M(K));let Q=A.userData?.variants;if(Q&&typeof Q=="object"){let se=new Map;for(let ae of Object.keys(Q)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let oe=Q[ae];if(!oe||typeof oe!="object")continue;let ce=T.indexOf(ae);if(ce===-1&&T.length<256&&(ce=T.length,T.push(ae)),ce===-1)continue;let Te=M(oe),Re=se.get(Te);Re||(Re=[],se.set(Te,Re)),Re.push(ce)}if(se.size>0){let ae=[];for(let[oe,ce]of se.entries())ae.push({material:oe,variants:ce});q.extensions={...q.extensions||{},KHR_materials_variants:{mappings:ae}},l.add("KHR_materials_variants")}}let te=A;if(te.isInstancedMesh&&typeof te.count=="number"&&te.count>0&&te.instanceMatrix?.array){let se=Math.min(1e4,Math.floor(te.count)),ae=te.instanceMatrix.array,oe=new Float32Array(se*3),ce=new Float32Array(se*4),Te=new Float32Array(se*3);for(let me=0;me<se;me++){let{t:Ne,r:Ee,s:Xe}=ur(ae,me*16);oe[me*3]=Ne[0],oe[me*3+1]=Ne[1],oe[me*3+2]=Ne[2],ce[me*4]=Ee[0],ce[me*4+1]=Ee[1],ce[me*4+2]=Ee[2],ce[me*4+3]=Ee[3],Te[me*3]=Xe[0],Te[me*3+1]=Xe[1],Te[me*3+2]=Xe[2]}let Re={TRANSLATION:m(oe,"VEC3",0,5126,se),ROTATION:m(ce,"VEC4",0,5126,se),SCALE:m(Te,"VEC3",0,5126,se)};if(te.instanceColor?.array&&te.instanceColor.array.length>=se*3){let me=new Float32Array(te.instanceColor.array.subarray(0,se*3));Re._COLOR_0=m(me,"VEC3",0,5126,se)}R.extensions={...R.extensions||{},EXT_mesh_gpu_instancing:{attributes:Re}},l.add("EXT_mesh_gpu_instancing")}let fe=a.length;a.push({primitives:[q],name:A.name,...R.extras?{extras:R.extras}:{}}),R.mesh=fe}}let V=o.length;o.push(R),h.push(A),_.push(V);let W=A.children;if(Array.isArray(W)&&W.length>0){let X=[];R.children=X;for(let U=W.length-1;U>=0;U--)D.push({obj:W[U],parentKids:X})}}for(let A=0;A<o.length;A++){let _=o[A];_.children&&_.children.length===0?delete _.children:_.children&&_.children.length>0&&(_.extras?.xr?.lod||_.extensions?.ANDROID_xr_scenecore?.lod||h[A]?.isLOD)&&(_.extensions={..._.extensions||{},MSFT_lod:{ids:[..._.children]}},l.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof I=="function"&&h.length>0){let A=t?.duration??4,_=t?.fps??15,d=Math.max(2,Math.round(A*_)+1),R=new Float32Array(d),G=h.map(O=>[ne(O.position?.x,0),ne(O.position?.y,0),ne(O.position?.z,0),ne(O.quaternion?.x,0),ne(O.quaternion?.y,0),ne(O.quaternion?.z,0),ne(O.quaternion?.w,1),ne(O.scale?.x,1),ne(O.scale?.y,1),ne(O.scale?.z,1)]),H=h.map(()=>new Float32Array(d*3)),B=h.map(()=>new Float32Array(d*4)),Z=h.map(()=>new Float32Array(d*3));for(let O=0;O<d;O++){let J=O/(d-1)*A;R[O]=J;try{I(J)}catch{}for(let V=0;V<h.length;V++){let W=h[V];H[V][O*3]=ne(W.position?.x,0),H[V][O*3+1]=ne(W.position?.y,0),H[V][O*3+2]=ne(W.position?.z,0);let X=ne(W.quaternion?.x,0),U=ne(W.quaternion?.y,0),$=ne(W.quaternion?.z,0),j=ne(W.quaternion?.w,1),q=Math.hypot(X,U,$,j)||1;if(X/=q,U/=q,$/=q,j/=q,O>0){let K=(O-1)*4,Q=B[V];Q[K]*X+Q[K+1]*U+Q[K+2]*$+Q[K+3]*j<0&&(X=-X,U=-U,$=-$,j=-j)}B[V][O*4]=X,B[V][O*4+1]=U,B[V][O*4+2]=$,B[V][O*4+3]=j,Z[V][O*3]=ne(W.scale?.x,1),Z[V][O*3+1]=ne(W.scale?.y,1),Z[V][O*3+2]=ne(W.scale?.z,1)}}for(let O=0;O<h.length;O++){let J=h[O],V=G[O];J.position?.set(V[0],V[1],V[2]),J.quaternion?.set(V[3],V[4],V[5],V[6]),J.scale?.set(V[7],V[8],V[9])}e.updateMatrixWorld(!0);let k=null,Y=()=>(k===null&&(k=m(R,"SCALAR",0,5126,d,[0],[A])),k),ie=[],re=[];for(let O=0;O<h.length;O++){let J=G[O],V=(X,U,$)=>X.some((j,q)=>Math.abs(j-J[$+q%U])>1e-4),W=(X,U,$,j)=>{X&&re.push({sampler:ie.push({input:Y(),interpolation:"LINEAR",output:m(U,$,0,5126,d)})-1,target:{node:O,path:j}})};W(V(H[O],3,0),H[O],"VEC3","translation"),W(V(B[O],4,3),B[O],"VEC4","rotation"),W(V(Z[O],3,7),Z[O],"VEC3","scale")}re.length>0&&P.push({name:"ProceduralLoop",samplers:ie,channels:re})}let N=zn(o,a,e.userData),C=[],L=[],E=[];for(let A=0;A<o.length;A++){let _=o[A],d=lr(_.extras?.xr);if(!d)continue;let{ae:R,src:G,preset:H,volume:B,loop:Z,isGlobal:k}=d,Y=_.name||`Node_${A}`,ie=L.length;L.push({name:`${Y}_source`,gain:B,loop:Z,autoPlay:typeof R.autoplay=="boolean"?R.autoplay:!0,...G!==void 0?{audio:C.push({uri:G})-1}:{},...H?{extras:{preset:H,pitch:Ue(R.pitch,.25,4,1)}}:{}});let re=E.length,O=Ue(R.refDistance,.05,100,1),J=Ue(R.coneInnerAngle,0,360,360),V=Ue(R.coneOuterAngle,J,360,360);E.push({name:`${Y}_emitter`,type:k?"global":"positional",gain:B,sources:[ie],...k?{}:{positional:{distanceModel:R.distanceModel==="linear"||R.distanceModel==="exponential"?R.distanceModel:"inverse",refDistance:O,maxDistance:Ue(R.maxDistance,O,500,Math.max(O,25)),rolloffFactor:Ue(R.rolloffFactor,0,10,1),coneInnerAngle:+(J*Math.PI/180).toFixed(6),coneOuterAngle:+(V*Math.PI/180).toFixed(6),coneOuterGain:Ue(R.coneOuterGain,0,1,0)}}}),_.extensions={..._.extensions||{},KHR_audio_emitter:{emitter:re}},l.add("KHR_audio_emitter")}let y={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:o,meshes:a,materials:u,...g.length>0?{images:g}:{},...w.length>0?{samplers:w}:{},...p.length>0?{textures:p}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...N||l.size>0?{extensionsUsed:[...N?["KHR_interactivity"]:[],...l]}:{},...N||T.length>0||E.length>0?{extensions:{...N?{KHR_interactivity:N}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(A=>({name:A}))}}:{},...E.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:L,emitters:E}}:{}}}:{}},F=new Uint8Array(r),z=0;for(let A of i)F.set(A,z),z+=A.byteLength;return[{gltf:y,bin:F.buffer,lights:x,environmentIntensity:e.environmentIntensity},h]}function Nn(e){return new TextEncoder().encode(e)}function tt(e,t){let{gltf:i,bin:r}=Ke(e,t),s=JSON.stringify(i),n=Nn(s),a=(4-n.byteLength%4)%4,o=n.byteLength+a,l=20+o+8+r.byteLength,h=new Uint8Array(l),u=new DataView(h.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,l,!0),u.setUint32(12,o,!0),u.setUint32(16,1313821514,!0),h.set(n,20);for(let g=0;g<a;g++)h[20+n.byteLength+g]=32;let f=20+o;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),h.set(new Uint8Array(r),f+8),h}function oi(e,t){let[i,r]=mr(e,t);return hr(i,r)}function hr(e,t){let i=[],r=e.gltf,s=le().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,a=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=r.accessors||[],l=r.bufferViews||[],h=r.materials||[],u=r.meshes||[],f=r.nodes||[],g=r.textures||[],w=r.images||[],p=r.samplers||[],b=new Set,T=h.map((S,D)=>cr(b,Ct(S?.name,`Material_${D}`))),x=new Map;function M(S){let D=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(S);if(!D)return null;let I=D[2].replace(/\s+/g,""),P=I.endsWith("==")?2:I.endsWith("=")?1:0,N=new Uint8Array((I.length*3>>2)-P),C=E=>{let y=I.charCodeAt(E);return y>96?y-71:y>64?y-65:y>47?y+4:y===43?62:y===47?63:0},L=0;for(let E=0;E<I.length;E+=4){let y=C(E)<<18|C(E+1)<<12|C(E+2)<<6|C(E+3);N[L++]=y>>16&255,L<N.length&&(N[L++]=y>>8&255),L<N.length&&(N[L++]=y&255)}return N}function c(S,D,I){let P=S?.index;if(typeof P!="number")return;let N=g[P],C=N?.source;if(typeof C!="number"||!w[C])return;let L=x.get(C);if(L===void 0){L=null;let F=w[C],z=null;if(typeof F.bufferView=="number"){let A=l[F.bufferView],_=A?.byteOffset||0,d=A?.byteLength||0;A&&d>0&&_>=0&&_+d<=a.byteLength&&(z=new Uint8Array(a,_,d))}else typeof F.uri=="string"&&(z=M(F.uri));if(z&&z.byteLength>0){let A=z[0]===255&&z[1]===216&&z[2]===255||!(z[0]===137&&z[1]===80)&&/jpe?g/i.test(F.mimeType||F.uri||"");L={file:`texture_${C}.${A?"jpg":"png"}`,data:z}}x.set(C,L)}if(!L)return;let E=typeof N.sampler=="number"?p[N.sampler]:void 0,y=F=>F===33071?"clamp":F===33648?"mirror":"repeat";return{file:L.file,data:L.data,wrapS:y(E?.wrapS),wrapT:y(E?.wrapT),...D?{scale:D}:{},...I?{bias:I}:{}}}function m(S){let D=o[S];if(!D)throw new Error(`Accessor ${S} not found`);let I=l[D.bufferView||0],P=(I.byteOffset||0)+(D.byteOffset||0),N=I.byteLength||0;return{acc:D,buffer:a.slice(P,P+N)}}function v(S,D,I,P){let N=[],C=u[S];if(!C)return N;let L=C.primitives||[];for(let E=0;E<L.length;E++){let y=L[E],F=y.attributes?.POSITION;if(F===void 0)continue;let{acc:z,buffer:A}=m(F),_=new Float32Array(A,0,z.count*3),d,R=y.attributes?.NORMAL;if(R!==void 0){let{acc:U,buffer:$}=m(R),j=new Float32Array($,0,U.count*3);d=new Float32Array(j.length);for(let q=0;q<U.count;q++){let K=j[q*3],Q=j[q*3+1],te=j[q*3+2],fe=Math.hypot(K,Q,te)||1;d[q*3]=K/fe,d[q*3+1]=Q/fe,d[q*3+2]=te/fe}}let G,H=y.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:U,buffer:$}=m(H);G=new Float32Array($,0,U.count*2)}let B;if(y.indices!==void 0){let{acc:U,buffer:$}=m(y.indices);B=U.componentType===5125?new Uint32Array($,0,U.count):new Uint16Array($,0,U.count);let j=z.count;for(let q of B)if(q>=j)throw new Error(`SecurityError: Index buffer value (${q}) out of vertex bounds [0, ${j}).`)}else{let U=z.count;B=U>65535?new Uint32Array(U):new Uint16Array(U);for(let $=0;$<U;$++)B[$]=$}let Z="DefaultMaterial",k=[1,1,1],Y=.5,ie=0,re=0,O=0,J=1.5,V=1,W=[0,0,0],X;if(y.material!==void 0&&h[y.material]){let U=h[y.material];Z=T[y.material]||`Material_${y.material}`;let $=U.pbrMetallicRoughness||{},j=(Ne,Ee)=>Array.isArray(Ne)&&Ne.length>=3?[Ne[0],Ne[1],Ne[2]]:Ee;k=j($.baseColorFactor,[1,1,1]);let q=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,K=k[0]!==1||k[1]!==1||k[2]!==1||q!==1,Q=c($.baseColorTexture,K?[k[0],k[1],k[2],q]:void 0),te=U.extras?.avgColor;!Q&&Array.isArray(te)&&te.length>=3&&(k=[k[0]*te[0],k[1]*te[1],k[2]*te[2]]),typeof $.roughnessFactor=="number"&&(Y=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,se=typeof $.metallicFactor=="number"?$.metallicFactor:1,ae=c($.metallicRoughnessTexture,fe!==1||se!==1?[1,fe,se,1]:void 0);W=j(U.emissiveFactor,[0,0,0]);let oe=(W[0]>0||W[1]>0||W[2]>0)&&(W[0]!==1||W[1]!==1||W[2]!==1)?[W[0],W[1],W[2],1]:void 0,ce=c(U.emissiveTexture,oe),Te=c(U.normalTexture,[2,2,2,1],[-1,-1,-1,0]),Re=c(U.occlusionTexture);(Q||ae||Te||ce||Re)&&(X=[Q,ae,Te,ce,Re]);let me=U.extensions||{};me.KHR_materials_clearcoat&&(re=me.KHR_materials_clearcoat.clearcoatFactor??0,O=me.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof me.KHR_materials_ior?.ior=="number"&&(J=me.KHR_materials_ior.ior),V=q*(1-(me.KHR_materials_transmission?.transmissionFactor??0))}N.push({name:L.length>1?`${D}_p${E}`:D,positions:_,indices:B,normals:d,uvs:G,materialName:Z,color:k,roughness:Y,metallic:ie,clearcoat:re,clearcoatRoughness:O,ior:J,opacity:V,emissiveColor:W,...X?{textures:X}:{},xrTraits:I||C.extras?.xr,...P?{invisible:!0}:{}})}return N}if(f.length>0){let S=new Float32Array(0),D=new Uint16Array(0),I=(_,d)=>{if(_===void 0)return null;let{acc:R,buffer:G}=m(_);return new Float32Array(G,0,R.count*d)},P=(_,d)=>Array.isArray(_)&&_.length>=3?[ne(_[0],d),ne(_[1],d),ne(_[2],d)]:[d,d,d],N=(_,d,R)=>_&&_.length>=(d+1)*3?[_[d*3],_[d*3+1],_[d*3+2]]:R,C=(_,d,R)=>_&&_.length>=(d+1)*4?[_[d*4],_[d*4+1],_[d*4+2],_[d*4+3]]:R,L=new Map,E=r.animations?.[0];if(E&&Array.isArray(E.channels)&&Array.isArray(E.samplers))for(let _ of E.channels){let d=E.samplers[_?.sampler],R=_?.target?.node,G=_?.target?.path;if(!d||typeof R!="number"||d.input===void 0)continue;let H=L.get(R);H||(H={input:d.input},L.set(R,H)),G==="translation"?H.t=d.output:G==="rotation"?H.r=d.output:G==="scale"&&(H.s=d.output)}let y=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(y)||y.length===0){let _=new Set;for(let d of f)if(Array.isArray(d?.children))for(let R of d.children)_.add(R);y=[];for(let d=0;d<f.length;d++)_.has(d)||y.push(d);y.length===0&&(y=[0])}let F=new Set,z=[],A=(_,d)=>{if(Array.isArray(_))for(let R=_.length-1;R>=0;R--)z.push({idx:_[R],out:d})};for(A(y,i);z.length>0;){let{idx:_,out:d}=z.pop();if(typeof _!="number"||_<0||_>=f.length||F.has(_))continue;F.add(_);let R=f[_];if(!R)continue;let G=[0,0,0],H=[0,0,0,1],B=[1,1,1];if(Array.isArray(R.matrix)&&R.matrix.length===16){let V=ur(R.matrix);G=V.t,H=V.r,B=V.s}else G=P(R.translation,0),Array.isArray(R.rotation)&&R.rotation.length>=4&&(H=[ne(R.rotation[0],0),ne(R.rotation[1],0),ne(R.rotation[2],0),ne(R.rotation[3],1)]),B=P(R.scale,1);let Z,k=L.get(_);if(k){let V=I(k.input,1);if(V&&V.length>0){let W=I(k.t,3),X=I(k.r,4),U=I(k.s,3),$=Array.from(V),j=[],q=[],K=[];for(let Q=0;Q<V.length;Q++)j.push(N(W,Q,G)),q.push(C(X,Q,H)),K.push(N(U,Q,B));Z={times:$,translations:j,rotations:q,scales:K}}}let Y=Array.isArray(R.children)?R.children:[],ie=typeof R.mesh=="number"&&R.mesh>=0&&R.mesh<u.length,re=t?.[_]?.userData?.xr??R.extras?.xr;if(!ie&&Y.length===0&&(R.camera!==void 0||R.extensions?.KHR_lights_punctual||!R.name&&!R.extras&&!re&&!Z))continue;let O=(V,W,X)=>({name:V,positions:S,indices:D,isXform:!0,xrTraits:re,timeSamples:Z,translation:G,rotation:H,scale:B,children:W,...X?{invisible:!0}:{}}),J=R.visible===!1||R.extensions?.KHR_node_visibility?.visible===!1||t?.[_]?.visible===!1;if(ie){let V=R.name||u[R.mesh]?.name||`Mesh_${_}`,W=v(R.mesh,V,re,J),X=R.extensions?.EXT_mesh_gpu_instancing?.attributes;if(X&&typeof X=="object"&&W.length>0){let U=I(X.TRANSLATION,3),$=I(X.ROTATION,4),j=I(X.SCALE,3),q=I(X._COLOR_0,3),K=Math.min(1e3,U?U.length/3:$?$.length/4:j?j.length/3:0);if(K>0){let Q=[];for(let te=0;te<K;te++){let fe=N(U,te,[0,0,0]),se=C($,te,[0,0,0,1]),ae=N(j,te,[1,1,1]);for(let oe of W){let ce=oe.color||[.8,.8,.8],Te=q&&q.length>=(te+1)*3;Q.push({...oe,name:`${oe.name}_${te}`,materialName:Te?`${oe.materialName}_inst_${te}`:oe.materialName,color:Te?[ce[0]*q[te*3],ce[1]*q[te*3+1],ce[2]*q[te*3+2]]:oe.color,translation:fe,rotation:se,scale:ae})}}A(Y,Q),d.push(O(V,Q,J));continue}}if(W.length===1)W[0].translation=G,W[0].rotation=H,W[0].scale=B,W[0].timeSamples=Z,Y.length>0&&(W[0].children=[],A(Y,W[0].children)),d.push(W[0]);else{let U=[...W];A(Y,U),d.push(O(V,U,J))}}else{let V=[];A(Y,V),d.push(O(R.name||`Group_${_}`,V,J))}}}else for(let S=0;S<u.length;S++){let D=u[S].name||`Mesh_${S}`;i.push(...v(S,D,u[S].extras?.xr))}return i}function Ct(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function At(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ye(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var Le=(e,t,i)=>`(${ye(e)}, ${ye(t)}, ${ye(i)})`,Et=(e,t,i,r)=>`(${ye(e)}, ${ye(t)}, ${ye(i)}, ${ye(r)})`;function ar(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Le(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ai(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${ye(e[r*2])}, ${ye(1-e[r*2+1])})`;return i.join(", ")}function ci(e){return Array.from(e).join(", ")}function ui(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let p=s.pop();if(!p.isXform&&p.positions&&p.positions.length>0){let b=Ct(p.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:p.color||[1,1,1],roughness:p.roughness??.5,metallic:p.metallic??0,clearcoat:p.clearcoat??0,clearcoatRoughness:p.clearcoatRoughness??0,ior:p.ior??1.5,opacity:p.opacity??1,emissiveColor:p.emissiveColor||[0,0,0],textures:p.textures})}if(p.timeSamples&&p.timeSamples.times.length>0){let b=p.timeSamples.times[p.timeSamples.times.length-1];b>i&&(i=b)}if(p.xrTraits?.anchor&&!r&&(r=p.xrTraits.anchor==="vertical"||p.xrTraits.anchor==="wall"?"vertical":"horizontal"),p.children)for(let b=p.children.length-1;b>=0;b--)s.push(p.children[b])}let n="";i>0&&(n=`startTimeCode = 0
250
+ endTimeCode = ${ye(i)}
254
251
  timeCodesPerSecond = 1.0
255
- `);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
252
+ `);let a="";r&&(a=`uniform token preliminary:anchoring:type = "plane"
256
253
  uniform token preliminary:planeAnchoring:alignment = "${r}"
257
254
  `);let o=`#usda 1.0
258
255
  (
259
256
  defaultPrim = "Root"
260
257
  metersPerUnit = 1.0
261
258
  upAxis = "Y"
262
- ${i})
259
+ ${n})
263
260
 
264
261
  def Xform "Root" (
265
262
  kind = "component"
266
263
  )
267
264
  {
268
- ${s}def Scope "Materials"
265
+ ${a}def Scope "Materials"
266
+ {
267
+ `;for(let[p,b]of t.entries()){let[T,x,M]=b.color,[c,m,v]=b.emissiveColor,S=`/Root/Materials/${p}`,[D,I,P,N,C]=b.textures||[],L=(A,_)=>`.connect = <${S}/${A}.outputs:${_}>`,E=D?`color3f inputs:diffuseColor${L("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Le(T,x,M)}`,y=I?`float inputs:metallic${L("MetallicRoughnessTexture","b")}
268
+ float inputs:roughness${L("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${ye(b.metallic)}
269
+ float inputs:roughness = ${ye(b.roughness)}`,F="";b.clearcoat>0&&(F+=`float inputs:clearcoat = ${ye(b.clearcoat)}
270
+ `,F+=`float inputs:clearcoatRoughness = ${ye(b.clearcoatRoughness)}
271
+ `),b.ior!==1.5&&(F+=`float inputs:ior = ${ye(b.ior)}
272
+ `),b.opacity<1&&(F+=`float inputs:opacity = ${ye(b.opacity)}
273
+ `),N?F+=`color3f inputs:emissiveColor${L("EmissiveTexture","rgb")}
274
+ `:(c>0||m>0||v>0)&&(F+=`color3f inputs:emissiveColor = ${Le(c,m,v)}
275
+ `),P&&(F+=`normal3f inputs:normal${L("NormalTexture","rgb")}
276
+ `),C&&(F+=`float inputs:occlusion${L("OcclusionTexture","r")}
277
+ `);let z="";if(D||I||P||N||C){z+=`def Shader "PrimvarReader"
278
+ {
279
+ uniform token info:id = "UsdPrimvarReader_float2"
280
+ string inputs:varname = "st"
281
+ float2 outputs:result
282
+ }
283
+ `;let A=(_,d,R,G)=>{if(!d)return;let H=d.scale?`float4 inputs:scale = ${Et(d.scale[0],d.scale[1],d.scale[2],d.scale[3])}
284
+ `:"",B=d.bias?`float4 inputs:bias = ${Et(d.bias[0],d.bias[1],d.bias[2],d.bias[3])}
285
+ `:"";z+=`def Shader "${_}"
269
286
  {
270
- `;for(let[a,u]of e.entries()){let[c,h,m]=u.color,[b,g,d]=u.emissiveColor,w="";u.clearcoat>0&&(w+=`float inputs:clearcoat = ${j(u.clearcoat)}
271
- `,w+=`float inputs:clearcoatRoughness = ${j(u.clearcoatRoughness)}
272
- `),u.ior!==1.5&&(w+=`float inputs:ior = ${j(u.ior)}
273
- `),u.opacity<1&&(w+=`float inputs:opacity = ${j(u.opacity)}
274
- `),(b>0||g>0||d>0)&&(w+=`color3f inputs:emissiveColor = (${j(b)}, ${j(g)}, ${j(d)})
275
- `),o+=`def Material "${a}"
287
+ uniform token info:id = "UsdUVTexture"
288
+ asset inputs:file = @${At(d.file)}@
289
+ float2 inputs:st${L("PrimvarReader","result")}
290
+ token inputs:sourceColorSpace = "${R}"
291
+ token inputs:wrapS = "${d.wrapS||"repeat"}"
292
+ token inputs:wrapT = "${d.wrapT||"repeat"}"
293
+ ${H}${B}${G}}
294
+ `};A("DiffuseTexture",D,"sRGB",`float3 outputs:rgb
295
+ `),A("MetallicRoughnessTexture",I,"raw",`float outputs:g
296
+ float outputs:b
297
+ `),A("NormalTexture",P,"raw",`float3 outputs:rgb
298
+ `),A("EmissiveTexture",N,"sRGB",`float3 outputs:rgb
299
+ `),A("OcclusionTexture",C,"raw",`float outputs:r
300
+ `)}o+=`def Material "${p}"
276
301
  {
277
302
  def Shader "PBRShader"
278
303
  {
279
304
  uniform token info:id = "UsdPreviewSurface"
280
- color3f inputs:diffuseColor = (${j(c)}, ${j(h)}, ${j(m)})
281
- float inputs:metallic = ${j(u.metallic)}
282
- float inputs:roughness = ${j(u.roughness)}
283
- ${w}token outputs:surface
284
- }
285
- token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
305
+ ${E}
306
+ ${y}
307
+ ${F}token outputs:surface
286
308
  }
309
+ token outputs:surface${L("PBRShader","surface")}
310
+ ${z}}
287
311
  `}o+=`}
288
312
  def Scope "Meshes"
289
313
  {
290
- `;let l=new Set;for(let a=0;a<n.length;a++){let u=n[a],c=u.positions.length/3,h=1/0,m=1/0,b=1/0,g=-1/0,d=-1/0,w=-1/0;for(let D=0;D<c;D++){let v=u.positions[D*3],M=u.positions[D*3+1],I=u.positions[D*3+2];v<h&&(h=v),v>g&&(g=v),M<m&&(m=M),M>d&&(d=M),I<b&&(b=I),I>w&&(w=I)}isFinite(h)||(h=m=b=-1,g=d=w=1);let C=Math.floor(u.indices.length/3),N=Kt(u.materialName,"DefaultMaterial"),f=Kt(u.name,`Mesh_${a}`);l.has(f)&&(f=`${f}_${a}`),l.add(f);let E=C>0?C===1?"3":"3, ".repeat(C-1)+"3":"",x=u.xrTraits,_="";if(x){let D=[];x.physics&&x.physics!=="none"&&D.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let v=Q().xrTraitSerializer?.usdLines(x,En)??[];if(!v.length)for(let M of["grab","billboard","follow","anchor","physics"]){let I=M==="follow"&&typeof x.follow=="object"?x.follow.mode??"head":x[M];I!==void 0&&v.push(`string ${M} = "${En(I)}"`)}v.length>0&&D.push(`customData = {
314
+ `;let l=(p,b,T)=>{let x=[];b&&x.push('"MaterialBindingAPI"');let M=!!(p?.rigidBody&&p.rigidBody!=="none"&&(typeof p.rigidBody!="object"||p.rigidBody.enabled!==!1)),c=!!(p?.physics&&p.physics!=="none"||M);c&&x.push(...M?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let m=[];if(x.length>0&&m.push(`prepend apiSchemas = [${x.join(", ")}]`),p){let P=le().xrTraitSerializer?.usdLines(p,At)??[];if(!P.length)for(let N of["grab","billboard","follow","anchor","physics"]){let C=N==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[N];C!==void 0&&P.push(`string ${N} = "${At(C)}"`)}P.length>0&&m.push(`customData = {
291
315
  dictionary xr = {
292
- ${v.join(`
316
+ ${P.join(`
293
317
  `)}
294
318
  }
295
- }`),D.length>0&&(_=` (
296
- ${D.join(`
319
+ }`)}let v=m.length>0?` (
320
+ ${m.join(`
297
321
  `)}
298
- )`)}if(o+=`def Mesh "${f}"${_}
299
- {
300
- `,x?.physics&&x.physics!=="none"){let D=x.physics==="static"?"true":"false";o+=`bool physics:rigidBodyEnabled = true
301
- bool physics:kinematicEnabled = ${D}
322
+ )`:"",S=T?`uniform token visibility = "invisible"
323
+ `:"";if(c){let P=p?.rigidBody??p?.physics,N=P?.body??P?.mode??P;S+=`bool physics:rigidBodyEnabled = true
324
+ bool physics:kinematicEnabled = ${N==="static"||N==="kinematic"}
302
325
  bool physics:collisionEnabled = true
303
- `}if(u.timeSamples&&u.timeSamples.times.length>0){let D=u.timeSamples,v=D.times.map((p,y)=>{let A=D.translations?.[y]||[0,0,0];return`${j(p)}: (${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", "),M=D.times.map((p,y)=>{let A=D.rotations?.[y]||[0,0,0,1];return`${j(p)}: (${j(A[3])}, ${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", "),I=D.times.map((p,y)=>{let A=D.scales?.[y]||[1,1,1];return`${j(p)}: (${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", ");o+=`double3 xformOp:translate.timeSamples = { ${v} }
304
- quatf xformOp:orient.timeSamples = { ${M} }
326
+ `,P?.mass>0&&Number.isFinite(P.mass)&&(S+=`float physics:mass = ${ye(P.mass)}
327
+ `)}let D=lr(p),I=D?`def SpatialAudio "AudioEmitter"
328
+ {
329
+ ${D.src?`asset inputs:file = @${At(D.src)}@
330
+ `:""}uniform token inputs:auralMode = "${D.isGlobal?"nonSpatial":"spatial"}"
331
+ uniform token inputs:playbackMode = "${D.loop?"loopFromStart":"onceFromStart"}"
332
+ double gain = ${ye(D.volume)}
333
+ }
334
+ `:"";return{header:v,body:S,tail:I}},h=p=>{if(p.timeSamples&&p.timeSamples.times.length>0){let m=p.timeSamples,v=(P,N,C)=>m.times.map((L,E)=>`${ye(L)}: ${C(P?.[E]||N)}`).join(", "),S=v(m.translations,[0,0,0],P=>Le(P[0],P[1],P[2])),D=v(m.rotations,[0,0,0,1],P=>{let N=Math.hypot(P[0],P[1],P[2],P[3])||1;return Et(P[3]/N,P[0]/N,P[1]/N,P[2]/N)}),I=v(m.scales,[1,1,1],P=>Le(P[0],P[1],P[2]));return`double3 xformOp:translate.timeSamples = { ${S} }
335
+ quatf xformOp:orient.timeSamples = { ${D} }
305
336
  double3 xformOp:scale.timeSamples = { ${I} }
306
337
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
307
- `}o+=`float3[] extent = [(${j(h)}, ${j(m)}, ${j(b)}), (${j(g)}, ${j(d)}, ${j(w)})]
308
- int[] faceVertexCounts = [${E}]
309
- int[] faceVertexIndices = [${gr(u.indices)}]
310
- point3f[] points = [${Rn(u.positions)}]
311
- `,u.normals&&u.normals.length===u.positions.length&&(o+=`normal3f[] normals = [${Rn(u.normals)}] (
338
+ `}let b=[],T="",x=p.translation;x&&(Math.abs(x[0])>1e-7||Math.abs(x[1])>1e-7||Math.abs(x[2])>1e-7)&&(T+=`double3 xformOp:translate = ${Le(x[0],x[1],x[2])}
339
+ `,b.push('"xformOp:translate"'));let M=p.rotation;if(M){let m=Math.hypot(M[0],M[1],M[2],M[3])||1,v=M[0]/m,S=M[1]/m,D=M[2]/m,I=M[3]/m;(1-Math.abs(I)>1e-7||Math.hypot(v,S,D)>1e-7)&&(T+=`quatf xformOp:orient = ${Et(I,v,S,D)}
340
+ `,b.push('"xformOp:orient"'))}let c=p.scale;return c&&(Math.abs(c[0]-1)>1e-7||Math.abs(c[1]-1)>1e-7||Math.abs(c[2]-1)>1e-7)&&(T+=`float3 xformOp:scale = ${Le(c[0],c[1],c[2])}
341
+ `,b.push('"xformOp:scale"')),b.length>0&&(T+=`uniform token[] xformOpOrder = [${b.join(", ")}]
342
+ `),T},u=p=>{let b=p.positions.length/3,T=1/0,x=1/0,M=1/0,c=-1/0,m=-1/0,v=-1/0;for(let N=0;N<b;N++){let C=p.positions[N*3],L=p.positions[N*3+1],E=p.positions[N*3+2];C<T&&(T=C),C>c&&(c=C),L<x&&(x=L),L>m&&(m=L),E<M&&(M=E),E>v&&(v=E)}isFinite(T)||(T=x=M=-1,c=m=v=1);let S=Math.floor(p.indices.length/3),D=Ct(p.materialName,"DefaultMaterial"),I=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",P=`float3[] extent = [${Le(T,x,M)}, ${Le(c,m,v)}]
343
+ int[] faceVertexCounts = [${I}]
344
+ int[] faceVertexIndices = [${ci(p.indices)}]
345
+ point3f[] points = [${ar(p.positions)}]
346
+ `;return p.normals&&p.normals.length===p.positions.length&&(P+=`normal3f[] normals = [${ar(p.normals)}] (
312
347
  interpolation = "vertex"
313
348
  )
314
- `),u.uvs&&u.uvs.length===c*2&&(o+=`texCoord2f[] primvars:st = [${yr(u.uvs,c)}] (
349
+ `),p.uvs&&p.uvs.length===b*2&&(P+=`texCoord2f[] primvars:st = [${ai(p.uvs,b)}] (
315
350
  interpolation = "vertex"
316
351
  )
317
- `),o+=`rel material:binding = </Root/Materials/${N}>
318
- }
319
- `}return o+=`}
352
+ `),P+=`rel material:binding = </Root/Materials/${D}>
353
+ `,P},f=new Set,g=[];for(let p=e.length-1;p>=0;p--)g.push({node:e[p],siblings:f});let w=0;for(;g.length>0;){let p=g.pop();if(p.close){o+=`}
354
+ `;continue}let{node:b,siblings:T}=p,x=!!(b.isXform||b.positions.length===0),M=cr(T,Ct(b.name,x?`Group_${w}`:`Mesh_${w}`));w++;let c=b.children||[];if(x){let m=l(b.xrTraits,!1,b.invisible);o+=`def Xform "${M}"${m.header}
355
+ {
356
+ ${m.body}${h(b)}${m.tail}`,g.push({close:!0});let v=new Set;for(let S=c.length-1;S>=0;S--)g.push({node:c[S],siblings:v})}else if(c.length>0){let m=l(b.xrTraits,!1,b.invisible),v=`${M}_mesh`;o+=`def Xform "${M}"${m.header}
357
+ {
358
+ ${m.body}${h(b)}${m.tail}`,o+=`def Mesh "${v}" (
359
+ prepend apiSchemas = ["MaterialBindingAPI"]
360
+ )
361
+ {
362
+ ${u(b)}}
363
+ `,g.push({close:!0});let S=new Set([v]);for(let D=c.length-1;D>=0;D--)g.push({node:c[D],siblings:S})}else{let m=l(b.xrTraits,!0,b.invisible);o+=`def Mesh "${M}"${m.header}
364
+ {
365
+ ${m.body}${h(b)}${u(b)}${m.tail}}
366
+ `}}return o+=`}
320
367
  }
321
- `,o}function xr(n,e){if(n&&typeof n.traverse=="function"){let i=br(n,e);return qt(i)}let t=Ue(n),r=_n(t);return qt(r)}var ut=null;function vr(n){if(!ut){ut=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;ut[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=ut[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Sn(n){let e=[],t=0,r=[];for(let c of n){let h=lt(c.filename),m=vr(c.data),b=c.data.length,g=30+h.length,d=t+g,w=0,C=d%64;C!==0&&(w=64-C);let N=new Uint8Array(g+w),f=new DataView(N.buffer);f.setUint32(0,67324752,!0),f.setUint16(4,20,!0),f.setUint16(6,0,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint32(14,m,!0),f.setUint32(18,b,!0),f.setUint32(22,b,!0),f.setUint16(26,h.length,!0),f.setUint16(28,w,!0),N.set(h,30),w>0&&N.fill(0,30+h.length),e.push({offset:t,size:b,crc:m,filenameBytes:h,entry:c}),r.push(N),r.push(c.data),t+=N.length+c.data.length}let i=t;for(let c of e){let h=new Uint8Array(46+c.filenameBytes.length),m=new DataView(h.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint16(14,0,!0),m.setUint32(16,c.crc,!0),m.setUint32(20,c.size,!0),m.setUint32(24,c.size,!0),m.setUint16(28,c.filenameBytes.length,!0),m.setUint16(30,0,!0),m.setUint16(32,0,!0),m.setUint16(34,0,!0),m.setUint16(36,0,!0),m.setUint32(38,0,!0),m.setUint32(42,c.offset,!0),h.set(c.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,o=new Uint8Array(22),l=new DataView(o.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,s,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(o),t+=22;let a=new Uint8Array(t),u=0;for(let c of r)a.set(c,u),u+=c.length;return a}function Pe(n){let e=xr(n),t=lt(e);return Sn([{filename:"model.usda",data:t}])}function mt(n){let e=Ue(n),t=_n(e),r=qt(t),i=lt(r);return Sn([{filename:"model.usda",data:i}])}function Zt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Pe(n):mt(n)}var ft=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}},te=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,o=t.x,l=t.y,a=t.z;return this.x=i*a-s*l,this.y=s*o-r*a,this.z=r*l-i*o,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)}lerp(e,t){return this.lerpVectors(this,e,t)}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,o=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])*o,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*o,this}},dt=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}},Ge=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}},He=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,o=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(s/2),u=Math.sin(r/2),c=Math.sin(i/2),h=Math.sin(s/2);return this._x=u*l*a+o*c*h,this._y=o*c*a-u*l*h,this._z=o*l*h+u*c*a,this._w=o*l*a-u*c*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this.set(e.x*i,e.y*i,e.z*i,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z,e.x*t.y-e.y*t.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,o=e.w,l=t.x,a=t.y,u=t.z,c=t.w;return this._x=r*c+o*l+i*u-s*a,this._y=i*c+o*a+s*l-r*u,this._z=s*c+o*u+r*a-i*l,this._w=o*c-r*l-i*a-s*u,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Ee=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 we(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 ee(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return De(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 te(0,0,0),r=new te(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}},pt=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 me(this.elements,e.elements),this}},de=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)}},Pn={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)},le=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}},bt=class extends le{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},yt=class extends le{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},gt=class extends le{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},he=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 le)this.index=e;else if(Array.isArray(e)){let t=0;for(let r of e)r>t&&(t=r);this.index=new le(new(t>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new le(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 te,s=new te,o=new te,l=new te,a=new te;if(this.index){let u=this.index.array;for(let c=0;c<u.length;c+=3){let h=u[c],m=u[c+1],b=u[c+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(b),e.getY(b),e.getZ(b)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let g of[h,m,b])r[g*3]+=l.x,r[g*3+1]+=l.y,r[g*3+2]+=l.z}}else for(let u=0;u<t;u+=3){i.set(e.getX(u),e.getY(u),e.getZ(u)),s.set(e.getX(u+1),e.getY(u+1),e.getZ(u+1)),o.set(e.getX(u+2),e.getY(u+2),e.getZ(u+2)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let c=0;c<3;c++)r[(u+c)*3]=l.x,r[(u+c)*3+1]=l.y,r[(u+c)*3+2]=l.z}for(let u=0;u<t;u++){let c=r[u*3],h=r[u*3+1],m=r[u*3+2],b=Math.hypot(c,h,m)||1;r[u*3]=c/b,r[u*3+1]=h/b,r[u*3+2]=m/b}return this.setAttribute("normal",new le(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new le(e,3)),this.setAttribute("normal",new le(t,3)),this.setAttribute("uv",new le(r,2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,t=new te(1/0,1/0,1/0),r=new te(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let s=e.getX(i),o=e.getY(i),l=e.getZ(i);s<t.x&&(t.x=s),o<t.y&&(t.y=o),l<t.z&&(t.z=l),s>r.x&&(r.x=s),o>r.y&&(r.y=o),l>r.z&&(r.z=l)}else t.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:t,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),t=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,s=this.attributes.position;if(s&&s.count>0){for(let o=0;o<s.count;o++)s.setXYZ(o,s.getX(o)-t,s.getY(o)-r,s.getZ(o)-i);this.computeBoundingBox()}return this}dispose(){}},Xe=class extends he{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,o=r/2,l=[-i,-s,o,i,-s,o,i,s,o,-i,s,o,i,-s,-o,-i,-s,-o,-i,s,-o,i,s,-o,-i,s,o,i,s,o,i,s,-o,-i,s,-o,-i,-s,-o,i,-s,-o,i,-s,o,-i,-s,o,i,-s,o,i,-s,-o,i,s,-o,i,s,o,-i,-s,-o,-i,-s,o,-i,s,o,-i,s,-o],a=[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],u=[],c=[];for(let h=0;h<6;h++){let m=h*4;u.push(0,0,1,0,1,1,0,1),c.push(m,m+1,m+2,m,m+2,m+3)}this.setFromBuffers(l,a,u,c)}},xt=class extends he{constructor(e=1,t=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let s=[],o=[],l=[],a=[];for(let u=0;u<=i;u++){let c=u/i;for(let h=0;h<=r;h++){let m=h/r;if(s.push((m-.5)*e,(.5-c)*t,0),o.push(0,0,1),l.push(m,1-c),u>0&&h>0){let b=(r+1)*u+h-1,g=b-(r+1);a.push(g,b,g+1,b,b+1,g+1)}}}this.setFromBuffers(s,o,l,a)}},We=class extends he{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=[],o=[],l=[];for(let a=0;a<=r;a++){let u=a/r;for(let c=0;c<=t;c++){let h=c/t,m=h*Math.PI*2,b=u*Math.PI,g=-Math.cos(m)*Math.sin(b),d=Math.cos(b),w=Math.sin(m)*Math.sin(b);if(i.push(e*g,e*d,e*w),s.push(g,d,w),o.push(h,1-u),a>0&&c>0){let C=(t+1)*a+c,N=C-(t+1),f=N-1,E=C-1;a!==1&&l.push(N,f,C),a!==r&&l.push(f,E,C)}}}this.setFromBuffers(i,s,o,l)}},Me=class extends he{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],o=[],l=[],a=[],u=r/2;for(let c=0;c<=1;c++){let h=c,m=c===0?e:t,b=c===0?u:-u;for(let g=0;g<=i;g++){let d=g/i,w=d*Math.PI*2,C=Math.sin(w),N=Math.cos(w);s.push(m*C,b,m*N),o.push(C,0,N),l.push(d,1-h)}}for(let c=0;c<i;c++){let h=c,m=c+i+1,b=c+i+2,g=c+1;a.push(h,m,g,m,b,g)}if(e>0){let c=s.length/3;s.push(0,u,0),o.push(0,1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,g=Math.sin(b),d=Math.cos(b);s.push(e*g,u,e*d),o.push(0,1,0),l.push(d*.5+.5,g*.5+.5)}for(let m=0;m<i;m++)a.push(c,h+m,h+m+1)}if(t>0){let c=s.length/3;s.push(0,-u,0),o.push(0,-1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,g=Math.sin(b),d=Math.cos(b);s.push(t*g,-u,t*d),o.push(0,-1,0),l.push(d*.5+.5,1-(g*.5+.5))}for(let m=0;m<i;m++)a.push(c,h+m+1,h+m)}this.setFromBuffers(s,o,l,a)}},vt=class extends Me{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Mt=class extends he{constructor(e=1,t=.4,r=12,i=48,s=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],l=[],a=[],u=[];for(let c=0;c<=r;c++){let h=c/r*Math.PI*2,m=Math.cos(h),b=Math.sin(h);for(let g=0;g<=i;g++){let d=g/i*s,w=Math.cos(d),C=Math.sin(d);if(o.push((e+t*m)*w,(e+t*m)*C,t*b),l.push(m*w,m*C,b),a.push(g/i,c/r),c>0&&g>0){let N=(i+1)*c+g-1,f=N-(i+1);u.push(N,f,N+1,f,f+1,N+1)}}}this.setFromBuffers(o,l,a,u)}},Tt=class extends he{constructor(e=1,t=.4,r=64,i=8,s=2,o=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],a=[],u=[],c=[],h=new te,m=new te,b=new te,g=new te,d=new te;function w(f,E){let x=Math.cos(E),_=Math.sin(E),D=o/s*E,v=e*(2+Math.cos(D))*.5;f.set(v*x,v*_,e*Math.sin(D)*.5)}let C=[];for(let f=0;f<=i;++f){let E=f/i*Math.PI*2;C.push(-t*Math.cos(E),t*Math.sin(E),f/i)}for(let f=0;f<=r;++f){let E=f/r,x=E*s*Math.PI*2;w(h,x),w(m,x+.01),b.subVectors(m,h).normalize(),g.addVectors(h,m).normalize(),d.crossVectors(b,g).normalize(),g.crossVectors(d,b).normalize();for(let _=0;_<=i;++_){let D=_*3,v=C[D],M=C[D+1],I=C[D+2],p=v*g.x+M*d.x,y=v*g.y+M*d.y,A=v*g.z+M*d.z;l.push(h.x+p,h.y+y,h.z+A);let T=Math.hypot(p,y,A)||1;a.push(p/T,y/T,A/T),u.push(E,I)}}let N=i+1;for(let f=1;f<=r;f++){let E=N*(f-1),x=E+N;for(let _=1;_<=i;_++){let D=E+(_-1),v=x+(_-1),M=x+_,I=E+_;c.push(D,v,I,v,M,I)}}this.setFromBuffers(l,a,u,c)}},$e=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(){}},wt=class{load(e,t){let r=new $e(e);return t?.(r),r}};function ue(n,e){return n!==void 0?Number(n):e}function Jt(n,e){return n!==void 0?!!n:e}var ye=class{constructor(e={}){this.name=e.name||"",this.color=new de(e.color!==void 0?e.color:16777215),this.emissive=new de(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ue(e.emissiveIntensity,1),this.roughness=ue(e.roughness,.5),this.metalness=ue(e.metalness,.1),this.opacity=ue(e.opacity,1),this.transparent=Jt(e.transparent,!1),this.wireframe=Jt(e.wireframe,!1),this.side=ue(e.side,2),this.doubleSided=Jt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ue(e.clearcoat,0),this.clearcoatRoughness=ue(e.clearcoatRoughness,0),this.sheen=ue(e.sheen,0),this.sheenColor=new de(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ue(e.sheenRoughness,0),this.transmission=ue(e.transmission,0),this.thickness=ue(e.thickness,0),this.attenuationColor=new de(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ue(e.attenuationDistance,1/0),this.ior=ue(e.ior,1.5),this.dispersion=ue(e.dispersion,0),this.iridescence=ue(e.iridescence,0),this.iridescenceIOR=ue(e.iridescenceIOR,1.3)}dispose(){}},Re=class extends ye{},Et=class extends ye{},Rt=class extends ye{},_t=class extends ye{},St=class extends ye{},pe=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 te,this.rotation=new Ge,this.quaternion=new He,this.scale=new te(1,1,1),this.matrix=new Ee,this.matrixWorld=new Ee,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){Fn(this),(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 te(e,t,r);this.updateMatrixWorld(!0);let s=new Ee;s.lookAt(this.position,i,new te(0,1,0));let o=s.elements,l=o[0],a=o[4],u=o[8],c=o[1],h=o[5],m=o[9],b=o[2],g=o[6],d=o[10],w=l+h+d;if(w>0){let C=.5/Math.sqrt(w+1);this.quaternion.set((g-m)*C,(u-b)*C,(c-a)*C,.25/C)}}},At=class extends pe{},_e=class extends pe{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof he?t:t?(fe("unsupported geometry","BoxGeometry"),new Xe(.5,.5,.5)):new he,this.material=i instanceof ye?i:i?(fe("unsupported material","MeshStandardMaterial"),new Re({color:13421772})):new Re}};function Fn(n){let e=Q().materializeDeclarativeGeometry;typeof e=="function"&&e(n)}var Ye=1e4,je=class extends _e{constructor(t,r,i=1){super(t,r);this.instanceColor=null;this.isInstancedMesh=!0;let s=Number(i);if(!Number.isFinite(s)||s<0||s>Ye)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Ye})`);this.count=Math.floor(s);let o=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;o[a]=1,o[a+5]=1,o[a+10]=1,o[a+15]=1}this.instanceMatrix=new le(o,16)}setMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);s[o+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++)r.elements[l]=s[o+l]}setColorAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let l=new Float32Array(this.count*3);l.fill(1),this.instanceColor=new le(l,3)}let s=this.instanceColor.array,o=i*3;s[o]=Number.isFinite(r.r)?r.r:1,s[o+1]=Number.isFinite(r.g)?r.g:1,s[o+2]=Number.isFinite(r.b)?r.b:1}getColorAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let s=this.instanceColor.array,o=i*3;r.setRGB(s[o],s[o+1],s[o+2])}dispose(){}},Se=class extends pe{constructor(e=16777215,t=1){super(),this.color=new de(e),this.intensity=Number(t),this.type="directional"}},Ke=class extends Se{constructor(e,t){super(e,t),this.type="ambient"}},Ct=class extends Se{constructor(t,r){super(t,r);this.target=new pe;this.type="directional"}},qe=class extends Se{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}},Ze=class extends pe{},It=class extends Ze{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new te(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},Je=class extends pe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return be.validate(this),Ne(this)}toGLB(){return be.validate(this),Oe(this)}toUSDZ(){return be.validate(this),Pe(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof _e){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},Qt=Ne,en=Oe,kn=Pe;var be=class{static validate(e){let t=0,r=0,i=0,s=new Set,o=(a,u,c)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${u}). Found: ${c}`)},l=(a,u)=>{if(!Number.isFinite(u))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(u)}), which cannot be bounds-checked.`);return u};e.traverse(a=>{if(Fn(a),a instanceof _e||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&o("MESHES",1e3,i),a instanceof je){let c=l("instance",a.count);(c<0||c>Ye)&&o("INSTANCES",Ye,c)}let u=a.geometry;if(u){let c=0;if(u.attributes.position&&(c=l("vertex",u.attributes.position.count),t+=c,t>1e5&&o("VERTICES",1e5,t)),u.index){let h=l("index",u.index.count);r+=h,r>3e5&&o("INDICES",3e5,r);let m=u.index.array;if(m&&c>0){let b=Math.min(h,m.length);for(let g=0;g<b;g++){let d=m[g];if(!Number.isFinite(d)||d<0||d>=c)throw new Error(`SecurityError: Index buffer value (${String(d)}) out of vertex bounds [0, ${c}).`)}}}}if(a.material){let c=a.material;c.map&&s.add(c.map),c.normalMap&&s.add(c.normalMap),c.roughnessMap&&s.add(c.roughnessMap)}}}),s.size>16&&o("TEXTURES",16,s.size);for(let a of s){let u=a,c=u.image,h=Number(c?.width??u.width??0)||0,m=Number(c?.height??u.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(m)||h>2048||m>2048)&&o("TEXTURE_DIMENSION",2048,Math.max(h,m))}}},Dt=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 de(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){be.validate(e);let i=(s,o)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(o&&o.length?self.postMessage(s,o):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),o={};for(let[l,a]of s.entries())o[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:o})}else{this.hasInitialModelRendered=!0;let s=Qt(e),o=en(e),l=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:o.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[o.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 An(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Lt=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=An(),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=An();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Mr(){}var Ve=new Proxy(Mr,{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:Ve},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ve,construct:()=>Ve}),Cn=(()=>{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 Fe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Te(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Fe());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 In,Be;function Un(n){if(!Te(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(Be===void 0||In!==t){In=t;try{Be=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Te(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Be=null}}return Be?Be.createScriptURL(n):n}function Tr(n){Q().sandboxEngineSrc=n}function tn(){let n=Q().sandboxEngineSrc;if(n)return n;if(Cn)return Cn;try{if(typeof document>"u")return null;let e=Fe(),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)&&Te(i,{requireSameOrigin:!0}))return i}}catch{}return null}function wr(){let n=tn();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(!Te(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,Fe()).href}function Er(n){Q().sandboxIframeSrc=n}function On(){let n=Q().sandboxIframeSrc;if(n)return n;let e=tn();if(!e||!Te(e))return null;let t=new URL(e,Fe());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Rr(){let n=On();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(!Te(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,Fe()).href}function _r(n){Q().allowClientScripts=n}function Bn(){return!!Q().allowClientScripts}function Sr(n){if(!Te(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,Fe()).href}var Ar=["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 Cr(n,e){let t=self,r=n.nonce,i=n.engineSrc,s=n.allowedScriptUrl,o=n.allowClientScripts,l=n.revoked,a=t.postMessage.bind(t);function u(_){a({type:"ERROR",nonce:r,message:String(_)})}let c=typeof t.importScripts=="function"?t.importScripts.bind(t):null,h=s,m=null;try{let _=i;if(typeof t.trustedTypes<"u"&&t.trustedTypes&&typeof t.trustedTypes.createPolicy=="function")try{let D={createScriptURL:function(M){if(M!==i&&(!s||M!==s))throw new TypeError("Disallowed worker importScripts URL");return M}};o&&(D.createScript=function(M){return String(M)});let v=t.trustedTypes.createPolicy("three-live#worker-boot",D);_=v.createScriptURL(i),s&&(h=v.createScriptURL(s)),o&&typeof v.createScript=="function"&&(m=v.createScript.bind(v))}catch{}c(_)}catch(_){u('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(_&&_.message||_));return}let b=t.THREE;if(!b||typeof b.Scene!="function"){u('Sandbox loaded "'+i+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(e)){let _=t.__THREE_LIVE_REGISTRY__;for(let D=0;D<e.length;D++)if(typeof e[D]=="function")try{e[D](b,_)}catch{}}for(let _=0;_<l.length;_++){let D=l[_],v=t;for(;v&&v!==Object.prototype;){if(v!==t)try{delete v[D]}catch{}try{Object.defineProperty(v,D,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{v=Object.getPrototypeOf(v)}catch{break}}}let g=Object.freeze({now:function(){return Date.now()}}),d=t;for(;d&&d!==Object.prototype;){if(d!==t)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:g,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let w=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],C=!1;function N(_,D){if(_.type==="3D_MODEL_READY"){if(C)return;C=!0}_.nonce=r,D&&D.length?a(_,D):a(_)}let f=function(_,D){if(!_||w.indexOf(_.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+w.join(", ")+").");N(_,D)},E=t;for(;E&&E!==Object.prototype;){if(E===t||Object.prototype.hasOwnProperty.call(E,"postMessage"))try{Object.defineProperty(E,"postMessage",{value:f,writable:!1,configurable:!1})}catch{}try{E=Object.getPrototypeOf(E)}catch{break}}let x=!1;t.onmessage=function(_){let D=_&&_.data;if(!(!D||D.nonce!==r)&&!(D.type!=="EXECUTE"&&D.type!=="EXECUTE_URL")&&!x){x=!0;try{let v=new b.Scene,M=new b.PerspectiveCamera(60,1,.1,1e3),I=new b.WebGLRenderer({isSandboxed:!0});if(D.type==="EXECUTE_URL"){if(!s||D.scriptUrl!==s||typeof c!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let p=h||s,y=c;if(c=null,h=null,t.THREE=b,t.scene=v,t.camera=M,t.renderer=I,y(p),typeof t.__THREE_LIVE_SCENE__=="function"){let A=t.__THREE_LIVE_SCENE__(b,v,M,I);A&&typeof A.toGLB=="function"&&(v=A)}else t.scene&&typeof t.scene.toGLB=="function"&&(v=t.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let p=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
368
+ `,o}var Rt=null;function Dt(e){if(!Rt){Rt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;Rt[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=Rt[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function li(e){let t=[],i=0,r=[];for(let u of e){let f=Nn(u.filename),g=Dt(u.data),w=u.data.length,p=30+f.length,b=(i+p)%64,T=b!==0?64-b:0;T>0&&T<4&&(T+=64);let x=new Uint8Array(p+T),M=new DataView(x.buffer);M.setUint32(0,67324752,!0),M.setUint16(4,20,!0),M.setUint32(14,g,!0),M.setUint32(18,w,!0),M.setUint32(22,w,!0),M.setUint16(26,f.length,!0),M.setUint16(28,T,!0),x.set(f,30),T>=4&&(M.setUint16(p,6534,!0),M.setUint16(p+2,T-4,!0)),t.push({offset:i,size:w,crc:g,filenameBytes:f,entry:u}),r.push(x,u.data),i+=x.length+u.data.length}let s=i;for(let u of t){let f=new Uint8Array(46+u.filenameBytes.length),g=new DataView(f.buffer);g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint32(16,u.crc,!0),g.setUint32(20,u.size,!0),g.setUint32(24,u.size,!0),g.setUint16(28,u.filenameBytes.length,!0),g.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,n,!0),o.setUint32(16,s,!0),r.push(a),i+=22;let l=new Uint8Array(i),h=0;for(let u of r)l.set(u,h),h+=u.length;return l}function fr(e){let t=[{filename:"model.usda",data:Nn(ui(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let s=r.pop();for(let n of s.textures||[])n?.file&&n.data?.byteLength&&!i.has(n.file)&&(i.add(n.file),t.push({filename:n.file,data:n.data}));if(s.children)for(let n=s.children.length-1;n>=0;n--)r.push(s.children[n])}return li(t)}function nt(e){return fr(oi(e))}function It(e){return fr(hr(wt(e)))}function Ln(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():It(e)}var Se=class Pi{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new Pi(this.x,this.y)}copy(t){return this.set(t.x,t.y)}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},ee=class Ni{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Ni(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,i){return this.set(t.x+i.x,t.y+i.y,t.z+i.z)}sub(t){return this.subVectors(this,t)}subVectors(t,i){return this.set(t.x-i.x,t.y-i.y,t.z-i.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.set(this.x+t.x*i,this.y+t.y*i,this.z+t.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,a=i.x,o=i.y,l=i.z;return this.set(s*l-n*o,n*a-r*l,r*o-s*a)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,a=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*a,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*a,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*a,this}},kt=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},ot=class Li{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new Li(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ye=class Ii{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new Ii(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,a=Math.cos(r/2),o=Math.cos(s/2),l=Math.cos(n/2),h=Math.sin(r/2),u=Math.sin(s/2),f=Math.sin(n/2);return this._x=h*o*l+a*u*f,this._y=a*u*l-h*o*f,this._z=a*o*f+h*u*l,this._w=a*o*l-h*u*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,a=t.w,o=i.x,l=i.y,h=i.z,u=i.w;return this._x=r*u+a*o+s*h-n*l,this._y=s*u+a*l+n*o-r*h,this._z=n*u+a*h+r*l-s*o,this._w=a*u-r*o-s*l-n*h,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Be=class Fi{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new Fi;return t.copy(this),t}compose(t,i,r){return Qe(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return be(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return We(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new ee(0,0,0),r=new ee(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Ut=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return Ce(this.elements,e.elements),this}},ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Nt=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,dr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},we=class Ui{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in dr)this.setHex(dr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>ve(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=ve(r);return this.setRGB(o,o,o)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?n+(s-n)*6*o:o<1/2?s:o<2/3?n+(s-n)*6*(2/3-o):n);return this.setRGB(ve(a(t+1/3)),ve(a(t)),ve(a(t-1/3)))}lerp(t,i){return this.lerpColors(this,t,i)}lerpColors(t,i,r){let s=Number(r)||0;return this.setRGB(t.r+(i.r-t.r)*s,t.g+(i.g-t.g)*s,t.b+(i.b-t.b)*s)}multiplyScalar(t){let i=Number(t)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.setRGB(ve((i>>16&255)/255),ve((i>>8&255)/255),ve((i&255)/255))}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(ve(this.r),ve(this.g),ve(this.b))}convertLinearToSRGB(){return this.setRGB(Nt(this.r),Nt(this.g),Nt(this.b))}getHex(){let t=i=>Math.round(Nt(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Ui(this.r,this.g,this.b)}},Tr={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},ge=class ki{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;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/i)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new ki(new t(this.array),this.itemSize)}},Ot=class extends ge{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},Bt=class extends ge{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Vt=class extends ge{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},de=class Oi{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof ge)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new ge(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new ge(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=!1;if(typeof i=="function"){let l=i(t.array,this.index?.array);return this.setAttribute("normal",new ge(l,3)),this}let r=t.count,s=t.array,n=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let h=(a?a[l]:l)*3,u=(a?a[l+1]:l+1)*3,f=(a?a[l+2]:l+2)*3,g=s[u],w=s[u+1],p=s[u+2],b=s[f]-g,T=s[f+1]-w,x=s[f+2]-p,M=s[h]-g,c=s[h+1]-w,m=s[h+2]-p,v=T*m-x*c,S=x*M-b*m,D=b*c-T*M;n[h]+=v,n[h+1]+=S,n[h+2]+=D,n[u]+=v,n[u+1]+=S,n[u+2]+=D,n[f]+=v,n[f+1]+=S,n[f+2]+=D}for(let l=0;l<r*3;l+=3){let h=n[l],u=n[l+1],f=n[l+2],g=Math.hypot(h,u,f)||1;n[l]=h/g,n[l+1]=u/g,n[l+2]=f/g}return this.setAttribute("normal",new ge(n,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new ge(t,3)),this.setAttribute("normal",new ge(i,3)),this.setAttribute("uv",new ge(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new ge(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new ee(1/0,1/0,1/0),r=new ee(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),a=t.getY(s),o=t.getZ(s);n<i.x&&(i.x=n),a<i.y&&(i.y=a),o<i.z&&(i.z=o),n>r.x&&(r.x=n),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let h=o[l+t],u=o[l+i];o[l+t]=h*s-u*n,o[l+i]=h*n+u*s}a.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new ee;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new Oi;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},at=class extends de{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,a=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],o=[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],l=[],h=[];for(let u=0;u<6;u++){let f=u*4;l.push(0,0,1,0,1,1,0,1),h.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(a,o,l,h)}},zt=class extends de{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],a=[],o=[];for(let l=0;l<=r;l++){let h=l/r;for(let u=0;u<=i;u++){let f=u/i;if(s.push((f-.5)*e,(.5-h)*t,0),n.push(0,0,1),a.push(f,1-h),l>0&&u>0){let g=(i+1)*l+u-1,w=g-(i+1);o.push(w,g,w+1,g,g+1,w+1)}}}this.setFromBuffers(s,n,a,o)}},Gt=class extends de{constructor(e=1,t=16,i=12,r=0,s=Math.PI*2,n=0,a=Math.PI){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let o=[],l=[],h=[],u=[],f=Math.min(n+a,Math.PI);for(let g=0;g<=i;g++){let w=g/i,p=n+w*a;for(let b=0;b<=t;b++){let T=b/t,x=r+T*s,M=-Math.cos(x)*Math.sin(p),c=Math.cos(p),m=Math.sin(x)*Math.sin(p);if(o.push(e*M,e*c,e*m),l.push(M,c,m),h.push(T,1-w),g>0&&b>0){let v=(t+1)*g+b,S=v-(t+1),D=S-1,I=v-1;(g!==1||n>0)&&u.push(S,D,v),(g!==i||f<Math.PI)&&u.push(D,I,v)}}}this.setFromBuffers(o,l,h,u)}},ct=class extends de{constructor(e=1,t=1,i=1,r=16,s=1,n=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1));let l=[],h=[],u=[],f=[],g=i/2,w=(t-e)/(i||1),p=r+1;for(let T=0;T<=s;T++){let x=T/s,M=x*(t-e)+e,c=g-x*i;for(let m=0;m<=r;m++){let v=m/r,S=a+v*o,D=Math.sin(S),I=Math.cos(S),P=Math.hypot(D,w,I)||1;if(l.push(M*D,c,M*I),h.push(D/P,w/P,I/P),u.push(v,1-x),T<s&&m<r){let N=T*p+m,C=N+p;f.push(N,C,N+1,C,C+1,N+1)}}}let b=(T,x)=>{if(n||T<=0)return;let M=x*g,c=l.length/3;l.push(0,M,0),h.push(0,x,0),u.push(.5,.5);let m=c+1;for(let v=0;v<=r;v++){let S=a+v/r*o,D=Math.sin(S),I=Math.cos(S);l.push(T*D,M,T*I),h.push(0,x,0),u.push(I*.5+.5,.5+x*D*.5),v<r&&f.push(c,m+v+(x>0?0:1),m+v+(x>0?1:0))}};b(e,1),b(t,-1),this.setFromBuffers(l,h,u,f)}},Ht=class extends ct{constructor(e=1,t=1,i=16,r=1,s=!1,n=0,a=Math.PI*2){super(0,e,t,i,r,s,n,a)}},$t=class extends de{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],a=[],o=[],l=[];for(let h=0;h<=i;h++){let u=h/i*Math.PI*2,f=Math.cos(u),g=Math.sin(u);for(let w=0;w<=r;w++){let p=w/r*s,b=Math.cos(p),T=Math.sin(p);if(n.push((e+t*f)*b,(e+t*f)*T,t*g),a.push(f*b,f*T,g),o.push(w/r,h/i),h>0&&w>0){let x=(r+1)*h+w-1,M=x-(r+1);l.push(x,M,x+1,M,M+1,x+1)}}}this.setFromBuffers(n,a,o,l)}};function _r(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],h=[],u=[],f=[],g=[],w=new ee,p=new ee,b=new ee;for(let x=0;x<=n;x++){let M=new ee;s(x/n,M),g.push(M)}let T=a+1;for(let x=0;x<=n;x++){let M=x/n,c=g[x];w.subVectors(g[Math.min(n,x+1)],g[Math.max(0,x-1)]).normalize(),x===0&&p.set(Math.abs(w.y)>.9?1:0,Math.abs(w.y)>.9?0:1,0),b.crossVectors(w,p).normalize(),p.crossVectors(b,w).normalize();for(let m=0;m<=a;m++){let v=m/a*Math.PI*2,S=-Math.cos(v),D=Math.sin(v),I=S*p.x+D*b.x,P=S*p.y+D*b.y,N=S*p.z+D*b.z;if(l.push(c.x+o*I,c.y+o*P,c.z+o*N),h.push(I,P,N),u.push(M,m/a),x>0&&m>0){let C=T*(x-1)+m-1,L=C+T;f.push(C,L,C+1,L,L+1,C+1)}}}e.setFromBuffers(l,h,u,f)}var Xt=class extends de{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),_r(this,i,r,t,(a,o)=>{let l=a*s*Math.PI*2,h=n/s*l,u=e*(2+Math.cos(h))*.5;o.set(u*Math.cos(l),u*Math.sin(l),e*Math.sin(h)*.5)})}},Fe=class{getPoint(e,t=new ee){return t}getPointAt(e,t=new ee){return this.getPoint(e,t)}getTangent(e,t=new ee){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Wt=class extends Fe{constructor(e=new ee,t=new ee){super(),this.v1=e,this.v2=t}getPoint(e,t=new ee){return t.lerpVectors(this.v1,this.v2,e)}},jt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new ee){return t.lerpVectors(this.v0,this.v1,e).lerp(new ee().lerpVectors(this.v1,this.v2,e),e)}},Kt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee,r=new ee){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new ee){let i=new ee().lerpVectors(this.v0,this.v1,e),r=new ee().lerpVectors(this.v1,this.v2,e),s=new ee().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Yt=class extends Fe{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new ee){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),a=s-n;!this.closed&&n>=r-1&&(n=r-2,a=1);let o=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],l=o(n-1),h=o(n),u=o(n+1),f=o(n+2),g=a*a,w=g*a,p=(b,T,x,M)=>.5*(2*T+(x-b)*a+(2*b-5*T+4*x-M)*g+(3*T-b-3*x+M)*w);return t.set(p(l.x,h.x,u.x,f.x),p(l.y,h.y,u.y,f.y),p(l.z,h.z,u.z,f.z))}},ut=class extends de{constructor(e=[new Se(0,-.5),new Se(.5,0),new Se(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Se(.2,0),new Se(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),a=[],o=[],l=[],h=[],u=s.length;for(let f=0;f<=n;f++){let g=f/n,w=i+g*r,p=Math.sin(w),b=Math.cos(w),T=f*u;for(let x=0;x<u;x++){let M=s[x],c=Number(M?.x)||0,m=Number(M?.y)||0;a.push(c*p,m,c*b);let v=s[Math.max(0,x-1)],S=s[Math.min(u-1,x+1)],D=(Number(S?.x)||0)-(Number(v?.x)||0),I=(Number(S?.y)||0)-(Number(v?.y)||0),P=Math.hypot(I,D)||1;if(o.push(I/P*p,-D/P,I/P*b),l.push(g,x/(u-1)),f<n&&x<u-1){let N=T+x,C=N+u;h.push(N,C,N+1,C,C+1,N+1)}}}this.setFromBuffers(a,o,l,h)}},qt=class extends de{constructor(e,t=64,i=1,r=8,s=!1){super(),_r(this,t,r,i,(n,a)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let l=o.call(e,n,a);l&&l!==a&&a.copy(l)}else a.set(0,n,0)})}},Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",qe=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Se(1,1),this.offset=new Se(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Zt=class extends qe{constructor(e=null,t=1,i=1,r=1023,s=1009,n,a=1001,o=1001,l=1003,h=1003,u=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let g=Number(t),w=Number(i),p=e&&typeof e.length=="number"?e:null;this.width=g,this.height=w,this.image={data:p,width:g,height:w},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(h)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),a=s*n,o=this.format,l=o===1021||o===1024||o===1028||t.length===a?1:o===1025||o===1030||t.length===a*2?2:o===1022||t.length===a*3?3:4,h=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,u=Math.min(s,48),f=Math.min(n,48),g=(this.flipY?257:1)^this.colorSpace.length^t.length,w=Math.max(1,t.length>>6|0);for(let L=0;L<t.length;L+=w)g=Math.imul(g^(t[L]*256|0),16777619)|0;if(g===this._sig&&this.source)return;this._sig=g;let p=f*(1+u*4),b=new Uint8Array(68+p),T=new DataView(b.buffer);T.setUint32(0,2303741511),T.setUint32(4,218765834),T.setUint32(8,13),T.setUint32(12,1229472850),T.setUint32(16,u),T.setUint32(20,f),b[24]=8,b[25]=6,T.setUint32(29,Dt(b.subarray(12,29))),T.setUint32(33,p+11),T.setUint32(37,1229209940),b[41]=120,b[42]=1,b[43]=1,T.setUint16(44,p,!0),T.setUint16(46,~p&65535,!0);let x=48,M=1,c=0,m=0,v=0,S=0,D=0,I=L=>{if(!Number.isFinite(L))return 0;let E=h&&L<=1?L*255:L;return E>0?E<255?E+.5|0:255:0};for(let L=0;L<f;L++){let E=L*n/f|0,y=this.flipY?n-1-E:E;b[x++]=0,c+=M;for(let F=0;F<u;F++){let z=(y*s+(F*s/u|0))*l,A=o===1021?255:I(t[z]??0),_=l>=3||o===1030?I(t[z+1]??0):A,d=l>=3?I(t[z+2]??0):o===1030?0:A,R=l===4?I(t[z+3]??255):o===1021?I(t[z]??255):o===1025?I(t[z+1]??255):255;b[x++]=A,M+=A,c+=M,b[x++]=_,M+=_,c+=M,b[x++]=d,M+=d,c+=M,b[x++]=R,M+=R,c+=M,m+=A,v+=_,S+=d,D+=R}M%=65521,c%=65521}T.setUint32(x,(c<<16|M)>>>0),T.setUint32(x+4,Dt(b.subarray(37,x+4))),T.setUint32(x+12,1229278788),T.setUint32(x+16,2923585666);let P=u*f*255,N=this.colorSpace==="srgb-linear";this.avgColor=[N?m/P:ve(m/P),N?v/P:ve(v/P),N?S/P:ve(S/P),D/P];let C=["data:image/png;base64,"];for(let L=0;L<b.length;L+=3){let E=b[L]<<16|(b[L+1]??0)<<8|(b[L+2]??0);C.push(Lt[E>>18&63]+Lt[E>>12&63]+(L+1<b.length?Lt[E>>6&63]:"=")+(L+2<b.length?Lt[E&63]:"="))}this.source=C.join("")}},Jt=class{load(e,t){let i=new qe(e);return t?.(i),i}};function xe(e,t){return e!==void 0?Number(e):t}function Pn(e,t){return e!==void 0?!!e:t}var Me=class{constructor(e={}){this.name=e.name||"",this.color=new we(e.color??16777215),this.emissive=new we(e.emissive??0),this.emissiveIntensity=xe(e.emissiveIntensity,1),this.roughness=xe(e.roughness,.5),this.metalness=xe(e.metalness,0),this.opacity=xe(e.opacity,1),this.transparent=Pn(e.transparent,!1),this.wireframe=Pn(e.wireframe,!1),this.side=xe(e.side,2),this.doubleSided=Pn(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=xe(e.clearcoat,0),this.clearcoatRoughness=xe(e.clearcoatRoughness,0),this.sheen=xe(e.sheen,0),this.sheenColor=new we(e.sheenColor??0),this.sheenRoughness=xe(e.sheenRoughness,0),this.transmission=xe(e.transmission,0),this.thickness=xe(e.thickness,0),this.attenuationColor=new we(e.attenuationColor??16777215),this.attenuationDistance=xe(e.attenuationDistance,1/0),this.ior=xe(e.ior,1.5),this.dispersion=xe(e.dispersion,0),this.iridescence=xe(e.iridescence,0),this.iridescenceIOR=xe(e.iridescenceIOR,1.3)}dispose(){}},ze=class extends Me{},Qt=class extends Me{},en=class extends Me{},tn=class extends Me{},nn=class extends Me{},Ae=class $i{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 ee,this.rotation=new ot,this.quaternion=new Ye,this.scale=new ee(1,1,1),this.matrix=new Be,this.matrixWorld=new Be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof $i&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let a=n.length-1;a>=0;a--)r.push(n[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Sr(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new ee(t,i,r);this.target instanceof ee?this.target.copy(s):this.target?.position instanceof ee&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Be;n.lookAt(this.position,s,new ee(0,1,0));let a=n.elements,o=a[0],l=a[4],h=a[8],u=a[1],f=a[5],g=a[9],w=a[2],p=a[6],b=a[10],T=o+f+b;if(T>0){let x=.5/Math.sqrt(T+1);this.quaternion.set((p-g)*x,(h-w)*x,(u-l)*x,.25/x)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Be().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new ee(1,0,0),t)}translateY(t){return this.translateOnAxis(new ee(0,1,0),t)}translateZ(t){return this.translateOnAxis(new ee(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let i=this;i&&t.length<64;i=i.parent)t.push(i);return t}_syncWorld(){let t=this._chain();for(let i=t.length-1;i>=0;i--){let r=t[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new ee){let i=this._syncWorld();return t.set(i[12],i[13],i[14])}getWorldScale(t=new ee){let i=this._syncWorld();return t.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(t=new ee){let i=this._syncWorld();return t.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(t=new Ye){let i=this._chain();t.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)t.multiply(i[r].quaternion);return t}clone(t=!0){let i=this instanceof Ve?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Ie?new Ie(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},rn=class extends Ae{},Ie=class extends Ae{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof de?e:e?(He("unsupported geometry","BoxGeometry"),new at(.5,.5,.5)):new de,this.material=i instanceof Me?i:i?(He("unsupported material","MeshStandardMaterial"),new ze({color:13421772})):new ze}};function Sr(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=le().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var lt=1e4,mt=class extends Ie{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>lt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${lt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let a=n*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new ge(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let a=Number(t.elements[n]);r[s+n]=Number.isFinite(a)?a:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new ge(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Ge=class extends Ae{constructor(e=16777215,t=1){super(),this.color=new we(e),this.intensity=Number(t),this.type="directional"}},ht=class extends Ge{constructor(e,t){super(e,t),this.type="ambient"}},sn=class extends Ge{constructor(e,t){super(e,t),this.target=new Ae,this.type="directional"}},ft=class extends Ge{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},dt=class extends Ae{},on=class extends dt{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new ee(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},pt=class extends Ae{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return De.validate(this),Ke(this)}toGLB(){return De.validate(this),tt(this)}toUSDZ(){return De.validate(this),nt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Ie){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Fn=Ke,kn=tt,wr=nt,De=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(o,l,h)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${h}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};e.traverse(o=>{if(Sr(o),o instanceof Ie||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),o instanceof mt){let h=a("instance",o.count);(h<0||h>lt)&&n("INSTANCES",lt,h)}let l=o.geometry;if(l){let h=0;if(l.attributes.position&&(h=a("vertex",l.attributes.position.count),t+=h,t>1e5&&n("VERTICES",1e5,t)),l.index){let u=a("index",l.index.count);i+=u,i>3e5&&n("INDICES",3e5,i);let f=l.index.array;if(f&&h>0){let g=Math.min(u,f.length);for(let w=0;w<g;w++){let p=f[w];if(!Number.isFinite(p)||p<0||p>=h)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${h}).`)}}}}if(o.material){let h=o.material;for(let u of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])h[u]&&s.add(h[u])}}}),s.size>16&&n("TEXTURES",16,s.size);for(let o of s){let l=o,h=l.image,u=Number(h?.width??l.width??0)||0,f=Number(h?.height??l.height??0)||0;(!Number.isFinite(u)||!Number.isFinite(f)||u>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(u,f))}}},an=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,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 i=new we(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){De.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[a,o]of s.entries())n[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Fn(e),n=kn(e),a=(s.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:a,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function pr(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var cn=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=pr(),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=pr();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function mi(){}var it=new Proxy(mi,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:it},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>it,construct:()=>it}),br=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function _n(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ze(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,_n());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var gr,rt;function Ar(e){if(!Ze(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(rt===void 0||gr!==t){gr=t;try{rt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ze(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{rt=null}}return rt?rt.createScriptURL(e):e}function hi(e){le().sandboxEngineSrc=e}function Un(){let e=le().sandboxEngineSrc;if(e)return e;if(br)return br;try{if(typeof document>"u")return null;let t=_n(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Ze(s,{requireSameOrigin:!0}))return s}}catch{}return null}function On(e,t){if(!Ze(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,_n()).href}function fi(){let e=Un();if(!e)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.");return On(e,"sandbox engine")}function di(e){le().sandboxIframeSrc=e}function Er(){let e=le().sandboxIframeSrc;if(e)return e;let t=Un();if(!t||!Ze(t))return null;let i=new URL(t,_n());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function pi(){let e=Er();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return On(e,"sandbox iframe")}function bi(e){le().allowClientScripts=e}function Rr(){return!!le().allowClientScripts}function gi(e){return On(e,"procedural scene script")}var yi=["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 xi(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,a=e.allowClientScripts,o=e.revoked,l=i.postMessage.bind(i);function h(c){l({type:"ERROR",nonce:r,message:String(c)})}let u=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,g=null;try{let c=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let m={createScriptURL:function(S){if(S!==s&&(!n||S!==n))throw new TypeError("Disallowed worker importScripts URL");return S}};a&&(m.createScript=function(S){return String(S)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",m);c=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),a&&typeof v.createScript=="function"&&(g=v.createScript.bind(v))}catch{}u(c)}catch(c){h('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(c&&c.message||c));return}let w=i.THREE;if(!w||typeof w.Scene!="function"){h('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let c=i.__THREE_LIVE_REGISTRY__;for(let m=0;m<t.length;m++)if(typeof t[m]=="function")try{t[m](w,c)}catch{}}function p(c,m,v){let S=i;for(;S&&S!==Object.prototype;){if(!v&&S!==i)try{delete S[c]}catch{}if(!v||S===i||Object.prototype.hasOwnProperty.call(S,c))try{Object.defineProperty(S,c,v?{value:m,writable:!1,configurable:!1}:{value:m,writable:!1,configurable:!1,enumerable:!1})}catch{}try{S=Object.getPrototypeOf(S)}catch{break}}}for(let c=0;c<o.length;c++)p(o[c],void 0);p("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],T=!1;function x(c,m){if(c.type==="3D_MODEL_READY"){if(T)return;T=!0}c.nonce=r,m&&m.length?l(c,m):l(c)}p("postMessage",function(c,m){if(!c||b.indexOf(c.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");x(c,m)},!0);let M=!1;i.onmessage=function(c){let m=c&&c.data;if(!(!m||m.nonce!==r)&&!(m.type!=="EXECUTE"&&m.type!=="EXECUTE_URL")&&!M){M=!0;try{let v=new w.Scene,S=new w.PerspectiveCamera(60,1,.1,1e3),D=new w.WebGLRenderer({isSandboxed:!0});if(m.type==="EXECUTE_URL"){if(!n||m.scriptUrl!==n||typeof u!="function"){h("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,P=u;if(u=null,f=null,i.THREE=w,i.scene=v,i.camera=S,i.renderer=D,P(I),typeof i.__THREE_LIVE_SCENE__=="function"){let N=i.__THREE_LIVE_SCENE__(w,v,S,D);N&&typeof N.toGLB=="function"&&(v=N)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!a){h("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=g?(0,eval)(g(`(function (THREE, scene, camera, renderer) {
322
369
  return (function () {
323
- `+D.script+`
370
+ `+m.script+`
371
+ ;
372
+ return typeof scene === "object" && scene ? scene : undefined;
324
373
  })();
325
374
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
326
- `+D.script+`
327
- })();`);m=null;let y=p(b,v,M,I);y&&typeof y.toGLB=="function"&&(v=y)}if(!C){b.SceneQuotaValidator&&b.SceneQuotaValidator.validate(v);let p=v.toGLB(),y=p instanceof ArrayBuffer?p:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);N({type:"3D_MODEL_READY",glbBuffer:y},[y])}a({type:"DONE",nonce:r})}catch(v){u(v&&v.message||v)}}},a({type:"READY",nonce:r})}function nn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:Ar},o=(Q().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${Cr.toString()})(${JSON.stringify(s)},[${o}]);`}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 ve=0;function zn(){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 Ir(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var Dr=1024,Lr=256;function Dn(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 rn(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,Dr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!Dn(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 o=Object.create(null),l=i;for(let a of s){if(a.length>Lr||a==="__proto__"||a==="constructor"||a==="prototype")return null;let u=l[a];if(!Dn(u))return null;o[a]=u}return{type:"3D_UPDATE_TRANSFORMS",transforms:o}}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 Nr(n){let e=Ir(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Gn(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 Pr(n,e,t,r){let i=zn(),s=nn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=t,ve++;let l=!1,a=!1,u={modelDispatched:!1},c,h=()=>{if(l||a)return;let d=o.contentWindow;!d||typeof d.postMessage!="function"||(a=!0,d.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},m=()=>{},b=d=>{if(l||!o.contentWindow||d.source!==o.contentWindow)return;let w=d.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){h();return}let C=rn(w,i);C&&Gn(C,r,m,u)};m=()=>{l||(l=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",b),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{l||(m(),Vn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",b),o.onload=()=>{h()},o.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let g=document.body||document.documentElement;if(!g||typeof g.appendChild!="function"){m();let d=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(d),d}return g.appendChild(o),{terminate:m}}function Ln(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(ve>=32)return r(`SecurityError: ${ve} 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=wr()}catch(m){let b=m instanceof Error?m.message:String(m);return r(b,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let m;try{m=Rr()}catch(b){let g=b instanceof Error?b.message:String(b);return r(g,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Pr(n,i,m,t))}catch(b){return Promise.reject(b)}}let s=zn(),o=nn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let m=new Blob([o],{type:"application/javascript"}),b=URL.createObjectURL(m);try{let g=Un(b);l=new Worker(g)}finally{URL.revokeObjectURL(b)}}catch(m){let b=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${b}`,"Security Error: Failed to start Worker sandbox.")}ve++;let a=!1,u={modelDispatched:!1},c,h=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),l.terminate())};return c=setTimeout(()=>{a||(h(),Vn(t))},3e3),l.onmessage=m=>{let b=rn(m.data,s);b&&Gn(b,t,h,u)},l.onerror=m=>{h(),t.onError?.(new Error(`Worker execution error: ${m.message}`))},n.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):l.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function Nn(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 Hn={execute(n,e,t,r){let i=(l,a)=>{let u=new Error(l);return t.onError?.(u),a&&t.onToast?.(a),Promise.reject(u)},s=Nn(e,i);if(s)return s;try{Nr(n)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Bn()?Ln({kind:"script",script:n},e,t,i):i(on,an)},executeUrl(n,e,t){let r=(o,l)=>{let a=new Error(o);return t.onError?.(a),l&&t.onToast?.(l),Promise.reject(a)},i=Nn(e,r);if(i)return i;let s;try{s=Sr(n)}catch(o){let l=o instanceof Error?o.message:String(o);return r(l,"Security Error: disallowed scene script URL.")}return Ln({kind:"url",scriptUrl:s},e,t,r)}},Nt=new Set;function fe(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 Xn(){return Array.from(Nt)}function Wn(){Nt.clear()}var Qe=class extends Re{constructor(e={}){fe("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}},$n=Qe,Ae=class extends We{constructor(e=1,t=0,r="PolyhedronGeometry"){fe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Pt=class extends Ae{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Ft=class extends Ae{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},kt=class extends Ae{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Ut=class extends Ae{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Ot=class extends Me{constructor(e=1,t=1,r=4,i=8){fe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},Bt=class extends Me{constructor(e=.5,t=1,r=16){fe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Vt=class extends Me{constructor(e=1,t=16){fe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},zt=class extends qe{constructor(t,r,i=0,s=Math.PI/3,o=0,l=2){fe("SpotLight","PointLight");super(t,r,i,l);this.target=new pe;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=o}},et=class extends Ke{constructor(e,t,r){fe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new de(t??4473924)}},Yn=et,jn={Vector2:ft,Vector3:te,Vector4:dt,Euler:Ge,Quaternion:He,Matrix4:Ee,Matrix3:pt,Color:de,MathUtils:Pn,BufferAttribute:le,Float32BufferAttribute:bt,Uint16BufferAttribute:yt,Uint32BufferAttribute:gt,BufferGeometry:he,BoxGeometry:Xe,PlaneGeometry:xt,SphereGeometry:We,CylinderGeometry:Me,ConeGeometry:vt,TorusGeometry:Mt,TorusKnotGeometry:Tt,IcosahedronGeometry:Pt,OctahedronGeometry:Ft,DodecahedronGeometry:kt,TetrahedronGeometry:Ut,CapsuleGeometry:Ot,RingGeometry:Bt,CircleGeometry:Vt,Texture:$e,TextureLoader:wt,Material:ye,MeshStandardMaterial:Re,MeshBasicMaterial:Et,MeshLambertMaterial:Rt,MeshPhongMaterial:_t,MeshPhysicalMaterial:St,ShaderMaterial:Qe,RawShaderMaterial:$n,Object3D:pe,Group:At,Mesh:_e,InstancedMesh:je,Light:Se,AmbientLight:Ke,DirectionalLight:Ct,PointLight:qe,SpotLight:zt,HemisphereLight:et,RectAreaLight:Yn,Camera:Ze,PerspectiveCamera:It,Scene:Je,WebGLRenderer:Dt,Clock:Lt,SceneQuotaValidator:be,exportSceneToCanvas3D:Qt,exportSceneToGLB:en,exportSceneToUSDZ:kn,generateUSDZ:Zt,glbToUSDZ:mt,sceneToCanvas3D:Ne,sceneToGLB:Oe,sceneToUSDZ:Pe,authorScriptRunner:Hn,getAuthorWarnings:Xn,clearAuthorWarnings:Wn};Object.freeze(be);Object.freeze(be.prototype);Object.freeze(Je.prototype);Object.freeze(jn);var Ce=new Proxy(jn,{get:(n,e)=>{if(e in n)return n[e];let t=Q().authorNamespace;return t&&typeof e=="string"&&e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&fe(`THREE.${e}`,"no-op proxy"),Ve)},has:(n,e)=>{if(e in n)return!0;let t=Q().authorNamespace;return!!(t&&typeof e=="string"&&e in t)},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")}}),ht=Q();ht.threeNamespace=Ce;if(ht.workerExtensionInstallers)for(let n of ht.workerExtensionInstallers)n(Ce,ht);var ze={name:"three_author",THREE:Ce},Fr=ze,xe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof xe.THREE>"u"&&(xe.THREE=Ce);typeof xe.requestAnimationFrame!="function"&&(xe.requestAnimationFrame=n=>(typeof n=="function"&&typeof xe.__three_live_raf_cb__!="function"&&(xe.__three_live_raf_cb__=n),xe.__three_live_in_step__||fe("requestAnimationFrame","single-frame static evaluation"),0));typeof xe.cancelAnimationFrame!="function"&&(xe.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Ce,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=ze,n.ThreeLivePlugins.three_author=ze,n.ThreeLivePlugins["three-author"]=ze}var kr=Ce;
375
+ `+m.script+`
376
+ ;
377
+ return typeof scene === "object" && scene ? scene : undefined;
378
+ })();`);g=null;let P=I(w,v,S,D);P&&typeof P.toGLB=="function"&&(v=P)}if(!T){w.SceneQuotaValidator&&w.SceneQuotaValidator.validate(v);let I=v.toGLB(),P=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);x({type:"3D_MODEL_READY",glbBuffer:P},[P])}l({type:"DONE",nonce:r})}catch(v){h(v&&v.message||v)}}},l({type:"READY",nonce:r})}function Bn(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:yi},a=(le().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${xi.toString()})(${JSON.stringify(n)},[${a}]);`}function Cr(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Oe=0;function Dr(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function vi(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Mi=1024,Ti=256;function yr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function Vn(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Mi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!yr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),a=r;for(let o of s){if(o.length>Ti||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!yr(l))return null;n[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function _i(e){let t=vi(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ir(e,t,i,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Si(e,t,i,r){let s=Dr(),n=Bn(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,Oe++;let o=!1,l=!1,h={modelDispatched:!1},u,f=()=>{if(o||l)return;let b=a.contentWindow;!b||typeof b.postMessage!="function"||(l=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},g=()=>{},w=b=>{if(o||!a.contentWindow||b.source!==a.contentWindow)return;let T=b.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){f();return}let x=Vn(T,s);x&&Ir(x,r,g,h)};g=()=>{o||(o=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",w),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{o||(g(),Cr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",w),a.onload=()=>{f()},a.onerror=()=>{g(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){g();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return p.appendChild(a),{terminate:g}}function xr(e,t,i,r){if(t==="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(t==="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(Oe>=32)return r(`SecurityError: ${Oe} 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 s;try{s=fi()}catch(g){let w=g instanceof Error?g.message:String(g);return r(w,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let g;try{g=pi()}catch(w){let p=w instanceof Error?w.message:String(w);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Si(e,s,g,i))}catch(w){return Promise.reject(w)}}let n=Dr(),a=Bn(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let g=new Blob([a],{type:"application/javascript"}),w=URL.createObjectURL(g);try{let p=Ar(w);o=new Worker(p)}finally{URL.revokeObjectURL(w)}}catch(g){let w=g instanceof Error?g.message:String(g);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${w}`,"Security Error: Failed to start Worker sandbox.")}Oe++;let l=!1,h={modelDispatched:!1},u,f=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),o.terminate())};return u=setTimeout(()=>{l||(f(),Cr(i))},3e3),o.onmessage=g=>{let w=Vn(g.data,n);w&&Ir(w,i,f,h)},o.onerror=g=>{f(),i.onError?.(new Error(`Worker execution error: ${g.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):o.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function vr(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Mr=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},Nr={execute(e,t,i,r){let s=Mr(i),n=vr(t,s);if(n)return n;try{_i(e)}catch(a){let o=a instanceof Error?a.message:String(a);return s(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Rr()?xr({kind:"script",script:e},t,i,s):s(Gn,Hn)},executeUrl(e,t,i){let r=Mr(i),s=vr(t,r);if(s)return s;let n;try{n=gi(e)}catch(a){let o=a instanceof Error?a.message:String(a);return r(o,"Security Error: disallowed scene script URL.")}return xr({kind:"url",scriptUrl:n},t,i,r)}},un=new Set;function He(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;un.has(i)||(un.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Lr(){return Array.from(un)}function Pr(){un.clear()}var bt=class extends ze{constructor(e={}){He("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Fr=bt,ke=class extends de{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=n+1,o=[],l=[],h=[],u=[],f=new ee,g=new ee,w=new ee,p=(x,M)=>M.set(e[x*3]||0,e[x*3+1]||0,e[x*3+2]||0),b=(x,M)=>{let c=x.clone().normalize();o.push(c.x*s,c.y*s,c.z*s),l.push(M.x,M.y,M.z),h.push(Math.atan2(c.z,-c.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,c.y)))/Math.PI)},T=(x,M,c)=>{let m=o.length/3,v=n===0?new ee().subVectors(c,M).cross(new ee().subVectors(x,M)).normalize():null;b(x,v||x.clone().normalize()),b(M,v||M.clone().normalize()),b(c,v||c.clone().normalize()),u.push(m,m+1,m+2)};for(let x=0;x<t.length;x+=3){p(t[x],f),p(t[x+1],g),p(t[x+2],w);let M=[];for(let c=0;c<=a;c++){M[c]=[];let m=f.clone().lerp(w,c/a),v=g.clone().lerp(w,c/a),S=a-c;for(let D=0;D<=S;D++)M[c][D]=S===0?m.clone():m.clone().lerp(v,D/S)}for(let c=0;c<a;c++)for(let m=0;m<2*(a-c)-1;m++){let v=m>>1;(m&1)===0?T(M[c][v+1],M[c+1][v],M[c][v]):T(M[c][v+1],M[c+1][v+1],M[c+1][v])}}this.setFromBuffers(o,l,h,u)}},wi=ke,ln=class extends ke{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},Pt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],kr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],mn=class extends ke{constructor(e=1,t=0){super(Pt,kr,e,t)}},ue=(1+Math.sqrt(5))/2,hn=class extends ke{constructor(e=1,t=0){super([-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,0,0,-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,ue,0,-1,ue,0,1,-ue,0,-1,-ue,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},_e=1/ue,fn=class extends ke{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,0,-ue,0,-_e,ue,0,-_e,-ue,0,_e,ue,0,_e],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},dn=class extends ut{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let h=0;h<=a;h++){if(l>0&&h===0&&n===0)continue;let u=(l<0?h/a-1:h/a)*(Math.PI/2);o.push(new Se(Math.max(0,Math.cos(u)*s),l*n+Math.sin(u)*s))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},gt=class extends de{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let a=Math.max(1e-4,Number(t)||1),o=Number(e),l=Number.isFinite(o)?Math.max(0,o):a*.5,h=Math.max(a,l),u=Math.min(h*.999,Math.min(a,l)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),g=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),w=Number.isFinite(Number(s))?Number(s):0,p=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],T=[],x=[],M=[];for(let c=0;c<=g;c++){let m=u+c/g*(h-u);for(let v=0;v<=f;v++){let S=w+v/f*p,D=Math.cos(S),I=Math.sin(S);if(b.push(m*D,m*I,0),T.push(0,0,1),x.push(m/h*D*.5+.5,m/h*I*.5+.5),c<g&&v<f){let P=c*(f+1)+v,N=P+f+1;m>1e-6&&M.push(P,N,P+1),M.push(N,N+1,P+1)}}}this.setFromBuffers(b,T,x,M)}},pn=class extends gt{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},yt=class extends Me{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Je=class extends Me{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},bn=class extends Je{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Ur(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),a=g=>`${Math.round((r[g*3]||0)*1e4)},${Math.round((r[g*3+1]||0)*1e4)},${Math.round((r[g*3+2]||0)*1e4)}`,o=t===void 0,l=o?1:Math.cos(t*Math.PI/180),h={},u=[],f=(g,w)=>u.push(r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0,r[w*3]||0,r[w*3+1]||0,r[w*3+2]||0);for(let g=0;g<n;g++){let w=s?s[g*3]:g*3,p=s?s[g*3+1]:g*3+1,b=s?s[g*3+2]:g*3+2,T=r[w*3]||0,x=r[w*3+1]||0,M=r[w*3+2]||0,c=(r[p*3]||0)-T,m=(r[p*3+1]||0)-x,v=(r[p*3+2]||0)-M,S=(r[b*3]||0)-T,D=(r[b*3+1]||0)-x,I=(r[b*3+2]||0)-M,P=m*I-v*D,N=v*S-c*I,C=c*D-m*S,L=Math.hypot(P,N,C);if(!o&&L<1e-8)continue;L>0&&(P/=L,N/=L,C/=L);let E=[w,p,b];for(let y=0;y<3;y++){let F=E[y],z=E[(y+1)%3],A=a(F),_=a(z);if(A===_)continue;let d=A<_?`${A}|${_}`:`${_}|${A}`,R=h[d];R?R.m||(R.m=1,R.nx*P+R.ny*N+R.nz*C<=l&&f(F,z)):(h[d]={va:F,vb:z,nx:P,ny:N,nz:C,m:o?1:0},o&&f(F,z))}}if(!o){let g=Object.keys(h);for(let w=0;w<g.length;w++){let p=h[g[w]];p&&!p.m&&f(p.va,p.vb)}}return new Float32Array(u)}var gn=class extends de{constructor(e){super(),this.setAttribute("position",new ge(Ur(e),3)),this.__isSegmentPairs=!0}},yn=class extends de{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new ge(Ur(e,i),3)),this.__isSegmentPairs=!0}};function Ai(e,t,i=1){let r=new de;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,a=e.index?.array,o=e.__isSegmentPairs?"segments":t,l=a?a.length:s.count,h=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(h===0)return r;e.computeBoundingBox();let u=e.boundingBox,f=u&&u.max.distanceTo(u.min)||1,g=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),w=[],p=[],b=[],T=[];for(let x=0;x<h;x++){let M=o==="segments"?x*2:x,c=o==="segments"?x*2+1:(x+1)%l,m=a?a[M]:M,v=a?a[c]:c,S=n[m*3]||0,D=n[m*3+1]||0,I=n[m*3+2]||0,P=(n[v*3]||0)-S,N=(n[v*3+1]||0)-D,C=(n[v*3+2]||0)-I,L=Math.hypot(P,N,C);if(L<1e-6)continue;let E=P/L,y=N/L,F=C/L,z=(Math.abs(y)<.9?Math.hypot(F,E):Math.hypot(F,y))||1,A=Math.abs(y)<.9?F/z:0,_=Math.abs(y)<.9?0:-F/z,d=Math.abs(y)<.9?-E/z:y/z,R=y*d-F*_,G=F*A-E*d,H=E*_-y*A,B=w.length/3,Z=[[A,_,d],[R,G,H],[-A,-_,-d],[-R,-G,-H]];for(let k=0;k<2;k++){let Y=S+k*P,ie=D+k*N,re=I+k*C;for(let O=0;O<4;O++){let J=Z[O];w.push(Y+J[0]*g,ie+J[1]*g,re+J[2]*g),p.push(J[0],J[1],J[2]),b.push(O/4,k)}}for(let k=0;k<4;k++){let Y=(k+1)%4;T.push(B+k,B+Y,B+4+Y,B+k,B+4+Y,B+4+k)}}return w.length>0&&r.setFromBuffers(w,p,b,T),r}function Ei(e,t=.05){let i=new de;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,a=Math.min(n,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),l=[],h=[],u=[],f=[];for(let g=0;g<a;g++){let w=n<=5e3?g:Math.floor(g*n/a),p=s[w*3]||0,b=s[w*3+1]||0,T=s[w*3+2]||0,x=g*6;for(let M=0;M<6;M++){let c=Pt[M*3],m=Pt[M*3+1],v=Pt[M*3+2];l.push(p+c*o,b+m*o,T+v*o),h.push(c,m,v),u.push(.5,.5)}for(let M=0;M<24;M++)f.push(x+kr[M])}return i.setFromBuffers(l,h,u,f),i}var Ve=class extends Ie{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Me?t:i==="points"?new yt(r):new Je(r),n=e instanceof de?e:new de;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,a=0;for(let o=0;o<r;o++)s+=i[o*3]||0,n+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(s/r,n/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ei(this._sourceGeo,this.material?.size??.05):Ai(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},xn=class extends Ve{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},vn=class extends Ve{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Mn=class extends Ve{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Tn=class extends ft{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Ae,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(s);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},xt=class extends ht{constructor(e,t,i){He("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new we(t??4473924)}},Or=xt,Br={Vector2:Se,Vector3:ee,Vector4:kt,Euler:ot,Quaternion:Ye,Matrix4:Be,Matrix3:Ut,Color:we,MathUtils:Tr,BufferAttribute:ge,Float32BufferAttribute:Ot,Uint16BufferAttribute:Bt,Uint32BufferAttribute:Vt,BufferGeometry:de,BoxGeometry:at,PlaneGeometry:zt,SphereGeometry:Gt,CylinderGeometry:ct,ConeGeometry:Ht,TorusGeometry:$t,TorusKnotGeometry:Xt,Curve:Fe,Curve3:Fe,LineCurve3:Wt,QuadraticBezierCurve3:jt,CubicBezierCurve3:Kt,CatmullRomCurve3:Yt,LatheGeometry:ut,TubeGeometry:qt,PolyhedronGeometry:ke,IcosahedronGeometry:hn,OctahedronGeometry:mn,DodecahedronGeometry:fn,TetrahedronGeometry:ln,CapsuleGeometry:dn,RingGeometry:gt,CircleGeometry:pn,WireframeGeometry:gn,EdgesGeometry:yn,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:qe,DataTexture:Zt,TextureLoader:Jt,Material:Me,MeshStandardMaterial:ze,MeshBasicMaterial:Qt,MeshLambertMaterial:en,MeshPhongMaterial:tn,MeshPhysicalMaterial:nn,PointsMaterial:yt,LineBasicMaterial:Je,LineDashedMaterial:bn,ShaderMaterial:bt,RawShaderMaterial:Fr,Object3D:Ae,Group:rn,Mesh:Ie,InstancedMesh:mt,Line:Ve,LineLoop:xn,LineSegments:vn,Points:Mn,Light:Ge,AmbientLight:ht,DirectionalLight:sn,PointLight:ft,SpotLight:Tn,HemisphereLight:xt,RectAreaLight:Or,Camera:dt,PerspectiveCamera:on,Scene:pt,WebGLRenderer:an,Clock:cn,SceneQuotaValidator:De,exportSceneToCanvas3D:Fn,exportSceneToGLB:kn,exportSceneToUSDZ:wr,generateUSDZ:Ln,glbToUSDZ:It,sceneToCanvas3D:Ke,sceneToGLB:tt,sceneToUSDZ:nt,authorScriptRunner:Nr,getAuthorWarnings:Lr,clearAuthorWarnings:Pr};Object.freeze(De),Object.freeze(De.prototype),Object.freeze(pt.prototype),Object.freeze(Br);var $e=new Proxy(Br,{get:(e,t)=>{if(t in e)return e[t];let i=le().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&He(`THREE.${t}`,"no-op proxy"),it)},has:(e,t)=>{if(t in e)return!0;let i=le().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Ft=le();if(Ft.threeNamespace=$e,Ft.workerExtensionInstallers)for(let e of Ft.workerExtensionInstallers)e($e,Ft);var st={name:"three_author",THREE:$e},Ri=st,Pe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Pe.THREE>"u"&&(Pe.THREE=$e),typeof Pe.requestAnimationFrame!="function"&&(Pe.requestAnimationFrame=e=>(typeof e=="function"&&typeof Pe.__three_live_raf_cb__!="function"&&(Pe.__three_live_raf_cb__=e),Pe.__three_live_in_step__||He("requestAnimationFrame","single-frame static evaluation"),0)),typeof Pe.cancelAnimationFrame!="function"&&(Pe.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=$e,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=st,e.ThreeLivePlugins.three_author=st,e.ThreeLivePlugins["three-author"]=st}var Ci=$e;