three-live 1.1.1 → 1.2.1

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.
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- function Xt(n,e,t){let r=[],i=new Map,s=[],c=[],m=[],u=new Map,o=y=>{let v=i.get(y);return v===void 0&&(v=r.length,r.push({op:y}),i.set(y,v)),v},a=y=>{let v=u.get(y);return v===void 0&&(v=m.length,m.push({id:y}),u.set(y,v)),v},h=(y,v={})=>s.push({declaration:o(y),...v})-1,l=(y,v,p)=>c.push({id:y,type:v,value:p})-1,b=y=>({node:y,socket:"value"}),f=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let y=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(y&&Array.isArray(y.nodes)){let v=Array.isArray(y.declarations)?y.declarations:[];for(let p of v)p?.op&&o(p.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let p of y.events||[])p?.id&&a(p.id);for(let p of y.nodes){if(!p||typeof p!="object")continue;let E=p.op||(typeof p.declaration=="number"?v[p.declaration]?.op:"");s.push(E?{...p,declaration:o(E)}:{...p})}}}let T=(y,v,p="translation")=>p==="baseColorFactor"||p==="metallicFactor"||p==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${p}`:p==="emissiveFactor"||p==="alphaCutoff"?`/materials/${Math.max(0,v)}/${p}`:p==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${p}`,S=new Map;n.forEach((y,v)=>{typeof y?.name=="string"&&!S.has(y.name)&&S.set(y.name,v)});let _=(y,v)=>typeof y.target=="string"&&S.has(y.target)?S.get(y.target):typeof y.targetNode=="number"?y.targetNode:v,I=y=>{let v=n[y];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<n.length;y++){let v=n[y],p=v?.extras?.interactivity;if(!p||typeof p!="object")continue;let E=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,d=w=>{let R=Array.isArray(w)?w:[w],D=[];for(let M=0;M<R.length;M++){let g=R[M];if(!g||typeof g!="object")continue;let U=g.action||"interpolate",C=typeof g.duration=="number"?g.duration:.35;if(U==="toggleTransform"){let V=g.property==="rotation"||g.property==="scale"?g.property:"translation",O=V==="rotation"?v.rotation||[0,0,0,1]:V==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],P=`/nodes/${y}/${V}`,F=l(`__toggle_${y}_${M}`,"bool",!1),A=h("variable/get",{configuration:{variable:F}}),B=h("math/not",{values:{a:b(A)}}),k=h("variable/set",{configuration:{variable:F},values:{value:b(B)}}),z=h("pointer/interpolate",{configuration:{pointer:P},values:{value:{value:Array.isArray(g.to)?g.to:O},duration:{value:C}}}),N=h("pointer/interpolate",{configuration:{pointer:P},values:{value:{value:Array.isArray(g.from)?g.from:O},duration:{value:C}}});s[k].flows={out:{node:h("flow/branch",{values:{condition:b(A)},flows:{true:{node:z},false:{node:N}}})}},D.push(k)}else if(U==="interpolate"){let V=g.to??g.value;if(V===void 0)continue;let O={value:{value:V},duration:{value:C}};g.from!==void 0&&(O.from={value:g.from}),D.push(h("pointer/interpolate",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:T(_(g,y),I(_(g,y)),g.property)},values:O}))}else if(U==="setProperty"){if(g.value===void 0)continue;D.push(h("pointer/set",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:T(_(g,y),I(_(g,y)),g.property)},values:{value:{value:g.value}}}))}else if(U==="toggleVisibility"){let V=_(g,y),O=l(`__vis_${V}_${M}`,"bool",!0),P=h("variable/get",{configuration:{variable:O}}),F=h("math/not",{values:{a:b(P)}}),A=h("variable/set",{configuration:{variable:O},values:{value:b(F)}});s[A].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:b(P)}})}},D.push(A)}else if(U==="cycleMaterialColor"&&Array.isArray(g.colors)&&g.colors.length>0){let V=typeof g.duration=="number"?g.duration:.25,O=`/materials/${Math.max(0,E)}/pbrMetallicRoughness/baseColorFactor`,P=l(`__color_idx_${y}_${M}`,"int",0),F=h("variable/get",{configuration:{variable:P}}),A=h("math/add",{values:{a:b(F),b:{value:1}}}),B=h("math/rem",{values:{a:b(A),b:{value:g.colors.length}}}),k=h("variable/set",{configuration:{variable:P},values:{value:b(B)}}),z={};for(let N=0;N<g.colors.length;N++){let H=g.colors[N],Y=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(N)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Y},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:O},values:{value:{value:Y}}})}}s[k].flows={out:{node:h("flow/switch",{values:{selection:b(F)},flows:z})}},D.push(k)}else if(U==="playAnimation")D.push(h("animation/start",{configuration:{animation:g.animation??g.clip??0}}));else if(U==="stopAnimation")D.push(h("animation/stop"));else if(U==="sendEvent"){let V={};for(let[O,P]of Object.entries(g.values||{}))V[O]={value:P};D.push(h("event/send",{configuration:{event:a(String(g.event??g.id??"custom"))},values:V}))}}if(!D.length)return null;if(D.length===1)return D[0];let L={};return D.forEach((M,g)=>{L[String(g)]={node:M}}),h("flow/sequence",{flows:L})},x=(w,R,D)=>{let L=d(R);L!==null&&h(w,{...D?{configuration:D}:{},flows:{out:{node:L}}})};if(p.onSelect&&x("pointer/onSelect",p.onSelect,{nodeIndex:y}),p.onHoverIn&&x("pointer/onHoverIn",p.onHoverIn,{nodeIndex:y}),p.onHoverOut&&x("pointer/onHoverOut",p.onHoverOut,{nodeIndex:y}),p.onStart&&x("event/onStart",p.onStart),p.onReceive&&typeof p.onReceive=="object")for(let[w,R]of Object.entries(p.onReceive))x("event/receive",R,{event:a(w)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:m}],graph:0}:null}var Gt='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).',Wt="Security Error: client-side scripts require allow-client-scripts opt-in.";var Be="__THREE_LIVE_REGISTRY__";function ee(){let n=typeof globalThis<"u"?globalThis:{};if(!n[Be]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Be,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Be]=e}}return n[Be]}var j=ee().plugins;function $t(n){let e=ee().plugins;e.some(t=>t.name===n.name)||e.push(n)}function Yt(){return ee().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Oe(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Te(n,e,t,r){let[i,s,c]=e,[m,u,o]=r,[a,h,l]=t,b=i-a,f=s-h,T=c-l,S=Math.hypot(b,f,T);S<=1e-5?(b=0,f=0,T=1):(b/=S,f/=S,T/=S);let _=u*T-o*f,I=o*b-m*T,y=m*f-u*b;S=Math.hypot(_,I,y),S<=1e-5?(_=0,I=0,y=0):(_/=S,I/=S,y/=S);let v=f*y-T*I,p=T*_-b*y,E=b*I-f*_;return S=Math.hypot(v,p,E),S<=1e-5?(v=0,p=0,E=0):(v/=S,p/=S,E/=S),n[0]=_,n[1]=v,n[2]=b,n[3]=0,n[4]=I,n[5]=p,n[6]=f,n[7]=0,n[8]=y,n[9]=E,n[10]=T,n[11]=0,n[12]=-(_*i+I*s+y*c),n[13]=-(v*i+p*s+E*c),n[14]=-(b*i+f*s+T*c),n[15]=1,n}function te(n,e,t){let r=e[0],i=e[1],s=e[2],c=e[3],m=e[4],u=e[5],o=e[6],a=e[7],h=e[8],l=e[9],b=e[10],f=e[11],T=e[12],S=e[13],_=e[14],I=e[15],y=t[0],v=t[1],p=t[2],E=t[3];return n[0]=y*r+v*m+p*h+E*T,n[1]=y*i+v*u+p*l+E*S,n[2]=y*s+v*o+p*b+E*_,n[3]=y*c+v*a+p*f+E*I,y=t[4],v=t[5],p=t[6],E=t[7],n[4]=y*r+v*m+p*h+E*T,n[5]=y*i+v*u+p*l+E*S,n[6]=y*s+v*o+p*b+E*_,n[7]=y*c+v*a+p*f+E*I,y=t[8],v=t[9],p=t[10],E=t[11],n[8]=y*r+v*m+p*h+E*T,n[9]=y*i+v*u+p*l+E*S,n[10]=y*s+v*o+p*b+E*_,n[11]=y*c+v*a+p*f+E*I,y=t[12],v=t[13],p=t[14],E=t[15],n[12]=y*r+v*m+p*h+E*T,n[13]=y*i+v*u+p*l+E*S,n[14]=y*s+v*o+p*b+E*_,n[15]=y*c+v*a+p*f+E*I,n}function ze(n,e,t,r){let i=e[0],s=e[1],c=e[2],m=e[3],u=i+i,o=s+s,a=c+c,h=i*u,l=i*o,b=i*a,f=s*o,T=s*a,S=c*a,_=m*u,I=m*o,y=m*a,v=r[0],p=r[1],E=r[2];return n[0]=(1-(f+S))*v,n[1]=(l+y)*v,n[2]=(b-I)*v,n[3]=0,n[4]=(l-y)*p,n[5]=(1-(h+S))*p,n[6]=(T+_)*p,n[7]=0,n[8]=(b+I)*E,n[9]=(T-_)*E,n[10]=(1-(h+f))*E,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function re(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],c=e[5],m=e[6],u=e[8],o=e[9],a=e[10],h=a*c-m*o,l=-a*s+m*u,b=o*s-c*u,f=t*h+r*l+i*b;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*o)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*s)*f,n[6]=b*f,n[7]=(-o*t+r*u)*f,n[8]=(c*t-r*s)*f),n}function qt(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],c=e[4],m=e[5],u=e[6],o=e[7],a=e[8],h=e[9],l=e[10],b=e[11],f=e[12],T=e[13],S=e[14],_=e[15],I=t*m-r*c,y=t*u-i*c,v=t*o-s*c,p=r*u-i*m,E=r*o-s*m,d=i*o-s*u,x=a*T-h*f,w=a*S-l*f,R=a*_-b*f,D=h*S-l*T,L=h*_-b*T,M=l*_-b*S,g=I*M-y*L+v*D+p*R-E*w+d*x;return g?(g=1/g,n[0]=(m*M-u*L+o*D)*g,n[1]=(i*L-r*M-s*D)*g,n[2]=(T*d-S*E+_*p)*g,n[3]=(l*E-h*d-b*p)*g,n[4]=(u*R-c*M-o*w)*g,n[5]=(t*M-i*R+s*w)*g,n[6]=(S*v-f*d-_*y)*g,n[7]=(a*d-l*v+b*y)*g,n[8]=(c*L-m*R+o*x)*g,n[9]=(r*R-t*L-s*x)*g,n[10]=(f*E-T*v+_*I)*g,n[11]=(h*v-a*E-b*I)*g,n[12]=(m*w-c*D-u*x)*g,n[13]=(t*D-r*w+i*x)*g,n[14]=(T*y-f*p-S*I)*g,n[15]=(a*p-h*y+l*I)*g,n):null}function at(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],c=i[1]*e+i[5]*t+i[9]*r+i[13],m=i[2]*e+i[6]*t+i[10]*r+i[14],u=i[3]*e+i[7]*t+i[11]*r+i[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=c*o,n[2]=m*o}function Kt(n,e,t,r,i,s,c,m,u,o,a,h,l,b,f,T,S=0){let _=o-c,I=a-m,y=h-u,v=l-c,p=b-m,E=f-u,d=i*E-s*p,x=s*v-r*E,w=r*p-i*v,R=_*d+I*x+y*w;if(R>-1e-7&&R<1e-7)return!1;let D=1/R,L=n-c,M=e-m,g=t-u,U=D*(L*d+M*x+g*w);if(U<-S||U>1+S)return!1;let C=M*y-g*I,V=g*_-L*y,O=L*I-M*_,P=D*(r*C+i*V+s*O);if(P<-S||U+P>1+S)return!1;let F=D*(v*C+p*V+E*O);if(F>1e-4&&F<T.distance){T.distance=F,T.point=[n+r*F,e+i*F,t+s*F];let A=I*E-y*p,B=y*v-_*E,k=_*p-I*v,z=Math.hypot(A,B,k)||1;return T.normal=[A/z,B/z,k/z],!0}return!1}function Ve(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(q());if(t===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||s.has(a))return;s.add(a);let b=n.nodes[a];if(!b)return;let f=q();if(e&&e[a])f.set(e[a]);else if(b.matrix&&b.matrix.length===16)f.set(b.matrix);else{let S=b.translation||[0,0,0],_=b.rotation||[0,0,0,1],I=b.scale||[1,1,1];ze(f,_,S,I)}let T=r[a];if(h?te(T,h,f):T.set(f),Array.isArray(b.children))for(let S of b.children)typeof S=="number"&&m(S,T,l+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)i.has(a)||u.push(a);for(let a of u)m(a,null);for(let a=0;a<t;a++)!i.has(a)&&!u.includes(a)&&m(a,null);return r}function Cn(n){return new TextDecoder().decode(n)}var Jt=ee().decoders;function In(n,e){Jt.set(n.toLowerCase(),e)}function Ce(n){return Jt.get(n.toLowerCase())}function Qt(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let l=t.getUint8(0);throw l===123||l===32||l===10||l===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=s&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),b=t.getUint32(c+4,!0),f=c+8;if(f+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${f+l} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let T=new Uint8Array(e,f,l),S=Cn(T);m=JSON.parse(S,(_,I)=>_==="__proto__"||_==="constructor"||_==="prototype"?void 0:I)}else b===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let o=m.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!Ce("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!Ce("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!Ce("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of j)l.onParseGLB?.(h);return h}function Ln(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function Ie(n){if(Ln(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return Qt(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var en=`#version 300 es
17
+ function Gt(n,e,t){let r=[],i=new Map,s=[],c=[],m=[],u=new Map,o=y=>{let v=i.get(y);return v===void 0&&(v=r.length,r.push({op:y}),i.set(y,v)),v},a=y=>{let v=u.get(y);return v===void 0&&(v=m.length,m.push({id:y}),u.set(y,v)),v},h=(y,v={})=>s.push({declaration:o(y),...v})-1,l=(y,v,p)=>c.push({id:y,type:v,value:p})-1,b=y=>({node:y,socket:"value"}),f=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let y=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(y&&Array.isArray(y.nodes)){let v=Array.isArray(y.declarations)?y.declarations:[];for(let p of v)p?.op&&o(p.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let p of y.events||[])p?.id&&a(p.id);for(let p of y.nodes){if(!p||typeof p!="object")continue;let E=p.op||(typeof p.declaration=="number"?v[p.declaration]?.op:"");s.push(E?{...p,declaration:o(E)}:{...p})}}}let T=(y,v,p="translation")=>p==="baseColorFactor"||p==="metallicFactor"||p==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${p}`:p==="emissiveFactor"||p==="alphaCutoff"?`/materials/${Math.max(0,v)}/${p}`:p==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${p}`,S=new Map;n.forEach((y,v)=>{typeof y?.name=="string"&&!S.has(y.name)&&S.set(y.name,v)});let _=(y,v)=>typeof y.target=="string"&&S.has(y.target)?S.get(y.target):typeof y.targetNode=="number"?y.targetNode:v,C=y=>{let v=n[y];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<n.length;y++){let v=n[y],p=v?.extras?.interactivity;if(!p||typeof p!="object")continue;let E=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,d=w=>{let R=Array.isArray(w)?w:[w],D=[];for(let M=0;M<R.length;M++){let g=R[M];if(!g||typeof g!="object")continue;let U=g.action||"interpolate",I=typeof g.duration=="number"?g.duration:.35;if(U==="toggleTransform"){let V=g.property==="rotation"||g.property==="scale"?g.property:"translation",O=V==="rotation"?v.rotation||[0,0,0,1]:V==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],P=`/nodes/${y}/${V}`,F=l(`__toggle_${y}_${M}`,"bool",!1),A=h("variable/get",{configuration:{variable:F}}),B=h("math/not",{values:{a:b(A)}}),k=h("variable/set",{configuration:{variable:F},values:{value:b(B)}}),z=h("pointer/interpolate",{configuration:{pointer:P},values:{value:{value:Array.isArray(g.to)?g.to:O},duration:{value:I}}}),N=h("pointer/interpolate",{configuration:{pointer:P},values:{value:{value:Array.isArray(g.from)?g.from:O},duration:{value:I}}});s[k].flows={out:{node:h("flow/branch",{values:{condition:b(A)},flows:{true:{node:z},false:{node:N}}})}},D.push(k)}else if(U==="interpolate"){let V=g.to??g.value;if(V===void 0)continue;let O={value:{value:V},duration:{value:I}};g.from!==void 0&&(O.from={value:g.from}),D.push(h("pointer/interpolate",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:T(_(g,y),C(_(g,y)),g.property)},values:O}))}else if(U==="setProperty"){if(g.value===void 0)continue;D.push(h("pointer/set",{configuration:{pointer:typeof g.pointer=="string"?g.pointer:T(_(g,y),C(_(g,y)),g.property)},values:{value:{value:g.value}}}))}else if(U==="toggleVisibility"){let V=_(g,y),O=l(`__vis_${V}_${M}`,"bool",!0),P=h("variable/get",{configuration:{variable:O}}),F=h("math/not",{values:{a:b(P)}}),A=h("variable/set",{configuration:{variable:O},values:{value:b(F)}});s[A].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:b(P)}})}},D.push(A)}else if(U==="cycleMaterialColor"&&Array.isArray(g.colors)&&g.colors.length>0){let V=typeof g.duration=="number"?g.duration:.25,O=`/materials/${Math.max(0,E)}/pbrMetallicRoughness/baseColorFactor`,P=l(`__color_idx_${y}_${M}`,"int",0),F=h("variable/get",{configuration:{variable:P}}),A=h("math/add",{values:{a:b(F),b:{value:1}}}),B=h("math/rem",{values:{a:b(A),b:{value:g.colors.length}}}),k=h("variable/set",{configuration:{variable:P},values:{value:b(B)}}),z={};for(let N=0;N<g.colors.length;N++){let H=g.colors[N],$=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(N)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:$},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:O},values:{value:{value:$}}})}}s[k].flows={out:{node:h("flow/switch",{values:{selection:b(F)},flows:z})}},D.push(k)}else if(U==="playAnimation")D.push(h("animation/start",{configuration:{animation:g.animation??g.clip??0}}));else if(U==="stopAnimation")D.push(h("animation/stop"));else if(U==="sendEvent"){let V={};for(let[O,P]of Object.entries(g.values||{}))V[O]={value:P};D.push(h("event/send",{configuration:{event:a(String(g.event??g.id??"custom"))},values:V}))}}if(!D.length)return null;if(D.length===1)return D[0];let L={};return D.forEach((M,g)=>{L[String(g)]={node:M}}),h("flow/sequence",{flows:L})},x=(w,R,D)=>{let L=d(R);L!==null&&h(w,{...D?{configuration:D}:{},flows:{out:{node:L}}})};if(p.onSelect&&x("pointer/onSelect",p.onSelect,{nodeIndex:y}),p.onHoverIn&&x("pointer/onHoverIn",p.onHoverIn,{nodeIndex:y}),p.onHoverOut&&x("pointer/onHoverOut",p.onHoverOut,{nodeIndex:y}),p.onStart&&x("event/onStart",p.onStart),p.onReceive&&typeof p.onReceive=="object")for(let[w,R]of Object.entries(p.onReceive))x("event/receive",R,{event:a(w)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:m}],graph:0}:null}var Xt='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',Wt="Security Error: client-side scripts require allow-client-scripts opt-in.";var Be="__THREE_LIVE_REGISTRY__";function J(){let n=typeof globalThis<"u"?globalThis:{};if(!n[Be]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Be,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Be]=e}}return n[Be]}var Z=J().plugins;function $t(n){let e=J().plugins;e.some(t=>t.name===n.name)||e.push(n)}function Yt(){return J().plugins}function j(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Oe(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Te(n,e,t,r){let[i,s,c]=e,[m,u,o]=r,[a,h,l]=t,b=i-a,f=s-h,T=c-l,S=Math.hypot(b,f,T);S<=1e-5?(b=0,f=0,T=1):(b/=S,f/=S,T/=S);let _=u*T-o*f,C=o*b-m*T,y=m*f-u*b;S=Math.hypot(_,C,y),S<=1e-5?(_=0,C=0,y=0):(_/=S,C/=S,y/=S);let v=f*y-T*C,p=T*_-b*y,E=b*C-f*_;return S=Math.hypot(v,p,E),S<=1e-5?(v=0,p=0,E=0):(v/=S,p/=S,E/=S),n[0]=_,n[1]=v,n[2]=b,n[3]=0,n[4]=C,n[5]=p,n[6]=f,n[7]=0,n[8]=y,n[9]=E,n[10]=T,n[11]=0,n[12]=-(_*i+C*s+y*c),n[13]=-(v*i+p*s+E*c),n[14]=-(b*i+f*s+T*c),n[15]=1,n}function te(n,e,t){let r=e[0],i=e[1],s=e[2],c=e[3],m=e[4],u=e[5],o=e[6],a=e[7],h=e[8],l=e[9],b=e[10],f=e[11],T=e[12],S=e[13],_=e[14],C=e[15],y=t[0],v=t[1],p=t[2],E=t[3];return n[0]=y*r+v*m+p*h+E*T,n[1]=y*i+v*u+p*l+E*S,n[2]=y*s+v*o+p*b+E*_,n[3]=y*c+v*a+p*f+E*C,y=t[4],v=t[5],p=t[6],E=t[7],n[4]=y*r+v*m+p*h+E*T,n[5]=y*i+v*u+p*l+E*S,n[6]=y*s+v*o+p*b+E*_,n[7]=y*c+v*a+p*f+E*C,y=t[8],v=t[9],p=t[10],E=t[11],n[8]=y*r+v*m+p*h+E*T,n[9]=y*i+v*u+p*l+E*S,n[10]=y*s+v*o+p*b+E*_,n[11]=y*c+v*a+p*f+E*C,y=t[12],v=t[13],p=t[14],E=t[15],n[12]=y*r+v*m+p*h+E*T,n[13]=y*i+v*u+p*l+E*S,n[14]=y*s+v*o+p*b+E*_,n[15]=y*c+v*a+p*f+E*C,n}function ze(n,e,t,r){let i=e[0],s=e[1],c=e[2],m=e[3],u=i+i,o=s+s,a=c+c,h=i*u,l=i*o,b=i*a,f=s*o,T=s*a,S=c*a,_=m*u,C=m*o,y=m*a,v=r[0],p=r[1],E=r[2];return n[0]=(1-(f+S))*v,n[1]=(l+y)*v,n[2]=(b-C)*v,n[3]=0,n[4]=(l-y)*p,n[5]=(1-(h+S))*p,n[6]=(T+_)*p,n[7]=0,n[8]=(b+C)*E,n[9]=(T-_)*E,n[10]=(1-(h+f))*E,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function re(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],c=e[5],m=e[6],u=e[8],o=e[9],a=e[10],h=a*c-m*o,l=-a*s+m*u,b=o*s-c*u,f=t*h+r*l+i*b;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*o)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*s)*f,n[6]=b*f,n[7]=(-o*t+r*u)*f,n[8]=(c*t-r*s)*f),n}function qt(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],c=e[4],m=e[5],u=e[6],o=e[7],a=e[8],h=e[9],l=e[10],b=e[11],f=e[12],T=e[13],S=e[14],_=e[15],C=t*m-r*c,y=t*u-i*c,v=t*o-s*c,p=r*u-i*m,E=r*o-s*m,d=i*o-s*u,x=a*T-h*f,w=a*S-l*f,R=a*_-b*f,D=h*S-l*T,L=h*_-b*T,M=l*_-b*S,g=C*M-y*L+v*D+p*R-E*w+d*x;return g?(g=1/g,n[0]=(m*M-u*L+o*D)*g,n[1]=(i*L-r*M-s*D)*g,n[2]=(T*d-S*E+_*p)*g,n[3]=(l*E-h*d-b*p)*g,n[4]=(u*R-c*M-o*w)*g,n[5]=(t*M-i*R+s*w)*g,n[6]=(S*v-f*d-_*y)*g,n[7]=(a*d-l*v+b*y)*g,n[8]=(c*L-m*R+o*x)*g,n[9]=(r*R-t*L-s*x)*g,n[10]=(f*E-T*v+_*C)*g,n[11]=(h*v-a*E-b*C)*g,n[12]=(m*w-c*D-u*x)*g,n[13]=(t*D-r*w+i*x)*g,n[14]=(T*y-f*p-S*C)*g,n[15]=(a*p-h*y+l*C)*g,n):null}function at(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],c=i[1]*e+i[5]*t+i[9]*r+i[13],m=i[2]*e+i[6]*t+i[10]*r+i[14],u=i[3]*e+i[7]*t+i[11]*r+i[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=c*o,n[2]=m*o}function jt(n,e,t,r,i,s,c,m,u,o,a,h,l,b,f,T,S=0){let _=o-c,C=a-m,y=h-u,v=l-c,p=b-m,E=f-u,d=i*E-s*p,x=s*v-r*E,w=r*p-i*v,R=_*d+C*x+y*w;if(R>-1e-7&&R<1e-7)return!1;let D=1/R,L=n-c,M=e-m,g=t-u,U=D*(L*d+M*x+g*w);if(U<-S||U>1+S)return!1;let I=M*y-g*C,V=g*_-L*y,O=L*C-M*_,P=D*(r*I+i*V+s*O);if(P<-S||U+P>1+S)return!1;let F=D*(v*I+p*V+E*O);if(F>1e-4&&F<T.distance){T.distance=F,T.point=[n+r*F,e+i*F,t+s*F];let A=C*E-y*p,B=y*v-_*E,k=_*p-C*v,z=Math.hypot(A,B,k)||1;return T.normal=[A/z,B/z,k/z],!0}return!1}function Ve(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(j());if(t===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||s.has(a))return;s.add(a);let b=n.nodes[a];if(!b)return;let f=j();if(e&&e[a])f.set(e[a]);else if(b.matrix&&b.matrix.length===16)f.set(b.matrix);else{let S=b.translation||[0,0,0],_=b.rotation||[0,0,0,1],C=b.scale||[1,1,1];ze(f,_,S,C)}let T=r[a];if(h?te(T,h,f):T.set(f),Array.isArray(b.children))for(let S of b.children)typeof S=="number"&&m(S,T,l+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)i.has(a)||u.push(a);for(let a of u)m(a,null);for(let a=0;a<t;a++)!i.has(a)&&!u.includes(a)&&m(a,null);return r}function In(n){return new TextDecoder().decode(n)}var Qt=J().decoders;function Ln(n,e){Qt.set(n.toLowerCase(),e)}function Ce(n){return Qt.get(n.toLowerCase())}function en(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let l=t.getUint8(0);throw l===123||l===32||l===10||l===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=s&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),b=t.getUint32(c+4,!0),f=c+8;if(f+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${f+l} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let T=new Uint8Array(e,f,l),S=In(T);m=JSON.parse(S,(_,C)=>_==="__proto__"||_==="constructor"||_==="prototype"?void 0:C)}else b===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let o=m.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!Ce("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!Ce("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!Ce("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of Z)l.onParseGLB?.(h);return h}function Pn(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 Ie(n){if(Pn(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return en(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var tn=`#version 300 es
18
18
  layout(location=0) in vec3 aPosition;
19
19
  layout(location=1) in vec3 aNormal;
20
20
  layout(location=2) in vec2 aUV;
@@ -32,7 +32,7 @@ vec2 scaleUV=uUvTransform.zw;
32
32
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
33
  vUV=aUV*scaleUV+uUvTransform.xy;
34
34
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,tn=`#version 300 es
35
+ }`,Fn=`#version 300 es
36
36
  precision highp float;
37
37
  in vec3 vNormal,vWorldPos;
38
38
  in vec2 vUV;
@@ -40,14 +40,13 @@ uniform vec4 uBaseColor;
40
40
  uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
41
41
  uniform vec2 uClearcoat;
42
42
  uniform vec3 uCameraPos,uAmbientColor;
43
- uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uXrDepthTex;
44
- uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uXrDepthEnabled,uXrDepthFormat;
45
- uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
46
- uniform mat4 uXrDepthUVTransform;
43
+ uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
44
+ uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap;
45
+ uniform float uNormalScale,uOcclusionStrength;
46
+ /*XRD_U*/
47
47
  uniform vec2 uViewportSize;
48
- uniform vec4 uViewport;
49
- uniform vec3 uCameraFwd;
50
- uniform int uToneMapping,uNumDirLights,uNumPointLights;
48
+ uniform vec4 uSectionPlane;
49
+ uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
51
50
  uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
52
51
  out vec4 fragColor;
53
52
 
@@ -116,6 +115,7 @@ return color;
116
115
  }
117
116
 
118
117
  void main(){
118
+ if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
119
119
  vec4 base=uBaseColor;
120
120
  if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
121
121
  if(length(vNormal)<1e-4&&uHasTexture==1){
@@ -196,31 +196,17 @@ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
196
196
  }
197
197
  color=applyToneMapping(color,uToneMapping);
198
198
  float outAlpha=base.a;
199
- if(uXrDepthEnabled==1){
200
- vec2 normViewUV=vec2((gl_FragCoord.x-uViewport.x)/max(uViewport.z,1.0),1.0-(gl_FragCoord.y-uViewport.y)/max(uViewport.w,1.0));
201
- vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
202
- if(depthUV.x>=0.0&&depthUV.x<=1.0&&depthUV.y>=0.0&&depthUV.y<=1.0){
203
- vec4 depthSample=texture(uXrDepthTex,depthUV);
204
- float rawDepth=uXrDepthFormat==1?depthSample.r:(depthSample.r*255.0+depthSample.a*65280.0);
205
- float realDepth=rawDepth*uXrRawValueToMeters;
206
- float virtDepth=dot(uCameraFwd,uCameraFwd)>0.5?dot(vWorldPos-uCameraPos,uCameraFwd):length(uCameraPos-vWorldPos);
207
- if(rawDepth>0.0&&(uXrDepthFormat==1||rawDepth<65500.0)&&realDepth>0.15&&realDepth<20.0&&virtDepth>realDepth+0.02){
208
- float occAlpha=1.0-smoothstep(0.0,0.035,virtDepth-realDepth-0.02);
209
- outAlpha*=occAlpha;
210
- if(outAlpha<0.01)discard;
211
- }
212
- }
213
- }
199
+ /*XRD_O*/
214
200
  fragColor=vec4(color,outAlpha);
215
- }`,Pn=`#version 300 es
201
+ }`,Un=`#version 300 es
216
202
  layout(location=0) in vec3 aPosition;
217
203
  uniform mat4 uMVP;
218
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Fn=`#version 300 es
204
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Nn=`#version 300 es
219
205
  precision highp float;
220
206
  uniform vec4 uColorId;
221
207
  out vec4 fragColor;
222
- void main(){fragColor=uColorId;}`;function jt(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function ut(n,e,t){let r=jt(n,35633,e),i=jt(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let c=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${c}`)}return s}function lt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var nn=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize","uViewport","uCameraFwd"];function Un(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function ct(n,e,t,r,i,s,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],o=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,h;if(a===s)h=new Float32Array(t,o,m.count*s);else{h=new Float32Array(m.count*s);let b=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let T=0;T<m.count;T++){let S=f+T*a;for(let _=0;_<s;_++)h[T*s+_]=b[S+_]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var br=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),rn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Zt(n,e,t=rn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:s}=e,c=[],m=Ve(i),u=[];if(Array.isArray(i.nodes))for(let x=0;x<i.nodes.length;x++){let w=i.nodes[x];w.mesh!==void 0&&i.meshes&&i.meshes[w.mesh]&&u.push({node:w,nodeIdx:x,meshIdx:w.mesh})}let o=u.length>0?u:(i.meshes||[]).map((x,w)=>({node:x,nodeIdx:-1,meshIdx:w})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let x=i.extensions.KHR_lights_punctual.lights;for(let w of x){let R=w.type==="directional"?"directional":w.type==="point"?"point":"ambient";a.push({type:R,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${i.textures.length}`);for(let x=0;x<i.textures.length;x++){let w=i.textures[x],R=i.images[w.source];if(R){let D=n.createTexture();if(n.bindTexture(3553,D),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),R.bufferView!==void 0){let L=i.bufferViews[R.bufferView],M=s.slice(L.byteOffset||0,(L.byteOffset||0)+L.byteLength),g=new Blob([M],{type:R.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(g).then(U=>{n.bindTexture(3553,D),n.texImage2D(3553,0,6408,6408,5121,U),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(R.uri){let L=Un(R.uri);if(L){let M=new Image;M.crossOrigin="anonymous",M.referrerPolicy="no-referrer",M.onload=()=>{n.bindTexture(3553,D),n.texImage2D(3553,0,6408,6408,5121,M),n.generateMipmap(3553),r?.()},M.src=L}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",R.uri)}h.push(D)}else h.push(null)}}let l=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],f=0,T=0;for(let x=0;x<o.length;x++){let w=o[x],R=i.meshes[w.meshIdx],D=w.nodeIdx>=0?m[w.nodeIdx]:q(),L=new Float32Array(9);re(L,D);let M={name:w.node.name||R.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:D,normalMatrix:L,primitives:[],extras:w.node.extras||R.extras};for(let g of R.primitives||[]){if(g.extensions?.KHR_draco_mesh_compression){let $=Ce("draco");$&&$.decodePrimitive(i,g,s)}let U=[],C=n.createVertexArray();n.bindVertexArray(C);let V=i.accessors[g.attributes.POSITION],O=Number(V?.count??0);if(!Number.isFinite(O)||O<0||f+O>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=O,V?.min&&V?.max)for(let $=0;$<3;$++){let ie=D[12+$],we=D[12+$];for(let he=0;he<3;he++){let Ne=D[he*4+$]*V.min[he],ke=D[he*4+$]*V.max[he];ie+=Ne<ke?Ne:ke,we+=Ne>ke?Ne:ke}ie<l[$]&&(l[$]=ie),we>b[$]&&(b[$]=we)}let P=ct(n,i,s,g.attributes.POSITION,0,3,U);ct(n,i,s,g.attributes.NORMAL,1,3,U),ct(n,i,s,g.attributes.TEXCOORD_0,2,2,U);let F=0,A=5123,B=null;if(g.indices!==void 0){let $=i.accessors[g.indices],we=(i.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(F=Number($.count??0),!Number.isFinite(F)||F<0||T+F>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=F,A=$.componentType===5125?5125||5125:5123||5123;let he=n.createBuffer();U.push(he),n.bindBuffer(34963,he),$.componentType===5125?(B=new Uint32Array(s,we,$.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,we,$.count),n.bufferData(34963,B,35044))}else F=V.count;let k={};for(let $ of j)if($.onBuildPrimitiveVAO){let ie=$.onBuildPrimitiveVAO(n,C,g,i,s);ie&&(k[$.name]=ie)}n.bindVertexArray(null);let z=i.materials&&g.material!==void 0?i.materials[g.material]:null,N=en,H=tn,Y=!1;for(let $ of j)if($.onResolveShader){let ie=$.onResolveShader(g,z,N,H);ie&&(N=ie.vs,H=ie.fs,Y=!0)}let G=Y?ut(n,N,H):null,ae=G?lt(n,G,nn):null,Z=z?.pbrMetallicRoughness,Q=Z?.baseColorFactor||[.8,.8,.8,1],de=Z?.metallicFactor??.1,pe=Z?.roughnessFactor??.5,ce=z?.extensions?.KHR_materials_clearcoat,ne=ce?ce.clearcoatFactor??1:0,be=Math.max(.04,ce?.clearcoatRoughnessFactor??.04),ye=Z?.baseColorTexture!==void 0&&h[Z.baseColorTexture.index]?h[Z.baseColorTexture.index]:null,De=Z?.metallicRoughnessTexture!==void 0&&h[Z.metallicRoughnessTexture.index]?h[Z.metallicRoughnessTexture.index]:null,Sn=z?.normalTexture!==void 0&&h[z.normalTexture.index]?h[z.normalTexture.index]:null,Rn=z?.normalTexture?.scale??1,An=z?.occlusionTexture!==void 0&&h[z.occlusionTexture.index]?h[z.occlusionTexture.index]:null,_n=z?.occlusionTexture?.strength??1,Dn=!!(z?.extensions?.KHR_materials_transmission||k.materials?.isTransmissive);M.primitives.push({vao:C,indexCount:F,indexType:A,baseColor:Q,metallic:de,roughness:pe,clearcoat:ne,clearcoatRoughness:be,positions:P,indices:B,texture:ye,metallicRoughnessTexture:De,normalTexture:Sn,occlusionTexture:An,normalScale:Rn,occlusionStrength:_n,buffers:U,materialIndex:g.material,pluginData:k,customProgram:G,customUniforms:ae,isTransmissive:Dn})}c.push(M)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let S=[(l[0]+b[0])/2,(l[1]+b[1])/2,(l[2]+b[2])/2],_=b[0]-l[0],I=b[1]-l[1],y=b[2]-l[2],v=Math.max(Math.hypot(_,I,y)/2,.5),p=[l[0],l[1],l[2]],E=[b[0],b[1],b[2]],d=e.animations;if(!d){for(let x of j)if(x.onParseGLB?.(e),e.animations){d=e.animations;break}}return d||(d=[]),{meshes:c,bounds:{center:S,radius:v,min:p,max:E},lights:a,animations:d,worldMatrices:m}}var He=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=q();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=q();this.viewMatrix=q();this.modelMatrix=q();this.mvpMatrix=q();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:q(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),i=u}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.renderProg=ut(m,en,tn),this.pickProg=ut(m,Pn,Fn),this.uRender=lt(m,this.renderProg,nn),this.uPick=lt(m,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){In(e,t)}static getDecoder(e){return Ce(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:s,animations:c,worldMatrices:m}=Zt(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of j)o.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Qt(e))}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(Ie(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ie(e),{meshes:i}=Zt(this.gl,r,rn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],re(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),re(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],c=[],m=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&c.length<6){let h=u.position||[0,0,0];c.push(h[0],h[1],h[2]),m.push(o[0]*a,o[1]*a,o[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(t.uniform3fv(e.uPointLightPos,c),t.uniform3fv(e.uPointLightColor,m)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of j)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of j)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],c=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of j)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=q();te(r,this.projMatrix,this.viewMatrix);let[i,s,c]=e,m=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(m=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*c+r[12],l=r[1]*i+r[5]*s+r[9]*c+r[13],b=r[2]*i+r[6]*s+r[10]*c+r[14],f=r[3]*i+r[7]*s+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,S=l/f,_=b/f,I=this.canvas.getBoundingClientRect(),y=I.width||this.canvas.clientWidth||this.canvas.width||300,v=I.height||this.canvas.clientHeight||this.canvas.height||150,p=(T*.5+.5)*y,E=(-S*.5+.5)*v,d=T>=-1.1&&T<=1.1&&S>=-1.1&&S<=1.1&&_>=-1&&_<=1;if(d&&t){let x=this.customTarget||this.bounds.center,w=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=x[1]+this.currDistance*Math.sin(this.currPhi),D=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),L=[i-w,s-R,c-D];m*L[0]+u*L[1]+o*L[2]>.05&&(d=!1)}return{x:p,y:E,z:_,visible:d}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],m=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+s*m[0])*o,u[1]+=(-i*c[1]+s*m[1])*o,u[2]+=(-i*c[2]+s*m[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),u=i.height>0?Math.floor((t-i.top)*(c/i.height)):Math.floor(t);return this.performMeshPick(m,u,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let m=q();te(m,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==c)&&this.resizePickingFbo(s,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let d=0;d<this.meshes.length;d++){let x=this.meshes[d];if(x.visible===!1||x.isPluginMesh)continue;let w=d+1,R=(w&255)/255,D=(w>>8&255)/255,L=(w>>16&255)/255;i.uniform4f(this.uPick.uColorId,R,D,L,1),te(this.modelMatrix,this.modelRootMatrix,x.transform),te(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let M of x.primitives)i.bindVertexArray(M.vao),i.drawElements(4,M.indexCount,M.indexType,0)}let p=new Uint8Array(4);i.readPixels(o,a,1,1,6408,5121,p),i.bindFramebuffer(36160,null);let E=p[0]+(p[1]<<8)+(p[2]<<16);E>0&&E<=this.meshes.length&&(u=[this.meshes[E-1]])}u.length===0&&(u=this.meshes.filter(p=>p.visible!==!1));let h=null,l=1/0,b=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,S=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=T[1]+this.currDistance*Math.sin(this.currPhi),I=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let p of u){te(this.modelMatrix,this.modelRootMatrix,p.transform),te(this.mvpMatrix,m,this.modelMatrix);let E=q();if(!qt(E,this.mvpMatrix))continue;let d=(o+.5)/s*2-1,x=(a+.5)/c*2-1,w=[0,0,0],R=[0,0,0];at(w,d,x,-1,E),at(R,d,x,1,E);let D=R[0]-w[0],L=R[1]-w[1],M=R[2]-w[2],g=Math.hypot(D,L,M)||1,U=D/g,C=L/g,V=M/g,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((F=>{for(let A of p.primitives){if(!A.positions)continue;let B=A.positions,k=A.indices,z=Math.floor(k?k.length/3:B.length/9);for(let N=0;N<z;N++){let H=k?k[N*3]:N*3,Y=k?k[N*3+1]:N*3+1,G=k?k[N*3+2]:N*3+2;Kt(w[0],w[1],w[2],U,C,V,B[H*3],B[H*3+1],B[H*3+2],B[Y*3],B[Y*3+1],B[Y*3+2],B[G*3],B[G*3+1],B[G*3+2],O,F)}}})(1e-4),isFinite(O.distance)){let F=O.point[0],A=O.point[1],B=O.point[2],k=this.modelMatrix,z=k[0]*F+k[4]*A+k[8]*B+k[12],N=k[1]*F+k[5]*A+k[9]*B+k[13],H=k[2]*F+k[6]*A+k[10]*B+k[14],Y=z-S,G=N-_,ae=H-I,Z=Math.hypot(Y,G,ae);if(Z<l){re(this.normalMatrix,this.modelMatrix);let Q=this.normalMatrix,de=O.normal[0],pe=O.normal[1],ce=O.normal[2],ne=Q[0]*de+Q[3]*pe+Q[6]*ce,be=Q[1]*de+Q[4]*pe+Q[7]*ce,ye=Q[2]*de+Q[5]*pe+Q[8]*ce,De=Math.hypot(ne,be,ye)||1;ne/=De,be/=De,ye/=De,ne*Y+be*G+ye*ae>0&&(ne=-ne,be=-be,ye=-ye),h=p,l=Math.round(Z*1e3)/1e3,b=[Math.round(z*1e3)/1e3,Math.round(N*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(ne*1e3)/1e3,Math.round(be*1e3)/1e3,Math.round(ye*1e3)/1e3]}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:b,normal:f,screenX:e,screenY:t};if(r){for(let p of j)p.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}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,c=i?Math.max(1,t-r):r,m=(s+.5)/c*2-1;return Math.floor((m*.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);Oe(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Te(this.viewMatrix,[i,s,c],r,[0,1,0]),te(this.mvpMatrix,this.projMatrix,this.viewMatrix),re(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 j)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 j)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 c of j)c.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 c of j)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),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 c={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,t,r,i,s=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,o=e?.transform?.position,a=o?[o.x,o.y,o.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:m,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),E=Math.max(1,Math.floor(v*.5)),d=Math.max(1,v-E),x=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),w=this.customTarget||this.bounds.center,R=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=w[1]+this.currDistance*Math.sin(this.currPhi),L=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),M=Math.cos(this.currTheta),g=-Math.sin(this.currTheta),U=.032,C=q(),V=q(),O=[R-M*U,D,L-g*U],P=[w[0]-M*U*.25,w[1],w[2]-g*U*.25];Oe(C,this.fov,E/p,.1,x),Te(V,O,P,[0,1,0]);let F=q(),A=q(),B=[R+M*U,D,L+g*U],k=[w[0]+M*U*.25,w[1],w[2]+g*U*.25];Oe(F,this.fov,d/p,.1,x),Te(A,B,k,[0,1,0]),this.render({viewMatrix:V,projMatrix:C,eyePos:O,viewport:[0,0,E,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:A,projMatrix:F,eyePos:B,viewport:[E,0,d,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,r=0,i=0,s=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],c=e.viewport[3],t.viewport(r,i,s,c)):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 m=q(),u=e?.viewMatrix??this.viewMatrix;te(m,e?.projMatrix??this.projMatrix,u);let o=[-u[2],-u[6],-u[10]],a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,h=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),b=e?e.eyePos[1]:h[1]+this.currDistance*Math.sin(this.currPhi),f=e?e.eyePos[2]:h[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of j)v.onBeforeDrawScene?.(this,t,m,[l,b,f],a);let T=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let S=e?.eye||"none",_=!1,I=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=v=>{for(let p=0;p<I.length;p++){let E=I[p];if(E.visible===!1)continue;let d=this.selectedMeshName!==""&&E.name===this.selectedMeshName;p<T||E.worldSpace===!0||E.name==="__xr_reticle__"?this.modelMatrix.set(E.transform):te(this.modelMatrix,this.modelRootMatrix,E.transform),te(this.mvpMatrix,m,this.modelMatrix),re(E.normalMatrix,this.modelMatrix);let x=E.extras?.xr?.stereo||E.userData?.xr?.stereo,w=0,R=0,D=1,L=1;x==="sbs"?(D=.5,w=S==="right"?.5:0):x==="ou"&&(L=.5,R=S==="right"?.5:0);for(let M of E.primitives){let g=!!M.isTransmissive;if(!v&&g){_=!0;continue}if(v&&!g)continue;let U=M.customProgram||this.renderProg,C=M.customUniforms||this.uRender;t.useProgram(U),t.uniform1i(C.uToneMapping,a),t.uniform1f(C.uEnvIntensity,this.envIntensity),t.uniform3f(C.uCameraPos,l,b,f),C.uCameraFwd&&t.uniform3f(C.uCameraFwd,o[0],o[1],o[2]),t.uniform1f(C.uEmissive,d?1:0),t.uniformMatrix4fv(C.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(C.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(C.uNormalMatrix,!1,E.normalMatrix),C.uUvTransform&&t.uniform4f(C.uUvTransform,w,R,D,L),C.uViewportSize&&t.uniform2f(C.uViewportSize,Math.max(1,s),Math.max(1,c)),C.uViewport&&t.uniform4f(C.uViewport,r,i,Math.max(1,s),Math.max(1,c)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),C.uXrDepthTex&&t.uniform1i(C.uXrDepthTex,5),C.uXrDepthEnabled&&t.uniform1i(C.uXrDepthEnabled,1),C.uXrDepthFormat&&t.uniform1i(C.uXrDepthFormat,this.xrDepthState.format||0),C.uXrRawValueToMeters&&t.uniform1f(C.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),C.uXrDepthUVTransform&&t.uniformMatrix4fv(C.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):C.uXrDepthEnabled&&t.uniform1i(C.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(C.uEnvironmentMap,4),t.uniform1i(C.uHasEnvironmentMap,1)):t.uniform1i(C.uHasEnvironmentMap,0),this.bindLights(C);for(let V of j)V.onBeforeDrawPrimitive?.(t,U,M,E,this.worldMatrices||[],this.gltf);t.uniform4fv(C.uBaseColor,M.baseColor),t.uniform1f(C.uMetallic,M.metallic),t.uniform1f(C.uRoughness,M.roughness),C.uClearcoat&&t.uniform2f(C.uClearcoat,M.clearcoat??0,M.clearcoatRoughness??.04),M.texture?(t.activeTexture(33984),t.bindTexture(3553,M.texture),t.uniform1i(C.uBaseColorTexture,0),t.uniform1i(C.uHasTexture,1)):t.uniform1i(C.uHasTexture,0),M.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,M.metallicRoughnessTexture),t.uniform1i(C.uMetallicRoughnessTexture,1),t.uniform1i(C.uHasMetallicRoughnessTexture,1)):t.uniform1i(C.uHasMetallicRoughnessTexture,0),M.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,M.normalTexture),t.uniform1i(C.uNormalTexture,2),t.uniform1i(C.uHasNormalTexture,1),t.uniform1f(C.uNormalScale,M.normalScale)):t.uniform1i(C.uHasNormalTexture,0),M.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,M.occlusionTexture),t.uniform1i(C.uOcclusionTexture,3),t.uniform1i(C.uHasOcclusionTexture,1),t.uniform1f(C.uOcclusionStrength,M.occlusionStrength)):t.uniform1i(C.uHasOcclusionTexture,0),t.bindVertexArray(M.vao),t.drawElements(4,M.indexCount,M.indexType,0)}}};if(y(!1),_){for(let v of j)v.onBeforeTransmissivePass?.(t,this);y(!0)}for(let v of j)v.onAfterRender?.(t,this,m)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&t.deleteVertexArray(i.vao),i.buffers)for(let s of i.buffers)t.deleteBuffer(s);i.texture&&t.deleteTexture(i.texture),i.metallicRoughnessTexture&&t.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&t.deleteTexture(i.normalTexture),i.occlusionTexture&&t.deleteTexture(i.occlusionTexture),i.customProgram&&t.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of j)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()}};He.registerPlugin=$t,He.getRegisteredPlugins=Yt;function Nn(n){return n+3&-4}function kn(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function Le(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],c=[],m=[],u=new Set,o=[],a=[],h=new Map,l=[];function b(d,x){let w=new Uint8Array(d.buffer,d.byteOffset,d.byteLength),R=Nn(w.byteLength),D=new Uint8Array(R);D.set(w),t.push(D);let L=i.length;return i.push({buffer:0,byteOffset:r,byteLength:w.byteLength,target:x}),r+=R,L}function f(d,x,w,R,D,L,M){let g=b(d,w),U=s.length,C={bufferView:g,byteOffset:0,componentType:R,count:D,type:x};return L&&(C.min=L),M&&(C.max=M),s.push(C),U}n.traverse(d=>{(d.isLight||d.color&&d.intensity!==void 0)&&l.push({type:d.type,color:[d.color.r,d.color.g,d.color.b],intensity:d.intensity,position:[d.position.x,d.position.y,d.position.z]})});let T=[];function S(d){let x={name:d.name||""},w=d.position,R=d.quaternion,D=d.scale;if((w.x||w.y||w.z)&&(x.translation=[w.x,w.y,w.z]),(R.x||R.y||R.z||R.w!==1)&&(x.rotation=[R.x,R.y,R.z,R.w]),(D.x!==1||D.y!==1||D.z!==1)&&(x.scale=[D.x,D.y,D.z]),d.userData&&Object.keys(d.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(d.userData,(M,g)=>{if(!(M==="__proto__"||M==="prototype"||M==="constructor"))return typeof g=="function"?void 0:g})),d.userData.xr)){let M=kn(d.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:M,ANDROID_xr_scenecore:M},ee().xrTraitSerializer?.gltfNode(x,d.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(d.geometry){let M=d.geometry,g=M.attributes.position;if(g&&g.count>0){let U=[1/0,1/0,1/0],C=[-1/0,-1/0,-1/0];for(let F=0;F<g.count;F++){let A=g.getX(F),B=g.getY(F),k=g.getZ(F);A<U[0]&&(U[0]=A),A>C[0]&&(C[0]=A),B<U[1]&&(U[1]=B),B>C[1]&&(C[1]=B),k<U[2]&&(U[2]=k),k>C[2]&&(C[2]=k)}let O={attributes:{POSITION:f(g.array,"VEC3",34962,5126,g.count,U,C)}};if(M.attributes.normal&&(O.attributes.NORMAL=f(M.attributes.normal.array,"VEC3",34962,5126,M.attributes.normal.count)),M.attributes.uv&&(O.attributes.TEXCOORD_0=f(M.attributes.uv.array,"VEC2",34962,5126,M.attributes.uv.count)),M.index){let F=M.index.array instanceof Uint32Array;O.indices=f(M.index.array,"SCALAR",34963,F?5125:5123,M.index.count)}if(d.material){let F=h.get(d.material);if(F===void 0){F=a.length,h.set(d.material,F);let A=d.material,B={name:A.name||"",pbrMetallicRoughness:{baseColorFactor:[A.color.r,A.color.g,A.color.b,A.opacity],metallicFactor:A.metalness,roughnessFactor:A.roughness},doubleSided:A.side===2||A.doubleSided};if(A.emissive&&(A.emissive.r>0||A.emissive.g>0||A.emissive.b>0)){let z=A.emissiveIntensity??1;B.emissiveFactor=[A.emissive.r*z,A.emissive.g*z,A.emissive.b*z]}let k={};A.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:A.clearcoat,clearcoatRoughnessFactor:A.clearcoatRoughness||0}),A.sheen>0&&(k.KHR_materials_sheen={sheenColorFactor:A.sheenColor?[A.sheenColor.r,A.sheenColor.g,A.sheenColor.b]:[1,1,1],sheenRoughnessFactor:A.sheenRoughness||0}),A.transmission>0&&(k.KHR_materials_transmission={transmissionFactor:A.transmission}),A.thickness>0&&(k.KHR_materials_volume={thicknessFactor:A.thickness,attenuationDistance:A.attenuationDistance??1/0,attenuationColor:A.attenuationColor?[A.attenuationColor.r,A.attenuationColor.g,A.attenuationColor.b]:[1,1,1]}),A.ior!==void 0&&A.ior!==1.5&&(k.KHR_materials_ior={ior:A.ior}),A.dispersion>0&&(k.KHR_materials_dispersion={dispersion:A.dispersion}),A.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:A.iridescence,iridescenceIor:A.iridescenceIOR??1.3}),Object.keys(k).length>0&&(B.extensions=k),a.push(B)}O.material=F}let P=c.length;c.push({primitives:[O],name:d.name,...x.extras?{extras:x.extras}:{}}),x.mesh=P}}let L=m.length;if(m.push(x),o.push(d),d.children.length>0){x.children=[];for(let M of d.children)x.children.push(S(M))}return L}for(let d of n.children)T.push(S(d));let _=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),I=[];if(typeof _=="function"&&o.length>0){let d=e?.duration??4,x=e?.fps??15,w=Math.max(2,Math.round(d*x)+1),R=new Float32Array(w),D=o.map(P=>({px:P.position.x,py:P.position.y,pz:P.position.z,qx:P.quaternion.x,qy:P.quaternion.y,qz:P.quaternion.z,qw:P.quaternion.w,sx:P.scale.x,sy:P.scale.y,sz:P.scale.z})),L=o.map(()=>new Float32Array(w*3)),M=o.map(()=>new Float32Array(w*4)),g=o.map(()=>new Float32Array(w*3));for(let P=0;P<w;P++){let F=P/(w-1)*d;R[P]=F;try{_(F)}catch{}for(let A=0;A<o.length;A++){let B=o[A];L[A][P*3]=B.position.x,L[A][P*3+1]=B.position.y,L[A][P*3+2]=B.position.z,M[A][P*4]=B.quaternion.x,M[A][P*4+1]=B.quaternion.y,M[A][P*4+2]=B.quaternion.z,M[A][P*4+3]=B.quaternion.w,g[A][P*3]=B.scale.x,g[A][P*3+1]=B.scale.y,g[A][P*3+2]=B.scale.z}}for(let P=0;P<o.length;P++){let F=o[P],A=D[P];F.position.set(A.px,A.py,A.pz),F.quaternion.set(A.qx,A.qy,A.qz,A.qw),F.scale.set(A.sx,A.sy,A.sz)}n.updateMatrixWorld(!0);let U=null,C=()=>(U===null&&(U=f(R,"SCALAR",0,5126,w,[0],[d])),U),V=[],O=[];for(let P=0;P<o.length;P++){let F=D[P],A=!1,B=!1,k=!1;for(let z=0;z<w;z++)(Math.abs(L[P][z*3]-F.px)>1e-4||Math.abs(L[P][z*3+1]-F.py)>1e-4||Math.abs(L[P][z*3+2]-F.pz)>1e-4)&&(A=!0),(Math.abs(M[P][z*4]-F.qx)>1e-4||Math.abs(M[P][z*4+1]-F.qy)>1e-4||Math.abs(M[P][z*4+2]-F.qz)>1e-4||Math.abs(M[P][z*4+3]-F.qw)>1e-4)&&(B=!0),(Math.abs(g[P][z*3]-F.sx)>1e-4||Math.abs(g[P][z*3+1]-F.sy)>1e-4||Math.abs(g[P][z*3+2]-F.sz)>1e-4)&&(k=!0);if(A){let z=f(L[P],"VEC3",0,5126,w),N=V.length;V.push({input:C(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"translation"}})}if(B){let z=f(M[P],"VEC4",0,5126,w),N=V.length;V.push({input:C(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"rotation"}})}if(k){let z=f(g[P],"VEC3",0,5126,w),N=V.length;V.push({input:C(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"scale"}})}}O.length>0&&I.push({name:"ProceduralLoop",samplers:V,channels:O})}let y=Xt(m,c,n.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:a,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...I.length>0?{animations:I}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},p=new Uint8Array(r),E=0;for(let d of t)p.set(d,E),E+=d.byteLength;return{gltf:v,bin:p.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function Ge(n){return new TextEncoder().encode(n)}function We(n,e){let{gltf:t,bin:r}=Le(n,e),i=JSON.stringify(t),s=Ge(i),c=(4-s.byteLength%4)%4,m=s.byteLength+c,u=20+m+8+r.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let l=0;l<c;l++)o[20+s.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),o.set(new Uint8Array(r),h+8),o}function Bn(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let c=s.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let d=0;d<c;d++){let x=s.getX(d),w=s.getY(d),R=s.getZ(d);m[d*3]=u[0]*x+u[4]*w+u[8]*R+u[12],m[d*3+1]=u[1]*x+u[5]*w+u[9]*R+u[13],m[d*3+2]=u[2]*x+u[6]*w+u[10]*R+u[14]}let o;if(i.attributes.normal){let d=i.attributes.normal;o=new Float32Array(c*3);let x=new Float32Array(9);re(x,u);for(let w=0;w<c;w++){let R=d.getX(w),D=d.getY(w),L=d.getZ(w),M=x[0]*R+x[3]*D+x[6]*L,g=x[1]*R+x[4]*D+x[7]*L,U=x[2]*R+x[5]*D+x[8]*L,C=Math.hypot(M,g,U)||1;o[w*3]=M/C,o[w*3+1]=g/C,o[w*3+2]=U/C}}let a;if(i.attributes.uv){let d=i.attributes.uv;a=new Float32Array(c*2);for(let x=0;x<c;x++)a[x*2]=d.getX(x),a[x*2+1]=d.getY(x)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let d=0;d<c;d++)h[d]=d}let l="DefaultMaterial",b=[.8,.8,.8],f=.5,T=.1,S=0,_=0,I=1.5,y=1,v=[0,0,0];if(r.material){let d=r.material;l=d.name||`Material_${t.length}`,d.color&&(b=[d.color.r,d.color.g,d.color.b]),typeof d.roughness=="number"&&(f=d.roughness),typeof d.metalness=="number"&&(T=d.metalness),typeof d.clearcoat=="number"&&(S=d.clearcoat),typeof d.clearcoatRoughness=="number"&&(_=d.clearcoatRoughness),typeof d.ior=="number"&&(I=d.ior);let x=typeof d.opacity=="number"?d.opacity:1,w=typeof d.transmission=="number"?d.transmission:0;if(y=x*(1-w),d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let R=d.emissiveIntensity??1;v=[d.emissive.r*R,d.emissive.g*R,d.emissive.b*R]}}let p,E=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 E=="function"){let d=e?.duration??4,x=e?.fps??4,w=Math.max(2,Math.round(d*x)+1),R=[],D=[],L=[],M=[],g=[r.position.x,r.position.y,r.position.z],U=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],C=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let O=0;O<w;O++){let P=O/(w-1)*d;R.push(P);try{E(P)}catch{}D.push([r.position.x,r.position.y,r.position.z]),L.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),M.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-g[0])>1e-4||Math.abs(r.position.y-g[1])>1e-4||Math.abs(r.position.z-g[2])>1e-4||Math.abs(r.quaternion.x-U[0])>1e-4||Math.abs(r.quaternion.y-U[1])>1e-4||Math.abs(r.quaternion.z-U[2])>1e-4||Math.abs(r.quaternion.w-U[3])>1e-4||Math.abs(r.scale.x-C[0])>1e-4)&&(V=!0)}r.position.set(g[0],g[1],g[2]),r.quaternion.set(U[0],U[1],U[2],U[3]),r.scale.set(C[0],C[1],C[2]),V&&(p={times:R,translations:D,rotations:L,scales:M})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:o,uvs:a,materialName:l,color:b,roughness:f,metallic:T,clearcoat:S,clearcoatRoughness:_,ior:I,opacity:y,emissiveColor:v,xrTraits:r.userData?.xr,timeSamples:p})}}),t}function an(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),s=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(b){let f=s[b];if(!f)throw new Error(`Accessor ${b} not found`);let T=c[f.bufferView||0],S=(T.byteOffset||0)+(f.byteOffset||0),_=T.byteLength||0,I=i.slice(S,S+_);return{acc:f,buffer:I}}let h=new Map;if(o.length>0){let b=Ve(t);for(let f=0;f<b.length;f++)h.set(f,b[f])}function l(b,f,T,S){let _=u[b];if(!_)return;let I=new Float32Array(9);re(I,f);for(let y=0;y<(_.primitives||[]).length;y++){let v=_.primitives[y],p=v.attributes?.POSITION;if(p===void 0)continue;let{acc:E,buffer:d}=a(p),x=new Float32Array(d,0,E.count*3),w=new Float32Array(x.length);for(let N=0;N<E.count;N++){let H=x[N*3],Y=x[N*3+1],G=x[N*3+2];w[N*3]=f[0]*H+f[4]*Y+f[8]*G+f[12],w[N*3+1]=f[1]*H+f[5]*Y+f[9]*G+f[13],w[N*3+2]=f[2]*H+f[6]*Y+f[10]*G+f[14]}let R,D=v.attributes?.NORMAL;if(D!==void 0){let{acc:N,buffer:H}=a(D),Y=new Float32Array(H,0,N.count*3);R=new Float32Array(Y.length);for(let G=0;G<N.count;G++){let ae=Y[G*3],Z=Y[G*3+1],Q=Y[G*3+2],de=I[0]*ae+I[3]*Z+I[6]*Q,pe=I[1]*ae+I[4]*Z+I[7]*Q,ce=I[2]*ae+I[5]*Z+I[8]*Q,ne=Math.hypot(de,pe,ce)||1;R[G*3]=de/ne,R[G*3+1]=pe/ne,R[G*3+2]=ce/ne}}let L,M=v.attributes?.TEXCOORD_0;if(M!==void 0){let{acc:N,buffer:H}=a(M);L=new Float32Array(H,0,N.count*2)}let g;if(v.indices!==void 0){let{acc:N,buffer:H}=a(v.indices);N.componentType===5125?g=new Uint32Array(H,0,N.count):g=new Uint16Array(H,0,N.count);let Y=E.count;for(let G of g)if(G>=Y)throw new Error(`SecurityError: Index buffer value (${G}) out of vertex bounds [0, ${Y}).`)}else{let N=E.count;g=N>65535?new Uint32Array(N):new Uint16Array(N);for(let H=0;H<N;H++)g[H]=H}let U="DefaultMaterial",C=[.8,.8,.8],V=.5,O=.1,P=0,F=0,A=1.5,B=1,k=[0,0,0];if(v.material!==void 0&&m[v.material]){let N=m[v.material];U=N.name||`Material_${v.material}`;let H=N.pbrMetallicRoughness||{},Y=1;Array.isArray(H.baseColorFactor)&&(C=[H.baseColorFactor[0],H.baseColorFactor[1],H.baseColorFactor[2]],typeof H.baseColorFactor[3]=="number"&&(Y=H.baseColorFactor[3])),typeof H.roughnessFactor=="number"&&(V=H.roughnessFactor),typeof H.metallicFactor=="number"&&(O=H.metallicFactor),Array.isArray(N.emissiveFactor)&&N.emissiveFactor.length>=3&&(k=[N.emissiveFactor[0],N.emissiveFactor[1],N.emissiveFactor[2]]);let G=N.extensions||{};G.KHR_materials_clearcoat&&(P=G.KHR_materials_clearcoat.clearcoatFactor??0,F=G.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),G.KHR_materials_ior&&typeof G.KHR_materials_ior.ior=="number"&&(A=G.KHR_materials_ior.ior);let ae=G.KHR_materials_transmission?.transmissionFactor??0;B=Y*(1-ae)}let z=(_.primitives||[]).length>1?`${T}_p${y}`:T;e.push({name:z,positions:w,indices:g,normals:R,uvs:L,materialName:U,color:C,roughness:V,metallic:O,clearcoat:P,clearcoatRoughness:F,ior:A,opacity:B,emissiveColor:k,xrTraits:S?.xr||_.extras?.xr})}}if(o.length>0)for(let b=0;b<o.length;b++){let f=o[b];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(b)||q(),S=f.name||u[f.mesh].name||`Node_${b}`;l(f.mesh,T,S,f.extras)}}else{let b=q();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,b,T,u[f].extras)}}return e}function ht(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function sn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function X(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function on(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${X(n[r*3])}, ${X(n[r*3+1])}, ${X(n[r*3+2])})`;return t.join(", ")}function On(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${X(n[r*2])}, ${X(1-n[r*2+1])})`;return t.join(", ")}function zn(n){return Array.from(n).join(", ")}function mt(n){let e=new Map;for(let u of n){let o=ht(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
223
- endTimeCode = ${X(t)}
208
+ void main(){fragColor=uColorId;}`;function Kt(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function ut(n,e,t){let r=Kt(n,35633,e),i=Kt(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let c=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${c}`)}return s}function lt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var Zt=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function nn(){let n=J().xrDepthShader;return{fs:Fn.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Zt,...n.uniformNames]:Zt}}function kn(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 ct(n,e,t,r,i,s,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],o=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,h;if(a===s)h=new Float32Array(t,o,m.count*s);else{h=new Float32Array(m.count*s);let b=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let T=0;T<m.count;T++){let S=f+T*a;for(let _=0;_<s;_++)h[T*s+_]=b[S+_]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var gr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),rn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Jt(n,e,t=rn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:s}=e,c=[],m=Ve(i),u=[];if(Array.isArray(i.nodes))for(let x=0;x<i.nodes.length;x++){let w=i.nodes[x];w.mesh!==void 0&&i.meshes&&i.meshes[w.mesh]&&u.push({node:w,nodeIdx:x,meshIdx:w.mesh})}let o=u.length>0?u:(i.meshes||[]).map((x,w)=>({node:x,nodeIdx:-1,meshIdx:w})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let x=i.extensions.KHR_lights_punctual.lights;for(let w of x){let R=w.type==="directional"?"directional":w.type==="point"?"point":"ambient";a.push({type:R,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${i.textures.length}`);for(let x=0;x<i.textures.length;x++){let w=i.textures[x],R=i.images[w.source];if(R){let D=n.createTexture();if(n.bindTexture(3553,D),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),R.bufferView!==void 0){let L=i.bufferViews[R.bufferView],M=s.slice(L.byteOffset||0,(L.byteOffset||0)+L.byteLength),g=new Blob([M],{type:R.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(g).then(U=>{n.bindTexture(3553,D),n.texImage2D(3553,0,6408,6408,5121,U),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(R.uri){let L=kn(R.uri);if(L){let M=new Image;M.crossOrigin="anonymous",M.referrerPolicy="no-referrer",M.onload=()=>{n.bindTexture(3553,D),n.texImage2D(3553,0,6408,6408,5121,M),n.generateMipmap(3553),r?.()},M.src=L}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",R.uri)}h.push(D)}else h.push(null)}}let l=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],f=0,T=0;for(let x=0;x<o.length;x++){let w=o[x],R=i.meshes[w.meshIdx],D=w.nodeIdx>=0?m[w.nodeIdx]:j(),L=new Float32Array(9);re(L,D);let M={name:w.node.name||R.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:D,normalMatrix:L,primitives:[],extras:w.node.extras||R.extras};for(let g of R.primitives||[]){if(g.extensions?.KHR_draco_mesh_compression){let Y=Ce("draco");Y&&Y.decodePrimitive(i,g,s)}let U=[],I=n.createVertexArray();n.bindVertexArray(I);let V=i.accessors[g.attributes.POSITION],O=Number(V?.count??0);if(!Number.isFinite(O)||O<0||f+O>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=O,V?.min&&V?.max)for(let Y=0;Y<3;Y++){let ie=D[12+Y],we=D[12+Y];for(let ue=0;ue<3;ue++){let Ne=D[ue*4+Y]*V.min[ue],ke=D[ue*4+Y]*V.max[ue];ie+=Ne<ke?Ne:ke,we+=Ne>ke?Ne:ke}ie<l[Y]&&(l[Y]=ie),we>b[Y]&&(b[Y]=we)}let P=ct(n,i,s,g.attributes.POSITION,0,3,U);ct(n,i,s,g.attributes.NORMAL,1,3,U),ct(n,i,s,g.attributes.TEXCOORD_0,2,2,U);let F=0,A=5123,B=null;if(g.indices!==void 0){let Y=i.accessors[g.indices],we=(i.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(F=Number(Y.count??0),!Number.isFinite(F)||F<0||T+F>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=F,A=Y.componentType===5125?5125||5125:5123||5123;let ue=n.createBuffer();U.push(ue),n.bindBuffer(34963,ue),Y.componentType===5125?(B=new Uint32Array(s,we,Y.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,we,Y.count),n.bufferData(34963,B,35044))}else F=V.count;let k={};for(let Y of Z)if(Y.onBuildPrimitiveVAO){let ie=Y.onBuildPrimitiveVAO(n,I,g,i,s);ie&&(k[Y.name]=ie)}n.bindVertexArray(null);let z=i.materials&&g.material!==void 0?i.materials[g.material]:null,N=nn(),H=tn,$=N.fs,X=!1;for(let Y of Z)if(Y.onResolveShader){let ie=Y.onResolveShader(g,z,H,$);ie&&(H=ie.vs,$=ie.fs,X=!0)}let ne=X?ut(n,H,$):null,me=ne?lt(n,ne,N.uniforms):null,q=z?.pbrMetallicRoughness,fe=q?.baseColorFactor||[.8,.8,.8,1],de=q?.metallicFactor??.1,pe=q?.roughnessFactor??.5,ee=z?.extensions?.KHR_materials_clearcoat,be=ee?ee.clearcoatFactor??1:0,ye=Math.max(.04,ee?.clearcoatRoughnessFactor??.04),De=q?.baseColorTexture!==void 0&&h[q.baseColorTexture.index]?h[q.baseColorTexture.index]:null,Sn=q?.metallicRoughnessTexture!==void 0&&h[q.metallicRoughnessTexture.index]?h[q.metallicRoughnessTexture.index]:null,Rn=z?.normalTexture!==void 0&&h[z.normalTexture.index]?h[z.normalTexture.index]:null,An=z?.normalTexture?.scale??1,_n=z?.occlusionTexture!==void 0&&h[z.occlusionTexture.index]?h[z.occlusionTexture.index]:null,Dn=z?.occlusionTexture?.strength??1,Cn=!!(z?.extensions?.KHR_materials_transmission||k.materials?.isTransmissive);M.primitives.push({vao:I,indexCount:F,indexType:A,baseColor:fe,metallic:de,roughness:pe,clearcoat:be,clearcoatRoughness:ye,positions:P,indices:B,texture:De,metallicRoughnessTexture:Sn,normalTexture:Rn,occlusionTexture:_n,normalScale:An,occlusionStrength:Dn,buffers:U,materialIndex:g.material,pluginData:k,customProgram:ne,customUniforms:me,isTransmissive:Cn})}c.push(M)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let S=[(l[0]+b[0])/2,(l[1]+b[1])/2,(l[2]+b[2])/2],_=b[0]-l[0],C=b[1]-l[1],y=b[2]-l[2],v=Math.max(Math.hypot(_,C,y)/2,.5),p=[l[0],l[1],l[2]],E=[b[0],b[1],b[2]],d=e.animations;if(!d){for(let x of Z)if(x.onParseGLB?.(e),e.animations){d=e.animations;break}}return d||(d=[]),{meshes:c,bounds:{center:S,radius:v,min:p,max:E},lights:a,animations:d,worldMatrices:m}}var He=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=j();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=j();this.viewMatrix=j();this.modelMatrix=j();this.mvpMatrix=j();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform: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 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)),i=o}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m;let u=nn();this.renderProg=ut(m,tn,u.fs),this.pickProg=ut(m,Un,Nn),this.uRender=lt(m,this.renderProg,u.uniforms),this.uPick=lt(m,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Ln(e,t)}static getDecoder(e){return Ce(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:s,animations:c,worldMatrices:m}=Jt(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of Z)o.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(en(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(Ie(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ie(e),{meshes:i}=Jt(this.gl,r,rn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],re(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),re(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],c=[],m=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&c.length<6){let h=u.position||[0,0,0];c.push(h[0],h[1],h[2]),m.push(o[0]*a,o[1]*a,o[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(t.uniform3fv(e.uPointLightPos,c),t.uniform3fv(e.uPointLightColor,m)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Z)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Z)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],c=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of Z)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=j();te(r,this.projMatrix,this.viewMatrix);let[i,s,c]=e,m=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(m=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*c+r[12],l=r[1]*i+r[5]*s+r[9]*c+r[13],b=r[2]*i+r[6]*s+r[10]*c+r[14],f=r[3]*i+r[7]*s+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,S=l/f,_=b/f,C=this.canvas.getBoundingClientRect(),y=C.width||this.canvas.clientWidth||this.canvas.width||300,v=C.height||this.canvas.clientHeight||this.canvas.height||150,p=(T*.5+.5)*y,E=(-S*.5+.5)*v,d=T>=-1.1&&T<=1.1&&S>=-1.1&&S<=1.1&&_>=-1&&_<=1;if(d&&t){let x=this.customTarget||this.bounds.center,w=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=x[1]+this.currDistance*Math.sin(this.currPhi),D=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),L=[i-w,s-R,c-D];m*L[0]+u*L[1]+o*L[2]>.05&&(d=!1)}return{x:p,y:E,z:_,visible:d}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],m=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+s*m[0])*o,u[1]+=(-i*c[1]+s*m[1])*o,u[2]+=(-i*c[2]+s*m[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),u=i.height>0?Math.floor((t-i.top)*(c/i.height)):Math.floor(t);return this.performMeshPick(m,u,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let m=j();te(m,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==c)&&this.resizePickingFbo(s,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let d=0;d<this.meshes.length;d++){let x=this.meshes[d];if(x.visible===!1||x.isPluginMesh)continue;let w=d+1,R=(w&255)/255,D=(w>>8&255)/255,L=(w>>16&255)/255;i.uniform4f(this.uPick.uColorId,R,D,L,1),te(this.modelMatrix,this.modelRootMatrix,x.transform),te(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let M of x.primitives)i.bindVertexArray(M.vao),i.drawElements(4,M.indexCount,M.indexType,0)}let p=new Uint8Array(4);i.readPixels(o,a,1,1,6408,5121,p),i.bindFramebuffer(36160,null);let E=p[0]+(p[1]<<8)+(p[2]<<16);E>0&&E<=this.meshes.length&&(u=[this.meshes[E-1]])}u.length===0&&(u=this.meshes.filter(p=>p.visible!==!1));let h=null,l=1/0,b=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,S=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=T[1]+this.currDistance*Math.sin(this.currPhi),C=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let p of u){te(this.modelMatrix,this.modelRootMatrix,p.transform),te(this.mvpMatrix,m,this.modelMatrix);let E=j();if(!qt(E,this.mvpMatrix))continue;let d=(o+.5)/s*2-1,x=(a+.5)/c*2-1,w=[0,0,0],R=[0,0,0];at(w,d,x,-1,E),at(R,d,x,1,E);let D=R[0]-w[0],L=R[1]-w[1],M=R[2]-w[2],g=Math.hypot(D,L,M)||1,U=D/g,I=L/g,V=M/g,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((F=>{for(let A of p.primitives){if(!A.positions)continue;let B=A.positions,k=A.indices,z=Math.floor(k?k.length/3:B.length/9);for(let N=0;N<z;N++){let H=k?k[N*3]:N*3,$=k?k[N*3+1]:N*3+1,X=k?k[N*3+2]:N*3+2;jt(w[0],w[1],w[2],U,I,V,B[H*3],B[H*3+1],B[H*3+2],B[$*3],B[$*3+1],B[$*3+2],B[X*3],B[X*3+1],B[X*3+2],O,F)}}})(1e-4),isFinite(O.distance)){let F=O.point[0],A=O.point[1],B=O.point[2],k=this.modelMatrix,z=k[0]*F+k[4]*A+k[8]*B+k[12],N=k[1]*F+k[5]*A+k[9]*B+k[13],H=k[2]*F+k[6]*A+k[10]*B+k[14],$=z-S,X=N-_,ne=H-C,me=Math.hypot($,X,ne);if(me<l){re(this.normalMatrix,this.modelMatrix);let q=this.normalMatrix,fe=O.normal[0],de=O.normal[1],pe=O.normal[2],ee=q[0]*fe+q[3]*de+q[6]*pe,be=q[1]*fe+q[4]*de+q[7]*pe,ye=q[2]*fe+q[5]*de+q[8]*pe,De=Math.hypot(ee,be,ye)||1;ee/=De,be/=De,ye/=De,ee*$+be*X+ye*ne>0&&(ee=-ee,be=-be,ye=-ye),h=p,l=Math.round(me*1e3)/1e3,b=[Math.round(z*1e3)/1e3,Math.round(N*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(ee*1e3)/1e3,Math.round(be*1e3)/1e3,Math.round(ye*1e3)/1e3]}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:b,normal:f,screenX:e,screenY:t};if(r){for(let p of Z)p.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}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,c=i?Math.max(1,t-r):r,m=(s+.5)/c*2-1;return Math.floor((m*.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);Oe(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Te(this.viewMatrix,[i,s,c],r,[0,1,0]),te(this.mvpMatrix,this.projMatrix,this.viewMatrix),re(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 Z)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 Z)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 c of Z)c.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 c of Z)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),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 c={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,t,r,i,s=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,o=e?.transform?.position,a=o?[o.x,o.y,o.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:m,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),E=Math.max(1,Math.floor(v*.5)),d=Math.max(1,v-E),x=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),w=this.customTarget||this.bounds.center,R=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=w[1]+this.currDistance*Math.sin(this.currPhi),L=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),M=Math.cos(this.currTheta),g=-Math.sin(this.currTheta),U=.032,I=j(),V=j(),O=[R-M*U,D,L-g*U],P=[w[0]-M*U*.25,w[1],w[2]-g*U*.25];Oe(I,this.fov,E/p,.1,x),Te(V,O,P,[0,1,0]);let F=j(),A=j(),B=[R+M*U,D,L+g*U],k=[w[0]+M*U*.25,w[1],w[2]+g*U*.25];Oe(F,this.fov,d/p,.1,x),Te(A,B,k,[0,1,0]),this.render({viewMatrix:V,projMatrix:I,eyePos:O,viewport:[0,0,E,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:A,projMatrix:F,eyePos:B,viewport:[E,0,d,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,r=0,i=0,s=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],c=e.viewport[3],t.viewport(r,i,s,c)):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 m=j(),u=e?.viewMatrix??this.viewMatrix;te(m,e?.projMatrix??this.projMatrix,u);let o=J().xrDepthShader,a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,h=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),b=e?e.eyePos[1]:h[1]+this.currDistance*Math.sin(this.currPhi),f=e?e.eyePos[2]:h[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of Z)v.onBeforeDrawScene?.(this,t,m,[l,b,f],a);let T=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let S=e?.eye||"none",_=!1,C=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=v=>{for(let p=0;p<C.length;p++){let E=C[p];if(E.visible===!1)continue;let d=this.selectedMeshName!==""&&E.name===this.selectedMeshName;p<T||E.worldSpace===!0||E.name==="__xr_reticle__"?this.modelMatrix.set(E.transform):te(this.modelMatrix,this.modelRootMatrix,E.transform),te(this.mvpMatrix,m,this.modelMatrix),re(E.normalMatrix,this.modelMatrix);let x=E.extras?.xr?.stereo||E.userData?.xr?.stereo,w=0,R=0,D=1,L=1;x==="sbs"?(D=.5,w=S==="right"?.5:0):x==="ou"&&(L=.5,R=S==="right"?.5:0);for(let M of E.primitives){let g=!!M.isTransmissive;if(!v&&g){_=!0;continue}if(v&&!g)continue;let U=M.customProgram||this.renderProg,I=M.customUniforms||this.uRender;t.useProgram(U),t.uniform1i(I.uToneMapping,a),t.uniform1f(I.uEnvIntensity,this.envIntensity),t.uniform3f(I.uCameraPos,l,b,f),t.uniform1f(I.uEmissive,d?1:0),t.uniformMatrix4fv(I.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(I.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(I.uNormalMatrix,!1,E.normalMatrix),I.uUvTransform&&t.uniform4f(I.uUvTransform,w,R,D,L),I.uViewportSize&&t.uniform2f(I.uViewportSize,Math.max(1,s),Math.max(1,c)),o?.bind(t,I,this.xrDepthState,u,[r,i,Math.max(1,s),Math.max(1,c)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(I.uEnvironmentMap,4),t.uniform1i(I.uHasEnvironmentMap,1)):t.uniform1i(I.uHasEnvironmentMap,0),this.bindLights(I),I.uSectionEnabled&&t.uniform1i(I.uSectionEnabled,0);for(let V of Z)V.onBeforeDrawPrimitive?.(t,U,M,E,this.worldMatrices||[],this.gltf);t.uniform4fv(I.uBaseColor,M.baseColor),t.uniform1f(I.uMetallic,M.metallic),t.uniform1f(I.uRoughness,M.roughness),I.uClearcoat&&t.uniform2f(I.uClearcoat,M.clearcoat??0,M.clearcoatRoughness??.04),M.texture?(t.activeTexture(33984),t.bindTexture(3553,M.texture),t.uniform1i(I.uBaseColorTexture,0),t.uniform1i(I.uHasTexture,1)):t.uniform1i(I.uHasTexture,0),M.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,M.metallicRoughnessTexture),t.uniform1i(I.uMetallicRoughnessTexture,1),t.uniform1i(I.uHasMetallicRoughnessTexture,1)):t.uniform1i(I.uHasMetallicRoughnessTexture,0),M.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,M.normalTexture),t.uniform1i(I.uNormalTexture,2),t.uniform1i(I.uHasNormalTexture,1),t.uniform1f(I.uNormalScale,M.normalScale)):t.uniform1i(I.uHasNormalTexture,0),M.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,M.occlusionTexture),t.uniform1i(I.uOcclusionTexture,3),t.uniform1i(I.uHasOcclusionTexture,1),t.uniform1f(I.uOcclusionStrength,M.occlusionStrength)):t.uniform1i(I.uHasOcclusionTexture,0),t.bindVertexArray(M.vao),t.drawElements(4,M.indexCount,M.indexType,0)}}};if(y(!1),_){for(let v of Z)v.onBeforeTransmissivePass?.(t,this);y(!0)}for(let v of Z)v.onAfterRender?.(t,this,m)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&t.deleteVertexArray(i.vao),i.buffers)for(let s of i.buffers)t.deleteBuffer(s);i.texture&&t.deleteTexture(i.texture),i.metallicRoughnessTexture&&t.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&t.deleteTexture(i.normalTexture),i.occlusionTexture&&t.deleteTexture(i.occlusionTexture),i.customProgram&&t.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Z)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()}};He.registerPlugin=$t,He.getRegisteredPlugins=Yt;function Bn(n){return n+3&-4}function On(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 Le(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],c=[],m=[],u=new Set,o=[],a=[],h=new Map,l=[];function b(d,x){let w=new Uint8Array(d.buffer,d.byteOffset,d.byteLength),R=Bn(w.byteLength),D=new Uint8Array(R);D.set(w),t.push(D);let L=i.length;return i.push({buffer:0,byteOffset:r,byteLength:w.byteLength,target:x}),r+=R,L}function f(d,x,w,R,D,L,M){let g=b(d,w),U=s.length,I={bufferView:g,byteOffset:0,componentType:R,count:D,type:x};return L&&(I.min=L),M&&(I.max=M),s.push(I),U}n.traverse(d=>{(d.isLight||d.color&&d.intensity!==void 0)&&l.push({type:d.type,color:[d.color.r,d.color.g,d.color.b],intensity:d.intensity,position:[d.position.x,d.position.y,d.position.z]})});let T=[];function S(d){let x={name:d.name||""},w=d.position,R=d.quaternion,D=d.scale;if((w.x||w.y||w.z)&&(x.translation=[w.x,w.y,w.z]),(R.x||R.y||R.z||R.w!==1)&&(x.rotation=[R.x,R.y,R.z,R.w]),(D.x!==1||D.y!==1||D.z!==1)&&(x.scale=[D.x,D.y,D.z]),d.userData&&Object.keys(d.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(d.userData,(M,g)=>{if(!(M==="__proto__"||M==="prototype"||M==="constructor"))return typeof g=="function"?void 0:g})),d.userData.xr)){let M=On(d.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:M,ANDROID_xr_scenecore:M},J().xrTraitSerializer?.gltfNode(x,d.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(d.geometry){let M=d.geometry,g=M.attributes.position;if(g&&g.count>0){let U=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0];for(let F=0;F<g.count;F++){let A=g.getX(F),B=g.getY(F),k=g.getZ(F);A<U[0]&&(U[0]=A),A>I[0]&&(I[0]=A),B<U[1]&&(U[1]=B),B>I[1]&&(I[1]=B),k<U[2]&&(U[2]=k),k>I[2]&&(I[2]=k)}let O={attributes:{POSITION:f(g.array,"VEC3",34962,5126,g.count,U,I)}};if(M.attributes.normal&&(O.attributes.NORMAL=f(M.attributes.normal.array,"VEC3",34962,5126,M.attributes.normal.count)),M.attributes.uv&&(O.attributes.TEXCOORD_0=f(M.attributes.uv.array,"VEC2",34962,5126,M.attributes.uv.count)),M.index){let F=M.index.array instanceof Uint32Array;O.indices=f(M.index.array,"SCALAR",34963,F?5125:5123,M.index.count)}if(d.material){let F=h.get(d.material);if(F===void 0){F=a.length,h.set(d.material,F);let A=d.material,B={name:A.name||"",pbrMetallicRoughness:{baseColorFactor:[A.color.r,A.color.g,A.color.b,A.opacity],metallicFactor:A.metalness,roughnessFactor:A.roughness},doubleSided:A.side===2||A.doubleSided};if(A.emissive&&(A.emissive.r>0||A.emissive.g>0||A.emissive.b>0)){let z=A.emissiveIntensity??1;B.emissiveFactor=[A.emissive.r*z,A.emissive.g*z,A.emissive.b*z]}let k={};A.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:A.clearcoat,clearcoatRoughnessFactor:A.clearcoatRoughness||0}),A.sheen>0&&(k.KHR_materials_sheen={sheenColorFactor:A.sheenColor?[A.sheenColor.r,A.sheenColor.g,A.sheenColor.b]:[1,1,1],sheenRoughnessFactor:A.sheenRoughness||0}),A.transmission>0&&(k.KHR_materials_transmission={transmissionFactor:A.transmission}),A.thickness>0&&(k.KHR_materials_volume={thicknessFactor:A.thickness,attenuationDistance:A.attenuationDistance??1/0,attenuationColor:A.attenuationColor?[A.attenuationColor.r,A.attenuationColor.g,A.attenuationColor.b]:[1,1,1]}),A.ior!==void 0&&A.ior!==1.5&&(k.KHR_materials_ior={ior:A.ior}),A.dispersion>0&&(k.KHR_materials_dispersion={dispersion:A.dispersion}),A.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:A.iridescence,iridescenceIor:A.iridescenceIOR??1.3}),Object.keys(k).length>0&&(B.extensions=k),a.push(B)}O.material=F}let P=c.length;c.push({primitives:[O],name:d.name,...x.extras?{extras:x.extras}:{}}),x.mesh=P}}let L=m.length;if(m.push(x),o.push(d),d.children.length>0){x.children=[];for(let M of d.children)x.children.push(S(M))}return L}for(let d of n.children)T.push(S(d));let _=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),C=[];if(typeof _=="function"&&o.length>0){let d=e?.duration??4,x=e?.fps??15,w=Math.max(2,Math.round(d*x)+1),R=new Float32Array(w),D=o.map(P=>({px:P.position.x,py:P.position.y,pz:P.position.z,qx:P.quaternion.x,qy:P.quaternion.y,qz:P.quaternion.z,qw:P.quaternion.w,sx:P.scale.x,sy:P.scale.y,sz:P.scale.z})),L=o.map(()=>new Float32Array(w*3)),M=o.map(()=>new Float32Array(w*4)),g=o.map(()=>new Float32Array(w*3));for(let P=0;P<w;P++){let F=P/(w-1)*d;R[P]=F;try{_(F)}catch{}for(let A=0;A<o.length;A++){let B=o[A];L[A][P*3]=B.position.x,L[A][P*3+1]=B.position.y,L[A][P*3+2]=B.position.z,M[A][P*4]=B.quaternion.x,M[A][P*4+1]=B.quaternion.y,M[A][P*4+2]=B.quaternion.z,M[A][P*4+3]=B.quaternion.w,g[A][P*3]=B.scale.x,g[A][P*3+1]=B.scale.y,g[A][P*3+2]=B.scale.z}}for(let P=0;P<o.length;P++){let F=o[P],A=D[P];F.position.set(A.px,A.py,A.pz),F.quaternion.set(A.qx,A.qy,A.qz,A.qw),F.scale.set(A.sx,A.sy,A.sz)}n.updateMatrixWorld(!0);let U=null,I=()=>(U===null&&(U=f(R,"SCALAR",0,5126,w,[0],[d])),U),V=[],O=[];for(let P=0;P<o.length;P++){let F=D[P],A=!1,B=!1,k=!1;for(let z=0;z<w;z++)(Math.abs(L[P][z*3]-F.px)>1e-4||Math.abs(L[P][z*3+1]-F.py)>1e-4||Math.abs(L[P][z*3+2]-F.pz)>1e-4)&&(A=!0),(Math.abs(M[P][z*4]-F.qx)>1e-4||Math.abs(M[P][z*4+1]-F.qy)>1e-4||Math.abs(M[P][z*4+2]-F.qz)>1e-4||Math.abs(M[P][z*4+3]-F.qw)>1e-4)&&(B=!0),(Math.abs(g[P][z*3]-F.sx)>1e-4||Math.abs(g[P][z*3+1]-F.sy)>1e-4||Math.abs(g[P][z*3+2]-F.sz)>1e-4)&&(k=!0);if(A){let z=f(L[P],"VEC3",0,5126,w),N=V.length;V.push({input:I(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"translation"}})}if(B){let z=f(M[P],"VEC4",0,5126,w),N=V.length;V.push({input:I(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"rotation"}})}if(k){let z=f(g[P],"VEC3",0,5126,w),N=V.length;V.push({input:I(),interpolation:"LINEAR",output:z}),O.push({sampler:N,target:{node:P,path:"scale"}})}}O.length>0&&C.push({name:"ProceduralLoop",samplers:V,channels:O})}let y=Gt(m,c,n.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:a,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...C.length>0?{animations:C}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},p=new Uint8Array(r),E=0;for(let d of t)p.set(d,E),E+=d.byteLength;return{gltf:v,bin:p.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function Xe(n){return new TextEncoder().encode(n)}function We(n,e){let{gltf:t,bin:r}=Le(n,e),i=JSON.stringify(t),s=Xe(i),c=(4-s.byteLength%4)%4,m=s.byteLength+c,u=20+m+8+r.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let l=0;l<c;l++)o[20+s.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),o.set(new Uint8Array(r),h+8),o}function zn(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let c=s.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let d=0;d<c;d++){let x=s.getX(d),w=s.getY(d),R=s.getZ(d);m[d*3]=u[0]*x+u[4]*w+u[8]*R+u[12],m[d*3+1]=u[1]*x+u[5]*w+u[9]*R+u[13],m[d*3+2]=u[2]*x+u[6]*w+u[10]*R+u[14]}let o;if(i.attributes.normal){let d=i.attributes.normal;o=new Float32Array(c*3);let x=new Float32Array(9);re(x,u);for(let w=0;w<c;w++){let R=d.getX(w),D=d.getY(w),L=d.getZ(w),M=x[0]*R+x[3]*D+x[6]*L,g=x[1]*R+x[4]*D+x[7]*L,U=x[2]*R+x[5]*D+x[8]*L,I=Math.hypot(M,g,U)||1;o[w*3]=M/I,o[w*3+1]=g/I,o[w*3+2]=U/I}}let a;if(i.attributes.uv){let d=i.attributes.uv;a=new Float32Array(c*2);for(let x=0;x<c;x++)a[x*2]=d.getX(x),a[x*2+1]=d.getY(x)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let d=0;d<c;d++)h[d]=d}let l="DefaultMaterial",b=[.8,.8,.8],f=.5,T=.1,S=0,_=0,C=1.5,y=1,v=[0,0,0];if(r.material){let d=r.material;l=d.name||`Material_${t.length}`,d.color&&(b=[d.color.r,d.color.g,d.color.b]),typeof d.roughness=="number"&&(f=d.roughness),typeof d.metalness=="number"&&(T=d.metalness),typeof d.clearcoat=="number"&&(S=d.clearcoat),typeof d.clearcoatRoughness=="number"&&(_=d.clearcoatRoughness),typeof d.ior=="number"&&(C=d.ior);let x=typeof d.opacity=="number"?d.opacity:1,w=typeof d.transmission=="number"?d.transmission:0;if(y=x*(1-w),d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let R=d.emissiveIntensity??1;v=[d.emissive.r*R,d.emissive.g*R,d.emissive.b*R]}}let p,E=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 E=="function"){let d=e?.duration??4,x=e?.fps??4,w=Math.max(2,Math.round(d*x)+1),R=[],D=[],L=[],M=[],g=[r.position.x,r.position.y,r.position.z],U=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],I=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let O=0;O<w;O++){let P=O/(w-1)*d;R.push(P);try{E(P)}catch{}D.push([r.position.x,r.position.y,r.position.z]),L.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),M.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-g[0])>1e-4||Math.abs(r.position.y-g[1])>1e-4||Math.abs(r.position.z-g[2])>1e-4||Math.abs(r.quaternion.x-U[0])>1e-4||Math.abs(r.quaternion.y-U[1])>1e-4||Math.abs(r.quaternion.z-U[2])>1e-4||Math.abs(r.quaternion.w-U[3])>1e-4||Math.abs(r.scale.x-I[0])>1e-4)&&(V=!0)}r.position.set(g[0],g[1],g[2]),r.quaternion.set(U[0],U[1],U[2],U[3]),r.scale.set(I[0],I[1],I[2]),V&&(p={times:R,translations:D,rotations:L,scales:M})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:o,uvs:a,materialName:l,color:b,roughness:f,metallic:T,clearcoat:S,clearcoatRoughness:_,ior:C,opacity:y,emissiveColor:v,xrTraits:r.userData?.xr,timeSamples:p})}}),t}function an(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),s=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(b){let f=s[b];if(!f)throw new Error(`Accessor ${b} not found`);let T=c[f.bufferView||0],S=(T.byteOffset||0)+(f.byteOffset||0),_=T.byteLength||0,C=i.slice(S,S+_);return{acc:f,buffer:C}}let h=new Map;if(o.length>0){let b=Ve(t);for(let f=0;f<b.length;f++)h.set(f,b[f])}function l(b,f,T,S){let _=u[b];if(!_)return;let C=new Float32Array(9);re(C,f);for(let y=0;y<(_.primitives||[]).length;y++){let v=_.primitives[y],p=v.attributes?.POSITION;if(p===void 0)continue;let{acc:E,buffer:d}=a(p),x=new Float32Array(d,0,E.count*3),w=new Float32Array(x.length);for(let N=0;N<E.count;N++){let H=x[N*3],$=x[N*3+1],X=x[N*3+2];w[N*3]=f[0]*H+f[4]*$+f[8]*X+f[12],w[N*3+1]=f[1]*H+f[5]*$+f[9]*X+f[13],w[N*3+2]=f[2]*H+f[6]*$+f[10]*X+f[14]}let R,D=v.attributes?.NORMAL;if(D!==void 0){let{acc:N,buffer:H}=a(D),$=new Float32Array(H,0,N.count*3);R=new Float32Array($.length);for(let X=0;X<N.count;X++){let ne=$[X*3],me=$[X*3+1],q=$[X*3+2],fe=C[0]*ne+C[3]*me+C[6]*q,de=C[1]*ne+C[4]*me+C[7]*q,pe=C[2]*ne+C[5]*me+C[8]*q,ee=Math.hypot(fe,de,pe)||1;R[X*3]=fe/ee,R[X*3+1]=de/ee,R[X*3+2]=pe/ee}}let L,M=v.attributes?.TEXCOORD_0;if(M!==void 0){let{acc:N,buffer:H}=a(M);L=new Float32Array(H,0,N.count*2)}let g;if(v.indices!==void 0){let{acc:N,buffer:H}=a(v.indices);N.componentType===5125?g=new Uint32Array(H,0,N.count):g=new Uint16Array(H,0,N.count);let $=E.count;for(let X of g)if(X>=$)throw new Error(`SecurityError: Index buffer value (${X}) out of vertex bounds [0, ${$}).`)}else{let N=E.count;g=N>65535?new Uint32Array(N):new Uint16Array(N);for(let H=0;H<N;H++)g[H]=H}let U="DefaultMaterial",I=[.8,.8,.8],V=.5,O=.1,P=0,F=0,A=1.5,B=1,k=[0,0,0];if(v.material!==void 0&&m[v.material]){let N=m[v.material];U=N.name||`Material_${v.material}`;let H=N.pbrMetallicRoughness||{},$=1;Array.isArray(H.baseColorFactor)&&(I=[H.baseColorFactor[0],H.baseColorFactor[1],H.baseColorFactor[2]],typeof H.baseColorFactor[3]=="number"&&($=H.baseColorFactor[3])),typeof H.roughnessFactor=="number"&&(V=H.roughnessFactor),typeof H.metallicFactor=="number"&&(O=H.metallicFactor),Array.isArray(N.emissiveFactor)&&N.emissiveFactor.length>=3&&(k=[N.emissiveFactor[0],N.emissiveFactor[1],N.emissiveFactor[2]]);let X=N.extensions||{};X.KHR_materials_clearcoat&&(P=X.KHR_materials_clearcoat.clearcoatFactor??0,F=X.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),X.KHR_materials_ior&&typeof X.KHR_materials_ior.ior=="number"&&(A=X.KHR_materials_ior.ior);let ne=X.KHR_materials_transmission?.transmissionFactor??0;B=$*(1-ne)}let z=(_.primitives||[]).length>1?`${T}_p${y}`:T;e.push({name:z,positions:w,indices:g,normals:R,uvs:L,materialName:U,color:I,roughness:V,metallic:O,clearcoat:P,clearcoatRoughness:F,ior:A,opacity:B,emissiveColor:k,xrTraits:S?.xr||_.extras?.xr})}}if(o.length>0)for(let b=0;b<o.length;b++){let f=o[b];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(b)||j(),S=f.name||u[f.mesh].name||`Node_${b}`;l(f.mesh,T,S,f.extras)}}else{let b=j();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,b,T,u[f].extras)}}return e}function ht(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function sn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function G(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function on(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${G(n[r*3])}, ${G(n[r*3+1])}, ${G(n[r*3+2])})`;return t.join(", ")}function Vn(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${G(n[r*2])}, ${G(1-n[r*2+1])})`;return t.join(", ")}function Hn(n){return Array.from(n).join(", ")}function mt(n){let e=new Map;for(let u of n){let o=ht(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
209
+ endTimeCode = ${G(t)}
224
210
  timeCodesPerSecond = 1.0
225
211
  `);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
226
212
  uniform token preliminary:planeAnchoring:alignment = "${r}"
@@ -237,19 +223,19 @@ kind = "component"
237
223
  {
238
224
  ${s}def Scope "Materials"
239
225
  {
240
- `;for(let[u,o]of e.entries()){let[a,h,l]=o.color,[b,f,T]=o.emissiveColor,S="";o.clearcoat>0&&(S+=`float inputs:clearcoat = ${X(o.clearcoat)}
241
- `,S+=`float inputs:clearcoatRoughness = ${X(o.clearcoatRoughness)}
242
- `),o.ior!==1.5&&(S+=`float inputs:ior = ${X(o.ior)}
243
- `),o.opacity<1&&(S+=`float inputs:opacity = ${X(o.opacity)}
244
- `),(b>0||f>0||T>0)&&(S+=`color3f inputs:emissiveColor = (${X(b)}, ${X(f)}, ${X(T)})
226
+ `;for(let[u,o]of e.entries()){let[a,h,l]=o.color,[b,f,T]=o.emissiveColor,S="";o.clearcoat>0&&(S+=`float inputs:clearcoat = ${G(o.clearcoat)}
227
+ `,S+=`float inputs:clearcoatRoughness = ${G(o.clearcoatRoughness)}
228
+ `),o.ior!==1.5&&(S+=`float inputs:ior = ${G(o.ior)}
229
+ `),o.opacity<1&&(S+=`float inputs:opacity = ${G(o.opacity)}
230
+ `),(b>0||f>0||T>0)&&(S+=`color3f inputs:emissiveColor = (${G(b)}, ${G(f)}, ${G(T)})
245
231
  `),c+=`def Material "${u}"
246
232
  {
247
233
  def Shader "PBRShader"
248
234
  {
249
235
  uniform token info:id = "UsdPreviewSurface"
250
- color3f inputs:diffuseColor = (${X(a)}, ${X(h)}, ${X(l)})
251
- float inputs:metallic = ${X(o.metallic)}
252
- float inputs:roughness = ${X(o.roughness)}
236
+ color3f inputs:diffuseColor = (${G(a)}, ${G(h)}, ${G(l)})
237
+ float inputs:metallic = ${G(o.metallic)}
238
+ float inputs:roughness = ${G(o.roughness)}
253
239
  ${S}token outputs:surface
254
240
  }
255
241
  token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
@@ -257,7 +243,7 @@ token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
257
243
  `}c+=`}
258
244
  def Scope "Meshes"
259
245
  {
260
- `;let m=new Set;for(let u=0;u<n.length;u++){let o=n[u],a=o.positions.length/3,h=1/0,l=1/0,b=1/0,f=-1/0,T=-1/0,S=-1/0;for(let d=0;d<a;d++){let x=o.positions[d*3],w=o.positions[d*3+1],R=o.positions[d*3+2];x<h&&(h=x),x>f&&(f=x),w<l&&(l=w),w>T&&(T=w),R<b&&(b=R),R>S&&(S=R)}isFinite(h)||(h=l=b=-1,f=T=S=1);let _=Math.floor(o.indices.length/3),I=ht(o.materialName,"DefaultMaterial"),y=ht(o.name,`Mesh_${u}`);m.has(y)&&(y=`${y}_${u}`),m.add(y);let v=_>0?_===1?"3":"3, ".repeat(_-1)+"3":"",p=o.xrTraits,E="";if(p){let d=[];p.physics&&p.physics!=="none"&&d.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let x=ee().xrTraitSerializer?.usdLines(p,sn)??[];if(!x.length)for(let w of["grab","billboard","follow","anchor","physics"]){let R=w==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[w];R!==void 0&&x.push(`string ${w} = "${sn(R)}"`)}x.length>0&&d.push(`customData = {
246
+ `;let m=new Set;for(let u=0;u<n.length;u++){let o=n[u],a=o.positions.length/3,h=1/0,l=1/0,b=1/0,f=-1/0,T=-1/0,S=-1/0;for(let d=0;d<a;d++){let x=o.positions[d*3],w=o.positions[d*3+1],R=o.positions[d*3+2];x<h&&(h=x),x>f&&(f=x),w<l&&(l=w),w>T&&(T=w),R<b&&(b=R),R>S&&(S=R)}isFinite(h)||(h=l=b=-1,f=T=S=1);let _=Math.floor(o.indices.length/3),C=ht(o.materialName,"DefaultMaterial"),y=ht(o.name,`Mesh_${u}`);m.has(y)&&(y=`${y}_${u}`),m.add(y);let v=_>0?_===1?"3":"3, ".repeat(_-1)+"3":"",p=o.xrTraits,E="";if(p){let d=[];p.physics&&p.physics!=="none"&&d.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let x=J().xrTraitSerializer?.usdLines(p,sn)??[];if(!x.length)for(let w of["grab","billboard","follow","anchor","physics"]){let R=w==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[w];R!==void 0&&x.push(`string ${w} = "${sn(R)}"`)}x.length>0&&d.push(`customData = {
261
247
  dictionary xr = {
262
248
  ${x.join(`
263
249
  `)}
@@ -270,28 +256,28 @@ ${d.join(`
270
256
  `,p?.physics&&p.physics!=="none"){let d=p.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
271
257
  bool physics:kinematicEnabled = ${d}
272
258
  bool physics:collisionEnabled = true
273
- `}if(o.timeSamples&&o.timeSamples.times.length>0){let d=o.timeSamples,x=d.times.map((D,L)=>{let M=d.translations?.[L]||[0,0,0];return`${X(D)}: (${X(M[0])}, ${X(M[1])}, ${X(M[2])})`}).join(", "),w=d.times.map((D,L)=>{let M=d.rotations?.[L]||[0,0,0,1];return`${X(D)}: (${X(M[3])}, ${X(M[0])}, ${X(M[1])}, ${X(M[2])})`}).join(", "),R=d.times.map((D,L)=>{let M=d.scales?.[L]||[1,1,1];return`${X(D)}: (${X(M[0])}, ${X(M[1])}, ${X(M[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${x} }
259
+ `}if(o.timeSamples&&o.timeSamples.times.length>0){let d=o.timeSamples,x=d.times.map((D,L)=>{let M=d.translations?.[L]||[0,0,0];return`${G(D)}: (${G(M[0])}, ${G(M[1])}, ${G(M[2])})`}).join(", "),w=d.times.map((D,L)=>{let M=d.rotations?.[L]||[0,0,0,1];return`${G(D)}: (${G(M[3])}, ${G(M[0])}, ${G(M[1])}, ${G(M[2])})`}).join(", "),R=d.times.map((D,L)=>{let M=d.scales?.[L]||[1,1,1];return`${G(D)}: (${G(M[0])}, ${G(M[1])}, ${G(M[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${x} }
274
260
  quatf xformOp:orient.timeSamples = { ${w} }
275
261
  double3 xformOp:scale.timeSamples = { ${R} }
276
262
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
277
- `}c+=`float3[] extent = [(${X(h)}, ${X(l)}, ${X(b)}), (${X(f)}, ${X(T)}, ${X(S)})]
263
+ `}c+=`float3[] extent = [(${G(h)}, ${G(l)}, ${G(b)}), (${G(f)}, ${G(T)}, ${G(S)})]
278
264
  int[] faceVertexCounts = [${v}]
279
- int[] faceVertexIndices = [${zn(o.indices)}]
265
+ int[] faceVertexIndices = [${Hn(o.indices)}]
280
266
  point3f[] points = [${on(o.positions)}]
281
267
  `,o.normals&&o.normals.length===o.positions.length&&(c+=`normal3f[] normals = [${on(o.normals)}] (
282
268
  interpolation = "vertex"
283
269
  )
284
- `),o.uvs&&o.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${On(o.uvs,a)}] (
270
+ `),o.uvs&&o.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${Vn(o.uvs,a)}] (
285
271
  interpolation = "vertex"
286
272
  )
287
- `),c+=`rel material:binding = </Root/Materials/${I}>
273
+ `),c+=`rel material:binding = </Root/Materials/${C}>
288
274
  }
289
275
  `}return c+=`}
290
276
  }
291
- `,c}function Vn(n,e){if(n&&typeof n.traverse=="function"){let i=Bn(n,e);return mt(i)}let t=Ie(n),r=an(t);return mt(r)}var Xe=null;function Hn(n){if(!Xe){Xe=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;Xe[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=Xe[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function cn(n){let e=[],t=0,r=[];for(let a of n){let h=Ge(a.filename),l=Hn(a.data),b=a.data.length,f=30+h.length,T=t+f,S=0,_=T%64;_!==0&&(S=64-_);let I=new Uint8Array(f+S),y=new DataView(I.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,l,!0),y.setUint32(18,b,!0),y.setUint32(22,b,!0),y.setUint16(26,h.length,!0),y.setUint16(28,S,!0),I.set(h,30),S>0&&I.fill(0,30+h.length),e.push({offset:t,size:b,crc:l,filenameBytes:h,entry:a}),r.push(I),r.push(a.data),t+=I.length+a.data.length}let i=t;for(let a of e){let h=new Uint8Array(46+a.filenameBytes.length),l=new DataView(h.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),h.set(a.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,c=new Uint8Array(22),m=new DataView(c.buffer);m.setUint32(0,101010256,!0),m.setUint16(4,0,!0),m.setUint16(6,0,!0),m.setUint16(8,e.length,!0),m.setUint16(10,e.length,!0),m.setUint32(12,s,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),o=0;for(let a of r)u.set(a,o),o+=a.length;return u}function Pe(n){let e=Vn(n),t=Ge(e);return cn([{filename:"model.usda",data:t}])}function ft(n){let e=Ie(n),t=an(e),r=mt(t),i=Ge(r);return cn([{filename:"model.usda",data:i}])}function un(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Pe(n):ft(n)}var pt=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}},K=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-s*m,this.y=s*c-r*u,this.z=r*m-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,c=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*c,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*c,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*c,this}},bt=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}},qe=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}},Ke=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(s/2),o=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(s/2);return this._x=o*m*u+c*a*h,this._y=c*a*u-o*m*h,this._z=c*m*h+o*a*u,this._w=c*m*u-o*a*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,c=e.w,m=t.x,u=t.y,o=t.z,a=t.w;return this._x=r*a+c*m+i*o-s*u,this._y=i*a+c*u+s*m-r*o,this._z=s*a+c*o+r*u-i*m,this._w=c*a-r*m-i*u-s*o,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},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 ze(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return te(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Te(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 K(0,0,0),r=new K(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}},yt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return re(this.elements,e.elements),this}},ue=class n{constructor(e,t,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(t!==void 0&&r!==void 0?this.setRGB(e,t,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let t=parseInt(e.slice(1),16);this.setHex(t)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let t=Math.floor(e);return this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,this}setRGB(e,t,r){return this.r=Number(e),this.g=Number(t),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new n(this.r,this.g,this.b)}},Xn={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},W=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/t)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},gt=class extends W{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},xt=class extends W{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},vt=class extends W{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},se=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof W)this.index=e;else if(Array.isArray(e)){let t=0;for(let i=0;i<e.length;i++)e[i]>t&&(t=e[i]);let r=t>65535?new Uint32Array(e):new Uint16Array(e);this.index=new W(r,1)}else e&&e.buffer&&(this.index=new W(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new K,s=new K,c=new K,m=new K,u=new K;if(this.index){let o=this.index.array;for(let a=0;a<o.length;a+=3){let h=o[a],l=o[a+1],b=o[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(b),e.getY(b),e.getZ(b)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let f of[h,l,b])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let o=0;o<t;o+=3){i.set(e.getX(o),e.getY(o),e.getZ(o)),s.set(e.getX(o+1),e.getY(o+1),e.getZ(o+1)),c.set(e.getX(o+2),e.getY(o+2),e.getZ(o+2)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let a=0;a<3;a++)r[(o+a)*3]=m.x,r[(o+a)*3+1]=m.y,r[(o+a)*3+2]=m.z}for(let o=0;o<t;o++){let a=r[o*3],h=r[o*3+1],l=r[o*3+2],b=Math.hypot(a,h,l)||1;r[o*3]=a/b,r[o*3+1]=h/b,r[o*3+2]=l/b}return this.setAttribute("normal",new W(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new W(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new W(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new W(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},je=class extends se{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,c=r/2,m=[-i,-s,c,i,-s,c,i,s,c,-i,s,c,i,-s,-c,-i,-s,-c,-i,s,-c,i,s,-c,-i,s,c,i,s,c,i,s,-c,-i,s,-c,-i,-s,-c,i,-s,-c,i,-s,c,-i,-s,c,i,-s,c,i,-s,-c,i,s,-c,i,s,c,-i,-s,-c,-i,-s,c,-i,s,c,-i,s,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],o=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let h=0;h<6;h++){let l=h*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},wt=class extends se{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Ze=class extends se{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=[],h=o/r;for(let l=0;l<=t;l++){let b=l/t,f=b*Math.PI*2,T=h*Math.PI,S=-e*Math.cos(f)*Math.sin(T),_=e*Math.cos(T),I=e*Math.sin(f)*Math.sin(T);i.push(S,_,I);let y=Math.hypot(S,_,I)||1;s.push(S/y,_/y,I/y),c.push(b,1-h),a.push(i.length/3-1)}u.push(a)}for(let o=0;o<r;o++)for(let a=0;a<t;a++){let h=u[o][a+1],l=u[o][a],b=u[o+1][a],f=u[o+1][a+1];o!==0&&m.push(h,l,f),o!==r-1&&m.push(l,b,f)}this.setAttribute("position",new W(new Float32Array(i),3)),this.setAttribute("normal",new W(new Float32Array(s),3)),this.setAttribute("uv",new W(new Float32Array(c),2)),this.setIndex(m)}},xe=class extends se{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[],o=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,b=a===0?o:-o;for(let f=0;f<=i;f++){let T=f/i,S=T*Math.PI*2,_=Math.sin(S),I=Math.cos(S);s.push(l*_,b,l*I),c.push(_,0,I),m.push(T,1-h)}}for(let a=0;a<i;a++){let h=a,l=a+i+1,b=a+i+2,f=a+1;u.push(h,l,f,l,b,f)}if(e>0){let a=s.length/3;s.push(0,o,0),c.push(0,1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let b=l/i*Math.PI*2,f=Math.sin(b),T=Math.cos(b);s.push(e*f,o,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(a,h+l,h+l+1)}if(t>0){let a=s.length/3;s.push(0,-o,0),c.push(0,-1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let b=l/i*Math.PI*2,f=Math.sin(b),T=Math.cos(b);s.push(t*f,-o,t*T),c.push(0,-1,0),m.push(T*.5+.5,1-(f*.5+.5))}for(let l=0;l<i;l++)u.push(a,h+l+1,h+l)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Tt=class extends xe{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Et=class extends se{constructor(e=1,t=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=o/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,b=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),T=t*Math.sin(a);s.push(b,f,T);let S=e*Math.cos(l),_=e*Math.sin(l),I=b-S,y=f-_,v=T,p=Math.hypot(I,y,v)||1;c.push(I/p,y/p,v/p),m.push(h/i,o/r)}}for(let o=1;o<=r;o++)for(let a=1;a<=i;a++){let h=(i+1)*o+a-1,l=(i+1)*(o-1)+a-1,b=(i+1)*(o-1)+a,f=(i+1)*o+a;u.push(h,l,f,l,b,f)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Mt=class extends se{constructor(e=1,t=.4,r=64,i=8,s=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);let m=[],u=[],o=[],a=[],h=new K,l=new K,b=new K,f=new K,T=new K;function S(y,v){let p=Math.cos(v),E=Math.sin(v),d=c/s*v,x=e*(2+Math.cos(d))*.5;y.set(x*p,x*E,e*Math.sin(d)*.5)}let _=[];for(let y=0;y<=i;++y){let v=y/i*Math.PI*2;_.push(-t*Math.cos(v),t*Math.sin(v),y/i)}for(let y=0;y<=r;++y){let v=y/r,p=v*s*Math.PI*2;S(h,p),S(l,p+.01),b.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(b,f).normalize(),f.crossVectors(T,b).normalize();for(let E=0;E<=i;++E){let d=E*3,x=_[d],w=_[d+1],R=_[d+2],D=x*f.x+w*T.x,L=x*f.y+w*T.y,M=x*f.z+w*T.z;m.push(h.x+D,h.y+L,h.z+M);let g=Math.hypot(D,L,M)||1;u.push(D/g,L/g,M/g),o.push(v,R)}}let I=i+1;for(let y=1;y<=r;y++){let v=I*(y-1),p=v+I;for(let E=1;E<=i;E++){let d=v+(E-1),x=p+(E-1),w=p+E,R=v+E;a.push(d,x,R,x,w,R)}}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},Je=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(){}},St=class{load(e,t){let r=new Je(e);return t?.(r),r}};function J(n,e){return n!==void 0?Number(n):e}function dt(n,e){return n!==void 0?!!n:e}var fe=class{constructor(e={}){this.name=e.name||"",this.color=new ue(e.color!==void 0?e.color:16777215),this.emissive=new ue(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=J(e.emissiveIntensity,1),this.roughness=J(e.roughness,.5),this.metalness=J(e.metalness,.1),this.opacity=J(e.opacity,1),this.transparent=dt(e.transparent,!1),this.wireframe=dt(e.wireframe,!1),this.side=J(e.side,2),this.doubleSided=dt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=J(e.clearcoat,0),this.clearcoatRoughness=J(e.clearcoatRoughness,0),this.sheen=J(e.sheen,0),this.sheenColor=new ue(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=J(e.sheenRoughness,0),this.transmission=J(e.transmission,0),this.thickness=J(e.thickness,0),this.attenuationColor=new ue(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=J(e.attenuationDistance,1/0),this.ior=J(e.ior,1.5),this.dispersion=J(e.dispersion,0),this.iridescence=J(e.iridescence,0),this.iridescenceIOR=J(e.iridescenceIOR,1.3)}dispose(){}},Me=class extends fe{},Rt=class extends fe{},At=class extends fe{},_t=class extends fe{},Dt=class extends fe{},le=class n{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new K,this.rotation=new qe,this.quaternion=new Ke,this.scale=new K(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){(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 K(e,t,r);this.updateMatrixWorld(!0);let s=new Ee;s.lookAt(this.position,i,new K(0,1,0));let c=s.elements,m=c[0],u=c[4],o=c[8],a=c[1],h=c[5],l=c[9],b=c[2],f=c[6],T=c[10],S=m+h+T;if(S>0){let _=.5/Math.sqrt(S+1);this.quaternion.set((f-l)*_,(o-b)*_,(a-u)*_,.25/_)}}},Ct=class extends le{},Ue=class extends le{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof se?t:t?(oe("unsupported geometry","BoxGeometry"),new je(.5,.5,.5)):new se,this.material=i instanceof fe?i:i?(oe("unsupported material","MeshStandardMaterial"),new Me({color:13421772})):new Me}},Se=class extends le{constructor(e=16777215,t=1){super(),this.color=new ue(e),this.intensity=Number(t),this.type="directional"}},Qe=class extends Se{constructor(e,t){super(e,t),this.type="ambient"}},It=class extends Se{constructor(t,r){super(t,r);this.target=new le;this.type="directional"}},et=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}},tt=class extends le{},Lt=class extends tt{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new K(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},nt=class extends le{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return me.validate(this),Le(this)}toGLB(){return me.validate(this),We(this)}toUSDZ(){return me.validate(this),Pe(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ue){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},bn=Le,yn=We,Gn=Pe;var me=class{static validate(e){let t=0,r=0,i=0,s=new Set,c=(u,o,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${o}). Found: ${a}`)},m=(u,o)=>{if(!Number.isFinite(o))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(o)}), which cannot be bounds-checked.`);return o};e.traverse(u=>{if(u instanceof Ue){i++,i>1e3&&c("MESHES",1e3,i);let o=u.geometry;if(o){let a=0;if(o.attributes.position&&(a=m("vertex",o.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),o.index){let h=m("index",o.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=o.index.array;if(l&&a>0){let b=Math.min(h,l.length);for(let f=0;f<b;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=a)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&s.add(a.map),a.normalMap&&s.add(a.normalMap),a.roughnessMap&&s.add(a.roughnessMap)}}}),s.size>16&&c("TEXTURES",16,s.size);for(let u of s){let o=u,a=o.image,h=Number(a?.width??o.width??0)||0,l=Number(a?.height??o.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Pt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new ue(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){me.validate(e);let i=(s,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(s,c):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),c={};for(let[m,u]of s.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let s=bn(e),c=yn(e),m=(s.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:m,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function ln(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Ft=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=ln(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=ln();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Wn(){}var $e=new Proxy(Wn,{get:(n,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:$e},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>$e,construct:()=>$e}),hn=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function _e(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function ve(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,_e());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var mn,Fe;function $n(n){if(!ve(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Fe===void 0||mn!==t){mn=t;try{Fe=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!ve(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Fe=null}}return Fe?Fe.createScriptURL(n):n}function Rr(n){ee().sandboxEngineSrc=n}function gn(){let n=ee().sandboxEngineSrc;if(n)return n;if(hn)return hn;try{if(typeof document>"u")return null;let e=_e(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&ve(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Yn(){let n=gn();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}function Ar(n){ee().sandboxIframeSrc=n}function qn(){let n=ee().sandboxIframeSrc;if(n)return n;let e=gn();if(!e||!ve(e))return null;let t=new URL(e,_e());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Kn(){let n=qn();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}function _r(n){ee().allowClientScripts=n}function jn(){return!!ee().allowClientScripts}function Zn(n){if(!ve(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}var Jn=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function Qn(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,s=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(p){m({type:"ERROR",nonce:t,message:String(p)})}let o=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let p=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let E={createScriptURL:function(x){if(x!==r&&(!i||x!==i))throw new TypeError("Disallowed worker importScripts URL");return x}};s&&(E.createScript=function(x){return String(x)});let d=e.trustedTypes.createPolicy("three-live#worker-boot",E);p=d.createScriptURL(r),i&&(a=d.createScriptURL(i)),s&&typeof d.createScript=="function"&&(h=d.createScript.bind(d))}catch{}o(p)}catch(p){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(p&&p.message||p));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let p=0;p<c.length;p++){let E=c[p],d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d[E]}catch{}try{Object.defineProperty(d,E,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}}let b=Object.freeze({now:function(){return Date.now()}}),f=e;for(;f&&f!==Object.prototype;){if(f!==e)try{delete f.performance}catch{}try{Object.defineProperty(f,"performance",{value:b,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],S=!1;function _(p,E){if(p.type==="3D_MODEL_READY"){if(S)return;S=!0}p.nonce=t,E&&E.length?m(p,E):m(p)}let I=function(p,E){if(!p||T.indexOf(p.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");_(p,E)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:I,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let v=!1;e.onmessage=function(p){let E=p&&p.data;if(!(!E||E.nonce!==t)&&!(E.type!=="EXECUTE"&&E.type!=="EXECUTE_URL")&&!v){v=!0;try{let d=new l.Scene,x=new l.PerspectiveCamera(60,1,.1,1e3),w=new l.WebGLRenderer({isSandboxed:!0});if(E.type==="EXECUTE_URL"){if(!i||E.scriptUrl!==i||typeof o!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let R=a||i,D=o;if(o=null,a=null,e.THREE=l,e.scene=d,e.camera=x,e.renderer=w,D(R),typeof e.__THREE_LIVE_SCENE__=="function"){let L=e.__THREE_LIVE_SCENE__(l,d,x,w);L&&typeof L.toGLB=="function"&&(d=L)}else e.scene&&typeof e.scene.toGLB=="function"&&(d=e.scene)}else{if(!s){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let R=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
277
+ `,c}function Gn(n,e){if(n&&typeof n.traverse=="function"){let i=zn(n,e);return mt(i)}let t=Ie(n),r=an(t);return mt(r)}var Ge=null;function Xn(n){if(!Ge){Ge=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;Ge[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=Ge[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function cn(n){let e=[],t=0,r=[];for(let a of n){let h=Xe(a.filename),l=Xn(a.data),b=a.data.length,f=30+h.length,T=t+f,S=0,_=T%64;_!==0&&(S=64-_);let C=new Uint8Array(f+S),y=new DataView(C.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,l,!0),y.setUint32(18,b,!0),y.setUint32(22,b,!0),y.setUint16(26,h.length,!0),y.setUint16(28,S,!0),C.set(h,30),S>0&&C.fill(0,30+h.length),e.push({offset:t,size:b,crc:l,filenameBytes:h,entry:a}),r.push(C),r.push(a.data),t+=C.length+a.data.length}let i=t;for(let a of e){let h=new Uint8Array(46+a.filenameBytes.length),l=new DataView(h.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),h.set(a.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,c=new Uint8Array(22),m=new DataView(c.buffer);m.setUint32(0,101010256,!0),m.setUint16(4,0,!0),m.setUint16(6,0,!0),m.setUint16(8,e.length,!0),m.setUint16(10,e.length,!0),m.setUint32(12,s,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),o=0;for(let a of r)u.set(a,o),o+=a.length;return u}function Pe(n){let e=Gn(n),t=Xe(e);return cn([{filename:"model.usda",data:t}])}function ft(n){let e=Ie(n),t=an(e),r=mt(t),i=Xe(r);return cn([{filename:"model.usda",data:i}])}function un(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Pe(n):ft(n)}var pt=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}},K=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-s*m,this.y=s*c-r*u,this.z=r*m-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,c=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*c,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*c,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*c,this}},bt=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}},qe=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}},je=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(s/2),o=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(s/2);return this._x=o*m*u+c*a*h,this._y=c*a*u-o*m*h,this._z=c*m*h+o*a*u,this._w=c*m*u-o*a*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,c=e.w,m=t.x,u=t.y,o=t.z,a=t.w;return this._x=r*a+c*m+i*o-s*u,this._y=i*a+c*u+s*m-r*o,this._z=s*a+c*o+r*u-i*m,this._w=c*a-r*m-i*u-s*o,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},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 ze(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return te(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Te(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 K(0,0,0),r=new K(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}},yt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return re(this.elements,e.elements),this}},ae=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)}},Wn={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},W=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/t)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},gt=class extends W{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},xt=class extends W{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},vt=class extends W{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},se=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof W)this.index=e;else if(Array.isArray(e)){let t=0;for(let i=0;i<e.length;i++)e[i]>t&&(t=e[i]);let r=t>65535?new Uint32Array(e):new Uint16Array(e);this.index=new W(r,1)}else e&&e.buffer&&(this.index=new W(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new K,s=new K,c=new K,m=new K,u=new K;if(this.index){let o=this.index.array;for(let a=0;a<o.length;a+=3){let h=o[a],l=o[a+1],b=o[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(b),e.getY(b),e.getZ(b)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let f of[h,l,b])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let o=0;o<t;o+=3){i.set(e.getX(o),e.getY(o),e.getZ(o)),s.set(e.getX(o+1),e.getY(o+1),e.getZ(o+1)),c.set(e.getX(o+2),e.getY(o+2),e.getZ(o+2)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let a=0;a<3;a++)r[(o+a)*3]=m.x,r[(o+a)*3+1]=m.y,r[(o+a)*3+2]=m.z}for(let o=0;o<t;o++){let a=r[o*3],h=r[o*3+1],l=r[o*3+2],b=Math.hypot(a,h,l)||1;r[o*3]=a/b,r[o*3+1]=h/b,r[o*3+2]=l/b}return this.setAttribute("normal",new W(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new W(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new W(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new W(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},Ke=class extends se{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,c=r/2,m=[-i,-s,c,i,-s,c,i,s,c,-i,s,c,i,-s,-c,-i,-s,-c,-i,s,-c,i,s,-c,-i,s,c,i,s,c,i,s,-c,-i,s,-c,-i,-s,-c,i,-s,-c,i,-s,c,-i,-s,c,i,-s,c,i,-s,-c,i,s,-c,i,s,c,-i,-s,-c,-i,-s,c,-i,s,c,-i,s,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],o=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let h=0;h<6;h++){let l=h*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},wt=class extends se{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Ze=class extends se{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=[],h=o/r;for(let l=0;l<=t;l++){let b=l/t,f=b*Math.PI*2,T=h*Math.PI,S=-e*Math.cos(f)*Math.sin(T),_=e*Math.cos(T),C=e*Math.sin(f)*Math.sin(T);i.push(S,_,C);let y=Math.hypot(S,_,C)||1;s.push(S/y,_/y,C/y),c.push(b,1-h),a.push(i.length/3-1)}u.push(a)}for(let o=0;o<r;o++)for(let a=0;a<t;a++){let h=u[o][a+1],l=u[o][a],b=u[o+1][a],f=u[o+1][a+1];o!==0&&m.push(h,l,f),o!==r-1&&m.push(l,b,f)}this.setAttribute("position",new W(new Float32Array(i),3)),this.setAttribute("normal",new W(new Float32Array(s),3)),this.setAttribute("uv",new W(new Float32Array(c),2)),this.setIndex(m)}},xe=class extends se{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[],o=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,b=a===0?o:-o;for(let f=0;f<=i;f++){let T=f/i,S=T*Math.PI*2,_=Math.sin(S),C=Math.cos(S);s.push(l*_,b,l*C),c.push(_,0,C),m.push(T,1-h)}}for(let a=0;a<i;a++){let h=a,l=a+i+1,b=a+i+2,f=a+1;u.push(h,l,f,l,b,f)}if(e>0){let a=s.length/3;s.push(0,o,0),c.push(0,1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let b=l/i*Math.PI*2,f=Math.sin(b),T=Math.cos(b);s.push(e*f,o,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(a,h+l,h+l+1)}if(t>0){let a=s.length/3;s.push(0,-o,0),c.push(0,-1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let b=l/i*Math.PI*2,f=Math.sin(b),T=Math.cos(b);s.push(t*f,-o,t*T),c.push(0,-1,0),m.push(T*.5+.5,1-(f*.5+.5))}for(let l=0;l<i;l++)u.push(a,h+l+1,h+l)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Tt=class extends xe{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Et=class extends se{constructor(e=1,t=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=o/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,b=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),T=t*Math.sin(a);s.push(b,f,T);let S=e*Math.cos(l),_=e*Math.sin(l),C=b-S,y=f-_,v=T,p=Math.hypot(C,y,v)||1;c.push(C/p,y/p,v/p),m.push(h/i,o/r)}}for(let o=1;o<=r;o++)for(let a=1;a<=i;a++){let h=(i+1)*o+a-1,l=(i+1)*(o-1)+a-1,b=(i+1)*(o-1)+a,f=(i+1)*o+a;u.push(h,l,f,l,b,f)}this.setAttribute("position",new W(new Float32Array(s),3)),this.setAttribute("normal",new W(new Float32Array(c),3)),this.setAttribute("uv",new W(new Float32Array(m),2)),this.setIndex(u)}},Mt=class extends se{constructor(e=1,t=.4,r=64,i=8,s=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);let m=[],u=[],o=[],a=[],h=new K,l=new K,b=new K,f=new K,T=new K;function S(y,v){let p=Math.cos(v),E=Math.sin(v),d=c/s*v,x=e*(2+Math.cos(d))*.5;y.set(x*p,x*E,e*Math.sin(d)*.5)}let _=[];for(let y=0;y<=i;++y){let v=y/i*Math.PI*2;_.push(-t*Math.cos(v),t*Math.sin(v),y/i)}for(let y=0;y<=r;++y){let v=y/r,p=v*s*Math.PI*2;S(h,p),S(l,p+.01),b.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(b,f).normalize(),f.crossVectors(T,b).normalize();for(let E=0;E<=i;++E){let d=E*3,x=_[d],w=_[d+1],R=_[d+2],D=x*f.x+w*T.x,L=x*f.y+w*T.y,M=x*f.z+w*T.z;m.push(h.x+D,h.y+L,h.z+M);let g=Math.hypot(D,L,M)||1;u.push(D/g,L/g,M/g),o.push(v,R)}}let C=i+1;for(let y=1;y<=r;y++){let v=C*(y-1),p=v+C;for(let E=1;E<=i;E++){let d=v+(E-1),x=p+(E-1),w=p+E,R=v+E;a.push(d,x,R,x,w,R)}}this.setAttribute("position",new W(new Float32Array(m),3)),this.setAttribute("normal",new W(new Float32Array(u),3)),this.setAttribute("uv",new W(new Float32Array(o),2)),this.setIndex(a)}},Je=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(){}},St=class{load(e,t){let r=new Je(e);return t?.(r),r}};function Q(n,e){return n!==void 0?Number(n):e}function dt(n,e){return n!==void 0?!!n:e}var he=class{constructor(e={}){this.name=e.name||"",this.color=new ae(e.color!==void 0?e.color:16777215),this.emissive=new ae(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Q(e.emissiveIntensity,1),this.roughness=Q(e.roughness,.5),this.metalness=Q(e.metalness,.1),this.opacity=Q(e.opacity,1),this.transparent=dt(e.transparent,!1),this.wireframe=dt(e.wireframe,!1),this.side=Q(e.side,2),this.doubleSided=dt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Q(e.clearcoat,0),this.clearcoatRoughness=Q(e.clearcoatRoughness,0),this.sheen=Q(e.sheen,0),this.sheenColor=new ae(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Q(e.sheenRoughness,0),this.transmission=Q(e.transmission,0),this.thickness=Q(e.thickness,0),this.attenuationColor=new ae(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Q(e.attenuationDistance,1/0),this.ior=Q(e.ior,1.5),this.dispersion=Q(e.dispersion,0),this.iridescence=Q(e.iridescence,0),this.iridescenceIOR=Q(e.iridescenceIOR,1.3)}dispose(){}},Me=class extends he{},Rt=class extends he{},At=class extends he{},_t=class extends he{},Dt=class extends he{},ce=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 K,this.rotation=new qe,this.quaternion=new je,this.scale=new K(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){(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 K(e,t,r);this.updateMatrixWorld(!0);let s=new Ee;s.lookAt(this.position,i,new K(0,1,0));let c=s.elements,m=c[0],u=c[4],o=c[8],a=c[1],h=c[5],l=c[9],b=c[2],f=c[6],T=c[10],S=m+h+T;if(S>0){let _=.5/Math.sqrt(S+1);this.quaternion.set((f-l)*_,(o-b)*_,(a-u)*_,.25/_)}}},Ct=class extends ce{},Ue=class extends ce{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof se?t:t?(oe("unsupported geometry","BoxGeometry"),new Ke(.5,.5,.5)):new se,this.material=i instanceof he?i:i?(oe("unsupported material","MeshStandardMaterial"),new Me({color:13421772})):new Me}},Se=class extends ce{constructor(e=16777215,t=1){super(),this.color=new ae(e),this.intensity=Number(t),this.type="directional"}},Qe=class extends Se{constructor(e,t){super(e,t),this.type="ambient"}},It=class extends Se{constructor(t,r){super(t,r);this.target=new ce;this.type="directional"}},et=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}},tt=class extends ce{},Lt=class extends tt{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new K(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},nt=class extends ce{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return le.validate(this),Le(this)}toGLB(){return le.validate(this),We(this)}toUSDZ(){return le.validate(this),Pe(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ue){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},bn=Le,yn=We,$n=Pe;var le=class{static validate(e){let t=0,r=0,i=0,s=new Set,c=(u,o,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${o}). Found: ${a}`)},m=(u,o)=>{if(!Number.isFinite(o))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(o)}), which cannot be bounds-checked.`);return o};e.traverse(u=>{if(u instanceof Ue){i++,i>1e3&&c("MESHES",1e3,i);let o=u.geometry;if(o){let a=0;if(o.attributes.position&&(a=m("vertex",o.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),o.index){let h=m("index",o.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=o.index.array;if(l&&a>0){let b=Math.min(h,l.length);for(let f=0;f<b;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=a)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&s.add(a.map),a.normalMap&&s.add(a.normalMap),a.roughnessMap&&s.add(a.roughnessMap)}}}),s.size>16&&c("TEXTURES",16,s.size);for(let u of s){let o=u,a=o.image,h=Number(a?.width??o.width??0)||0,l=Number(a?.height??o.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Pt=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 ae(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){le.validate(e);let i=(s,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(s,c):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),c={};for(let[m,u]of s.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let s=bn(e),c=yn(e),m=(s.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:m,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function ln(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Ft=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=ln(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=ln();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Yn(){}var $e=new Proxy(Yn,{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:$e},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>$e,construct:()=>$e}),hn=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function _e(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function ve(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,_e());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var mn,Fe;function qn(n){if(!ve(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Fe===void 0||mn!==t){mn=t;try{Fe=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!ve(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Fe=null}}return Fe?Fe.createScriptURL(n):n}function _r(n){J().sandboxEngineSrc=n}function gn(){let n=J().sandboxEngineSrc;if(n)return n;if(hn)return hn;try{if(typeof document>"u")return null;let e=_e(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&ve(i,{requireSameOrigin:!0}))return i}}catch{}return null}function jn(){let n=gn();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}function Dr(n){J().sandboxIframeSrc=n}function Kn(){let n=J().sandboxIframeSrc;if(n)return n;let e=gn();if(!e||!ve(e))return null;let t=new URL(e,_e());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Zn(){let n=Kn();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!ve(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}function Cr(n){J().allowClientScripts=n}function Jn(){return!!J().allowClientScripts}function Qn(n){if(!ve(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,_e()).href}var er=["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 tr(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,s=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(p){m({type:"ERROR",nonce:t,message:String(p)})}let o=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let p=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let E={createScriptURL:function(x){if(x!==r&&(!i||x!==i))throw new TypeError("Disallowed worker importScripts URL");return x}};s&&(E.createScript=function(x){return String(x)});let d=e.trustedTypes.createPolicy("three-live#worker-boot",E);p=d.createScriptURL(r),i&&(a=d.createScriptURL(i)),s&&typeof d.createScript=="function"&&(h=d.createScript.bind(d))}catch{}o(p)}catch(p){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(p&&p.message||p));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let p=0;p<c.length;p++){let E=c[p],d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d[E]}catch{}try{Object.defineProperty(d,E,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}}let b=Object.freeze({now:function(){return Date.now()}}),f=e;for(;f&&f!==Object.prototype;){if(f!==e)try{delete f.performance}catch{}try{Object.defineProperty(f,"performance",{value:b,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],S=!1;function _(p,E){if(p.type==="3D_MODEL_READY"){if(S)return;S=!0}p.nonce=t,E&&E.length?m(p,E):m(p)}let C=function(p,E){if(!p||T.indexOf(p.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");_(p,E)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:C,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let v=!1;e.onmessage=function(p){let E=p&&p.data;if(!(!E||E.nonce!==t)&&!(E.type!=="EXECUTE"&&E.type!=="EXECUTE_URL")&&!v){v=!0;try{let d=new l.Scene,x=new l.PerspectiveCamera(60,1,.1,1e3),w=new l.WebGLRenderer({isSandboxed:!0});if(E.type==="EXECUTE_URL"){if(!i||E.scriptUrl!==i||typeof o!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let R=a||i,D=o;if(o=null,a=null,e.THREE=l,e.scene=d,e.camera=x,e.renderer=w,D(R),typeof e.__THREE_LIVE_SCENE__=="function"){let L=e.__THREE_LIVE_SCENE__(l,d,x,w);L&&typeof L.toGLB=="function"&&(d=L)}else e.scene&&typeof e.scene.toGLB=="function"&&(d=e.scene)}else{if(!s){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let R=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
292
278
  return (function () {
293
279
  `+E.script+`
294
280
  })();
295
281
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
296
282
  `+E.script+`
297
- })();`);h=null;let D=R(l,d,x,w);D&&typeof D.toGLB=="function"&&(d=D)}if(!S){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(d);let R=d.toGLB(),D=R instanceof ArrayBuffer?R:R.buffer.slice(R.byteOffset,R.byteOffset+R.byteLength);_({type:"3D_MODEL_READY",glbBuffer:D},[D])}m({type:"DONE",nonce:t})}catch(d){u(d&&d.message||d)}}},m({type:"READY",nonce:t})}function xn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:Jn};return`'use strict';(${Qn.toString()})(${JSON.stringify(s)});`}function vn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var ge=0;function wn(){try{let n=new Uint32Array(4);return globalThis.crypto?.getRandomValues(n),Array.from(n,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function er(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var tr=1024,nr=256;function fn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function Tn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,tr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!fn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let c=Object.create(null),m=i;for(let u of s){if(u.length>nr||u==="__proto__"||u==="constructor"||u==="prototype")return null;let o=m[u];if(!fn(o))return null;c[u]=o}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function rr(n){let e=er(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function En(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function ir(n,e,t,r){let i=wn(),s=xn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=t,ge++;let m=!1,u=!1,o={modelDispatched:!1},a,h=()=>{if(m||u)return;let T=c.contentWindow;!T||typeof T.postMessage!="function"||(u=!0,T.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},l=()=>{},b=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let S=T.data;if(S&&typeof S=="object"&&S.type==="IFRAME_READY"){h();return}let _=Tn(S,i);_&&En(_,r,l,o)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",b),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{m||(l(),vn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",b),c.onload=()=>{h()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){l();let T=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(T),T}return f.appendChild(c),{terminate:l}}function dn(n,e,t,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ge>=32)return r(`SecurityError: ${ge} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=Yn()}catch(l){let b=l instanceof Error?l.message:String(l);return r(b,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=Kn()}catch(b){let f=b instanceof Error?b.message:String(b);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(ir(n,i,l,t))}catch(b){return Promise.reject(b)}}let s=wn(),c=xn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),b=URL.createObjectURL(l);try{let f=$n(b);m=new Worker(f)}finally{URL.revokeObjectURL(b)}}catch(l){let b=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${b}`,"Security Error: Failed to start Worker sandbox.")}ge++;let u=!1,o={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),m.terminate())};return a=setTimeout(()=>{u||(h(),vn(t))},3e3),m.onmessage=l=>{let b=Tn(l.data,s);b&&En(b,t,h,o)},m.onerror=l=>{h(),t.onError?.(new Error(`Worker execution error: ${l.message}`))},n.kind==="url"?m.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):m.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function pn(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var sr={execute(n,e,t,r){let i=(m,u)=>{let o=new Error(m);return t.onError?.(o),u&&t.onToast?.(u),Promise.reject(o)},s=pn(e,i);if(s)return s;try{rr(n)}catch(m){let u=m instanceof Error?m.message:String(m);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??jn()?dn({kind:"script",script:n},e,t,i):i(Gt,Wt)},executeUrl(n,e,t){let r=(c,m)=>{let u=new Error(c);return t.onError?.(u),m&&t.onToast?.(m),Promise.reject(u)},i=pn(e,r);if(i)return i;let s;try{s=Zn(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return dn({kind:"url",scriptUrl:s},e,t,r)}},rt=new Set;function oe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;rt.has(t)||(rt.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function or(){return Array.from(rt)}function ar(){rt.clear()}var it=class extends Me{constructor(e={}){oe("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},cr=it,Re=class extends Ze{constructor(e=1,t=0,r="PolyhedronGeometry"){oe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ut=class extends Re{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Nt=class extends Re{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},kt=class extends Re{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Bt=class extends Re{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Ot=class extends xe{constructor(e=1,t=1,r=4,i=8){oe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},zt=class extends xe{constructor(e=.5,t=1,r=16){oe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Vt=class extends xe{constructor(e=1,t=16){oe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Ht=class extends et{constructor(t,r,i=0,s=Math.PI/3,c=0,m=2){oe("SpotLight","PointLight");super(t,r,i,m);this.target=new le;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=c}},st=class extends Qe{constructor(e,t,r){oe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new ue(t??4473924)}},ur=st,Mn={Vector2:pt,Vector3:K,Vector4:bt,Euler:qe,Quaternion:Ke,Matrix4:Ee,Matrix3:yt,Color:ue,MathUtils:Xn,BufferAttribute:W,Float32BufferAttribute:gt,Uint16BufferAttribute:xt,Uint32BufferAttribute:vt,BufferGeometry:se,BoxGeometry:je,PlaneGeometry:wt,SphereGeometry:Ze,CylinderGeometry:xe,ConeGeometry:Tt,TorusGeometry:Et,TorusKnotGeometry:Mt,IcosahedronGeometry:Ut,OctahedronGeometry:Nt,DodecahedronGeometry:kt,TetrahedronGeometry:Bt,CapsuleGeometry:Ot,RingGeometry:zt,CircleGeometry:Vt,Texture:Je,TextureLoader:St,Material:fe,MeshStandardMaterial:Me,MeshBasicMaterial:Rt,MeshLambertMaterial:At,MeshPhongMaterial:_t,MeshPhysicalMaterial:Dt,ShaderMaterial:it,RawShaderMaterial:cr,Object3D:le,Group:Ct,Mesh:Ue,Light:Se,AmbientLight:Qe,DirectionalLight:It,PointLight:et,SpotLight:Ht,HemisphereLight:st,RectAreaLight:ur,Camera:tt,PerspectiveCamera:Lt,Scene:nt,WebGLRenderer:Pt,Clock:Ft,SceneQuotaValidator:me,exportSceneToCanvas3D:bn,exportSceneToGLB:yn,exportSceneToUSDZ:Gn,generateUSDZ:un,glbToUSDZ:ft,sceneToCanvas3D:Le,sceneToGLB:We,sceneToUSDZ:Pe,authorScriptRunner:sr,getAuthorWarnings:or,clearAuthorWarnings:ar};Object.freeze(me);Object.freeze(me.prototype);Object.freeze(nt.prototype);Object.freeze(Mn);var ot=new Proxy(Mn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&oe(`THREE.${e}`,"no-op proxy"),$e),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")}}),Ye={name:"three_author",THREE:ot},Dr=Ye,Ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Ae.THREE>"u"&&(Ae.THREE=ot);typeof Ae.requestAnimationFrame!="function"&&(Ae.requestAnimationFrame=()=>(oe("requestAnimationFrame","single-frame static evaluation"),0));typeof Ae.cancelAnimationFrame!="function"&&(Ae.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=ot,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Ye,n.ThreeLivePlugins.three_author=Ye,n.ThreeLivePlugins["three-author"]=Ye}var Cr=ot;export{Qe as AmbientLight,je as BoxGeometry,W as BufferAttribute,se as BufferGeometry,tt as Camera,Ot as CapsuleGeometry,Vt as CircleGeometry,Ft as Clock,ue as Color,Tt as ConeGeometry,xe as CylinderGeometry,It as DirectionalLight,kt as DodecahedronGeometry,qe as Euler,gt as Float32BufferAttribute,Ct as Group,st as HemisphereLight,Ut as IcosahedronGeometry,Se as Light,fe as Material,Xn as MathUtils,yt as Matrix3,Ee as Matrix4,Ue as Mesh,Rt as MeshBasicMaterial,At as MeshLambertMaterial,_t as MeshPhongMaterial,Dt as MeshPhysicalMaterial,Me as MeshStandardMaterial,le as Object3D,Nt as OctahedronGeometry,Lt as PerspectiveCamera,wt as PlaneGeometry,et as PointLight,Re as PolyhedronFallbackGeometry,Ke as Quaternion,cr as RawShaderMaterial,ur as RectAreaLight,zt as RingGeometry,nt as Scene,me as SceneQuotaValidator,it as ShaderMaterial,Ze as SphereGeometry,Ht as SpotLight,ot as THREE,Bt as TetrahedronGeometry,Je as Texture,St as TextureLoader,Et as TorusGeometry,Mt as TorusKnotGeometry,xt as Uint16BufferAttribute,vt as Uint32BufferAttribute,pt as Vector2,K as Vector3,bt as Vector4,Pt as WebGLRenderer,sr as authorScriptRunner,xn as buildSandboxWorkerSource,ar as clearAuthorWarnings,Cr as default,bn as exportSceneToCanvas3D,yn as exportSceneToGLB,Gn as exportSceneToUSDZ,un as generateUSDZ,jn as getAllowClientScripts,or as getAuthorWarnings,gn as getSandboxEngineSrc,qn as getSandboxIframeSrc,ft as glbToUSDZ,ve as isAllowedSandboxEngineUrl,$e as noopProxy,Le as sceneToCanvas3D,We as sceneToGLB,Pe as sceneToUSDZ,_r as setAllowClientScripts,Rr as setSandboxEngineSrc,Ar as setSandboxIframeSrc,Ye as threeAuthorPlugin,Dr as threeMicroPlugin,$n as toTrustedWorkerScriptURL,Tn as validateSandboxWorkerMessage,oe as warnUnsupported};
283
+ })();`);h=null;let D=R(l,d,x,w);D&&typeof D.toGLB=="function"&&(d=D)}if(!S){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(d);let R=d.toGLB(),D=R instanceof ArrayBuffer?R:R.buffer.slice(R.byteOffset,R.byteOffset+R.byteLength);_({type:"3D_MODEL_READY",glbBuffer:D},[D])}m({type:"DONE",nonce:t})}catch(d){u(d&&d.message||d)}}},m({type:"READY",nonce:t})}function xn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:er};return`'use strict';(${tr.toString()})(${JSON.stringify(s)});`}function vn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var ge=0;function wn(){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 nr(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var rr=1024,ir=256;function fn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function Tn(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,rr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!fn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let c=Object.create(null),m=i;for(let u of s){if(u.length>ir||u==="__proto__"||u==="constructor"||u==="prototype")return null;let o=m[u];if(!fn(o))return null;c[u]=o}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function sr(n){let e=nr(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function En(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function or(n,e,t,r){let i=wn(),s=xn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=t,ge++;let m=!1,u=!1,o={modelDispatched:!1},a,h=()=>{if(m||u)return;let T=c.contentWindow;!T||typeof T.postMessage!="function"||(u=!0,T.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},l=()=>{},b=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let S=T.data;if(S&&typeof S=="object"&&S.type==="IFRAME_READY"){h();return}let _=Tn(S,i);_&&En(_,r,l,o)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",b),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{m||(l(),vn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",b),c.onload=()=>{h()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){l();let T=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(T),T}return f.appendChild(c),{terminate:l}}function dn(n,e,t,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ge>=32)return r(`SecurityError: ${ge} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=jn()}catch(l){let b=l instanceof Error?l.message:String(l);return r(b,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=Zn()}catch(b){let f=b instanceof Error?b.message:String(b);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(or(n,i,l,t))}catch(b){return Promise.reject(b)}}let s=wn(),c=xn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),b=URL.createObjectURL(l);try{let f=qn(b);m=new Worker(f)}finally{URL.revokeObjectURL(b)}}catch(l){let b=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${b}`,"Security Error: Failed to start Worker sandbox.")}ge++;let u=!1,o={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),ge=Math.max(0,ge-1),m.terminate())};return a=setTimeout(()=>{u||(h(),vn(t))},3e3),m.onmessage=l=>{let b=Tn(l.data,s);b&&En(b,t,h,o)},m.onerror=l=>{h(),t.onError?.(new Error(`Worker execution error: ${l.message}`))},n.kind==="url"?m.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):m.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function pn(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var ar={execute(n,e,t,r){let i=(m,u)=>{let o=new Error(m);return t.onError?.(o),u&&t.onToast?.(u),Promise.reject(o)},s=pn(e,i);if(s)return s;try{sr(n)}catch(m){let u=m instanceof Error?m.message:String(m);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Jn()?dn({kind:"script",script:n},e,t,i):i(Xt,Wt)},executeUrl(n,e,t){let r=(c,m)=>{let u=new Error(c);return t.onError?.(u),m&&t.onToast?.(m),Promise.reject(u)},i=pn(e,r);if(i)return i;let s;try{s=Qn(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return dn({kind:"url",scriptUrl:s},e,t,r)}},rt=new Set;function oe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;rt.has(t)||(rt.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function cr(){return Array.from(rt)}function ur(){rt.clear()}var it=class extends Me{constructor(e={}){oe("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},lr=it,Re=class extends Ze{constructor(e=1,t=0,r="PolyhedronGeometry"){oe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ut=class extends Re{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Nt=class extends Re{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},kt=class extends Re{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Bt=class extends Re{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Ot=class extends xe{constructor(e=1,t=1,r=4,i=8){oe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},zt=class extends xe{constructor(e=.5,t=1,r=16){oe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Vt=class extends xe{constructor(e=1,t=16){oe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Ht=class extends et{constructor(t,r,i=0,s=Math.PI/3,c=0,m=2){oe("SpotLight","PointLight");super(t,r,i,m);this.target=new ce;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=c}},st=class extends Qe{constructor(e,t,r){oe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new ae(t??4473924)}},hr=st,Mn={Vector2:pt,Vector3:K,Vector4:bt,Euler:qe,Quaternion:je,Matrix4:Ee,Matrix3:yt,Color:ae,MathUtils:Wn,BufferAttribute:W,Float32BufferAttribute:gt,Uint16BufferAttribute:xt,Uint32BufferAttribute:vt,BufferGeometry:se,BoxGeometry:Ke,PlaneGeometry:wt,SphereGeometry:Ze,CylinderGeometry:xe,ConeGeometry:Tt,TorusGeometry:Et,TorusKnotGeometry:Mt,IcosahedronGeometry:Ut,OctahedronGeometry:Nt,DodecahedronGeometry:kt,TetrahedronGeometry:Bt,CapsuleGeometry:Ot,RingGeometry:zt,CircleGeometry:Vt,Texture:Je,TextureLoader:St,Material:he,MeshStandardMaterial:Me,MeshBasicMaterial:Rt,MeshLambertMaterial:At,MeshPhongMaterial:_t,MeshPhysicalMaterial:Dt,ShaderMaterial:it,RawShaderMaterial:lr,Object3D:ce,Group:Ct,Mesh:Ue,Light:Se,AmbientLight:Qe,DirectionalLight:It,PointLight:et,SpotLight:Ht,HemisphereLight:st,RectAreaLight:hr,Camera:tt,PerspectiveCamera:Lt,Scene:nt,WebGLRenderer:Pt,Clock:Ft,SceneQuotaValidator:le,exportSceneToCanvas3D:bn,exportSceneToGLB:yn,exportSceneToUSDZ:$n,generateUSDZ:un,glbToUSDZ:ft,sceneToCanvas3D:Le,sceneToGLB:We,sceneToUSDZ:Pe,authorScriptRunner:ar,getAuthorWarnings:cr,clearAuthorWarnings:ur};Object.freeze(le);Object.freeze(le.prototype);Object.freeze(nt.prototype);Object.freeze(Mn);var ot=new Proxy(Mn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&oe(`THREE.${e}`,"no-op proxy"),$e),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")}}),Ye={name:"three_author",THREE:ot},Ir=Ye,Ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Ae.THREE>"u"&&(Ae.THREE=ot);typeof Ae.requestAnimationFrame!="function"&&(Ae.requestAnimationFrame=()=>(oe("requestAnimationFrame","single-frame static evaluation"),0));typeof Ae.cancelAnimationFrame!="function"&&(Ae.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=ot,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Ye,n.ThreeLivePlugins.three_author=Ye,n.ThreeLivePlugins["three-author"]=Ye}var Lr=ot;export{Qe as AmbientLight,Ke as BoxGeometry,W as BufferAttribute,se as BufferGeometry,tt as Camera,Ot as CapsuleGeometry,Vt as CircleGeometry,Ft as Clock,ae as Color,Tt as ConeGeometry,xe as CylinderGeometry,It as DirectionalLight,kt as DodecahedronGeometry,qe as Euler,gt as Float32BufferAttribute,Ct as Group,st as HemisphereLight,Ut as IcosahedronGeometry,Se as Light,he as Material,Wn as MathUtils,yt as Matrix3,Ee as Matrix4,Ue as Mesh,Rt as MeshBasicMaterial,At as MeshLambertMaterial,_t as MeshPhongMaterial,Dt as MeshPhysicalMaterial,Me as MeshStandardMaterial,ce as Object3D,Nt as OctahedronGeometry,Lt as PerspectiveCamera,wt as PlaneGeometry,et as PointLight,Re as PolyhedronFallbackGeometry,je as Quaternion,lr as RawShaderMaterial,hr as RectAreaLight,zt as RingGeometry,nt as Scene,le as SceneQuotaValidator,it as ShaderMaterial,Ze as SphereGeometry,Ht as SpotLight,ot as THREE,Bt as TetrahedronGeometry,Je as Texture,St as TextureLoader,Et as TorusGeometry,Mt as TorusKnotGeometry,xt as Uint16BufferAttribute,vt as Uint32BufferAttribute,pt as Vector2,K as Vector3,bt as Vector4,Pt as WebGLRenderer,ar as authorScriptRunner,xn as buildSandboxWorkerSource,ur as clearAuthorWarnings,Lr as default,bn as exportSceneToCanvas3D,yn as exportSceneToGLB,$n as exportSceneToUSDZ,un as generateUSDZ,Jn as getAllowClientScripts,cr as getAuthorWarnings,gn as getSandboxEngineSrc,Kn as getSandboxIframeSrc,ft as glbToUSDZ,ve as isAllowedSandboxEngineUrl,$e as noopProxy,Le as sceneToCanvas3D,We as sceneToGLB,Pe as sceneToUSDZ,Cr as setAllowClientScripts,_r as setSandboxEngineSrc,Dr as setSandboxIframeSrc,Ye as threeAuthorPlugin,Ir as threeMicroPlugin,qn as toTrustedWorkerScriptURL,Tn as validateSandboxWorkerMessage,oe as warnUnsupported};