three-live 1.2.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +22 -0
  3. package/dist/three-author-engine.js +28 -26
  4. package/dist/three-author.cjs +29 -27
  5. package/dist/three-author.d.ts +22 -0
  6. package/dist/three-author.js +29 -27
  7. package/dist/three-convert.cjs +21 -19
  8. package/dist/three-convert.d.ts +22 -0
  9. package/dist/three-convert.js +21 -19
  10. package/dist/three-live-animation.cjs +4 -4
  11. package/dist/three-live-animation.d.ts +22 -0
  12. package/dist/three-live-animation.js +4 -4
  13. package/dist/three-live-animation.min.js +4 -4
  14. package/dist/three-live-cad.cjs +2 -2
  15. package/dist/three-live-cad.d.ts +22 -0
  16. package/dist/three-live-cad.js +2 -2
  17. package/dist/three-live-cad.min.js +2 -2
  18. package/dist/three-live-element.cjs +5 -3
  19. package/dist/three-live-element.d.ts +22 -0
  20. package/dist/three-live-element.js +5 -3
  21. package/dist/three-live-full.cjs +48 -46
  22. package/dist/three-live-full.js +47 -45
  23. package/dist/three-live-full.min.js +48 -46
  24. package/dist/three-live-studio.cjs +10 -10
  25. package/dist/three-live-studio.d.ts +22 -0
  26. package/dist/three-live-studio.js +10 -10
  27. package/dist/three-live-studio.min.js +10 -10
  28. package/dist/three-live-viewer.cjs +5 -3
  29. package/dist/three-live-viewer.d.ts +22 -0
  30. package/dist/three-live-viewer.js +5 -3
  31. package/dist/three-live-viewer.min.js +5 -3
  32. package/dist/three-live.cjs +23 -21
  33. package/dist/three-live.js +25 -23
  34. package/dist/three-live.min.js +23 -21
  35. package/dist/three-view.cjs +8 -6
  36. package/dist/three-view.d.ts +22 -0
  37. package/dist/three-view.js +8 -6
  38. package/dist/three-xr.cjs +24 -22
  39. package/dist/three-xr.d.ts +22 -0
  40. package/dist/three-xr.js +24 -22
  41. package/package.json +1 -1
@@ -14,8 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- function _e(n,e,t){let r=[],i=new Map,s=[],a=[],d=[],o=new Map,c=m=>{let E=i.get(m);return E===void 0&&(E=r.length,r.push({op:m}),i.set(m,E)),E},u=m=>{let E=o.get(m);return E===void 0&&(E=d.length,d.push({id:m}),o.set(m,E)),E},b=(m,E={})=>s.push({declaration:c(m),...E})-1,v=(m,E,f)=>a.push({id:m,type:E,value:f})-1,L=m=>({node:m,socket:"value"}),M=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(M&&typeof M=="object"){let m=Array.isArray(M.graphs)?M.graphs[M.graph??0]:M;if(m&&Array.isArray(m.nodes)){let E=Array.isArray(m.declarations)?m.declarations:[];for(let f of E)f?.op&&c(f.op);Array.isArray(m.variables)&&a.push(...m.variables);for(let f of m.events||[])f?.id&&u(f.id);for(let f of m.nodes){if(!f||typeof f!="object")continue;let S=f.op||(typeof f.declaration=="number"?E[f.declaration]?.op:"");s.push(S?{...f,declaration:c(S)}:{...f})}}}let R=(m,E,f="translation")=>f==="baseColorFactor"||f==="metallicFactor"||f==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${f}`:f==="emissiveFactor"||f==="alphaCutoff"?`/materials/${Math.max(0,E)}/${f}`:f==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${f}`,T=new Map;n.forEach((m,E)=>{typeof m?.name=="string"&&!T.has(m.name)&&T.set(m.name,E)});let I=(m,E)=>typeof m.target=="string"&&T.has(m.target)?T.get(m.target):typeof m.targetNode=="number"?m.targetNode:E,F=m=>{let E=n[m];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<n.length;m++){let E=n[m],f=E?.extras?.interactivity;if(!f||typeof f!="object")continue;let S=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,U=g=>{let D=Array.isArray(g)?g:[g],l=[];for(let w=0;w<D.length;w++){let p=D[w];if(!p||typeof p!="object")continue;let y=p.action||"interpolate",_=typeof p.duration=="number"?p.duration:.35;if(y==="toggleTransform"){let P=p.property==="rotation"||p.property==="scale"?p.property:"translation",G=P==="rotation"?E.rotation||[0,0,0,1]:P==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],N=`/nodes/${m}/${P}`,k=v(`__toggle_${m}_${w}`,"bool",!1),x=b("variable/get",{configuration:{variable:k}}),H=b("math/not",{values:{a:L(x)}}),O=b("variable/set",{configuration:{variable:k},values:{value:L(H)}}),B=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.to)?p.to:G},duration:{value:_}}}),z=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.from)?p.from:G},duration:{value:_}}});s[O].flows={out:{node:b("flow/branch",{values:{condition:L(x)},flows:{true:{node:B},false:{node:z}}})}},l.push(O)}else if(y==="interpolate"){let P=p.to??p.value;if(P===void 0)continue;let G={value:{value:P},duration:{value:_}};p.from!==void 0&&(G.from={value:p.from}),l.push(b("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:R(I(p,m),F(I(p,m)),p.property)},values:G}))}else if(y==="setProperty"){if(p.value===void 0)continue;l.push(b("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:R(I(p,m),F(I(p,m)),p.property)},values:{value:{value:p.value}}}))}else if(y==="toggleVisibility"){let P=I(p,m),G=v(`__vis_${P}_${w}`,"bool",!0),N=b("variable/get",{configuration:{variable:G}}),k=b("math/not",{values:{a:L(N)}}),x=b("variable/set",{configuration:{variable:G},values:{value:L(k)}});s[x].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${P}/extensions/KHR_node_visibility/visible`},values:{value:L(N)}})}},l.push(x)}else if(y==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let P=typeof p.duration=="number"?p.duration:.25,G=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,N=v(`__color_idx_${m}_${w}`,"int",0),k=b("variable/get",{configuration:{variable:N}}),x=b("math/add",{values:{a:L(k),b:{value:1}}}),H=b("math/rem",{values:{a:L(x),b:{value:p.colors.length}}}),O=b("variable/set",{configuration:{variable:N},values:{value:L(H)}}),B={};for(let z=0;z<p.colors.length;z++){let C=p.colors[z],V=Array.isArray(C)&&C.length>=3?[C[0],C[1],C[2],C[3]??1]:[1,1,1,1];B[String(z)]={node:P>0?b("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:V},duration:{value:P}}}):b("pointer/set",{configuration:{pointer:G},values:{value:{value:V}}})}}s[O].flows={out:{node:b("flow/switch",{values:{selection:L(k)},flows:B})}},l.push(O)}else if(y==="playAnimation")l.push(b("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(y==="stopAnimation")l.push(b("animation/stop"));else if(y==="sendEvent"){let P={};for(let[G,N]of Object.entries(p.values||{}))P[G]={value:N};l.push(b("event/send",{configuration:{event:u(String(p.event??p.id??"custom"))},values:P}))}}if(!l.length)return null;if(l.length===1)return l[0];let h={};return l.forEach((w,p)=>{h[String(p)]={node:w}}),b("flow/sequence",{flows:h})},A=(g,D,l)=>{let h=U(D);h!==null&&b(g,{...l?{configuration:l}:{},flows:{out:{node:h}}})};if(f.onSelect&&A("pointer/onSelect",f.onSelect,{nodeIndex:m}),f.onHoverIn&&A("pointer/onHoverIn",f.onHoverIn,{nodeIndex:m}),f.onHoverOut&&A("pointer/onHoverOut",f.onHoverOut,{nodeIndex:m}),f.onStart&&A("event/onStart",f.onStart),f.onReceive&&typeof f.onReceive=="object")for(let[g,D]of Object.entries(f.onReceive))A("event/receive",D,{event:u(g)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:d}],graph:0}:null}var ge="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ge]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ge,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ge]=e}}return n[ge]}var ne=ue().plugins;function Ne(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function Be(){return ue().plugins}var nt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function we(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=t.componentType??5126,d=nt[a];if(!d)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let o=d*r,c=i.byteStride&&i.byteStride>0?i.byteStride:o,u=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(u)||u<0||c<o||u+(s-1)*c+o>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&c===o&&u%4===0)return new Float32Array(e,u,s*r);let b=new DataView(e),v=t.normalized===!0,L=new Float32Array(s*r);for(let M=0;M<s;M++){let R=u+M*c;for(let T=0;T<r;T++){let I=R+T*d,F;switch(a){case 5126:F=b.getFloat32(I,!0);break;case 5120:F=b.getInt8(I),v&&(F=Math.max(F/127,-1));break;case 5121:F=b.getUint8(I),v&&(F/=255);break;case 5122:F=b.getInt16(I,!0),v&&(F=Math.max(F/32767,-1));break;case 5123:F=b.getUint16(I,!0),v&&(F/=65535);break;default:F=b.getUint32(I,!0),v&&(F/=4294967295)}L[M*r+T]=F}}return L}function Ue(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,d=Math.cos(a),o=Math.sin(a),c=(Number.isFinite(i)?i:1)*d,u=(Number.isFinite(i)?i:1)*o,b=-(Number.isFinite(s)?s:1)*o,v=(Number.isFinite(s)?s:1)*d;for(let L=0;L+1<n.length;L+=2){let M=n[L],R=n[L+1];n[L]=c*M+u*R+t,n[L+1]=b*M+v*R+r}}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function ye(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 a=1/(r-i);return n[10]=(i+r)*a,n[14]=2*i*r*a,n}function ve(n,e,t,r){let[i,s,a]=e,[d,o,c]=r,[u,b,v]=t,L=i-u,M=s-b,R=a-v,T=Math.hypot(L,M,R);T<=1e-5?(L=0,M=0,R=1):(L/=T,M/=T,R/=T);let I=o*R-c*M,F=c*L-d*R,m=d*M-o*L;T=Math.hypot(I,F,m),T<=1e-5?(I=0,F=0,m=0):(I/=T,F/=T,m/=T);let E=M*m-R*F,f=R*I-L*m,S=L*F-M*I;return T=Math.hypot(E,f,S),T<=1e-5?(E=0,f=0,S=0):(E/=T,f/=T,S/=T),n[0]=I,n[1]=E,n[2]=L,n[3]=0,n[4]=F,n[5]=f,n[6]=M,n[7]=0,n[8]=m,n[9]=S,n[10]=R,n[11]=0,n[12]=-(I*i+F*s+m*a),n[13]=-(E*i+f*s+S*a),n[14]=-(L*i+M*s+R*a),n[15]=1,n}function ee(n,e,t){let r=e[0],i=e[1],s=e[2],a=e[3],d=e[4],o=e[5],c=e[6],u=e[7],b=e[8],v=e[9],L=e[10],M=e[11],R=e[12],T=e[13],I=e[14],F=e[15],m=t[0],E=t[1],f=t[2],S=t[3];return n[0]=m*r+E*d+f*b+S*R,n[1]=m*i+E*o+f*v+S*T,n[2]=m*s+E*c+f*L+S*I,n[3]=m*a+E*u+f*M+S*F,m=t[4],E=t[5],f=t[6],S=t[7],n[4]=m*r+E*d+f*b+S*R,n[5]=m*i+E*o+f*v+S*T,n[6]=m*s+E*c+f*L+S*I,n[7]=m*a+E*u+f*M+S*F,m=t[8],E=t[9],f=t[10],S=t[11],n[8]=m*r+E*d+f*b+S*R,n[9]=m*i+E*o+f*v+S*T,n[10]=m*s+E*c+f*L+S*I,n[11]=m*a+E*u+f*M+S*F,m=t[12],E=t[13],f=t[14],S=t[15],n[12]=m*r+E*d+f*b+S*R,n[13]=m*i+E*o+f*v+S*T,n[14]=m*s+E*c+f*L+S*I,n[15]=m*a+E*u+f*M+S*F,n}function he(n,e,t,r){let i=e[0],s=e[1],a=e[2],d=e[3],o=i+i,c=s+s,u=a+a,b=i*o,v=i*c,L=i*u,M=s*c,R=s*u,T=a*u,I=d*o,F=d*c,m=d*u,E=r[0],f=r[1],S=r[2];return n[0]=(1-(M+T))*E,n[1]=(v+m)*E,n[2]=(L-F)*E,n[3]=0,n[4]=(v-m)*f,n[5]=(1-(b+T))*f,n[6]=(R+I)*f,n[7]=0,n[8]=(L+F)*S,n[9]=(R-I)*S,n[10]=(1-(b+M))*S,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],a=e[5],d=e[6],o=e[8],c=e[9],u=e[10],b=u*a-d*c,v=-u*s+d*o,L=c*s-a*o,M=t*b+r*v+i*L;return M&&(M=1/M,n[0]=b*M,n[1]=v*M,n[2]=L*M,n[3]=(-u*r+i*c)*M,n[4]=(u*t-i*o)*M,n[5]=(-c*t+r*o)*M,n[6]=(d*r-i*a)*M,n[7]=(-d*t+i*s)*M,n[8]=(a*t-r*s)*M),n}function ke(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],d=e[5],o=e[6],c=e[7],u=e[8],b=e[9],v=e[10],L=e[11],M=e[12],R=e[13],T=e[14],I=e[15],F=t*d-r*a,m=t*o-i*a,E=t*c-s*a,f=r*o-i*d,S=r*c-s*d,U=i*c-s*o,A=u*R-b*M,g=u*T-v*M,D=u*I-L*M,l=b*T-v*R,h=b*I-L*R,w=v*I-L*T,p=F*w-m*h+E*l+f*D-S*g+U*A;return p?(p=1/p,n[0]=(d*w-o*h+c*l)*p,n[1]=(i*h-r*w-s*l)*p,n[2]=(R*U-T*S+I*f)*p,n[3]=(v*S-b*U-L*f)*p,n[4]=(o*D-a*w-c*g)*p,n[5]=(t*w-i*D+s*g)*p,n[6]=(T*E-M*U-I*m)*p,n[7]=(u*U-v*E+L*m)*p,n[8]=(a*h-d*D+c*A)*p,n[9]=(r*D-t*h-s*A)*p,n[10]=(M*S-R*E+I*F)*p,n[11]=(b*E-u*S-L*F)*p,n[12]=(d*g-a*l-o*A)*p,n[13]=(t*l-r*g+i*A)*p,n[14]=(R*m-M*f-T*F)*p,n[15]=(u*f-b*m+v*F)*p,n):null}function Ee(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],a=i[1]*e+i[5]*t+i[9]*r+i[13],d=i[2]*e+i[6]*t+i[10]*r+i[14],o=i[3]*e+i[7]*t+i[11]*r+i[15],c=o!==0?1/o:1;n[0]=s*c,n[1]=a*c,n[2]=d*c}function Ge(n,e,t,r,i,s,a,d,o,c,u,b,v,L,M,R,T=0){let I=c-a,F=u-d,m=b-o,E=v-a,f=L-d,S=M-o,U=i*S-s*f,A=s*E-r*S,g=r*f-i*E,D=I*U+F*A+m*g;if(D>-1e-7&&D<1e-7)return!1;let l=1/D,h=n-a,w=e-d,p=t-o,y=l*(h*U+w*A+p*g);if(y<-T||y>1+T)return!1;let _=w*m-p*F,P=p*I-h*m,G=h*F-w*I,N=l*(r*_+i*P+s*G);if(N<-T||y+N>1+T)return!1;let k=l*(E*_+f*P+S*G);if(k>1e-4&&k<R.distance){R.distance=k,R.point=[n+r*k,e+i*k,t+s*k];let x=F*S-m*f,H=m*E-I*S,O=I*f-F*E,B=Math.hypot(x,H,O)||1;return R.normal=[x/B,H/B,O/B],!0}return!1}function xe(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let u=0;u<t;u++)r.push(J());if(t===0)return r;let i=new Set;for(let u of n.nodes)if(Array.isArray(u.children))for(let b of u.children)i.add(b);let s=new Set,a=128,d=(u,b,v=0)=>{if(v>a||u<0||u>=t||s.has(u))return;s.add(u);let L=n.nodes[u];if(!L)return;let M=J();if(e&&e[u])M.set(e[u]);else if(L.matrix&&L.matrix.length===16)M.set(L.matrix);else{let T=L.translation||[0,0,0],I=L.rotation||[0,0,0,1],F=L.scale||[1,1,1];he(M,I,T,F)}let R=r[u];if(b?ee(R,b,M):R.set(M),Array.isArray(L.children))for(let T of L.children)typeof T=="number"&&d(T,R,v+1)},o=[],c=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(c&&Array.isArray(c.nodes))o.push(...c.nodes);else for(let u=0;u<t;u++)i.has(u)||o.push(u);for(let u of o)d(u,null);for(let u=0;u<t;u++)!i.has(u)&&!o.includes(u)&&d(u,null);return r}var ze=["neutral","reinhard","none","aces","agx"];function Le(n){let e=String(n??"").trim().toLowerCase();return ze.includes(e)?e:"neutral"}function rt(n){return ze.indexOf(Le(n))}function it(n){return new TextDecoder().decode(n)}var $e=ue().decoders;function st(n,e){$e.set(n.toLowerCase(),e)}function me(n){return $e.get(n.toLowerCase())}function We(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 v=t.getUint8(0);throw v===123||v===32||v===10||v===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),a=12,d=null,o=null;for(;a+8<=s&&a+8<=e.byteLength;){let v=t.getUint32(a,!0),L=t.getUint32(a+4,!0),M=a+8;if(M+v>e.byteLength)throw new Error(`Truncated GLB chunk: required ${M+v} bytes, buffer has ${e.byteLength}`);if(L===1313821514){let R=new Uint8Array(e,M,v),T=it(R);d=JSON.parse(T,(I,F)=>I==="__proto__"||I==="constructor"||I==="prototype"?void 0:F)}else L===5130562&&(o=e.slice(M,M+v));a=M+v}if(!d)throw new Error("Missing JSON chunk in GLB");let c=d.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let v of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(v)&&!me("meshopt"))throw new Error(`Model requires ${v}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=o||new ArrayBuffer(0),b={gltf:d,bin:u,animations:[]};for(let v of ne)v.onParseGLB?.(b);return b}function ot(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 de(n){if(ot(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return We(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xe=`#version 300 es
18
- layout(location=0) in vec3 aPosition;
17
+ function _e(n,e,t){let r=[],i=new Map,s=[],a=[],d=[],o=new Map,c=h=>{let w=i.get(h);return w===void 0&&(w=r.length,r.push({op:h}),i.set(h,w)),w},u=h=>{let w=o.get(h);return w===void 0&&(w=d.length,d.push({id:h}),o.set(h,w)),w},b=(h,w={})=>s.push({declaration:c(h),...w})-1,v=(h,w,f)=>a.push({id:h,type:w,value:f})-1,L=h=>({node:h,socket:"value"}),E=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(E&&typeof E=="object"){let h=Array.isArray(E.graphs)?E.graphs[E.graph??0]:E;if(h&&Array.isArray(h.nodes)){let w=Array.isArray(h.declarations)?h.declarations:[];for(let f of w)f?.op&&c(f.op);Array.isArray(h.variables)&&a.push(...h.variables);for(let f of h.events||[])f?.id&&u(f.id);for(let f of h.nodes){if(!f||typeof f!="object")continue;let S=f.op||(typeof f.declaration=="number"?w[f.declaration]?.op:"");s.push(S?{...f,declaration:c(S)}:{...f})}}}let x=(h,w,f="translation")=>f==="baseColorFactor"||f==="metallicFactor"||f==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${f}`:f==="emissiveFactor"||f==="alphaCutoff"?`/materials/${Math.max(0,w)}/${f}`:f==="visible"?`/nodes/${h}/extensions/KHR_node_visibility/visible`:`/nodes/${h}/${f}`,T=new Map;n.forEach((h,w)=>{typeof h?.name=="string"&&!T.has(h.name)&&T.set(h.name,w)});let I=(h,w)=>typeof h.target=="string"&&T.has(h.target)?T.get(h.target):typeof h.targetNode=="number"?h.targetNode:w,F=h=>{let w=n[h];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let h=0;h<n.length;h++){let w=n[h],f=w?.extras?.interactivity;if(!f||typeof f!="object")continue;let S=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,U=y=>{let D=Array.isArray(y)?y:[y],l=[];for(let R=0;R<D.length;R++){let p=D[R];if(!p||typeof p!="object")continue;let g=p.action||"interpolate",_=typeof p.duration=="number"?p.duration:.35;if(g==="toggleTransform"){let P=p.property==="rotation"||p.property==="scale"?p.property:"translation",G=P==="rotation"?w.rotation||[0,0,0,1]:P==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],N=`/nodes/${h}/${P}`,k=v(`__toggle_${h}_${R}`,"bool",!1),M=b("variable/get",{configuration:{variable:k}}),H=b("math/not",{values:{a:L(M)}}),O=b("variable/set",{configuration:{variable:k},values:{value:L(H)}}),B=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.to)?p.to:G},duration:{value:_}}}),z=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.from)?p.from:G},duration:{value:_}}});s[O].flows={out:{node:b("flow/branch",{values:{condition:L(M)},flows:{true:{node:B},false:{node:z}}})}},l.push(O)}else if(g==="interpolate"){let P=p.to??p.value;if(P===void 0)continue;let G={value:{value:P},duration:{value:_}};p.from!==void 0&&(G.from={value:p.from}),l.push(b("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(I(p,h),F(I(p,h)),p.property)},values:G}))}else if(g==="setProperty"){if(p.value===void 0)continue;l.push(b("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(I(p,h),F(I(p,h)),p.property)},values:{value:{value:p.value}}}))}else if(g==="toggleVisibility"){let P=I(p,h),G=v(`__vis_${P}_${R}`,"bool",!0),N=b("variable/get",{configuration:{variable:G}}),k=b("math/not",{values:{a:L(N)}}),M=b("variable/set",{configuration:{variable:G},values:{value:L(k)}});s[M].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${P}/extensions/KHR_node_visibility/visible`},values:{value:L(N)}})}},l.push(M)}else if(g==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let P=typeof p.duration=="number"?p.duration:.25,G=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,N=v(`__color_idx_${h}_${R}`,"int",0),k=b("variable/get",{configuration:{variable:N}}),M=b("math/add",{values:{a:L(k),b:{value:1}}}),H=b("math/rem",{values:{a:L(M),b:{value:p.colors.length}}}),O=b("variable/set",{configuration:{variable:N},values:{value:L(H)}}),B={};for(let z=0;z<p.colors.length;z++){let C=p.colors[z],V=Array.isArray(C)&&C.length>=3?[C[0],C[1],C[2],C[3]??1]:[1,1,1,1];B[String(z)]={node:P>0?b("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:V},duration:{value:P}}}):b("pointer/set",{configuration:{pointer:G},values:{value:{value:V}}})}}s[O].flows={out:{node:b("flow/switch",{values:{selection:L(k)},flows:B})}},l.push(O)}else if(g==="playAnimation")l.push(b("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(g==="stopAnimation")l.push(b("animation/stop"));else if(g==="sendEvent"){let P={};for(let[G,N]of Object.entries(p.values||{}))P[G]={value:N};l.push(b("event/send",{configuration:{event:u(String(p.event??p.id??"custom"))},values:P}))}}if(!l.length)return null;if(l.length===1)return l[0];let m={};return l.forEach((R,p)=>{m[String(p)]={node:R}}),b("flow/sequence",{flows:m})},A=(y,D,l)=>{let m=U(D);m!==null&&b(y,{...l?{configuration:l}:{},flows:{out:{node:m}}})};if(f.onSelect&&A("pointer/onSelect",f.onSelect,{nodeIndex:h}),f.onHoverIn&&A("pointer/onHoverIn",f.onHoverIn,{nodeIndex:h}),f.onHoverOut&&A("pointer/onHoverOut",f.onHoverOut,{nodeIndex:h}),f.onStart&&A("event/onStart",f.onStart),f.onReceive&&typeof f.onReceive=="object")for(let[y,D]of Object.entries(f.onReceive))A("event/receive",D,{event:u(y)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:d}],graph:0}:null}var ge="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ge]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ge,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ge]=e}}return n[ge]}var ne=ue().plugins;function Ne(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function Be(){return ue().plugins}function ye(n,e,t,r=!0){let i=[],s=null;try{for(let[a,d]of[[35633,e],[35632,t]]){let o=n.createShader(a);if(!o){if(r)throw new Error("Shader allocation failed");return null}if(i.push(o),n.shaderSource(o,d),n.compileShader(o),n.getShaderParameter&&!n.getShaderParameter(o,35713)){if(r)throw new Error(`Shader compile error: ${n.getShaderInfoLog(o)}`);return null}}if(s=n.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let a of i)n.attachShader(s,a);if(n.linkProgram(s),n.getProgramParameter&&!n.getProgramParameter(s,35714)){let a=r?n.getProgramInfoLog(s):null;if(n.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${a}`);return null}return s}finally{for(let a of i)s&&n.detachShader?.(s,a),n.deleteShader?.(a)}}var tt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ee(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=t.componentType??5126,d=tt[a];if(!d)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let o=d*r,c=i.byteStride&&i.byteStride>0?i.byteStride:o,u=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(u)||u<0||c<o||u+(s-1)*c+o>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&c===o&&u%4===0)return new Float32Array(e,u,s*r);let b=new DataView(e),v=t.normalized===!0,L=new Float32Array(s*r);for(let E=0;E<s;E++){let x=u+E*c;for(let T=0;T<r;T++){let I=x+T*d,F;switch(a){case 5126:F=b.getFloat32(I,!0);break;case 5120:F=b.getInt8(I),v&&(F=Math.max(F/127,-1));break;case 5121:F=b.getUint8(I),v&&(F/=255);break;case 5122:F=b.getInt16(I,!0),v&&(F=Math.max(F/32767,-1));break;case 5123:F=b.getUint16(I,!0),v&&(F/=65535);break;default:F=b.getUint32(I,!0),v&&(F/=4294967295)}L[E*r+T]=F}}return L}function Ue(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,d=Math.cos(a),o=Math.sin(a),c=(Number.isFinite(i)?i:1)*d,u=(Number.isFinite(i)?i:1)*o,b=-(Number.isFinite(s)?s:1)*o,v=(Number.isFinite(s)?s:1)*d;for(let L=0;L+1<n.length;L+=2){let E=n[L],x=n[L+1];n[L]=c*E+u*x+t,n[L+1]=b*E+v*x+r}}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function ve(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 a=1/(r-i);return n[10]=(i+r)*a,n[14]=2*i*r*a,n}function xe(n,e,t,r){let[i,s,a]=e,[d,o,c]=r,[u,b,v]=t,L=i-u,E=s-b,x=a-v,T=Math.hypot(L,E,x);T<=1e-5?(L=0,E=0,x=1):(L/=T,E/=T,x/=T);let I=o*x-c*E,F=c*L-d*x,h=d*E-o*L;T=Math.hypot(I,F,h),T<=1e-5?(I=0,F=0,h=0):(I/=T,F/=T,h/=T);let w=E*h-x*F,f=x*I-L*h,S=L*F-E*I;return T=Math.hypot(w,f,S),T<=1e-5?(w=0,f=0,S=0):(w/=T,f/=T,S/=T),n[0]=I,n[1]=w,n[2]=L,n[3]=0,n[4]=F,n[5]=f,n[6]=E,n[7]=0,n[8]=h,n[9]=S,n[10]=x,n[11]=0,n[12]=-(I*i+F*s+h*a),n[13]=-(w*i+f*s+S*a),n[14]=-(L*i+E*s+x*a),n[15]=1,n}function ee(n,e,t){let r=e[0],i=e[1],s=e[2],a=e[3],d=e[4],o=e[5],c=e[6],u=e[7],b=e[8],v=e[9],L=e[10],E=e[11],x=e[12],T=e[13],I=e[14],F=e[15],h=t[0],w=t[1],f=t[2],S=t[3];return n[0]=h*r+w*d+f*b+S*x,n[1]=h*i+w*o+f*v+S*T,n[2]=h*s+w*c+f*L+S*I,n[3]=h*a+w*u+f*E+S*F,h=t[4],w=t[5],f=t[6],S=t[7],n[4]=h*r+w*d+f*b+S*x,n[5]=h*i+w*o+f*v+S*T,n[6]=h*s+w*c+f*L+S*I,n[7]=h*a+w*u+f*E+S*F,h=t[8],w=t[9],f=t[10],S=t[11],n[8]=h*r+w*d+f*b+S*x,n[9]=h*i+w*o+f*v+S*T,n[10]=h*s+w*c+f*L+S*I,n[11]=h*a+w*u+f*E+S*F,h=t[12],w=t[13],f=t[14],S=t[15],n[12]=h*r+w*d+f*b+S*x,n[13]=h*i+w*o+f*v+S*T,n[14]=h*s+w*c+f*L+S*I,n[15]=h*a+w*u+f*E+S*F,n}function he(n,e,t,r){let i=e[0],s=e[1],a=e[2],d=e[3],o=i+i,c=s+s,u=a+a,b=i*o,v=i*c,L=i*u,E=s*c,x=s*u,T=a*u,I=d*o,F=d*c,h=d*u,w=r[0],f=r[1],S=r[2];return n[0]=(1-(E+T))*w,n[1]=(v+h)*w,n[2]=(L-F)*w,n[3]=0,n[4]=(v-h)*f,n[5]=(1-(b+T))*f,n[6]=(x+I)*f,n[7]=0,n[8]=(L+F)*S,n[9]=(x-I)*S,n[10]=(1-(b+E))*S,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ae(n,e,t=0){let r=e[0],i=e[1],s=e[2],a=e[4],d=e[5],o=e[6],c=e[8],u=e[9],b=e[10],v=b*d-o*u,L=-b*a+o*c,E=u*a-d*c,x=r*v+i*L+s*E;return!x||t>0&&(!Number.isFinite(x)||Math.abs(x)<=t)||(x=1/x,n[0]=v*x,n[1]=L*x,n[2]=E*x,n[3]=(-b*i+s*u)*x,n[4]=(b*r-s*c)*x,n[5]=(-u*r+i*c)*x,n[6]=(o*i-s*d)*x,n[7]=(-o*r+s*a)*x,n[8]=(d*r-i*a)*x),n}function ke(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],d=e[5],o=e[6],c=e[7],u=e[8],b=e[9],v=e[10],L=e[11],E=e[12],x=e[13],T=e[14],I=e[15],F=t*d-r*a,h=t*o-i*a,w=t*c-s*a,f=r*o-i*d,S=r*c-s*d,U=i*c-s*o,A=u*x-b*E,y=u*T-v*E,D=u*I-L*E,l=b*T-v*x,m=b*I-L*x,R=v*I-L*T,p=F*R-h*m+w*l+f*D-S*y+U*A;return p?(p=1/p,n[0]=(d*R-o*m+c*l)*p,n[1]=(i*m-r*R-s*l)*p,n[2]=(x*U-T*S+I*f)*p,n[3]=(v*S-b*U-L*f)*p,n[4]=(o*D-a*R-c*y)*p,n[5]=(t*R-i*D+s*y)*p,n[6]=(T*w-E*U-I*h)*p,n[7]=(u*U-v*w+L*h)*p,n[8]=(a*m-d*D+c*A)*p,n[9]=(r*D-t*m-s*A)*p,n[10]=(E*S-x*w+I*F)*p,n[11]=(b*w-u*S-L*F)*p,n[12]=(d*y-a*l-o*A)*p,n[13]=(t*l-r*y+i*A)*p,n[14]=(x*h-E*f-T*F)*p,n[15]=(u*f-b*h+v*F)*p,n):null}function De(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],a=i[1]*e+i[5]*t+i[9]*r+i[13],d=i[2]*e+i[6]*t+i[10]*r+i[14],o=i[3]*e+i[7]*t+i[11]*r+i[15],c=o!==0?1/o:1;n[0]=s*c,n[1]=a*c,n[2]=d*c}function Ge(n,e,t,r,i,s,a,d,o,c,u,b,v,L,E,x,T=0){let I=c-a,F=u-d,h=b-o,w=v-a,f=L-d,S=E-o,U=i*S-s*f,A=s*w-r*S,y=r*f-i*w,D=I*U+F*A+h*y;if(D>-1e-7&&D<1e-7)return!1;let l=1/D,m=n-a,R=e-d,p=t-o,g=l*(m*U+R*A+p*y);if(g<-T||g>1+T)return!1;let _=R*h-p*F,P=p*I-m*h,G=m*F-R*I,N=l*(r*_+i*P+s*G);if(N<-T||g+N>1+T)return!1;let k=l*(w*_+f*P+S*G);if(k>1e-4&&k<x.distance){x.distance=k,x.point=[n+r*k,e+i*k,t+s*k];let M=F*S-h*f,H=h*w-I*S,O=I*f-F*w,B=Math.hypot(M,H,O)||1;return x.normal=[M/B,H/B,O/B],!0}return!1}function Me(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let u=0;u<t;u++)r.push(J());if(t===0)return r;let i=new Set;for(let u of n.nodes)if(Array.isArray(u.children))for(let b of u.children)i.add(b);let s=new Set,a=128,d=(u,b,v=0)=>{if(v>a||u<0||u>=t||s.has(u))return;s.add(u);let L=n.nodes[u];if(!L)return;let E=J();if(e&&e[u])E.set(e[u]);else if(L.matrix&&L.matrix.length===16)E.set(L.matrix);else{let T=L.translation||[0,0,0],I=L.rotation||[0,0,0,1],F=L.scale||[1,1,1];he(E,I,T,F)}let x=r[u];if(b?ee(x,b,E):x.set(E),Array.isArray(L.children))for(let T of L.children)typeof T=="number"&&d(T,x,v+1)},o=[],c=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(c&&Array.isArray(c.nodes))o.push(...c.nodes);else for(let u=0;u<t;u++)i.has(u)||o.push(u);for(let u of o)d(u,null);for(let u=0;u<t;u++)!i.has(u)&&!o.includes(u)&&d(u,null);return r}var He=["neutral","reinhard","none","aces","agx"];function Pe(n){let e=String(n??"").trim().toLowerCase();return He.includes(e)?e:"neutral"}function nt(n){return He.indexOf(Pe(n))}function rt(n){return new TextDecoder().decode(n)}var ze=ue().decoders;function it(n,e){ze.set(n.toLowerCase(),e)}function me(n){return ze.get(n.toLowerCase())}function $e(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 v=t.getUint8(0);throw v===123||v===32||v===10||v===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),a=12,d=null,o=null;for(;a+8<=s&&a+8<=e.byteLength;){let v=t.getUint32(a,!0),L=t.getUint32(a+4,!0),E=a+8;if(E+v>e.byteLength)throw new Error(`Truncated GLB chunk: required ${E+v} bytes, buffer has ${e.byteLength}`);if(L===1313821514){let x=new Uint8Array(e,E,v),T=rt(x);d=JSON.parse(T,(I,F)=>I==="__proto__"||I==="constructor"||I==="prototype"?void 0:F)}else L===5130562&&(o=e.slice(E,E+v));a=E+v}if(!d)throw new Error("Missing JSON chunk in GLB");let c=d.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let v of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(v)&&!me("meshopt"))throw new Error(`Model requires ${v}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=o||new ArrayBuffer(0),b={gltf:d,bin:u,animations:[]};for(let v of ne)v.onParseGLB?.(b);return b}function st(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 de(n){if(st(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return $e(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var We=`#version 300 es
18
+ layout(location=0) in vec3 aPos;
19
+ layout(location=3) in vec3 aOff;
19
20
  layout(location=1) in vec3 aNormal;
20
21
  layout(location=2) in vec2 aUV;
21
22
  uniform mat4 uMVP,uModel;
@@ -38,6 +39,7 @@ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):u
38
39
  out vec3 vNormal,vWorldPos;
39
40
  out vec2 vUV;
40
41
  void main(){
42
+ vec3 aPosition=aPos+aOff;
41
43
  vInstTint=uInstanced==1?aInstColor:vec4(1.0);
42
44
  vec3 rawN=uNormalMatrix*aNormal;
43
45
  vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
@@ -47,7 +49,7 @@ vec2 scaleUV=uUvTransform.zw;
47
49
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
48
50
  vUV=aUV*scaleUV+uUvTransform.xy;
49
51
  gl_Position=uMVP*vec4(aPosition,1.0);
50
- }`,at=`#version 300 es
52
+ }`,ot=`#version 300 es
51
53
  precision highp float;
52
54
  in vec3 vNormal,vWorldPos;
53
55
  in vec2 vUV;
@@ -240,14 +242,14 @@ color=applyToneMapping(color,uToneMapping);
240
242
  float outAlpha=base.a;
241
243
  /*XRD_O*/
242
244
  fragColor=vec4(color,outAlpha);
243
- }`;var ut=`#version 300 es
245
+ }`;var at=`#version 300 es
244
246
  layout(location=0) in vec3 aPosition;
245
247
  uniform mat4 uMVP;
246
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ct=`#version 300 es
248
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ut=`#version 300 es
247
249
  precision highp float;
248
250
  uniform vec4 uColorId;
249
251
  out vec4 fragColor;
250
- void main(){fragColor=uColorId;}`;function Ve(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 Pe(n,e,t){let r=Ve(n,35633,e),i=Ve(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let a=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${a}`)}return s}function Ie(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var Oe=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function qe(){let n=ue().xrDepthShader;return{fs:at.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Oe,...n.uniformNames]:Oe}}function lt(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 De(n,e,t,r,i,s,a,d){if(r===void 0||!e.accessors?.[r])return null;let o=we(e,t,e.accessors[r],s);if(!o)return null;d&&(o=o.slice(),Ue(o,d));let c=n.createBuffer();return a.push(c),n.bindBuffer(34962,c),n.bufferData(34962,o,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),o}function Ce(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function Ke(n,e,t){let r=qe(),i=Xe,s=r.fs,a=!1;for(let o of ne)if(o.onResolveShader){let c=o.onResolveShader(e,t,i,s);c&&(i=c.vs,s=c.fs,a=!0)}let d=a?Pe(n,i,s):null;return{program:d,uniforms:d?Ie(n,d,r.uniforms):null}}function mt(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,a=new Float32Array(i*20);for(let o=0;o<i;o++)a.set(r.subarray(o*16,o*16+16),o*20),a[o*20+16]=s?s[o*3]:1,a[o*20+17]=s?s[o*3+1]:1,a[o*20+18]=s?s[o*3+2]:1,a[o*20+19]=1;let d=n.createBuffer();t.push(d),n.bindBuffer(34962,d),n.bufferData(34962,a,35044);for(let o=0;o<5;o++)n.enableVertexAttribArray(8+o),n.vertexAttribPointer(8+o,4,5126,!1,80,o*16),n.vertexAttribDivisor(8+o,1);return!0}function ht(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var St=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ye=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Me(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function Ze(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=a=>a!==void 0&&e[a.index]?e[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function je(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&n.deleteVertexArray(a.vao),a.buffers)for(let o of a.buffers)n.deleteBuffer(o);i(a.texture),i(a.metallicRoughnessTexture),i(a.normalTexture),i(a.occlusionTexture);let d=new Set;a.customProgram&&d.add(a.customProgram);for(let o of a.programCache?.values()??[])o.program&&d.add(o.program);for(let o of d)n.deleteProgram(o)}if(t)for(let s of t)i(s)}function He(n,e,t=Ye,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ft(n,e,t,r,i)}catch(s){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;je(n,a,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let d of i.buffers)n.deleteBuffer(d);throw s}}function ft(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=me("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let d=e.bin,o=[];i.meshes=o;let c=[],u=s.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((h,w)=>{c.push(typeof h?.name=="string"&&h.name?h.name:`Variant_${w}`)});let b=xe(s),v=[];if(Array.isArray(s.nodes))for(let h=0;h<s.nodes.length;h++){let w=s.nodes[h];w.mesh!==void 0&&s.meshes&&s.meshes[w.mesh]&&v.push({node:w,nodeIdx:h,meshIdx:w.mesh})}let L=v.length>0?v:(s.meshes||[]).map((h,w)=>({node:h,nodeIdx:-1,meshIdx:w})),M=[];if(Array.isArray(e.lights)&&e.lights.length>0)M.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let h=s.extensions.KHR_lights_punctual.lights;for(let w of h){let p=w.type==="directional"?"directional":w.type==="point"?"point":"ambient";M.push({type:p,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(M.length===0&&(M.push({type:"ambient",color:[1,1,1],intensity:.35}),M.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),L.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${L.length}`);let R=[];if(i.gpuTextures=R,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let h=0;h<s.textures.length;h++){let w=s.textures[h],p=s.images[w.source];if(p){let y=n.createTexture();if(n.bindTexture(3553,y),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),p.bufferView!==void 0){let _=s.bufferViews[p.bufferView],P=d.slice(_.byteOffset||0,(_.byteOffset||0)+_.byteLength),G=new Blob([P],{type:p.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(G).then(N=>{n.bindTexture(3553,y),n.texImage2D(3553,0,6408,6408,5121,N),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(p.uri){let _=lt(p.uri);if(_){let P=new Image;P.crossOrigin="anonymous",P.referrerPolicy="no-referrer",P.onload=()=>{n.bindTexture(3553,y),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()},P.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",p.uri)}R.push(y)}else R.push(null)}}let T=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0],F=0,m=0;for(let h=0;h<L.length;h++){let w=L[h],p=s.meshes[w.meshIdx],y=w.nodeIdx>=0?b[w.nodeIdx]:J(),_=new Float32Array(9);ae(_,y);let P={name:w.node.name||p.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:y,normalMatrix:_,primitives:[],extras:w.node.extras||p.extras};i.mesh=P;let G=w.node?.extensions?.EXT_mesh_gpu_instancing;if(G&&G.attributes&&typeof G.attributes=="object"){let N=G.attributes,k=N.TRANSLATION!==void 0?s.accessors?.[N.TRANSLATION]:null,x=N.ROTATION!==void 0?s.accessors?.[N.ROTATION]:null,H=N.SCALE!==void 0?s.accessors?.[N.SCALE]:null,O=N._COLOR_0!==void 0?s.accessors?.[N._COLOR_0]:null,B=Number(k?.count??x?.count??H?.count??0);if(!Number.isFinite(B)||B<0||B>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${B}`);if(B>0){let z=(X,Z)=>{if(!X||X.bufferView===void 0||!s.bufferViews?.[X.bufferView])return null;let re=X.componentType??5126,oe=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(re!==5120&&re!==5121&&re!==5122&&re!==5123&&re!==5126)return oe(`componentType ${re}`);if(!(Number(X.count)>=B))return oe(`count ${X.count} < ${B}`);let Y=null;try{Y=we(s,d,{...X,count:B},Z)}catch{return oe("out of bounds")}return!Y||!Y.every(Number.isFinite)?oe("non-finite value"):Y},C=z(k,3),V=z(x,4),$=z(H,3),W=O?.type==="VEC4"?4:3,q=z(O,W),te=new Float32Array(B*16),se=J();for(let X=0;X<B;X++){let Z=C?[C[X*3],C[X*3+1],C[X*3+2]]:[0,0,0],re=V?[V[X*4],V[X*4+1],V[X*4+2],V[X*4+3]]:[0,0,0,1],oe=$?[$[X*3],$[X*3+1],$[X*3+2]]:[1,1,1];he(se,re,Z,oe),te.set(se,X*16)}if(P.instanceMatrices=te,q){let X=new Float32Array(B*3);for(let Z=0;Z<B;Z++)X[Z*3]=q[Z*W],X[Z*3+1]=q[Z*W+1],X[Z*3+2]=q[Z*W+2];P.instanceColors=X}}}for(let N of p.primitives||[]){if(N.extensions?.KHR_draco_mesh_compression){let Y=me("draco");Y&&Y.decodePrimitive(s,N,d)}let k=[],x=n.createVertexArray();i.vao=x,i.buffers=k,n.bindVertexArray(x);let H=mt(n,P,k),O=s.accessors[N.attributes.POSITION],B=Number(O?.count??0);if(!Number.isFinite(B)||B<0||F+B>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(F+=B,O?.min&&O?.max){let Y=Q=>{for(let j=0;j<3;j++){let ie=Q[12+j],ce=Q[12+j];for(let le=0;le<3;le++){let pe=Q[le*4+j]*O.min[le],be=Q[le*4+j]*O.max[le];ie+=pe<be?pe:be,ce+=pe>be?pe:be}ie<T[j]&&(T[j]=ie),ce>I[j]&&(I[j]=ce)}};if(P.instanceMatrices&&P.instanceMatrices.length>=16){let Q=P.instanceMatrices.length>>4,j=J();for(let ie=0;ie<Q;ie++){let ce=P.instanceMatrices.subarray(ie*16,ie*16+16);ee(j,y,ce),Y(j)}}else Y(y)}let z=De(n,s,d,N.attributes.POSITION,0,3,k);De(n,s,d,N.attributes.NORMAL,1,3,k),De(n,s,d,N.attributes.TEXCOORD_0,2,2,k,ht(s,N));let C=0,V=5123,$=null;if(N.indices!==void 0){let Y=s.accessors[N.indices],j=(s.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(C=Number(Y.count??0),!Number.isFinite(C)||C<0||m+C>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);m+=C,V=Y.componentType===5125?5125||5125:5123||5123;let ie=n.createBuffer();k.push(ie),n.bindBuffer(34963,ie),Y.componentType===5125?($=new Uint32Array(d,j,Y.count),n.bufferData(34963,$,35044)):Y.componentType===5121?($=Uint16Array.from(new Uint8Array(d,j,Y.count)),n.bufferData(34963,$,35044)):($=j%2===0?new Uint16Array(d,j,Y.count):new Uint16Array(d.slice(j,j+Y.count*2)),n.bufferData(34963,$,35044))}else C=O.count;let W={};for(let Y of ne)if(Y.onBuildPrimitiveVAO){let Q=Y.onBuildPrimitiveVAO(n,x,N,s,d);Q&&(W[Y.name]=Q)}n.bindVertexArray(null);let q=s.materials&&N.material!==void 0?s.materials[N.material]:null,{program:te,uniforms:se}=Ke(n,N,q),X=Ze(q,R),Z=!!(q?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),re=N.extensions?.KHR_materials_variants?.mappings,oe=Array.isArray(re)?re.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(Q=>Number(Q)|0)})):void 0;P.primitives.push({vao:x,instanced:H,indexCount:C,indexType:V,...X,positions:z,indices:$,buffers:k,materialIndex:N.material,defaultMaterialIndex:N.material,variantMappings:oe,primitiveDef:N,programCache:new Map([[N.material??-1,{program:te,uniforms:se}]]),pluginData:W,customProgram:te,customUniforms:se,isTransmissive:Z})}o.push(P)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(I[0])||(I=[1,1,1]);let E=[(T[0]+I[0])/2,(T[1]+I[1])/2,(T[2]+I[2])/2],f=I[0]-T[0],S=I[1]-T[1],U=I[2]-T[2],A=Math.max(Math.hypot(f,S,U)/2,.5),g=[T[0],T[1],T[2]],D=[I[0],I[1],I[2]],l=e.animations;if(!l){for(let h of ne)if(h.onParseGLB?.(e),e.animations){l=e.animations;break}}return l||(l=[]),{meshes:o,bounds:{center:E,radius:A,min:g,max:D},lights:M,animations:l,worldMatrices:b,gpuTextures:R,availableVariants:c}}function fe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var Te=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.activeViewMatrix=null;this.modelMatrix=J();this.mvpMatrix=J();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:J(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Ce(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=Le(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let d=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!d)throw new Error("WebGL2 not supported");this.gl=d,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){st(e,t)}static getDecoder(e){return me(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=qe();this.renderProg=Pe(e,Xe,t.fs),this.pickProg=Pe(e,ut,ct),this.uRender=Ie(e,this.renderProg,t.uniforms),this.uPick=Ie(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ne)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:a,worldMatrices:d,gpuTextures:o,availableVariants:c}=He(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=a||[],this.worldMatrices=d||[],this.gpuTextures=o||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let v of e.gltf.nodes)this.initialNodeTransforms.push({t:v.translation?[v.translation[0],v.translation[1],v.translation[2]]:[0,0,0],r:v.rotation?[v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]]:[0,0,0,1],s:v.scale?[v.scale[0],v.scale[1],v.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let v of ne)v.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.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Ce(u));let b=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;b!==void 0&&(this.envIntensity=Math.max(0,Number(b)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(We(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(de(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=de(e),{meshes:i}=He(this.gl,r,Ye,()=>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=[],a=[],d=[];for(let o of this.lights){let c=o.color||[1,1,1],u=o.intensity!==void 0?o.intensity:1;if(o.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(o.type==="directional"&&i.length<6){let b=o.direction||[.5,1,.8];i.push(b[0],b[1],b[2]),s.push(c[0]*u,c[1]*u,c[2]*u)}else if(o.type==="point"&&a.length<6){let b=o.position||[0,0,0];a.push(b[0],b[1],b[2]),d.push(c[0]*u,c[1]*u,c[2]*u)}}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,a.length/3),a.length>0&&(t.uniform3fv(e.uPointLightPos,a),t.uniform3fv(e.uPointLightColor,d)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Ce(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Le(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ne)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ne)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(u=>u.primitives.filter(b=>b.materialIndex===r||e.length===1&&b.materialIndex===void 0)),s=i[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],d=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:d,roughnessFactor:o,setBaseColorFactor:u=>{let b=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=b,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=b);for(let v of i)v.baseColor=b;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let b of i)b.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let b of i)b.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let s of this.meshes)for(let a of s.primitives){let d=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){d=c.material;break}}let o=d!==void 0?i[d]:void 0;a.materialIndex=o?d:void 0,Object.assign(a,Ze(o,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=Ke(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of ne)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=J();ee(r,this.projMatrix,this.viewMatrix);let[i,s,a]=e,d=t?t[0]:0,o=t?t[1]:0,c=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],s=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],a=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(d=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],c=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let b=r[0]*i+r[4]*s+r[8]*a+r[12],v=r[1]*i+r[5]*s+r[9]*a+r[13],L=r[2]*i+r[6]*s+r[10]*a+r[14],M=r[3]*i+r[7]*s+r[11]*a+r[15];if(M<=1e-4)return{x:0,y:0,z:1,visible:!1};let R=b/M,T=v/M,I=L/M,F=this.canvas.getBoundingClientRect(),m=F.width||this.canvas.clientWidth||this.canvas.width||300,E=F.height||this.canvas.clientHeight||this.canvas.height||150,f=(R*.5+.5)*m,S=(-T*.5+.5)*E,U=R>=-1.1&&R<=1.1&&T>=-1.1&&T<=1.1&&I>=-1&&I<=1;if(U&&t){let[A,g,D]=fe(this),l=[i-A,s-g,a-D];d*l[0]+o*l[1]+c*l[2]>.05&&(U=!1)}return{x:f,y:S,z:I,visible:U}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],d=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],o=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;o[0]+=(-i*a[0]+s*d[0])*c,o[1]+=(-i*a[1]+s*d[1])*c,o[2]+=(-i*a[2]+s*d[2])*c,this.customTarget=o}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,a=r.height||300,d=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(a/i.height)):Math.floor(t);return this.performMeshPick(d,o,!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),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let d=J();ee(d,this.projMatrix,this.viewMatrix);let o=[],c=Math.max(0,Math.min(s-1,e)),u=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,a),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let U=0;U<this.meshes.length;U++){let A=this.meshes[U];if(A.visible===!1||A.isPluginMesh)continue;let g=U+1,D=(g&255)/255,l=(g>>8&255)/255,h=(g>>16&255)/255;i.uniform4f(this.uPick.uColorId,D,l,h,1),ee(this.modelMatrix,this.modelRootMatrix,A.transform);let w=A.instanceMatrices;if(w&&w.length>=16){let p=w.length>>4,y=J();for(let _ of A.primitives){i.bindVertexArray(_.vao);for(let P=0;P<p;P++)ee(y,this.modelMatrix,w.subarray(P*16,P*16+16)),ee(this.mvpMatrix,d,y),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Me(i,_)}}else{ee(this.mvpMatrix,d,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let p of A.primitives)i.bindVertexArray(p.vao),Me(i,p)}}let f=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,f),i.bindFramebuffer(36160,null);let S=f[0]+(f[1]<<8)+(f[2]<<16);S>0&&S<=this.meshes.length&&(o=[this.meshes[S-1]])}o.length===0&&(o=this.meshes.filter(f=>f.visible!==!1));let b=null,v=1/0,L=[0,0,0],M=[0,1,0],[R,T,I]=fe(this),F=J();for(let f of o){ee(F,this.modelRootMatrix,f.transform);let S=f.instanceMatrices,U=S&&S.length>=16?S.length>>4:1;for(let A=0;A<U;A++){S&&S.length>=16?ee(this.modelMatrix,F,S.subarray(A*16,A*16+16)):this.modelMatrix.set(F),ee(this.mvpMatrix,d,this.modelMatrix);let g=J();if(!ke(g,this.mvpMatrix))continue;let D=(c+.5)/s*2-1,l=(u+.5)/a*2-1,h=[0,0,0],w=[0,0,0];Ee(h,D,l,-1,g),Ee(w,D,l,1,g);let p=w[0]-h[0],y=w[1]-h[1],_=w[2]-h[2],P=Math.hypot(p,y,_)||1,G=p/P,N=y/P,k=_/P,x={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((O=>{for(let B of f.primitives){if(!B.positions)continue;let z=B.positions,C=B.indices,V=Math.floor(C?C.length/3:z.length/9);for(let $=0;$<V;$++){let W=C?C[$*3]:$*3,q=C?C[$*3+1]:$*3+1,te=C?C[$*3+2]:$*3+2;Ge(h[0],h[1],h[2],G,N,k,z[W*3],z[W*3+1],z[W*3+2],z[q*3],z[q*3+1],z[q*3+2],z[te*3],z[te*3+1],z[te*3+2],x,O)}}})(1e-4),isFinite(x.distance)){let O=x.point[0],B=x.point[1],z=x.point[2],C=this.modelMatrix,V=C[0]*O+C[4]*B+C[8]*z+C[12],$=C[1]*O+C[5]*B+C[9]*z+C[13],W=C[2]*O+C[6]*B+C[10]*z+C[14],q=V-R,te=$-T,se=W-I,X=Math.hypot(q,te,se);if(X<v){ae(this.normalMatrix,this.modelMatrix);let Z=this.normalMatrix,re=x.normal[0],oe=x.normal[1],Y=x.normal[2],Q=Z[0]*re+Z[3]*oe+Z[6]*Y,j=Z[1]*re+Z[4]*oe+Z[7]*Y,ie=Z[2]*re+Z[5]*oe+Z[8]*Y,ce=Math.hypot(Q,j,ie)||1;Q/=ce,j/=ce,ie/=ce,Q*q+j*te+ie*se>0&&(Q=-Q,j=-j,ie=-ie),b=f,v=Math.round(X*1e3)/1e3,L=[Math.round(V*1e3)/1e3,Math.round($*1e3)/1e3,Math.round(W*1e3)/1e3],M=[Math.round(Q*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(ie*1e3)/1e3]}}}}if(!b)return null;let E={meshIndex:this.meshes.indexOf(b),meshName:b.name,nodeIndex:b.nodeIndex,distance:v,hitPoint:L,normal:M,screenX:e,screenY:t};if(r){for(let f of ne)f.onMeshSelect?.(this,E);this.opts.onMeshClick&&this.opts.onMeshClick(E),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:E}))}return E}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,a=i?Math.max(1,t-r):r,d=(s+.5)/a*2-1;return Math.floor((d*.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);ye(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;ve(this.viewMatrix,fe(this),r,[0,1,0]),ee(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 ne)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 ne)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 a of ne)a.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 a of ne)a.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 a={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,t,r,i,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let d=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:d,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let m=Math.max(2,this.canvas.width||2),E=Math.max(1,this.canvas.height||1),f=Math.max(1,Math.floor(m*.5)),S=Math.max(1,m-f),U=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),A=this.customTarget||this.bounds.center,[g,D,l]=fe(this),h=Math.cos(this.currTheta),w=-Math.sin(this.currTheta),p=.032,y=J(),_=J(),P=[g-h*p,D,l-w*p],G=[A[0]-h*p*.25,A[1],A[2]-w*p*.25];ye(y,this.fov,f/E,.1,U),ve(_,P,G,[0,1,0]);let N=J(),k=J(),x=[g+h*p,D,l+w*p],H=[A[0]+h*p*.25,A[1],A[2]+w*p*.25];ye(N,this.fov,S/E,.1,U),ve(k,x,H,[0,1,0]),this.render({viewMatrix:_,projMatrix:y,eyePos:P,viewport:[0,0,f,E],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:k,projMatrix:N,eyePos:x,viewport:[f,0,S,E],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,m,E);return}let t=this.gl,r=0,i=0,s=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],a=e.viewport[3],t.viewport(r,i,s,a)):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 d=J(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,ee(d,e?.projMatrix??this.projMatrix,o);let c=ue().xrDepthShader,u=rt(this.toneMapping),[b,v,L]=e?e.eyePos:fe(this);for(let m of ne)m.onBeforeDrawScene?.(this,t,d,[b,v,L],u);let M=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&M===0)return;let R=e?.eye||"none",T=!1,I=M>0?[...this.backdropMeshes,...this.meshes]:this.meshes,F=m=>{for(let E=0;E<I.length;E++){let f=I[E];if(f.visible===!1)continue;let S=this.selectedMeshName!==""&&f.name===this.selectedMeshName;E<M||f.worldSpace===!0||f.name==="__xr_reticle__"?this.modelMatrix.set(f.transform):ee(this.modelMatrix,this.modelRootMatrix,f.transform),ee(this.mvpMatrix,d,this.modelMatrix),ae(f.normalMatrix,this.modelMatrix);let U=f.extras?.xr?.stereo||f.userData?.xr?.stereo,A=0,g=0,D=1,l=1;U==="sbs"?(D=.5,A=R==="right"?.5:0):U==="ou"&&(l=.5,g=R==="right"?.5:0);for(let h of f.primitives){let w=!!h.isTransmissive;if(!m&&w){T=!0;continue}if(m&&!w)continue;let p=h.customProgram||this.renderProg,y=h.customUniforms||this.uRender;t.useProgram(p),t.uniform1i(y.uToneMapping,u),t.uniform1f(y.uEnvIntensity,this.envIntensity),y.uExposure&&t.uniform1f(y.uExposure,this.exposure),t.uniform3f(y.uCameraPos,b,v,L),t.uniform1f(y.uEmissive,S?1:0),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(y.uNormalMatrix,!1,f.normalMatrix),y.uUvTransform&&t.uniform4f(y.uUvTransform,A,g,D,l),y.uViewportSize&&t.uniform2f(y.uViewportSize,Math.max(1,s),Math.max(1,a)),c?.bind(t,y,this.xrDepthState,o,[r,i,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(y.uEnvironmentMap,4),t.uniform1i(y.uHasEnvironmentMap,1)):t.uniform1i(y.uHasEnvironmentMap,0),this.bindLights(y),y.uSectionEnabled&&t.uniform1i(y.uSectionEnabled,0);for(let P of ne)P.onBeforeDrawPrimitive?.(t,p,h,f,this.worldMatrices||[],this.gltf);t.uniform4fv(y.uBaseColor,h.baseColor),t.uniform1f(y.uMetallic,h.metallic),t.uniform1f(y.uRoughness,h.roughness),y.uClearcoat&&t.uniform2f(y.uClearcoat,h.clearcoat??0,h.clearcoatRoughness??.04),h.texture?(t.activeTexture(33984),t.bindTexture(3553,h.texture),t.uniform1i(y.uBaseColorTexture,0),t.uniform1i(y.uHasTexture,1)):t.uniform1i(y.uHasTexture,0),h.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,h.metallicRoughnessTexture),t.uniform1i(y.uMetallicRoughnessTexture,1),t.uniform1i(y.uHasMetallicRoughnessTexture,1)):t.uniform1i(y.uHasMetallicRoughnessTexture,0),h.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,h.normalTexture),t.uniform1i(y.uNormalTexture,2),t.uniform1i(y.uHasNormalTexture,1),t.uniform1f(y.uNormalScale,h.normalScale)):t.uniform1i(y.uHasNormalTexture,0),h.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,h.occlusionTexture),t.uniform1i(y.uOcclusionTexture,3),t.uniform1i(y.uHasOcclusionTexture,1),t.uniform1f(y.uOcclusionStrength,h.occlusionStrength)):t.uniform1i(y.uHasOcclusionTexture,0),t.bindVertexArray(h.vao);let _=f.instanceMatrices;if(_&&_.length>=16&&h.instanced&&y.uInstanced&&y.uViewProj){let P=_.length>>4;t.uniform1i(y.uInstanced,1),t.uniformMatrix4fv(y.uViewProj,!1,d),h.indices?t.drawElementsInstanced(4,h.indexCount,h.indexType,0,P):t.drawArraysInstanced(4,0,h.indexCount,P),t.uniform1i(y.uInstanced,0)}else if(_&&_.length>=16){let P=_.length>>4,G=f.instanceColors,N=J(),k=new Float32Array(9),x=[h.baseColor[0],h.baseColor[1],h.baseColor[2],h.baseColor[3]];for(let H=0;H<P;H++)ee(N,this.modelMatrix,_.subarray(H*16,H*16+16)),ee(this.mvpMatrix,d,N),ae(k,N),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,N),t.uniformMatrix3fv(y.uNormalMatrix,!1,k),G&&(x[0]=h.baseColor[0]*G[H*3],x[1]=h.baseColor[1]*G[H*3+1],x[2]=h.baseColor[2]*G[H*3+2],x[3]=h.baseColor[3],t.uniform4fv(y.uBaseColor,x)),Me(t,h)}else Me(t,h)}}};if(F(!1),T){for(let m of ne)m.onBeforeTransmissivePass?.(t,this);F(!0)}for(let m of ne)m.onAfterRender?.(t,this,d)}disposeMeshListGpuResources(e,t){je(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of ne)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()}};Te.registerPlugin=Ne,Te.getRegisteredPlugins=Be;function dt(n){return n+3&-4}function pt(n,e=0){let t=(x,H)=>typeof x=="number"&&Number.isFinite(x)?x:H,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),a=t(n[e+0],1),d=t(n[e+1],0),o=t(n[e+2],0),c=t(n[e+4],0),u=t(n[e+5],1),b=t(n[e+6],0),v=t(n[e+8],0),L=t(n[e+9],0),M=t(n[e+10],1),R=Math.hypot(a,d,o),T=Math.hypot(c,u,b),I=Math.hypot(v,L,M);a*(u*M-L*b)-c*(d*M-L*o)+v*(d*b-u*o)<0&&(R=-R);let m=Math.abs(R)>1e-8?1/R:0,E=Math.abs(T)>1e-8?1/T:0,f=Math.abs(I)>1e-8?1/I:0,S=a*m,U=d*m,A=o*m,g=c*E,D=u*E,l=b*E,h=v*f,w=L*f,p=M*f,y=S+D+p,_=0,P=0,G=0,N=1;if(y>0){let x=.5/Math.sqrt(y+1);N=.25/x,_=(l-w)*x,P=(h-A)*x,G=(U-g)*x}else if(S>D&&S>p){let x=2*Math.sqrt(Math.max(0,1+S-D-p));x>1e-8&&(N=(l-w)/x,_=.25*x,P=(g+U)/x,G=(h+A)/x)}else if(D>p){let x=2*Math.sqrt(Math.max(0,1+D-S-p));x>1e-8&&(N=(h-A)/x,_=(g+U)/x,P=.25*x,G=(l+w)/x)}else{let x=2*Math.sqrt(Math.max(0,1+p-S-D));x>1e-8&&(N=(U-g)/x,_=(h+A)/x,P=(l+w)/x,G=.25*x)}let k=Math.hypot(_,P,G,N);return k>1e-8&&Number.isFinite(k)?(_/=k,P/=k,G/=k,N/=k):(_=0,P=0,G=0,N=1),{t:[r,i,s],r:[_,P,G,N],s:[R,T,I]}}function bt(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 gt(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],a=[],d=[],o=new Set,c=[],u=[],b=new Map,v=[],L=[];function M(g){let D=b.get(g);if(D!==void 0)return D;D=u.length,b.set(g,D);let l=g,h=l.color?.r??.8,w=l.color?.g??.8,p=l.color?.b??.8,y=l.opacity??1,_={name:l.name||"",pbrMetallicRoughness:{baseColorFactor:[h,w,p,y],metallicFactor:l.metalness??.1,roughnessFactor:l.roughness??.5},doubleSided:l.side===2||!!l.doubleSided};if(l.emissive&&(l.emissive.r>0||l.emissive.g>0||l.emissive.b>0)){let G=l.emissiveIntensity??1;_.emissiveFactor=[l.emissive.r*G,l.emissive.g*G,l.emissive.b*G]}let P={};return l.clearcoat&&l.clearcoat>0&&(P.KHR_materials_clearcoat={clearcoatFactor:l.clearcoat,clearcoatRoughnessFactor:l.clearcoatRoughness||0}),l.sheen&&l.sheen>0&&(P.KHR_materials_sheen={sheenColorFactor:l.sheenColor?[l.sheenColor.r,l.sheenColor.g,l.sheenColor.b]:[1,1,1],sheenRoughnessFactor:l.sheenRoughness||0}),l.transmission&&l.transmission>0&&(P.KHR_materials_transmission={transmissionFactor:l.transmission}),l.thickness&&l.thickness>0&&(P.KHR_materials_volume={thicknessFactor:l.thickness,attenuationDistance:l.attenuationDistance??1/0,attenuationColor:l.attenuationColor?[l.attenuationColor.r,l.attenuationColor.g,l.attenuationColor.b]:[1,1,1]}),l.ior!==void 0&&l.ior!==1.5&&(P.KHR_materials_ior={ior:l.ior}),l.dispersion&&l.dispersion>0&&(P.KHR_materials_dispersion={dispersion:l.dispersion}),l.iridescence&&l.iridescence>0&&(P.KHR_materials_iridescence={iridescenceFactor:l.iridescence,iridescenceIor:l.iridescenceIOR??1.3}),Object.keys(P).length>0&&(_.extensions=P),u.push(_),D}function R(g,D){let l=new Uint8Array(g.buffer,g.byteOffset,g.byteLength),h=dt(l.byteLength),w=new Uint8Array(h);w.set(l),t.push(w);let p=i.length;return i.push({buffer:0,byteOffset:r,byteLength:l.byteLength,target:D}),r+=h,p}function T(g,D,l,h,w,p,y){let _=R(g,l),P=s.length,G={bufferView:_,byteOffset:0,componentType:h,count:w,type:D};return p&&(G.min=p),y&&(G.max=y),s.push(G),P}n.traverse(g=>{(g.isLight||g.color&&g.intensity!==void 0)&&L.push({type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[g.position.x,g.position.y,g.position.z]})});let I=[];function F(g){let D={name:g.name||""},l=g.position,h=g.quaternion,w=g.scale;if((l.x||l.y||l.z)&&(D.translation=[l.x,l.y,l.z]),(h.x||h.y||h.z||h.w!==1)&&(D.rotation=[h.x,h.y,h.z,h.w]),(w.x!==1||w.y!==1||w.z!==1)&&(D.scale=[w.x,w.y,w.z]),g.userData&&Object.keys(g.userData).length>0&&(D.extras=JSON.parse(JSON.stringify(g.userData,(y,_)=>{if(!(y==="__proto__"||y==="prototype"||y==="constructor"))return typeof _=="function"?void 0:_})),g.userData.xr)){let y=bt(g.userData.xr);D.extensions={...D.extensions||{},MOZ_hubs_components:y,ANDROID_xr_scenecore:y},ue().xrTraitSerializer?.gltfNode(D,g.userData.xr),o.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(g.geometry){let y=g.geometry,_=y.attributes.position;if(_&&_.count>0){let P=[1/0,1/0,1/0],G=[-1/0,-1/0,-1/0];for(let B=0;B<_.count;B++){let z=_.getX(B),C=_.getY(B),V=_.getZ(B);z<P[0]&&(P[0]=z),z>G[0]&&(G[0]=z),C<P[1]&&(P[1]=C),C>G[1]&&(G[1]=C),V<P[2]&&(P[2]=V),V>G[2]&&(G[2]=V)}let k={attributes:{POSITION:T(_.array,"VEC3",34962,5126,_.count,P,G)}};if(y.attributes.normal&&(k.attributes.NORMAL=T(y.attributes.normal.array,"VEC3",34962,5126,y.attributes.normal.count)),y.attributes.uv&&(k.attributes.TEXCOORD_0=T(y.attributes.uv.array,"VEC2",34962,5126,y.attributes.uv.count)),y.index){let B=y.index.array instanceof Uint32Array;k.indices=T(y.index.array,"SCALAR",34963,B?5125:5123,y.index.count)}g.material&&(k.material=M(g.material));let x=g.userData?.variants;if(x&&typeof x=="object"){let B=new Map;for(let z of Object.keys(x)){if(!z||z==="__proto__"||z==="constructor"||z==="prototype")continue;let C=x[z];if(!C||typeof C!="object")continue;let V=v.indexOf(z);if(V===-1&&v.length<256&&(V=v.length,v.push(z)),V===-1)continue;let $=M(C),W=B.get($);W||(W=[],B.set($,W)),W.push(V)}if(B.size>0){let z=[];for(let[C,V]of B.entries())z.push({material:C,variants:V});k.extensions={...k.extensions||{},KHR_materials_variants:{mappings:z}},o.add("KHR_materials_variants")}}let H=g;if(H.isInstancedMesh&&typeof H.count=="number"&&H.count>0&&H.instanceMatrix?.array){let B=Math.min(1e4,Math.floor(H.count)),z=H.instanceMatrix.array,C=new Float32Array(B*3),V=new Float32Array(B*4),$=new Float32Array(B*3);for(let q=0;q<B;q++){let{t:te,r:se,s:X}=pt(z,q*16);C[q*3]=te[0],C[q*3+1]=te[1],C[q*3+2]=te[2],V[q*4]=se[0],V[q*4+1]=se[1],V[q*4+2]=se[2],V[q*4+3]=se[3],$[q*3]=X[0],$[q*3+1]=X[1],$[q*3+2]=X[2]}let W={TRANSLATION:T(C,"VEC3",0,5126,B),ROTATION:T(V,"VEC4",0,5126,B),SCALE:T($,"VEC3",0,5126,B)};if(H.instanceColor?.array&&H.instanceColor.array.length>=B*3){let q=new Float32Array(H.instanceColor.array.subarray(0,B*3));W._COLOR_0=T(q,"VEC3",0,5126,B)}D.extensions={...D.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},o.add("EXT_mesh_gpu_instancing")}let O=a.length;a.push({primitives:[k],name:g.name,...D.extras?{extras:D.extras}:{}}),D.mesh=O}}let p=d.length;if(d.push(D),c.push(g),g.children.length>0){D.children=[];for(let y of g.children)D.children.push(F(y))}return p}for(let g of n.children)I.push(F(g));let 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),E=[];if(typeof m=="function"&&c.length>0){let g=e?.duration??4,D=e?.fps??15,l=Math.max(2,Math.round(g*D)+1),h=new Float32Array(l),w=c.map(x=>({px:x.position.x,py:x.position.y,pz:x.position.z,qx:x.quaternion.x,qy:x.quaternion.y,qz:x.quaternion.z,qw:x.quaternion.w,sx:x.scale.x,sy:x.scale.y,sz:x.scale.z})),p=c.map(()=>new Float32Array(l*3)),y=c.map(()=>new Float32Array(l*4)),_=c.map(()=>new Float32Array(l*3));for(let x=0;x<l;x++){let H=x/(l-1)*g;h[x]=H;try{m(H)}catch{}for(let O=0;O<c.length;O++){let B=c[O];p[O][x*3]=B.position.x,p[O][x*3+1]=B.position.y,p[O][x*3+2]=B.position.z,y[O][x*4]=B.quaternion.x,y[O][x*4+1]=B.quaternion.y,y[O][x*4+2]=B.quaternion.z,y[O][x*4+3]=B.quaternion.w,_[O][x*3]=B.scale.x,_[O][x*3+1]=B.scale.y,_[O][x*3+2]=B.scale.z}}for(let x=0;x<c.length;x++){let H=c[x],O=w[x];H.position.set(O.px,O.py,O.pz),H.quaternion.set(O.qx,O.qy,O.qz,O.qw),H.scale.set(O.sx,O.sy,O.sz)}n.updateMatrixWorld(!0);let P=null,G=()=>(P===null&&(P=T(h,"SCALAR",0,5126,l,[0],[g])),P),N=[],k=[];for(let x=0;x<c.length;x++){let H=w[x],O=!1,B=!1,z=!1;for(let C=0;C<l;C++)(Math.abs(p[x][C*3]-H.px)>1e-4||Math.abs(p[x][C*3+1]-H.py)>1e-4||Math.abs(p[x][C*3+2]-H.pz)>1e-4)&&(O=!0),(Math.abs(y[x][C*4]-H.qx)>1e-4||Math.abs(y[x][C*4+1]-H.qy)>1e-4||Math.abs(y[x][C*4+2]-H.qz)>1e-4||Math.abs(y[x][C*4+3]-H.qw)>1e-4)&&(B=!0),(Math.abs(_[x][C*3]-H.sx)>1e-4||Math.abs(_[x][C*3+1]-H.sy)>1e-4||Math.abs(_[x][C*3+2]-H.sz)>1e-4)&&(z=!0);if(O){let C=T(p[x],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:x,path:"translation"}})}if(B){let C=T(y[x],"VEC4",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:x,path:"rotation"}})}if(z){let C=T(_[x],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:x,path:"scale"}})}}k.length>0&&E.push({name:"ProceduralLoop",samplers:N,channels:k})}let f=_e(d,a,n.userData),S={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:I}],scene:0,nodes:d,meshes:a,materials:u,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...f||o.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...o]}:{},...f||v.length>0?{extensions:{...f?{KHR_interactivity:f}:{},...v.length>0?{KHR_materials_variants:{variants:v.map(g=>({name:g}))}}:{}}}:{}},U=new Uint8Array(r),A=0;for(let g of t)U.set(g,A),A+=g.byteLength;return{gltf:S,bin:U.buffer,lights:L,environmentIntensity:n.environmentIntensity}}function Re(n){return new TextEncoder().encode(n)}function kt(n,e){let{gltf:t,bin:r}=gt(n,e),i=JSON.stringify(t),s=Re(i),a=(4-s.byteLength%4)%4,d=s.byteLength+a,o=20+d+8+r.byteLength,c=new Uint8Array(o),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,o,!0),u.setUint32(12,d,!0),u.setUint32(16,1313821514,!0),c.set(s,20);for(let v=0;v<a;v++)c[20+s.byteLength+v]=32;let b=20+d;return u.setUint32(b,r.byteLength,!0),u.setUint32(b+4,5130562,!0),c.set(new Uint8Array(r),b+8),c}function yt(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 a=s.count,d=new Float32Array(a*3),o=r.matrixWorld.elements;for(let A=0;A<a;A++){let g=s.getX(A),D=s.getY(A),l=s.getZ(A);d[A*3]=o[0]*g+o[4]*D+o[8]*l+o[12],d[A*3+1]=o[1]*g+o[5]*D+o[9]*l+o[13],d[A*3+2]=o[2]*g+o[6]*D+o[10]*l+o[14]}let c;if(i.attributes.normal){let A=i.attributes.normal;c=new Float32Array(a*3);let g=new Float32Array(9);ae(g,o);for(let D=0;D<a;D++){let l=A.getX(D),h=A.getY(D),w=A.getZ(D),p=g[0]*l+g[3]*h+g[6]*w,y=g[1]*l+g[4]*h+g[7]*w,_=g[2]*l+g[5]*h+g[8]*w,P=Math.hypot(p,y,_)||1;c[D*3]=p/P,c[D*3+1]=y/P,c[D*3+2]=_/P}}let u;if(i.attributes.uv){let A=i.attributes.uv;u=new Float32Array(a*2);for(let g=0;g<a;g++)u[g*2]=A.getX(g),u[g*2+1]=A.getY(g)}let b;if(i.index)b=i.index.array;else{b=a>65535?new Uint32Array(a):new Uint16Array(a);for(let A=0;A<a;A++)b[A]=A}let v="DefaultMaterial",L=[.8,.8,.8],M=.5,R=.1,T=0,I=0,F=1.5,m=1,E=[0,0,0];if(r.material){let A=r.material;v=A.name||`Material_${t.length}`,A.color&&(L=[A.color.r,A.color.g,A.color.b]),typeof A.roughness=="number"&&(M=A.roughness),typeof A.metalness=="number"&&(R=A.metalness),typeof A.clearcoat=="number"&&(T=A.clearcoat),typeof A.clearcoatRoughness=="number"&&(I=A.clearcoatRoughness),typeof A.ior=="number"&&(F=A.ior);let g=typeof A.opacity=="number"?A.opacity:1,D=typeof A.transmission=="number"?A.transmission:0;if(m=g*(1-D),A.emissive&&(A.emissive.r>0||A.emissive.g>0||A.emissive.b>0)){let l=A.emissiveIntensity??1;E=[A.emissive.r*l,A.emissive.g*l,A.emissive.b*l]}}let f,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);if(typeof S=="function"){let A=e?.duration??4,g=e?.fps??4,D=Math.max(2,Math.round(A*g)+1),l=[],h=[],w=[],p=[],y=[r.position.x,r.position.y,r.position.z],_=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],P=[r.scale.x,r.scale.y,r.scale.z],G=!1;for(let N=0;N<D;N++){let k=N/(D-1)*A;l.push(k);try{S(k)}catch{}h.push([r.position.x,r.position.y,r.position.z]),w.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),p.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-y[0])>1e-4||Math.abs(r.position.y-y[1])>1e-4||Math.abs(r.position.z-y[2])>1e-4||Math.abs(r.quaternion.x-_[0])>1e-4||Math.abs(r.quaternion.y-_[1])>1e-4||Math.abs(r.quaternion.z-_[2])>1e-4||Math.abs(r.quaternion.w-_[3])>1e-4||Math.abs(r.scale.x-P[0])>1e-4)&&(G=!0)}r.position.set(y[0],y[1],y[2]),r.quaternion.set(_[0],_[1],_[2],_[3]),r.scale.set(P[0],P[1],P[2]),G&&(f={times:l,translations:h,rotations:w,scales:p})}let U=r;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let A=Math.min(1e3,Math.floor(U.count)),g=U.instanceMatrix.array,D=U.instanceColor?.array,l=r.name||`Mesh_${t.length}`,h=new Float32Array(16),w=new Float32Array(9);for(let p=0;p<A;p++){let y=g.subarray(p*16,(p+1)*16);ee(h,o,y);let _=new Float32Array(a*3);for(let k=0;k<a;k++){let x=s.getX(k),H=s.getY(k),O=s.getZ(k);_[k*3]=h[0]*x+h[4]*H+h[8]*O+h[12],_[k*3+1]=h[1]*x+h[5]*H+h[9]*O+h[13],_[k*3+2]=h[2]*x+h[6]*H+h[10]*O+h[14]}let P;if(i.attributes.normal){let k=i.attributes.normal;P=new Float32Array(a*3),ae(w,h);for(let x=0;x<a;x++){let H=k.getX(x),O=k.getY(x),B=k.getZ(x),z=w[0]*H+w[3]*O+w[6]*B,C=w[1]*H+w[4]*O+w[7]*B,V=w[2]*H+w[5]*O+w[8]*B,$=Math.hypot(z,C,V)||1;P[x*3]=z/$,P[x*3+1]=C/$,P[x*3+2]=V/$}}let G=L,N=v;D&&D.length>=(p+1)*3&&(G=[L[0]*D[p*3],L[1]*D[p*3+1],L[2]*D[p*3+2]],N=`${v}_inst_${p}`),t.push({name:`${l}_${p}`,positions:_,indices:b,normals:P,uvs:u,materialName:N,color:G,roughness:M,metallic:R,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:m,emissiveColor:E,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:d,indices:b,normals:c,uvs:u,materialName:v,color:L,roughness:M,metallic:R,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:m,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:f})}}),t}function et(n){let e=[],t=n.gltf,r=ue().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),a=t.accessors||[],d=t.bufferViews||[],o=t.materials||[],c=t.meshes||[],u=t.nodes||[];function b(M){let R=a[M];if(!R)throw new Error(`Accessor ${M} not found`);let T=d[R.bufferView||0],I=(T.byteOffset||0)+(R.byteOffset||0),F=T.byteLength||0,m=s.slice(I,I+F);return{acc:R,buffer:m}}let v=new Map;if(u.length>0){let M=xe(t);for(let R=0;R<M.length;R++)v.set(R,M[R])}function L(M,R,T,I){let F=c[M];if(!F)return;let m=new Float32Array(9);ae(m,R);for(let E=0;E<(F.primitives||[]).length;E++){let f=F.primitives[E],S=f.attributes?.POSITION;if(S===void 0)continue;let{acc:U,buffer:A}=b(S),g=new Float32Array(A,0,U.count*3),D=new Float32Array(g.length);for(let C=0;C<U.count;C++){let V=g[C*3],$=g[C*3+1],W=g[C*3+2];D[C*3]=R[0]*V+R[4]*$+R[8]*W+R[12],D[C*3+1]=R[1]*V+R[5]*$+R[9]*W+R[13],D[C*3+2]=R[2]*V+R[6]*$+R[10]*W+R[14]}let l,h=f.attributes?.NORMAL;if(h!==void 0){let{acc:C,buffer:V}=b(h),$=new Float32Array(V,0,C.count*3);l=new Float32Array($.length);for(let W=0;W<C.count;W++){let q=$[W*3],te=$[W*3+1],se=$[W*3+2],X=m[0]*q+m[3]*te+m[6]*se,Z=m[1]*q+m[4]*te+m[7]*se,re=m[2]*q+m[5]*te+m[8]*se,oe=Math.hypot(X,Z,re)||1;l[W*3]=X/oe,l[W*3+1]=Z/oe,l[W*3+2]=re/oe}}let w,p=f.attributes?.TEXCOORD_0;if(p!==void 0){let{acc:C,buffer:V}=b(p);w=new Float32Array(V,0,C.count*2)}let y;if(f.indices!==void 0){let{acc:C,buffer:V}=b(f.indices);C.componentType===5125?y=new Uint32Array(V,0,C.count):y=new Uint16Array(V,0,C.count);let $=U.count;for(let W of y)if(W>=$)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${$}).`)}else{let C=U.count;y=C>65535?new Uint32Array(C):new Uint16Array(C);for(let V=0;V<C;V++)y[V]=V}let _="DefaultMaterial",P=[.8,.8,.8],G=.5,N=.1,k=0,x=0,H=1.5,O=1,B=[0,0,0];if(f.material!==void 0&&o[f.material]){let C=o[f.material];_=C.name||`Material_${f.material}`;let V=C.pbrMetallicRoughness||{},$=1;Array.isArray(V.baseColorFactor)&&(P=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&($=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(G=V.roughnessFactor),typeof V.metallicFactor=="number"&&(N=V.metallicFactor),Array.isArray(C.emissiveFactor)&&C.emissiveFactor.length>=3&&(B=[C.emissiveFactor[0],C.emissiveFactor[1],C.emissiveFactor[2]]);let W=C.extensions||{};W.KHR_materials_clearcoat&&(k=W.KHR_materials_clearcoat.clearcoatFactor??0,x=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(H=W.KHR_materials_ior.ior);let q=W.KHR_materials_transmission?.transmissionFactor??0;O=$*(1-q)}let z=(F.primitives||[]).length>1?`${T}_p${E}`:T;e.push({name:z,positions:D,indices:y,normals:l,uvs:w,materialName:_,color:P,roughness:G,metallic:N,clearcoat:k,clearcoatRoughness:x,ior:H,opacity:O,emissiveColor:B,xrTraits:I?.xr||F.extras?.xr})}}if(u.length>0)for(let M=0;M<u.length;M++){let R=u[M];if(R.mesh!==void 0&&R.mesh<c.length){let T=v.get(M)||J(),I=R.name||c[R.mesh].name||`Node_${M}`,F=R.extensions?.EXT_mesh_gpu_instancing?.attributes;if(F&&typeof F=="object"){let m=F.TRANSLATION,E=F.ROTATION,f=F.SCALE,S=m!==void 0?(()=>{let{acc:D,buffer:l}=b(m);return new Float32Array(l,0,D.count*3)})():null,U=E!==void 0?(()=>{let{acc:D,buffer:l}=b(E);return new Float32Array(l,0,D.count*4)})():null,A=f!==void 0?(()=>{let{acc:D,buffer:l}=b(f);return new Float32Array(l,0,D.count*3)})():null,g=Math.min(1e3,S?S.length/3:U?U.length/4:A?A.length/3:0);if(g>0){let D=new Float32Array(16),l=new Float32Array(16);for(let h=0;h<g;h++){let w=S?[S[h*3],S[h*3+1],S[h*3+2]]:[0,0,0],p=U?[U[h*4],U[h*4+1],U[h*4+2],U[h*4+3]]:[0,0,0,1],y=A?[A[h*3],A[h*3+1],A[h*3+2]]:[1,1,1];he(D,p,w,y),ee(l,T,D),L(R.mesh,l,`${I}_${h}`,R.extras)}continue}}L(R.mesh,T,I,R.extras)}}else{let M=J();for(let R=0;R<c.length;R++){let T=c[R].name||`Mesh_${R}`;L(R,M,T,c[R].extras)}}return e}function Fe(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 Je(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function K(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 Qe(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*3])}, ${K(n[r*3+1])}, ${K(n[r*3+2])})`;return t.join(", ")}function vt(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*2])}, ${K(1-n[r*2+1])})`;return t.join(", ")}function xt(n){return Array.from(n).join(", ")}function Se(n){let e=new Map;for(let o of n){let c=Fe(o.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:o.color||[.8,.8,.8],roughness:o.roughness??.5,metallic:o.metallic??0,clearcoat:o.clearcoat??0,clearcoatRoughness:o.clearcoatRoughness??0,ior:o.ior??1.5,opacity:o.opacity??1,emissiveColor:o.emissiveColor||[0,0,0]})}let t=0,r=null;for(let o of n){if(o.timeSamples&&o.timeSamples.times.length>0){let c=o.timeSamples.times[o.timeSamples.times.length-1];c>t&&(t=c)}o.xrTraits?.anchor&&!r&&(r=o.xrTraits.anchor==="vertical"||o.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
252
+ void main(){fragColor=uColorId;}`;function Ie(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var Ve=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Xe(){let n=ue().xrDepthShader;return{fs:ot.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Ve,...n.uniformNames]:Ve}}function ct(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 Ce(n,e,t,r,i,s,a,d){if(r===void 0||!e.accessors?.[r])return null;let o=Ee(e,t,e.accessors[r],s);if(!o)return null;d&&(o=o.slice(),Ue(o,d));let c=n.createBuffer();return a.push(c),n.bindBuffer(34962,c),n.bufferData(34962,o,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),o}function Le(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function qe(n,e,t){let r=Xe(),i=We,s=r.fs,a=!1;for(let o of ne)if(o.onResolveShader){let c=o.onResolveShader(e,t,i,s);c&&(i=c.vs,s=c.fs,a=!0)}let d=a?ye(n,i,s):null;return{program:d,uniforms:d?Ie(n,d,r.uniforms):null}}function lt(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,a=new Float32Array(i*20);for(let o=0;o<i;o++)a.set(r.subarray(o*16,o*16+16),o*20),a[o*20+16]=s?s[o*3]:1,a[o*20+17]=s?s[o*3+1]:1,a[o*20+18]=s?s[o*3+2]:1,a[o*20+19]=1;let d=n.createBuffer();t.push(d),n.bindBuffer(34962,d),n.bufferData(34962,a,35044);for(let o=0;o<5;o++)n.enableVertexAttribArray(8+o),n.vertexAttribPointer(8+o,4,5126,!1,80,o*16),n.vertexAttribDivisor(8+o,1);return!0}function mt(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var _t=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ke=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Te(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function Ye(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=a=>a!==void 0&&e[a.index]?e[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ze(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&n.deleteVertexArray(a.vao),a.buffers)for(let o of a.buffers)n.deleteBuffer(o);i(a.texture),i(a.metallicRoughnessTexture),i(a.normalTexture),i(a.occlusionTexture);let d=new Set;a.customProgram&&d.add(a.customProgram);for(let o of a.programCache?.values()??[])o.program&&d.add(o.program);for(let o of d)n.deleteProgram(o)}if(t)for(let s of t)i(s)}function Oe(n,e,t=Ke,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ht(n,e,t,r,i)}catch(s){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Ze(n,a,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let d of i.buffers)n.deleteBuffer(d);throw s}}function ht(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=me("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let d=e.bin,o=[];i.meshes=o;let c=[],u=s.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((m,R)=>{c.push(typeof m?.name=="string"&&m.name?m.name:`Variant_${R}`)});let b=Me(s),v=[];if(Array.isArray(s.nodes))for(let m=0;m<s.nodes.length;m++){let R=s.nodes[m];R.mesh!==void 0&&s.meshes&&s.meshes[R.mesh]&&v.push({node:R,nodeIdx:m,meshIdx:R.mesh})}let L=v.length>0?v:(s.meshes||[]).map((m,R)=>({node:m,nodeIdx:-1,meshIdx:R})),E=[];if(Array.isArray(e.lights)&&e.lights.length>0)E.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let m=s.extensions.KHR_lights_punctual.lights;for(let R of m){let p=R.type==="directional"?"directional":R.type==="point"?"point":"ambient";E.push({type:p,color:R.color||[1,1,1],intensity:R.intensity!==void 0?R.intensity:1})}}if(E.length===0&&(E.push({type:"ambient",color:[1,1,1],intensity:.35}),E.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),L.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${L.length}`);let x=[];if(i.gpuTextures=x,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let m=0;m<s.textures.length;m++){let R=s.textures[m],p=s.images[R.source];if(p){let g=n.createTexture();if(n.bindTexture(3553,g),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),p.bufferView!==void 0){let _=s.bufferViews[p.bufferView],P=d.slice(_.byteOffset||0,(_.byteOffset||0)+_.byteLength),G=new Blob([P],{type:p.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(G).then(N=>{n.bindTexture(3553,g),n.texImage2D(3553,0,6408,6408,5121,N),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(p.uri){let _=ct(p.uri);if(_){let P=new Image;P.crossOrigin="anonymous",P.referrerPolicy="no-referrer",P.onload=()=>{n.bindTexture(3553,g),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()},P.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",p.uri)}x.push(g)}else x.push(null)}}let T=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0],F=0,h=0;for(let m=0;m<L.length;m++){let R=L[m],p=s.meshes[R.meshIdx],g=R.nodeIdx>=0?b[R.nodeIdx]:J(),_=new Float32Array(9);ae(_,g);let P={name:R.node.name||p.name||`Mesh_${R.meshIdx}`,nodeIndex:R.nodeIdx,transform:g,normalMatrix:_,primitives:[],extras:R.node.extras||p.extras};i.mesh=P;let G=R.node?.extensions?.EXT_mesh_gpu_instancing;if(G&&G.attributes&&typeof G.attributes=="object"){let N=G.attributes,k=N.TRANSLATION!==void 0?s.accessors?.[N.TRANSLATION]:null,M=N.ROTATION!==void 0?s.accessors?.[N.ROTATION]:null,H=N.SCALE!==void 0?s.accessors?.[N.SCALE]:null,O=N._COLOR_0!==void 0?s.accessors?.[N._COLOR_0]:null,B=Number(k?.count??M?.count??H?.count??0);if(!Number.isFinite(B)||B<0||B>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${B}`);if(B>0){let z=(X,Z)=>{if(!X||X.bufferView===void 0||!s.bufferViews?.[X.bufferView])return null;let re=X.componentType??5126,oe=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(re!==5120&&re!==5121&&re!==5122&&re!==5123&&re!==5126)return oe(`componentType ${re}`);if(!(Number(X.count)>=B))return oe(`count ${X.count} < ${B}`);let Y=null;try{Y=Ee(s,d,{...X,count:B},Z)}catch{return oe("out of bounds")}return!Y||!Y.every(Number.isFinite)?oe("non-finite value"):Y},C=z(k,3),V=z(M,4),$=z(H,3),W=O?.type==="VEC4"?4:3,q=z(O,W),te=new Float32Array(B*16),se=J();for(let X=0;X<B;X++){let Z=C?[C[X*3],C[X*3+1],C[X*3+2]]:[0,0,0],re=V?[V[X*4],V[X*4+1],V[X*4+2],V[X*4+3]]:[0,0,0,1],oe=$?[$[X*3],$[X*3+1],$[X*3+2]]:[1,1,1];he(se,re,Z,oe),te.set(se,X*16)}if(P.instanceMatrices=te,q){let X=new Float32Array(B*3);for(let Z=0;Z<B;Z++)X[Z*3]=q[Z*W],X[Z*3+1]=q[Z*W+1],X[Z*3+2]=q[Z*W+2];P.instanceColors=X}}}for(let N of p.primitives||[]){if(N.extensions?.KHR_draco_mesh_compression){let Y=me("draco");Y&&Y.decodePrimitive(s,N,d)}let k=[],M=n.createVertexArray();i.vao=M,i.buffers=k,n.bindVertexArray(M);let H=lt(n,P,k),O=s.accessors[N.attributes.POSITION],B=Number(O?.count??0);if(!Number.isFinite(B)||B<0||F+B>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(F+=B,O?.min&&O?.max){let Y=Q=>{for(let j=0;j<3;j++){let ie=Q[12+j],ce=Q[12+j];for(let le=0;le<3;le++){let pe=Q[le*4+j]*O.min[le],be=Q[le*4+j]*O.max[le];ie+=pe<be?pe:be,ce+=pe>be?pe:be}ie<T[j]&&(T[j]=ie),ce>I[j]&&(I[j]=ce)}};if(P.instanceMatrices&&P.instanceMatrices.length>=16){let Q=P.instanceMatrices.length>>4,j=J();for(let ie=0;ie<Q;ie++){let ce=P.instanceMatrices.subarray(ie*16,ie*16+16);ee(j,g,ce),Y(j)}}else Y(g)}let z=Ce(n,s,d,N.attributes.POSITION,0,3,k);Ce(n,s,d,N.attributes.NORMAL,1,3,k),Ce(n,s,d,N.attributes.TEXCOORD_0,2,2,k,mt(s,N));let C=0,V=5123,$=null;if(N.indices!==void 0){let Y=s.accessors[N.indices],j=(s.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(C=Number(Y.count??0),!Number.isFinite(C)||C<0||h+C>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);h+=C,V=Y.componentType===5125?5125||5125:5123||5123;let ie=n.createBuffer();k.push(ie),n.bindBuffer(34963,ie),Y.componentType===5125?($=new Uint32Array(d,j,Y.count),n.bufferData(34963,$,35044)):Y.componentType===5121?($=Uint16Array.from(new Uint8Array(d,j,Y.count)),n.bufferData(34963,$,35044)):($=j%2===0?new Uint16Array(d,j,Y.count):new Uint16Array(d.slice(j,j+Y.count*2)),n.bufferData(34963,$,35044))}else C=O.count;let W={};for(let Y of ne)if(Y.onBuildPrimitiveVAO){let Q=Y.onBuildPrimitiveVAO(n,M,N,s,d);Q&&(W[Y.name]=Q)}n.bindVertexArray(null);let q=s.materials&&N.material!==void 0?s.materials[N.material]:null,{program:te,uniforms:se}=qe(n,N,q),X=Ye(q,x),Z=!!(q?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),re=N.extensions?.KHR_materials_variants?.mappings,oe=Array.isArray(re)?re.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(Q=>Number(Q)|0)})):void 0;P.primitives.push({vao:M,instanced:H,indexCount:C,indexType:V,...X,positions:z,indices:$,buffers:k,materialIndex:N.material,defaultMaterialIndex:N.material,variantMappings:oe,primitiveDef:N,programCache:new Map([[N.material??-1,{program:te,uniforms:se}]]),pluginData:W,customProgram:te,customUniforms:se,isTransmissive:Z})}o.push(P)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(I[0])||(I=[1,1,1]);let w=[(T[0]+I[0])/2,(T[1]+I[1])/2,(T[2]+I[2])/2],f=I[0]-T[0],S=I[1]-T[1],U=I[2]-T[2],A=Math.max(Math.hypot(f,S,U)/2,.5),y=[T[0],T[1],T[2]],D=[I[0],I[1],I[2]],l=e.animations;if(!l){for(let m of ne)if(m.onParseGLB?.(e),e.animations){l=e.animations;break}}return l||(l=[]),{meshes:o,bounds:{center:w,radius:A,min:y,max:D},lights:E,animations:l,worldMatrices:b,gpuTextures:x,availableVariants:c}}function fe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var Ae=class{constructor(e,t,r){this.supportsInstanceOffsets=!0;this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.activeViewMatrix=null;this.modelMatrix=J();this.mvpMatrix=J();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:J(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Le(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=Pe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let d=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!d)throw new Error("WebGL2 not supported");this.gl=d,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){it(e,t)}static getDecoder(e){return me(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=Xe();this.renderProg=ye(e,We,t.fs),this.pickProg=ye(e,at,ut),this.uRender=Ie(e,this.renderProg,t.uniforms),this.uPick=Ie(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ne)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:a,worldMatrices:d,gpuTextures:o,availableVariants:c}=Oe(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=a||[],this.worldMatrices=d||[],this.gpuTextures=o||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let v of e.gltf.nodes)this.initialNodeTransforms.push({t:v.translation?[v.translation[0],v.translation[1],v.translation[2]]:[0,0,0],r:v.rotation?[v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]]:[0,0,0,1],s:v.scale?[v.scale[0],v.scale[1],v.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let v of ne)v.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.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Le(u));let b=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;b!==void 0&&(this.envIntensity=Math.max(0,Number(b)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData($e(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(de(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=de(e),{meshes:i}=Oe(this.gl,r,Ke,()=>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=[],a=[],d=[];for(let o of this.lights){let c=o.color||[1,1,1],u=o.intensity!==void 0?o.intensity:1;if(o.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(o.type==="directional"&&i.length<6){let b=o.direction||[.5,1,.8];i.push(b[0],b[1],b[2]),s.push(c[0]*u,c[1]*u,c[2]*u)}else if(o.type==="point"&&a.length<6){let b=o.position||[0,0,0];a.push(b[0],b[1],b[2]),d.push(c[0]*u,c[1]*u,c[2]*u)}}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,a.length/3),a.length>0&&(t.uniform3fv(e.uPointLightPos,a),t.uniform3fv(e.uPointLightColor,d)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Le(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Pe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ne)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ne)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(u=>u.primitives.filter(b=>b.materialIndex===r||e.length===1&&b.materialIndex===void 0)),s=i[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],d=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:d,roughnessFactor:o,setBaseColorFactor:u=>{let b=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=b,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=b);for(let v of i)v.baseColor=b;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let b of i)b.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let b of i)b.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let s of this.meshes)for(let a of s.primitives){let d=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){d=c.material;break}}let o=d!==void 0?i[d]:void 0;a.materialIndex=o?d:void 0,Object.assign(a,Ye(o,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=qe(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of ne)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=J();ee(r,this.projMatrix,this.viewMatrix);let[i,s,a]=e,d=t?t[0]:0,o=t?t[1]:0,c=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],s=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],a=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(d=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],c=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let b=r[0]*i+r[4]*s+r[8]*a+r[12],v=r[1]*i+r[5]*s+r[9]*a+r[13],L=r[2]*i+r[6]*s+r[10]*a+r[14],E=r[3]*i+r[7]*s+r[11]*a+r[15];if(E<=1e-4)return{x:0,y:0,z:1,visible:!1};let x=b/E,T=v/E,I=L/E,F=this.canvas.getBoundingClientRect(),h=F.width||this.canvas.clientWidth||this.canvas.width||300,w=F.height||this.canvas.clientHeight||this.canvas.height||150,f=(x*.5+.5)*h,S=(-T*.5+.5)*w,U=x>=-1.1&&x<=1.1&&T>=-1.1&&T<=1.1&&I>=-1&&I<=1;if(U&&t){let[A,y,D]=fe(this),l=[i-A,s-y,a-D];d*l[0]+o*l[1]+c*l[2]>.05&&(U=!1)}return{x:f,y:S,z:I,visible:U}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],d=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],o=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;o[0]+=(-i*a[0]+s*d[0])*c,o[1]+=(-i*a[1]+s*d[1])*c,o[2]+=(-i*a[2]+s*d[2])*c,this.customTarget=o}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,a=r.height||300,d=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(a/i.height)):Math.floor(t);return this.performMeshPick(d,o,!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),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let d=J();ee(d,this.projMatrix,this.viewMatrix);let o=[],c=Math.max(0,Math.min(s-1,e)),u=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,a),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let U=0;U<this.meshes.length;U++){let A=this.meshes[U];if(A.visible===!1||A.isPluginMesh)continue;let y=U+1,D=(y&255)/255,l=(y>>8&255)/255,m=(y>>16&255)/255;i.uniform4f(this.uPick.uColorId,D,l,m,1),ee(this.modelMatrix,this.modelRootMatrix,A.transform);let R=A.instanceMatrices;if(R&&R.length>=16){let p=R.length>>4,g=J();for(let _ of A.primitives){i.bindVertexArray(_.vao);for(let P=0;P<p;P++)ee(g,this.modelMatrix,R.subarray(P*16,P*16+16)),ee(this.mvpMatrix,d,g),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Te(i,_)}}else{ee(this.mvpMatrix,d,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let p of A.primitives)i.bindVertexArray(p.vao),Te(i,p)}}let f=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,f),i.bindFramebuffer(36160,null);let S=f[0]+(f[1]<<8)+(f[2]<<16);S>0&&S<=this.meshes.length&&(o=[this.meshes[S-1]])}o.length===0&&(o=this.meshes.filter(f=>f.visible!==!1));let b=null,v=1/0,L=[0,0,0],E=[0,1,0],[x,T,I]=fe(this),F=J();for(let f of o){ee(F,this.modelRootMatrix,f.transform);let S=f.instanceMatrices,U=S&&S.length>=16?S.length>>4:1;for(let A=0;A<U;A++){S&&S.length>=16?ee(this.modelMatrix,F,S.subarray(A*16,A*16+16)):this.modelMatrix.set(F),ee(this.mvpMatrix,d,this.modelMatrix);let y=J();if(!ke(y,this.mvpMatrix))continue;let D=(c+.5)/s*2-1,l=(u+.5)/a*2-1,m=[0,0,0],R=[0,0,0];De(m,D,l,-1,y),De(R,D,l,1,y);let p=R[0]-m[0],g=R[1]-m[1],_=R[2]-m[2],P=Math.hypot(p,g,_)||1,G=p/P,N=g/P,k=_/P,M={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((O=>{for(let B of f.primitives){if(!B.positions)continue;let z=B.positions,C=B.indices,V=Math.floor(C?C.length/3:z.length/9);for(let $=0;$<V;$++){let W=C?C[$*3]:$*3,q=C?C[$*3+1]:$*3+1,te=C?C[$*3+2]:$*3+2;Ge(m[0],m[1],m[2],G,N,k,z[W*3],z[W*3+1],z[W*3+2],z[q*3],z[q*3+1],z[q*3+2],z[te*3],z[te*3+1],z[te*3+2],M,O)}}})(1e-4),isFinite(M.distance)){let O=M.point[0],B=M.point[1],z=M.point[2],C=this.modelMatrix,V=C[0]*O+C[4]*B+C[8]*z+C[12],$=C[1]*O+C[5]*B+C[9]*z+C[13],W=C[2]*O+C[6]*B+C[10]*z+C[14],q=V-x,te=$-T,se=W-I,X=Math.hypot(q,te,se);if(X<v){ae(this.normalMatrix,this.modelMatrix);let Z=this.normalMatrix,re=M.normal[0],oe=M.normal[1],Y=M.normal[2],Q=Z[0]*re+Z[3]*oe+Z[6]*Y,j=Z[1]*re+Z[4]*oe+Z[7]*Y,ie=Z[2]*re+Z[5]*oe+Z[8]*Y,ce=Math.hypot(Q,j,ie)||1;Q/=ce,j/=ce,ie/=ce,Q*q+j*te+ie*se>0&&(Q=-Q,j=-j,ie=-ie),b=f,v=Math.round(X*1e3)/1e3,L=[Math.round(V*1e3)/1e3,Math.round($*1e3)/1e3,Math.round(W*1e3)/1e3],E=[Math.round(Q*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(ie*1e3)/1e3]}}}}if(!b)return null;let w={meshIndex:this.meshes.indexOf(b),meshName:b.name,nodeIndex:b.nodeIndex,distance:v,hitPoint:L,normal:E,screenX:e,screenY:t};if(r){for(let f of ne)f.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,a=i?Math.max(1,t-r):r,d=(s+.5)/a*2-1;return Math.floor((d*.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);ve(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;xe(this.viewMatrix,fe(this),r,[0,1,0]),ee(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 ne)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 ne)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 a of ne)a.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 a of ne)a.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 a={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,t,r,i,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let d=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:d,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let h=Math.max(2,this.canvas.width||2),w=Math.max(1,this.canvas.height||1),f=Math.max(1,Math.floor(h*.5)),S=Math.max(1,h-f),U=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),A=this.customTarget||this.bounds.center,[y,D,l]=fe(this),m=Math.cos(this.currTheta),R=-Math.sin(this.currTheta),p=.032,g=J(),_=J(),P=[y-m*p,D,l-R*p],G=[A[0]-m*p*.25,A[1],A[2]-R*p*.25];ve(g,this.fov,f/w,.1,U),xe(_,P,G,[0,1,0]);let N=J(),k=J(),M=[y+m*p,D,l+R*p],H=[A[0]+m*p*.25,A[1],A[2]+R*p*.25];ve(N,this.fov,S/w,.1,U),xe(k,M,H,[0,1,0]),this.render({viewMatrix:_,projMatrix:g,eyePos:P,viewport:[0,0,f,w],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:k,projMatrix:N,eyePos:M,viewport:[f,0,S,w],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,h,w);return}let t=this.gl,r=0,i=0,s=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],a=e.viewport[3],t.viewport(r,i,s,a)):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 d=J(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,ee(d,e?.projMatrix??this.projMatrix,o);let c=ue().xrDepthShader,u=nt(this.toneMapping),[b,v,L]=e?e.eyePos:fe(this);for(let h of ne)h.onBeforeDrawScene?.(this,t,d,[b,v,L],u);let E=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&E===0)return;let x=e?.eye||"none",T=!1,I=E>0?[...this.backdropMeshes,...this.meshes]:this.meshes,F=h=>{for(let w=0;w<I.length;w++){let f=I[w];if(f.visible===!1)continue;let S=this.selectedMeshName!==""&&f.name===this.selectedMeshName;w<E||f.worldSpace===!0||f.name==="__xr_reticle__"?this.modelMatrix.set(f.transform):ee(this.modelMatrix,this.modelRootMatrix,f.transform),ee(this.mvpMatrix,d,this.modelMatrix),ae(f.normalMatrix,this.modelMatrix);let U=f.extras?.xr?.stereo||f.userData?.xr?.stereo,A=0,y=0,D=1,l=1;U==="sbs"?(D=.5,A=x==="right"?.5:0):U==="ou"&&(l=.5,y=x==="right"?.5:0);for(let m of f.primitives){let R=!!m.isTransmissive;if(!h&&R){T=!0;continue}if(h&&!R)continue;let p=m.customProgram||this.renderProg,g=m.customUniforms||this.uRender;t.useProgram(p),t.vertexAttrib3f(3,0,0,0),g.uInstanced&&t.uniform1i(g.uInstanced,0),t.uniform1i(g.uToneMapping,u),t.uniform1f(g.uEnvIntensity,this.envIntensity),g.uExposure&&t.uniform1f(g.uExposure,this.exposure),t.uniform3f(g.uCameraPos,b,v,L),t.uniform1f(g.uEmissive,S?1:0),t.uniformMatrix4fv(g.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(g.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(g.uNormalMatrix,!1,f.normalMatrix),g.uUvTransform&&t.uniform4f(g.uUvTransform,A,y,D,l),g.uViewportSize&&t.uniform2f(g.uViewportSize,Math.max(1,s),Math.max(1,a)),c?.bind(t,g,this.xrDepthState,o,[r,i,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(g.uEnvironmentMap,4),t.uniform1i(g.uHasEnvironmentMap,1)):t.uniform1i(g.uHasEnvironmentMap,0),this.bindLights(g),g.uSectionEnabled&&t.uniform1i(g.uSectionEnabled,0);for(let P of ne)P.onBeforeDrawPrimitive?.(t,p,m,f,this.worldMatrices||[],this.gltf);t.uniform4fv(g.uBaseColor,m.baseColor),t.uniform1f(g.uMetallic,m.metallic),t.uniform1f(g.uRoughness,m.roughness),g.uClearcoat&&t.uniform2f(g.uClearcoat,m.clearcoat??0,m.clearcoatRoughness??.04),m.texture?(t.activeTexture(33984),t.bindTexture(3553,m.texture),t.uniform1i(g.uBaseColorTexture,0),t.uniform1i(g.uHasTexture,1)):t.uniform1i(g.uHasTexture,0),m.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,m.metallicRoughnessTexture),t.uniform1i(g.uMetallicRoughnessTexture,1),t.uniform1i(g.uHasMetallicRoughnessTexture,1)):t.uniform1i(g.uHasMetallicRoughnessTexture,0),m.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,m.normalTexture),t.uniform1i(g.uNormalTexture,2),t.uniform1i(g.uHasNormalTexture,1),t.uniform1f(g.uNormalScale,m.normalScale)):t.uniform1i(g.uHasNormalTexture,0),m.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,m.occlusionTexture),t.uniform1i(g.uOcclusionTexture,3),t.uniform1i(g.uHasOcclusionTexture,1),t.uniform1f(g.uOcclusionStrength,m.occlusionStrength)):t.uniform1i(g.uHasOcclusionTexture,0),t.bindVertexArray(m.vao);let _=f.instanceMatrices;if(m.instanceCount!==void 0)t.drawElementsInstanced(4,m.indexCount,m.indexType,0,m.instanceCount);else if(_&&_.length>=16&&m.instanced&&g.uInstanced&&g.uViewProj){let P=_.length>>4;t.uniform1i(g.uInstanced,1),t.uniformMatrix4fv(g.uViewProj,!1,d),m.indices?t.drawElementsInstanced(4,m.indexCount,m.indexType,0,P):t.drawArraysInstanced(4,0,m.indexCount,P),t.uniform1i(g.uInstanced,0)}else if(_&&_.length>=16){let P=_.length>>4,G=f.instanceColors,N=J(),k=new Float32Array(9),M=[m.baseColor[0],m.baseColor[1],m.baseColor[2],m.baseColor[3]];for(let H=0;H<P;H++)ee(N,this.modelMatrix,_.subarray(H*16,H*16+16)),ee(this.mvpMatrix,d,N),ae(k,N),t.uniformMatrix4fv(g.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(g.uModel,!1,N),t.uniformMatrix3fv(g.uNormalMatrix,!1,k),G&&(M[0]=m.baseColor[0]*G[H*3],M[1]=m.baseColor[1]*G[H*3+1],M[2]=m.baseColor[2]*G[H*3+2],M[3]=m.baseColor[3],t.uniform4fv(g.uBaseColor,M)),Te(t,m)}else Te(t,m)}}};if(F(!1),T){for(let h of ne)h.onBeforeTransmissivePass?.(t,this);F(!0)}for(let h of ne)h.onAfterRender?.(t,this,d,e?.eye??"none",[r,i,s,a],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){Ze(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of ne)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()}};Ae.registerPlugin=Ne,Ae.getRegisteredPlugins=Be;function ft(n){return n+3&-4}function dt(n,e=0){let t=(M,H)=>typeof M=="number"&&Number.isFinite(M)?M:H,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),a=t(n[e+0],1),d=t(n[e+1],0),o=t(n[e+2],0),c=t(n[e+4],0),u=t(n[e+5],1),b=t(n[e+6],0),v=t(n[e+8],0),L=t(n[e+9],0),E=t(n[e+10],1),x=Math.hypot(a,d,o),T=Math.hypot(c,u,b),I=Math.hypot(v,L,E);a*(u*E-L*b)-c*(d*E-L*o)+v*(d*b-u*o)<0&&(x=-x);let h=Math.abs(x)>1e-8?1/x:0,w=Math.abs(T)>1e-8?1/T:0,f=Math.abs(I)>1e-8?1/I:0,S=a*h,U=d*h,A=o*h,y=c*w,D=u*w,l=b*w,m=v*f,R=L*f,p=E*f,g=S+D+p,_=0,P=0,G=0,N=1;if(g>0){let M=.5/Math.sqrt(g+1);N=.25/M,_=(l-R)*M,P=(m-A)*M,G=(U-y)*M}else if(S>D&&S>p){let M=2*Math.sqrt(Math.max(0,1+S-D-p));M>1e-8&&(N=(l-R)/M,_=.25*M,P=(y+U)/M,G=(m+A)/M)}else if(D>p){let M=2*Math.sqrt(Math.max(0,1+D-S-p));M>1e-8&&(N=(m-A)/M,_=(y+U)/M,P=.25*M,G=(l+R)/M)}else{let M=2*Math.sqrt(Math.max(0,1+p-S-D));M>1e-8&&(N=(U-y)/M,_=(m+A)/M,P=(l+R)/M,G=.25*M)}let k=Math.hypot(_,P,G,N);return k>1e-8&&Number.isFinite(k)?(_/=k,P/=k,G/=k,N/=k):(_=0,P=0,G=0,N=1),{t:[r,i,s],r:[_,P,G,N],s:[x,T,I]}}function pt(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 bt(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],a=[],d=[],o=new Set,c=[],u=[],b=new Map,v=[],L=[];function E(y){let D=b.get(y);if(D!==void 0)return D;D=u.length,b.set(y,D);let l=y,m=l.color?.r??.8,R=l.color?.g??.8,p=l.color?.b??.8,g=l.opacity??1,_={name:l.name||"",pbrMetallicRoughness:{baseColorFactor:[m,R,p,g],metallicFactor:l.metalness??.1,roughnessFactor:l.roughness??.5},doubleSided:l.side===2||!!l.doubleSided};if(l.emissive&&(l.emissive.r>0||l.emissive.g>0||l.emissive.b>0)){let G=l.emissiveIntensity??1;_.emissiveFactor=[l.emissive.r*G,l.emissive.g*G,l.emissive.b*G]}let P={};return l.clearcoat&&l.clearcoat>0&&(P.KHR_materials_clearcoat={clearcoatFactor:l.clearcoat,clearcoatRoughnessFactor:l.clearcoatRoughness||0}),l.sheen&&l.sheen>0&&(P.KHR_materials_sheen={sheenColorFactor:l.sheenColor?[l.sheenColor.r,l.sheenColor.g,l.sheenColor.b]:[1,1,1],sheenRoughnessFactor:l.sheenRoughness||0}),l.transmission&&l.transmission>0&&(P.KHR_materials_transmission={transmissionFactor:l.transmission}),l.thickness&&l.thickness>0&&(P.KHR_materials_volume={thicknessFactor:l.thickness,attenuationDistance:l.attenuationDistance??1/0,attenuationColor:l.attenuationColor?[l.attenuationColor.r,l.attenuationColor.g,l.attenuationColor.b]:[1,1,1]}),l.ior!==void 0&&l.ior!==1.5&&(P.KHR_materials_ior={ior:l.ior}),l.dispersion&&l.dispersion>0&&(P.KHR_materials_dispersion={dispersion:l.dispersion}),l.iridescence&&l.iridescence>0&&(P.KHR_materials_iridescence={iridescenceFactor:l.iridescence,iridescenceIor:l.iridescenceIOR??1.3}),Object.keys(P).length>0&&(_.extensions=P),u.push(_),D}function x(y,D){let l=new Uint8Array(y.buffer,y.byteOffset,y.byteLength),m=ft(l.byteLength),R=new Uint8Array(m);R.set(l),t.push(R);let p=i.length;return i.push({buffer:0,byteOffset:r,byteLength:l.byteLength,target:D}),r+=m,p}function T(y,D,l,m,R,p,g){let _=x(y,l),P=s.length,G={bufferView:_,byteOffset:0,componentType:m,count:R,type:D};return p&&(G.min=p),g&&(G.max=g),s.push(G),P}n.traverse(y=>{(y.isLight||y.color&&y.intensity!==void 0)&&L.push({type:y.type,color:[y.color.r,y.color.g,y.color.b],intensity:y.intensity,position:[y.position.x,y.position.y,y.position.z]})});let I=[];function F(y){let D={name:y.name||""},l=y.position,m=y.quaternion,R=y.scale;if((l.x||l.y||l.z)&&(D.translation=[l.x,l.y,l.z]),(m.x||m.y||m.z||m.w!==1)&&(D.rotation=[m.x,m.y,m.z,m.w]),(R.x!==1||R.y!==1||R.z!==1)&&(D.scale=[R.x,R.y,R.z]),y.userData&&Object.keys(y.userData).length>0&&(D.extras=JSON.parse(JSON.stringify(y.userData,(g,_)=>{if(!(g==="__proto__"||g==="prototype"||g==="constructor"))return typeof _=="function"?void 0:_})),y.userData.xr)){let g=pt(y.userData.xr);D.extensions={...D.extensions||{},MOZ_hubs_components:g,ANDROID_xr_scenecore:g},ue().xrTraitSerializer?.gltfNode(D,y.userData.xr),o.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(y.geometry){let g=y.geometry,_=g.attributes.position;if(_&&_.count>0){let P=[1/0,1/0,1/0],G=[-1/0,-1/0,-1/0];for(let B=0;B<_.count;B++){let z=_.getX(B),C=_.getY(B),V=_.getZ(B);z<P[0]&&(P[0]=z),z>G[0]&&(G[0]=z),C<P[1]&&(P[1]=C),C>G[1]&&(G[1]=C),V<P[2]&&(P[2]=V),V>G[2]&&(G[2]=V)}let k={attributes:{POSITION:T(_.array,"VEC3",34962,5126,_.count,P,G)}};if(g.attributes.normal&&(k.attributes.NORMAL=T(g.attributes.normal.array,"VEC3",34962,5126,g.attributes.normal.count)),g.attributes.uv&&(k.attributes.TEXCOORD_0=T(g.attributes.uv.array,"VEC2",34962,5126,g.attributes.uv.count)),g.index){let B=g.index.array instanceof Uint32Array;k.indices=T(g.index.array,"SCALAR",34963,B?5125:5123,g.index.count)}y.material&&(k.material=E(y.material));let M=y.userData?.variants;if(M&&typeof M=="object"){let B=new Map;for(let z of Object.keys(M)){if(!z||z==="__proto__"||z==="constructor"||z==="prototype")continue;let C=M[z];if(!C||typeof C!="object")continue;let V=v.indexOf(z);if(V===-1&&v.length<256&&(V=v.length,v.push(z)),V===-1)continue;let $=E(C),W=B.get($);W||(W=[],B.set($,W)),W.push(V)}if(B.size>0){let z=[];for(let[C,V]of B.entries())z.push({material:C,variants:V});k.extensions={...k.extensions||{},KHR_materials_variants:{mappings:z}},o.add("KHR_materials_variants")}}let H=y;if(H.isInstancedMesh&&typeof H.count=="number"&&H.count>0&&H.instanceMatrix?.array){let B=Math.min(1e4,Math.floor(H.count)),z=H.instanceMatrix.array,C=new Float32Array(B*3),V=new Float32Array(B*4),$=new Float32Array(B*3);for(let q=0;q<B;q++){let{t:te,r:se,s:X}=dt(z,q*16);C[q*3]=te[0],C[q*3+1]=te[1],C[q*3+2]=te[2],V[q*4]=se[0],V[q*4+1]=se[1],V[q*4+2]=se[2],V[q*4+3]=se[3],$[q*3]=X[0],$[q*3+1]=X[1],$[q*3+2]=X[2]}let W={TRANSLATION:T(C,"VEC3",0,5126,B),ROTATION:T(V,"VEC4",0,5126,B),SCALE:T($,"VEC3",0,5126,B)};if(H.instanceColor?.array&&H.instanceColor.array.length>=B*3){let q=new Float32Array(H.instanceColor.array.subarray(0,B*3));W._COLOR_0=T(q,"VEC3",0,5126,B)}D.extensions={...D.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},o.add("EXT_mesh_gpu_instancing")}let O=a.length;a.push({primitives:[k],name:y.name,...D.extras?{extras:D.extras}:{}}),D.mesh=O}}let p=d.length;if(d.push(D),c.push(y),y.children.length>0){D.children=[];for(let g of y.children)D.children.push(F(g))}return p}for(let y of n.children)I.push(F(y));let h=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),w=[];if(typeof h=="function"&&c.length>0){let y=e?.duration??4,D=e?.fps??15,l=Math.max(2,Math.round(y*D)+1),m=new Float32Array(l),R=c.map(M=>({px:M.position.x,py:M.position.y,pz:M.position.z,qx:M.quaternion.x,qy:M.quaternion.y,qz:M.quaternion.z,qw:M.quaternion.w,sx:M.scale.x,sy:M.scale.y,sz:M.scale.z})),p=c.map(()=>new Float32Array(l*3)),g=c.map(()=>new Float32Array(l*4)),_=c.map(()=>new Float32Array(l*3));for(let M=0;M<l;M++){let H=M/(l-1)*y;m[M]=H;try{h(H)}catch{}for(let O=0;O<c.length;O++){let B=c[O];p[O][M*3]=B.position.x,p[O][M*3+1]=B.position.y,p[O][M*3+2]=B.position.z,g[O][M*4]=B.quaternion.x,g[O][M*4+1]=B.quaternion.y,g[O][M*4+2]=B.quaternion.z,g[O][M*4+3]=B.quaternion.w,_[O][M*3]=B.scale.x,_[O][M*3+1]=B.scale.y,_[O][M*3+2]=B.scale.z}}for(let M=0;M<c.length;M++){let H=c[M],O=R[M];H.position.set(O.px,O.py,O.pz),H.quaternion.set(O.qx,O.qy,O.qz,O.qw),H.scale.set(O.sx,O.sy,O.sz)}n.updateMatrixWorld(!0);let P=null,G=()=>(P===null&&(P=T(m,"SCALAR",0,5126,l,[0],[y])),P),N=[],k=[];for(let M=0;M<c.length;M++){let H=R[M],O=!1,B=!1,z=!1;for(let C=0;C<l;C++)(Math.abs(p[M][C*3]-H.px)>1e-4||Math.abs(p[M][C*3+1]-H.py)>1e-4||Math.abs(p[M][C*3+2]-H.pz)>1e-4)&&(O=!0),(Math.abs(g[M][C*4]-H.qx)>1e-4||Math.abs(g[M][C*4+1]-H.qy)>1e-4||Math.abs(g[M][C*4+2]-H.qz)>1e-4||Math.abs(g[M][C*4+3]-H.qw)>1e-4)&&(B=!0),(Math.abs(_[M][C*3]-H.sx)>1e-4||Math.abs(_[M][C*3+1]-H.sy)>1e-4||Math.abs(_[M][C*3+2]-H.sz)>1e-4)&&(z=!0);if(O){let C=T(p[M],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"translation"}})}if(B){let C=T(g[M],"VEC4",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"rotation"}})}if(z){let C=T(_[M],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"scale"}})}}k.length>0&&w.push({name:"ProceduralLoop",samplers:N,channels:k})}let f=_e(d,a,n.userData),S={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:I}],scene:0,nodes:d,meshes:a,materials:u,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...w.length>0?{animations:w}:{},...f||o.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...o]}:{},...f||v.length>0?{extensions:{...f?{KHR_interactivity:f}:{},...v.length>0?{KHR_materials_variants:{variants:v.map(y=>({name:y}))}}:{}}}:{}},U=new Uint8Array(r),A=0;for(let y of t)U.set(y,A),A+=y.byteLength;return{gltf:S,bin:U.buffer,lights:L,environmentIntensity:n.environmentIntensity}}function we(n){return new TextEncoder().encode(n)}function Gt(n,e){let{gltf:t,bin:r}=bt(n,e),i=JSON.stringify(t),s=we(i),a=(4-s.byteLength%4)%4,d=s.byteLength+a,o=20+d+8+r.byteLength,c=new Uint8Array(o),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,o,!0),u.setUint32(12,d,!0),u.setUint32(16,1313821514,!0),c.set(s,20);for(let v=0;v<a;v++)c[20+s.byteLength+v]=32;let b=20+d;return u.setUint32(b,r.byteLength,!0),u.setUint32(b+4,5130562,!0),c.set(new Uint8Array(r),b+8),c}function gt(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 a=s.count,d=new Float32Array(a*3),o=r.matrixWorld.elements;for(let A=0;A<a;A++){let y=s.getX(A),D=s.getY(A),l=s.getZ(A);d[A*3]=o[0]*y+o[4]*D+o[8]*l+o[12],d[A*3+1]=o[1]*y+o[5]*D+o[9]*l+o[13],d[A*3+2]=o[2]*y+o[6]*D+o[10]*l+o[14]}let c;if(i.attributes.normal){let A=i.attributes.normal;c=new Float32Array(a*3);let y=new Float32Array(9);ae(y,o);for(let D=0;D<a;D++){let l=A.getX(D),m=A.getY(D),R=A.getZ(D),p=y[0]*l+y[3]*m+y[6]*R,g=y[1]*l+y[4]*m+y[7]*R,_=y[2]*l+y[5]*m+y[8]*R,P=Math.hypot(p,g,_)||1;c[D*3]=p/P,c[D*3+1]=g/P,c[D*3+2]=_/P}}let u;if(i.attributes.uv){let A=i.attributes.uv;u=new Float32Array(a*2);for(let y=0;y<a;y++)u[y*2]=A.getX(y),u[y*2+1]=A.getY(y)}let b;if(i.index)b=i.index.array;else{b=a>65535?new Uint32Array(a):new Uint16Array(a);for(let A=0;A<a;A++)b[A]=A}let v="DefaultMaterial",L=[.8,.8,.8],E=.5,x=.1,T=0,I=0,F=1.5,h=1,w=[0,0,0];if(r.material){let A=r.material;v=A.name||`Material_${t.length}`,A.color&&(L=[A.color.r,A.color.g,A.color.b]),typeof A.roughness=="number"&&(E=A.roughness),typeof A.metalness=="number"&&(x=A.metalness),typeof A.clearcoat=="number"&&(T=A.clearcoat),typeof A.clearcoatRoughness=="number"&&(I=A.clearcoatRoughness),typeof A.ior=="number"&&(F=A.ior);let y=typeof A.opacity=="number"?A.opacity:1,D=typeof A.transmission=="number"?A.transmission:0;if(h=y*(1-D),A.emissive&&(A.emissive.r>0||A.emissive.g>0||A.emissive.b>0)){let l=A.emissiveIntensity??1;w=[A.emissive.r*l,A.emissive.g*l,A.emissive.b*l]}}let f,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);if(typeof S=="function"){let A=e?.duration??4,y=e?.fps??4,D=Math.max(2,Math.round(A*y)+1),l=[],m=[],R=[],p=[],g=[r.position.x,r.position.y,r.position.z],_=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],P=[r.scale.x,r.scale.y,r.scale.z],G=!1;for(let N=0;N<D;N++){let k=N/(D-1)*A;l.push(k);try{S(k)}catch{}m.push([r.position.x,r.position.y,r.position.z]),R.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),p.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-g[0])>1e-4||Math.abs(r.position.y-g[1])>1e-4||Math.abs(r.position.z-g[2])>1e-4||Math.abs(r.quaternion.x-_[0])>1e-4||Math.abs(r.quaternion.y-_[1])>1e-4||Math.abs(r.quaternion.z-_[2])>1e-4||Math.abs(r.quaternion.w-_[3])>1e-4||Math.abs(r.scale.x-P[0])>1e-4)&&(G=!0)}r.position.set(g[0],g[1],g[2]),r.quaternion.set(_[0],_[1],_[2],_[3]),r.scale.set(P[0],P[1],P[2]),G&&(f={times:l,translations:m,rotations:R,scales:p})}let U=r;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let A=Math.min(1e3,Math.floor(U.count)),y=U.instanceMatrix.array,D=U.instanceColor?.array,l=r.name||`Mesh_${t.length}`,m=new Float32Array(16),R=new Float32Array(9);for(let p=0;p<A;p++){let g=y.subarray(p*16,(p+1)*16);ee(m,o,g);let _=new Float32Array(a*3);for(let k=0;k<a;k++){let M=s.getX(k),H=s.getY(k),O=s.getZ(k);_[k*3]=m[0]*M+m[4]*H+m[8]*O+m[12],_[k*3+1]=m[1]*M+m[5]*H+m[9]*O+m[13],_[k*3+2]=m[2]*M+m[6]*H+m[10]*O+m[14]}let P;if(i.attributes.normal){let k=i.attributes.normal;P=new Float32Array(a*3),ae(R,m);for(let M=0;M<a;M++){let H=k.getX(M),O=k.getY(M),B=k.getZ(M),z=R[0]*H+R[3]*O+R[6]*B,C=R[1]*H+R[4]*O+R[7]*B,V=R[2]*H+R[5]*O+R[8]*B,$=Math.hypot(z,C,V)||1;P[M*3]=z/$,P[M*3+1]=C/$,P[M*3+2]=V/$}}let G=L,N=v;D&&D.length>=(p+1)*3&&(G=[L[0]*D[p*3],L[1]*D[p*3+1],L[2]*D[p*3+2]],N=`${v}_inst_${p}`),t.push({name:`${l}_${p}`,positions:_,indices:b,normals:P,uvs:u,materialName:N,color:G,roughness:E,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:h,emissiveColor:w,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:d,indices:b,normals:c,uvs:u,materialName:v,color:L,roughness:E,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:h,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:f})}}),t}function Qe(n){let e=[],t=n.gltf,r=ue().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),a=t.accessors||[],d=t.bufferViews||[],o=t.materials||[],c=t.meshes||[],u=t.nodes||[];function b(E){let x=a[E];if(!x)throw new Error(`Accessor ${E} not found`);let T=d[x.bufferView||0],I=(T.byteOffset||0)+(x.byteOffset||0),F=T.byteLength||0,h=s.slice(I,I+F);return{acc:x,buffer:h}}let v=new Map;if(u.length>0){let E=Me(t);for(let x=0;x<E.length;x++)v.set(x,E[x])}function L(E,x,T,I){let F=c[E];if(!F)return;let h=new Float32Array(9);ae(h,x);for(let w=0;w<(F.primitives||[]).length;w++){let f=F.primitives[w],S=f.attributes?.POSITION;if(S===void 0)continue;let{acc:U,buffer:A}=b(S),y=new Float32Array(A,0,U.count*3),D=new Float32Array(y.length);for(let C=0;C<U.count;C++){let V=y[C*3],$=y[C*3+1],W=y[C*3+2];D[C*3]=x[0]*V+x[4]*$+x[8]*W+x[12],D[C*3+1]=x[1]*V+x[5]*$+x[9]*W+x[13],D[C*3+2]=x[2]*V+x[6]*$+x[10]*W+x[14]}let l,m=f.attributes?.NORMAL;if(m!==void 0){let{acc:C,buffer:V}=b(m),$=new Float32Array(V,0,C.count*3);l=new Float32Array($.length);for(let W=0;W<C.count;W++){let q=$[W*3],te=$[W*3+1],se=$[W*3+2],X=h[0]*q+h[3]*te+h[6]*se,Z=h[1]*q+h[4]*te+h[7]*se,re=h[2]*q+h[5]*te+h[8]*se,oe=Math.hypot(X,Z,re)||1;l[W*3]=X/oe,l[W*3+1]=Z/oe,l[W*3+2]=re/oe}}let R,p=f.attributes?.TEXCOORD_0;if(p!==void 0){let{acc:C,buffer:V}=b(p);R=new Float32Array(V,0,C.count*2)}let g;if(f.indices!==void 0){let{acc:C,buffer:V}=b(f.indices);C.componentType===5125?g=new Uint32Array(V,0,C.count):g=new Uint16Array(V,0,C.count);let $=U.count;for(let W of g)if(W>=$)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${$}).`)}else{let C=U.count;g=C>65535?new Uint32Array(C):new Uint16Array(C);for(let V=0;V<C;V++)g[V]=V}let _="DefaultMaterial",P=[.8,.8,.8],G=.5,N=.1,k=0,M=0,H=1.5,O=1,B=[0,0,0];if(f.material!==void 0&&o[f.material]){let C=o[f.material];_=C.name||`Material_${f.material}`;let V=C.pbrMetallicRoughness||{},$=1;Array.isArray(V.baseColorFactor)&&(P=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&($=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(G=V.roughnessFactor),typeof V.metallicFactor=="number"&&(N=V.metallicFactor),Array.isArray(C.emissiveFactor)&&C.emissiveFactor.length>=3&&(B=[C.emissiveFactor[0],C.emissiveFactor[1],C.emissiveFactor[2]]);let W=C.extensions||{};W.KHR_materials_clearcoat&&(k=W.KHR_materials_clearcoat.clearcoatFactor??0,M=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(H=W.KHR_materials_ior.ior);let q=W.KHR_materials_transmission?.transmissionFactor??0;O=$*(1-q)}let z=(F.primitives||[]).length>1?`${T}_p${w}`:T;e.push({name:z,positions:D,indices:g,normals:l,uvs:R,materialName:_,color:P,roughness:G,metallic:N,clearcoat:k,clearcoatRoughness:M,ior:H,opacity:O,emissiveColor:B,xrTraits:I?.xr||F.extras?.xr})}}if(u.length>0)for(let E=0;E<u.length;E++){let x=u[E];if(x.mesh!==void 0&&x.mesh<c.length){let T=v.get(E)||J(),I=x.name||c[x.mesh].name||`Node_${E}`,F=x.extensions?.EXT_mesh_gpu_instancing?.attributes;if(F&&typeof F=="object"){let h=F.TRANSLATION,w=F.ROTATION,f=F.SCALE,S=h!==void 0?(()=>{let{acc:D,buffer:l}=b(h);return new Float32Array(l,0,D.count*3)})():null,U=w!==void 0?(()=>{let{acc:D,buffer:l}=b(w);return new Float32Array(l,0,D.count*4)})():null,A=f!==void 0?(()=>{let{acc:D,buffer:l}=b(f);return new Float32Array(l,0,D.count*3)})():null,y=Math.min(1e3,S?S.length/3:U?U.length/4:A?A.length/3:0);if(y>0){let D=new Float32Array(16),l=new Float32Array(16);for(let m=0;m<y;m++){let R=S?[S[m*3],S[m*3+1],S[m*3+2]]:[0,0,0],p=U?[U[m*4],U[m*4+1],U[m*4+2],U[m*4+3]]:[0,0,0,1],g=A?[A[m*3],A[m*3+1],A[m*3+2]]:[1,1,1];he(D,p,R,g),ee(l,T,D),L(x.mesh,l,`${I}_${m}`,x.extras)}continue}}L(x.mesh,T,I,x.extras)}}else{let E=J();for(let x=0;x<c.length;x++){let T=c[x].name||`Mesh_${x}`;L(x,E,T,c[x].extras)}}return e}function Fe(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 je(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function K(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 Je(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*3])}, ${K(n[r*3+1])}, ${K(n[r*3+2])})`;return t.join(", ")}function yt(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*2])}, ${K(1-n[r*2+1])})`;return t.join(", ")}function vt(n){return Array.from(n).join(", ")}function Se(n){let e=new Map;for(let o of n){let c=Fe(o.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:o.color||[.8,.8,.8],roughness:o.roughness??.5,metallic:o.metallic??0,clearcoat:o.clearcoat??0,clearcoatRoughness:o.clearcoatRoughness??0,ior:o.ior??1.5,opacity:o.opacity??1,emissiveColor:o.emissiveColor||[0,0,0]})}let t=0,r=null;for(let o of n){if(o.timeSamples&&o.timeSamples.times.length>0){let c=o.timeSamples.times[o.timeSamples.times.length-1];c>t&&(t=c)}o.xrTraits?.anchor&&!r&&(r=o.xrTraits.anchor==="vertical"||o.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
251
253
  endTimeCode = ${K(t)}
252
254
  timeCodesPerSecond = 1.0
253
255
  `);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
@@ -265,11 +267,11 @@ kind = "component"
265
267
  {
266
268
  ${s}def Scope "Materials"
267
269
  {
268
- `;for(let[o,c]of e.entries()){let[u,b,v]=c.color,[L,M,R]=c.emissiveColor,T="";c.clearcoat>0&&(T+=`float inputs:clearcoat = ${K(c.clearcoat)}
270
+ `;for(let[o,c]of e.entries()){let[u,b,v]=c.color,[L,E,x]=c.emissiveColor,T="";c.clearcoat>0&&(T+=`float inputs:clearcoat = ${K(c.clearcoat)}
269
271
  `,T+=`float inputs:clearcoatRoughness = ${K(c.clearcoatRoughness)}
270
272
  `),c.ior!==1.5&&(T+=`float inputs:ior = ${K(c.ior)}
271
273
  `),c.opacity<1&&(T+=`float inputs:opacity = ${K(c.opacity)}
272
- `),(L>0||M>0||R>0)&&(T+=`color3f inputs:emissiveColor = (${K(L)}, ${K(M)}, ${K(R)})
274
+ `),(L>0||E>0||x>0)&&(T+=`color3f inputs:emissiveColor = (${K(L)}, ${K(E)}, ${K(x)})
273
275
  `),a+=`def Material "${o}"
274
276
  {
275
277
  def Shader "PBRShader"
@@ -285,7 +287,7 @@ token outputs:surface.connect = </Root/Materials/${o}/PBRShader.outputs:surface>
285
287
  `}a+=`}
286
288
  def Scope "Meshes"
287
289
  {
288
- `;let d=new Set;for(let o=0;o<n.length;o++){let c=n[o],u=c.positions.length/3,b=1/0,v=1/0,L=1/0,M=-1/0,R=-1/0,T=-1/0;for(let U=0;U<u;U++){let A=c.positions[U*3],g=c.positions[U*3+1],D=c.positions[U*3+2];A<b&&(b=A),A>M&&(M=A),g<v&&(v=g),g>R&&(R=g),D<L&&(L=D),D>T&&(T=D)}isFinite(b)||(b=v=L=-1,M=R=T=1);let I=Math.floor(c.indices.length/3),F=Fe(c.materialName,"DefaultMaterial"),m=Fe(c.name,`Mesh_${o}`);d.has(m)&&(m=`${m}_${o}`),d.add(m);let E=I>0?I===1?"3":"3, ".repeat(I-1)+"3":"",f=c.xrTraits,S="";if(f){let U=[];f.physics&&f.physics!=="none"&&U.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let A=ue().xrTraitSerializer?.usdLines(f,Je)??[];if(!A.length)for(let g of["grab","billboard","follow","anchor","physics"]){let D=g==="follow"&&typeof f.follow=="object"?f.follow.mode??"head":f[g];D!==void 0&&A.push(`string ${g} = "${Je(D)}"`)}A.length>0&&U.push(`customData = {
290
+ `;let d=new Set;for(let o=0;o<n.length;o++){let c=n[o],u=c.positions.length/3,b=1/0,v=1/0,L=1/0,E=-1/0,x=-1/0,T=-1/0;for(let U=0;U<u;U++){let A=c.positions[U*3],y=c.positions[U*3+1],D=c.positions[U*3+2];A<b&&(b=A),A>E&&(E=A),y<v&&(v=y),y>x&&(x=y),D<L&&(L=D),D>T&&(T=D)}isFinite(b)||(b=v=L=-1,E=x=T=1);let I=Math.floor(c.indices.length/3),F=Fe(c.materialName,"DefaultMaterial"),h=Fe(c.name,`Mesh_${o}`);d.has(h)&&(h=`${h}_${o}`),d.add(h);let w=I>0?I===1?"3":"3, ".repeat(I-1)+"3":"",f=c.xrTraits,S="";if(f){let U=[];f.physics&&f.physics!=="none"&&U.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let A=ue().xrTraitSerializer?.usdLines(f,je)??[];if(!A.length)for(let y of["grab","billboard","follow","anchor","physics"]){let D=y==="follow"&&typeof f.follow=="object"?f.follow.mode??"head":f[y];D!==void 0&&A.push(`string ${y} = "${je(D)}"`)}A.length>0&&U.push(`customData = {
289
291
  dictionary xr = {
290
292
  ${A.join(`
291
293
  `)}
@@ -293,27 +295,27 @@ def Scope "Meshes"
293
295
  }`),U.length>0&&(S=` (
294
296
  ${U.join(`
295
297
  `)}
296
- )`)}if(a+=`def Mesh "${m}"${S}
298
+ )`)}if(a+=`def Mesh "${h}"${S}
297
299
  {
298
300
  `,f?.physics&&f.physics!=="none"){let U=f.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
299
301
  bool physics:kinematicEnabled = ${U}
300
302
  bool physics:collisionEnabled = true
301
- `}if(c.timeSamples&&c.timeSamples.times.length>0){let U=c.timeSamples,A=U.times.map((l,h)=>{let w=U.translations?.[h]||[0,0,0];return`${K(l)}: (${K(w[0])}, ${K(w[1])}, ${K(w[2])})`}).join(", "),g=U.times.map((l,h)=>{let w=U.rotations?.[h]||[0,0,0,1];return`${K(l)}: (${K(w[3])}, ${K(w[0])}, ${K(w[1])}, ${K(w[2])})`}).join(", "),D=U.times.map((l,h)=>{let w=U.scales?.[h]||[1,1,1];return`${K(l)}: (${K(w[0])}, ${K(w[1])}, ${K(w[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${A} }
302
- quatf xformOp:orient.timeSamples = { ${g} }
303
+ `}if(c.timeSamples&&c.timeSamples.times.length>0){let U=c.timeSamples,A=U.times.map((l,m)=>{let R=U.translations?.[m]||[0,0,0];return`${K(l)}: (${K(R[0])}, ${K(R[1])}, ${K(R[2])})`}).join(", "),y=U.times.map((l,m)=>{let R=U.rotations?.[m]||[0,0,0,1];return`${K(l)}: (${K(R[3])}, ${K(R[0])}, ${K(R[1])}, ${K(R[2])})`}).join(", "),D=U.times.map((l,m)=>{let R=U.scales?.[m]||[1,1,1];return`${K(l)}: (${K(R[0])}, ${K(R[1])}, ${K(R[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${A} }
304
+ quatf xformOp:orient.timeSamples = { ${y} }
303
305
  double3 xformOp:scale.timeSamples = { ${D} }
304
306
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
305
- `}a+=`float3[] extent = [(${K(b)}, ${K(v)}, ${K(L)}), (${K(M)}, ${K(R)}, ${K(T)})]
306
- int[] faceVertexCounts = [${E}]
307
- int[] faceVertexIndices = [${xt(c.indices)}]
308
- point3f[] points = [${Qe(c.positions)}]
309
- `,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${Qe(c.normals)}] (
307
+ `}a+=`float3[] extent = [(${K(b)}, ${K(v)}, ${K(L)}), (${K(E)}, ${K(x)}, ${K(T)})]
308
+ int[] faceVertexCounts = [${w}]
309
+ int[] faceVertexIndices = [${vt(c.indices)}]
310
+ point3f[] points = [${Je(c.positions)}]
311
+ `,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${Je(c.normals)}] (
310
312
  interpolation = "vertex"
311
313
  )
312
- `),c.uvs&&c.uvs.length===u*2&&(a+=`texCoord2f[] primvars:st = [${vt(c.uvs,u)}] (
314
+ `),c.uvs&&c.uvs.length===u*2&&(a+=`texCoord2f[] primvars:st = [${yt(c.uvs,u)}] (
313
315
  interpolation = "vertex"
314
316
  )
315
317
  `),a+=`rel material:binding = </Root/Materials/${F}>
316
318
  }
317
319
  `}return a+=`}
318
320
  }
319
- `,a}function Mt(n,e){if(n&&typeof n.traverse=="function"){let i=yt(n,e);return Se(i)}let t=de(n),r=et(t);return Se(r)}var Ae=null;function Tt(n){if(!Ae){Ae=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;Ae[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=Ae[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function tt(n){let e=[],t=0,r=[];for(let u of n){let b=Re(u.filename),v=Tt(u.data),L=u.data.length,M=30+b.length,R=t+M,T=0,I=R%64;I!==0&&(T=64-I);let F=new Uint8Array(M+T),m=new DataView(F.buffer);m.setUint32(0,67324752,!0),m.setUint16(4,20,!0),m.setUint16(6,0,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint32(14,v,!0),m.setUint32(18,L,!0),m.setUint32(22,L,!0),m.setUint16(26,b.length,!0),m.setUint16(28,T,!0),F.set(b,30),T>0&&F.fill(0,30+b.length),e.push({offset:t,size:L,crc:v,filenameBytes:b,entry:u}),r.push(F),r.push(u.data),t+=F.length+u.data.length}let i=t;for(let u of e){let b=new Uint8Array(46+u.filenameBytes.length),v=new DataView(b.buffer);v.setUint32(0,33639248,!0),v.setUint16(4,20,!0),v.setUint16(6,20,!0),v.setUint16(8,0,!0),v.setUint16(10,0,!0),v.setUint16(12,0,!0),v.setUint16(14,0,!0),v.setUint32(16,u.crc,!0),v.setUint32(20,u.size,!0),v.setUint32(24,u.size,!0),v.setUint16(28,u.filenameBytes.length,!0),v.setUint16(30,0,!0),v.setUint16(32,0,!0),v.setUint16(34,0,!0),v.setUint16(36,0,!0),v.setUint32(38,0,!0),v.setUint32(42,u.offset,!0),b.set(u.filenameBytes,46),r.push(b),t+=b.length}let s=t-i,a=new Uint8Array(22),d=new DataView(a.buffer);d.setUint32(0,101010256,!0),d.setUint16(4,0,!0),d.setUint16(6,0,!0),d.setUint16(8,e.length,!0),d.setUint16(10,e.length,!0),d.setUint32(12,s,!0),d.setUint32(16,i,!0),d.setUint16(20,0,!0),r.push(a),t+=22;let o=new Uint8Array(t),c=0;for(let u of r)o.set(u,c),c+=u.length;return o}function At(n){let e=Mt(n),t=Re(e);return tt([{filename:"model.usda",data:t}])}function Rt(n){let e=de(n),t=et(e),r=Se(t),i=Re(r);return tt([{filename:"model.usda",data:i}])}function wt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?At(n):Rt(n)}function Gt(n){let e=wt(n);return new Blob([e],{type:"model/vnd.usdz+zip"})}export{tt as buildUSDZZip,Tt as calculateCRC32,_e as compileInteractivityGraph,Gt as createUSDZBlob,Re as encodeUtf8,et as extractMeshesFromGLB,yt as extractMeshesFromScene,Mt as generateUSDA,Se as generateUSDAFromMeshes,wt as generateUSDZ,Rt as glbToUSDZ,Fe as sanitizeUsdIdentifier,Je as sanitizeUsdStringLiteral,gt as sceneToCanvas3D,kt as sceneToGLB,At as sceneToUSDZ};
321
+ `,a}function xt(n,e){if(n&&typeof n.traverse=="function"){let i=gt(n,e);return Se(i)}let t=de(n),r=Qe(t);return Se(r)}var Re=null;function Mt(n){if(!Re){Re=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;Re[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=Re[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function et(n){let e=[],t=0,r=[];for(let u of n){let b=we(u.filename),v=Mt(u.data),L=u.data.length,E=30+b.length,x=t+E,T=0,I=x%64;I!==0&&(T=64-I);let F=new Uint8Array(E+T),h=new DataView(F.buffer);h.setUint32(0,67324752,!0),h.setUint16(4,20,!0),h.setUint16(6,0,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint32(14,v,!0),h.setUint32(18,L,!0),h.setUint32(22,L,!0),h.setUint16(26,b.length,!0),h.setUint16(28,T,!0),F.set(b,30),T>0&&F.fill(0,30+b.length),e.push({offset:t,size:L,crc:v,filenameBytes:b,entry:u}),r.push(F),r.push(u.data),t+=F.length+u.data.length}let i=t;for(let u of e){let b=new Uint8Array(46+u.filenameBytes.length),v=new DataView(b.buffer);v.setUint32(0,33639248,!0),v.setUint16(4,20,!0),v.setUint16(6,20,!0),v.setUint16(8,0,!0),v.setUint16(10,0,!0),v.setUint16(12,0,!0),v.setUint16(14,0,!0),v.setUint32(16,u.crc,!0),v.setUint32(20,u.size,!0),v.setUint32(24,u.size,!0),v.setUint16(28,u.filenameBytes.length,!0),v.setUint16(30,0,!0),v.setUint16(32,0,!0),v.setUint16(34,0,!0),v.setUint16(36,0,!0),v.setUint32(38,0,!0),v.setUint32(42,u.offset,!0),b.set(u.filenameBytes,46),r.push(b),t+=b.length}let s=t-i,a=new Uint8Array(22),d=new DataView(a.buffer);d.setUint32(0,101010256,!0),d.setUint16(4,0,!0),d.setUint16(6,0,!0),d.setUint16(8,e.length,!0),d.setUint16(10,e.length,!0),d.setUint32(12,s,!0),d.setUint32(16,i,!0),d.setUint16(20,0,!0),r.push(a),t+=22;let o=new Uint8Array(t),c=0;for(let u of r)o.set(u,c),c+=u.length;return o}function Tt(n){let e=xt(n),t=we(e);return et([{filename:"model.usda",data:t}])}function At(n){let e=de(n),t=Qe(e),r=Se(t),i=we(r);return et([{filename:"model.usda",data:i}])}function Rt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Tt(n):At(n)}function Vt(n){let e=Rt(n);return new Blob([e],{type:"model/vnd.usdz+zip"})}export{et as buildUSDZZip,Mt as calculateCRC32,_e as compileInteractivityGraph,Vt as createUSDZBlob,we as encodeUtf8,Qe as extractMeshesFromGLB,gt as extractMeshesFromScene,xt as generateUSDA,Se as generateUSDAFromMeshes,Rt as generateUSDZ,At as glbToUSDZ,Fe as sanitizeUsdIdentifier,je as sanitizeUsdStringLiteral,bt as sceneToCanvas3D,Gt as sceneToGLB,Tt as sceneToUSDZ};