three-live 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- "use strict";var ThreeEngine=(()=>{var Bt=Object.defineProperty;var jn=Object.getOwnPropertyDescriptor;var Zn=Object.getOwnPropertyNames;var Jn=Object.prototype.hasOwnProperty;var Qn=(n,e)=>{for(var t in e)Bt(n,t,{get:e[t],enumerable:!0})},er=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Zn(e))!Jn.call(n,i)&&i!==t&&Bt(n,i,{get:()=>e[i],enumerable:!(r=jn(e,i))||r.enumerable});return n};var tr=n=>er(Bt({},"__esModule",{value:!0}),n);var $r={};Qn($r,{AmbientLight:()=>Ye,BoxGeometry:()=>Ge,BufferAttribute:()=>X,BufferGeometry:()=>ce,Camera:()=>Ke,CapsuleGeometry:()=>Ft,CircleGeometry:()=>kt,Clock:()=>Dt,Color:()=>he,ConeGeometry:()=>gt,CylinderGeometry:()=>Ee,DirectionalLight:()=>At,DodecahedronGeometry:()=>Pt,Euler:()=>He,Float32BufferAttribute:()=>dt,Group:()=>St,HemisphereLight:()=>Ze,IcosahedronGeometry:()=>It,Light:()=>Me,Material:()=>me,MathUtils:()=>Ln,Matrix3:()=>ft,Matrix4:()=>ye,Mesh:()=>Pe,MeshBasicMaterial:()=>wt,MeshLambertMaterial:()=>Et,MeshPhongMaterial:()=>Mt,MeshPhysicalMaterial:()=>Rt,MeshStandardMaterial:()=>Se,Object3D:()=>ie,OctahedronGeometry:()=>Lt,PerspectiveCamera:()=>Ue,PlaneGeometry:()=>yt,PointLight:()=>qe,PolyhedronFallbackGeometry:()=>_e,Quaternion:()=>Xe,RawShaderMaterial:()=>Hn,RectAreaLight:()=>Xn,RingGeometry:()=>Nt,Scene:()=>Ae,SceneQuotaValidator:()=>pe,ShaderMaterial:()=>je,SphereGeometry:()=>We,SpotLight:()=>Ot,THREE:()=>Je,TetrahedronGeometry:()=>Ut,Texture:()=>$e,TextureLoader:()=>Tt,TorusGeometry:()=>xt,TorusKnotGeometry:()=>vt,Uint16BufferAttribute:()=>pt,Uint32BufferAttribute:()=>bt,Vector2:()=>ht,Vector3:()=>q,Vector4:()=>mt,WebGLRenderer:()=>_t,authorScriptRunner:()=>zn,buildSandboxWorkerSource:()=>nn,clearAuthorWarnings:()=>on,default:()=>Wr,exportSceneToCanvas3D:()=>Qt,exportSceneToGLB:()=>en,exportSceneToUSDZ:()=>Pn,generateUSDZ:()=>$t,getAllowClientScripts:()=>Nn,getAuthorWarnings:()=>Vn,getSandboxEngineSrc:()=>tn,getSandboxIframeSrc:()=>Fn,glbToUSDZ:()=>ut,isAllowedSandboxEngineUrl:()=>Re,noopProxy:()=>Le,sceneToCanvas3D:()=>Ce,sceneToGLB:()=>Be,sceneToUSDZ:()=>Ie,setAllowClientScripts:()=>Fr,setSandboxEngineSrc:()=>Ir,setSandboxIframeSrc:()=>Pr,threeAuthorPlugin:()=>Ve,threeMicroPlugin:()=>Gr,toTrustedWorkerScriptURL:()=>Un,validateSandboxWorkerMessage:()=>rn,warnUnsupported:()=>oe});function tt(n,e,t){let r=[],i=new Map,o=[],c=[],m=[],u=new Map,a=y=>{let E=i.get(y);return E===void 0&&(E=r.length,r.push({op:y}),i.set(y,E)),E},s=y=>{let E=u.get(y);return E===void 0&&(E=m.length,m.push({id:y}),u.set(y,E)),E},h=(y,E={})=>o.push({declaration:a(y),...E})-1,l=(y,E,g)=>c.push({id:y,type:E,value:g})-1,p=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 E=Array.isArray(y.declarations)?y.declarations:[];for(let g of E)g?.op&&a(g.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let g of y.events||[])g?.id&&s(g.id);for(let g of y.nodes){if(!g||typeof g!="object")continue;let A=g.op||(typeof g.declaration=="number"?E[g.declaration]?.op:"");o.push(A?{...g,declaration:a(A)}:{...g})}}}let T=(y,E,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,E)}/${g}`:g==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${g}`,M=new Map;n.forEach((y,E)=>{typeof y?.name=="string"&&!M.has(y.name)&&M.set(y.name,E)});let R=(y,E)=>typeof y.target=="string"&&M.has(y.target)?M.get(y.target):typeof y.targetNode=="number"?y.targetNode:E,I=y=>{let E=n[y];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<n.length;y++){let E=n[y],g=E?.extras?.interactivity;if(!g||typeof g!="object")continue;let A=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,b=v=>{let _=Array.isArray(v)?v:[v],C=[];for(let S=0;S<_.length;S++){let x=_[S];if(!x||typeof x!="object")continue;let P=x.action||"interpolate",B=typeof x.duration=="number"?x.duration:.35;if(P==="toggleTransform"){let V=x.property==="rotation"||x.property==="scale"?x.property:"translation",k=V==="rotation"?E.rotation||[0,0,0,1]:V==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],L=`/nodes/${y}/${V}`,U=l(`__toggle_${y}_${S}`,"bool",!1),D=h("variable/get",{configuration:{variable:U}}),O=h("math/not",{values:{a:p(D)}}),N=h("variable/set",{configuration:{variable:U},values:{value:p(O)}}),z=h("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(x.to)?x.to:k},duration:{value:B}}}),F=h("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(x.from)?x.from:k},duration:{value:B}}});o[N].flows={out:{node:h("flow/branch",{values:{condition:p(D)},flows:{true:{node:z},false:{node:F}}})}},C.push(N)}else if(P==="interpolate"){let V=x.to??x.value;if(V===void 0)continue;let k={value:{value:V},duration:{value:B}};x.from!==void 0&&(k.from={value:x.from}),C.push(h("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(R(x,y),I(R(x,y)),x.property)},values:k}))}else if(P==="setProperty"){if(x.value===void 0)continue;C.push(h("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(R(x,y),I(R(x,y)),x.property)},values:{value:{value:x.value}}}))}else if(P==="toggleVisibility"){let V=R(x,y),k=l(`__vis_${V}_${S}`,"bool",!0),L=h("variable/get",{configuration:{variable:k}}),U=h("math/not",{values:{a:p(L)}}),D=h("variable/set",{configuration:{variable:k},values:{value:p(U)}});o[D].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:p(L)}})}},C.push(D)}else if(P==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let V=typeof x.duration=="number"?x.duration:.25,k=`/materials/${Math.max(0,A)}/pbrMetallicRoughness/baseColorFactor`,L=l(`__color_idx_${y}_${S}`,"int",0),U=h("variable/get",{configuration:{variable:L}}),D=h("math/add",{values:{a:p(U),b:{value:1}}}),O=h("math/rem",{values:{a:p(D),b:{value:x.colors.length}}}),N=h("variable/set",{configuration:{variable:L},values:{value:p(O)}}),z={};for(let F=0;F<x.colors.length;F++){let H=x.colors[F],Y=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(F)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Y},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:k},values:{value:{value:Y}}})}}o[N].flows={out:{node:h("flow/switch",{values:{selection:p(U)},flows:z})}},C.push(N)}else if(P==="playAnimation")C.push(h("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(P==="stopAnimation")C.push(h("animation/stop"));else if(P==="sendEvent"){let V={};for(let[k,L]of Object.entries(x.values||{}))V[k]={value:L};C.push(h("event/send",{configuration:{event:s(String(x.event??x.id??"custom"))},values:V}))}}if(!C.length)return null;if(C.length===1)return C[0];let d={};return C.forEach((S,x)=>{d[String(x)]={node:S}}),h("flow/sequence",{flows:d})},w=(v,_,C)=>{let d=b(_);d!==null&&h(v,{...C?{configuration:C}:{},flows:{out:{node:d}}})};if(g.onSelect&&w("pointer/onSelect",g.onSelect,{nodeIndex:y}),g.onHoverIn&&w("pointer/onHoverIn",g.onHoverIn,{nodeIndex:y}),g.onHoverOut&&w("pointer/onHoverOut",g.onHoverOut,{nodeIndex:y}),g.onStart&&w("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[v,_]of Object.entries(g.onReceive))w("event/receive",_,{event:s(v)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:c,events:m}],graph:0}:null}var sn='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',an="Security Error: client-side scripts require allow-client-scripts opt-in.";var nt="__THREE_LIVE_REGISTRY__";function j(){let n=typeof globalThis<"u"?globalThis:{};if(!n[nt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,nt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[nt]=e}}return n[nt]}var Z=j().plugins;function cn(n){let e=j().plugins;e.some(t=>t.name===n.name)||e.push(n)}function un(){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 ln(n,e,t,r,i){let o=1/Math.tan(e/2);n.fill(0),n[0]=o/t,n[5]=o,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function rt(n,e,t,r){let[i,o,c]=e,[m,u,a]=r,[s,h,l]=t,p=i-s,f=o-h,T=c-l,M=Math.hypot(p,f,T);M<=1e-5?(p=0,f=0,T=1):(p/=M,f/=M,T/=M);let R=u*T-a*f,I=a*p-m*T,y=m*f-u*p;M=Math.hypot(R,I,y),M<=1e-5?(R=0,I=0,y=0):(R/=M,I/=M,y/=M);let E=f*y-T*I,g=T*R-p*y,A=p*I-f*R;return M=Math.hypot(E,g,A),M<=1e-5?(E=0,g=0,A=0):(E/=M,g/=M,A/=M),n[0]=R,n[1]=E,n[2]=p,n[3]=0,n[4]=I,n[5]=g,n[6]=f,n[7]=0,n[8]=y,n[9]=A,n[10]=T,n[11]=0,n[12]=-(R*i+I*o+y*c),n[13]=-(E*i+g*o+A*c),n[14]=-(p*i+f*o+T*c),n[15]=1,n}function re(n,e,t){let r=e[0],i=e[1],o=e[2],c=e[3],m=e[4],u=e[5],a=e[6],s=e[7],h=e[8],l=e[9],p=e[10],f=e[11],T=e[12],M=e[13],R=e[14],I=e[15],y=t[0],E=t[1],g=t[2],A=t[3];return n[0]=y*r+E*m+g*h+A*T,n[1]=y*i+E*u+g*l+A*M,n[2]=y*o+E*a+g*p+A*R,n[3]=y*c+E*s+g*f+A*I,y=t[4],E=t[5],g=t[6],A=t[7],n[4]=y*r+E*m+g*h+A*T,n[5]=y*i+E*u+g*l+A*M,n[6]=y*o+E*a+g*p+A*R,n[7]=y*c+E*s+g*f+A*I,y=t[8],E=t[9],g=t[10],A=t[11],n[8]=y*r+E*m+g*h+A*T,n[9]=y*i+E*u+g*l+A*M,n[10]=y*o+E*a+g*p+A*R,n[11]=y*c+E*s+g*f+A*I,y=t[12],E=t[13],g=t[14],A=t[15],n[12]=y*r+E*m+g*h+A*T,n[13]=y*i+E*u+g*l+A*M,n[14]=y*o+E*a+g*p+A*R,n[15]=y*c+E*s+g*f+A*I,n}function it(n,e,t,r){let i=e[0],o=e[1],c=e[2],m=e[3],u=i+i,a=o+o,s=c+c,h=i*u,l=i*a,p=i*s,f=o*a,T=o*s,M=c*s,R=m*u,I=m*a,y=m*s,E=r[0],g=r[1],A=r[2];return n[0]=(1-(f+M))*E,n[1]=(l+y)*E,n[2]=(p-I)*E,n[3]=0,n[4]=(l-y)*g,n[5]=(1-(h+M))*g,n[6]=(T+R)*g,n[7]=0,n[8]=(p+I)*A,n[9]=(T-R)*A,n[10]=(1-(h+f))*A,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ae(n,e){let t=e[0],r=e[1],i=e[2],o=e[4],c=e[5],m=e[6],u=e[8],a=e[9],s=e[10],h=s*c-m*a,l=-s*o+m*u,p=a*o-c*u,f=t*h+r*l+i*p;return f&&(f=1/f,n[0]=h*f,n[1]=(-s*r+i*a)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(s*t-i*u)*f,n[5]=(-m*t+i*o)*f,n[6]=p*f,n[7]=(-a*t+r*u)*f,n[8]=(c*t-r*o)*f),n}function hn(n,e){let t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],m=e[5],u=e[6],a=e[7],s=e[8],h=e[9],l=e[10],p=e[11],f=e[12],T=e[13],M=e[14],R=e[15],I=t*m-r*c,y=t*u-i*c,E=t*a-o*c,g=r*u-i*m,A=r*a-o*m,b=i*a-o*u,w=s*T-h*f,v=s*M-l*f,_=s*R-p*f,C=h*M-l*T,d=h*R-p*T,S=l*R-p*M,x=I*S-y*d+E*C+g*_-A*v+b*w;return x?(x=1/x,n[0]=(m*S-u*d+a*C)*x,n[1]=(i*d-r*S-o*C)*x,n[2]=(T*b-M*A+R*g)*x,n[3]=(l*A-h*b-p*g)*x,n[4]=(u*_-c*S-a*v)*x,n[5]=(t*S-i*_+o*v)*x,n[6]=(M*E-f*b-R*y)*x,n[7]=(s*b-l*E+p*y)*x,n[8]=(c*d-m*_+a*w)*x,n[9]=(r*_-t*d-o*w)*x,n[10]=(f*A-T*E+R*I)*x,n[11]=(h*E-s*A-p*I)*x,n[12]=(m*v-c*C-u*w)*x,n[13]=(t*C-r*v+i*w)*x,n[14]=(T*y-f*g-M*I)*x,n[15]=(s*g-h*y+l*I)*x,n):null}function zt(n,e,t,r,i){let o=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],a=u!==0?1/u:1;n[0]=o*a,n[1]=c*a,n[2]=m*a}function mn(n,e,t,r,i,o,c,m,u,a,s,h,l,p,f,T,M=0){let R=a-c,I=s-m,y=h-u,E=l-c,g=p-m,A=f-u,b=i*A-o*g,w=o*E-r*A,v=r*g-i*E,_=R*b+I*w+y*v;if(_>-1e-7&&_<1e-7)return!1;let C=1/_,d=n-c,S=e-m,x=t-u,P=C*(d*b+S*w+x*v);if(P<-M||P>1+M)return!1;let B=S*y-x*I,V=x*R-d*y,k=d*I-S*R,L=C*(r*B+i*V+o*k);if(L<-M||P+L>1+M)return!1;let U=C*(E*B+g*V+A*k);if(U>1e-4&&U<T.distance){T.distance=U,T.point=[n+r*U,e+i*U,t+o*U];let D=I*A-y*g,O=y*E-R*A,N=R*g-I*E,z=Math.hypot(D,O,N)||1;return T.normal=[D/z,O/z,N/z],!0}return!1}function ot(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let s=0;s<t;s++)r.push(J());if(t===0)return r;let i=new Set;for(let s of n.nodes)if(Array.isArray(s.children))for(let h of s.children)i.add(h);let o=new Set,c=128,m=(s,h,l=0)=>{if(l>c||s<0||s>=t||o.has(s))return;o.add(s);let p=n.nodes[s];if(!p)return;let f=J();if(e&&e[s])f.set(e[s]);else if(p.matrix&&p.matrix.length===16)f.set(p.matrix);else{let M=p.translation||[0,0,0],R=p.rotation||[0,0,0,1],I=p.scale||[1,1,1];it(f,R,M,I)}let T=r[s];if(h?re(T,h,f):T.set(f),Array.isArray(p.children))for(let M of p.children)typeof M=="number"&&m(M,T,l+1)},u=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(a&&Array.isArray(a.nodes))u.push(...a.nodes);else for(let s=0;s<t;s++)i.has(s)||u.push(s);for(let s of u)m(s,null);for(let s=0;s<t;s++)!i.has(s)&&!u.includes(s)&&m(s,null);return r}function nr(n){return new TextDecoder().decode(n)}var pn=j().decoders;function rr(n,e){pn.set(n.toLowerCase(),e)}function ke(n){return pn.get(n.toLowerCase())}function bn(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 o=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=o&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),p=t.getUint32(c+4,!0),f=c+8;if(f+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${f+l} bytes, buffer has ${e.byteLength}`);if(p===1313821514){let T=new Uint8Array(e,f,l),M=nr(T);m=JSON.parse(M,(R,I)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:I)}else p===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let a=m.extensionsRequired||[];if(a.includes("KHR_draco_mesh_compression")&&!ke("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(a.includes("EXT_meshopt_compression")&&!ke("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(a.includes("KHR_texture_basisu")&&!ke("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let s=u||new ArrayBuffer(0),h={gltf:m,bin:s,animations:[]};for(let l of Z)l.onParseGLB?.(h);return h}function ir(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 Oe(n){if(ir(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return bn(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var yn=`#version 300 es
17
+ "use strict";var ThreeEngine=(()=>{var Ht=Object.defineProperty;var tr=Object.getOwnPropertyDescriptor;var nr=Object.getOwnPropertyNames;var rr=Object.prototype.hasOwnProperty;var ir=(n,e)=>{for(var t in e)Ht(n,t,{get:e[t],enumerable:!0})},or=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nr(e))!rr.call(n,i)&&i!==t&&Ht(n,i,{get:()=>e[i],enumerable:!(r=tr(e,i))||r.enumerable});return n};var sr=n=>or(Ht({},"__esModule",{value:!0}),n);var ai={};ir(ai,{AmbientLight:()=>Ke,BoxGeometry:()=>Ye,BufferAttribute:()=>G,BufferGeometry:()=>ue,Camera:()=>Je,CapsuleGeometry:()=>Ot,CircleGeometry:()=>zt,Clock:()=>Pt,Color:()=>he,ConeGeometry:()=>Tt,CylinderGeometry:()=>Ee,DirectionalLight:()=>Ct,DodecahedronGeometry:()=>Nt,Euler:()=>We,Float32BufferAttribute:()=>yt,Group:()=>Dt,HemisphereLight:()=>et,IcosahedronGeometry:()=>Ut,Light:()=>Se,Material:()=>me,MathUtils:()=>Nn,Matrix3:()=>bt,Matrix4:()=>pe,Mesh:()=>Fe,MeshBasicMaterial:()=>Mt,MeshLambertMaterial:()=>Rt,MeshPhongMaterial:()=>At,MeshPhysicalMaterial:()=>_t,MeshStandardMaterial:()=>Ae,Object3D:()=>oe,OctahedronGeometry:()=>Ft,PerspectiveCamera:()=>Ne,PlaneGeometry:()=>vt,PointLight:()=>Ze,PolyhedronFallbackGeometry:()=>De,Quaternion:()=>$e,RawShaderMaterial:()=>$n,RectAreaLight:()=>Yn,RingGeometry:()=>Bt,Scene:()=>_e,SceneQuotaValidator:()=>fe,ShaderMaterial:()=>Qe,SphereGeometry:()=>qe,SpotLight:()=>Vt,THREE:()=>tt,TetrahedronGeometry:()=>kt,Texture:()=>je,TextureLoader:()=>St,TorusGeometry:()=>wt,TorusKnotGeometry:()=>Et,Uint16BufferAttribute:()=>gt,Uint32BufferAttribute:()=>xt,Vector2:()=>dt,Vector3:()=>Z,Vector4:()=>pt,WebGLRenderer:()=>Lt,authorScriptRunner:()=>Xn,buildSandboxWorkerSource:()=>on,clearAuthorWarnings:()=>an,default:()=>si,exportSceneToCanvas3D:()=>tn,exportSceneToGLB:()=>nn,exportSceneToUSDZ:()=>kn,generateUSDZ:()=>jt,getAllowClientScripts:()=>zn,getAuthorWarnings:()=>Wn,getSandboxEngineSrc:()=>rn,getSandboxIframeSrc:()=>Bn,glbToUSDZ:()=>mt,isAllowedSandboxEngineUrl:()=>Me,noopProxy:()=>Ue,sceneToCanvas3D:()=>Pe,sceneToGLB:()=>Ve,sceneToUSDZ:()=>Ie,setAllowClientScripts:()=>Kr,setSandboxEngineSrc:()=>$r,setSandboxIframeSrc:()=>qr,threeAuthorPlugin:()=>Xe,threeMicroPlugin:()=>oi,toTrustedWorkerScriptURL:()=>On,validateSandboxWorkerMessage:()=>sn,warnUnsupported:()=>se});function it(n,e,t){let r=[],i=new Map,o=[],c=[],m=[],u=new Map,s=y=>{let w=i.get(y);return w===void 0&&(w=r.length,r.push({op:y}),i.set(y,w)),w},a=y=>{let w=u.get(y);return w===void 0&&(w=m.length,m.push({id:y}),u.set(y,w)),w},h=(y,w={})=>o.push({declaration:s(y),...w})-1,l=(y,w,b)=>c.push({id:y,type:w,value:b})-1,d=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 w=Array.isArray(y.declarations)?y.declarations:[];for(let b of w)b?.op&&s(b.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let b of y.events||[])b?.id&&a(b.id);for(let b of y.nodes){if(!b||typeof b!="object")continue;let M=b.op||(typeof b.declaration=="number"?w[b.declaration]?.op:"");o.push(M?{...b,declaration:s(M)}:{...b})}}}let S=(y,w,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,w)}/${b}`:b==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${b}`,A=new Map;n.forEach((y,w)=>{typeof y?.name=="string"&&!A.has(y.name)&&A.set(y.name,w)});let R=(y,w)=>typeof y.target=="string"&&A.has(y.target)?A.get(y.target):typeof y.targetNode=="number"?y.targetNode:w,P=y=>{let w=n[y];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<n.length;y++){let w=n[y],b=w?.extras?.interactivity;if(!b||typeof b!="object")continue;let M=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,p=v=>{let _=Array.isArray(v)?v:[v],C=[];for(let T=0;T<_.length;T++){let x=_[T];if(!x||typeof x!="object")continue;let I=x.action||"interpolate",L=typeof x.duration=="number"?x.duration:.35;if(I==="toggleTransform"){let V=x.property==="rotation"||x.property==="scale"?x.property:"translation",N=V==="rotation"?w.rotation||[0,0,0,1]:V==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],U=`/nodes/${y}/${V}`,F=l(`__toggle_${y}_${T}`,"bool",!1),D=h("variable/get",{configuration:{variable:F}}),O=h("math/not",{values:{a:d(D)}}),k=h("variable/set",{configuration:{variable:F},values:{value:d(O)}}),z=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.to)?x.to:N},duration:{value:L}}}),B=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.from)?x.from:N},duration:{value:L}}});o[k].flows={out:{node:h("flow/branch",{values:{condition:d(D)},flows:{true:{node:z},false:{node:B}}})}},C.push(k)}else if(I==="interpolate"){let V=x.to??x.value;if(V===void 0)continue;let N={value:{value:V},duration:{value:L}};x.from!==void 0&&(N.from={value:x.from}),C.push(h("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(R(x,y),P(R(x,y)),x.property)},values:N}))}else if(I==="setProperty"){if(x.value===void 0)continue;C.push(h("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(R(x,y),P(R(x,y)),x.property)},values:{value:{value:x.value}}}))}else if(I==="toggleVisibility"){let V=R(x,y),N=l(`__vis_${V}_${T}`,"bool",!0),U=h("variable/get",{configuration:{variable:N}}),F=h("math/not",{values:{a:d(U)}}),D=h("variable/set",{configuration:{variable:N},values:{value:d(F)}});o[D].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(U)}})}},C.push(D)}else if(I==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let V=typeof x.duration=="number"?x.duration:.25,N=`/materials/${Math.max(0,M)}/pbrMetallicRoughness/baseColorFactor`,U=l(`__color_idx_${y}_${T}`,"int",0),F=h("variable/get",{configuration:{variable:U}}),D=h("math/add",{values:{a:d(F),b:{value:1}}}),O=h("math/rem",{values:{a:d(D),b:{value:x.colors.length}}}),k=h("variable/set",{configuration:{variable:U},values:{value:d(O)}}),z={};for(let B=0;B<x.colors.length;B++){let H=x.colors[B],$=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(B)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:$},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:N},values:{value:{value:$}}})}}o[k].flows={out:{node:h("flow/switch",{values:{selection:d(F)},flows:z})}},C.push(k)}else if(I==="playAnimation")C.push(h("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(I==="stopAnimation")C.push(h("animation/stop"));else if(I==="sendEvent"){let V={};for(let[N,U]of Object.entries(x.values||{}))V[N]={value:U};C.push(h("event/send",{configuration:{event:a(String(x.event??x.id??"custom"))},values:V}))}}if(!C.length)return null;if(C.length===1)return C[0];let g={};return C.forEach((T,x)=>{g[String(x)]={node:T}}),h("flow/sequence",{flows:g})},E=(v,_,C)=>{let g=p(_);g!==null&&h(v,{...C?{configuration:C}:{},flows:{out:{node:g}}})};if(b.onSelect&&E("pointer/onSelect",b.onSelect,{nodeIndex:y}),b.onHoverIn&&E("pointer/onHoverIn",b.onHoverIn,{nodeIndex:y}),b.onHoverOut&&E("pointer/onHoverOut",b.onHoverOut,{nodeIndex:y}),b.onStart&&E("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[v,_]of Object.entries(b.onReceive))E("event/receive",_,{event:a(v)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:c,events:m}],graph:0}:null}var cn='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).',un="Security Error: client-side scripts require allow-client-scripts opt-in.";var ot="__THREE_LIVE_REGISTRY__";function J(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ot]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ot,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ot]=e}}return n[ot]}var Q=J().plugins;function ln(n){let e=J().plugins;e.some(t=>t.name===n.name)||e.push(n)}function hn(){return J().plugins}function K(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function st(n,e,t,r,i){let o=1/Math.tan(e/2);n.fill(0),n[0]=o/t,n[5]=o,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Le(n,e,t,r){let[i,o,c]=e,[m,u,s]=r,[a,h,l]=t,d=i-a,f=o-h,S=c-l,A=Math.hypot(d,f,S);A<=1e-5?(d=0,f=0,S=1):(d/=A,f/=A,S/=A);let R=u*S-s*f,P=s*d-m*S,y=m*f-u*d;A=Math.hypot(R,P,y),A<=1e-5?(R=0,P=0,y=0):(R/=A,P/=A,y/=A);let w=f*y-S*P,b=S*R-d*y,M=d*P-f*R;return A=Math.hypot(w,b,M),A<=1e-5?(w=0,b=0,M=0):(w/=A,b/=A,M/=A),n[0]=R,n[1]=w,n[2]=d,n[3]=0,n[4]=P,n[5]=b,n[6]=f,n[7]=0,n[8]=y,n[9]=M,n[10]=S,n[11]=0,n[12]=-(R*i+P*o+y*c),n[13]=-(w*i+b*o+M*c),n[14]=-(d*i+f*o+S*c),n[15]=1,n}function ie(n,e,t){let r=e[0],i=e[1],o=e[2],c=e[3],m=e[4],u=e[5],s=e[6],a=e[7],h=e[8],l=e[9],d=e[10],f=e[11],S=e[12],A=e[13],R=e[14],P=e[15],y=t[0],w=t[1],b=t[2],M=t[3];return n[0]=y*r+w*m+b*h+M*S,n[1]=y*i+w*u+b*l+M*A,n[2]=y*o+w*s+b*d+M*R,n[3]=y*c+w*a+b*f+M*P,y=t[4],w=t[5],b=t[6],M=t[7],n[4]=y*r+w*m+b*h+M*S,n[5]=y*i+w*u+b*l+M*A,n[6]=y*o+w*s+b*d+M*R,n[7]=y*c+w*a+b*f+M*P,y=t[8],w=t[9],b=t[10],M=t[11],n[8]=y*r+w*m+b*h+M*S,n[9]=y*i+w*u+b*l+M*A,n[10]=y*o+w*s+b*d+M*R,n[11]=y*c+w*a+b*f+M*P,y=t[12],w=t[13],b=t[14],M=t[15],n[12]=y*r+w*m+b*h+M*S,n[13]=y*i+w*u+b*l+M*A,n[14]=y*o+w*s+b*d+M*R,n[15]=y*c+w*a+b*f+M*P,n}function at(n,e,t,r){let i=e[0],o=e[1],c=e[2],m=e[3],u=i+i,s=o+o,a=c+c,h=i*u,l=i*s,d=i*a,f=o*s,S=o*a,A=c*a,R=m*u,P=m*s,y=m*a,w=r[0],b=r[1],M=r[2];return n[0]=(1-(f+A))*w,n[1]=(l+y)*w,n[2]=(d-P)*w,n[3]=0,n[4]=(l-y)*b,n[5]=(1-(h+A))*b,n[6]=(S+R)*b,n[7]=0,n[8]=(d+P)*M,n[9]=(S-R)*M,n[10]=(1-(h+f))*M,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ce(n,e){let t=e[0],r=e[1],i=e[2],o=e[4],c=e[5],m=e[6],u=e[8],s=e[9],a=e[10],h=a*c-m*s,l=-a*o+m*u,d=s*o-c*u,f=t*h+r*l+i*d;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*s)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*o)*f,n[6]=d*f,n[7]=(-s*t+r*u)*f,n[8]=(c*t-r*o)*f),n}function mn(n,e){let t=e[0],r=e[1],i=e[2],o=e[3],c=e[4],m=e[5],u=e[6],s=e[7],a=e[8],h=e[9],l=e[10],d=e[11],f=e[12],S=e[13],A=e[14],R=e[15],P=t*m-r*c,y=t*u-i*c,w=t*s-o*c,b=r*u-i*m,M=r*s-o*m,p=i*s-o*u,E=a*S-h*f,v=a*A-l*f,_=a*R-d*f,C=h*A-l*S,g=h*R-d*S,T=l*R-d*A,x=P*T-y*g+w*C+b*_-M*v+p*E;return x?(x=1/x,n[0]=(m*T-u*g+s*C)*x,n[1]=(i*g-r*T-o*C)*x,n[2]=(S*p-A*M+R*b)*x,n[3]=(l*M-h*p-d*b)*x,n[4]=(u*_-c*T-s*v)*x,n[5]=(t*T-i*_+o*v)*x,n[6]=(A*w-f*p-R*y)*x,n[7]=(a*p-l*w+d*y)*x,n[8]=(c*g-m*_+s*E)*x,n[9]=(r*_-t*g-o*E)*x,n[10]=(f*M-S*w+R*P)*x,n[11]=(h*w-a*M-d*P)*x,n[12]=(m*v-c*C-u*E)*x,n[13]=(t*C-r*v+i*E)*x,n[14]=(S*y-f*b-A*P)*x,n[15]=(a*b-h*y+l*P)*x,n):null}function Gt(n,e,t,r,i){let o=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],s=u!==0?1/u:1;n[0]=o*s,n[1]=c*s,n[2]=m*s}function fn(n,e,t,r,i,o,c,m,u,s,a,h,l,d,f,S,A=0){let R=s-c,P=a-m,y=h-u,w=l-c,b=d-m,M=f-u,p=i*M-o*b,E=o*w-r*M,v=r*b-i*w,_=R*p+P*E+y*v;if(_>-1e-7&&_<1e-7)return!1;let C=1/_,g=n-c,T=e-m,x=t-u,I=C*(g*p+T*E+x*v);if(I<-A||I>1+A)return!1;let L=T*y-x*P,V=x*R-g*y,N=g*P-T*R,U=C*(r*L+i*V+o*N);if(U<-A||I+U>1+A)return!1;let F=C*(w*L+b*V+M*N);if(F>1e-4&&F<S.distance){S.distance=F,S.point=[n+r*F,e+i*F,t+o*F];let D=P*M-y*b,O=y*w-R*M,k=R*b-P*w,z=Math.hypot(D,O,k)||1;return S.normal=[D/z,O/z,k/z],!0}return!1}function ct(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(K());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 o=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||o.has(a))return;o.add(a);let d=n.nodes[a];if(!d)return;let f=K();if(e&&e[a])f.set(e[a]);else if(d.matrix&&d.matrix.length===16)f.set(d.matrix);else{let A=d.translation||[0,0,0],R=d.rotation||[0,0,0,1],P=d.scale||[1,1,1];at(f,R,A,P)}let S=r[a];if(h?ie(S,h,f):S.set(f),Array.isArray(d.children))for(let A of d.children)typeof A=="number"&&m(A,S,l+1)},u=[],s=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(s&&Array.isArray(s.nodes))u.push(...s.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 ar(n){return new TextDecoder().decode(n)}var yn=J().decoders;function cr(n,e){yn.set(n.toLowerCase(),e)}function Be(n){return yn.get(n.toLowerCase())}function gn(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 o=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=o&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),d=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(d===1313821514){let S=new Uint8Array(e,f,l),A=ar(S);m=JSON.parse(A,(R,P)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:P)}else d===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let s=m.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!Be("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!Be("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!Be("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of Q)l.onParseGLB?.(h);return h}function ur(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 ze(n){if(ur(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return gn(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var xn=`#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
- }`,gn=`#version 300 es
35
+ }`,lr=`#version 300 es
36
36
  precision highp float;
37
37
  in vec3 vNormal,vWorldPos;
38
38
  in vec2 vUV;
@@ -40,12 +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 int uToneMapping,uNumDirLights,uNumPointLights;
48
+ uniform vec4 uSectionPlane;
49
+ uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
49
50
  uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
50
51
  out vec4 fragColor;
51
52
 
@@ -114,6 +115,7 @@ return color;
114
115
  }
115
116
 
116
117
  void main(){
118
+ if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
117
119
  vec4 base=uBaseColor;
118
120
  if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
119
121
  if(length(vNormal)<1e-4&&uHasTexture==1){
@@ -194,28 +196,17 @@ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
194
196
  }
195
197
  color=applyToneMapping(color,uToneMapping);
196
198
  float outAlpha=base.a;
197
- if(uXrDepthEnabled==1){
198
- vec2 normViewUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.0));
199
- vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
200
- vec4 depthSample=texture(uXrDepthTex,depthUV);
201
- float realDepth=(uXrDepthFormat==1?depthSample.r:(depthSample.r+depthSample.a*256.0))*uXrRawValueToMeters;
202
- float virtDepth=length(uCameraPos-vWorldPos);
203
- if(realDepth>0.05&&virtDepth>realDepth){
204
- float occAlpha=1.0-smoothstep(0.0,0.025,virtDepth-realDepth);
205
- outAlpha*=occAlpha;
206
- if(outAlpha<0.01)discard;
207
- }
208
- }
199
+ /*XRD_O*/
209
200
  fragColor=vec4(color,outAlpha);
210
- }`,or=`#version 300 es
201
+ }`,hr=`#version 300 es
211
202
  layout(location=0) in vec3 aPosition;
212
203
  uniform mat4 uMVP;
213
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,sr=`#version 300 es
204
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,mr=`#version 300 es
214
205
  precision highp float;
215
206
  uniform vec4 uColorId;
216
207
  out vec4 fragColor;
217
- void main(){fragColor=uColorId;}`;function fn(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 Ht(n,e,t){let r=fn(n,35633,e),i=fn(n,35632,t),o=n.createProgram();if(n.attachShader(o,r),n.attachShader(o,i),n.linkProgram(o),!n.getProgramParameter(o,35714)){let c=n.getProgramInfoLog(o);throw n.deleteProgram(o),new Error(`Program link error: ${c}`)}return o}function Xt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var xn=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize"];function ar(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 Vt(n,e,t,r,i,o,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],a=(u.byteOffset||0)+(m.byteOffset||0),s=u.byteStride&&u.byteStride>o*4?u.byteStride>>2:o,h;if(s===o)h=new Float32Array(t,a,m.count*o);else{h=new Float32Array(m.count*o);let p=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let T=0;T<m.count;T++){let M=f+T*s;for(let R=0;R<o;R++)h[T*o+R]=p[M+R]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,o,5126,!1,0,0),h}var ei=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),vn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function dn(n,e,t=vn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,c=[],m=ot(i),u=[];if(Array.isArray(i.nodes))for(let w=0;w<i.nodes.length;w++){let v=i.nodes[w];v.mesh!==void 0&&i.meshes&&i.meshes[v.mesh]&&u.push({node:v,nodeIdx:w,meshIdx:v.mesh})}let a=u.length>0?u:(i.meshes||[]).map((w,v)=>({node:w,nodeIdx:-1,meshIdx:v})),s=[];if(Array.isArray(e.lights)&&e.lights.length>0)s.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let w=i.extensions.KHR_lights_punctual.lights;for(let v of w){let _=v.type==="directional"?"directional":v.type==="point"?"point":"ambient";s.push({type:_,color:v.color||[1,1,1],intensity:v.intensity!==void 0?v.intensity:1})}}if(s.length===0&&(s.push({type:"ambient",color:[1,1,1],intensity:.35}),s.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),a.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${a.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 w=0;w<i.textures.length;w++){let v=i.textures[w],_=i.images[v.source];if(_){let C=n.createTexture();if(n.bindTexture(3553,C),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),_.bufferView!==void 0){let d=i.bufferViews[_.bufferView],S=o.slice(d.byteOffset||0,(d.byteOffset||0)+d.byteLength),x=new Blob([S],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(P=>{n.bindTexture(3553,C),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let d=ar(_.uri);if(d){let S=new Image;S.crossOrigin="anonymous",S.referrerPolicy="no-referrer",S.onload=()=>{n.bindTexture(3553,C),n.texImage2D(3553,0,6408,6408,5121,S),n.generateMipmap(3553),r?.()},S.src=d}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}h.push(C)}else h.push(null)}}let l=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0],f=0,T=0;for(let w=0;w<a.length;w++){let v=a[w],_=i.meshes[v.meshIdx],C=v.nodeIdx>=0?m[v.nodeIdx]:J(),d=new Float32Array(9);ae(d,C);let S={name:v.node.name||_.name||`Mesh_${v.meshIdx}`,nodeIndex:v.nodeIdx,transform:C,normalMatrix:d,primitives:[],extras:v.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let $=ke("draco");$&&$.decodePrimitive(i,x,o)}let P=[],B=n.createVertexArray();n.bindVertexArray(B);let V=i.accessors[x.attributes.POSITION],k=Number(V?.count??0);if(!Number.isFinite(k)||k<0||f+k>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=k,V?.min&&V?.max)for(let $=0;$<3;$++){let ue=C[12+$],De=C[12+$];for(let be=0;be<3;be++){let Qe=C[be*4+$]*V.min[be],et=C[be*4+$]*V.max[be];ue+=Qe<et?Qe:et,De+=Qe>et?Qe:et}ue<l[$]&&(l[$]=ue),De>p[$]&&(p[$]=De)}let L=Vt(n,i,o,x.attributes.POSITION,0,3,P);Vt(n,i,o,x.attributes.NORMAL,1,3,P),Vt(n,i,o,x.attributes.TEXCOORD_0,2,2,P);let U=0,D=5123,O=null;if(x.indices!==void 0){let $=i.accessors[x.indices],De=(i.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(U=Number($.count??0),!Number.isFinite(U)||U<0||T+U>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=U,D=$.componentType===5125?5125||5125:5123||5123;let be=n.createBuffer();P.push(be),n.bindBuffer(34963,be),$.componentType===5125?(O=new Uint32Array(o,De,$.count),n.bufferData(34963,O,35044)):(O=new Uint16Array(o,De,$.count),n.bufferData(34963,O,35044))}else U=V.count;let N={};for(let $ of Z)if($.onBuildPrimitiveVAO){let ue=$.onBuildPrimitiveVAO(n,B,x,i,o);ue&&(N[$.name]=ue)}n.bindVertexArray(null);let z=i.materials&&x.material!==void 0?i.materials[x.material]:null,F=yn,H=gn,Y=!1;for(let $ of Z)if($.onResolveShader){let ue=$.onResolveShader(x,z,F,H);ue&&(F=ue.vs,H=ue.fs,Y=!0)}let W=Y?Ht(n,F,H):null,fe=W?Xt(n,W,xn):null,ee=z?.pbrMetallicRoughness,ne=ee?.baseColorFactor||[.8,.8,.8,1],ge=ee?.metallicFactor??.1,xe=ee?.roughnessFactor??.5,de=z?.extensions?.KHR_materials_clearcoat,se=de?de.clearcoatFactor??1:0,ve=Math.max(.04,de?.clearcoatRoughnessFactor??.04),Te=ee?.baseColorTexture!==void 0&&h[ee.baseColorTexture.index]?h[ee.baseColorTexture.index]:null,Ne=ee?.metallicRoughnessTexture!==void 0&&h[ee.metallicRoughnessTexture.index]?h[ee.metallicRoughnessTexture.index]:null,Wn=z?.normalTexture!==void 0&&h[z.normalTexture.index]?h[z.normalTexture.index]:null,$n=z?.normalTexture?.scale??1,Yn=z?.occlusionTexture!==void 0&&h[z.occlusionTexture.index]?h[z.occlusionTexture.index]:null,qn=z?.occlusionTexture?.strength??1,Kn=!!(z?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive);S.primitives.push({vao:B,indexCount:U,indexType:D,baseColor:ne,metallic:ge,roughness:xe,clearcoat:se,clearcoatRoughness:ve,positions:L,indices:O,texture:Te,metallicRoughnessTexture:Ne,normalTexture:Wn,occlusionTexture:Yn,normalScale:$n,occlusionStrength:qn,buffers:P,materialIndex:x.material,pluginData:N,customProgram:W,customUniforms:fe,isTransmissive:Kn})}c.push(S)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(p[0])||(p=[1,1,1]);let M=[(l[0]+p[0])/2,(l[1]+p[1])/2,(l[2]+p[2])/2],R=p[0]-l[0],I=p[1]-l[1],y=p[2]-l[2],E=Math.max(Math.hypot(R,I,y)/2,.5),g=[l[0],l[1],l[2]],A=[p[0],p[1],p[2]],b=e.animations;if(!b){for(let w of Z)if(w.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:c,bounds:{center:M,radius:E,min:g,max:A},lights:s,animations:b,worldMatrices:m}}var st=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.modelMatrix=J();this.mvpMatrix=J();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.xrDepthState={enabled:!1,texture:null,uvTransform:J(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(t&&typeof t.getContext=="function"?(i=t,o=r):(o=t,i=o?.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=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.renderProg=Ht(m,yn,gn),this.pickProg=Ht(m,or,sr),this.uRender=Xt(m,this.renderProg,xn),this.uPick=Xt(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){rr(e,t)}static getDecoder(e){return ke(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),o=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:o,animations:c,worldMatrices:m}=dn(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let a of e.gltf.nodes)this.initialNodeTransforms.push({t:a.translation?[a.translation[0],a.translation[1],a.translation[2]]:[0,0,0],r:a.rotation?[a.rotation[0],a.rotation[1],a.rotation[2],a.rotation[3]]:[0,0,0,1],s:a.scale?[a.scale[0],a.scale[1],a.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let a of Z)a.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(bn(e))}loadModel(e){this.loadGLBData(Oe(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Oe(e),{meshes:i}=dn(this.gl,r,vn,()=>this.render());if(t)for(let o of i)o.transform[12]+=t[0],o.transform[13]+=t[1],o.transform[14]+=t[2],ae(o.normalMatrix,o.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),ae(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],o=[],c=[],m=[];for(let u of this.lights){let a=u.color||[1,1,1],s=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[a[0]*s,a[1]*s,a[2]*s];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),o.push(a[0]*s,a[1]*s,a[2]*s)}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(a[0]*s,a[1]*s,a[2]*s)}}i.length===0&&(i.push(.5,1,.8),o.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,o)),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(s=>s.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),o=i[0],c=o?[...o.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=o?o.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=o?o.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:s=>{let h=[s[0],s[1],s[2],s[3]??1];a.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:s=>{a.metallicFactor=s,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=s);for(let h of i)h.metallic=s;this.render()},setRoughnessFactor:s=>{a.roughnessFactor=s,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=s);for(let h of i)h.roughness=s;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:a}})}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 o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=J();re(r,this.projMatrix,this.viewMatrix);let[i,o,c]=e,m=t?t[0]:0,u=t?t[1]:0,a=t?t[2]:0,s=this.modelRootMatrix;s&&(i=s[0]*e[0]+s[4]*e[1]+s[8]*e[2]+s[12],o=s[1]*e[0]+s[5]*e[1]+s[9]*e[2]+s[13],c=s[2]*e[0]+s[6]*e[1]+s[10]*e[2]+s[14],t&&(m=s[0]*t[0]+s[4]*t[1]+s[8]*t[2],u=s[1]*t[0]+s[5]*t[1]+s[9]*t[2],a=s[2]*t[0]+s[6]*t[1]+s[10]*t[2]));let h=r[0]*i+r[4]*o+r[8]*c+r[12],l=r[1]*i+r[5]*o+r[9]*c+r[13],p=r[2]*i+r[6]*o+r[10]*c+r[14],f=r[3]*i+r[7]*o+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,M=l/f,R=p/f,I=this.canvas.getBoundingClientRect(),y=I.width||this.canvas.clientWidth||this.canvas.width||300,E=I.height||this.canvas.clientHeight||this.canvas.height||150,g=(T*.5+.5)*y,A=(-M*.5+.5)*E,b=T>=-1.1&&T<=1.1&&M>=-1.1&&M<=1.1&&R>=-1&&R<=1;if(b&&t){let w=this.customTarget||this.bounds.center,v=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=w[1]+this.currDistance*Math.sin(this.currPhi),C=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),d=[i-v,o-_,c-C];m*d[0]+u*d[1]+a*d[2]>.05&&(b=!1)}return{x:g,y:A,z:R,visible:b}}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,o=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,o),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],a=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+o*m[0])*a,u[1]+=(-i*c[1]+o*m[1])*a,u[2]+=(-i*c[2]+o*m[2])*a,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=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))),o=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!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(),o=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(o/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,o=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300),m=J();re(m,this.projMatrix,this.viewMatrix);let u=[],a=Math.max(0,Math.min(o-1,e)),s=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i){(this.pickFboWidth!==o||this.pickFboHeight!==c)&&this.resizePickingFbo(o,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let b=0;b<this.meshes.length;b++){let w=this.meshes[b];if(w.visible===!1||w.isPluginMesh)continue;let v=b+1,_=(v&255)/255,C=(v>>8&255)/255,d=(v>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,C,d,1),re(this.modelMatrix,this.modelRootMatrix,w.transform),re(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let S of w.primitives)i.bindVertexArray(S.vao),i.drawElements(4,S.indexCount,S.indexType,0)}let g=new Uint8Array(4);i.readPixels(a,s,1,1,6408,5121,g),i.bindFramebuffer(36160,null);let A=g[0]+(g[1]<<8)+(g[2]<<16);A>0&&A<=this.meshes.length&&(u=[this.meshes[A-1]])}u.length===0&&(u=this.meshes.filter(g=>g.visible!==!1));let h=null,l=1/0,p=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,M=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=T[1]+this.currDistance*Math.sin(this.currPhi),I=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let g of u){re(this.modelMatrix,this.modelRootMatrix,g.transform),re(this.mvpMatrix,m,this.modelMatrix);let A=J();if(!hn(A,this.mvpMatrix))continue;let b=(a+.5)/o*2-1,w=(s+.5)/c*2-1,v=[0,0,0],_=[0,0,0];zt(v,b,w,-1,A),zt(_,b,w,1,A);let C=_[0]-v[0],d=_[1]-v[1],S=_[2]-v[2],x=Math.hypot(C,d,S)||1,P=C/x,B=d/x,V=S/x,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((U=>{for(let D of g.primitives){if(!D.positions)continue;let O=D.positions,N=D.indices,z=Math.floor(N?N.length/3:O.length/9);for(let F=0;F<z;F++){let H=N?N[F*3]:F*3,Y=N?N[F*3+1]:F*3+1,W=N?N[F*3+2]:F*3+2;mn(v[0],v[1],v[2],P,B,V,O[H*3],O[H*3+1],O[H*3+2],O[Y*3],O[Y*3+1],O[Y*3+2],O[W*3],O[W*3+1],O[W*3+2],k,U)}}})(1e-4),isFinite(k.distance)){let U=k.point[0],D=k.point[1],O=k.point[2],N=this.modelMatrix,z=N[0]*U+N[4]*D+N[8]*O+N[12],F=N[1]*U+N[5]*D+N[9]*O+N[13],H=N[2]*U+N[6]*D+N[10]*O+N[14],Y=z-M,W=F-R,fe=H-I,ee=Math.hypot(Y,W,fe);if(ee<l){ae(this.normalMatrix,this.modelMatrix);let ne=this.normalMatrix,ge=k.normal[0],xe=k.normal[1],de=k.normal[2],se=ne[0]*ge+ne[3]*xe+ne[6]*de,ve=ne[1]*ge+ne[4]*xe+ne[7]*de,Te=ne[2]*ge+ne[5]*xe+ne[8]*de,Ne=Math.hypot(se,ve,Te)||1;se/=Ne,ve/=Ne,Te/=Ne,se*Y+ve*W+Te*fe>0&&(se=-se,ve=-ve,Te=-Te),h=g,l=Math.round(ee*1e3)/1e3,p=[Math.round(z*1e3)/1e3,Math.round(F*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(se*1e3)/1e3,Math.round(ve*1e3)/1e3,Math.round(Te*1e3)/1e3]}}}if(!h)return null;let E={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:p,normal:f,screenX:e,screenY:t};if(r){for(let g of Z)g.onMeshSelect?.(this,E);this.opts.onMeshClick&&this.opts.onMeshClick(E),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:E}))}return E}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));(this.canvas.width!==r||this.canvas.height!==i)&&(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i))}start(){if(this.animFrameId!==null)return;this.lastTime=performance.now();let e=t=>{let r=Math.min((t-this.lastTime)/1e3,.1);this.lastTime=t,this.isVisible&&(this.resize(),this.update(r),this.render()),this.animFrameId=requestAnimationFrame(e)};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-t,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=t,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+t*i),o[13]=0,o[14]=i-(-t*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let l of Z)l.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let l of Z)l.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12;let r=(this.canvas.width||1)/(this.canvas.height||1),i=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):this.bounds.radius*20;ln(this.projMatrix,this.fov,r,.1,i);let o=this.customTarget||this.bounds.center,c=o[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),m=o[1]+this.currDistance*Math.sin(this.currPhi),u=o[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);rt(this.viewMatrix,[c,m,u],o,[0,1,0]),re(this.mvpMatrix,this.projMatrix,this.viewMatrix),ae(this.normalMatrix,this.modelMatrix);let a=Math.round((this.currTheta*180/Math.PI%360+360)%360),s=Math.round(this.currPhi*180/Math.PI),h=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(a-this.lastReportedTheta)>=1||Math.abs(s-this.lastReportedPhi)>=1||Math.abs(h-this.lastReportedZoom)>=.02){this.lastReportedTheta=a,this.lastReportedPhi=s,this.lastReportedZoom=h;let l={theta:a,phi:s,zoom:h,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(l),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:l}))}}renderXRView(e,t,r,i){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let o=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,m=e?.transform?.position,u=m?[m.x,m.y,m.z]:[0,1.6,0];r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:o,projMatrix:c,eyePos:u,viewport:i,eye:e?.eye||"none",clear:e?.eye!=="right"})}render(e){let t=this.gl,r=this.canvas.width,i=this.canvas.height;e?.viewport?(t.viewport(e.viewport[0],e.viewport[1],e.viewport[2],e.viewport[3]),r=e.viewport[2],i=e.viewport[3]):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let o=J();re(o,e?.projMatrix??this.projMatrix,e?.viewMatrix??this.viewMatrix);let c=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,u=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),a=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),s=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let M of Z)M.onBeforeDrawScene?.(this,t,o,[u,a,s],c);if(this.meshes.length===0&&this.backdropMeshes.length===0)return;let h=e?.eye||"none",l=!1,p=this.backdropMeshes.length,f=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,T=M=>{for(let R=0;R<f.length;R++){let I=f[R];if(I.visible===!1)continue;let y=this.selectedMeshName!==""&&I.name===this.selectedMeshName;R<p?this.modelMatrix.set(I.transform):re(this.modelMatrix,this.modelRootMatrix,I.transform),re(this.mvpMatrix,o,this.modelMatrix),ae(I.normalMatrix,this.modelMatrix);let E=I.extras?.xr?.stereo||I.userData?.xr?.stereo,g=0,A=0,b=1,w=1;E==="sbs"?(b=.5,g=h==="right"?.5:0):E==="ou"&&(w=.5,A=h==="right"?.5:0);for(let v of I.primitives){let _=!!v.isTransmissive;if(!M&&_){l=!0;continue}if(M&&!_)continue;let C=v.customProgram||this.renderProg,d=v.customUniforms||this.uRender;t.useProgram(C),t.uniform1i(d.uToneMapping,c),t.uniform1f(d.uEnvIntensity,this.envIntensity),t.uniform3f(d.uCameraPos,u,a,s),t.uniform1f(d.uEmissive,y?1:0),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(d.uNormalMatrix,!1,I.normalMatrix),d.uUvTransform&&t.uniform4f(d.uUvTransform,g,A,b,w),d.uViewportSize&&t.uniform2f(d.uViewportSize,Math.max(1,r),Math.max(1,i)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),d.uXrDepthTex&&t.uniform1i(d.uXrDepthTex,5),d.uXrDepthEnabled&&t.uniform1i(d.uXrDepthEnabled,1),d.uXrDepthFormat&&t.uniform1i(d.uXrDepthFormat,this.xrDepthState.format||0),d.uXrRawValueToMeters&&t.uniform1f(d.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),d.uXrDepthUVTransform&&t.uniformMatrix4fv(d.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):d.uXrDepthEnabled&&t.uniform1i(d.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(d.uEnvironmentMap,4),t.uniform1i(d.uHasEnvironmentMap,1)):t.uniform1i(d.uHasEnvironmentMap,0),this.bindLights(d);for(let S of Z)S.onBeforeDrawPrimitive?.(t,C,v,I,this.worldMatrices||[],this.gltf);t.uniform4fv(d.uBaseColor,v.baseColor),t.uniform1f(d.uMetallic,v.metallic),t.uniform1f(d.uRoughness,v.roughness),d.uClearcoat&&t.uniform2f(d.uClearcoat,v.clearcoat??0,v.clearcoatRoughness??.04),v.texture?(t.activeTexture(33984),t.bindTexture(3553,v.texture),t.uniform1i(d.uBaseColorTexture,0),t.uniform1i(d.uHasTexture,1)):t.uniform1i(d.uHasTexture,0),v.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,v.metallicRoughnessTexture),t.uniform1i(d.uMetallicRoughnessTexture,1),t.uniform1i(d.uHasMetallicRoughnessTexture,1)):t.uniform1i(d.uHasMetallicRoughnessTexture,0),v.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,v.normalTexture),t.uniform1i(d.uNormalTexture,2),t.uniform1i(d.uHasNormalTexture,1),t.uniform1f(d.uNormalScale,v.normalScale)):t.uniform1i(d.uHasNormalTexture,0),v.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,v.occlusionTexture),t.uniform1i(d.uOcclusionTexture,3),t.uniform1i(d.uHasOcclusionTexture,1),t.uniform1f(d.uOcclusionStrength,v.occlusionStrength)):t.uniform1i(d.uHasOcclusionTexture,0),t.bindVertexArray(v.vao),t.drawElements(4,v.indexCount,v.indexType,0)}}};if(T(!1),l){for(let M of Z)M.onBeforeTransmissivePass?.(t,this);T(!0)}for(let M of Z)M.onAfterRender?.(t,this,o)}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 o of i.buffers)t.deleteBuffer(o);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()}};st.registerPlugin=cn,st.getRegisteredPlugins=un;function cr(n){return n+3&-4}function ur(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 Ce(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],o=[],c=[],m=[],u=new Set,a=[],s=[],h=new Map,l=[];function p(b,w){let v=new Uint8Array(b.buffer,b.byteOffset,b.byteLength),_=cr(v.byteLength),C=new Uint8Array(_);C.set(v),t.push(C);let d=i.length;return i.push({buffer:0,byteOffset:r,byteLength:v.byteLength,target:w}),r+=_,d}function f(b,w,v,_,C,d,S){let x=p(b,v),P=o.length,B={bufferView:x,byteOffset:0,componentType:_,count:C,type:w};return d&&(B.min=d),S&&(B.max=S),o.push(B),P}n.traverse(b=>{(b.isLight||b.color&&b.intensity!==void 0)&&l.push({type:b.type,color:[b.color.r,b.color.g,b.color.b],intensity:b.intensity,position:[b.position.x,b.position.y,b.position.z]})});let T=[];function M(b){let w={name:b.name||""},v=b.position,_=b.quaternion,C=b.scale;if((v.x||v.y||v.z)&&(w.translation=[v.x,v.y,v.z]),(_.x||_.y||_.z||_.w!==1)&&(w.rotation=[_.x,_.y,_.z,_.w]),(C.x!==1||C.y!==1||C.z!==1)&&(w.scale=[C.x,C.y,C.z]),b.userData&&Object.keys(b.userData).length>0&&(w.extras=JSON.parse(JSON.stringify(b.userData,(S,x)=>{if(!(S==="__proto__"||S==="prototype"||S==="constructor"))return typeof x=="function"?void 0:x})),b.userData.xr)){let S=ur(b.userData.xr);w.extensions={...w.extensions||{},MOZ_hubs_components:S,ANDROID_xr_scenecore:S},j().xrTraitSerializer?.gltfNode(w,b.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(b.geometry){let S=b.geometry,x=S.attributes.position;if(x&&x.count>0){let P=[1/0,1/0,1/0],B=[-1/0,-1/0,-1/0];for(let U=0;U<x.count;U++){let D=x.getX(U),O=x.getY(U),N=x.getZ(U);D<P[0]&&(P[0]=D),D>B[0]&&(B[0]=D),O<P[1]&&(P[1]=O),O>B[1]&&(B[1]=O),N<P[2]&&(P[2]=N),N>B[2]&&(B[2]=N)}let k={attributes:{POSITION:f(x.array,"VEC3",34962,5126,x.count,P,B)}};if(S.attributes.normal&&(k.attributes.NORMAL=f(S.attributes.normal.array,"VEC3",34962,5126,S.attributes.normal.count)),S.attributes.uv&&(k.attributes.TEXCOORD_0=f(S.attributes.uv.array,"VEC2",34962,5126,S.attributes.uv.count)),S.index){let U=S.index.array instanceof Uint32Array;k.indices=f(S.index.array,"SCALAR",34963,U?5125:5123,S.index.count)}if(b.material){let U=h.get(b.material);if(U===void 0){U=s.length,h.set(b.material,U);let D=b.material,O={name:D.name||"",pbrMetallicRoughness:{baseColorFactor:[D.color.r,D.color.g,D.color.b,D.opacity],metallicFactor:D.metalness,roughnessFactor:D.roughness},doubleSided:D.side===2||D.doubleSided};if(D.emissive&&(D.emissive.r>0||D.emissive.g>0||D.emissive.b>0)){let z=D.emissiveIntensity??1;O.emissiveFactor=[D.emissive.r*z,D.emissive.g*z,D.emissive.b*z]}let N={};D.clearcoat>0&&(N.KHR_materials_clearcoat={clearcoatFactor:D.clearcoat,clearcoatRoughnessFactor:D.clearcoatRoughness||0}),D.sheen>0&&(N.KHR_materials_sheen={sheenColorFactor:D.sheenColor?[D.sheenColor.r,D.sheenColor.g,D.sheenColor.b]:[1,1,1],sheenRoughnessFactor:D.sheenRoughness||0}),D.transmission>0&&(N.KHR_materials_transmission={transmissionFactor:D.transmission}),D.thickness>0&&(N.KHR_materials_volume={thicknessFactor:D.thickness,attenuationDistance:D.attenuationDistance??1/0,attenuationColor:D.attenuationColor?[D.attenuationColor.r,D.attenuationColor.g,D.attenuationColor.b]:[1,1,1]}),D.ior!==void 0&&D.ior!==1.5&&(N.KHR_materials_ior={ior:D.ior}),D.dispersion>0&&(N.KHR_materials_dispersion={dispersion:D.dispersion}),D.iridescence>0&&(N.KHR_materials_iridescence={iridescenceFactor:D.iridescence,iridescenceIor:D.iridescenceIOR??1.3}),Object.keys(N).length>0&&(O.extensions=N),s.push(O)}k.material=U}let L=c.length;c.push({primitives:[k],name:b.name,...w.extras?{extras:w.extras}:{}}),w.mesh=L}}let d=m.length;if(m.push(w),a.push(b),b.children.length>0){w.children=[];for(let S of b.children)w.children.push(M(S))}return d}for(let b of n.children)T.push(M(b));let R=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),I=[];if(typeof R=="function"&&a.length>0){let b=e?.duration??4,w=e?.fps??15,v=Math.max(2,Math.round(b*w)+1),_=new Float32Array(v),C=a.map(L=>({px:L.position.x,py:L.position.y,pz:L.position.z,qx:L.quaternion.x,qy:L.quaternion.y,qz:L.quaternion.z,qw:L.quaternion.w,sx:L.scale.x,sy:L.scale.y,sz:L.scale.z})),d=a.map(()=>new Float32Array(v*3)),S=a.map(()=>new Float32Array(v*4)),x=a.map(()=>new Float32Array(v*3));for(let L=0;L<v;L++){let U=L/(v-1)*b;_[L]=U;try{R(U)}catch{}for(let D=0;D<a.length;D++){let O=a[D];d[D][L*3]=O.position.x,d[D][L*3+1]=O.position.y,d[D][L*3+2]=O.position.z,S[D][L*4]=O.quaternion.x,S[D][L*4+1]=O.quaternion.y,S[D][L*4+2]=O.quaternion.z,S[D][L*4+3]=O.quaternion.w,x[D][L*3]=O.scale.x,x[D][L*3+1]=O.scale.y,x[D][L*3+2]=O.scale.z}}for(let L=0;L<a.length;L++){let U=a[L],D=C[L];U.position.set(D.px,D.py,D.pz),U.quaternion.set(D.qx,D.qy,D.qz,D.qw),U.scale.set(D.sx,D.sy,D.sz)}n.updateMatrixWorld(!0);let P=null,B=()=>(P===null&&(P=f(_,"SCALAR",0,5126,v,[0],[b])),P),V=[],k=[];for(let L=0;L<a.length;L++){let U=C[L],D=!1,O=!1,N=!1;for(let z=0;z<v;z++)(Math.abs(d[L][z*3]-U.px)>1e-4||Math.abs(d[L][z*3+1]-U.py)>1e-4||Math.abs(d[L][z*3+2]-U.pz)>1e-4)&&(D=!0),(Math.abs(S[L][z*4]-U.qx)>1e-4||Math.abs(S[L][z*4+1]-U.qy)>1e-4||Math.abs(S[L][z*4+2]-U.qz)>1e-4||Math.abs(S[L][z*4+3]-U.qw)>1e-4)&&(O=!0),(Math.abs(x[L][z*3]-U.sx)>1e-4||Math.abs(x[L][z*3+1]-U.sy)>1e-4||Math.abs(x[L][z*3+2]-U.sz)>1e-4)&&(N=!0);if(D){let z=f(d[L],"VEC3",0,5126,v),F=V.length;V.push({input:B(),interpolation:"LINEAR",output:z}),k.push({sampler:F,target:{node:L,path:"translation"}})}if(O){let z=f(S[L],"VEC4",0,5126,v),F=V.length;V.push({input:B(),interpolation:"LINEAR",output:z}),k.push({sampler:F,target:{node:L,path:"rotation"}})}if(N){let z=f(x[L],"VEC3",0,5126,v),F=V.length;V.push({input:B(),interpolation:"LINEAR",output:z}),k.push({sampler:F,target:{node:L,path:"scale"}})}}k.length>0&&I.push({name:"ProceduralLoop",samplers:V,channels:k})}let y=tt(m,c,n.userData),E={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:s,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...I.length>0?{animations:I}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},g=new Uint8Array(r),A=0;for(let b of t)g.set(b,A),A+=b.byteLength;return{gltf:E,bin:g.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function ct(n){return new TextEncoder().encode(n)}function Be(n,e){let{gltf:t,bin:r}=Ce(n,e),i=JSON.stringify(t),o=ct(i),c=(4-o.byteLength%4)%4,m=o.byteLength+c,u=20+m+8+r.byteLength,a=new Uint8Array(u),s=new DataView(a.buffer);s.setUint32(0,1179937895,!0),s.setUint32(4,2,!0),s.setUint32(8,u,!0),s.setUint32(12,m,!0),s.setUint32(16,1313821514,!0),a.set(o,20);for(let l=0;l<c;l++)a[20+o.byteLength+l]=32;let h=20+m;return s.setUint32(h,r.byteLength,!0),s.setUint32(h+4,5130562,!0),a.set(new Uint8Array(r),h+8),a}function lr(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let c=o.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let b=0;b<c;b++){let w=o.getX(b),v=o.getY(b),_=o.getZ(b);m[b*3]=u[0]*w+u[4]*v+u[8]*_+u[12],m[b*3+1]=u[1]*w+u[5]*v+u[9]*_+u[13],m[b*3+2]=u[2]*w+u[6]*v+u[10]*_+u[14]}let a;if(i.attributes.normal){let b=i.attributes.normal;a=new Float32Array(c*3);let w=new Float32Array(9);ae(w,u);for(let v=0;v<c;v++){let _=b.getX(v),C=b.getY(v),d=b.getZ(v),S=w[0]*_+w[3]*C+w[6]*d,x=w[1]*_+w[4]*C+w[7]*d,P=w[2]*_+w[5]*C+w[8]*d,B=Math.hypot(S,x,P)||1;a[v*3]=S/B,a[v*3+1]=x/B,a[v*3+2]=P/B}}let s;if(i.attributes.uv){let b=i.attributes.uv;s=new Float32Array(c*2);for(let w=0;w<c;w++)s[w*2]=b.getX(w),s[w*2+1]=b.getY(w)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let b=0;b<c;b++)h[b]=b}let l="DefaultMaterial",p=[.8,.8,.8],f=.5,T=.1,M=0,R=0,I=1.5,y=1,E=[0,0,0];if(r.material){let b=r.material;l=b.name||`Material_${t.length}`,b.color&&(p=[b.color.r,b.color.g,b.color.b]),typeof b.roughness=="number"&&(f=b.roughness),typeof b.metalness=="number"&&(T=b.metalness),typeof b.clearcoat=="number"&&(M=b.clearcoat),typeof b.clearcoatRoughness=="number"&&(R=b.clearcoatRoughness),typeof b.ior=="number"&&(I=b.ior);let w=typeof b.opacity=="number"?b.opacity:1,v=typeof b.transmission=="number"?b.transmission:0;if(y=w*(1-v),b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let _=b.emissiveIntensity??1;E=[b.emissive.r*_,b.emissive.g*_,b.emissive.b*_]}}let g,A=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof A=="function"){let b=e?.duration??4,w=e?.fps??4,v=Math.max(2,Math.round(b*w)+1),_=[],C=[],d=[],S=[],x=[r.position.x,r.position.y,r.position.z],P=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],B=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let k=0;k<v;k++){let L=k/(v-1)*b;_.push(L);try{A(L)}catch{}C.push([r.position.x,r.position.y,r.position.z]),d.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),S.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-x[0])>1e-4||Math.abs(r.position.y-x[1])>1e-4||Math.abs(r.position.z-x[2])>1e-4||Math.abs(r.quaternion.x-P[0])>1e-4||Math.abs(r.quaternion.y-P[1])>1e-4||Math.abs(r.quaternion.z-P[2])>1e-4||Math.abs(r.quaternion.w-P[3])>1e-4||Math.abs(r.scale.x-B[0])>1e-4)&&(V=!0)}r.position.set(x[0],x[1],x[2]),r.quaternion.set(P[0],P[1],P[2],P[3]),r.scale.set(B[0],B[1],B[2]),V&&(g={times:_,translations:C,rotations:d,scales:S})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:a,uvs:s,materialName:l,color:p,roughness:f,metallic:T,clearcoat:M,clearcoatRoughness:R,ior:I,opacity:y,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:g})}}),t}function En(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],a=t.nodes||[];function s(p){let f=o[p];if(!f)throw new Error(`Accessor ${p} not found`);let T=c[f.bufferView||0],M=(T.byteOffset||0)+(f.byteOffset||0),R=T.byteLength||0,I=i.slice(M,M+R);return{acc:f,buffer:I}}let h=new Map;if(a.length>0){let p=ot(t);for(let f=0;f<p.length;f++)h.set(f,p[f])}function l(p,f,T,M){let R=u[p];if(!R)return;let I=new Float32Array(9);ae(I,f);for(let y=0;y<(R.primitives||[]).length;y++){let E=R.primitives[y],g=E.attributes?.POSITION;if(g===void 0)continue;let{acc:A,buffer:b}=s(g),w=new Float32Array(b,0,A.count*3),v=new Float32Array(w.length);for(let F=0;F<A.count;F++){let H=w[F*3],Y=w[F*3+1],W=w[F*3+2];v[F*3]=f[0]*H+f[4]*Y+f[8]*W+f[12],v[F*3+1]=f[1]*H+f[5]*Y+f[9]*W+f[13],v[F*3+2]=f[2]*H+f[6]*Y+f[10]*W+f[14]}let _,C=E.attributes?.NORMAL;if(C!==void 0){let{acc:F,buffer:H}=s(C),Y=new Float32Array(H,0,F.count*3);_=new Float32Array(Y.length);for(let W=0;W<F.count;W++){let fe=Y[W*3],ee=Y[W*3+1],ne=Y[W*3+2],ge=I[0]*fe+I[3]*ee+I[6]*ne,xe=I[1]*fe+I[4]*ee+I[7]*ne,de=I[2]*fe+I[5]*ee+I[8]*ne,se=Math.hypot(ge,xe,de)||1;_[W*3]=ge/se,_[W*3+1]=xe/se,_[W*3+2]=de/se}}let d,S=E.attributes?.TEXCOORD_0;if(S!==void 0){let{acc:F,buffer:H}=s(S);d=new Float32Array(H,0,F.count*2)}let x;if(E.indices!==void 0){let{acc:F,buffer:H}=s(E.indices);F.componentType===5125?x=new Uint32Array(H,0,F.count):x=new Uint16Array(H,0,F.count);let Y=A.count;for(let W of x)if(W>=Y)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${Y}).`)}else{let F=A.count;x=F>65535?new Uint32Array(F):new Uint16Array(F);for(let H=0;H<F;H++)x[H]=H}let P="DefaultMaterial",B=[.8,.8,.8],V=.5,k=.1,L=0,U=0,D=1.5,O=1,N=[0,0,0];if(E.material!==void 0&&m[E.material]){let F=m[E.material];P=F.name||`Material_${E.material}`;let H=F.pbrMetallicRoughness||{},Y=1;Array.isArray(H.baseColorFactor)&&(B=[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"&&(k=H.metallicFactor),Array.isArray(F.emissiveFactor)&&F.emissiveFactor.length>=3&&(N=[F.emissiveFactor[0],F.emissiveFactor[1],F.emissiveFactor[2]]);let W=F.extensions||{};W.KHR_materials_clearcoat&&(L=W.KHR_materials_clearcoat.clearcoatFactor??0,U=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(D=W.KHR_materials_ior.ior);let fe=W.KHR_materials_transmission?.transmissionFactor??0;O=Y*(1-fe)}let z=(R.primitives||[]).length>1?`${T}_p${y}`:T;e.push({name:z,positions:v,indices:x,normals:_,uvs:d,materialName:P,color:B,roughness:V,metallic:k,clearcoat:L,clearcoatRoughness:U,ior:D,opacity:O,emissiveColor:N,xrTraits:M?.xr||R.extras?.xr})}}if(a.length>0)for(let p=0;p<a.length;p++){let f=a[p];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(p)||J(),M=f.name||u[f.mesh].name||`Node_${p}`;l(f.mesh,T,M,f.extras)}}else{let p=J();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,p,T,u[f].extras)}}return e}function Gt(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 Tn(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 wn(n){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(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 hr(n,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(n)}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 mr(n){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(n)}return Array.from(n).join(", ")}function Wt(n){let e=new Map;for(let u of n){let a=Gt(u.materialName,"DefaultMaterial");e.has(a)||e.set(a,{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 a=u.timeSamples.times[u.timeSamples.times.length-1];a>t&&(t=a)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
218
- endTimeCode = ${G(t)}
208
+ void main(){fragColor=uColorId;}`;function dn(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 Wt(n,e,t){let r=dn(n,35633,e),i=dn(n,35632,t),o=n.createProgram();if(n.attachShader(o,r),n.attachShader(o,i),n.linkProgram(o),!n.getProgramParameter(o,35714)){let c=n.getProgramInfoLog(o);throw n.deleteProgram(o),new Error(`Program link error: ${c}`)}return o}function $t(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var pn=["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 vn(){let n=J().xrDepthShader;return{fs:lr.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...pn,...n.uniformNames]:pn}}function fr(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 Xt(n,e,t,r,i,o,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],s=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>o*4?u.byteStride>>2:o,h;if(a===o)h=new Float32Array(t,s,m.count*o);else{h=new Float32Array(m.count*o);let d=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let S=0;S<m.count;S++){let A=f+S*a;for(let R=0;R<o;R++)h[S*o+R]=d[A+R]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,o,5126,!1,0,0),h}var pi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Tn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function bn(n,e,t=Tn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,c=[],m=ct(i),u=[];if(Array.isArray(i.nodes))for(let E=0;E<i.nodes.length;E++){let v=i.nodes[E];v.mesh!==void 0&&i.meshes&&i.meshes[v.mesh]&&u.push({node:v,nodeIdx:E,meshIdx:v.mesh})}let s=u.length>0?u:(i.meshes||[]).map((E,v)=>({node:E,nodeIdx:-1,meshIdx:v})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let E=i.extensions.KHR_lights_punctual.lights;for(let v of E){let _=v.type==="directional"?"directional":v.type==="point"?"point":"ambient";a.push({type:_,color:v.color||[1,1,1],intensity:v.intensity!==void 0?v.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),s.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${s.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 E=0;E<i.textures.length;E++){let v=i.textures[E],_=i.images[v.source];if(_){let C=n.createTexture();if(n.bindTexture(3553,C),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),_.bufferView!==void 0){let g=i.bufferViews[_.bufferView],T=o.slice(g.byteOffset||0,(g.byteOffset||0)+g.byteLength),x=new Blob([T],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(I=>{n.bindTexture(3553,C),n.texImage2D(3553,0,6408,6408,5121,I),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let g=fr(_.uri);if(g){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>{n.bindTexture(3553,C),n.texImage2D(3553,0,6408,6408,5121,T),n.generateMipmap(3553),r?.()},T.src=g}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}h.push(C)}else h.push(null)}}let l=[1/0,1/0,1/0],d=[-1/0,-1/0,-1/0],f=0,S=0;for(let E=0;E<s.length;E++){let v=s[E],_=i.meshes[v.meshIdx],C=v.nodeIdx>=0?m[v.nodeIdx]:K(),g=new Float32Array(9);ce(g,C);let T={name:v.node.name||_.name||`Mesh_${v.meshIdx}`,nodeIndex:v.nodeIdx,transform:C,normalMatrix:g,primitives:[],extras:v.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let Y=Be("draco");Y&&Y.decodePrimitive(i,x,o)}let I=[],L=n.createVertexArray();n.bindVertexArray(L);let V=i.accessors[x.attributes.POSITION],N=Number(V?.count??0);if(!Number.isFinite(N)||N<0||f+N>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=N,V?.min&&V?.max)for(let Y=0;Y<3;Y++){let le=C[12+Y],Ce=C[12+Y];for(let de=0;de<3;de++){let nt=C[de*4+Y]*V.min[de],rt=C[de*4+Y]*V.max[de];le+=nt<rt?nt:rt,Ce+=nt>rt?nt:rt}le<l[Y]&&(l[Y]=le),Ce>d[Y]&&(d[Y]=Ce)}let U=Xt(n,i,o,x.attributes.POSITION,0,3,I);Xt(n,i,o,x.attributes.NORMAL,1,3,I),Xt(n,i,o,x.attributes.TEXCOORD_0,2,2,I);let F=0,D=5123,O=null;if(x.indices!==void 0){let Y=i.accessors[x.indices],Ce=(i.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(F=Number(Y.count??0),!Number.isFinite(F)||F<0||S+F>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);S+=F,D=Y.componentType===5125?5125||5125:5123||5123;let de=n.createBuffer();I.push(de),n.bindBuffer(34963,de),Y.componentType===5125?(O=new Uint32Array(o,Ce,Y.count),n.bufferData(34963,O,35044)):(O=new Uint16Array(o,Ce,Y.count),n.bufferData(34963,O,35044))}else F=V.count;let k={};for(let Y of Q)if(Y.onBuildPrimitiveVAO){let le=Y.onBuildPrimitiveVAO(n,L,x,i,o);le&&(k[Y.name]=le)}n.bindVertexArray(null);let z=i.materials&&x.material!==void 0?i.materials[x.material]:null,B=vn(),H=xn,$=B.fs,W=!1;for(let Y of Q)if(Y.onResolveShader){let le=Y.onResolveShader(x,z,H,$);le&&(H=le.vs,$=le.fs,W=!0)}let ae=W?Wt(n,H,$):null,be=ae?$t(n,ae,B.uniforms):null,j=z?.pbrMetallicRoughness,ye=j?.baseColorFactor||[.8,.8,.8,1],ge=j?.metallicFactor??.1,xe=j?.roughnessFactor??.5,re=z?.extensions?.KHR_materials_clearcoat,ve=re?re.clearcoatFactor??1:0,Te=Math.max(.04,re?.clearcoatRoughnessFactor??.04),Oe=j?.baseColorTexture!==void 0&&h[j.baseColorTexture.index]?h[j.baseColorTexture.index]:null,jn=j?.metallicRoughnessTexture!==void 0&&h[j.metallicRoughnessTexture.index]?h[j.metallicRoughnessTexture.index]:null,Kn=z?.normalTexture!==void 0&&h[z.normalTexture.index]?h[z.normalTexture.index]:null,Zn=z?.normalTexture?.scale??1,Jn=z?.occlusionTexture!==void 0&&h[z.occlusionTexture.index]?h[z.occlusionTexture.index]:null,Qn=z?.occlusionTexture?.strength??1,er=!!(z?.extensions?.KHR_materials_transmission||k.materials?.isTransmissive);T.primitives.push({vao:L,indexCount:F,indexType:D,baseColor:ye,metallic:ge,roughness:xe,clearcoat:ve,clearcoatRoughness:Te,positions:U,indices:O,texture:Oe,metallicRoughnessTexture:jn,normalTexture:Kn,occlusionTexture:Jn,normalScale:Zn,occlusionStrength:Qn,buffers:I,materialIndex:x.material,pluginData:k,customProgram:ae,customUniforms:be,isTransmissive:er})}c.push(T)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(d[0])||(d=[1,1,1]);let A=[(l[0]+d[0])/2,(l[1]+d[1])/2,(l[2]+d[2])/2],R=d[0]-l[0],P=d[1]-l[1],y=d[2]-l[2],w=Math.max(Math.hypot(R,P,y)/2,.5),b=[l[0],l[1],l[2]],M=[d[0],d[1],d[2]],p=e.animations;if(!p){for(let E of Q)if(E.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:c,bounds:{center:A,radius:w,min:b,max:M},lights:a,animations:p,worldMatrices:m}}var ut=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=K();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=K();this.viewMatrix=K();this.modelMatrix=K();this.mvpMatrix=K();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:K(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(t&&typeof t.getContext=="function"?(i=t,o=r):(o=t,i=o?.canvas),!i){let s=e.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",e.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m;let u=vn();this.renderProg=Wt(m,xn,u.fs),this.pickProg=Wt(m,hr,mr),this.uRender=$t(m,this.renderProg,u.uniforms),this.uPick=$t(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){cr(e,t)}static getDecoder(e){return Be(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let 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),o=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:o,animations:c,worldMatrices:m}=bn(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let s of e.gltf.nodes)this.initialNodeTransforms.push({t:s.translation?[s.translation[0],s.translation[1],s.translation[2]]:[0,0,0],r:s.rotation?[s.rotation[0],s.rotation[1],s.rotation[2],s.rotation[3]]:[0,0,0,1],s:s.scale?[s.scale[0],s.scale[1],s.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let s of Q)s.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(gn(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(ze(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=ze(e),{meshes:i}=bn(this.gl,r,Tn,()=>this.render());if(t)for(let o of i)o.transform[12]+=t[0],o.transform[13]+=t[1],o.transform[14]+=t[2],ce(o.normalMatrix,o.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),ce(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],o=[],c=[],m=[];for(let u of this.lights){let s=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[s[0]*a,s[1]*a,s[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),o.push(s[0]*a,s[1]*a,s[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(s[0]*a,s[1]*a,s[2]*a)}}i.length===0&&(i.push(.5,1,.8),o.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,o)),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 Q)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Q)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)),o=i[0],c=o?[...o.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=o?o.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=o?o.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];s.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{s.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{s.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:s}})}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 Q)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 o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=K();ie(r,this.projMatrix,this.viewMatrix);let[i,o,c]=e,m=t?t[0]:0,u=t?t[1]:0,s=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],o=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],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],s=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*o+r[8]*c+r[12],l=r[1]*i+r[5]*o+r[9]*c+r[13],d=r[2]*i+r[6]*o+r[10]*c+r[14],f=r[3]*i+r[7]*o+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let S=h/f,A=l/f,R=d/f,P=this.canvas.getBoundingClientRect(),y=P.width||this.canvas.clientWidth||this.canvas.width||300,w=P.height||this.canvas.clientHeight||this.canvas.height||150,b=(S*.5+.5)*y,M=(-A*.5+.5)*w,p=S>=-1.1&&S<=1.1&&A>=-1.1&&A<=1.1&&R>=-1&&R<=1;if(p&&t){let E=this.customTarget||this.bounds.center,v=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=E[1]+this.currDistance*Math.sin(this.currPhi),C=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=[i-v,o-_,c-C];m*g[0]+u*g[1]+s*g[2]>.05&&(p=!1)}return{x:b,y:M,z:R,visible:p}}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,o=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,o),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],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+o*m[0])*s,u[1]+=(-i*c[1]+o*m[1])*s,u[2]+=(-i*c[2]+o*m[2])*s,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=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))),o=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!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(),o=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(o/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,o=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let m=K();ie(m,this.projMatrix,this.viewMatrix);let u=[],s=Math.max(0,Math.min(o-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==c)&&this.resizePickingFbo(o,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let p=0;p<this.meshes.length;p++){let E=this.meshes[p];if(E.visible===!1||E.isPluginMesh)continue;let v=p+1,_=(v&255)/255,C=(v>>8&255)/255,g=(v>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,C,g,1),ie(this.modelMatrix,this.modelRootMatrix,E.transform),ie(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let T of E.primitives)i.bindVertexArray(T.vao),i.drawElements(4,T.indexCount,T.indexType,0)}let b=new Uint8Array(4);i.readPixels(s,a,1,1,6408,5121,b),i.bindFramebuffer(36160,null);let M=b[0]+(b[1]<<8)+(b[2]<<16);M>0&&M<=this.meshes.length&&(u=[this.meshes[M-1]])}u.length===0&&(u=this.meshes.filter(b=>b.visible!==!1));let h=null,l=1/0,d=[0,0,0],f=[0,1,0],S=this.customTarget||this.bounds.center,A=S[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=S[1]+this.currDistance*Math.sin(this.currPhi),P=S[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let b of u){ie(this.modelMatrix,this.modelRootMatrix,b.transform),ie(this.mvpMatrix,m,this.modelMatrix);let M=K();if(!mn(M,this.mvpMatrix))continue;let p=(s+.5)/o*2-1,E=(a+.5)/c*2-1,v=[0,0,0],_=[0,0,0];Gt(v,p,E,-1,M),Gt(_,p,E,1,M);let C=_[0]-v[0],g=_[1]-v[1],T=_[2]-v[2],x=Math.hypot(C,g,T)||1,I=C/x,L=g/x,V=T/x,N={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((F=>{for(let D of b.primitives){if(!D.positions)continue;let O=D.positions,k=D.indices,z=Math.floor(k?k.length/3:O.length/9);for(let B=0;B<z;B++){let H=k?k[B*3]:B*3,$=k?k[B*3+1]:B*3+1,W=k?k[B*3+2]:B*3+2;fn(v[0],v[1],v[2],I,L,V,O[H*3],O[H*3+1],O[H*3+2],O[$*3],O[$*3+1],O[$*3+2],O[W*3],O[W*3+1],O[W*3+2],N,F)}}})(1e-4),isFinite(N.distance)){let F=N.point[0],D=N.point[1],O=N.point[2],k=this.modelMatrix,z=k[0]*F+k[4]*D+k[8]*O+k[12],B=k[1]*F+k[5]*D+k[9]*O+k[13],H=k[2]*F+k[6]*D+k[10]*O+k[14],$=z-A,W=B-R,ae=H-P,be=Math.hypot($,W,ae);if(be<l){ce(this.normalMatrix,this.modelMatrix);let j=this.normalMatrix,ye=N.normal[0],ge=N.normal[1],xe=N.normal[2],re=j[0]*ye+j[3]*ge+j[6]*xe,ve=j[1]*ye+j[4]*ge+j[7]*xe,Te=j[2]*ye+j[5]*ge+j[8]*xe,Oe=Math.hypot(re,ve,Te)||1;re/=Oe,ve/=Oe,Te/=Oe,re*$+ve*W+Te*ae>0&&(re=-re,ve=-ve,Te=-Te),h=b,l=Math.round(be*1e3)/1e3,d=[Math.round(z*1e3)/1e3,Math.round(B*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(re*1e3)/1e3,Math.round(ve*1e3)/1e3,Math.round(Te*1e3)/1e3]}}}if(!h)return null;let w={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:d,normal:f,screenX:e,screenY:t};if(r){for(let b of Q)b.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,o=i?e-r:e,c=i?Math.max(1,t-r):r,m=(o+.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);st(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),o=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Le(this.viewMatrix,[i,o,c],r,[0,1,0]),ie(this.mvpMatrix,this.projMatrix,this.viewMatrix),ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),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 Q)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 Q)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],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-t,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=t,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+t*i),o[13]=0,o[14]=i-(-t*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of Q)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 Q)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let c={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,t,r,i,o=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,s=e?.transform?.position,a=s?[s.x,s.y,s.z]:[0,1.6,0];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:o})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),b=Math.max(1,this.canvas.height||1),M=Math.max(1,Math.floor(w*.5)),p=Math.max(1,w-M),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,_=v[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),C=v[1]+this.currDistance*Math.sin(this.currPhi),g=v[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),T=Math.cos(this.currTheta),x=-Math.sin(this.currTheta),I=.032,L=K(),V=K(),N=[_-T*I,C,g-x*I],U=[v[0]-T*I*.25,v[1],v[2]-x*I*.25];st(L,this.fov,M/b,.1,E),Le(V,N,U,[0,1,0]);let F=K(),D=K(),O=[_+T*I,C,g+x*I],k=[v[0]+T*I*.25,v[1],v[2]+x*I*.25];st(F,this.fov,p/b,.1,E),Le(D,O,k,[0,1,0]),this.render({viewMatrix:V,projMatrix:L,eyePos:N,viewport:[0,0,M,b],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:D,projMatrix:F,eyePos:O,viewport:[M,0,p,b],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,b);return}let t=this.gl,r=0,i=0,o=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],c=e.viewport[3],t.viewport(r,i,o,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=K(),u=e?.viewMatrix??this.viewMatrix;ie(m,e?.projMatrix??this.projMatrix,u);let s=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),d=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 w of Q)w.onBeforeDrawScene?.(this,t,m,[l,d,f],a);let S=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let A=e?.eye||"none",R=!1,P=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=w=>{for(let b=0;b<P.length;b++){let M=P[b];if(M.visible===!1)continue;let p=this.selectedMeshName!==""&&M.name===this.selectedMeshName;b<S||M.worldSpace===!0||M.name==="__xr_reticle__"?this.modelMatrix.set(M.transform):ie(this.modelMatrix,this.modelRootMatrix,M.transform),ie(this.mvpMatrix,m,this.modelMatrix),ce(M.normalMatrix,this.modelMatrix);let E=M.extras?.xr?.stereo||M.userData?.xr?.stereo,v=0,_=0,C=1,g=1;E==="sbs"?(C=.5,v=A==="right"?.5:0):E==="ou"&&(g=.5,_=A==="right"?.5:0);for(let T of M.primitives){let x=!!T.isTransmissive;if(!w&&x){R=!0;continue}if(w&&!x)continue;let I=T.customProgram||this.renderProg,L=T.customUniforms||this.uRender;t.useProgram(I),t.uniform1i(L.uToneMapping,a),t.uniform1f(L.uEnvIntensity,this.envIntensity),t.uniform3f(L.uCameraPos,l,d,f),t.uniform1f(L.uEmissive,p?1:0),t.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(L.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(L.uNormalMatrix,!1,M.normalMatrix),L.uUvTransform&&t.uniform4f(L.uUvTransform,v,_,C,g),L.uViewportSize&&t.uniform2f(L.uViewportSize,Math.max(1,o),Math.max(1,c)),s?.bind(t,L,this.xrDepthState,u,[r,i,Math.max(1,o),Math.max(1,c)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(L.uEnvironmentMap,4),t.uniform1i(L.uHasEnvironmentMap,1)):t.uniform1i(L.uHasEnvironmentMap,0),this.bindLights(L),L.uSectionEnabled&&t.uniform1i(L.uSectionEnabled,0);for(let V of Q)V.onBeforeDrawPrimitive?.(t,I,T,M,this.worldMatrices||[],this.gltf);t.uniform4fv(L.uBaseColor,T.baseColor),t.uniform1f(L.uMetallic,T.metallic),t.uniform1f(L.uRoughness,T.roughness),L.uClearcoat&&t.uniform2f(L.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(t.activeTexture(33984),t.bindTexture(3553,T.texture),t.uniform1i(L.uBaseColorTexture,0),t.uniform1i(L.uHasTexture,1)):t.uniform1i(L.uHasTexture,0),T.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,T.metallicRoughnessTexture),t.uniform1i(L.uMetallicRoughnessTexture,1),t.uniform1i(L.uHasMetallicRoughnessTexture,1)):t.uniform1i(L.uHasMetallicRoughnessTexture,0),T.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,T.normalTexture),t.uniform1i(L.uNormalTexture,2),t.uniform1i(L.uHasNormalTexture,1),t.uniform1f(L.uNormalScale,T.normalScale)):t.uniform1i(L.uHasNormalTexture,0),T.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,T.occlusionTexture),t.uniform1i(L.uOcclusionTexture,3),t.uniform1i(L.uHasOcclusionTexture,1),t.uniform1f(L.uOcclusionStrength,T.occlusionStrength)):t.uniform1i(L.uHasOcclusionTexture,0),t.bindVertexArray(T.vao),t.drawElements(4,T.indexCount,T.indexType,0)}}};if(y(!1),R){for(let w of Q)w.onBeforeTransmissivePass?.(t,this);y(!0)}for(let w of Q)w.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 o of i.buffers)t.deleteBuffer(o);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 Q)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()}};ut.registerPlugin=ln,ut.getRegisteredPlugins=hn;function dr(n){return n+3&-4}function pr(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function Pe(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],o=[],c=[],m=[],u=new Set,s=[],a=[],h=new Map,l=[];function d(p,E){let v=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),_=dr(v.byteLength),C=new Uint8Array(_);C.set(v),t.push(C);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:v.byteLength,target:E}),r+=_,g}function f(p,E,v,_,C,g,T){let x=d(p,v),I=o.length,L={bufferView:x,byteOffset:0,componentType:_,count:C,type:E};return g&&(L.min=g),T&&(L.max=T),o.push(L),I}n.traverse(p=>{(p.isLight||p.color&&p.intensity!==void 0)&&l.push({type:p.type,color:[p.color.r,p.color.g,p.color.b],intensity:p.intensity,position:[p.position.x,p.position.y,p.position.z]})});let S=[];function A(p){let E={name:p.name||""},v=p.position,_=p.quaternion,C=p.scale;if((v.x||v.y||v.z)&&(E.translation=[v.x,v.y,v.z]),(_.x||_.y||_.z||_.w!==1)&&(E.rotation=[_.x,_.y,_.z,_.w]),(C.x!==1||C.y!==1||C.z!==1)&&(E.scale=[C.x,C.y,C.z]),p.userData&&Object.keys(p.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(p.userData,(T,x)=>{if(!(T==="__proto__"||T==="prototype"||T==="constructor"))return typeof x=="function"?void 0:x})),p.userData.xr)){let T=pr(p.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:T,ANDROID_xr_scenecore:T},J().xrTraitSerializer?.gltfNode(E,p.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(p.geometry){let T=p.geometry,x=T.attributes.position;if(x&&x.count>0){let I=[1/0,1/0,1/0],L=[-1/0,-1/0,-1/0];for(let F=0;F<x.count;F++){let D=x.getX(F),O=x.getY(F),k=x.getZ(F);D<I[0]&&(I[0]=D),D>L[0]&&(L[0]=D),O<I[1]&&(I[1]=O),O>L[1]&&(L[1]=O),k<I[2]&&(I[2]=k),k>L[2]&&(L[2]=k)}let N={attributes:{POSITION:f(x.array,"VEC3",34962,5126,x.count,I,L)}};if(T.attributes.normal&&(N.attributes.NORMAL=f(T.attributes.normal.array,"VEC3",34962,5126,T.attributes.normal.count)),T.attributes.uv&&(N.attributes.TEXCOORD_0=f(T.attributes.uv.array,"VEC2",34962,5126,T.attributes.uv.count)),T.index){let F=T.index.array instanceof Uint32Array;N.indices=f(T.index.array,"SCALAR",34963,F?5125:5123,T.index.count)}if(p.material){let F=h.get(p.material);if(F===void 0){F=a.length,h.set(p.material,F);let D=p.material,O={name:D.name||"",pbrMetallicRoughness:{baseColorFactor:[D.color.r,D.color.g,D.color.b,D.opacity],metallicFactor:D.metalness,roughnessFactor:D.roughness},doubleSided:D.side===2||D.doubleSided};if(D.emissive&&(D.emissive.r>0||D.emissive.g>0||D.emissive.b>0)){let z=D.emissiveIntensity??1;O.emissiveFactor=[D.emissive.r*z,D.emissive.g*z,D.emissive.b*z]}let k={};D.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:D.clearcoat,clearcoatRoughnessFactor:D.clearcoatRoughness||0}),D.sheen>0&&(k.KHR_materials_sheen={sheenColorFactor:D.sheenColor?[D.sheenColor.r,D.sheenColor.g,D.sheenColor.b]:[1,1,1],sheenRoughnessFactor:D.sheenRoughness||0}),D.transmission>0&&(k.KHR_materials_transmission={transmissionFactor:D.transmission}),D.thickness>0&&(k.KHR_materials_volume={thicknessFactor:D.thickness,attenuationDistance:D.attenuationDistance??1/0,attenuationColor:D.attenuationColor?[D.attenuationColor.r,D.attenuationColor.g,D.attenuationColor.b]:[1,1,1]}),D.ior!==void 0&&D.ior!==1.5&&(k.KHR_materials_ior={ior:D.ior}),D.dispersion>0&&(k.KHR_materials_dispersion={dispersion:D.dispersion}),D.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:D.iridescence,iridescenceIor:D.iridescenceIOR??1.3}),Object.keys(k).length>0&&(O.extensions=k),a.push(O)}N.material=F}let U=c.length;c.push({primitives:[N],name:p.name,...E.extras?{extras:E.extras}:{}}),E.mesh=U}}let g=m.length;if(m.push(E),s.push(p),p.children.length>0){E.children=[];for(let T of p.children)E.children.push(A(T))}return g}for(let p of n.children)S.push(A(p));let R=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof R=="function"&&s.length>0){let p=e?.duration??4,E=e?.fps??15,v=Math.max(2,Math.round(p*E)+1),_=new Float32Array(v),C=s.map(U=>({px:U.position.x,py:U.position.y,pz:U.position.z,qx:U.quaternion.x,qy:U.quaternion.y,qz:U.quaternion.z,qw:U.quaternion.w,sx:U.scale.x,sy:U.scale.y,sz:U.scale.z})),g=s.map(()=>new Float32Array(v*3)),T=s.map(()=>new Float32Array(v*4)),x=s.map(()=>new Float32Array(v*3));for(let U=0;U<v;U++){let F=U/(v-1)*p;_[U]=F;try{R(F)}catch{}for(let D=0;D<s.length;D++){let O=s[D];g[D][U*3]=O.position.x,g[D][U*3+1]=O.position.y,g[D][U*3+2]=O.position.z,T[D][U*4]=O.quaternion.x,T[D][U*4+1]=O.quaternion.y,T[D][U*4+2]=O.quaternion.z,T[D][U*4+3]=O.quaternion.w,x[D][U*3]=O.scale.x,x[D][U*3+1]=O.scale.y,x[D][U*3+2]=O.scale.z}}for(let U=0;U<s.length;U++){let F=s[U],D=C[U];F.position.set(D.px,D.py,D.pz),F.quaternion.set(D.qx,D.qy,D.qz,D.qw),F.scale.set(D.sx,D.sy,D.sz)}n.updateMatrixWorld(!0);let I=null,L=()=>(I===null&&(I=f(_,"SCALAR",0,5126,v,[0],[p])),I),V=[],N=[];for(let U=0;U<s.length;U++){let F=C[U],D=!1,O=!1,k=!1;for(let z=0;z<v;z++)(Math.abs(g[U][z*3]-F.px)>1e-4||Math.abs(g[U][z*3+1]-F.py)>1e-4||Math.abs(g[U][z*3+2]-F.pz)>1e-4)&&(D=!0),(Math.abs(T[U][z*4]-F.qx)>1e-4||Math.abs(T[U][z*4+1]-F.qy)>1e-4||Math.abs(T[U][z*4+2]-F.qz)>1e-4||Math.abs(T[U][z*4+3]-F.qw)>1e-4)&&(O=!0),(Math.abs(x[U][z*3]-F.sx)>1e-4||Math.abs(x[U][z*3+1]-F.sy)>1e-4||Math.abs(x[U][z*3+2]-F.sz)>1e-4)&&(k=!0);if(D){let z=f(g[U],"VEC3",0,5126,v),B=V.length;V.push({input:L(),interpolation:"LINEAR",output:z}),N.push({sampler:B,target:{node:U,path:"translation"}})}if(O){let z=f(T[U],"VEC4",0,5126,v),B=V.length;V.push({input:L(),interpolation:"LINEAR",output:z}),N.push({sampler:B,target:{node:U,path:"rotation"}})}if(k){let z=f(x[U],"VEC3",0,5126,v),B=V.length;V.push({input:L(),interpolation:"LINEAR",output:z}),N.push({sampler:B,target:{node:U,path:"scale"}})}}N.length>0&&P.push({name:"ProceduralLoop",samplers:V,channels:N})}let y=it(m,c,n.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:S}],scene:0,nodes:m,meshes:c,materials:a,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},b=new Uint8Array(r),M=0;for(let p of t)b.set(p,M),M+=p.byteLength;return{gltf:w,bin:b.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function ht(n){return new TextEncoder().encode(n)}function Ve(n,e){let{gltf:t,bin:r}=Pe(n,e),i=JSON.stringify(t),o=ht(i),c=(4-o.byteLength%4)%4,m=o.byteLength+c,u=20+m+8+r.byteLength,s=new Uint8Array(u),a=new DataView(s.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),s.set(o,20);for(let l=0;l<c;l++)s[20+o.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),s.set(new Uint8Array(r),h+8),s}function br(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let c=o.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let p=0;p<c;p++){let E=o.getX(p),v=o.getY(p),_=o.getZ(p);m[p*3]=u[0]*E+u[4]*v+u[8]*_+u[12],m[p*3+1]=u[1]*E+u[5]*v+u[9]*_+u[13],m[p*3+2]=u[2]*E+u[6]*v+u[10]*_+u[14]}let s;if(i.attributes.normal){let p=i.attributes.normal;s=new Float32Array(c*3);let E=new Float32Array(9);ce(E,u);for(let v=0;v<c;v++){let _=p.getX(v),C=p.getY(v),g=p.getZ(v),T=E[0]*_+E[3]*C+E[6]*g,x=E[1]*_+E[4]*C+E[7]*g,I=E[2]*_+E[5]*C+E[8]*g,L=Math.hypot(T,x,I)||1;s[v*3]=T/L,s[v*3+1]=x/L,s[v*3+2]=I/L}}let a;if(i.attributes.uv){let p=i.attributes.uv;a=new Float32Array(c*2);for(let E=0;E<c;E++)a[E*2]=p.getX(E),a[E*2+1]=p.getY(E)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let p=0;p<c;p++)h[p]=p}let l="DefaultMaterial",d=[.8,.8,.8],f=.5,S=.1,A=0,R=0,P=1.5,y=1,w=[0,0,0];if(r.material){let p=r.material;l=p.name||`Material_${t.length}`,p.color&&(d=[p.color.r,p.color.g,p.color.b]),typeof p.roughness=="number"&&(f=p.roughness),typeof p.metalness=="number"&&(S=p.metalness),typeof p.clearcoat=="number"&&(A=p.clearcoat),typeof p.clearcoatRoughness=="number"&&(R=p.clearcoatRoughness),typeof p.ior=="number"&&(P=p.ior);let E=typeof p.opacity=="number"?p.opacity:1,v=typeof p.transmission=="number"?p.transmission:0;if(y=E*(1-v),p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let _=p.emissiveIntensity??1;w=[p.emissive.r*_,p.emissive.g*_,p.emissive.b*_]}}let b,M=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 M=="function"){let p=e?.duration??4,E=e?.fps??4,v=Math.max(2,Math.round(p*E)+1),_=[],C=[],g=[],T=[],x=[r.position.x,r.position.y,r.position.z],I=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],L=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let N=0;N<v;N++){let U=N/(v-1)*p;_.push(U);try{M(U)}catch{}C.push([r.position.x,r.position.y,r.position.z]),g.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),T.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-x[0])>1e-4||Math.abs(r.position.y-x[1])>1e-4||Math.abs(r.position.z-x[2])>1e-4||Math.abs(r.quaternion.x-I[0])>1e-4||Math.abs(r.quaternion.y-I[1])>1e-4||Math.abs(r.quaternion.z-I[2])>1e-4||Math.abs(r.quaternion.w-I[3])>1e-4||Math.abs(r.scale.x-L[0])>1e-4)&&(V=!0)}r.position.set(x[0],x[1],x[2]),r.quaternion.set(I[0],I[1],I[2],I[3]),r.scale.set(L[0],L[1],L[2]),V&&(b={times:_,translations:C,rotations:g,scales:T})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:s,uvs:a,materialName:l,color:d,roughness:f,metallic:S,clearcoat:A,clearcoatRoughness:R,ior:P,opacity:y,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:b})}}),t}function Sn(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],s=t.nodes||[];function a(d){let f=o[d];if(!f)throw new Error(`Accessor ${d} not found`);let S=c[f.bufferView||0],A=(S.byteOffset||0)+(f.byteOffset||0),R=S.byteLength||0,P=i.slice(A,A+R);return{acc:f,buffer:P}}let h=new Map;if(s.length>0){let d=ct(t);for(let f=0;f<d.length;f++)h.set(f,d[f])}function l(d,f,S,A){let R=u[d];if(!R)return;let P=new Float32Array(9);ce(P,f);for(let y=0;y<(R.primitives||[]).length;y++){let w=R.primitives[y],b=w.attributes?.POSITION;if(b===void 0)continue;let{acc:M,buffer:p}=a(b),E=new Float32Array(p,0,M.count*3),v=new Float32Array(E.length);for(let B=0;B<M.count;B++){let H=E[B*3],$=E[B*3+1],W=E[B*3+2];v[B*3]=f[0]*H+f[4]*$+f[8]*W+f[12],v[B*3+1]=f[1]*H+f[5]*$+f[9]*W+f[13],v[B*3+2]=f[2]*H+f[6]*$+f[10]*W+f[14]}let _,C=w.attributes?.NORMAL;if(C!==void 0){let{acc:B,buffer:H}=a(C),$=new Float32Array(H,0,B.count*3);_=new Float32Array($.length);for(let W=0;W<B.count;W++){let ae=$[W*3],be=$[W*3+1],j=$[W*3+2],ye=P[0]*ae+P[3]*be+P[6]*j,ge=P[1]*ae+P[4]*be+P[7]*j,xe=P[2]*ae+P[5]*be+P[8]*j,re=Math.hypot(ye,ge,xe)||1;_[W*3]=ye/re,_[W*3+1]=ge/re,_[W*3+2]=xe/re}}let g,T=w.attributes?.TEXCOORD_0;if(T!==void 0){let{acc:B,buffer:H}=a(T);g=new Float32Array(H,0,B.count*2)}let x;if(w.indices!==void 0){let{acc:B,buffer:H}=a(w.indices);B.componentType===5125?x=new Uint32Array(H,0,B.count):x=new Uint16Array(H,0,B.count);let $=M.count;for(let W of x)if(W>=$)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${$}).`)}else{let B=M.count;x=B>65535?new Uint32Array(B):new Uint16Array(B);for(let H=0;H<B;H++)x[H]=H}let I="DefaultMaterial",L=[.8,.8,.8],V=.5,N=.1,U=0,F=0,D=1.5,O=1,k=[0,0,0];if(w.material!==void 0&&m[w.material]){let B=m[w.material];I=B.name||`Material_${w.material}`;let H=B.pbrMetallicRoughness||{},$=1;Array.isArray(H.baseColorFactor)&&(L=[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"&&(N=H.metallicFactor),Array.isArray(B.emissiveFactor)&&B.emissiveFactor.length>=3&&(k=[B.emissiveFactor[0],B.emissiveFactor[1],B.emissiveFactor[2]]);let W=B.extensions||{};W.KHR_materials_clearcoat&&(U=W.KHR_materials_clearcoat.clearcoatFactor??0,F=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(D=W.KHR_materials_ior.ior);let ae=W.KHR_materials_transmission?.transmissionFactor??0;O=$*(1-ae)}let z=(R.primitives||[]).length>1?`${S}_p${y}`:S;e.push({name:z,positions:v,indices:x,normals:_,uvs:g,materialName:I,color:L,roughness:V,metallic:N,clearcoat:U,clearcoatRoughness:F,ior:D,opacity:O,emissiveColor:k,xrTraits:A?.xr||R.extras?.xr})}}if(s.length>0)for(let d=0;d<s.length;d++){let f=s[d];if(f.mesh!==void 0&&f.mesh<u.length){let S=h.get(d)||K(),A=f.name||u[f.mesh].name||`Node_${d}`;l(f.mesh,S,A,f.extras)}}else{let d=K();for(let f=0;f<u.length;f++){let S=u[f].name||`Mesh_${f}`;l(f,d,S,u[f].extras)}}return e}function Yt(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 wn(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 En(n){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(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 yr(n,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(n)}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 gr(n){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(n)}return Array.from(n).join(", ")}function qt(n){let e=new Map;for(let u of n){let s=Yt(u.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let s=u.timeSamples.times[u.timeSamples.times.length-1];s>t&&(t=s)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
209
+ endTimeCode = ${X(t)}
219
210
  timeCodesPerSecond = 1.0
220
211
  `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
221
212
  uniform token preliminary:planeAnchoring:alignment = "${r}"
@@ -232,61 +223,61 @@ kind = "component"
232
223
  {
233
224
  ${o}def Scope "Materials"
234
225
  {
235
- `;for(let[u,a]of e.entries()){let[s,h,l]=a.color,[p,f,T]=a.emissiveColor,M="";a.clearcoat>0&&(M+=`float inputs:clearcoat = ${G(a.clearcoat)}
236
- `,M+=`float inputs:clearcoatRoughness = ${G(a.clearcoatRoughness)}
237
- `),a.ior!==1.5&&(M+=`float inputs:ior = ${G(a.ior)}
238
- `),a.opacity<1&&(M+=`float inputs:opacity = ${G(a.opacity)}
239
- `),(p>0||f>0||T>0)&&(M+=`color3f inputs:emissiveColor = (${G(p)}, ${G(f)}, ${G(T)})
226
+ `;for(let[u,s]of e.entries()){let[a,h,l]=s.color,[d,f,S]=s.emissiveColor,A="";s.clearcoat>0&&(A+=`float inputs:clearcoat = ${X(s.clearcoat)}
227
+ `,A+=`float inputs:clearcoatRoughness = ${X(s.clearcoatRoughness)}
228
+ `),s.ior!==1.5&&(A+=`float inputs:ior = ${X(s.ior)}
229
+ `),s.opacity<1&&(A+=`float inputs:opacity = ${X(s.opacity)}
230
+ `),(d>0||f>0||S>0)&&(A+=`color3f inputs:emissiveColor = (${X(d)}, ${X(f)}, ${X(S)})
240
231
  `),c+=`def Material "${u}"
241
232
  {
242
233
  def Shader "PBRShader"
243
234
  {
244
235
  uniform token info:id = "UsdPreviewSurface"
245
- color3f inputs:diffuseColor = (${G(s)}, ${G(h)}, ${G(l)})
246
- float inputs:metallic = ${G(a.metallic)}
247
- float inputs:roughness = ${G(a.roughness)}
248
- ${M}token outputs:surface
236
+ color3f inputs:diffuseColor = (${X(a)}, ${X(h)}, ${X(l)})
237
+ float inputs:metallic = ${X(s.metallic)}
238
+ float inputs:roughness = ${X(s.roughness)}
239
+ ${A}token outputs:surface
249
240
  }
250
241
  token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
251
242
  }
252
243
  `}c+=`}
253
244
  def Scope "Meshes"
254
245
  {
255
- `;let m=new Set;for(let u=0;u<n.length;u++){let a=n[u],s=a.positions.length/3,h=1/0,l=1/0,p=1/0,f=-1/0,T=-1/0,M=-1/0;for(let b=0;b<s;b++){let w=a.positions[b*3],v=a.positions[b*3+1],_=a.positions[b*3+2];w<h&&(h=w),w>f&&(f=w),v<l&&(l=v),v>T&&(T=v),_<p&&(p=_),_>M&&(M=_)}isFinite(h)||(h=l=p=-1,f=T=M=1);let R=Math.floor(a.indices.length/3),I=Gt(a.materialName,"DefaultMaterial"),y=Gt(a.name,`Mesh_${u}`);m.has(y)&&(y=`${y}_${u}`),m.add(y);let E=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",g=a.xrTraits,A="";if(g){let b=[];g.physics&&g.physics!=="none"&&b.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let w=j().xrTraitSerializer?.usdLines(g,Tn)??[];if(!w.length)for(let v of["grab","billboard","follow","anchor","physics"]){let _=v==="follow"&&typeof g.follow=="object"?g.follow.mode??"head":g[v];_!==void 0&&w.push(`string ${v} = "${Tn(_)}"`)}w.length>0&&b.push(`customData = {
246
+ `;let m=new Set;for(let u=0;u<n.length;u++){let s=n[u],a=s.positions.length/3,h=1/0,l=1/0,d=1/0,f=-1/0,S=-1/0,A=-1/0;for(let p=0;p<a;p++){let E=s.positions[p*3],v=s.positions[p*3+1],_=s.positions[p*3+2];E<h&&(h=E),E>f&&(f=E),v<l&&(l=v),v>S&&(S=v),_<d&&(d=_),_>A&&(A=_)}isFinite(h)||(h=l=d=-1,f=S=A=1);let R=Math.floor(s.indices.length/3),P=Yt(s.materialName,"DefaultMaterial"),y=Yt(s.name,`Mesh_${u}`);m.has(y)&&(y=`${y}_${u}`),m.add(y);let w=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",b=s.xrTraits,M="";if(b){let p=[];b.physics&&b.physics!=="none"&&p.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let E=J().xrTraitSerializer?.usdLines(b,wn)??[];if(!E.length)for(let v of["grab","billboard","follow","anchor","physics"]){let _=v==="follow"&&typeof b.follow=="object"?b.follow.mode??"head":b[v];_!==void 0&&E.push(`string ${v} = "${wn(_)}"`)}E.length>0&&p.push(`customData = {
256
247
  dictionary xr = {
257
- ${w.join(`
248
+ ${E.join(`
258
249
  `)}
259
250
  }
260
- }`),b.length>0&&(A=` (
261
- ${b.join(`
251
+ }`),p.length>0&&(M=` (
252
+ ${p.join(`
262
253
  `)}
263
- )`)}if(c+=`def Mesh "${y}"${A}
254
+ )`)}if(c+=`def Mesh "${y}"${M}
264
255
  {
265
- `,g?.physics&&g.physics!=="none"){let b=g.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
266
- bool physics:kinematicEnabled = ${b}
256
+ `,b?.physics&&b.physics!=="none"){let p=b.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
257
+ bool physics:kinematicEnabled = ${p}
267
258
  bool physics:collisionEnabled = true
268
- `}if(a.timeSamples&&a.timeSamples.times.length>0){let b=a.timeSamples,w=b.times.map((C,d)=>{let S=b.translations?.[d]||[0,0,0];return`${G(C)}: (${G(S[0])}, ${G(S[1])}, ${G(S[2])})`}).join(", "),v=b.times.map((C,d)=>{let S=b.rotations?.[d]||[0,0,0,1];return`${G(C)}: (${G(S[3])}, ${G(S[0])}, ${G(S[1])}, ${G(S[2])})`}).join(", "),_=b.times.map((C,d)=>{let S=b.scales?.[d]||[1,1,1];return`${G(C)}: (${G(S[0])}, ${G(S[1])}, ${G(S[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${w} }
259
+ `}if(s.timeSamples&&s.timeSamples.times.length>0){let p=s.timeSamples,E=p.times.map((C,g)=>{let T=p.translations?.[g]||[0,0,0];return`${X(C)}: (${X(T[0])}, ${X(T[1])}, ${X(T[2])})`}).join(", "),v=p.times.map((C,g)=>{let T=p.rotations?.[g]||[0,0,0,1];return`${X(C)}: (${X(T[3])}, ${X(T[0])}, ${X(T[1])}, ${X(T[2])})`}).join(", "),_=p.times.map((C,g)=>{let T=p.scales?.[g]||[1,1,1];return`${X(C)}: (${X(T[0])}, ${X(T[1])}, ${X(T[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${E} }
269
260
  quatf xformOp:orient.timeSamples = { ${v} }
270
261
  double3 xformOp:scale.timeSamples = { ${_} }
271
262
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
272
- `}c+=`float3[] extent = [(${G(h)}, ${G(l)}, ${G(p)}), (${G(f)}, ${G(T)}, ${G(M)})]
273
- int[] faceVertexCounts = [${E}]
274
- int[] faceVertexIndices = [${mr(a.indices)}]
275
- point3f[] points = [${wn(a.positions)}]
276
- `,a.normals&&a.normals.length===a.positions.length&&(c+=`normal3f[] normals = [${wn(a.normals)}] (
263
+ `}c+=`float3[] extent = [(${X(h)}, ${X(l)}, ${X(d)}), (${X(f)}, ${X(S)}, ${X(A)})]
264
+ int[] faceVertexCounts = [${w}]
265
+ int[] faceVertexIndices = [${gr(s.indices)}]
266
+ point3f[] points = [${En(s.positions)}]
267
+ `,s.normals&&s.normals.length===s.positions.length&&(c+=`normal3f[] normals = [${En(s.normals)}] (
277
268
  interpolation = "vertex"
278
269
  )
279
- `),a.uvs&&a.uvs.length===s*2&&(c+=`texCoord2f[] primvars:st = [${hr(a.uvs,s)}] (
270
+ `),s.uvs&&s.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${yr(s.uvs,a)}] (
280
271
  interpolation = "vertex"
281
272
  )
282
- `),c+=`rel material:binding = </Root/Materials/${I}>
273
+ `),c+=`rel material:binding = </Root/Materials/${P}>
283
274
  }
284
275
  `}return c+=`}
285
276
  }
286
- `,c}function fr(n,e){if(n&&typeof n.traverse=="function"){let i=lr(n,e);return Wt(i)}let t=Oe(n),r=En(t);return Wt(r)}var at=null;function dr(n){{let t=globalThis.__three_live_native_crc32__;if(typeof t=="function")return t(n)}if(!at){at=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;at[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=at[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Mn(n){{let s=globalThis.__three_live_native_build_usdz_zip__;if(typeof s=="function")return s(n)}let e=[],t=0,r=[];for(let s of n){let h=ct(s.filename),l=dr(s.data),p=s.data.length,f=30+h.length,T=t+f,M=0,R=T%64;R!==0&&(M=64-R);let I=new Uint8Array(f+M),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,p,!0),y.setUint32(22,p,!0),y.setUint16(26,h.length,!0),y.setUint16(28,M,!0),I.set(h,30),M>0&&I.fill(0,30+h.length),e.push({offset:t,size:p,crc:l,filenameBytes:h,entry:s}),r.push(I),r.push(s.data),t+=I.length+s.data.length}let i=t;for(let s of e){let h=new Uint8Array(46+s.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,s.crc,!0),l.setUint32(20,s.size,!0),l.setUint32(24,s.size,!0),l.setUint16(28,s.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,s.offset,!0),h.set(s.filenameBytes,46),r.push(h),t+=h.length}let o=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,o,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),a=0;for(let s of r)u.set(s,a),a+=s.length;return u}function Ie(n){let e=fr(n),t=ct(e);return Mn([{filename:"model.usda",data:t}])}function ut(n){let e=Oe(n),t=En(e),r=Wt(t),i=ct(r);return Mn([{filename:"model.usda",data:i}])}function $t(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Ie(n):ut(n)}function Q(n,e,t,r){let i=typeof n=="number"&&Number.isFinite(n)?n:r;return Math.max(e,Math.min(t,i))}function qt(n){return Array.isArray(n)&&n.length>=3&&Number.isFinite(n[0])&&Number.isFinite(n[1])&&Number.isFinite(n[2])}function le(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function Kt(n,e=256){return typeof n=="string"&&n.length>0?n.slice(0,e):void 0}function pr(n){let e=le(n);if(!e||e.lazy===!1)return null;let t=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=t!=="head";return{mode:t,lazy:!0,distance:Q(e.distance,.1,10,r?.15:1),deadzoneDeg:Q(e.deadzoneDeg,0,90,r?0:15),stiffness:Q(e.stiffness,.5,40,6),height:Q(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function br(n){let e=le(n);if(!e)return null;let t=e.target;return{target:qt(t)?[t[0],t[1],t[2]]:typeof t=="string"&&t.length>0&&t.length<=256?t:[0,0,0],radius:Q(e.radius,.01,50,.5),speed:Q(e.speed,-20,20,.5),height:Q(e.height,-10,10,0),phase:Q(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function yr(n){if(!n)return null;let e=le(n)??{},t=Q(e.minScale,.001,1e3,.1),r=Q(e.maxScale,t,1e3,Math.max(t,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:t,maxScale:r}}var gr=2e3,xr={rain:600,snow:400,sparks:300,confetti:300};function vr(n){let e=le(n);if(!e)return null;let t=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=c=>Q(c,.05,50,2),o=qt(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:t,count:Math.round(Q(e.count,1,gr,xr[t])),area:o,speed:Q(e.speed,.05,10,1)}}var Tr=4e3;function wr(n){if(!n)return null;let e=le(n)??{};return{prompt:Kt(e.prompt,Tr)??"What is this?",holdMs:Q(e.holdMs,100,5e3,600)}}function Er(n){if(!n)return null;let e=le(n)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function Yt(n){let e=Kt(n,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Mr(n){if(typeof n=="string"){let r=Yt(n);return r?{src:r,refDistance:1,loop:!1}:null}let e=le(n),t=Yt(e?.src);return!e||!t?null:{src:t,refDistance:Q(e.refDistance,.01,1e3,1),loop:e.loop===!0}}var Rr=new Set(["horizontal","vertical","floor","wall","table"]),Sr=new Set(["capsule","cylindrical","spherical"]);function lt(n){let e=le(n);if(!e)return null;let t=Array.isArray(e.traits)?e.traits:[],r=y=>t.includes(y),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let c=e.scale??e.scalable;if(c||r("scale")){let y=le(c)??{},E=Q(y.min,.001,1e3,.05);i.scale={min:E,max:Q(y.max,E,1e3,Math.max(E,5))},i.scalable=!0}let m=e.billboard;typeof m=="string"&&Sr.has(m)?i.billboard=m:(m===!0||r("billboard"))&&(i.billboard="capsule");let u=e.follow,a=typeof u=="string"?u:le(u)?.mode;if(typeof u=="string"?u:le(u)?.lazy===!1)i.follow=a==="hand-left"||a==="hand-right"?a:"head";else{let y=pr(u);y&&(i.follow=y)}let s=e.anchor;typeof s=="string"&&Rr.has(s)&&(i.anchor=s),(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let h=br(e.orbit);h&&(i.orbit=h);let l=yr(e.handles);l&&(i.handles=l);let p=vr(e.particles);p&&(i.particles=p);let f=wr(e.holdToAsk);f&&(i.holdToAsk=f);let T=Er(e.worldUnderstanding);T&&(i.worldUnderstanding=T);let M=Yt(e.splatUrl);M&&(i.splatUrl=M);let R=Kt(e.spatialSlot);R&&(i.spatialSlot=R);let I=Mr(e.audio);return I&&(i.audio=I),e.pointerEvents==="none"&&(i.pointerEvents="none"),Object.keys(i).length>0?i:null}function jt(n){let e={};return n.grab&&(e.interactable={mode:n.grab},e.movable={systemMovable:!0,scaleInZ:!!n.scale,minScale:n.scale?.min??.05,maxScale:n.scale?.max??5}),n.billboard&&(e.billboard={mode:n.billboard}),typeof n.follow=="string"?e.follow={target:n.follow,lazy:!1}:n.follow&&(e.follow={target:n.follow.mode,lazy:!0,distance:n.follow.distance,deadzoneDeg:n.follow.deadzoneDeg,stiffness:n.follow.stiffness,height:n.follow.height,faceUser:n.follow.faceUser}),n.anchor&&(e.anchor={planeType:n.anchor==="vertical"||n.anchor==="wall"?"VERTICAL":"HORIZONTAL",semanticType:n.anchor.toUpperCase()}),n.physics&&(e.rigidbody={type:n.physics}),n.orbit&&(e.orbit={...n.orbit}),n.handles&&(e.resizable={...n.handles}),n.particles&&(e.particles={...n.particles}),n.holdToAsk&&(e.holdToAsk={...n.holdToAsk}),n.worldUnderstanding&&(e.worldUnderstanding={...n.worldUnderstanding}),n.splatUrl&&(e.splat={url:n.splatUrl}),n.spatialSlot&&(e.spatialPanel={slot:n.spatialSlot}),n.audio&&(e.spatialAudio={...n.audio}),e}function Ar(n){let e={},t=(r,i)=>{for(let[o,c]of Object.entries(i)){let m=r+o[0].toUpperCase()+o.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[m]=c:qt(c)&&(e[m]=[c[0],c[1],c[2]])}};return n.grab&&(e.grab=n.grab),n.scale&&t("scale",n.scale),n.billboard&&(e.billboard=n.billboard),typeof n.follow=="string"?e.follow=n.follow:n.follow&&(e.follow=n.follow.mode,t("follow",{...n.follow,mode:void 0})),n.anchor&&(e.anchor=n.anchor),n.physics&&(e.physics=n.physics),n.orbit&&t("orbit",n.orbit),n.handles&&(e.handles=!0,t("handles",n.handles)),n.particles&&t("particles",n.particles),n.holdToAsk&&(e.holdToAsk=!0,t("holdToAsk",n.holdToAsk)),n.worldUnderstanding&&t("worldUnderstanding",n.worldUnderstanding),n.splatUrl&&(e.splatUrl=n.splatUrl),n.spatialSlot&&(e.spatialSlot=n.spatialSlot),n.audio&&t("audio",n.audio),n.pointerEvents&&(e.pointerEvents=n.pointerEvents),e}function _r(n,e){let t=lt(e);t&&(n.extras={...n.extras,xr:{...n.extras?.xr,...t}},n.extensions={...n.extensions,MOZ_hubs_components:Zt(t),ANDROID_xr_scenecore:jt(t)})}function Zt(n){let e={};return n.grab&&(e.grabbable={cursor:!0,hand:!0}),n.billboard&&(e.billboard={onlyY:n.billboard!=="spherical"}),e}function Dr(n,e){let t=lt(n),r=[];if(!t)return r;for(let[i,o]of Object.entries(Ar(t)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function Rn(){try{Object.defineProperty(j(),"xrTraitSerializer",{value:Object.freeze({gltfNode:_r,usdLines:Dr}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var ht=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},q=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,o=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-o*m,this.y=o*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,o=e.elements,c=1/(o[3]*t+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*t+o[4]*r+o[8]*i+o[12])*c,this.y=(o[1]*t+o[5]*r+o[9]*i+o[13])*c,this.z=(o[2]*t+o[6]*r+o[10]*i+o[14])*c,this}},mt=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}},He=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}},Xe=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,o=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(o/2),a=Math.sin(r/2),s=Math.sin(i/2),h=Math.sin(o/2);return this._x=a*m*u+c*s*h,this._y=c*s*u-a*m*h,this._z=c*m*h+a*s*u,this._w=c*m*u-a*s*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,o=e.z,c=e.w,m=t.x,u=t.y,a=t.z,s=t.w;return this._x=r*s+c*m+i*a-o*u,this._y=i*s+c*u+o*m-r*a,this._z=o*s+c*a+r*u-i*m,this._w=c*s-r*m-i*u-o*a,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},ye=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 it(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 re(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return rt(this.elements,[e.x,e.y,e.z],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let t=new q(0,0,0),r=new q(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},ft=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 ae(this.elements,e.elements),this}},he=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)}},Ln={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)},X=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 o=e*this.itemSize;return this.array[o]=t,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},dt=class extends X{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},pt=class extends X{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},bt=class extends X{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ce=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 X)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 X(r,1)}else e&&e.buffer&&(this.index=new X(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new q,o=new q,c=new q,m=new q,u=new q;if(this.index){let a=this.index.array;for(let s=0;s<a.length;s+=3){let h=a[s],l=a[s+1],p=a[s+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),o.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(p),e.getY(p),e.getZ(p)),m.subVectors(c,o),u.subVectors(i,o),m.cross(u).normalize();for(let f of[h,l,p])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let a=0;a<t;a+=3){i.set(e.getX(a),e.getY(a),e.getZ(a)),o.set(e.getX(a+1),e.getY(a+1),e.getZ(a+1)),c.set(e.getX(a+2),e.getY(a+2),e.getZ(a+2)),m.subVectors(c,o),u.subVectors(i,o),m.cross(u).normalize();for(let s=0;s<3;s++)r[(a+s)*3]=m.x,r[(a+s)*3+1]=m.y,r[(a+s)*3+2]=m.z}for(let a=0;a<t;a++){let s=r[a*3],h=r[a*3+1],l=r[a*3+2],p=Math.hypot(s,h,l)||1;r[a*3]=s/p,r[a*3+1]=h/p,r[a*3+2]=l/p}return this.setAttribute("normal",new X(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new X(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new X(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new X(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},Ge=class extends ce{constructor(e=1,t=1,r=1){super();{let h=globalThis.__three_live_native_box__;if(typeof h=="function"){let l=h(e,t,r);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let i=e/2,o=t/2,c=r/2,m=[-i,-o,c,i,-o,c,i,o,c,-i,o,c,i,-o,-c,-i,-o,-c,-i,o,-c,i,o,-c,-i,o,c,i,o,c,i,o,-c,-i,o,-c,-i,-o,-c,i,-o,-c,i,-o,c,-i,-o,c,i,-o,c,i,-o,-c,i,o,-c,i,o,c,-i,-o,-c,-i,-o,c,-i,o,c,-i,o,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],a=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],s=[];for(let h=0;h<6;h++){let l=h*4;s.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new X(new Float32Array(m),3)),this.setAttribute("normal",new X(new Float32Array(u),3)),this.setAttribute("uv",new X(new Float32Array(a),2)),this.setIndex(s)}},yt=class extends ce{constructor(e=1,t=1){super();let r=e/2,i=t/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new X(new Float32Array(o),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},We=class extends ce{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));{let a=globalThis.__three_live_native_sphere__;if(typeof a=="function"){let s=a(e,t,r);this.setAttribute("position",new X(s.positions,3)),this.setAttribute("normal",new X(s.normals,3)),this.setAttribute("uv",new X(s.uvs,2)),this.setIndex(s.indices);return}}let i=[],o=[],c=[],m=[],u=[];for(let a=0;a<=r;a++){let s=[],h=a/r;for(let l=0;l<=t;l++){let p=l/t,f=p*Math.PI*2,T=h*Math.PI,M=-e*Math.cos(f)*Math.sin(T),R=e*Math.cos(T),I=e*Math.sin(f)*Math.sin(T);i.push(M,R,I);let y=Math.hypot(M,R,I)||1;o.push(M/y,R/y,I/y),c.push(p,1-h),s.push(i.length/3-1)}u.push(s)}for(let a=0;a<r;a++)for(let s=0;s<t;s++){let h=u[a][s+1],l=u[a][s],p=u[a+1][s],f=u[a+1][s+1];a!==0&&m.push(h,l,f),a!==r-1&&m.push(l,p,f)}this.setAttribute("position",new X(new Float32Array(i),3)),this.setAttribute("normal",new X(new Float32Array(o),3)),this.setAttribute("uv",new X(new Float32Array(c),2)),this.setIndex(m)}},Ee=class extends ce{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let s=globalThis.__three_live_native_cylinder__;if(typeof s=="function"){let h=s(e,t,r,i);this.setAttribute("position",new X(h.positions,3)),this.setAttribute("normal",new X(h.normals,3)),this.setAttribute("uv",new X(h.uvs,2)),this.setIndex(h.indices);return}}let o=[],c=[],m=[],u=[],a=r/2;for(let s=0;s<=1;s++){let h=s,l=s===0?e:t,p=s===0?a:-a;for(let f=0;f<=i;f++){let T=f/i,M=T*Math.PI*2,R=Math.sin(M),I=Math.cos(M);o.push(l*R,p,l*I),c.push(R,0,I),m.push(T,1-h)}}for(let s=0;s<i;s++){let h=s,l=s+i+1,p=s+i+2,f=s+1;u.push(h,l,f,l,p,f)}if(e>0){let s=o.length/3;o.push(0,a,0),c.push(0,1,0),m.push(.5,.5);let h=o.length/3;for(let l=0;l<=i;l++){let p=l/i*Math.PI*2,f=Math.sin(p),T=Math.cos(p);o.push(e*f,a,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(s,h+l,h+l+1)}if(t>0){let s=o.length/3;o.push(0,-a,0),c.push(0,-1,0),m.push(.5,.5);let h=o.length/3;for(let l=0;l<=i;l++){let p=l/i*Math.PI*2,f=Math.sin(p),T=Math.cos(p);o.push(t*f,-a,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(s,h+l+1,h+l)}this.setAttribute("position",new X(new Float32Array(o),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},gt=class extends Ee{constructor(e=1,t=1,r=16){super(0,e,t,r)}},xt=class extends ce{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 o=[],c=[],m=[],u=[];for(let a=0;a<=r;a++){let s=a/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,p=(e+t*Math.cos(s))*Math.cos(l),f=(e+t*Math.cos(s))*Math.sin(l),T=t*Math.sin(s);o.push(p,f,T);let M=e*Math.cos(l),R=e*Math.sin(l),I=p-M,y=f-R,E=T,g=Math.hypot(I,y,E)||1;c.push(I/g,y/g,E/g),m.push(h/i,a/r)}}for(let a=1;a<=r;a++)for(let s=1;s<=i;s++){let h=(i+1)*a+s-1,l=(i+1)*(a-1)+s-1,p=(i+1)*(a-1)+s,f=(i+1)*a+s;u.push(h,l,f,l,p,f)}this.setAttribute("position",new X(new Float32Array(o),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},vt=class extends ce{constructor(e=1,t=.4,r=64,i=8,o=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let y=globalThis.__three_live_native_torus_knot__;if(typeof y=="function"){let E=y(e,t,r,i,o,c);this.setAttribute("position",new X(E.positions,3)),this.setAttribute("normal",new X(E.normals,3)),this.setAttribute("uv",new X(E.uvs,2)),this.setIndex(E.indices);return}}let m=[],u=[],a=[],s=[],h=new q,l=new q,p=new q,f=new q,T=new q;function M(y,E){let g=Math.cos(E),A=Math.sin(E),b=c/o*E,w=e*(2+Math.cos(b))*.5;y.set(w*g,w*A,e*Math.sin(b)*.5)}let R=[];for(let y=0;y<=i;++y){let E=y/i*Math.PI*2;R.push(-t*Math.cos(E),t*Math.sin(E),y/i)}for(let y=0;y<=r;++y){let E=y/r,g=E*o*Math.PI*2;M(h,g),M(l,g+.01),p.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(p,f).normalize(),f.crossVectors(T,p).normalize();for(let A=0;A<=i;++A){let b=A*3,w=R[b],v=R[b+1],_=R[b+2],C=w*f.x+v*T.x,d=w*f.y+v*T.y,S=w*f.z+v*T.z;m.push(h.x+C,h.y+d,h.z+S);let x=Math.hypot(C,d,S)||1;u.push(C/x,d/x,S/x),a.push(E,_)}}let I=i+1;for(let y=1;y<=r;y++){let E=I*(y-1),g=E+I;for(let A=1;A<=i;A++){let b=E+(A-1),w=g+(A-1),v=g+A,_=E+A;s.push(b,w,_,w,v,_)}}this.setAttribute("position",new X(new Float32Array(m),3)),this.setAttribute("normal",new X(new Float32Array(u),3)),this.setAttribute("uv",new X(new Float32Array(a),2)),this.setIndex(s)}},$e=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Tt=class{load(e,t){let r=new $e(e);return t?.(r),r}};function te(n,e){return n!==void 0?Number(n):e}function Jt(n,e){return n!==void 0?!!n:e}var me=class{constructor(e={}){this.name=e.name||"",this.color=new he(e.color!==void 0?e.color:16777215),this.emissive=new he(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=te(e.emissiveIntensity,1),this.roughness=te(e.roughness,.5),this.metalness=te(e.metalness,.1),this.opacity=te(e.opacity,1),this.transparent=Jt(e.transparent,!1),this.wireframe=Jt(e.wireframe,!1),this.side=te(e.side,2),this.doubleSided=Jt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=te(e.clearcoat,0),this.clearcoatRoughness=te(e.clearcoatRoughness,0),this.sheen=te(e.sheen,0),this.sheenColor=new he(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=te(e.sheenRoughness,0),this.transmission=te(e.transmission,0),this.thickness=te(e.thickness,0),this.attenuationColor=new he(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=te(e.attenuationDistance,1/0),this.ior=te(e.ior,1.5),this.dispersion=te(e.dispersion,0),this.iridescence=te(e.iridescence,0),this.iridescenceIOR=te(e.iridescenceIOR,1.3)}dispose(){}},Se=class extends me{},wt=class extends me{},Et=class extends me{},Mt=class extends me{},Rt=class extends me{},ie=class n{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new q,this.rotation=new He,this.quaternion=new Xe,this.scale=new q(1,1,1),this.matrix=new ye,this.matrixWorld=new ye,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,t=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(t,r,i)})}add(...e){for(let t of e)t&&t instanceof n&&(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t));return this}remove(...e){for(let t of e){let r=this.children.indexOf(t);r!==-1&&(t.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let t of this.children)t.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let t of this.children)t.updateMatrixWorld(e)}lookAt(e,t,r){let i=typeof e=="object"?e:new q(e,t,r);this.updateMatrixWorld(!0);let o=new ye;o.lookAt(this.position,i,new q(0,1,0));let c=o.elements,m=c[0],u=c[4],a=c[8],s=c[1],h=c[5],l=c[9],p=c[2],f=c[6],T=c[10],M=m+h+T;if(M>0){let R=.5/Math.sqrt(M+1);this.quaternion.set((f-l)*R,(a-p)*R,(s-u)*R,.25/R)}}},St=class extends ie{},Pe=class extends ie{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof ce?t:t?(oe("unsupported geometry","BoxGeometry"),new Ge(.5,.5,.5)):new ce,this.material=i instanceof me?i:i?(oe("unsupported material","MeshStandardMaterial"),new Se({color:13421772})):new Se}},Me=class extends ie{constructor(e=16777215,t=1){super(),this.color=new he(e),this.intensity=Number(t),this.type="directional"}},Ye=class extends Me{constructor(e,t){super(e,t),this.type="ambient"}},At=class extends Me{constructor(t,r){super(t,r);this.target=new ie;this.type="directional"}},qe=class extends Me{constructor(t,r,i=0,o=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},Ke=class extends ie{},Ue=class extends Ke{constructor(t=45,r=1,i=.1,o=1e3){super();this.target=new q(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Ae=class extends ie{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return pe.validate(this),Ce(this)}toGLB(){return pe.validate(this),Be(this)}toUSDZ(){return pe.validate(this),Ie(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Pe){let o=new Float32Array(i.matrixWorld.elements);t.set(r,o),i.name&&t.set(i.name,o),r++}}),t}},Qt=Ce,en=Be,Pn=Ie;var pe=class{static validate(e){let t=0,r=0,i=0,o=new Set,c=(u,a,s)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${a}). Found: ${s}`)},m=(u,a)=>{if(!Number.isFinite(a))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(a)}), which cannot be bounds-checked.`);return a};e.traverse(u=>{if(u instanceof Pe){i++,i>1e3&&c("MESHES",1e3,i);let a=u.geometry;if(a){let s=0;if(a.attributes.position&&(s=m("vertex",a.attributes.position.count),t+=s,t>1e5&&c("VERTICES",1e5,t)),a.index){let h=m("index",a.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=a.index.array;if(l&&s>0){let p=Math.min(h,l.length);for(let f=0;f<p;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=s)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${s}).`)}}}}if(u.material){let s=u.material;s.map&&o.add(s.map),s.normalMap&&o.add(s.normalMap),s.roughnessMap&&o.add(s.roughnessMap)}}}),o.size>16&&c("TEXTURES",16,o.size);for(let u of o){let a=u,s=a.image,h=Number(s?.width??a.width??0)||0,l=Number(s?.height??a.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},_t=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 he(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){pe.validate(e);let i=(o,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(o,c):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),c={};for(let[m,u]of o.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let o=Qt(e),c=en(e),m=(o.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights: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 Sn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Dt=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=Sn(),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=Sn();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Cr(){}var Le=new Proxy(Cr,{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:Le},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Le,construct:()=>Le}),An=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function Fe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Re(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Fe());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var _n,ze;function Un(n){if(!Re(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(ze===void 0||_n!==t){_n=t;try{ze=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Re(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{ze=null}}return ze?ze.createScriptURL(n):n}function Ir(n){j().sandboxEngineSrc=n}function tn(){let n=j().sandboxEngineSrc;if(n)return n;if(An)return An;try{if(typeof document>"u")return null;let e=Fe(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Re(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Lr(){let n=tn();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Re(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Fe()).href}function Pr(n){j().sandboxIframeSrc=n}function Fn(){let n=j().sandboxIframeSrc;if(n)return n;let e=tn();if(!e||!Re(e))return null;let t=new URL(e,Fe());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Ur(){let n=Fn();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(!Re(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Fe()).href}function Fr(n){j().allowClientScripts=n}function Nn(){return!!j().allowClientScripts}function Nr(n){if(!Re(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Fe()).href}var kr=["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 Or(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,o=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(g){m({type:"ERROR",nonce:t,message:String(g)})}let a=typeof e.importScripts=="function"?e.importScripts.bind(e):null,s=i,h=null;try{let g=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let A={createScriptURL:function(w){if(w!==r&&(!i||w!==i))throw new TypeError("Disallowed worker importScripts URL");return w}};o&&(A.createScript=function(w){return String(w)});let b=e.trustedTypes.createPolicy("three-live#worker-boot",A);g=b.createScriptURL(r),i&&(s=b.createScriptURL(i)),o&&typeof b.createScript=="function"&&(h=b.createScript.bind(b))}catch{}a(g)}catch(g){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: '+(g&&g.message||g));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 g=0;g<c.length;g++){let A=c[g],b=e;for(;b&&b!==Object.prototype;){if(b!==e)try{delete b[A]}catch{}try{Object.defineProperty(b,A,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}}let p=Object.freeze({now:function(){return Date.now()}}),f=e;for(;f&&f!==Object.prototype;){if(f!==e)try{delete f.performance}catch{}try{Object.defineProperty(f,"performance",{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],M=!1;function R(g,A){if(g.type==="3D_MODEL_READY"){if(M)return;M=!0}g.nonce=t,A&&A.length?m(g,A):m(g)}let I=function(g,A){if(!g||T.indexOf(g.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");R(g,A)},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 E=!1;e.onmessage=function(g){let A=g&&g.data;if(!(!A||A.nonce!==t)&&!(A.type!=="EXECUTE"&&A.type!=="EXECUTE_URL")&&!E){E=!0;try{let b=new l.Scene,w=new l.PerspectiveCamera(60,1,.1,1e3),v=new l.WebGLRenderer({isSandboxed:!0});if(A.type==="EXECUTE_URL"){if(!i||A.scriptUrl!==i||typeof a!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=s||i,C=a;if(a=null,s=null,e.THREE=l,e.scene=b,e.camera=w,e.renderer=v,C(_),typeof e.__THREE_LIVE_SCENE__=="function"){let d=e.__THREE_LIVE_SCENE__(l,b,w,v);d&&typeof d.toGLB=="function"&&(b=d)}else e.scene&&typeof e.scene.toGLB=="function"&&(b=e.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
277
+ `,c}function xr(n,e){if(n&&typeof n.traverse=="function"){let i=br(n,e);return qt(i)}let t=ze(n),r=Sn(t);return qt(r)}var lt=null;function vr(n){{let t=globalThis.__three_live_native_crc32__;if(typeof t=="function")return t(n)}if(!lt){lt=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;lt[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=lt[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Mn(n){{let a=globalThis.__three_live_native_build_usdz_zip__;if(typeof a=="function")return a(n)}let e=[],t=0,r=[];for(let a of n){let h=ht(a.filename),l=vr(a.data),d=a.data.length,f=30+h.length,S=t+f,A=0,R=S%64;R!==0&&(A=64-R);let P=new Uint8Array(f+A),y=new DataView(P.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,l,!0),y.setUint32(18,d,!0),y.setUint32(22,d,!0),y.setUint16(26,h.length,!0),y.setUint16(28,A,!0),P.set(h,30),A>0&&P.fill(0,30+h.length),e.push({offset:t,size:d,crc:l,filenameBytes:h,entry:a}),r.push(P),r.push(a.data),t+=P.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 o=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,o,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),s=0;for(let a of r)u.set(a,s),s+=a.length;return u}function Ie(n){let e=xr(n),t=ht(e);return Mn([{filename:"model.usda",data:t}])}function mt(n){let e=ze(n),t=Sn(e),r=qt(t),i=ht(r);return Mn([{filename:"model.usda",data:i}])}function jt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Ie(n):mt(n)}function q(n,e,t,r){let i=typeof n=="number"&&Number.isFinite(n)?n:r;return Math.max(e,Math.min(t,i))}function He(n){return Array.isArray(n)&&n.length>=3&&Number.isFinite(n[0])&&Number.isFinite(n[1])&&Number.isFinite(n[2])}function ee(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function Re(n,e=256){return typeof n=="string"&&n.length>0?n.slice(0,e):void 0}function Tr(n){let e=ee(n);if(!e||e.lazy===!1)return null;let t=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=t!=="head";return{mode:t,lazy:!0,distance:q(e.distance,.1,10,r?.15:1),deadzoneDeg:q(e.deadzoneDeg,0,90,r?0:15),stiffness:q(e.stiffness,.5,40,6),height:q(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function wr(n){let e=ee(n);if(!e)return null;let t=e.target;return{target:He(t)?[t[0],t[1],t[2]]:typeof t=="string"&&t.length>0&&t.length<=256?t:[0,0,0],radius:q(e.radius,.01,50,.5),speed:q(e.speed,-20,20,.5),height:q(e.height,-10,10,0),phase:q(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Er(n){if(!n)return null;let e=ee(n)??{},t=q(e.minScale,.001,1e3,.1),r=q(e.maxScale,t,1e3,Math.max(t,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:t,maxScale:r}}var Sr=2e3,Mr={rain:600,snow:400,sparks:300,confetti:300};function Rr(n){let e=ee(n);if(!e)return null;let t=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=c=>q(c,.05,50,2),o=He(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:t,count:Math.round(q(e.count,1,Sr,Mr[t])),area:o,speed:q(e.speed,.05,10,1)}}var Ar=4e3;function _r(n){if(!n)return null;let e=ee(n)??{};return{prompt:Re(e.prompt,Ar)??"What is this?",holdMs:q(e.holdMs,100,5e3,600)}}function Dr(n){if(!n)return null;let e=ee(n)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function Zt(n){let e=Re(n,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Cr(n){if(typeof n=="string"){let r=Zt(n);return r?{src:r,refDistance:1,loop:!1}:null}let e=ee(n),t=Zt(e?.src);return!e||!t?null:{src:t,refDistance:q(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function _n(n,e){let t=Re(n,16)?.trim();if(!t)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t);return r?`#${r[1].toLowerCase()}`:e}var Lr=new Set(["m","cm","mm","in","ft-in","auto"]),Rn=["x","y","z"];function Pr(n){if(!n)return null;let e=ee(n);if(e&&e.enabled===!1)return null;let t=e?.unit,r=typeof t=="string"&&Lr.has(t)?t:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(m=>typeof m=="string"):typeof i=="string"?i.split(""):[]),c=Rn.filter(m=>o.has(m));return{enabled:!0,unit:r,axes:c.length>0?c:[...Rn],color:_n(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var Ir=new Set(["none","floor","wall","ceiling","any"]);function Ur(n){if(!n)return null;let e=ee(n)??{},t=e.grid,r=c=>q(c,.001,100,.1),i=He(t)?[r(t[0]),r(t[1]),r(t[2])]:typeof t=="number"&&Number.isFinite(t)&&t>0?[r(t),r(t),r(t)]:null,o=e.surface;return{grid:i,angleDeg:q(e.angleDeg,0,180,0),surface:typeof o=="string"&&Ir.has(o)?o:"none",socketTag:Re(e.socketTag,128)??"",radius:q(e.radius,.01,2,.15)}}function Fr(n){if(typeof n=="string"){let r=Re(n,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=ee(n),t=Re(e?.tag,128);return!e||!t?null:{tag:t,radius:q(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:_n(e.highlightColor,"#22c55e")}}function Nr(n){if(!n)return null;let e=ee(n);if(e&&e.enabled===!1)return null;let t=e?.action;return{enabled:!0,dwellMs:Math.round(q(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:t==="ask"?"ask":"select"}}function kr(n){if(!n)return null;let e=ee(n);if(e&&e.enabled===!1)return null;let t=e?.direction,r=null;if(He(t)){let i=Math.hypot(t[0],t[1],t[2]);i>1e-8&&(r=[t[0]/i,t[1]/i,t[2]/i])}return{enabled:!0,direction:r,distance:q(e?.distance,0,10,.35),layer:Math.round(q(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var Or=new Set(["__proto__","constructor","prototype"]);function Br(n){if(typeof n!="string")return;let e=n.trim().slice(0,128);if(!(!e||Or.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function Kt(n){let e=ee(n);if(!e||e.persist===!1)return null;let t=Br(e.id);return e.persist!==!0&&!t?null:t?{id:t,persist:!0}:{persist:!0}}function zr(n){return n===!0||n==="walkable"?"walkable":n===!1||n==="blocked"?"blocked":null}var An=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),Vr=new Set(["capsule","cylindrical","spherical"]);function ft(n){let e=ee(n);if(!e)return null;let t=Array.isArray(e.traits)?e.traits:[],r=v=>t.includes(v),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let c=e.scale??e.scalable;if(c||r("scale")){let v=ee(c)??{},_=q(v.min,.001,1e3,.05);i.scale={min:_,max:q(v.max,_,1e3,Math.max(_,5))},i.scalable=!0}let m=e.billboard;typeof m=="string"&&Vr.has(m)?i.billboard=m:(m===!0||r("billboard"))&&(i.billboard="capsule");let u=e.follow,s=typeof u=="string"?u:ee(u)?.mode;if(typeof u=="string"?u:ee(u)?.lazy===!1)i.follow=s==="hand-left"||s==="hand-right"?s:"head";else{let v=Tr(u);v&&(i.follow=v)}let a=e.anchor;if(typeof a=="string"&&An.has(a))i.anchor=a;else{let _=ee(a)?.target;typeof _=="string"&&An.has(_)&&(i.anchor=_);let C=Kt(a)??Kt(e.anchorPersist);C&&(i.anchorPersist=C)}if(!i.anchorPersist){let v=Kt(e.anchorPersist);v&&(i.anchorPersist=v)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let h=wr(e.orbit);h&&(i.orbit=h);let l=Er(e.handles);l&&(i.handles=l);let d=Rr(e.particles);d&&(i.particles=d);let f=_r(e.holdToAsk);f&&(i.holdToAsk=f);let S=Dr(e.worldUnderstanding);S&&(i.worldUnderstanding=S);let A=Zt(e.splatUrl);A&&(i.splatUrl=A);let R=Re(e.spatialSlot);R&&(i.spatialSlot=R);let P=Cr(e.audio);P&&(i.audio=P);let y=Pr(e.dimensions);y&&(i.dimensions=y);let w=Ur(e.snapTo);w&&(i.snapTo=w);let b=Fr(e.snapSocket);b&&(i.snapSocket=b);let M=Nr(e.gaze);M&&(i.gaze=M);let p=kr(e.explode);p&&(i.explode=p);let E=zr(e.navigable);return E&&(i.navigable=E),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none"),Object.keys(i).length>0?i:null}function Jt(n){let e={};if(n.grab&&(e.interactable={mode:n.grab},e.movable={systemMovable:!0,scaleInZ:!!n.scale,minScale:n.scale?.min??.05,maxScale:n.scale?.max??5}),n.billboard&&(e.billboard={mode:n.billboard}),typeof n.follow=="string"?e.follow={target:n.follow,lazy:!1}:n.follow&&(e.follow={target:n.follow.mode,lazy:!0,distance:n.follow.distance,deadzoneDeg:n.follow.deadzoneDeg,stiffness:n.follow.stiffness,height:n.follow.height,faceUser:n.follow.faceUser}),n.anchor||n.anchorPersist){let t={};n.anchor&&(t.planeType=n.anchor==="vertical"||n.anchor==="wall"?"VERTICAL":"HORIZONTAL",t.semanticType=n.anchor.toUpperCase()),n.anchorPersist&&(t.persist=n.anchorPersist.persist,n.anchorPersist.id&&(t.id=n.anchorPersist.id)),e.anchor=t}return n.physics&&(e.rigidbody={type:n.physics}),n.orbit&&(e.orbit={...n.orbit}),n.handles&&(e.resizable={...n.handles}),n.particles&&(e.particles={...n.particles}),n.holdToAsk&&(e.holdToAsk={...n.holdToAsk}),n.worldUnderstanding&&(e.worldUnderstanding={...n.worldUnderstanding}),n.splatUrl&&(e.splat={url:n.splatUrl}),n.spatialSlot&&(e.spatialPanel={slot:n.spatialSlot}),n.audio&&(e.spatialAudio={...n.audio}),n.dimensions&&(e.dimensions={...n.dimensions,axes:[...n.dimensions.axes]}),n.snapTo&&(e.snapTo={...n.snapTo,grid:n.snapTo.grid?[...n.snapTo.grid]:null}),n.snapSocket&&(e.snapSocket={...n.snapSocket}),n.gaze&&(e.gaze={...n.gaze}),n.explode&&(e.explode={...n.explode,direction:n.explode.direction?[...n.explode.direction]:null}),n.navigable&&(e.navigable={mode:n.navigable}),typeof n.sync=="boolean"&&(e.sync={enabled:n.sync}),e}function Hr(n){let e={},t=(r,i)=>{for(let[o,c]of Object.entries(i)){let m=r+o[0].toUpperCase()+o.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[m]=c:He(c)&&(e[m]=[c[0],c[1],c[2]])}};return n.grab&&(e.grab=n.grab),n.scale&&t("scale",n.scale),n.billboard&&(e.billboard=n.billboard),typeof n.follow=="string"?e.follow=n.follow:n.follow&&(e.follow=n.follow.mode,t("follow",{...n.follow,mode:void 0})),n.anchor&&(e.anchor=n.anchor),n.anchorPersist&&(e.anchorPersist=n.anchorPersist.persist,n.anchorPersist.id&&(e.anchorId=n.anchorPersist.id)),n.physics&&(e.physics=n.physics),n.orbit&&t("orbit",n.orbit),n.handles&&(e.handles=!0,t("handles",n.handles)),n.particles&&t("particles",n.particles),n.holdToAsk&&(e.holdToAsk=!0,t("holdToAsk",n.holdToAsk)),n.worldUnderstanding&&t("worldUnderstanding",n.worldUnderstanding),n.splatUrl&&(e.splatUrl=n.splatUrl),n.spatialSlot&&(e.spatialSlot=n.spatialSlot),n.audio&&t("audio",n.audio),n.dimensions&&t("dimensions",{...n.dimensions,axes:n.dimensions.axes.join("")}),n.snapTo&&(e.snapTo=!0,t("snapTo",n.snapTo)),n.snapSocket&&t("snapSocket",n.snapSocket),n.gaze&&t("gaze",n.gaze),n.explode&&t("explode",n.explode),n.navigable&&(e.navigable=n.navigable),typeof n.sync=="boolean"&&(e.sync=n.sync),n.pointerEvents&&(e.pointerEvents=n.pointerEvents),e}function Gr(n,e){let t=ft(e);if(!t)return;let r={...n.extras?.xr,...t};t.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,n.extras={...n.extras,xr:r},n.extensions={...n.extensions,MOZ_hubs_components:Qt(t),ANDROID_xr_scenecore:Jt(t)}}function Qt(n){let e={};return n.grab&&(e.grabbable={cursor:!0,hand:!0}),n.billboard&&(e.billboard={onlyY:n.billboard!=="spherical"}),e}function Xr(n,e){let t=ft(n),r=[];if(!t)return r;for(let[i,o]of Object.entries(Hr(t)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function Dn(){try{Object.defineProperty(J(),"xrTraitSerializer",{value:Object.freeze({gltfNode:Gr,usdLines:Xr}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var dt=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},Z=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,o=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-o*m,this.y=o*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,o=e.elements,c=1/(o[3]*t+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*t+o[4]*r+o[8]*i+o[12])*c,this.y=(o[1]*t+o[5]*r+o[9]*i+o[13])*c,this.z=(o[2]*t+o[6]*r+o[10]*i+o[14])*c,this}},pt=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},We=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}},$e=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,o=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(o/2),s=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(o/2);return this._x=s*m*u+c*a*h,this._y=c*a*u-s*m*h,this._z=c*m*h+s*a*u,this._w=c*m*u-s*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,o=e.z,c=e.w,m=t.x,u=t.y,s=t.z,a=t.w;return this._x=r*a+c*m+i*s-o*u,this._y=i*a+c*u+o*m-r*s,this._z=o*a+c*s+r*u-i*m,this._w=c*a-r*m-i*u-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},pe=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 at(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 ie(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Le(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 Z(0,0,0),r=new Z(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},bt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return ce(this.elements,e.elements),this}},he=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)}},Nn={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)},G=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 o=e*this.itemSize;return this.array[o]=t,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},yt=class extends G{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},gt=class extends G{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},xt=class extends G{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ue=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 G)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 G(r,1)}else e&&e.buffer&&(this.index=new G(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new Z,o=new Z,c=new Z,m=new Z,u=new Z;if(this.index){let s=this.index.array;for(let a=0;a<s.length;a+=3){let h=s[a],l=s[a+1],d=s[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),o.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(d),e.getY(d),e.getZ(d)),m.subVectors(c,o),u.subVectors(i,o),m.cross(u).normalize();for(let f of[h,l,d])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let s=0;s<t;s+=3){i.set(e.getX(s),e.getY(s),e.getZ(s)),o.set(e.getX(s+1),e.getY(s+1),e.getZ(s+1)),c.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),m.subVectors(c,o),u.subVectors(i,o),m.cross(u).normalize();for(let a=0;a<3;a++)r[(s+a)*3]=m.x,r[(s+a)*3+1]=m.y,r[(s+a)*3+2]=m.z}for(let s=0;s<t;s++){let a=r[s*3],h=r[s*3+1],l=r[s*3+2],d=Math.hypot(a,h,l)||1;r[s*3]=a/d,r[s*3+1]=h/d,r[s*3+2]=l/d}return this.setAttribute("normal",new G(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new G(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new G(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new G(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},Ye=class extends ue{constructor(e=1,t=1,r=1){super();{let h=globalThis.__three_live_native_box__;if(typeof h=="function"){let l=h(e,t,r);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let i=e/2,o=t/2,c=r/2,m=[-i,-o,c,i,-o,c,i,o,c,-i,o,c,i,-o,-c,-i,-o,-c,-i,o,-c,i,o,-c,-i,o,c,i,o,c,i,o,-c,-i,o,-c,-i,-o,-c,i,-o,-c,i,-o,c,-i,-o,c,i,-o,c,i,-o,-c,i,o,-c,i,o,c,-i,-o,-c,-i,-o,c,-i,o,c,-i,o,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],s=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let 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 G(new Float32Array(m),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),2)),this.setIndex(a)}},vt=class extends ue{constructor(e=1,t=1){super();let r=e/2,i=t/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(m),2)),this.setIndex(u)}},qe=class extends ue{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));{let s=globalThis.__three_live_native_sphere__;if(typeof s=="function"){let a=s(e,t,r);this.setAttribute("position",new G(a.positions,3)),this.setAttribute("normal",new G(a.normals,3)),this.setAttribute("uv",new G(a.uvs,2)),this.setIndex(a.indices);return}}let i=[],o=[],c=[],m=[],u=[];for(let s=0;s<=r;s++){let a=[],h=s/r;for(let l=0;l<=t;l++){let d=l/t,f=d*Math.PI*2,S=h*Math.PI,A=-e*Math.cos(f)*Math.sin(S),R=e*Math.cos(S),P=e*Math.sin(f)*Math.sin(S);i.push(A,R,P);let y=Math.hypot(A,R,P)||1;o.push(A/y,R/y,P/y),c.push(d,1-h),a.push(i.length/3-1)}u.push(a)}for(let s=0;s<r;s++)for(let a=0;a<t;a++){let h=u[s][a+1],l=u[s][a],d=u[s+1][a],f=u[s+1][a+1];s!==0&&m.push(h,l,f),s!==r-1&&m.push(l,d,f)}this.setAttribute("position",new G(new Float32Array(i),3)),this.setAttribute("normal",new G(new Float32Array(o),3)),this.setAttribute("uv",new G(new Float32Array(c),2)),this.setIndex(m)}},Ee=class extends ue{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let a=globalThis.__three_live_native_cylinder__;if(typeof a=="function"){let h=a(e,t,r,i);this.setAttribute("position",new G(h.positions,3)),this.setAttribute("normal",new G(h.normals,3)),this.setAttribute("uv",new G(h.uvs,2)),this.setIndex(h.indices);return}}let o=[],c=[],m=[],u=[],s=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,d=a===0?s:-s;for(let f=0;f<=i;f++){let S=f/i,A=S*Math.PI*2,R=Math.sin(A),P=Math.cos(A);o.push(l*R,d,l*P),c.push(R,0,P),m.push(S,1-h)}}for(let a=0;a<i;a++){let h=a,l=a+i+1,d=a+i+2,f=a+1;u.push(h,l,f,l,d,f)}if(e>0){let a=o.length/3;o.push(0,s,0),c.push(0,1,0),m.push(.5,.5);let h=o.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),S=Math.cos(d);o.push(e*f,s,e*S),c.push(0,1,0),m.push(S*.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=o.length/3;o.push(0,-s,0),c.push(0,-1,0),m.push(.5,.5);let h=o.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),S=Math.cos(d);o.push(t*f,-s,t*S),c.push(0,-1,0),m.push(S*.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 G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(m),2)),this.setIndex(u)}},Tt=class extends Ee{constructor(e=1,t=1,r=16){super(0,e,t,r)}},wt=class extends ue{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 o=[],c=[],m=[],u=[];for(let s=0;s<=r;s++){let a=s/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,d=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),S=t*Math.sin(a);o.push(d,f,S);let A=e*Math.cos(l),R=e*Math.sin(l),P=d-A,y=f-R,w=S,b=Math.hypot(P,y,w)||1;c.push(P/b,y/b,w/b),m.push(h/i,s/r)}}for(let s=1;s<=r;s++)for(let a=1;a<=i;a++){let h=(i+1)*s+a-1,l=(i+1)*(s-1)+a-1,d=(i+1)*(s-1)+a,f=(i+1)*s+a;u.push(h,l,f,l,d,f)}this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(m),2)),this.setIndex(u)}},Et=class extends ue{constructor(e=1,t=.4,r=64,i=8,o=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let y=globalThis.__three_live_native_torus_knot__;if(typeof y=="function"){let w=y(e,t,r,i,o,c);this.setAttribute("position",new G(w.positions,3)),this.setAttribute("normal",new G(w.normals,3)),this.setAttribute("uv",new G(w.uvs,2)),this.setIndex(w.indices);return}}let m=[],u=[],s=[],a=[],h=new Z,l=new Z,d=new Z,f=new Z,S=new Z;function A(y,w){let b=Math.cos(w),M=Math.sin(w),p=c/o*w,E=e*(2+Math.cos(p))*.5;y.set(E*b,E*M,e*Math.sin(p)*.5)}let R=[];for(let y=0;y<=i;++y){let w=y/i*Math.PI*2;R.push(-t*Math.cos(w),t*Math.sin(w),y/i)}for(let y=0;y<=r;++y){let w=y/r,b=w*o*Math.PI*2;A(h,b),A(l,b+.01),d.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),S.crossVectors(d,f).normalize(),f.crossVectors(S,d).normalize();for(let M=0;M<=i;++M){let p=M*3,E=R[p],v=R[p+1],_=R[p+2],C=E*f.x+v*S.x,g=E*f.y+v*S.y,T=E*f.z+v*S.z;m.push(h.x+C,h.y+g,h.z+T);let x=Math.hypot(C,g,T)||1;u.push(C/x,g/x,T/x),s.push(w,_)}}let P=i+1;for(let y=1;y<=r;y++){let w=P*(y-1),b=w+P;for(let M=1;M<=i;M++){let p=w+(M-1),E=b+(M-1),v=b+M,_=w+M;a.push(p,E,_,E,v,_)}}this.setAttribute("position",new G(new Float32Array(m),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),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 ne(n,e){return n!==void 0?Number(n):e}function en(n,e){return n!==void 0?!!n:e}var me=class{constructor(e={}){this.name=e.name||"",this.color=new he(e.color!==void 0?e.color:16777215),this.emissive=new he(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ne(e.emissiveIntensity,1),this.roughness=ne(e.roughness,.5),this.metalness=ne(e.metalness,.1),this.opacity=ne(e.opacity,1),this.transparent=en(e.transparent,!1),this.wireframe=en(e.wireframe,!1),this.side=ne(e.side,2),this.doubleSided=en(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ne(e.clearcoat,0),this.clearcoatRoughness=ne(e.clearcoatRoughness,0),this.sheen=ne(e.sheen,0),this.sheenColor=new he(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ne(e.sheenRoughness,0),this.transmission=ne(e.transmission,0),this.thickness=ne(e.thickness,0),this.attenuationColor=new he(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ne(e.attenuationDistance,1/0),this.ior=ne(e.ior,1.5),this.dispersion=ne(e.dispersion,0),this.iridescence=ne(e.iridescence,0),this.iridescenceIOR=ne(e.iridescenceIOR,1.3)}dispose(){}},Ae=class extends me{},Mt=class extends me{},Rt=class extends me{},At=class extends me{},_t=class extends me{},oe=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 Z,this.rotation=new We,this.quaternion=new $e,this.scale=new Z(1,1,1),this.matrix=new pe,this.matrixWorld=new pe,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 Z(e,t,r);this.updateMatrixWorld(!0);let o=new pe;o.lookAt(this.position,i,new Z(0,1,0));let c=o.elements,m=c[0],u=c[4],s=c[8],a=c[1],h=c[5],l=c[9],d=c[2],f=c[6],S=c[10],A=m+h+S;if(A>0){let R=.5/Math.sqrt(A+1);this.quaternion.set((f-l)*R,(s-d)*R,(a-u)*R,.25/R)}}},Dt=class extends oe{},Fe=class extends oe{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof ue?t:t?(se("unsupported geometry","BoxGeometry"),new Ye(.5,.5,.5)):new ue,this.material=i instanceof me?i:i?(se("unsupported material","MeshStandardMaterial"),new Ae({color:13421772})):new Ae}},Se=class extends oe{constructor(e=16777215,t=1){super(),this.color=new he(e),this.intensity=Number(t),this.type="directional"}},Ke=class extends Se{constructor(e,t){super(e,t),this.type="ambient"}},Ct=class extends Se{constructor(t,r){super(t,r);this.target=new oe;this.type="directional"}},Ze=class extends Se{constructor(t,r,i=0,o=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},Je=class extends oe{},Ne=class extends Je{constructor(t=45,r=1,i=.1,o=1e3){super();this.target=new Z(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},_e=class extends oe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return fe.validate(this),Pe(this)}toGLB(){return fe.validate(this),Ve(this)}toUSDZ(){return fe.validate(this),Ie(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Fe){let o=new Float32Array(i.matrixWorld.elements);t.set(r,o),i.name&&t.set(i.name,o),r++}}),t}},tn=Pe,nn=Ve,kn=Ie;var fe=class{static validate(e){let t=0,r=0,i=0,o=new Set,c=(u,s,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${s}). Found: ${a}`)},m=(u,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(u=>{if(u instanceof Fe){i++,i>1e3&&c("MESHES",1e3,i);let s=u.geometry;if(s){let a=0;if(s.attributes.position&&(a=m("vertex",s.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),s.index){let h=m("index",s.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=s.index.array;if(l&&a>0){let d=Math.min(h,l.length);for(let f=0;f<d;f++){let S=l[f];if(!Number.isFinite(S)||S<0||S>=a)throw new Error(`SecurityError: Index buffer value (${String(S)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&o.add(a.map),a.normalMap&&o.add(a.normalMap),a.roughnessMap&&o.add(a.roughnessMap)}}}),o.size>16&&c("TEXTURES",16,o.size);for(let u of o){let s=u,a=s.image,h=Number(a?.width??s.width??0)||0,l=Number(a?.height??s.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Lt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new he(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){fe.validate(e);let i=(o,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(o,c):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),c={};for(let[m,u]of o.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let o=tn(e),c=nn(e),m=(o.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights: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 Cn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Pt=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Cn(),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=Cn();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Wr(){}var Ue=new Proxy(Wr,{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:Ue},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ue,construct:()=>Ue}),Ln=(()=>{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 ke(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Me(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,ke());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 Pn,Ge;function On(n){if(!Me(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(Ge===void 0||Pn!==t){Pn=t;try{Ge=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Me(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Ge=null}}return Ge?Ge.createScriptURL(n):n}function $r(n){J().sandboxEngineSrc=n}function rn(){let n=J().sandboxEngineSrc;if(n)return n;if(Ln)return Ln;try{if(typeof document>"u")return null;let e=ke(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Me(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Yr(){let n=rn();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(!Me(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,ke()).href}function qr(n){J().sandboxIframeSrc=n}function Bn(){let n=J().sandboxIframeSrc;if(n)return n;let e=rn();if(!e||!Me(e))return null;let t=new URL(e,ke());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function jr(){let n=Bn();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(!Me(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,ke()).href}function Kr(n){J().allowClientScripts=n}function zn(){return!!J().allowClientScripts}function Zr(n){if(!Me(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,ke()).href}var Jr=["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 Qr(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,o=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(b){m({type:"ERROR",nonce:t,message:String(b)})}let s=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let b=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let M={createScriptURL:function(E){if(E!==r&&(!i||E!==i))throw new TypeError("Disallowed worker importScripts URL");return E}};o&&(M.createScript=function(E){return String(E)});let p=e.trustedTypes.createPolicy("three-live#worker-boot",M);b=p.createScriptURL(r),i&&(a=p.createScriptURL(i)),o&&typeof p.createScript=="function"&&(h=p.createScript.bind(p))}catch{}s(b)}catch(b){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(b&&b.message||b));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let b=0;b<c.length;b++){let M=c[b],p=e;for(;p&&p!==Object.prototype;){if(p!==e)try{delete p[M]}catch{}try{Object.defineProperty(p,M,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}}let d=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:d,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let S=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],A=!1;function R(b,M){if(b.type==="3D_MODEL_READY"){if(A)return;A=!0}b.nonce=t,M&&M.length?m(b,M):m(b)}let P=function(b,M){if(!b||S.indexOf(b.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+S.join(", ")+").");R(b,M)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:P,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let w=!1;e.onmessage=function(b){let M=b&&b.data;if(!(!M||M.nonce!==t)&&!(M.type!=="EXECUTE"&&M.type!=="EXECUTE_URL")&&!w){w=!0;try{let p=new l.Scene,E=new l.PerspectiveCamera(60,1,.1,1e3),v=new l.WebGLRenderer({isSandboxed:!0});if(M.type==="EXECUTE_URL"){if(!i||M.scriptUrl!==i||typeof s!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=a||i,C=s;if(s=null,a=null,e.THREE=l,e.scene=p,e.camera=E,e.renderer=v,C(_),typeof e.__THREE_LIVE_SCENE__=="function"){let g=e.__THREE_LIVE_SCENE__(l,p,E,v);g&&typeof g.toGLB=="function"&&(p=g)}else e.scene&&typeof e.scene.toGLB=="function"&&(p=e.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
287
278
  return (function () {
288
- `+A.script+`
279
+ `+M.script+`
289
280
  })();
290
281
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
291
- `+A.script+`
292
- })();`);h=null;let C=_(l,b,w,v);C&&typeof C.toGLB=="function"&&(b=C)}if(!M){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(b);let _=b.toGLB(),C=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);R({type:"3D_MODEL_READY",glbBuffer:C},[C])}m({type:"DONE",nonce:t})}catch(b){u(b&&b.message||b)}}},m({type:"READY",nonce:t})}function nn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,o={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:kr};return`'use strict';(${Or.toString()})(${JSON.stringify(o)});`}function kn(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 we=0;function On(){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 Br(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var zr=1024,Vr=256;function Dn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function rn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Dn(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let c=Object.create(null),m=i;for(let u of o){if(u.length>Vr||u==="__proto__"||u==="constructor"||u==="prototype")return null;let a=m[u];if(!Dn(a))return null;c[u]=a}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 Hr(n){let e=Br(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Bn(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 Xr(n,e,t,r){let i=On(),o=nn(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,we++;let m=!1,u=!1,a={modelDispatched:!1},s,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:o,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:n.script},"*"))},l=()=>{},p=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let M=T.data;if(M&&typeof M=="object"&&M.type==="IFRAME_READY"){h();return}let R=rn(M,i);R&&Bn(R,r,l,a)};l=()=>{m||(m=!0,s!==void 0&&clearTimeout(s),we=Math.max(0,we-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",p),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},s=setTimeout(()=>{m||(l(),kn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",p),c.onload=()=>{h()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){l();let T=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(T),T}return f.appendChild(c),{terminate:l}}function Cn(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(we>=32)return r(`SecurityError: ${we} 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=Lr()}catch(l){let p=l instanceof Error?l.message:String(l);return r(p,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=Ur()}catch(p){let f=p instanceof Error?p.message:String(p);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Xr(n,i,l,t))}catch(p){return Promise.reject(p)}}let o=On(),c=nn(i,o,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),p=URL.createObjectURL(l);try{let f=Un(p);m=new Worker(f)}finally{URL.revokeObjectURL(p)}}catch(l){let p=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${p}`,"Security Error: Failed to start Worker sandbox.")}we++;let u=!1,a={modelDispatched:!1},s,h=()=>{u||(u=!0,s!==void 0&&clearTimeout(s),we=Math.max(0,we-1),m.terminate())};return s=setTimeout(()=>{u||(h(),kn(t))},3e3),m.onmessage=l=>{let p=rn(l.data,o);p&&Bn(p,t,h,a)},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:o}):m.postMessage({type:"EXECUTE",script:n.script,nonce:o}),Promise.resolve({terminate:h})}function In(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 zn={execute(n,e,t,r){let i=(m,u)=>{let a=new Error(m);return t.onError?.(a),u&&t.onToast?.(u),Promise.reject(a)},o=In(e,i);if(o)return o;try{Hr(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??Nn()?Cn({kind:"script",script:n},e,t,i):i(sn,an)},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=In(e,r);if(i)return i;let o;try{o=Nr(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return Cn({kind:"url",scriptUrl:o},e,t,r)}},Ct=new Set;function oe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;Ct.has(t)||(Ct.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function Vn(){return Array.from(Ct)}function on(){Ct.clear()}var je=class extends Se{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}},Hn=je,_e=class extends We{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)}},It=class extends _e{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Lt=class extends _e{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Pt=class extends _e{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Ut=class extends _e{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Ft=class extends Ee{constructor(e=1,t=1,r=4,i=8){oe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},Nt=class extends Ee{constructor(e=.5,t=1,r=16){oe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},kt=class extends Ee{constructor(e=1,t=16){oe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Ot=class extends qe{constructor(t,r,i=0,o=Math.PI/3,c=0,m=2){oe("SpotLight","PointLight");super(t,r,i,m);this.target=new ie;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=c}},Ze=class extends Ye{constructor(e,t,r){oe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new he(t??4473924)}},Xn=Ze,Gn={Vector2:ht,Vector3:q,Vector4:mt,Euler:He,Quaternion:Xe,Matrix4:ye,Matrix3:ft,Color:he,MathUtils:Ln,BufferAttribute:X,Float32BufferAttribute:dt,Uint16BufferAttribute:pt,Uint32BufferAttribute:bt,BufferGeometry:ce,BoxGeometry:Ge,PlaneGeometry:yt,SphereGeometry:We,CylinderGeometry:Ee,ConeGeometry:gt,TorusGeometry:xt,TorusKnotGeometry:vt,IcosahedronGeometry:It,OctahedronGeometry:Lt,DodecahedronGeometry:Pt,TetrahedronGeometry:Ut,CapsuleGeometry:Ft,RingGeometry:Nt,CircleGeometry:kt,Texture:$e,TextureLoader:Tt,Material:me,MeshStandardMaterial:Se,MeshBasicMaterial:wt,MeshLambertMaterial:Et,MeshPhongMaterial:Mt,MeshPhysicalMaterial:Rt,ShaderMaterial:je,RawShaderMaterial:Hn,Object3D:ie,Group:St,Mesh:Pe,Light:Me,AmbientLight:Ye,DirectionalLight:At,PointLight:qe,SpotLight:Ot,HemisphereLight:Ze,RectAreaLight:Xn,Camera:Ke,PerspectiveCamera:Ue,Scene:Ae,WebGLRenderer:_t,Clock:Dt,SceneQuotaValidator:pe,exportSceneToCanvas3D:Qt,exportSceneToGLB:en,exportSceneToUSDZ:Pn,generateUSDZ:$t,glbToUSDZ:ut,sceneToCanvas3D:Ce,sceneToGLB:Be,sceneToUSDZ:Ie,authorScriptRunner:zn,getAuthorWarnings:Vn,clearAuthorWarnings:on};Object.freeze(pe);Object.freeze(pe.prototype);Object.freeze(Ae.prototype);Object.freeze(Gn);var Je=new Proxy(Gn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&oe(`THREE.${e}`,"no-op proxy"),Le),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")}}),Ve={name:"three_author",THREE:Je},Gr=Ve,K=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof K.THREE>"u"&&(K.THREE=Je);typeof K.requestAnimationFrame!="function"&&(K.requestAnimationFrame=()=>(oe("requestAnimationFrame","single-frame static evaluation"),0));typeof K.cancelAnimationFrame!="function"&&(K.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Je,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Ve,n.ThreeLivePlugins.three_author=Ve,n.ThreeLivePlugins["three-author"]=Ve}{Rn();let n=new Ae,e=new Ue(45,1,.1,1e3);e.position.set(0,2,5),K.scene=n,K.camera=e,typeof K.window>"u"&&(K.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof K.document>"u"&&(K.document={createElement:()=>({getContext:()=>Le,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(K,"__three_live_reset_scene__",{value:function(){on(),n=new Ae,e=new Ue(45,1,.1,1e3),e.position.set(0,2,5),K.scene=n,K.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let a=2e4,s=new Set,h=(l,p)=>{if(--a<0||p>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(typeof l!="object"||s.has(l))return;s.add(l);let f;if(Array.isArray(l)){f=[];for(let T of l)f.push(h(T,p+1)??null)}else{f={};for(let T of Object.keys(l)){if(T==="__proto__"||T==="prototype"||T==="constructor")continue;let M=h(l[T],p+1);M!==void 0&&(f[T]=M)}}return s.delete(l),f};try{return h(u,0)??null}catch{return null}},i=15*1024,o=1e3*4,c=function(u){let a=lt(u);if(!a)return{};let s=JSON.stringify({...u,...a});return s.length>i&&(oe(`userData.xr larger than ${i} characters`,"canonical XR traits only"),s=JSON.stringify(a)),{xr_normalized_json:s,xr_scenecore_json:JSON.stringify(jt(a)),xr_hubs_json:JSON.stringify(Zt(a))}};Object.defineProperty(K,"__three_live_extract_scene_raw__",{value:function(){let u=[],a=[],s=[],h=[];function l(d){if(!d)return null;let S=h.indexOf(d);if(S===-1){h.push(d);let x="";d.map&&(typeof d.map=="string"?x=d.map:d.map.source?x=d.map.source:d.map.image&&(x=d.map.image)),a.push({name:d.name||`Material_${a.length}`,base_color:[d.color.r,d.color.g,d.color.b,d.opacity!==void 0?d.opacity:1],metallic:d.metalness!==void 0?d.metalness:.1,roughness:d.roughness!==void 0?d.roughness:.5,double_sided:d.side===2||d.doubleSided,base_color_texture:x||null,clearcoat:d.clearcoat||0,clearcoat_roughness:d.clearcoatRoughness||0,transmission:d.transmission||0,ior:d.ior!==void 0?d.ior:1.5,thickness:d.thickness||0}),S=a.length-1}return S}let p=(d,S)=>typeof d=="number"&&Number.isFinite(d)?d:S,f=[],T=[],M=!1,R=K.scene||n,I=new ye().compose({x:p(R.position?.x,0),y:p(R.position?.y,0),z:p(R.position?.z,0)},{x:p(R.quaternion?.x,0),y:p(R.quaternion?.y,0),z:p(R.quaternion?.z,0),w:p(R.quaternion?.w,1)},{x:p(R.scale?.x,1),y:p(R.scale?.y,1),z:p(R.scale?.z,1)}),y=new Set([R]);{let d=new Set([R]),S=Array.isArray(R.children)?[...R.children]:[],x=0;for(;S.length>0&&x<=o;){let P=S.pop();if(!(!(P instanceof ie)||d.has(P))&&(d.add(P),x++,Array.isArray(P.children)))for(let B of P.children)S.push(B)}if(x>o)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let E=[],g=(d,S)=>{let x=Array.isArray(d.children)?d.children:[];for(let P=x.length-1;P>=0;P--)E.push([x[P],S])};g(R,-1);let A=d=>{let S=[];for(let P=d;P>=0&&S.length<=f.length;P=f[P].parent)S.push(P);let x=I.clone();for(let P=S.length-1;P>=0;P--){let B=f[S[P]];x.multiply(new ye().compose({x:B.translation[0],y:B.translation[1],z:B.translation[2]},{x:B.rotation[0],y:B.rotation[1],z:B.rotation[2],w:B.rotation[3]},{x:B.scale[0],y:B.scale[1],z:B.scale[2]}))}return x};for(;E.length>0;){let[d,S]=E.pop();if(!(d instanceof ie)||y.has(d))continue;y.add(d);let x=[p(d.position?.x,0),p(d.position?.y,0),p(d.position?.z,0)],P=[p(d.quaternion?.x,0),p(d.quaternion?.y,0),p(d.quaternion?.z,0),p(d.quaternion?.w,1)],B=[p(d.scale?.x,1),p(d.scale?.y,1),p(d.scale?.z,1)],V=-1,k=d.geometry,L=k?.attributes?.position;L&&L.array&&L.count>0&&(V=u.length,u.push({name:d.name||`Mesh_${u.length}`,raw_positions:L.array,raw_normals:k.attributes.normal?k.attributes.normal.array:null,raw_uvs:k.attributes.uv?k.attributes.uv.array:null,raw_indices:k.index?k.index.array:null,vertex_count:L.count,material_index:l(d.material instanceof me?d.material:null)}));let U=r(d.userData?.xr),D=!!d.userData?.xr&&U!==null,O=f.length;f.push({name:typeof d.name=="string"?d.name.slice(0,1024):"",parent:S,translation:x,rotation:P,scale:B,mesh:V,xr_traits_json:D?JSON.stringify(U):null,...D?c(U):{}});let N=r(d.userData?.interactivity);if(T.push(N),N&&(M=!0),f.length>o)break;if(d instanceof Me){let z=A(O).elements;s.push({light_type:d.type,color:[d.color.r,d.color.g,d.color.b],intensity:d.intensity,position:[p(z[12],0),p(z[13],0),p(z[14],0)]})}g(d,O)}let b=(d,S)=>d.every((x,P)=>x===S[P]),w=r({interactivity:R.userData?.interactivity,gltfExtensions:{KHR_interactivity:R.userData?.gltfExtensions?.KHR_interactivity}}),v=!!(w?.interactivity??w?.gltfExtensions?.KHR_interactivity),_=null;(M||v)&&(_=tt(f.map((d,S)=>({name:d.name,...d.mesh>=0?{mesh:d.mesh}:{},...b(d.translation,[0,0,0])?{}:{translation:d.translation},...b(d.rotation,[0,0,0,1])?{}:{rotation:d.rotation},...b(d.scale,[1,1,1])?{}:{scale:d.scale},extras:T[S]?{interactivity:T[S]}:void 0})),u.map(d=>({primitives:[{material:d.material_index??0}]})),w??void 0));let C=K.camera||e;return{meshes:u,nodes:f,materials:a,lights:s,interactivity_json:_?JSON.stringify(_):null,camera:{fov:C.fov||45,position:C.position?[C.position.x,C.position.y,C.position.z]:[0,2,5],target:C.target?[C.target.x,C.target.y,C.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Wr=Je;return tr($r);})();
282
+ `+M.script+`
283
+ })();`);h=null;let C=_(l,p,E,v);C&&typeof C.toGLB=="function"&&(p=C)}if(!A){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(p);let _=p.toGLB(),C=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);R({type:"3D_MODEL_READY",glbBuffer:C},[C])}m({type:"DONE",nonce:t})}catch(p){u(p&&p.message||p)}}},m({type:"READY",nonce:t})}function on(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,o={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:Jr};return`'use strict';(${Qr.toString()})(${JSON.stringify(o)});`}function Vn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var we=0;function Hn(){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 ei(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var ti=1024,ni=256;function In(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 sn(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,ti)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!In(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let c=Object.create(null),m=i;for(let u of o){if(u.length>ni||u==="__proto__"||u==="constructor"||u==="prototype")return null;let s=m[u];if(!In(s))return null;c[u]=s}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 ri(n){let e=ei(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Gn(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function ii(n,e,t,r){let i=Hn(),o=on(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,we++;let m=!1,u=!1,s={modelDispatched:!1},a,h=()=>{if(m||u)return;let S=c.contentWindow;!S||typeof S.postMessage!="function"||(u=!0,S.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:n.script},"*"))},l=()=>{},d=S=>{if(m||!c.contentWindow||S.source!==c.contentWindow)return;let A=S.data;if(A&&typeof A=="object"&&A.type==="IFRAME_READY"){h();return}let R=sn(A,i);R&&Gn(R,r,l,s)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),we=Math.max(0,we-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),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",d),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 S=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(S),S}return f.appendChild(c),{terminate:l}}function Un(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(we>=32)return r(`SecurityError: ${we} 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=Yr()}catch(l){let d=l instanceof Error?l.message:String(l);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=jr()}catch(d){let f=d instanceof Error?d.message:String(d);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(ii(n,i,l,t))}catch(d){return Promise.reject(d)}}let o=Hn(),c=on(i,o,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),d=URL.createObjectURL(l);try{let f=On(d);m=new Worker(f)}finally{URL.revokeObjectURL(d)}}catch(l){let d=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}we++;let u=!1,s={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),we=Math.max(0,we-1),m.terminate())};return a=setTimeout(()=>{u||(h(),Vn(t))},3e3),m.onmessage=l=>{let d=sn(l.data,o);d&&Gn(d,t,h,s)},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:o}):m.postMessage({type:"EXECUTE",script:n.script,nonce:o}),Promise.resolve({terminate:h})}function Fn(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 Xn={execute(n,e,t,r){let i=(m,u)=>{let s=new Error(m);return t.onError?.(s),u&&t.onToast?.(u),Promise.reject(s)},o=Fn(e,i);if(o)return o;try{ri(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??zn()?Un({kind:"script",script:n},e,t,i):i(cn,un)},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=Fn(e,r);if(i)return i;let o;try{o=Zr(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return Un({kind:"url",scriptUrl:o},e,t,r)}},It=new Set;function se(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;It.has(t)||(It.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function Wn(){return Array.from(It)}function an(){It.clear()}var Qe=class extends Ae{constructor(e={}){se("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},$n=Qe,De=class extends qe{constructor(e=1,t=0,r="PolyhedronGeometry"){se(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ut=class extends De{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Ft=class extends De{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Nt=class extends De{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},kt=class extends De{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Ot=class extends Ee{constructor(e=1,t=1,r=4,i=8){se("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},Bt=class extends Ee{constructor(e=.5,t=1,r=16){se("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},zt=class extends Ee{constructor(e=1,t=16){se("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Vt=class extends Ze{constructor(t,r,i=0,o=Math.PI/3,c=0,m=2){se("SpotLight","PointLight");super(t,r,i,m);this.target=new oe;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=c}},et=class extends Ke{constructor(e,t,r){se("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new he(t??4473924)}},Yn=et,qn={Vector2:dt,Vector3:Z,Vector4:pt,Euler:We,Quaternion:$e,Matrix4:pe,Matrix3:bt,Color:he,MathUtils:Nn,BufferAttribute:G,Float32BufferAttribute:yt,Uint16BufferAttribute:gt,Uint32BufferAttribute:xt,BufferGeometry:ue,BoxGeometry:Ye,PlaneGeometry:vt,SphereGeometry:qe,CylinderGeometry:Ee,ConeGeometry:Tt,TorusGeometry:wt,TorusKnotGeometry:Et,IcosahedronGeometry:Ut,OctahedronGeometry:Ft,DodecahedronGeometry:Nt,TetrahedronGeometry:kt,CapsuleGeometry:Ot,RingGeometry:Bt,CircleGeometry:zt,Texture:je,TextureLoader:St,Material:me,MeshStandardMaterial:Ae,MeshBasicMaterial:Mt,MeshLambertMaterial:Rt,MeshPhongMaterial:At,MeshPhysicalMaterial:_t,ShaderMaterial:Qe,RawShaderMaterial:$n,Object3D:oe,Group:Dt,Mesh:Fe,Light:Se,AmbientLight:Ke,DirectionalLight:Ct,PointLight:Ze,SpotLight:Vt,HemisphereLight:et,RectAreaLight:Yn,Camera:Je,PerspectiveCamera:Ne,Scene:_e,WebGLRenderer:Lt,Clock:Pt,SceneQuotaValidator:fe,exportSceneToCanvas3D:tn,exportSceneToGLB:nn,exportSceneToUSDZ:kn,generateUSDZ:jt,glbToUSDZ:mt,sceneToCanvas3D:Pe,sceneToGLB:Ve,sceneToUSDZ:Ie,authorScriptRunner:Xn,getAuthorWarnings:Wn,clearAuthorWarnings:an};Object.freeze(fe);Object.freeze(fe.prototype);Object.freeze(_e.prototype);Object.freeze(qn);var tt=new Proxy(qn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&se(`THREE.${e}`,"no-op proxy"),Ue),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")}}),Xe={name:"three_author",THREE:tt},oi=Xe,te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof te.THREE>"u"&&(te.THREE=tt);typeof te.requestAnimationFrame!="function"&&(te.requestAnimationFrame=()=>(se("requestAnimationFrame","single-frame static evaluation"),0));typeof te.cancelAnimationFrame!="function"&&(te.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=tt,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Xe,n.ThreeLivePlugins.three_author=Xe,n.ThreeLivePlugins["three-author"]=Xe}{Dn();let n=new _e,e=new Ne(45,1,.1,1e3);e.position.set(0,2,5),te.scene=n,te.camera=e,typeof te.window>"u"&&(te.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof te.document>"u"&&(te.document={createElement:()=>({getContext:()=>Ue,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(te,"__three_live_reset_scene__",{value:function(){an(),n=new _e,e=new Ne(45,1,.1,1e3),e.position.set(0,2,5),te.scene=n,te.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let s=2e4,a=new Set,h=(l,d)=>{if(--s<0||d>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(typeof l!="object"||a.has(l))return;a.add(l);let f;if(Array.isArray(l)){f=[];for(let S of l)f.push(h(S,d+1)??null)}else{f={};for(let S of Object.keys(l)){if(S==="__proto__"||S==="prototype"||S==="constructor")continue;let A=h(l[S],d+1);A!==void 0&&(f[S]=A)}}return a.delete(l),f};try{return h(u,0)??null}catch{return null}},i=15*1024,o=1e3*4,c=function(u){let s=ft(u);if(!s)return{};let a=JSON.stringify({...u,...s});return a.length>i&&(se(`userData.xr larger than ${i} characters`,"canonical XR traits only"),a=JSON.stringify(s)),{xr_normalized_json:a,xr_scenecore_json:JSON.stringify(Jt(s)),xr_hubs_json:JSON.stringify(Qt(s))}};Object.defineProperty(te,"__three_live_extract_scene_raw__",{value:function(){let u=[],s=[],a=[],h=[];function l(g){if(!g)return null;let T=h.indexOf(g);if(T===-1){h.push(g);let x="";g.map&&(typeof g.map=="string"?x=g.map:g.map.source?x=g.map.source:g.map.image&&(x=g.map.image)),s.push({name:g.name||`Material_${s.length}`,base_color:[g.color.r,g.color.g,g.color.b,g.opacity!==void 0?g.opacity:1],metallic:g.metalness!==void 0?g.metalness:.1,roughness:g.roughness!==void 0?g.roughness:.5,double_sided:g.side===2||g.doubleSided,base_color_texture:x||null,clearcoat:g.clearcoat||0,clearcoat_roughness:g.clearcoatRoughness||0,transmission:g.transmission||0,ior:g.ior!==void 0?g.ior:1.5,thickness:g.thickness||0}),T=s.length-1}return T}let d=(g,T)=>typeof g=="number"&&Number.isFinite(g)?g:T,f=[],S=[],A=!1,R=te.scene||n,P=new pe().compose({x:d(R.position?.x,0),y:d(R.position?.y,0),z:d(R.position?.z,0)},{x:d(R.quaternion?.x,0),y:d(R.quaternion?.y,0),z:d(R.quaternion?.z,0),w:d(R.quaternion?.w,1)},{x:d(R.scale?.x,1),y:d(R.scale?.y,1),z:d(R.scale?.z,1)}),y=new Set([R]);{let g=new Set([R]),T=Array.isArray(R.children)?[...R.children]:[],x=0;for(;T.length>0&&x<=o;){let I=T.pop();if(!(!(I instanceof oe)||g.has(I))&&(g.add(I),x++,Array.isArray(I.children)))for(let L of I.children)T.push(L)}if(x>o)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let w=[],b=(g,T)=>{let x=Array.isArray(g.children)?g.children:[];for(let I=x.length-1;I>=0;I--)w.push([x[I],T])};b(R,-1);let M=g=>{let T=[];for(let I=g;I>=0&&T.length<=f.length;I=f[I].parent)T.push(I);let x=P.clone();for(let I=T.length-1;I>=0;I--){let L=f[T[I]];x.multiply(new pe().compose({x:L.translation[0],y:L.translation[1],z:L.translation[2]},{x:L.rotation[0],y:L.rotation[1],z:L.rotation[2],w:L.rotation[3]},{x:L.scale[0],y:L.scale[1],z:L.scale[2]}))}return x};for(;w.length>0;){let[g,T]=w.pop();if(!(g instanceof oe)||y.has(g))continue;y.add(g);let x=[d(g.position?.x,0),d(g.position?.y,0),d(g.position?.z,0)],I=[d(g.quaternion?.x,0),d(g.quaternion?.y,0),d(g.quaternion?.z,0),d(g.quaternion?.w,1)],L=[d(g.scale?.x,1),d(g.scale?.y,1),d(g.scale?.z,1)],V=-1,N=g.geometry,U=N?.attributes?.position;U&&U.array&&U.count>0&&(V=u.length,u.push({name:g.name||`Mesh_${u.length}`,raw_positions:U.array,raw_normals:N.attributes.normal?N.attributes.normal.array:null,raw_uvs:N.attributes.uv?N.attributes.uv.array:null,raw_indices:N.index?N.index.array:null,vertex_count:U.count,material_index:l(g.material instanceof me?g.material:null)}));let F=r(g.userData?.xr),D=!!g.userData?.xr&&F!==null,O=f.length;f.push({name:typeof g.name=="string"?g.name.slice(0,1024):"",parent:T,translation:x,rotation:I,scale:L,mesh:V,xr_traits_json:D?JSON.stringify(F):null,...D?c(F):{}});let k=r(g.userData?.interactivity);if(S.push(k),k&&(A=!0),f.length>o)break;if(g instanceof Se){let z=M(O).elements;a.push({light_type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[d(z[12],0),d(z[13],0),d(z[14],0)]})}b(g,O)}let p=(g,T)=>g.every((x,I)=>x===T[I]),E=r({interactivity:R.userData?.interactivity,gltfExtensions:{KHR_interactivity:R.userData?.gltfExtensions?.KHR_interactivity}}),v=!!(E?.interactivity??E?.gltfExtensions?.KHR_interactivity),_=null;(A||v)&&(_=it(f.map((g,T)=>({name:g.name,...g.mesh>=0?{mesh:g.mesh}:{},...p(g.translation,[0,0,0])?{}:{translation:g.translation},...p(g.rotation,[0,0,0,1])?{}:{rotation:g.rotation},...p(g.scale,[1,1,1])?{}:{scale:g.scale},extras:S[T]?{interactivity:S[T]}:void 0})),u.map(g=>({primitives:[{material:g.material_index??0}]})),E??void 0));let C=te.camera||e;return{meshes:u,nodes:f,materials:s,lights:a,interactivity_json:_?JSON.stringify(_):null,camera:{fov:C.fov||45,position:C.position?[C.position.x,C.position.y,C.position.z]:[0,2,5],target:C.target?[C.target.x,C.target.y,C.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var si=tt;return sr(ai);})();