three-live 1.1.1 → 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 zt=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var Zn=Object.getOwnPropertyNames;var Jn=Object.prototype.hasOwnProperty;var Qn=(n,e)=>{for(var t in e)zt(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&&zt(n,i,{get:()=>e[i],enumerable:!(r=Kn(e,i))||r.enumerable});return n};var tr=n=>er(zt({},"__esModule",{value:!0}),n);var $r={};Qn($r,{AmbientLight:()=>qe,BoxGeometry:()=>We,BufferAttribute:()=>X,BufferGeometry:()=>ce,Camera:()=>Ke,CapsuleGeometry:()=>Nt,CircleGeometry:()=>Ot,Clock:()=>Ct,Color:()=>he,ConeGeometry:()=>xt,CylinderGeometry:()=>Ee,DirectionalLight:()=>_t,DodecahedronGeometry:()=>Ut,Euler:()=>Xe,Float32BufferAttribute:()=>pt,Group:()=>At,HemisphereLight:()=>Je,IcosahedronGeometry:()=>Lt,Light:()=>Me,Material:()=>me,MathUtils:()=>Ln,Matrix3:()=>dt,Matrix4:()=>ye,Mesh:()=>Ue,MeshBasicMaterial:()=>Et,MeshLambertMaterial:()=>Mt,MeshPhongMaterial:()=>Rt,MeshPhysicalMaterial:()=>St,MeshStandardMaterial:()=>Se,Object3D:()=>ie,OctahedronGeometry:()=>Pt,PerspectiveCamera:()=>Fe,PlaneGeometry:()=>gt,PointLight:()=>je,PolyhedronFallbackGeometry:()=>_e,Quaternion:()=>Ge,RawShaderMaterial:()=>Hn,RectAreaLight:()=>Xn,RingGeometry:()=>kt,Scene:()=>Ae,SceneQuotaValidator:()=>pe,ShaderMaterial:()=>Ze,SphereGeometry:()=>$e,SpotLight:()=>Bt,THREE:()=>Qe,TetrahedronGeometry:()=>Ft,Texture:()=>Ye,TextureLoader:()=>Tt,TorusGeometry:()=>vt,TorusKnotGeometry:()=>wt,Uint16BufferAttribute:()=>bt,Uint32BufferAttribute:()=>yt,Vector2:()=>mt,Vector3:()=>j,Vector4:()=>ft,WebGLRenderer:()=>Dt,authorScriptRunner:()=>zn,buildSandboxWorkerSource:()=>rn,clearAuthorWarnings:()=>on,default:()=>Wr,exportSceneToCanvas3D:()=>en,exportSceneToGLB:()=>tn,exportSceneToUSDZ:()=>Pn,generateUSDZ:()=>Yt,getAllowClientScripts:()=>Nn,getAuthorWarnings:()=>Vn,getSandboxEngineSrc:()=>nn,getSandboxIframeSrc:()=>Fn,glbToUSDZ:()=>lt,isAllowedSandboxEngineUrl:()=>Re,noopProxy:()=>Pe,sceneToCanvas3D:()=>Ie,sceneToGLB:()=>ze,sceneToUSDZ:()=>Le,setAllowClientScripts:()=>Fr,setSandboxEngineSrc:()=>Ir,setSandboxIframeSrc:()=>Pr,threeAuthorPlugin:()=>He,threeMicroPlugin:()=>Gr,toTrustedWorkerScriptURL:()=>Un,validateSandboxWorkerMessage:()=>sn,warnUnsupported:()=>se});function nt(n,e,t){let r=[],i=new Map,s=[],c=[],m=[],u=new Map,o=b=>{let w=i.get(b);return w===void 0&&(w=r.length,r.push({op:b}),i.set(b,w)),w},a=b=>{let w=u.get(b);return w===void 0&&(w=m.length,m.push({id:b}),u.set(b,w)),w},h=(b,w={})=>s.push({declaration:o(b),...w})-1,l=(b,w,y)=>c.push({id:b,type:w,value:y})-1,d=b=>({node:b,socket:"value"}),f=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let b=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(b&&Array.isArray(b.nodes)){let w=Array.isArray(b.declarations)?b.declarations:[];for(let y of w)y?.op&&o(y.op);Array.isArray(b.variables)&&c.push(...b.variables);for(let y of b.events||[])y?.id&&a(y.id);for(let y of b.nodes){if(!y||typeof y!="object")continue;let R=y.op||(typeof y.declaration=="number"?w[y.declaration]?.op:"");s.push(R?{...y,declaration:o(R)}:{...y})}}}let T=(b,w,y="translation")=>y==="baseColorFactor"||y==="metallicFactor"||y==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${y}`:y==="emissiveFactor"||y==="alphaCutoff"?`/materials/${Math.max(0,w)}/${y}`:y==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${y}`,A=new Map;n.forEach((b,w)=>{typeof b?.name=="string"&&!A.has(b.name)&&A.set(b.name,w)});let S=(b,w)=>typeof b.target=="string"&&A.has(b.target)?A.get(b.target):typeof b.targetNode=="number"?b.targetNode:w,L=b=>{let w=n[b];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<n.length;b++){let w=n[b],y=w?.extras?.interactivity;if(!y||typeof y!="object")continue;let R=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,p=M=>{let _=Array.isArray(M)?M:[M],I=[];for(let v=0;v<_.length;v++){let x=_[v];if(!x||typeof x!="object")continue;let P=x.action||"interpolate",D=typeof x.duration=="number"?x.duration:.35;if(P==="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/${b}/${V}`,F=l(`__toggle_${b}_${v}`,"bool",!1),C=h("variable/get",{configuration:{variable:F}}),B=h("math/not",{values:{a:d(C)}}),k=h("variable/set",{configuration:{variable:F},values:{value:d(B)}}),z=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.to)?x.to:N},duration:{value:D}}}),O=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.from)?x.from:N},duration:{value:D}}});s[k].flows={out:{node:h("flow/branch",{values:{condition:d(C)},flows:{true:{node:z},false:{node:O}}})}},I.push(k)}else if(P==="interpolate"){let V=x.to??x.value;if(V===void 0)continue;let N={value:{value:V},duration:{value:D}};x.from!==void 0&&(N.from={value:x.from}),I.push(h("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(S(x,b),L(S(x,b)),x.property)},values:N}))}else if(P==="setProperty"){if(x.value===void 0)continue;I.push(h("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(S(x,b),L(S(x,b)),x.property)},values:{value:{value:x.value}}}))}else if(P==="toggleVisibility"){let V=S(x,b),N=l(`__vis_${V}_${v}`,"bool",!0),U=h("variable/get",{configuration:{variable:N}}),F=h("math/not",{values:{a:d(U)}}),C=h("variable/set",{configuration:{variable:N},values:{value:d(F)}});s[C].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(U)}})}},I.push(C)}else if(P==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let V=typeof x.duration=="number"?x.duration:.25,N=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,U=l(`__color_idx_${b}_${v}`,"int",0),F=h("variable/get",{configuration:{variable:U}}),C=h("math/add",{values:{a:d(F),b:{value:1}}}),B=h("math/rem",{values:{a:d(C),b:{value:x.colors.length}}}),k=h("variable/set",{configuration:{variable:U},values:{value:d(B)}}),z={};for(let O=0;O<x.colors.length;O++){let H=x.colors[O],Y=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(O)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Y},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:N},values:{value:{value:Y}}})}}s[k].flows={out:{node:h("flow/switch",{values:{selection:d(F)},flows:z})}},I.push(k)}else if(P==="playAnimation")I.push(h("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(P==="stopAnimation")I.push(h("animation/stop"));else if(P==="sendEvent"){let V={};for(let[N,U]of Object.entries(x.values||{}))V[N]={value:U};I.push(h("event/send",{configuration:{event:a(String(x.event??x.id??"custom"))},values:V}))}}if(!I.length)return null;if(I.length===1)return I[0];let g={};return I.forEach((v,x)=>{g[String(x)]={node:v}}),h("flow/sequence",{flows:g})},E=(M,_,I)=>{let g=p(_);g!==null&&h(M,{...I?{configuration:I}:{},flows:{out:{node:g}}})};if(y.onSelect&&E("pointer/onSelect",y.onSelect,{nodeIndex:b}),y.onHoverIn&&E("pointer/onHoverIn",y.onHoverIn,{nodeIndex:b}),y.onHoverOut&&E("pointer/onHoverOut",y.onHoverOut,{nodeIndex:b}),y.onStart&&E("event/onStart",y.onStart),y.onReceive&&typeof y.onReceive=="object")for(let[M,_]of Object.entries(y.onReceive))E("event/receive",_,{event:a(M)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:m}],graph:0}:null}var an='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).',cn="Security Error: client-side scripts require allow-client-scripts opt-in.";var rt="__THREE_LIVE_REGISTRY__";function J(){let n=typeof globalThis<"u"?globalThis:{};if(!n[rt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,rt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[rt]=e}}return n[rt]}var K=J().plugins;function un(n){let e=J().plugins;e.some(t=>t.name===n.name)||e.push(n)}function ln(){return J().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function it(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Ce(n,e,t,r){let[i,s,c]=e,[m,u,o]=r,[a,h,l]=t,d=i-a,f=s-h,T=c-l,A=Math.hypot(d,f,T);A<=1e-5?(d=0,f=0,T=1):(d/=A,f/=A,T/=A);let S=u*T-o*f,L=o*d-m*T,b=m*f-u*d;A=Math.hypot(S,L,b),A<=1e-5?(S=0,L=0,b=0):(S/=A,L/=A,b/=A);let w=f*b-T*L,y=T*S-d*b,R=d*L-f*S;return A=Math.hypot(w,y,R),A<=1e-5?(w=0,y=0,R=0):(w/=A,y/=A,R/=A),n[0]=S,n[1]=w,n[2]=d,n[3]=0,n[4]=L,n[5]=y,n[6]=f,n[7]=0,n[8]=b,n[9]=R,n[10]=T,n[11]=0,n[12]=-(S*i+L*s+b*c),n[13]=-(w*i+y*s+R*c),n[14]=-(d*i+f*s+T*c),n[15]=1,n}function re(n,e,t){let r=e[0],i=e[1],s=e[2],c=e[3],m=e[4],u=e[5],o=e[6],a=e[7],h=e[8],l=e[9],d=e[10],f=e[11],T=e[12],A=e[13],S=e[14],L=e[15],b=t[0],w=t[1],y=t[2],R=t[3];return n[0]=b*r+w*m+y*h+R*T,n[1]=b*i+w*u+y*l+R*A,n[2]=b*s+w*o+y*d+R*S,n[3]=b*c+w*a+y*f+R*L,b=t[4],w=t[5],y=t[6],R=t[7],n[4]=b*r+w*m+y*h+R*T,n[5]=b*i+w*u+y*l+R*A,n[6]=b*s+w*o+y*d+R*S,n[7]=b*c+w*a+y*f+R*L,b=t[8],w=t[9],y=t[10],R=t[11],n[8]=b*r+w*m+y*h+R*T,n[9]=b*i+w*u+y*l+R*A,n[10]=b*s+w*o+y*d+R*S,n[11]=b*c+w*a+y*f+R*L,b=t[12],w=t[13],y=t[14],R=t[15],n[12]=b*r+w*m+y*h+R*T,n[13]=b*i+w*u+y*l+R*A,n[14]=b*s+w*o+y*d+R*S,n[15]=b*c+w*a+y*f+R*L,n}function st(n,e,t,r){let i=e[0],s=e[1],c=e[2],m=e[3],u=i+i,o=s+s,a=c+c,h=i*u,l=i*o,d=i*a,f=s*o,T=s*a,A=c*a,S=m*u,L=m*o,b=m*a,w=r[0],y=r[1],R=r[2];return n[0]=(1-(f+A))*w,n[1]=(l+b)*w,n[2]=(d-L)*w,n[3]=0,n[4]=(l-b)*y,n[5]=(1-(h+A))*y,n[6]=(T+S)*y,n[7]=0,n[8]=(d+L)*R,n[9]=(T-S)*R,n[10]=(1-(h+f))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ae(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],c=e[5],m=e[6],u=e[8],o=e[9],a=e[10],h=a*c-m*o,l=-a*s+m*u,d=o*s-c*u,f=t*h+r*l+i*d;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*o)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*s)*f,n[6]=d*f,n[7]=(-o*t+r*u)*f,n[8]=(c*t-r*s)*f),n}function hn(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],c=e[4],m=e[5],u=e[6],o=e[7],a=e[8],h=e[9],l=e[10],d=e[11],f=e[12],T=e[13],A=e[14],S=e[15],L=t*m-r*c,b=t*u-i*c,w=t*o-s*c,y=r*u-i*m,R=r*o-s*m,p=i*o-s*u,E=a*T-h*f,M=a*A-l*f,_=a*S-d*f,I=h*A-l*T,g=h*S-d*T,v=l*S-d*A,x=L*v-b*g+w*I+y*_-R*M+p*E;return x?(x=1/x,n[0]=(m*v-u*g+o*I)*x,n[1]=(i*g-r*v-s*I)*x,n[2]=(T*p-A*R+S*y)*x,n[3]=(l*R-h*p-d*y)*x,n[4]=(u*_-c*v-o*M)*x,n[5]=(t*v-i*_+s*M)*x,n[6]=(A*w-f*p-S*b)*x,n[7]=(a*p-l*w+d*b)*x,n[8]=(c*g-m*_+o*E)*x,n[9]=(r*_-t*g-s*E)*x,n[10]=(f*R-T*w+S*L)*x,n[11]=(h*w-a*R-d*L)*x,n[12]=(m*M-c*I-u*E)*x,n[13]=(t*I-r*M+i*E)*x,n[14]=(T*b-f*y-A*L)*x,n[15]=(a*y-h*b+l*L)*x,n):null}function Vt(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],c=i[1]*e+i[5]*t+i[9]*r+i[13],m=i[2]*e+i[6]*t+i[10]*r+i[14],u=i[3]*e+i[7]*t+i[11]*r+i[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=c*o,n[2]=m*o}function mn(n,e,t,r,i,s,c,m,u,o,a,h,l,d,f,T,A=0){let S=o-c,L=a-m,b=h-u,w=l-c,y=d-m,R=f-u,p=i*R-s*y,E=s*w-r*R,M=r*y-i*w,_=S*p+L*E+b*M;if(_>-1e-7&&_<1e-7)return!1;let I=1/_,g=n-c,v=e-m,x=t-u,P=I*(g*p+v*E+x*M);if(P<-A||P>1+A)return!1;let D=v*b-x*L,V=x*S-g*b,N=g*L-v*S,U=I*(r*D+i*V+s*N);if(U<-A||P+U>1+A)return!1;let F=I*(w*D+y*V+R*N);if(F>1e-4&&F<T.distance){T.distance=F,T.point=[n+r*F,e+i*F,t+s*F];let C=L*R-b*y,B=b*w-S*R,k=S*y-L*w,z=Math.hypot(C,B,k)||1;return T.normal=[C/z,B/z,k/z],!0}return!1}function ot(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(q());if(t===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||s.has(a))return;s.add(a);let d=n.nodes[a];if(!d)return;let f=q();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],S=d.rotation||[0,0,0,1],L=d.scale||[1,1,1];st(f,S,A,L)}let T=r[a];if(h?re(T,h,f):T.set(f),Array.isArray(d.children))for(let A of d.children)typeof A=="number"&&m(A,T,l+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)i.has(a)||u.push(a);for(let a of u)m(a,null);for(let a=0;a<t;a++)!i.has(a)&&!u.includes(a)&&m(a,null);return r}function nr(n){return new TextDecoder().decode(n)}var pn=J().decoders;function rr(n,e){pn.set(n.toLowerCase(),e)}function Oe(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 s=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=s&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),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 T=new Uint8Array(e,f,l),A=nr(T);m=JSON.parse(A,(S,L)=>S==="__proto__"||S==="constructor"||S==="prototype"?void 0:L)}else d===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let o=m.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!Oe("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!Oe("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!Oe("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of K)l.onParseGLB?.(h);return h}function 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 Be(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,14 +40,13 @@ uniform vec4 uBaseColor;
40
40
  uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
41
41
  uniform vec2 uClearcoat;
42
42
  uniform vec3 uCameraPos,uAmbientColor;
43
- uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uXrDepthTex;
44
- uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uXrDepthEnabled,uXrDepthFormat;
45
- uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
46
- uniform mat4 uXrDepthUVTransform;
43
+ uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
44
+ uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap;
45
+ uniform float uNormalScale,uOcclusionStrength;
46
+ /*XRD_U*/
47
47
  uniform vec2 uViewportSize;
48
- uniform vec4 uViewport;
49
- uniform vec3 uCameraFwd;
50
- uniform int uToneMapping,uNumDirLights,uNumPointLights;
48
+ uniform vec4 uSectionPlane;
49
+ uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
51
50
  uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
52
51
  out vec4 fragColor;
53
52
 
@@ -116,6 +115,7 @@ return color;
116
115
  }
117
116
 
118
117
  void main(){
118
+ if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
119
119
  vec4 base=uBaseColor;
120
120
  if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
121
121
  if(length(vNormal)<1e-4&&uHasTexture==1){
@@ -196,33 +196,19 @@ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
196
196
  }
197
197
  color=applyToneMapping(color,uToneMapping);
198
198
  float outAlpha=base.a;
199
- if(uXrDepthEnabled==1){
200
- vec2 normViewUV=vec2((gl_FragCoord.x-uViewport.x)/max(uViewport.z,1.0),1.0-(gl_FragCoord.y-uViewport.y)/max(uViewport.w,1.0));
201
- vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
202
- if(depthUV.x>=0.0&&depthUV.x<=1.0&&depthUV.y>=0.0&&depthUV.y<=1.0){
203
- vec4 depthSample=texture(uXrDepthTex,depthUV);
204
- float rawDepth=uXrDepthFormat==1?depthSample.r:(depthSample.r*255.0+depthSample.a*65280.0);
205
- float realDepth=rawDepth*uXrRawValueToMeters;
206
- float virtDepth=dot(uCameraFwd,uCameraFwd)>0.5?dot(vWorldPos-uCameraPos,uCameraFwd):length(uCameraPos-vWorldPos);
207
- if(rawDepth>0.0&&(uXrDepthFormat==1||rawDepth<65500.0)&&realDepth>0.15&&realDepth<20.0&&virtDepth>realDepth+0.02){
208
- float occAlpha=1.0-smoothstep(0.0,0.035,virtDepth-realDepth-0.02);
209
- outAlpha*=occAlpha;
210
- if(outAlpha<0.01)discard;
211
- }
212
- }
213
- }
199
+ /*XRD_O*/
214
200
  fragColor=vec4(color,outAlpha);
215
- }`,sr=`#version 300 es
201
+ }`,hr=`#version 300 es
216
202
  layout(location=0) in vec3 aPosition;
217
203
  uniform mat4 uMVP;
218
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,or=`#version 300 es
204
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,mr=`#version 300 es
219
205
  precision highp float;
220
206
  uniform vec4 uColorId;
221
207
  out vec4 fragColor;
222
- 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 Xt(n,e,t){let r=fn(n,35633,e),i=fn(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let c=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${c}`)}return s}function Gt(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","uViewport","uCameraFwd"];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 Ht(n,e,t,r,i,s,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],o=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,h;if(a===s)h=new Float32Array(t,o,m.count*s);else{h=new Float32Array(m.count*s);let d=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 A=f+T*a;for(let S=0;S<s;S++)h[T*s+S]=d[A+S]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var 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:s}=e,c=[],m=ot(i),u=[];if(Array.isArray(i.nodes))for(let E=0;E<i.nodes.length;E++){let M=i.nodes[E];M.mesh!==void 0&&i.meshes&&i.meshes[M.mesh]&&u.push({node:M,nodeIdx:E,meshIdx:M.mesh})}let o=u.length>0?u:(i.meshes||[]).map((E,M)=>({node:E,nodeIdx:-1,meshIdx:M})),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 M of E){let _=M.type==="directional"?"directional":M.type==="point"?"point":"ambient";a.push({type:_,color:M.color||[1,1,1],intensity:M.intensity!==void 0?M.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${i.textures.length}`);for(let E=0;E<i.textures.length;E++){let M=i.textures[E],_=i.images[M.source];if(_){let I=n.createTexture();if(n.bindTexture(3553,I),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),_.bufferView!==void 0){let g=i.bufferViews[_.bufferView],v=s.slice(g.byteOffset||0,(g.byteOffset||0)+g.byteLength),x=new Blob([v],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(P=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let g=ar(_.uri);if(g){let v=new Image;v.crossOrigin="anonymous",v.referrerPolicy="no-referrer",v.onload=()=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,v),n.generateMipmap(3553),r?.()},v.src=g}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}h.push(I)}else h.push(null)}}let l=[1/0,1/0,1/0],d=[-1/0,-1/0,-1/0],f=0,T=0;for(let E=0;E<o.length;E++){let M=o[E],_=i.meshes[M.meshIdx],I=M.nodeIdx>=0?m[M.nodeIdx]:q(),g=new Float32Array(9);ae(g,I);let v={name:M.node.name||_.name||`Mesh_${M.meshIdx}`,nodeIndex:M.nodeIdx,transform:I,normalMatrix:g,primitives:[],extras:M.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let $=Oe("draco");$&&$.decodePrimitive(i,x,s)}let P=[],D=n.createVertexArray();n.bindVertexArray(D);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 $=0;$<3;$++){let ue=I[12+$],De=I[12+$];for(let be=0;be<3;be++){let et=I[be*4+$]*V.min[be],tt=I[be*4+$]*V.max[be];ue+=et<tt?et:tt,De+=et>tt?et:tt}ue<l[$]&&(l[$]=ue),De>d[$]&&(d[$]=De)}let U=Ht(n,i,s,x.attributes.POSITION,0,3,P);Ht(n,i,s,x.attributes.NORMAL,1,3,P),Ht(n,i,s,x.attributes.TEXCOORD_0,2,2,P);let F=0,C=5123,B=null;if(x.indices!==void 0){let $=i.accessors[x.indices],De=(i.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(F=Number($.count??0),!Number.isFinite(F)||F<0||T+F>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=F,C=$.componentType===5125?5125||5125:5123||5123;let be=n.createBuffer();P.push(be),n.bindBuffer(34963,be),$.componentType===5125?(B=new Uint32Array(s,De,$.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,De,$.count),n.bufferData(34963,B,35044))}else F=V.count;let k={};for(let $ of K)if($.onBuildPrimitiveVAO){let ue=$.onBuildPrimitiveVAO(n,D,x,i,s);ue&&(k[$.name]=ue)}n.bindVertexArray(null);let z=i.materials&&x.material!==void 0?i.materials[x.material]:null,O=yn,H=gn,Y=!1;for(let $ of K)if($.onResolveShader){let ue=$.onResolveShader(x,z,O,H);ue&&(O=ue.vs,H=ue.fs,Y=!0)}let W=Y?Xt(n,O,H):null,fe=W?Gt(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,oe=de?de.clearcoatFactor??1:0,ve=Math.max(.04,de?.clearcoatRoughnessFactor??.04),we=ee?.baseColorTexture!==void 0&&h[ee.baseColorTexture.index]?h[ee.baseColorTexture.index]:null,ke=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,jn=!!(z?.extensions?.KHR_materials_transmission||k.materials?.isTransmissive);v.primitives.push({vao:D,indexCount:F,indexType:C,baseColor:ne,metallic:ge,roughness:xe,clearcoat:oe,clearcoatRoughness:ve,positions:U,indices:B,texture:we,metallicRoughnessTexture:ke,normalTexture:Wn,occlusionTexture:Yn,normalScale:$n,occlusionStrength:qn,buffers:P,materialIndex:x.material,pluginData:k,customProgram:W,customUniforms:fe,isTransmissive:jn})}c.push(v)}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],S=d[0]-l[0],L=d[1]-l[1],b=d[2]-l[2],w=Math.max(Math.hypot(S,L,b)/2,.5),y=[l[0],l[1],l[2]],R=[d[0],d[1],d[2]],p=e.animations;if(!p){for(let E of K)if(E.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:c,bounds:{center:A,radius:w,min:y,max:R},lights:a,animations:p,worldMatrices:m}}var at=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=q();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=q();this.viewMatrix=q();this.modelMatrix=q();this.mvpMatrix=q();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:q(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),i=u}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.renderProg=Xt(m,yn,gn),this.pickProg=Xt(m,sr,or),this.uRender=Gt(m,this.renderProg,xn),this.uPick=Gt(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 Oe(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:s,animations:c,worldMatrices:m}=dn(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of K)o.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(bn(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(Be(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Be(e),{meshes:i}=dn(this.gl,r,vn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],ae(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),ae(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],c=[],m=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&c.length<6){let h=u.position||[0,0,0];c.push(h[0],h[1],h[2]),m.push(o[0]*a,o[1]*a,o[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(t.uniform3fv(e.uPointLightPos,c),t.uniform3fv(e.uPointLightColor,m)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of K)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of K)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],c=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of K)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=q();re(r,this.projMatrix,this.viewMatrix);let[i,s,c]=e,m=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(m=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*c+r[12],l=r[1]*i+r[5]*s+r[9]*c+r[13],d=r[2]*i+r[6]*s+r[10]*c+r[14],f=r[3]*i+r[7]*s+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,A=l/f,S=d/f,L=this.canvas.getBoundingClientRect(),b=L.width||this.canvas.clientWidth||this.canvas.width||300,w=L.height||this.canvas.clientHeight||this.canvas.height||150,y=(T*.5+.5)*b,R=(-A*.5+.5)*w,p=T>=-1.1&&T<=1.1&&A>=-1.1&&A<=1.1&&S>=-1&&S<=1;if(p&&t){let E=this.customTarget||this.bounds.center,M=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=E[1]+this.currDistance*Math.sin(this.currPhi),I=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=[i-M,s-_,c-I];m*g[0]+u*g[1]+o*g[2]>.05&&(p=!1)}return{x:y,y:R,z:S,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,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],m=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+s*m[0])*o,u[1]+=(-i*c[1]+s*m[1])*o,u[2]+=(-i*c[2]+s*m[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),u=i.height>0?Math.floor((t-i.top)*(c/i.height)):Math.floor(t);return this.performMeshPick(m,u,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let m=q();re(m,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==c)&&this.resizePickingFbo(s,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let p=0;p<this.meshes.length;p++){let E=this.meshes[p];if(E.visible===!1||E.isPluginMesh)continue;let M=p+1,_=(M&255)/255,I=(M>>8&255)/255,g=(M>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,I,g,1),re(this.modelMatrix,this.modelRootMatrix,E.transform),re(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let v of E.primitives)i.bindVertexArray(v.vao),i.drawElements(4,v.indexCount,v.indexType,0)}let y=new Uint8Array(4);i.readPixels(o,a,1,1,6408,5121,y),i.bindFramebuffer(36160,null);let R=y[0]+(y[1]<<8)+(y[2]<<16);R>0&&R<=this.meshes.length&&(u=[this.meshes[R-1]])}u.length===0&&(u=this.meshes.filter(y=>y.visible!==!1));let h=null,l=1/0,d=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,A=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),S=T[1]+this.currDistance*Math.sin(this.currPhi),L=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let y of u){re(this.modelMatrix,this.modelRootMatrix,y.transform),re(this.mvpMatrix,m,this.modelMatrix);let R=q();if(!hn(R,this.mvpMatrix))continue;let p=(o+.5)/s*2-1,E=(a+.5)/c*2-1,M=[0,0,0],_=[0,0,0];Vt(M,p,E,-1,R),Vt(_,p,E,1,R);let I=_[0]-M[0],g=_[1]-M[1],v=_[2]-M[2],x=Math.hypot(I,g,v)||1,P=I/x,D=g/x,V=v/x,N={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((F=>{for(let C of y.primitives){if(!C.positions)continue;let B=C.positions,k=C.indices,z=Math.floor(k?k.length/3:B.length/9);for(let O=0;O<z;O++){let H=k?k[O*3]:O*3,Y=k?k[O*3+1]:O*3+1,W=k?k[O*3+2]:O*3+2;mn(M[0],M[1],M[2],P,D,V,B[H*3],B[H*3+1],B[H*3+2],B[Y*3],B[Y*3+1],B[Y*3+2],B[W*3],B[W*3+1],B[W*3+2],N,F)}}})(1e-4),isFinite(N.distance)){let F=N.point[0],C=N.point[1],B=N.point[2],k=this.modelMatrix,z=k[0]*F+k[4]*C+k[8]*B+k[12],O=k[1]*F+k[5]*C+k[9]*B+k[13],H=k[2]*F+k[6]*C+k[10]*B+k[14],Y=z-A,W=O-S,fe=H-L,ee=Math.hypot(Y,W,fe);if(ee<l){ae(this.normalMatrix,this.modelMatrix);let ne=this.normalMatrix,ge=N.normal[0],xe=N.normal[1],de=N.normal[2],oe=ne[0]*ge+ne[3]*xe+ne[6]*de,ve=ne[1]*ge+ne[4]*xe+ne[7]*de,we=ne[2]*ge+ne[5]*xe+ne[8]*de,ke=Math.hypot(oe,ve,we)||1;oe/=ke,ve/=ke,we/=ke,oe*Y+ve*W+we*fe>0&&(oe=-oe,ve=-ve,we=-we),h=y,l=Math.round(ee*1e3)/1e3,d=[Math.round(z*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(oe*1e3)/1e3,Math.round(ve*1e3)/1e3,Math.round(we*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 y of K)y.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,c=i?Math.max(1,t-r):r,m=(s+.5)/c*2-1;return Math.floor((m*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);it(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Ce(this.viewMatrix,[i,s,c],r,[0,1,0]),re(this.mvpMatrix,this.projMatrix,this.viewMatrix),ae(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 K)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 K)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of K)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 K)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let c={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,t,r,i,s=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,o=e?.transform?.position,a=o?[o.x,o.y,o.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:m,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),y=Math.max(1,this.canvas.height||1),R=Math.max(1,Math.floor(w*.5)),p=Math.max(1,w-R),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),M=this.customTarget||this.bounds.center,_=M[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),I=M[1]+this.currDistance*Math.sin(this.currPhi),g=M[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),v=Math.cos(this.currTheta),x=-Math.sin(this.currTheta),P=.032,D=q(),V=q(),N=[_-v*P,I,g-x*P],U=[M[0]-v*P*.25,M[1],M[2]-x*P*.25];it(D,this.fov,R/y,.1,E),Ce(V,N,U,[0,1,0]);let F=q(),C=q(),B=[_+v*P,I,g+x*P],k=[M[0]+v*P*.25,M[1],M[2]+x*P*.25];it(F,this.fov,p/y,.1,E),Ce(C,B,k,[0,1,0]),this.render({viewMatrix:V,projMatrix:D,eyePos:N,viewport:[0,0,R,y],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:C,projMatrix:F,eyePos:B,viewport:[R,0,p,y],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,y);return}let t=this.gl,r=0,i=0,s=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],c=e.viewport[3],t.viewport(r,i,s,c)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let m=q(),u=e?.viewMatrix??this.viewMatrix;re(m,e?.projMatrix??this.projMatrix,u);let o=[-u[2],-u[6],-u[10]],a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,h=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),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 K)w.onBeforeDrawScene?.(this,t,m,[l,d,f],a);let T=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let A=e?.eye||"none",S=!1,L=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=w=>{for(let y=0;y<L.length;y++){let R=L[y];if(R.visible===!1)continue;let p=this.selectedMeshName!==""&&R.name===this.selectedMeshName;y<T||R.worldSpace===!0||R.name==="__xr_reticle__"?this.modelMatrix.set(R.transform):re(this.modelMatrix,this.modelRootMatrix,R.transform),re(this.mvpMatrix,m,this.modelMatrix),ae(R.normalMatrix,this.modelMatrix);let E=R.extras?.xr?.stereo||R.userData?.xr?.stereo,M=0,_=0,I=1,g=1;E==="sbs"?(I=.5,M=A==="right"?.5:0):E==="ou"&&(g=.5,_=A==="right"?.5:0);for(let v of R.primitives){let x=!!v.isTransmissive;if(!w&&x){S=!0;continue}if(w&&!x)continue;let P=v.customProgram||this.renderProg,D=v.customUniforms||this.uRender;t.useProgram(P),t.uniform1i(D.uToneMapping,a),t.uniform1f(D.uEnvIntensity,this.envIntensity),t.uniform3f(D.uCameraPos,l,d,f),D.uCameraFwd&&t.uniform3f(D.uCameraFwd,o[0],o[1],o[2]),t.uniform1f(D.uEmissive,p?1:0),t.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(D.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(D.uNormalMatrix,!1,R.normalMatrix),D.uUvTransform&&t.uniform4f(D.uUvTransform,M,_,I,g),D.uViewportSize&&t.uniform2f(D.uViewportSize,Math.max(1,s),Math.max(1,c)),D.uViewport&&t.uniform4f(D.uViewport,r,i,Math.max(1,s),Math.max(1,c)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),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 V of K)V.onBeforeDrawPrimitive?.(t,P,v,R,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(b(!1),S){for(let w of K)w.onBeforeTransmissivePass?.(t,this);b(!0)}for(let w of K)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 s of i.buffers)t.deleteBuffer(s);i.texture&&t.deleteTexture(i.texture),i.metallicRoughnessTexture&&t.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&t.deleteTexture(i.normalTexture),i.occlusionTexture&&t.deleteTexture(i.occlusionTexture),i.customProgram&&t.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of K)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};at.registerPlugin=un,at.getRegisteredPlugins=ln;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 Ie(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],c=[],m=[],u=new Set,o=[],a=[],h=new Map,l=[];function d(p,E){let M=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),_=cr(M.byteLength),I=new Uint8Array(_);I.set(M),t.push(I);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:M.byteLength,target:E}),r+=_,g}function f(p,E,M,_,I,g,v){let x=d(p,M),P=s.length,D={bufferView:x,byteOffset:0,componentType:_,count:I,type:E};return g&&(D.min=g),v&&(D.max=v),s.push(D),P}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 T=[];function A(p){let E={name:p.name||""},M=p.position,_=p.quaternion,I=p.scale;if((M.x||M.y||M.z)&&(E.translation=[M.x,M.y,M.z]),(_.x||_.y||_.z||_.w!==1)&&(E.rotation=[_.x,_.y,_.z,_.w]),(I.x!==1||I.y!==1||I.z!==1)&&(E.scale=[I.x,I.y,I.z]),p.userData&&Object.keys(p.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(p.userData,(v,x)=>{if(!(v==="__proto__"||v==="prototype"||v==="constructor"))return typeof x=="function"?void 0:x})),p.userData.xr)){let v=ur(p.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:v,ANDROID_xr_scenecore:v},J().xrTraitSerializer?.gltfNode(E,p.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(p.geometry){let v=p.geometry,x=v.attributes.position;if(x&&x.count>0){let P=[1/0,1/0,1/0],D=[-1/0,-1/0,-1/0];for(let F=0;F<x.count;F++){let C=x.getX(F),B=x.getY(F),k=x.getZ(F);C<P[0]&&(P[0]=C),C>D[0]&&(D[0]=C),B<P[1]&&(P[1]=B),B>D[1]&&(D[1]=B),k<P[2]&&(P[2]=k),k>D[2]&&(D[2]=k)}let N={attributes:{POSITION:f(x.array,"VEC3",34962,5126,x.count,P,D)}};if(v.attributes.normal&&(N.attributes.NORMAL=f(v.attributes.normal.array,"VEC3",34962,5126,v.attributes.normal.count)),v.attributes.uv&&(N.attributes.TEXCOORD_0=f(v.attributes.uv.array,"VEC2",34962,5126,v.attributes.uv.count)),v.index){let F=v.index.array instanceof Uint32Array;N.indices=f(v.index.array,"SCALAR",34963,F?5125:5123,v.index.count)}if(p.material){let F=h.get(p.material);if(F===void 0){F=a.length,h.set(p.material,F);let C=p.material,B={name:C.name||"",pbrMetallicRoughness:{baseColorFactor:[C.color.r,C.color.g,C.color.b,C.opacity],metallicFactor:C.metalness,roughnessFactor:C.roughness},doubleSided:C.side===2||C.doubleSided};if(C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0)){let z=C.emissiveIntensity??1;B.emissiveFactor=[C.emissive.r*z,C.emissive.g*z,C.emissive.b*z]}let k={};C.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen>0&&(k.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission>0&&(k.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness>0&&(k.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(k.KHR_materials_ior={ior:C.ior}),C.dispersion>0&&(k.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3}),Object.keys(k).length>0&&(B.extensions=k),a.push(B)}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),o.push(p),p.children.length>0){E.children=[];for(let v of p.children)E.children.push(A(v))}return g}for(let p of n.children)T.push(A(p));let S=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),L=[];if(typeof S=="function"&&o.length>0){let p=e?.duration??4,E=e?.fps??15,M=Math.max(2,Math.round(p*E)+1),_=new Float32Array(M),I=o.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=o.map(()=>new Float32Array(M*3)),v=o.map(()=>new Float32Array(M*4)),x=o.map(()=>new Float32Array(M*3));for(let U=0;U<M;U++){let F=U/(M-1)*p;_[U]=F;try{S(F)}catch{}for(let C=0;C<o.length;C++){let B=o[C];g[C][U*3]=B.position.x,g[C][U*3+1]=B.position.y,g[C][U*3+2]=B.position.z,v[C][U*4]=B.quaternion.x,v[C][U*4+1]=B.quaternion.y,v[C][U*4+2]=B.quaternion.z,v[C][U*4+3]=B.quaternion.w,x[C][U*3]=B.scale.x,x[C][U*3+1]=B.scale.y,x[C][U*3+2]=B.scale.z}}for(let U=0;U<o.length;U++){let F=o[U],C=I[U];F.position.set(C.px,C.py,C.pz),F.quaternion.set(C.qx,C.qy,C.qz,C.qw),F.scale.set(C.sx,C.sy,C.sz)}n.updateMatrixWorld(!0);let P=null,D=()=>(P===null&&(P=f(_,"SCALAR",0,5126,M,[0],[p])),P),V=[],N=[];for(let U=0;U<o.length;U++){let F=I[U],C=!1,B=!1,k=!1;for(let z=0;z<M;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)&&(C=!0),(Math.abs(v[U][z*4]-F.qx)>1e-4||Math.abs(v[U][z*4+1]-F.qy)>1e-4||Math.abs(v[U][z*4+2]-F.qz)>1e-4||Math.abs(v[U][z*4+3]-F.qw)>1e-4)&&(B=!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(C){let z=f(g[U],"VEC3",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"translation"}})}if(B){let z=f(v[U],"VEC4",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"rotation"}})}if(k){let z=f(x[U],"VEC3",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"scale"}})}}N.length>0&&L.push({name:"ProceduralLoop",samplers:V,channels:N})}let b=nt(m,c,n.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:a,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...L.length>0?{animations:L}:{},...b||u.size>0?{extensionsUsed:[...b?["KHR_interactivity"]:[],...u]}:{},...b?{extensions:{KHR_interactivity:b}}:{}},y=new Uint8Array(r),R=0;for(let p of t)y.set(p,R),R+=p.byteLength;return{gltf:w,bin:y.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function ut(n){return new TextEncoder().encode(n)}function ze(n,e){let{gltf:t,bin:r}=Ie(n,e),i=JSON.stringify(t),s=ut(i),c=(4-s.byteLength%4)%4,m=s.byteLength+c,u=20+m+8+r.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let l=0;l<c;l++)o[20+s.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),o.set(new Uint8Array(r),h+8),o}function lr(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let c=s.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let p=0;p<c;p++){let E=s.getX(p),M=s.getY(p),_=s.getZ(p);m[p*3]=u[0]*E+u[4]*M+u[8]*_+u[12],m[p*3+1]=u[1]*E+u[5]*M+u[9]*_+u[13],m[p*3+2]=u[2]*E+u[6]*M+u[10]*_+u[14]}let o;if(i.attributes.normal){let p=i.attributes.normal;o=new Float32Array(c*3);let E=new Float32Array(9);ae(E,u);for(let M=0;M<c;M++){let _=p.getX(M),I=p.getY(M),g=p.getZ(M),v=E[0]*_+E[3]*I+E[6]*g,x=E[1]*_+E[4]*I+E[7]*g,P=E[2]*_+E[5]*I+E[8]*g,D=Math.hypot(v,x,P)||1;o[M*3]=v/D,o[M*3+1]=x/D,o[M*3+2]=P/D}}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,T=.1,A=0,S=0,L=1.5,b=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"&&(T=p.metalness),typeof p.clearcoat=="number"&&(A=p.clearcoat),typeof p.clearcoatRoughness=="number"&&(S=p.clearcoatRoughness),typeof p.ior=="number"&&(L=p.ior);let E=typeof p.opacity=="number"?p.opacity:1,M=typeof p.transmission=="number"?p.transmission:0;if(b=E*(1-M),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 y,R=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof R=="function"){let p=e?.duration??4,E=e?.fps??4,M=Math.max(2,Math.round(p*E)+1),_=[],I=[],g=[],v=[],x=[r.position.x,r.position.y,r.position.z],P=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],D=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let N=0;N<M;N++){let U=N/(M-1)*p;_.push(U);try{R(U)}catch{}I.push([r.position.x,r.position.y,r.position.z]),g.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),v.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-D[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(D[0],D[1],D[2]),V&&(y={times:_,translations:I,rotations:g,scales:v})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:o,uvs:a,materialName:l,color:d,roughness:f,metallic:T,clearcoat:A,clearcoatRoughness:S,ior:L,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:y})}}),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),s=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(d){let f=s[d];if(!f)throw new Error(`Accessor ${d} not found`);let T=c[f.bufferView||0],A=(T.byteOffset||0)+(f.byteOffset||0),S=T.byteLength||0,L=i.slice(A,A+S);return{acc:f,buffer:L}}let h=new Map;if(o.length>0){let d=ot(t);for(let f=0;f<d.length;f++)h.set(f,d[f])}function l(d,f,T,A){let S=u[d];if(!S)return;let L=new Float32Array(9);ae(L,f);for(let b=0;b<(S.primitives||[]).length;b++){let w=S.primitives[b],y=w.attributes?.POSITION;if(y===void 0)continue;let{acc:R,buffer:p}=a(y),E=new Float32Array(p,0,R.count*3),M=new Float32Array(E.length);for(let O=0;O<R.count;O++){let H=E[O*3],Y=E[O*3+1],W=E[O*3+2];M[O*3]=f[0]*H+f[4]*Y+f[8]*W+f[12],M[O*3+1]=f[1]*H+f[5]*Y+f[9]*W+f[13],M[O*3+2]=f[2]*H+f[6]*Y+f[10]*W+f[14]}let _,I=w.attributes?.NORMAL;if(I!==void 0){let{acc:O,buffer:H}=a(I),Y=new Float32Array(H,0,O.count*3);_=new Float32Array(Y.length);for(let W=0;W<O.count;W++){let fe=Y[W*3],ee=Y[W*3+1],ne=Y[W*3+2],ge=L[0]*fe+L[3]*ee+L[6]*ne,xe=L[1]*fe+L[4]*ee+L[7]*ne,de=L[2]*fe+L[5]*ee+L[8]*ne,oe=Math.hypot(ge,xe,de)||1;_[W*3]=ge/oe,_[W*3+1]=xe/oe,_[W*3+2]=de/oe}}let g,v=w.attributes?.TEXCOORD_0;if(v!==void 0){let{acc:O,buffer:H}=a(v);g=new Float32Array(H,0,O.count*2)}let x;if(w.indices!==void 0){let{acc:O,buffer:H}=a(w.indices);O.componentType===5125?x=new Uint32Array(H,0,O.count):x=new Uint16Array(H,0,O.count);let Y=R.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 O=R.count;x=O>65535?new Uint32Array(O):new Uint16Array(O);for(let H=0;H<O;H++)x[H]=H}let P="DefaultMaterial",D=[.8,.8,.8],V=.5,N=.1,U=0,F=0,C=1.5,B=1,k=[0,0,0];if(w.material!==void 0&&m[w.material]){let O=m[w.material];P=O.name||`Material_${w.material}`;let H=O.pbrMetallicRoughness||{},Y=1;Array.isArray(H.baseColorFactor)&&(D=[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"&&(N=H.metallicFactor),Array.isArray(O.emissiveFactor)&&O.emissiveFactor.length>=3&&(k=[O.emissiveFactor[0],O.emissiveFactor[1],O.emissiveFactor[2]]);let W=O.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"&&(C=W.KHR_materials_ior.ior);let fe=W.KHR_materials_transmission?.transmissionFactor??0;B=Y*(1-fe)}let z=(S.primitives||[]).length>1?`${T}_p${b}`:T;e.push({name:z,positions:M,indices:x,normals:_,uvs:g,materialName:P,color:D,roughness:V,metallic:N,clearcoat:U,clearcoatRoughness:F,ior:C,opacity:B,emissiveColor:k,xrTraits:A?.xr||S.extras?.xr})}}if(o.length>0)for(let d=0;d<o.length;d++){let f=o[d];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(d)||q(),A=f.name||u[f.mesh].name||`Node_${d}`;l(f.mesh,T,A,f.extras)}}else{let d=q();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,d,T,u[f].extras)}}return e}function Wt(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 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 Tn(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 $t(n){let e=new Map;for(let u of n){let o=Wt(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
223
- endTimeCode = ${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)}
224
210
  timeCodesPerSecond = 1.0
225
- `);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
211
+ `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
226
212
  uniform token preliminary:planeAnchoring:alignment = "${r}"
227
213
  `);let c=`#usda 1.0
228
214
  (
@@ -235,21 +221,21 @@ def Xform "Root" (
235
221
  kind = "component"
236
222
  )
237
223
  {
238
- ${s}def Scope "Materials"
224
+ ${o}def Scope "Materials"
239
225
  {
240
- `;for(let[u,o]of e.entries()){let[a,h,l]=o.color,[d,f,T]=o.emissiveColor,A="";o.clearcoat>0&&(A+=`float inputs:clearcoat = ${G(o.clearcoat)}
241
- `,A+=`float inputs:clearcoatRoughness = ${G(o.clearcoatRoughness)}
242
- `),o.ior!==1.5&&(A+=`float inputs:ior = ${G(o.ior)}
243
- `),o.opacity<1&&(A+=`float inputs:opacity = ${G(o.opacity)}
244
- `),(d>0||f>0||T>0)&&(A+=`color3f inputs:emissiveColor = (${G(d)}, ${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)})
245
231
  `),c+=`def Material "${u}"
246
232
  {
247
233
  def Shader "PBRShader"
248
234
  {
249
235
  uniform token info:id = "UsdPreviewSurface"
250
- color3f inputs:diffuseColor = (${G(a)}, ${G(h)}, ${G(l)})
251
- float inputs:metallic = ${G(o.metallic)}
252
- float inputs:roughness = ${G(o.roughness)}
236
+ color3f inputs:diffuseColor = (${X(a)}, ${X(h)}, ${X(l)})
237
+ float inputs:metallic = ${X(s.metallic)}
238
+ float inputs:roughness = ${X(s.roughness)}
253
239
  ${A}token outputs:surface
254
240
  }
255
241
  token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
@@ -257,41 +243,41 @@ token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
257
243
  `}c+=`}
258
244
  def Scope "Meshes"
259
245
  {
260
- `;let m=new Set;for(let u=0;u<n.length;u++){let o=n[u],a=o.positions.length/3,h=1/0,l=1/0,d=1/0,f=-1/0,T=-1/0,A=-1/0;for(let p=0;p<a;p++){let E=o.positions[p*3],M=o.positions[p*3+1],_=o.positions[p*3+2];E<h&&(h=E),E>f&&(f=E),M<l&&(l=M),M>T&&(T=M),_<d&&(d=_),_>A&&(A=_)}isFinite(h)||(h=l=d=-1,f=T=A=1);let S=Math.floor(o.indices.length/3),L=Wt(o.materialName,"DefaultMaterial"),b=Wt(o.name,`Mesh_${u}`);m.has(b)&&(b=`${b}_${u}`),m.add(b);let w=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",y=o.xrTraits,R="";if(y){let p=[];y.physics&&y.physics!=="none"&&p.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let E=J().xrTraitSerializer?.usdLines(y,wn)??[];if(!E.length)for(let M of["grab","billboard","follow","anchor","physics"]){let _=M==="follow"&&typeof y.follow=="object"?y.follow.mode??"head":y[M];_!==void 0&&E.push(`string ${M} = "${wn(_)}"`)}E.length>0&&p.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 = {
261
247
  dictionary xr = {
262
248
  ${E.join(`
263
249
  `)}
264
250
  }
265
- }`),p.length>0&&(R=` (
251
+ }`),p.length>0&&(M=` (
266
252
  ${p.join(`
267
253
  `)}
268
- )`)}if(c+=`def Mesh "${b}"${R}
254
+ )`)}if(c+=`def Mesh "${y}"${M}
269
255
  {
270
- `,y?.physics&&y.physics!=="none"){let p=y.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
256
+ `,b?.physics&&b.physics!=="none"){let p=b.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
271
257
  bool physics:kinematicEnabled = ${p}
272
258
  bool physics:collisionEnabled = true
273
- `}if(o.timeSamples&&o.timeSamples.times.length>0){let p=o.timeSamples,E=p.times.map((I,g)=>{let v=p.translations?.[g]||[0,0,0];return`${G(I)}: (${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", "),M=p.times.map((I,g)=>{let v=p.rotations?.[g]||[0,0,0,1];return`${G(I)}: (${G(v[3])}, ${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", "),_=p.times.map((I,g)=>{let v=p.scales?.[g]||[1,1,1];return`${G(I)}: (${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${E} }
274
- quatf xformOp:orient.timeSamples = { ${M} }
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} }
260
+ quatf xformOp:orient.timeSamples = { ${v} }
275
261
  double3 xformOp:scale.timeSamples = { ${_} }
276
262
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
277
- `}c+=`float3[] extent = [(${G(h)}, ${G(l)}, ${G(d)}), (${G(f)}, ${G(T)}, ${G(A)})]
263
+ `}c+=`float3[] extent = [(${X(h)}, ${X(l)}, ${X(d)}), (${X(f)}, ${X(S)}, ${X(A)})]
278
264
  int[] faceVertexCounts = [${w}]
279
- int[] faceVertexIndices = [${mr(o.indices)}]
280
- point3f[] points = [${Tn(o.positions)}]
281
- `,o.normals&&o.normals.length===o.positions.length&&(c+=`normal3f[] normals = [${Tn(o.normals)}] (
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)}] (
282
268
  interpolation = "vertex"
283
269
  )
284
- `),o.uvs&&o.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${hr(o.uvs,a)}] (
270
+ `),s.uvs&&s.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${yr(s.uvs,a)}] (
285
271
  interpolation = "vertex"
286
272
  )
287
- `),c+=`rel material:binding = </Root/Materials/${L}>
273
+ `),c+=`rel material:binding = </Root/Materials/${P}>
288
274
  }
289
275
  `}return c+=`}
290
276
  }
291
- `,c}function fr(n,e){if(n&&typeof n.traverse=="function"){let i=lr(n,e);return $t(i)}let t=Be(n),r=En(t);return $t(r)}var ct=null;function dr(n){{let t=globalThis.__three_live_native_crc32__;if(typeof t=="function")return t(n)}if(!ct){ct=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;ct[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=ct[(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=ut(a.filename),l=dr(a.data),d=a.data.length,f=30+h.length,T=t+f,A=0,S=T%64;S!==0&&(A=64-S);let L=new Uint8Array(f+A),b=new DataView(L.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,l,!0),b.setUint32(18,d,!0),b.setUint32(22,d,!0),b.setUint16(26,h.length,!0),b.setUint16(28,A,!0),L.set(h,30),A>0&&L.fill(0,30+h.length),e.push({offset:t,size:d,crc:l,filenameBytes:h,entry:a}),r.push(L),r.push(a.data),t+=L.length+a.data.length}let i=t;for(let a of e){let h=new Uint8Array(46+a.filenameBytes.length),l=new DataView(h.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),h.set(a.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,c=new Uint8Array(22),m=new DataView(c.buffer);m.setUint32(0,101010256,!0),m.setUint16(4,0,!0),m.setUint16(6,0,!0),m.setUint16(8,e.length,!0),m.setUint16(10,e.length,!0),m.setUint32(12,s,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),o=0;for(let a of r)u.set(a,o),o+=a.length;return u}function Le(n){let e=fr(n),t=ut(e);return Mn([{filename:"model.usda",data:t}])}function lt(n){let e=Be(n),t=En(e),r=$t(t),i=ut(r);return Mn([{filename:"model.usda",data:i}])}function Yt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Le(n):lt(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 jt(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:jt(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),s=jt(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:s,speed:Q(e.speed,.05,10,1)}}var wr=4e3;function Tr(n){if(!n)return null;let e=le(n)??{};return{prompt:Kt(e.prompt,wr)??"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 qt(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=qt(n);return r?{src:r,refDistance:1,loop:!1}:null}let e=le(n),t=qt(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 ht(n){let e=le(n);if(!e)return null;let t=Array.isArray(e.traits)?e.traits:[],r=b=>t.includes(b),i={},s=e.grab;s==="1-hand"||s==="2-hand"?i.grab=s:(s===!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 b=le(c)??{},w=Q(b.min,.001,1e3,.05);i.scale={min:w,max:Q(b.max,w,1e3,Math.max(w,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,o=typeof u=="string"?u:le(u)?.mode;if(typeof u=="string"?u:le(u)?.lazy===!1)i.follow=o==="hand-left"||o==="hand-right"?o:"head";else{let b=pr(u);b&&(i.follow=b)}let a=e.anchor;typeof a=="string"&&Rr.has(a)&&(i.anchor=a),(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 d=vr(e.particles);d&&(i.particles=d);let f=Tr(e.holdToAsk);f&&(i.holdToAsk=f);let T=Er(e.worldUnderstanding);T&&(i.worldUnderstanding=T);let A=qt(e.splatUrl);A&&(i.splatUrl=A);let S=Kt(e.spatialSlot);S&&(i.spatialSlot=S);let L=Mr(e.audio);return L&&(i.audio=L),e.pointerEvents==="none"&&(i.pointerEvents="none"),Object.keys(i).length>0?i:null}function Zt(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[s,c]of Object.entries(i)){let m=r+s[0].toUpperCase()+s.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[m]=c:jt(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=ht(e);t&&(n.extras={...n.extras,xr:{...n.extras?.xr,...t}},n.extensions={...n.extensions,MOZ_hubs_components:Jt(t),ANDROID_xr_scenecore:Zt(t)})}function Jt(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=ht(n),r=[];if(!t)return r;for(let[i,s]of Object.entries(Ar(t)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof s=="boolean"?r.push(`bool ${i} = ${s}`):typeof s=="number"?Number.isFinite(s)&&r.push(`double ${i} = ${s}`):typeof s=="string"?r.push(`string ${i} = "${e(s)}"`):s.length===3&&s.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${s.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 mt=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}},j=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-s*m,this.y=s*c-r*u,this.z=r*m-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,c=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*c,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*c,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*c,this}},ft=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}},Xe=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}},Ge=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(s/2),o=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(s/2);return this._x=o*m*u+c*a*h,this._y=c*a*u-o*m*h,this._z=c*m*h+o*a*u,this._w=c*m*u-o*a*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,c=e.w,m=t.x,u=t.y,o=t.z,a=t.w;return this._x=r*a+c*m+i*o-s*u,this._y=i*a+c*u+s*m-r*o,this._z=s*a+c*o+r*u-i*m,this._w=c*a-r*m-i*u-s*o,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},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 st(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 Ce(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 j(0,0,0),r=new j(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}},dt=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 s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},pt=class extends X{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},bt=class extends X{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},yt=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 j,s=new j,c=new j,m=new j,u=new j;if(this.index){let o=this.index.array;for(let a=0;a<o.length;a+=3){let h=o[a],l=o[a+1],d=o[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(d),e.getY(d),e.getZ(d)),m.subVectors(c,s),u.subVectors(i,s),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 o=0;o<t;o+=3){i.set(e.getX(o),e.getY(o),e.getZ(o)),s.set(e.getX(o+1),e.getY(o+1),e.getZ(o+1)),c.set(e.getX(o+2),e.getY(o+2),e.getZ(o+2)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let a=0;a<3;a++)r[(o+a)*3]=m.x,r[(o+a)*3+1]=m.y,r[(o+a)*3+2]=m.z}for(let o=0;o<t;o++){let a=r[o*3],h=r[o*3+1],l=r[o*3+2],d=Math.hypot(a,h,l)||1;r[o*3]=a/d,r[o*3+1]=h/d,r[o*3+2]=l/d}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(){}},We=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,s=t/2,c=r/2,m=[-i,-s,c,i,-s,c,i,s,c,-i,s,c,i,-s,-c,-i,-s,-c,-i,s,-c,i,s,-c,-i,s,c,i,s,c,i,s,-c,-i,s,-c,-i,-s,-c,i,-s,-c,i,-s,c,-i,-s,c,i,-s,c,i,-s,-c,i,s,-c,i,s,c,-i,-s,-c,-i,-s,c,-i,s,c,-i,s,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],o=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let h=0;h<6;h++){let l=h*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new X(new Float32Array(m),3)),this.setAttribute("normal",new X(new Float32Array(u),3)),this.setAttribute("uv",new X(new Float32Array(o),2)),this.setIndex(a)}},gt=class extends ce{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},$e=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 o=globalThis.__three_live_native_sphere__;if(typeof o=="function"){let a=o(e,t,r);this.setAttribute("position",new X(a.positions,3)),this.setAttribute("normal",new X(a.normals,3)),this.setAttribute("uv",new X(a.uvs,2)),this.setIndex(a.indices);return}}let i=[],s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=[],h=o/r;for(let l=0;l<=t;l++){let d=l/t,f=d*Math.PI*2,T=h*Math.PI,A=-e*Math.cos(f)*Math.sin(T),S=e*Math.cos(T),L=e*Math.sin(f)*Math.sin(T);i.push(A,S,L);let b=Math.hypot(A,S,L)||1;s.push(A/b,S/b,L/b),c.push(d,1-h),a.push(i.length/3-1)}u.push(a)}for(let o=0;o<r;o++)for(let a=0;a<t;a++){let h=u[o][a+1],l=u[o][a],d=u[o+1][a],f=u[o+1][a+1];o!==0&&m.push(h,l,f),o!==r-1&&m.push(l,d,f)}this.setAttribute("position",new X(new Float32Array(i),3)),this.setAttribute("normal",new X(new Float32Array(s),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 a=globalThis.__three_live_native_cylinder__;if(typeof a=="function"){let h=a(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 s=[],c=[],m=[],u=[],o=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,d=a===0?o:-o;for(let f=0;f<=i;f++){let T=f/i,A=T*Math.PI*2,S=Math.sin(A),L=Math.cos(A);s.push(l*S,d,l*L),c.push(S,0,L),m.push(T,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=s.length/3;s.push(0,o,0),c.push(0,1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),T=Math.cos(d);s.push(e*f,o,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(a,h+l,h+l+1)}if(t>0){let a=s.length/3;s.push(0,-o,0),c.push(0,-1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),T=Math.cos(d);s.push(t*f,-o,t*T),c.push(0,-1,0),m.push(T*.5+.5,1-(f*.5+.5))}for(let l=0;l<i;l++)u.push(a,h+l+1,h+l)}this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},xt=class extends Ee{constructor(e=1,t=1,r=16){super(0,e,t,r)}},vt=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 s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=o/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,d=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),T=t*Math.sin(a);s.push(d,f,T);let A=e*Math.cos(l),S=e*Math.sin(l),L=d-A,b=f-S,w=T,y=Math.hypot(L,b,w)||1;c.push(L/y,b/y,w/y),m.push(h/i,o/r)}}for(let o=1;o<=r;o++)for(let a=1;a<=i;a++){let h=(i+1)*o+a-1,l=(i+1)*(o-1)+a-1,d=(i+1)*(o-1)+a,f=(i+1)*o+a;u.push(h,l,f,l,d,f)}this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},wt=class extends ce{constructor(e=1,t=.4,r=64,i=8,s=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let b=globalThis.__three_live_native_torus_knot__;if(typeof b=="function"){let w=b(e,t,r,i,s,c);this.setAttribute("position",new X(w.positions,3)),this.setAttribute("normal",new X(w.normals,3)),this.setAttribute("uv",new X(w.uvs,2)),this.setIndex(w.indices);return}}let m=[],u=[],o=[],a=[],h=new j,l=new j,d=new j,f=new j,T=new j;function A(b,w){let y=Math.cos(w),R=Math.sin(w),p=c/s*w,E=e*(2+Math.cos(p))*.5;b.set(E*y,E*R,e*Math.sin(p)*.5)}let S=[];for(let b=0;b<=i;++b){let w=b/i*Math.PI*2;S.push(-t*Math.cos(w),t*Math.sin(w),b/i)}for(let b=0;b<=r;++b){let w=b/r,y=w*s*Math.PI*2;A(h,y),A(l,y+.01),d.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(d,f).normalize(),f.crossVectors(T,d).normalize();for(let R=0;R<=i;++R){let p=R*3,E=S[p],M=S[p+1],_=S[p+2],I=E*f.x+M*T.x,g=E*f.y+M*T.y,v=E*f.z+M*T.z;m.push(h.x+I,h.y+g,h.z+v);let x=Math.hypot(I,g,v)||1;u.push(I/x,g/x,v/x),o.push(w,_)}}let L=i+1;for(let b=1;b<=r;b++){let w=L*(b-1),y=w+L;for(let R=1;R<=i;R++){let p=w+(R-1),E=y+(R-1),M=y+R,_=w+R;a.push(p,E,_,E,M,_)}}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(o),2)),this.setIndex(a)}},Ye=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 Ye(e);return t?.(r),r}};function te(n,e){return n!==void 0?Number(n):e}function Qt(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=Qt(e.transparent,!1),this.wireframe=Qt(e.wireframe,!1),this.side=te(e.side,2),this.doubleSided=Qt(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{},Et=class extends me{},Mt=class extends me{},Rt=class extends me{},St=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 j,this.rotation=new Xe,this.quaternion=new Ge,this.scale=new j(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 j(e,t,r);this.updateMatrixWorld(!0);let s=new ye;s.lookAt(this.position,i,new j(0,1,0));let c=s.elements,m=c[0],u=c[4],o=c[8],a=c[1],h=c[5],l=c[9],d=c[2],f=c[6],T=c[10],A=m+h+T;if(A>0){let S=.5/Math.sqrt(A+1);this.quaternion.set((f-l)*S,(o-d)*S,(a-u)*S,.25/S)}}},At=class extends ie{},Ue=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?(se("unsupported geometry","BoxGeometry"),new We(.5,.5,.5)):new ce,this.material=i instanceof me?i:i?(se("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"}},qe=class extends Me{constructor(e,t){super(e,t),this.type="ambient"}},_t=class extends Me{constructor(t,r){super(t,r);this.target=new ie;this.type="directional"}},je=class extends Me{constructor(t,r,i=0,s=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=s}},Ke=class extends ie{},Fe=class extends Ke{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new j(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},Ae=class extends ie{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return pe.validate(this),Ie(this)}toGLB(){return pe.validate(this),ze(this)}toUSDZ(){return pe.validate(this),Le(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ue){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},en=Ie,tn=ze,Pn=Le;var pe=class{static validate(e){let t=0,r=0,i=0,s=new Set,c=(u,o,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${o}). Found: ${a}`)},m=(u,o)=>{if(!Number.isFinite(o))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(o)}), which cannot be bounds-checked.`);return o};e.traverse(u=>{if(u instanceof Ue){i++,i>1e3&&c("MESHES",1e3,i);let o=u.geometry;if(o){let a=0;if(o.attributes.position&&(a=m("vertex",o.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),o.index){let h=m("index",o.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=o.index.array;if(l&&a>0){let d=Math.min(h,l.length);for(let f=0;f<d;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=a)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&s.add(a.map),a.normalMap&&s.add(a.normalMap),a.roughnessMap&&s.add(a.roughnessMap)}}}),s.size>16&&c("TEXTURES",16,s.size);for(let u of s){let o=u,a=o.image,h=Number(a?.width??o.width??0)||0,l=Number(a?.height??o.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Dt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new 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=(s,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(s,c):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),c={};for(let[m,u]of s.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let s=en(e),c=tn(e),m=(s.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:m,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Sn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Ct=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 Pe=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:Pe},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Pe,construct:()=>Pe}),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 Ne(){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,Ne());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,Ve;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(Ve===void 0||_n!==t){_n=t;try{Ve=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Re(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Ve=null}}return Ve?Ve.createScriptURL(n):n}function Ir(n){J().sandboxEngineSrc=n}function nn(){let n=J().sandboxEngineSrc;if(n)return n;if(An)return An;try{if(typeof document>"u")return null;let e=Ne(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Re(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Lr(){let n=nn();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,Ne()).href}function Pr(n){J().sandboxIframeSrc=n}function Fn(){let n=J().sandboxIframeSrc;if(n)return n;let e=nn();if(!e||!Re(e))return null;let t=new URL(e,Ne());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,Ne()).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,Ne()).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,s=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(y){m({type:"ERROR",nonce:t,message:String(y)})}let o=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let y=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let R={createScriptURL:function(E){if(E!==r&&(!i||E!==i))throw new TypeError("Disallowed worker importScripts URL");return E}};s&&(R.createScript=function(E){return String(E)});let p=e.trustedTypes.createPolicy("three-live#worker-boot",R);y=p.createScriptURL(r),i&&(a=p.createScriptURL(i)),s&&typeof p.createScript=="function"&&(h=p.createScript.bind(p))}catch{}o(y)}catch(y){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(y&&y.message||y));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let y=0;y<c.length;y++){let R=c[y],p=e;for(;p&&p!==Object.prototype;){if(p!==e)try{delete p[R]}catch{}try{Object.defineProperty(p,R,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}}let 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 T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],A=!1;function S(y,R){if(y.type==="3D_MODEL_READY"){if(A)return;A=!0}y.nonce=t,R&&R.length?m(y,R):m(y)}let L=function(y,R){if(!y||T.indexOf(y.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");S(y,R)},b=e;for(;b&&b!==Object.prototype;){if(b===e||Object.prototype.hasOwnProperty.call(b,"postMessage"))try{Object.defineProperty(b,"postMessage",{value:L,writable:!1,configurable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}let w=!1;e.onmessage=function(y){let R=y&&y.data;if(!(!R||R.nonce!==t)&&!(R.type!=="EXECUTE"&&R.type!=="EXECUTE_URL")&&!w){w=!0;try{let p=new l.Scene,E=new l.PerspectiveCamera(60,1,.1,1e3),M=new l.WebGLRenderer({isSandboxed:!0});if(R.type==="EXECUTE_URL"){if(!i||R.scriptUrl!==i||typeof o!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=a||i,I=o;if(o=null,a=null,e.THREE=l,e.scene=p,e.camera=E,e.renderer=M,I(_),typeof e.__THREE_LIVE_SCENE__=="function"){let g=e.__THREE_LIVE_SCENE__(l,p,E,M);g&&typeof g.toGLB=="function"&&(p=g)}else e.scene&&typeof e.scene.toGLB=="function"&&(p=e.scene)}else{if(!s){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) {
292
278
  return (function () {
293
- `+R.script+`
279
+ `+M.script+`
294
280
  })();
295
281
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
296
- `+R.script+`
297
- })();`);h=null;let I=_(l,p,E,M);I&&typeof I.toGLB=="function"&&(p=I)}if(!A){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(p);let _=p.toGLB(),I=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);S({type:"3D_MODEL_READY",glbBuffer:I},[I])}m({type:"DONE",nonce:t})}catch(p){u(p&&p.message||p)}}},m({type:"READY",nonce:t})}function rn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:kr};return`'use strict';(${Or.toString()})(${JSON.stringify(s)});`}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 Te=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 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,zr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!Dn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let c=Object.create(null),m=i;for(let u of s){if(u.length>Vr||u==="__proto__"||u==="constructor"||u==="prototype")return null;let o=m[u];if(!Dn(o))return null;c[u]=o}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function 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(),s=rn(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,Te++;let m=!1,u=!1,o={modelDispatched:!1},a,h=()=>{if(m||u)return;let T=c.contentWindow;!T||typeof T.postMessage!="function"||(u=!0,T.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},l=()=>{},d=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let A=T.data;if(A&&typeof A=="object"&&A.type==="IFRAME_READY"){h();return}let S=sn(A,i);S&&Bn(S,r,l,o)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),Te=Math.max(0,Te-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(),kn(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 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(Te>=32)return r(`SecurityError: ${Te} 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 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=Ur()}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(Xr(n,i,l,t))}catch(d){return Promise.reject(d)}}let s=On(),c=rn(i,s,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=Un(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.")}Te++;let u=!1,o={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),Te=Math.max(0,Te-1),m.terminate())};return a=setTimeout(()=>{u||(h(),kn(t))},3e3),m.onmessage=l=>{let d=sn(l.data,s);d&&Bn(d,t,h,o)},m.onerror=l=>{h(),t.onError?.(new Error(`Worker execution error: ${l.message}`))},n.kind==="url"?m.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):m.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function 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 o=new Error(m);return t.onError?.(o),u&&t.onToast?.(u),Promise.reject(o)},s=In(e,i);if(s)return s;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(an,cn)},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 s;try{s=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:s},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 Vn(){return Array.from(It)}function on(){It.clear()}var Ze=class extends Se{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}},Hn=Ze,_e=class extends $e{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)}},Lt=class extends _e{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Pt=class extends _e{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Ut=class extends _e{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Ft=class extends _e{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Nt=class extends Ee{constructor(e=1,t=1,r=4,i=8){se("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},kt=class extends Ee{constructor(e=.5,t=1,r=16){se("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Ot=class extends Ee{constructor(e=1,t=16){se("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Bt=class extends je{constructor(t,r,i=0,s=Math.PI/3,c=0,m=2){se("SpotLight","PointLight");super(t,r,i,m);this.target=new ie;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=c}},Je=class extends qe{constructor(e,t,r){se("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new he(t??4473924)}},Xn=Je,Gn={Vector2:mt,Vector3:j,Vector4:ft,Euler:Xe,Quaternion:Ge,Matrix4:ye,Matrix3:dt,Color:he,MathUtils:Ln,BufferAttribute:X,Float32BufferAttribute:pt,Uint16BufferAttribute:bt,Uint32BufferAttribute:yt,BufferGeometry:ce,BoxGeometry:We,PlaneGeometry:gt,SphereGeometry:$e,CylinderGeometry:Ee,ConeGeometry:xt,TorusGeometry:vt,TorusKnotGeometry:wt,IcosahedronGeometry:Lt,OctahedronGeometry:Pt,DodecahedronGeometry:Ut,TetrahedronGeometry:Ft,CapsuleGeometry:Nt,RingGeometry:kt,CircleGeometry:Ot,Texture:Ye,TextureLoader:Tt,Material:me,MeshStandardMaterial:Se,MeshBasicMaterial:Et,MeshLambertMaterial:Mt,MeshPhongMaterial:Rt,MeshPhysicalMaterial:St,ShaderMaterial:Ze,RawShaderMaterial:Hn,Object3D:ie,Group:At,Mesh:Ue,Light:Me,AmbientLight:qe,DirectionalLight:_t,PointLight:je,SpotLight:Bt,HemisphereLight:Je,RectAreaLight:Xn,Camera:Ke,PerspectiveCamera:Fe,Scene:Ae,WebGLRenderer:Dt,Clock:Ct,SceneQuotaValidator:pe,exportSceneToCanvas3D:en,exportSceneToGLB:tn,exportSceneToUSDZ:Pn,generateUSDZ:Yt,glbToUSDZ:lt,sceneToCanvas3D:Ie,sceneToGLB:ze,sceneToUSDZ:Le,authorScriptRunner:zn,getAuthorWarnings:Vn,clearAuthorWarnings:on};Object.freeze(pe);Object.freeze(pe.prototype);Object.freeze(Ae.prototype);Object.freeze(Gn);var Qe=new Proxy(Gn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&se(`THREE.${e}`,"no-op proxy"),Pe),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")}}),He={name:"three_author",THREE:Qe},Gr=He,Z=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Z.THREE>"u"&&(Z.THREE=Qe);typeof Z.requestAnimationFrame!="function"&&(Z.requestAnimationFrame=()=>(se("requestAnimationFrame","single-frame static evaluation"),0));typeof Z.cancelAnimationFrame!="function"&&(Z.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Qe,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=He,n.ThreeLivePlugins.three_author=He,n.ThreeLivePlugins["three-author"]=He}{Rn();let n=new Ae,e=new Fe(45,1,.1,1e3);e.position.set(0,2,5),Z.scene=n,Z.camera=e,typeof Z.window>"u"&&(Z.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Z.document>"u"&&(Z.document={createElement:()=>({getContext:()=>Pe,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Z,"__three_live_reset_scene__",{value:function(){on(),n=new Ae,e=new Fe(45,1,.1,1e3),e.position.set(0,2,5),Z.scene=n,Z.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let o=2e4,a=new Set,h=(l,d)=>{if(--o<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 T of l)f.push(h(T,d+1)??null)}else{f={};for(let T of Object.keys(l)){if(T==="__proto__"||T==="prototype"||T==="constructor")continue;let A=h(l[T],d+1);A!==void 0&&(f[T]=A)}}return a.delete(l),f};try{return h(u,0)??null}catch{return null}},i=15*1024,s=1e3*4,c=function(u){let o=ht(u);if(!o)return{};let a=JSON.stringify({...u,...o});return a.length>i&&(se(`userData.xr larger than ${i} characters`,"canonical XR traits only"),a=JSON.stringify(o)),{xr_normalized_json:a,xr_scenecore_json:JSON.stringify(Zt(o)),xr_hubs_json:JSON.stringify(Jt(o))}};Object.defineProperty(Z,"__three_live_extract_scene_raw__",{value:function(){let u=[],o=[],a=[],h=[];function l(g){if(!g)return null;let v=h.indexOf(g);if(v===-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)),o.push({name:g.name||`Material_${o.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}),v=o.length-1}return v}let d=(g,v)=>typeof g=="number"&&Number.isFinite(g)?g:v,f=[],T=[],A=!1,S=Z.scene||n,L=new ye().compose({x:d(S.position?.x,0),y:d(S.position?.y,0),z:d(S.position?.z,0)},{x:d(S.quaternion?.x,0),y:d(S.quaternion?.y,0),z:d(S.quaternion?.z,0),w:d(S.quaternion?.w,1)},{x:d(S.scale?.x,1),y:d(S.scale?.y,1),z:d(S.scale?.z,1)}),b=new Set([S]);{let g=new Set([S]),v=Array.isArray(S.children)?[...S.children]:[],x=0;for(;v.length>0&&x<=s;){let P=v.pop();if(!(!(P instanceof ie)||g.has(P))&&(g.add(P),x++,Array.isArray(P.children)))for(let D of P.children)v.push(D)}if(x>s)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let w=[],y=(g,v)=>{let x=Array.isArray(g.children)?g.children:[];for(let P=x.length-1;P>=0;P--)w.push([x[P],v])};y(S,-1);let R=g=>{let v=[];for(let P=g;P>=0&&v.length<=f.length;P=f[P].parent)v.push(P);let x=L.clone();for(let P=v.length-1;P>=0;P--){let D=f[v[P]];x.multiply(new ye().compose({x:D.translation[0],y:D.translation[1],z:D.translation[2]},{x:D.rotation[0],y:D.rotation[1],z:D.rotation[2],w:D.rotation[3]},{x:D.scale[0],y:D.scale[1],z:D.scale[2]}))}return x};for(;w.length>0;){let[g,v]=w.pop();if(!(g instanceof ie)||b.has(g))continue;b.add(g);let x=[d(g.position?.x,0),d(g.position?.y,0),d(g.position?.z,0)],P=[d(g.quaternion?.x,0),d(g.quaternion?.y,0),d(g.quaternion?.z,0),d(g.quaternion?.w,1)],D=[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),C=!!g.userData?.xr&&F!==null,B=f.length;f.push({name:typeof g.name=="string"?g.name.slice(0,1024):"",parent:v,translation:x,rotation:P,scale:D,mesh:V,xr_traits_json:C?JSON.stringify(F):null,...C?c(F):{}});let k=r(g.userData?.interactivity);if(T.push(k),k&&(A=!0),f.length>s)break;if(g instanceof Me){let z=R(B).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)]})}y(g,B)}let p=(g,v)=>g.every((x,P)=>x===v[P]),E=r({interactivity:S.userData?.interactivity,gltfExtensions:{KHR_interactivity:S.userData?.gltfExtensions?.KHR_interactivity}}),M=!!(E?.interactivity??E?.gltfExtensions?.KHR_interactivity),_=null;(A||M)&&(_=nt(f.map((g,v)=>({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:T[v]?{interactivity:T[v]}:void 0})),u.map(g=>({primitives:[{material:g.material_index??0}]})),E??void 0));let I=Z.camera||e;return{meshes:u,nodes:f,materials:o,lights:a,interactivity_json:_?JSON.stringify(_):null,camera:{fov:I.fov||45,position:I.position?[I.position.x,I.position.y,I.position.z]:[0,2,5],target:I.target?[I.target.x,I.target.y,I.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Wr=Qe;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);})();