three-live 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +115 -6
- package/dist/three-author-engine.js +42 -51
- package/dist/three-author.cjs +38 -47
- package/dist/three-author.d.ts +115 -6
- package/dist/three-author.js +38 -47
- package/dist/three-convert.cjs +41 -50
- package/dist/three-convert.d.ts +115 -6
- package/dist/three-convert.js +41 -50
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +115 -6
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +6 -6
- package/dist/three-live-element.cjs +13 -22
- package/dist/three-live-element.d.ts +115 -6
- package/dist/three-live-element.js +13 -22
- package/dist/three-live-extras.cjs +13 -13
- package/dist/three-live-extras.d.ts +115 -6
- package/dist/three-live-extras.js +13 -13
- package/dist/three-live-extras.min.js +13 -13
- package/dist/three-live-full.cjs +68 -77
- package/dist/three-live-full.js +68 -77
- package/dist/three-live-full.min.js +68 -77
- package/dist/three-live-viewer.cjs +13 -22
- package/dist/three-live-viewer.d.ts +115 -6
- package/dist/three-live-viewer.js +13 -22
- package/dist/three-live-viewer.min.js +13 -22
- package/dist/three-live.cjs +47 -56
- package/dist/three-live.js +47 -56
- package/dist/three-live.min.js +47 -56
- package/dist/three-view.cjs +13 -22
- package/dist/three-view.d.ts +115 -6
- package/dist/three-view.js +13 -22
- package/dist/three-xr.cjs +45 -54
- package/dist/three-xr.d.ts +115 -6
- package/dist/three-xr.js +45 -54
- package/package.json +1 -1
package/dist/three-convert.cjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var Me=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var at=Object.prototype.hasOwnProperty;var ot=(n,e)=>{for(var t in e)Me(n,t,{get:e[t],enumerable:!0})},ut=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of st(e))!at.call(n,r)&&r!==t&&Me(n,r,{get:()=>e[r],enumerable:!(i=rt(e,r))||i.enumerable});return n};var ct=n=>ut(Me({},"__esModule",{value:!0}),n);var Rt={};ot(Rt,{buildUSDZZip:()=>Le,calculateCRC32:()=>je,compileInteractivityGraph:()=>Re,createUSDZBlob:()=>Mt,encodeUtf8:()=>fe,extractMeshesFromGLB:()=>Fe,extractMeshesFromScene:()=>Ye,generateUSDA:()=>Ze,generateUSDAFromMeshes:()=>Te,generateUSDZ:()=>Tt,glbToUSDZ:()=>Ie,sanitizeUsdIdentifier:()=>xe,sanitizeUsdStringLiteral:()=>Pe,sceneToCanvas3D:()=>qe,sceneToGLB:()=>yt,sceneToUSDZ:()=>Je});module.exports=ct(Rt);function Re(n,e,t){let i=[],r=new Map,s=[],d=[],y=[],u=new Map,o=f=>{let M=r.get(f);return M===void 0&&(M=i.length,i.push({op:f}),r.set(f,M)),M},a=f=>{let M=u.get(f);return M===void 0&&(M=y.length,y.push({id:f}),u.set(f,M)),M},l=(f,M={})=>s.push({declaration:o(f),...M})-1,g=(f,M,b)=>d.push({id:f,type:M,value:b})-1,T=f=>({node:f,socket:"value"}),m=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(m&&typeof m=="object"){let f=Array.isArray(m.graphs)?m.graphs[m.graph??0]:m;if(f&&Array.isArray(f.nodes)){let M=Array.isArray(f.declarations)?f.declarations:[];for(let b of M)b?.op&&o(b.op);Array.isArray(f.variables)&&d.push(...f.variables);for(let b of f.events||[])b?.id&&a(b.id);for(let b of f.nodes){if(!b||typeof b!="object")continue;let I=b.op||(typeof b.declaration=="number"?M[b.declaration]?.op:"");s.push(I?{...b,declaration:o(I)}:{...b})}}}let E=(f,M,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,M)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,M)}/${b}`:b==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${b}`,A=new Map;n.forEach((f,M)=>{typeof f?.name=="string"&&!A.has(f.name)&&A.set(f.name,M)});let F=(f,M)=>typeof f.target=="string"&&A.has(f.target)?A.get(f.target):typeof f.targetNode=="number"?f.targetNode:M,P=f=>{let M=n[f];return(typeof M?.mesh=="number"?e[M.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let M=n[f],b=M?.extras?.interactivity;if(!b||typeof b!="object")continue;let I=(typeof M.mesh=="number"?e[M.mesh]?.primitives?.[0]?.material:0)??0,c=h=>{let w=Array.isArray(h)?h:[h],L=[];for(let D=0;D<w.length;D++){let p=w[D];if(!p||typeof p!="object")continue;let N=p.action||"interpolate",H=typeof p.duration=="number"?p.duration:.35;if(N==="toggleTransform"){let O=p.property==="rotation"||p.property==="scale"?p.property:"translation",V=O==="rotation"?M.rotation||[0,0,0,1]:O==="scale"?M.scale||[1,1,1]:M.translation||[0,0,0],S=`/nodes/${f}/${O}`,C=g(`__toggle_${f}_${D}`,"bool",!1),R=l("variable/get",{configuration:{variable:C}}),B=l("math/not",{values:{a:T(R)}}),U=l("variable/set",{configuration:{variable:C},values:{value:T(B)}}),k=l("pointer/interpolate",{configuration:{pointer:S},values:{value:{value:Array.isArray(p.to)?p.to:V},duration:{value:H}}}),_=l("pointer/interpolate",{configuration:{pointer:S},values:{value:{value:Array.isArray(p.from)?p.from:V},duration:{value:H}}});s[U].flows={out:{node:l("flow/branch",{values:{condition:T(R)},flows:{true:{node:k},false:{node:_}}})}},L.push(U)}else if(N==="interpolate"){let O=p.to??p.value;if(O===void 0)continue;let V={value:{value:O},duration:{value:H}};p.from!==void 0&&(V.from={value:p.from}),L.push(l("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:E(F(p,f),P(F(p,f)),p.property)},values:V}))}else if(N==="setProperty"){if(p.value===void 0)continue;L.push(l("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:E(F(p,f),P(F(p,f)),p.property)},values:{value:{value:p.value}}}))}else if(N==="toggleVisibility"){let O=F(p,f),V=g(`__vis_${O}_${D}`,"bool",!0),S=l("variable/get",{configuration:{variable:V}}),C=l("math/not",{values:{a:T(S)}}),R=l("variable/set",{configuration:{variable:V},values:{value:T(C)}});s[R].flows={out:{node:l("pointer/set",{configuration:{pointer:`/nodes/${O}/extensions/KHR_node_visibility/visible`},values:{value:T(S)}})}},L.push(R)}else if(N==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let O=typeof p.duration=="number"?p.duration:.25,V=`/materials/${Math.max(0,I)}/pbrMetallicRoughness/baseColorFactor`,S=g(`__color_idx_${f}_${D}`,"int",0),C=l("variable/get",{configuration:{variable:S}}),R=l("math/add",{values:{a:T(C),b:{value:1}}}),B=l("math/rem",{values:{a:T(R),b:{value:p.colors.length}}}),U=l("variable/set",{configuration:{variable:S},values:{value:T(B)}}),k={};for(let _=0;_<p.colors.length;_++){let G=p.colors[_],W=Array.isArray(G)&&G.length>=3?[G[0],G[1],G[2],G[3]??1]:[1,1,1,1];k[String(_)]={node:O>0?l("pointer/interpolate",{configuration:{pointer:V},values:{value:{value:W},duration:{value:O}}}):l("pointer/set",{configuration:{pointer:V},values:{value:{value:W}}})}}s[U].flows={out:{node:l("flow/switch",{values:{selection:T(C)},flows:k})}},L.push(U)}else if(N==="playAnimation")L.push(l("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(N==="stopAnimation")L.push(l("animation/stop"));else if(N==="sendEvent"){let O={};for(let[V,S]of Object.entries(p.values||{}))O[V]={value:S};L.push(l("event/send",{configuration:{event:a(String(p.event??p.id??"custom"))},values:O}))}}if(!L.length)return null;if(L.length===1)return L[0];let v={};return L.forEach((D,p)=>{v[String(p)]={node:D}}),l("flow/sequence",{flows:v})},x=(h,w,L)=>{let v=c(w);v!==null&&l(h,{...L?{configuration:L}:{},flows:{out:{node:v}}})};if(b.onSelect&&x("pointer/onSelect",b.onSelect,{nodeIndex:f}),b.onHoverIn&&x("pointer/onHoverIn",b.onHoverIn,{nodeIndex:f}),b.onHoverOut&&x("pointer/onHoverOut",b.onHoverOut,{nodeIndex:f}),b.onStart&&x("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[h,w]of Object.entries(b.onReceive))x("event/receive",w,{event:a(h)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:d,events:y}],graph:0}:null}var be="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[be]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,be,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[be]=e}}return n[be]}var K=ue().plugins;function Se(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n)}function Ce(){return ue().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function _e(n,e,t,i,r){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let d=1/(i-r);return n[10]=(r+i)*d,n[14]=2*r*i*d,n}function Ue(n,e,t,i){let[r,s,d]=e,[y,u,o]=i,[a,l,g]=t,T=r-a,m=s-l,E=d-g,A=Math.hypot(T,m,E);A<=1e-5?(T=0,m=0,E=1):(T/=A,m/=A,E/=A);let F=u*E-o*m,P=o*T-y*E,f=y*m-u*T;A=Math.hypot(F,P,f),A<=1e-5?(F=0,P=0,f=0):(F/=A,P/=A,f/=A);let M=m*f-E*P,b=E*F-T*f,I=T*P-m*F;return A=Math.hypot(M,b,I),A<=1e-5?(M=0,b=0,I=0):(M/=A,b/=A,I/=A),n[0]=F,n[1]=M,n[2]=T,n[3]=0,n[4]=P,n[5]=b,n[6]=m,n[7]=0,n[8]=f,n[9]=I,n[10]=E,n[11]=0,n[12]=-(F*r+P*s+f*d),n[13]=-(M*r+b*s+I*d),n[14]=-(T*r+m*s+E*d),n[15]=1,n}function J(n,e,t){let i=e[0],r=e[1],s=e[2],d=e[3],y=e[4],u=e[5],o=e[6],a=e[7],l=e[8],g=e[9],T=e[10],m=e[11],E=e[12],A=e[13],F=e[14],P=e[15],f=t[0],M=t[1],b=t[2],I=t[3];return n[0]=f*i+M*y+b*l+I*E,n[1]=f*r+M*u+b*g+I*A,n[2]=f*s+M*o+b*T+I*F,n[3]=f*d+M*a+b*m+I*P,f=t[4],M=t[5],b=t[6],I=t[7],n[4]=f*i+M*y+b*l+I*E,n[5]=f*r+M*u+b*g+I*A,n[6]=f*s+M*o+b*T+I*F,n[7]=f*d+M*a+b*m+I*P,f=t[8],M=t[9],b=t[10],I=t[11],n[8]=f*i+M*y+b*l+I*E,n[9]=f*r+M*u+b*g+I*A,n[10]=f*s+M*o+b*T+I*F,n[11]=f*d+M*a+b*m+I*P,f=t[12],M=t[13],b=t[14],I=t[15],n[12]=f*i+M*y+b*l+I*E,n[13]=f*r+M*u+b*g+I*A,n[14]=f*s+M*o+b*T+I*F,n[15]=f*d+M*a+b*m+I*P,n}function Be(n,e,t,i){let r=e[0],s=e[1],d=e[2],y=e[3],u=r+r,o=s+s,a=d+d,l=r*u,g=r*o,T=r*a,m=s*o,E=s*a,A=d*a,F=y*u,P=y*o,f=y*a,M=i[0],b=i[1],I=i[2];return n[0]=(1-(m+A))*M,n[1]=(g+f)*M,n[2]=(T-P)*M,n[3]=0,n[4]=(g-f)*b,n[5]=(1-(l+A))*b,n[6]=(E+F)*b,n[7]=0,n[8]=(T+P)*I,n[9]=(E-F)*I,n[10]=(1-(l+m))*I,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ne(n,e){let t=e[0],i=e[1],r=e[2],s=e[4],d=e[5],y=e[6],u=e[8],o=e[9],a=e[10],l=a*d-y*o,g=-a*s+y*u,T=o*s-d*u,m=t*l+i*g+r*T;return m&&(m=1/m,n[0]=l*m,n[1]=(-a*i+r*o)*m,n[2]=(y*i-r*d)*m,n[3]=g*m,n[4]=(a*t-r*u)*m,n[5]=(-y*t+r*s)*m,n[6]=T*m,n[7]=(-o*t+i*u)*m,n[8]=(d*t-i*s)*m),n}function Ne(n,e){let t=e[0],i=e[1],r=e[2],s=e[3],d=e[4],y=e[5],u=e[6],o=e[7],a=e[8],l=e[9],g=e[10],T=e[11],m=e[12],E=e[13],A=e[14],F=e[15],P=t*y-i*d,f=t*u-r*d,M=t*o-s*d,b=i*u-r*y,I=i*o-s*y,c=r*o-s*u,x=a*E-l*m,h=a*A-g*m,w=a*F-T*m,L=l*A-g*E,v=l*F-T*E,D=g*F-T*A,p=P*D-f*v+M*L+b*w-I*h+c*x;return p?(p=1/p,n[0]=(y*D-u*v+o*L)*p,n[1]=(r*v-i*D-s*L)*p,n[2]=(E*c-A*I+F*b)*p,n[3]=(g*I-l*c-T*b)*p,n[4]=(u*w-d*D-o*h)*p,n[5]=(t*D-r*w+s*h)*p,n[6]=(A*M-m*c-F*f)*p,n[7]=(a*c-g*M+T*f)*p,n[8]=(d*v-y*w+o*x)*p,n[9]=(i*w-t*v-s*x)*p,n[10]=(m*I-E*M+F*P)*p,n[11]=(l*M-a*I-T*P)*p,n[12]=(y*h-d*L-u*x)*p,n[13]=(t*L-i*h+r*x)*p,n[14]=(E*f-m*b-A*P)*p,n[15]=(a*b-l*f+g*P)*p,n):null}function Ae(n,e,t,i,r){let s=r[0]*e+r[4]*t+r[8]*i+r[12],d=r[1]*e+r[5]*t+r[9]*i+r[13],y=r[2]*e+r[6]*t+r[10]*i+r[14],u=r[3]*e+r[7]*t+r[11]*i+r[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=d*o,n[2]=y*o}function ke(n,e,t,i,r,s,d,y,u,o,a,l,g,T,m,E,A=0){let F=o-d,P=a-y,f=l-u,M=g-d,b=T-y,I=m-u,c=r*I-s*b,x=s*M-i*I,h=i*b-r*M,w=F*c+P*x+f*h;if(w>-1e-7&&w<1e-7)return!1;let L=1/w,v=n-d,D=e-y,p=t-u,N=L*(v*c+D*x+p*h);if(N<-A||N>1+A)return!1;let H=D*f-p*P,O=p*F-v*f,V=v*P-D*F,S=L*(i*H+r*O+s*V);if(S<-A||N+S>1+A)return!1;let C=L*(M*H+b*O+I*V);if(C>1e-4&&C<E.distance){E.distance=C,E.point=[n+i*C,e+r*C,t+s*C];let R=P*I-f*b,B=f*M-F*I,U=F*b-P*M,k=Math.hypot(R,B,U)||1;return E.normal=[R/k,B/k,U/k],!0}return!1}function ge(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,i=[];for(let a=0;a<t;a++)i.push(q());if(t===0)return i;let r=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let l of a.children)r.add(l);let s=new Set,d=128,y=(a,l,g=0)=>{if(g>d||a<0||a>=t||s.has(a))return;s.add(a);let T=n.nodes[a];if(!T)return;let m=q();if(e&&e[a])m.set(e[a]);else if(T.matrix&&T.matrix.length===16)m.set(T.matrix);else{let A=T.translation||[0,0,0],F=T.rotation||[0,0,0,1],P=T.scale||[1,1,1];Be(m,F,A,P)}let E=i[a];if(l?J(E,l,m):E.set(m),Array.isArray(T.children))for(let A of T.children)typeof A=="number"&&y(A,E,g+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)r.has(a)||u.push(a);for(let a of u)y(a,null);for(let a=0;a<t;a++)!r.has(a)&&!u.includes(a)&&y(a,null);return i}function lt(n){return new TextDecoder().decode(n)}var Oe=ue().decoders;function mt(n,e){Oe.set(n.toLowerCase(),e)}function me(n){return Oe.get(n.toLowerCase())}function He(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 i=t.getUint32(0,!0);if(i!==1179937895){let g=t.getUint8(0);throw g===123||g===32||g===10||g===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${i.toString(16)}`)}let r=t.getUint32(4,!0);if(r!==2)throw new Error(`Unsupported GLB version: ${r}`);let s=t.getUint32(8,!0),d=12,y=null,u=null;for(;d+8<=s&&d+8<=e.byteLength;){let g=t.getUint32(d,!0),T=t.getUint32(d+4,!0),m=d+8;if(m+g>e.byteLength)throw new Error(`Truncated GLB chunk: required ${m+g} bytes, buffer has ${e.byteLength}`);if(T===1313821514){let E=new Uint8Array(e,m,g),A=lt(E);y=JSON.parse(A,(F,P)=>F==="__proto__"||F==="constructor"||F==="prototype"?void 0:P)}else T===5130562&&(u=e.slice(m,m+g));d=m+g}if(!y)throw new Error("Missing JSON chunk in GLB");let o=y.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!me("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),l={gltf:y,bin:a,animations:[]};for(let g of K)g.onParseGLB?.(l);return l}function ht(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 he(n){if(ht(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return He(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ze=`#version 300 es
|
|
17
|
+
"use strict";var Ae=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var ct=Object.prototype.hasOwnProperty;var ut=(n,e)=>{for(var t in e)Ae(n,t,{get:e[t],enumerable:!0})},lt=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ot(e))!ct.call(n,r)&&r!==t&&Ae(n,r,{get:()=>e[r],enumerable:!(i=at(e,r))||i.enumerable});return n};var mt=n=>lt(Ae({},"__esModule",{value:!0}),n);var wt={};ut(wt,{buildUSDZZip:()=>Ce,calculateCRC32:()=>Ze,compileInteractivityGraph:()=>we,createUSDZBlob:()=>At,encodeUtf8:()=>fe,extractMeshesFromGLB:()=>Le,extractMeshesFromScene:()=>qe,generateUSDA:()=>Ye,generateUSDAFromMeshes:()=>Re,generateUSDZ:()=>Qe,glbToUSDZ:()=>Je,sanitizeUsdIdentifier:()=>Me,sanitizeUsdStringLiteral:()=>Fe,sceneToCanvas3D:()=>Ke,sceneToGLB:()=>Tt,sceneToUSDZ:()=>je});module.exports=mt(wt);function we(n,e,t){let i=[],r=new Map,s=[],l=[],y=[],u=new Map,a=f=>{let v=r.get(f);return v===void 0&&(v=i.length,i.push({op:f}),r.set(f,v)),v},o=f=>{let v=u.get(f);return v===void 0&&(v=y.length,y.push({id:f}),u.set(f,v)),v},m=(f,v={})=>s.push({declaration:a(f),...v})-1,T=(f,v,p)=>l.push({id:f,type:v,value:p})-1,M=f=>({node:f,socket:"value"}),h=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(h&&typeof h=="object"){let f=Array.isArray(h.graphs)?h.graphs[h.graph??0]:h;if(f&&Array.isArray(f.nodes)){let v=Array.isArray(f.declarations)?f.declarations:[];for(let p of v)p?.op&&a(p.op);Array.isArray(f.variables)&&l.push(...f.variables);for(let p of f.events||[])p?.id&&o(p.id);for(let p of f.nodes){if(!p||typeof p!="object")continue;let w=p.op||(typeof p.declaration=="number"?v[p.declaration]?.op:"");s.push(w?{...p,declaration:a(w)}:{...p})}}}let E=(f,v,p="translation")=>p==="baseColorFactor"||p==="metallicFactor"||p==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${p}`:p==="emissiveFactor"||p==="alphaCutoff"?`/materials/${Math.max(0,v)}/${p}`:p==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${p}`,D=new Map;n.forEach((f,v)=>{typeof f?.name=="string"&&!D.has(f.name)&&D.set(f.name,v)});let F=(f,v)=>typeof f.target=="string"&&D.has(f.target)?D.get(f.target):typeof f.targetNode=="number"?f.targetNode:v,C=f=>{let v=n[f];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let v=n[f],p=v?.extras?.interactivity;if(!p||typeof p!="object")continue;let w=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,c=b=>{let A=Array.isArray(b)?b:[b],P=[];for(let g=0;g<A.length;g++){let d=A[g];if(!d||typeof d!="object")continue;let U=d.action||"interpolate",S=typeof d.duration=="number"?d.duration:.35;if(U==="toggleTransform"){let V=d.property==="rotation"||d.property==="scale"?d.property:"translation",G=V==="rotation"?v.rotation||[0,0,0,1]:V==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],L=`/nodes/${f}/${V}`,_=T(`__toggle_${f}_${g}`,"bool",!1),R=m("variable/get",{configuration:{variable:_}}),k=m("math/not",{values:{a:M(R)}}),N=m("variable/set",{configuration:{variable:_},values:{value:M(k)}}),O=m("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(d.to)?d.to:G},duration:{value:S}}}),B=m("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(d.from)?d.from:G},duration:{value:S}}});s[N].flows={out:{node:m("flow/branch",{values:{condition:M(R)},flows:{true:{node:O},false:{node:B}}})}},P.push(N)}else if(U==="interpolate"){let V=d.to??d.value;if(V===void 0)continue;let G={value:{value:V},duration:{value:S}};d.from!==void 0&&(G.from={value:d.from}),P.push(m("pointer/interpolate",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:E(F(d,f),C(F(d,f)),d.property)},values:G}))}else if(U==="setProperty"){if(d.value===void 0)continue;P.push(m("pointer/set",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:E(F(d,f),C(F(d,f)),d.property)},values:{value:{value:d.value}}}))}else if(U==="toggleVisibility"){let V=F(d,f),G=T(`__vis_${V}_${g}`,"bool",!0),L=m("variable/get",{configuration:{variable:G}}),_=m("math/not",{values:{a:M(L)}}),R=m("variable/set",{configuration:{variable:G},values:{value:M(_)}});s[R].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:M(L)}})}},P.push(R)}else if(U==="cycleMaterialColor"&&Array.isArray(d.colors)&&d.colors.length>0){let V=typeof d.duration=="number"?d.duration:.25,G=`/materials/${Math.max(0,w)}/pbrMetallicRoughness/baseColorFactor`,L=T(`__color_idx_${f}_${g}`,"int",0),_=m("variable/get",{configuration:{variable:L}}),R=m("math/add",{values:{a:M(_),b:{value:1}}}),k=m("math/rem",{values:{a:M(R),b:{value:d.colors.length}}}),N=m("variable/set",{configuration:{variable:L},values:{value:M(k)}}),O={};for(let B=0;B<d.colors.length;B++){let H=d.colors[B],W=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];O[String(B)]={node:V>0?m("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:W},duration:{value:V}}}):m("pointer/set",{configuration:{pointer:G},values:{value:{value:W}}})}}s[N].flows={out:{node:m("flow/switch",{values:{selection:M(_)},flows:O})}},P.push(N)}else if(U==="playAnimation")P.push(m("animation/start",{configuration:{animation:d.animation??d.clip??0}}));else if(U==="stopAnimation")P.push(m("animation/stop"));else if(U==="sendEvent"){let V={};for(let[G,L]of Object.entries(d.values||{}))V[G]={value:L};P.push(m("event/send",{configuration:{event:o(String(d.event??d.id??"custom"))},values:V}))}}if(!P.length)return null;if(P.length===1)return P[0];let I={};return P.forEach((g,d)=>{I[String(d)]={node:g}}),m("flow/sequence",{flows:I})},x=(b,A,P)=>{let I=c(A);I!==null&&m(b,{...P?{configuration:P}:{},flows:{out:{node:I}}})};if(p.onSelect&&x("pointer/onSelect",p.onSelect,{nodeIndex:f}),p.onHoverIn&&x("pointer/onHoverIn",p.onHoverIn,{nodeIndex:f}),p.onHoverOut&&x("pointer/onHoverOut",p.onHoverOut,{nodeIndex:f}),p.onStart&&x("event/onStart",p.onStart),p.onReceive&&typeof p.onReceive=="object")for(let[b,A]of Object.entries(p.onReceive))x("event/receive",A,{event:o(b)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:l,events:y}],graph:0}:null}var be="__THREE_LIVE_REGISTRY__";function ee(){let n=typeof globalThis<"u"?globalThis:{};if(!n[be]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,be,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[be]=e}}return n[be]}var Y=ee().plugins;function Ie(n){let e=ee().plugins;e.some(t=>t.name===n.name)||e.push(n)}function _e(){return ee().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function ge(n,e,t,i,r){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let l=1/(i-r);return n[10]=(r+i)*l,n[14]=2*r*i*l,n}function ye(n,e,t,i){let[r,s,l]=e,[y,u,a]=i,[o,m,T]=t,M=r-o,h=s-m,E=l-T,D=Math.hypot(M,h,E);D<=1e-5?(M=0,h=0,E=1):(M/=D,h/=D,E/=D);let F=u*E-a*h,C=a*M-y*E,f=y*h-u*M;D=Math.hypot(F,C,f),D<=1e-5?(F=0,C=0,f=0):(F/=D,C/=D,f/=D);let v=h*f-E*C,p=E*F-M*f,w=M*C-h*F;return D=Math.hypot(v,p,w),D<=1e-5?(v=0,p=0,w=0):(v/=D,p/=D,w/=D),n[0]=F,n[1]=v,n[2]=M,n[3]=0,n[4]=C,n[5]=p,n[6]=h,n[7]=0,n[8]=f,n[9]=w,n[10]=E,n[11]=0,n[12]=-(F*r+C*s+f*l),n[13]=-(v*r+p*s+w*l),n[14]=-(M*r+h*s+E*l),n[15]=1,n}function J(n,e,t){let i=e[0],r=e[1],s=e[2],l=e[3],y=e[4],u=e[5],a=e[6],o=e[7],m=e[8],T=e[9],M=e[10],h=e[11],E=e[12],D=e[13],F=e[14],C=e[15],f=t[0],v=t[1],p=t[2],w=t[3];return n[0]=f*i+v*y+p*m+w*E,n[1]=f*r+v*u+p*T+w*D,n[2]=f*s+v*a+p*M+w*F,n[3]=f*l+v*o+p*h+w*C,f=t[4],v=t[5],p=t[6],w=t[7],n[4]=f*i+v*y+p*m+w*E,n[5]=f*r+v*u+p*T+w*D,n[6]=f*s+v*a+p*M+w*F,n[7]=f*l+v*o+p*h+w*C,f=t[8],v=t[9],p=t[10],w=t[11],n[8]=f*i+v*y+p*m+w*E,n[9]=f*r+v*u+p*T+w*D,n[10]=f*s+v*a+p*M+w*F,n[11]=f*l+v*o+p*h+w*C,f=t[12],v=t[13],p=t[14],w=t[15],n[12]=f*i+v*y+p*m+w*E,n[13]=f*r+v*u+p*T+w*D,n[14]=f*s+v*a+p*M+w*F,n[15]=f*l+v*o+p*h+w*C,n}function Ue(n,e,t,i){let r=e[0],s=e[1],l=e[2],y=e[3],u=r+r,a=s+s,o=l+l,m=r*u,T=r*a,M=r*o,h=s*a,E=s*o,D=l*o,F=y*u,C=y*a,f=y*o,v=i[0],p=i[1],w=i[2];return n[0]=(1-(h+D))*v,n[1]=(T+f)*v,n[2]=(M-C)*v,n[3]=0,n[4]=(T-f)*p,n[5]=(1-(m+D))*p,n[6]=(E+F)*p,n[7]=0,n[8]=(M+C)*w,n[9]=(E-F)*w,n[10]=(1-(m+h))*w,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function te(n,e){let t=e[0],i=e[1],r=e[2],s=e[4],l=e[5],y=e[6],u=e[8],a=e[9],o=e[10],m=o*l-y*a,T=-o*s+y*u,M=a*s-l*u,h=t*m+i*T+r*M;return h&&(h=1/h,n[0]=m*h,n[1]=(-o*i+r*a)*h,n[2]=(y*i-r*l)*h,n[3]=T*h,n[4]=(o*t-r*u)*h,n[5]=(-y*t+r*s)*h,n[6]=M*h,n[7]=(-a*t+i*u)*h,n[8]=(l*t-i*s)*h),n}function Be(n,e){let t=e[0],i=e[1],r=e[2],s=e[3],l=e[4],y=e[5],u=e[6],a=e[7],o=e[8],m=e[9],T=e[10],M=e[11],h=e[12],E=e[13],D=e[14],F=e[15],C=t*y-i*l,f=t*u-r*l,v=t*a-s*l,p=i*u-r*y,w=i*a-s*y,c=r*a-s*u,x=o*E-m*h,b=o*D-T*h,A=o*F-M*h,P=m*D-T*E,I=m*F-M*E,g=T*F-M*D,d=C*g-f*I+v*P+p*A-w*b+c*x;return d?(d=1/d,n[0]=(y*g-u*I+a*P)*d,n[1]=(r*I-i*g-s*P)*d,n[2]=(E*c-D*w+F*p)*d,n[3]=(T*w-m*c-M*p)*d,n[4]=(u*A-l*g-a*b)*d,n[5]=(t*g-r*A+s*b)*d,n[6]=(D*v-h*c-F*f)*d,n[7]=(o*c-T*v+M*f)*d,n[8]=(l*I-y*A+a*x)*d,n[9]=(i*A-t*I-s*x)*d,n[10]=(h*w-E*v+F*C)*d,n[11]=(m*v-o*w-M*C)*d,n[12]=(y*b-l*P-u*x)*d,n[13]=(t*P-i*b+r*x)*d,n[14]=(E*f-h*p-D*C)*d,n[15]=(o*p-m*f+T*C)*d,n):null}function De(n,e,t,i,r){let s=r[0]*e+r[4]*t+r[8]*i+r[12],l=r[1]*e+r[5]*t+r[9]*i+r[13],y=r[2]*e+r[6]*t+r[10]*i+r[14],u=r[3]*e+r[7]*t+r[11]*i+r[15],a=u!==0?1/u:1;n[0]=s*a,n[1]=l*a,n[2]=y*a}function Ne(n,e,t,i,r,s,l,y,u,a,o,m,T,M,h,E,D=0){let F=a-l,C=o-y,f=m-u,v=T-l,p=M-y,w=h-u,c=r*w-s*p,x=s*v-i*w,b=i*p-r*v,A=F*c+C*x+f*b;if(A>-1e-7&&A<1e-7)return!1;let P=1/A,I=n-l,g=e-y,d=t-u,U=P*(I*c+g*x+d*b);if(U<-D||U>1+D)return!1;let S=g*f-d*C,V=d*F-I*f,G=I*C-g*F,L=P*(i*S+r*V+s*G);if(L<-D||U+L>1+D)return!1;let _=P*(v*S+p*V+w*G);if(_>1e-4&&_<E.distance){E.distance=_,E.point=[n+i*_,e+r*_,t+s*_];let R=C*w-f*p,k=f*v-F*w,N=F*p-C*v,O=Math.hypot(R,k,N)||1;return E.normal=[R/O,k/O,N/O],!0}return!1}function ve(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,i=[];for(let o=0;o<t;o++)i.push(q());if(t===0)return i;let r=new Set;for(let o of n.nodes)if(Array.isArray(o.children))for(let m of o.children)r.add(m);let s=new Set,l=128,y=(o,m,T=0)=>{if(T>l||o<0||o>=t||s.has(o))return;s.add(o);let M=n.nodes[o];if(!M)return;let h=q();if(e&&e[o])h.set(e[o]);else if(M.matrix&&M.matrix.length===16)h.set(M.matrix);else{let D=M.translation||[0,0,0],F=M.rotation||[0,0,0,1],C=M.scale||[1,1,1];Ue(h,F,D,C)}let E=i[o];if(m?J(E,m,h):E.set(h),Array.isArray(M.children))for(let D of M.children)typeof D=="number"&&y(D,E,T+1)},u=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(a&&Array.isArray(a.nodes))u.push(...a.nodes);else for(let o=0;o<t;o++)r.has(o)||u.push(o);for(let o of u)y(o,null);for(let o=0;o<t;o++)!r.has(o)&&!u.includes(o)&&y(o,null);return i}function ht(n){return new TextDecoder().decode(n)}var Ve=ee().decoders;function ft(n,e){Ve.set(n.toLowerCase(),e)}function me(n){return Ve.get(n.toLowerCase())}function He(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 i=t.getUint32(0,!0);if(i!==1179937895){let T=t.getUint8(0);throw T===123||T===32||T===10||T===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${i.toString(16)}`)}let r=t.getUint32(4,!0);if(r!==2)throw new Error(`Unsupported GLB version: ${r}`);let s=t.getUint32(8,!0),l=12,y=null,u=null;for(;l+8<=s&&l+8<=e.byteLength;){let T=t.getUint32(l,!0),M=t.getUint32(l+4,!0),h=l+8;if(h+T>e.byteLength)throw new Error(`Truncated GLB chunk: required ${h+T} bytes, buffer has ${e.byteLength}`);if(M===1313821514){let E=new Uint8Array(e,h,T),D=ht(E);y=JSON.parse(D,(F,C)=>F==="__proto__"||F==="constructor"||F==="prototype"?void 0:C)}else M===5130562&&(u=e.slice(h,h+T));l=h+T}if(!y)throw new Error("Missing JSON chunk in GLB");let a=y.extensionsRequired||[];if(a.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(a.includes("EXT_meshopt_compression")&&!me("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(a.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let o=u||new ArrayBuffer(0),m={gltf:y,bin:o,animations:[]};for(let T of Y)T.onParseGLB?.(m);return m}function dt(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 he(n){if(dt(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return He(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ze=`#version 300 es
|
|
18
18
|
layout(location=0) in vec3 aPosition;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
20
20
|
layout(location=2) in vec2 aUV;
|
|
@@ -32,7 +32,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
32
32
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
33
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
34
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
-
}
|
|
35
|
+
}`,pt=`#version 300 es
|
|
36
36
|
precision highp float;
|
|
37
37
|
in vec3 vNormal,vWorldPos;
|
|
38
38
|
in vec2 vUV;
|
|
@@ -40,12 +40,13 @@ uniform vec4 uBaseColor;
|
|
|
40
40
|
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
|
|
41
41
|
uniform vec2 uClearcoat;
|
|
42
42
|
uniform vec3 uCameraPos,uAmbientColor;
|
|
43
|
-
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap
|
|
44
|
-
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap
|
|
45
|
-
uniform float uNormalScale,uOcclusionStrength
|
|
46
|
-
|
|
43
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
|
|
44
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap;
|
|
45
|
+
uniform float uNormalScale,uOcclusionStrength;
|
|
46
|
+
/*XRD_U*/
|
|
47
47
|
uniform vec2 uViewportSize;
|
|
48
|
-
uniform
|
|
48
|
+
uniform vec4 uSectionPlane;
|
|
49
|
+
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
49
50
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
|
|
50
51
|
out vec4 fragColor;
|
|
51
52
|
|
|
@@ -114,6 +115,7 @@ return color;
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
void main(){
|
|
118
|
+
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
117
119
|
vec4 base=uBaseColor;
|
|
118
120
|
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
119
121
|
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
@@ -194,32 +196,21 @@ color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
|
194
196
|
}
|
|
195
197
|
color=applyToneMapping(color,uToneMapping);
|
|
196
198
|
float outAlpha=base.a;
|
|
197
|
-
|
|
198
|
-
vec2 normViewUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.0));
|
|
199
|
-
vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
|
|
200
|
-
vec4 depthSample=texture(uXrDepthTex,depthUV);
|
|
201
|
-
float realDepth=(uXrDepthFormat==1?depthSample.r:(depthSample.r+depthSample.a*256.0))*uXrRawValueToMeters;
|
|
202
|
-
float virtDepth=length(uCameraPos-vWorldPos);
|
|
203
|
-
if(realDepth>0.05&&virtDepth>realDepth){
|
|
204
|
-
float occAlpha=1.0-smoothstep(0.0,0.025,virtDepth-realDepth);
|
|
205
|
-
outAlpha*=occAlpha;
|
|
206
|
-
if(outAlpha<0.01)discard;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
199
|
+
/*XRD_O*/
|
|
209
200
|
fragColor=vec4(color,outAlpha);
|
|
210
|
-
}`,
|
|
201
|
+
}`,bt=`#version 300 es
|
|
211
202
|
layout(location=0) in vec3 aPosition;
|
|
212
203
|
uniform mat4 uMVP;
|
|
213
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
204
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,gt=`#version 300 es
|
|
214
205
|
precision highp float;
|
|
215
206
|
uniform vec4 uColorId;
|
|
216
207
|
out vec4 fragColor;
|
|
217
|
-
void main(){fragColor=uColorId;}`;function Ve(n,e,t){let i=n.createShader(e);if(n.shaderSource(i,t),n.compileShader(i),!n.getShaderParameter(i,35713)){let r=n.getShaderInfoLog(i);throw n.deleteShader(i),new Error(`Shader compile error: ${r}`)}return i}function we(n,e,t){let i=Ve(n,35633,e),r=Ve(n,35632,t),s=n.createProgram();if(n.attachShader(s,i),n.attachShader(s,r),n.linkProgram(s),!n.getProgramParameter(s,35714)){let d=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${d}`)}return s}function Ee(n,e,t){let i={};for(let r of t)i[r]=n.getUniformLocation(e,r);return i}var Xe=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize"];function pt(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,i,r,s,d){if(i===void 0||!e.accessors?.[i])return null;let y=e.accessors[i],u=e.bufferViews[y.bufferView],o=(u.byteOffset||0)+(y.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,l;if(a===s)l=new Float32Array(t,o,y.count*s);else{l=new Float32Array(y.count*s);let T=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),m=(y.byteOffset||0)>>2;for(let E=0;E<y.count;E++){let A=m+E*a;for(let F=0;F<s;F++)l[E*s+F]=T[A+F]}}let g=n.createBuffer();return d.push(g),n.bindBuffer(34962,g),n.bufferData(34962,l,35044),n.enableVertexAttribArray(r),n.vertexAttribPointer(r,s,5126,!1,0,0),l}var Lt=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),We=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ge(n,e,t=We,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r,bin:s}=e,d=[],y=ge(r),u=[];if(Array.isArray(r.nodes))for(let x=0;x<r.nodes.length;x++){let h=r.nodes[x];h.mesh!==void 0&&r.meshes&&r.meshes[h.mesh]&&u.push({node:h,nodeIdx:x,meshIdx:h.mesh})}let o=u.length>0?u:(r.meshes||[]).map((x,h)=>({node:x,nodeIdx:-1,meshIdx:h})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let x=r.extensions.KHR_lights_punctual.lights;for(let h of x){let w=h.type==="directional"?"directional":h.type==="point"?"point":"ambient";a.push({type:w,color:h.color||[1,1,1],intensity:h.intensity!==void 0?h.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let l=[];if(r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let x=0;x<r.textures.length;x++){let h=r.textures[x],w=r.images[h.source];if(w){let L=n.createTexture();if(n.bindTexture(3553,L),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),w.bufferView!==void 0){let v=r.bufferViews[w.bufferView],D=s.slice(v.byteOffset||0,(v.byteOffset||0)+v.byteLength),p=new Blob([D],{type:w.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(p).then(N=>{n.bindTexture(3553,L),n.texImage2D(3553,0,6408,6408,5121,N),n.generateMipmap(3553),i?.()}).catch(()=>{})}else if(w.uri){let v=pt(w.uri);if(v){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{n.bindTexture(3553,L),n.texImage2D(3553,0,6408,6408,5121,D),n.generateMipmap(3553),i?.()},D.src=v}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",w.uri)}l.push(L)}else l.push(null)}}let g=[1/0,1/0,1/0],T=[-1/0,-1/0,-1/0],m=0,E=0;for(let x=0;x<o.length;x++){let h=o[x],w=r.meshes[h.meshIdx],L=h.nodeIdx>=0?y[h.nodeIdx]:q(),v=new Float32Array(9);ne(v,L);let D={name:h.node.name||w.name||`Mesh_${h.meshIdx}`,nodeIndex:h.nodeIdx,transform:L,normalMatrix:v,primitives:[],extras:h.node.extras||w.extras};for(let p of w.primitives||[]){if(p.extensions?.KHR_draco_mesh_compression){let X=me("draco");X&&X.decodePrimitive(r,p,s)}let N=[],H=n.createVertexArray();n.bindVertexArray(H);let O=r.accessors[p.attributes.POSITION],V=Number(O?.count??0);if(!Number.isFinite(V)||V<0||m+V>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(m+=V,O?.min&&O?.max)for(let X=0;X<3;X++){let Q=L[12+X],ce=L[12+X];for(let ie=0;ie<3;ie++){let de=L[ie*4+X]*O.min[ie],pe=L[ie*4+X]*O.max[ie];Q+=de<pe?de:pe,ce+=de>pe?de:pe}Q<g[X]&&(g[X]=Q),ce>T[X]&&(T[X]=ce)}let S=De(n,r,s,p.attributes.POSITION,0,3,N);De(n,r,s,p.attributes.NORMAL,1,3,N),De(n,r,s,p.attributes.TEXCOORD_0,2,2,N);let C=0,R=5123,B=null;if(p.indices!==void 0){let X=r.accessors[p.indices],ce=(r.bufferViews[X.bufferView].byteOffset||0)+(X.byteOffset||0);if(C=Number(X.count??0),!Number.isFinite(C)||C<0||E+C>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);E+=C,R=X.componentType===5125?5125||5125:5123||5123;let ie=n.createBuffer();N.push(ie),n.bindBuffer(34963,ie),X.componentType===5125?(B=new Uint32Array(s,ce,X.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,ce,X.count),n.bufferData(34963,B,35044))}else C=O.count;let U={};for(let X of K)if(X.onBuildPrimitiveVAO){let Q=X.onBuildPrimitiveVAO(n,H,p,r,s);Q&&(U[X.name]=Q)}n.bindVertexArray(null);let k=r.materials&&p.material!==void 0?r.materials[p.material]:null,_=ze,G=$e,W=!1;for(let X of K)if(X.onResolveShader){let Q=X.onResolveShader(p,k,_,G);Q&&(_=Q.vs,G=Q.fs,W=!0)}let $=W?we(n,_,G):null,ee=$?Ee(n,$,Xe):null,Y=k?.pbrMetallicRoughness,Z=Y?.baseColorFactor||[.8,.8,.8,1],re=Y?.metallicFactor??.1,se=Y?.roughnessFactor??.5,te=k?.extensions?.KHR_materials_clearcoat,j=te?te.clearcoatFactor??1:0,ae=Math.max(.04,te?.clearcoatRoughnessFactor??.04),oe=Y?.baseColorTexture!==void 0&&l[Y.baseColorTexture.index]?l[Y.baseColorTexture.index]:null,le=Y?.metallicRoughnessTexture!==void 0&&l[Y.metallicRoughnessTexture.index]?l[Y.metallicRoughnessTexture.index]:null,Qe=k?.normalTexture!==void 0&&l[k.normalTexture.index]?l[k.normalTexture.index]:null,et=k?.normalTexture?.scale??1,tt=k?.occlusionTexture!==void 0&&l[k.occlusionTexture.index]?l[k.occlusionTexture.index]:null,nt=k?.occlusionTexture?.strength??1,it=!!(k?.extensions?.KHR_materials_transmission||U.materials?.isTransmissive);D.primitives.push({vao:H,indexCount:C,indexType:R,baseColor:Z,metallic:re,roughness:se,clearcoat:j,clearcoatRoughness:ae,positions:S,indices:B,texture:oe,metallicRoughnessTexture:le,normalTexture:Qe,occlusionTexture:tt,normalScale:et,occlusionStrength:nt,buffers:N,materialIndex:p.material,pluginData:U,customProgram:$,customUniforms:ee,isTransmissive:it})}d.push(D)}isFinite(g[0])||(g=[-1,-1,-1]),isFinite(T[0])||(T=[1,1,1]);let A=[(g[0]+T[0])/2,(g[1]+T[1])/2,(g[2]+T[2])/2],F=T[0]-g[0],P=T[1]-g[1],f=T[2]-g[2],M=Math.max(Math.hypot(F,P,f)/2,.5),b=[g[0],g[1],g[2]],I=[T[0],T[1],T[2]],c=e.animations;if(!c){for(let x of K)if(x.onParseGLB?.(e),e.animations){c=e.animations;break}}return c||(c=[]),{meshes:d,bounds:{center:A,radius:M,min:b,max:I},lights:a,animations:c,worldMatrices:y}}var ye=class{constructor(e,t,i){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=q();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=q();this.viewMatrix=q();this.modelMatrix=q();this.mvpMatrix=q();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.xrDepthState={enabled:!1,texture:null,uvTransform:q(),rawValueToMeters:.001,format:0};this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),r=u}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let d=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!d:d&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let y=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!y)throw new Error("WebGL2 not supported");this.gl=y,this.renderProg=we(y,ze,$e),this.pickProg=we(y,ft,dt),this.uRender=Ee(y,this.renderProg,Xe),this.uPick=Ee(y,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){mt(e,t)}static getDecoder(e){return me(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:d,worldMatrices:y}=Ge(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=d||[],this.worldMatrices=y||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of K)o.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(He(e))}loadModel(e){this.loadGLBData(he(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=he(e),{meshes:r}=Ge(this.gl,i,We,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],ne(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),ne(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],d=[],y=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")i=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&r.length<6){let l=u.direction||[.5,1,.8];r.push(l[0],l[1],l[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&d.length<6){let l=u.position||[0,0,0];d.push(l[0],l[1],l[2]),y.push(o[0]*a,o[1]*a,o[2]*a)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,d.length/3),d.length>0&&(t.uniform3fv(e.uPointLightPos,d),t.uniform3fv(e.uPointLightColor,y)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of K)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of K)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(a=>a.primitives.filter(l=>l.materialIndex===i||e.length===1&&l.materialIndex===void 0)),s=r[0],d=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],y=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:d,metallicFactor:y,roughnessFactor:u,setBaseColorFactor:a=>{let l=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=l);for(let g of r)g.baseColor=l;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let l of r)l.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let l of r)l.roughness=a;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of K)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=q();J(i,this.projMatrix,this.viewMatrix);let[r,s,d]=e,y=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(r=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],d=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(y=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let l=i[0]*r+i[4]*s+i[8]*d+i[12],g=i[1]*r+i[5]*s+i[9]*d+i[13],T=i[2]*r+i[6]*s+i[10]*d+i[14],m=i[3]*r+i[7]*s+i[11]*d+i[15];if(m<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=l/m,A=g/m,F=T/m,P=this.canvas.getBoundingClientRect(),f=P.width||this.canvas.clientWidth||this.canvas.width||300,M=P.height||this.canvas.clientHeight||this.canvas.height||150,b=(E*.5+.5)*f,I=(-A*.5+.5)*M,c=E>=-1.1&&E<=1.1&&A>=-1.1&&A<=1.1&&F>=-1&&F<=1;if(c&&t){let x=this.customTarget||this.bounds.center,h=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),w=x[1]+this.currDistance*Math.sin(this.currPhi),L=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),v=[r-h,s-w,d-L];y*v[0]+u*v[1]+o*v[2]>.05&&(c=!1)}return{x:b,y:I,z:F,visible:c}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let i=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},r=t.clientX-i.x,s=t.clientY-i.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(r,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let d=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],y=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-r*d[0]+s*y[0])*o,u[1]+=(-r*d[1]+s*y[1])*o,u[2]+=(-r*d[2]+s*y[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-r*.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 i=e.getBoundingClientRect(),r=Math.floor((t.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((t.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(r,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 i=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let i=t.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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 i=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=i,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,d=i.height||300,y=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),u=r.height>0?Math.floor((t-r.top)*(d/r.height)):Math.floor(t);return this.performMeshPick(y,u,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),d=Math.max(1,this.canvas.height||300),y=q();J(y,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(d-1,d-1-t));if(this.pickFbo&&r){(this.pickFboWidth!==s||this.pickFboHeight!==d)&&this.resizePickingFbo(s,d),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,d),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16384|256),r.useProgram(this.pickProg);for(let c=0;c<this.meshes.length;c++){let x=this.meshes[c];if(x.visible===!1||x.isPluginMesh)continue;let h=c+1,w=(h&255)/255,L=(h>>8&255)/255,v=(h>>16&255)/255;r.uniform4f(this.uPick.uColorId,w,L,v,1),J(this.modelMatrix,this.modelRootMatrix,x.transform),J(this.mvpMatrix,y,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let D of x.primitives)r.bindVertexArray(D.vao),r.drawElements(4,D.indexCount,D.indexType,0)}let b=new Uint8Array(4);r.readPixels(o,a,1,1,6408,5121,b),r.bindFramebuffer(36160,null);let I=b[0]+(b[1]<<8)+(b[2]<<16);I>0&&I<=this.meshes.length&&(u=[this.meshes[I-1]])}u.length===0&&(u=this.meshes.filter(b=>b.visible!==!1));let l=null,g=1/0,T=[0,0,0],m=[0,1,0],E=this.customTarget||this.bounds.center,A=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),F=E[1]+this.currDistance*Math.sin(this.currPhi),P=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let b of u){J(this.modelMatrix,this.modelRootMatrix,b.transform),J(this.mvpMatrix,y,this.modelMatrix);let I=q();if(!Ne(I,this.mvpMatrix))continue;let c=(o+.5)/s*2-1,x=(a+.5)/d*2-1,h=[0,0,0],w=[0,0,0];Ae(h,c,x,-1,I),Ae(w,c,x,1,I);let L=w[0]-h[0],v=w[1]-h[1],D=w[2]-h[2],p=Math.hypot(L,v,D)||1,N=L/p,H=v/p,O=D/p,V={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((C=>{for(let R of b.primitives){if(!R.positions)continue;let B=R.positions,U=R.indices,k=Math.floor(U?U.length/3:B.length/9);for(let _=0;_<k;_++){let G=U?U[_*3]:_*3,W=U?U[_*3+1]:_*3+1,$=U?U[_*3+2]:_*3+2;ke(h[0],h[1],h[2],N,H,O,B[G*3],B[G*3+1],B[G*3+2],B[W*3],B[W*3+1],B[W*3+2],B[$*3],B[$*3+1],B[$*3+2],V,C)}}})(1e-4),isFinite(V.distance)){let C=V.point[0],R=V.point[1],B=V.point[2],U=this.modelMatrix,k=U[0]*C+U[4]*R+U[8]*B+U[12],_=U[1]*C+U[5]*R+U[9]*B+U[13],G=U[2]*C+U[6]*R+U[10]*B+U[14],W=k-A,$=_-F,ee=G-P,Y=Math.hypot(W,$,ee);if(Y<g){ne(this.normalMatrix,this.modelMatrix);let Z=this.normalMatrix,re=V.normal[0],se=V.normal[1],te=V.normal[2],j=Z[0]*re+Z[3]*se+Z[6]*te,ae=Z[1]*re+Z[4]*se+Z[7]*te,oe=Z[2]*re+Z[5]*se+Z[8]*te,le=Math.hypot(j,ae,oe)||1;j/=le,ae/=le,oe/=le,j*W+ae*$+oe*ee>0&&(j=-j,ae=-ae,oe=-oe),l=b,g=Math.round(Y*1e3)/1e3,T=[Math.round(k*1e3)/1e3,Math.round(_*1e3)/1e3,Math.round(G*1e3)/1e3],m=[Math.round(j*1e3)/1e3,Math.round(ae*1e3)/1e3,Math.round(oe*1e3)/1e3]}}}if(!l)return null;let M={meshIndex:this.meshes.indexOf(l),meshName:l.name,nodeIndex:l.nodeIndex,distance:g,hitPoint:T,normal:m,screenX:e,screenY:t};if(i){for(let b of K)b.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));(this.canvas.width!==i||this.canvas.height!==r)&&(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r))}start(){if(this.animFrameId!==null)return;this.lastTime=performance.now();let e=t=>{let i=Math.min((t-this.lastTime)/1e3,.1);this.lastTime=t,this.isVisible&&(this.resize(),this.update(i),this.render()),this.animFrameId=requestAnimationFrame(e)};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let g of K)g.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 g of K)g.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12;let i=(this.canvas.width||1)/(this.canvas.height||1),r=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):this.bounds.radius*20;_e(this.projMatrix,this.fov,i,.1,r);let s=this.customTarget||this.bounds.center,d=s[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),y=s[1]+this.currDistance*Math.sin(this.currPhi),u=s[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Ue(this.viewMatrix,[d,y,u],s,[0,1,0]),J(this.mvpMatrix,this.projMatrix,this.viewMatrix),ne(this.normalMatrix,this.modelMatrix);let o=Math.round((this.currTheta*180/Math.PI%360+360)%360),a=Math.round(this.currPhi*180/Math.PI),l=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(o-this.lastReportedTheta)>=1||Math.abs(a-this.lastReportedPhi)>=1||Math.abs(l-this.lastReportedZoom)>=.02){this.lastReportedTheta=o,this.lastReportedPhi=a,this.lastReportedZoom=l;let g={theta:o,phi:a,zoom:l,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:g}))}}renderXRView(e,t,i,r){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let s=e?.transform?.inverse?.matrix||this.viewMatrix,d=e?.projectionMatrix||this.projMatrix,y=e?.transform?.position,u=y?[y.x,y.y,y.z]:[0,1.6,0];i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:s,projMatrix:d,eyePos:u,viewport:r,eye:e?.eye||"none",clear:e?.eye!=="right"})}render(e){let t=this.gl,i=this.canvas.width,r=this.canvas.height;e?.viewport?(t.viewport(e.viewport[0],e.viewport[1],e.viewport[2],e.viewport[3]),i=e.viewport[2],r=e.viewport[3]):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let s=q();J(s,e?.projMatrix??this.projMatrix,e?.viewMatrix??this.viewMatrix);let d=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,y=this.customTarget||this.bounds.center,u=e?e.eyePos[0]:y[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=e?e.eyePos[1]:y[1]+this.currDistance*Math.sin(this.currPhi),a=e?e.eyePos[2]:y[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let A of K)A.onBeforeDrawScene?.(this,t,s,[u,o,a],d);if(this.meshes.length===0&&this.backdropMeshes.length===0)return;let l=e?.eye||"none",g=!1,T=this.backdropMeshes.length,m=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,E=A=>{for(let F=0;F<m.length;F++){let P=m[F];if(P.visible===!1)continue;let f=this.selectedMeshName!==""&&P.name===this.selectedMeshName;F<T?this.modelMatrix.set(P.transform):J(this.modelMatrix,this.modelRootMatrix,P.transform),J(this.mvpMatrix,s,this.modelMatrix),ne(P.normalMatrix,this.modelMatrix);let M=P.extras?.xr?.stereo||P.userData?.xr?.stereo,b=0,I=0,c=1,x=1;M==="sbs"?(c=.5,b=l==="right"?.5:0):M==="ou"&&(x=.5,I=l==="right"?.5:0);for(let h of P.primitives){let w=!!h.isTransmissive;if(!A&&w){g=!0;continue}if(A&&!w)continue;let L=h.customProgram||this.renderProg,v=h.customUniforms||this.uRender;t.useProgram(L),t.uniform1i(v.uToneMapping,d),t.uniform1f(v.uEnvIntensity,this.envIntensity),t.uniform3f(v.uCameraPos,u,o,a),t.uniform1f(v.uEmissive,f?1:0),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(v.uNormalMatrix,!1,P.normalMatrix),v.uUvTransform&&t.uniform4f(v.uUvTransform,b,I,c,x),v.uViewportSize&&t.uniform2f(v.uViewportSize,Math.max(1,i),Math.max(1,r)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),v.uXrDepthTex&&t.uniform1i(v.uXrDepthTex,5),v.uXrDepthEnabled&&t.uniform1i(v.uXrDepthEnabled,1),v.uXrDepthFormat&&t.uniform1i(v.uXrDepthFormat,this.xrDepthState.format||0),v.uXrRawValueToMeters&&t.uniform1f(v.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),v.uXrDepthUVTransform&&t.uniformMatrix4fv(v.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):v.uXrDepthEnabled&&t.uniform1i(v.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(v.uEnvironmentMap,4),t.uniform1i(v.uHasEnvironmentMap,1)):t.uniform1i(v.uHasEnvironmentMap,0),this.bindLights(v);for(let D of K)D.onBeforeDrawPrimitive?.(t,L,h,P,this.worldMatrices||[],this.gltf);t.uniform4fv(v.uBaseColor,h.baseColor),t.uniform1f(v.uMetallic,h.metallic),t.uniform1f(v.uRoughness,h.roughness),v.uClearcoat&&t.uniform2f(v.uClearcoat,h.clearcoat??0,h.clearcoatRoughness??.04),h.texture?(t.activeTexture(33984),t.bindTexture(3553,h.texture),t.uniform1i(v.uBaseColorTexture,0),t.uniform1i(v.uHasTexture,1)):t.uniform1i(v.uHasTexture,0),h.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,h.metallicRoughnessTexture),t.uniform1i(v.uMetallicRoughnessTexture,1),t.uniform1i(v.uHasMetallicRoughnessTexture,1)):t.uniform1i(v.uHasMetallicRoughnessTexture,0),h.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,h.normalTexture),t.uniform1i(v.uNormalTexture,2),t.uniform1i(v.uHasNormalTexture,1),t.uniform1f(v.uNormalScale,h.normalScale)):t.uniform1i(v.uHasNormalTexture,0),h.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,h.occlusionTexture),t.uniform1i(v.uOcclusionTexture,3),t.uniform1i(v.uHasOcclusionTexture,1),t.uniform1f(v.uOcclusionStrength,h.occlusionStrength)):t.uniform1i(v.uHasOcclusionTexture,0),t.bindVertexArray(h.vao),t.drawElements(4,h.indexCount,h.indexType,0)}}};if(E(!1),g){for(let A of K)A.onBeforeTransmissivePass?.(t,this);E(!0)}for(let A of K)A.onAfterRender?.(t,this,s)}disposeMeshListGpuResources(e){let t=this.gl;for(let i of e)for(let r of i.primitives){if(r.vao&&t.deleteVertexArray(r.vao),r.buffers)for(let s of r.buffers)t.deleteBuffer(s);r.texture&&t.deleteTexture(r.texture),r.metallicRoughnessTexture&&t.deleteTexture(r.metallicRoughnessTexture),r.normalTexture&&t.deleteTexture(r.normalTexture),r.occlusionTexture&&t.deleteTexture(r.occlusionTexture),r.customProgram&&t.deleteProgram(r.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of K)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};ye.registerPlugin=Se,ye.getRegisteredPlugins=Ce;function bt(n){return n+3&-4}function gt(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 qe(n,e){n.updateMatrixWorld(!0);let t=[],i=0,r=[],s=[],d=[],y=[],u=new Set,o=[],a=[],l=new Map,g=[];function T(c,x){let h=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),w=bt(h.byteLength),L=new Uint8Array(w);L.set(h),t.push(L);let v=r.length;return r.push({buffer:0,byteOffset:i,byteLength:h.byteLength,target:x}),i+=w,v}function m(c,x,h,w,L,v,D){let p=T(c,h),N=s.length,H={bufferView:p,byteOffset:0,componentType:w,count:L,type:x};return v&&(H.min=v),D&&(H.max=D),s.push(H),N}n.traverse(c=>{(c.isLight||c.color&&c.intensity!==void 0)&&g.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:[c.position.x,c.position.y,c.position.z]})});let E=[];function A(c){let x={name:c.name||""},h=c.position,w=c.quaternion,L=c.scale;if((h.x||h.y||h.z)&&(x.translation=[h.x,h.y,h.z]),(w.x||w.y||w.z||w.w!==1)&&(x.rotation=[w.x,w.y,w.z,w.w]),(L.x!==1||L.y!==1||L.z!==1)&&(x.scale=[L.x,L.y,L.z]),c.userData&&Object.keys(c.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(c.userData,(D,p)=>{if(!(D==="__proto__"||D==="prototype"||D==="constructor"))return typeof p=="function"?void 0:p})),c.userData.xr)){let D=gt(c.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:D,ANDROID_xr_scenecore:D},ue().xrTraitSerializer?.gltfNode(x,c.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(c.geometry){let D=c.geometry,p=D.attributes.position;if(p&&p.count>0){let N=[1/0,1/0,1/0],H=[-1/0,-1/0,-1/0];for(let C=0;C<p.count;C++){let R=p.getX(C),B=p.getY(C),U=p.getZ(C);R<N[0]&&(N[0]=R),R>H[0]&&(H[0]=R),B<N[1]&&(N[1]=B),B>H[1]&&(H[1]=B),U<N[2]&&(N[2]=U),U>H[2]&&(H[2]=U)}let V={attributes:{POSITION:m(p.array,"VEC3",34962,5126,p.count,N,H)}};if(D.attributes.normal&&(V.attributes.NORMAL=m(D.attributes.normal.array,"VEC3",34962,5126,D.attributes.normal.count)),D.attributes.uv&&(V.attributes.TEXCOORD_0=m(D.attributes.uv.array,"VEC2",34962,5126,D.attributes.uv.count)),D.index){let C=D.index.array instanceof Uint32Array;V.indices=m(D.index.array,"SCALAR",34963,C?5125:5123,D.index.count)}if(c.material){let C=l.get(c.material);if(C===void 0){C=a.length,l.set(c.material,C);let R=c.material,B={name:R.name||"",pbrMetallicRoughness:{baseColorFactor:[R.color.r,R.color.g,R.color.b,R.opacity],metallicFactor:R.metalness,roughnessFactor:R.roughness},doubleSided:R.side===2||R.doubleSided};if(R.emissive&&(R.emissive.r>0||R.emissive.g>0||R.emissive.b>0)){let k=R.emissiveIntensity??1;B.emissiveFactor=[R.emissive.r*k,R.emissive.g*k,R.emissive.b*k]}let U={};R.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:R.clearcoat,clearcoatRoughnessFactor:R.clearcoatRoughness||0}),R.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:R.sheenColor?[R.sheenColor.r,R.sheenColor.g,R.sheenColor.b]:[1,1,1],sheenRoughnessFactor:R.sheenRoughness||0}),R.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:R.transmission}),R.thickness>0&&(U.KHR_materials_volume={thicknessFactor:R.thickness,attenuationDistance:R.attenuationDistance??1/0,attenuationColor:R.attenuationColor?[R.attenuationColor.r,R.attenuationColor.g,R.attenuationColor.b]:[1,1,1]}),R.ior!==void 0&&R.ior!==1.5&&(U.KHR_materials_ior={ior:R.ior}),R.dispersion>0&&(U.KHR_materials_dispersion={dispersion:R.dispersion}),R.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:R.iridescence,iridescenceIor:R.iridescenceIOR??1.3}),Object.keys(U).length>0&&(B.extensions=U),a.push(B)}V.material=C}let S=d.length;d.push({primitives:[V],name:c.name,...x.extras?{extras:x.extras}:{}}),x.mesh=S}}let v=y.length;if(y.push(x),o.push(c),c.children.length>0){x.children=[];for(let D of c.children)x.children.push(A(D))}return v}for(let c of n.children)E.push(A(c));let F=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof F=="function"&&o.length>0){let c=e?.duration??4,x=e?.fps??15,h=Math.max(2,Math.round(c*x)+1),w=new Float32Array(h),L=o.map(S=>({px:S.position.x,py:S.position.y,pz:S.position.z,qx:S.quaternion.x,qy:S.quaternion.y,qz:S.quaternion.z,qw:S.quaternion.w,sx:S.scale.x,sy:S.scale.y,sz:S.scale.z})),v=o.map(()=>new Float32Array(h*3)),D=o.map(()=>new Float32Array(h*4)),p=o.map(()=>new Float32Array(h*3));for(let S=0;S<h;S++){let C=S/(h-1)*c;w[S]=C;try{F(C)}catch{}for(let R=0;R<o.length;R++){let B=o[R];v[R][S*3]=B.position.x,v[R][S*3+1]=B.position.y,v[R][S*3+2]=B.position.z,D[R][S*4]=B.quaternion.x,D[R][S*4+1]=B.quaternion.y,D[R][S*4+2]=B.quaternion.z,D[R][S*4+3]=B.quaternion.w,p[R][S*3]=B.scale.x,p[R][S*3+1]=B.scale.y,p[R][S*3+2]=B.scale.z}}for(let S=0;S<o.length;S++){let C=o[S],R=L[S];C.position.set(R.px,R.py,R.pz),C.quaternion.set(R.qx,R.qy,R.qz,R.qw),C.scale.set(R.sx,R.sy,R.sz)}n.updateMatrixWorld(!0);let N=null,H=()=>(N===null&&(N=m(w,"SCALAR",0,5126,h,[0],[c])),N),O=[],V=[];for(let S=0;S<o.length;S++){let C=L[S],R=!1,B=!1,U=!1;for(let k=0;k<h;k++)(Math.abs(v[S][k*3]-C.px)>1e-4||Math.abs(v[S][k*3+1]-C.py)>1e-4||Math.abs(v[S][k*3+2]-C.pz)>1e-4)&&(R=!0),(Math.abs(D[S][k*4]-C.qx)>1e-4||Math.abs(D[S][k*4+1]-C.qy)>1e-4||Math.abs(D[S][k*4+2]-C.qz)>1e-4||Math.abs(D[S][k*4+3]-C.qw)>1e-4)&&(B=!0),(Math.abs(p[S][k*3]-C.sx)>1e-4||Math.abs(p[S][k*3+1]-C.sy)>1e-4||Math.abs(p[S][k*3+2]-C.sz)>1e-4)&&(U=!0);if(R){let k=m(v[S],"VEC3",0,5126,h),_=O.length;O.push({input:H(),interpolation:"LINEAR",output:k}),V.push({sampler:_,target:{node:S,path:"translation"}})}if(B){let k=m(D[S],"VEC4",0,5126,h),_=O.length;O.push({input:H(),interpolation:"LINEAR",output:k}),V.push({sampler:_,target:{node:S,path:"rotation"}})}if(U){let k=m(p[S],"VEC3",0,5126,h),_=O.length;O.push({input:H(),interpolation:"LINEAR",output:k}),V.push({sampler:_,target:{node:S,path:"scale"}})}}V.length>0&&P.push({name:"ProceduralLoop",samplers:O,channels:V})}let f=Re(y,d,n.userData),M={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:E}],scene:0,nodes:y,meshes:d,materials:a,accessors:s,bufferViews:r,buffers:[{byteLength:i}],...P.length>0?{animations:P}:{},...f||u.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...u]}:{},...f?{extensions:{KHR_interactivity:f}}:{}},b=new Uint8Array(i),I=0;for(let c of t)b.set(c,I),I+=c.byteLength;return{gltf:M,bin:b.buffer,lights:g,environmentIntensity:n.environmentIntensity}}function fe(n){return new TextEncoder().encode(n)}function yt(n,e){let{gltf:t,bin:i}=qe(n,e),r=JSON.stringify(t),s=fe(r),d=(4-s.byteLength%4)%4,y=s.byteLength+d,u=20+y+8+i.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,y,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let g=0;g<d;g++)o[20+s.byteLength+g]=32;let l=20+y;return a.setUint32(l,i.byteLength,!0),a.setUint32(l+4,5130562,!0),o.set(new Uint8Array(i),l+8),o}function Ye(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(i=>{if(i.geometry){let r=i.geometry,s=r.attributes.position;if(!s||s.count===0)return;let d=s.count,y=new Float32Array(d*3),u=i.matrixWorld.elements;for(let c=0;c<d;c++){let x=s.getX(c),h=s.getY(c),w=s.getZ(c);y[c*3]=u[0]*x+u[4]*h+u[8]*w+u[12],y[c*3+1]=u[1]*x+u[5]*h+u[9]*w+u[13],y[c*3+2]=u[2]*x+u[6]*h+u[10]*w+u[14]}let o;if(r.attributes.normal){let c=r.attributes.normal;o=new Float32Array(d*3);let x=new Float32Array(9);ne(x,u);for(let h=0;h<d;h++){let w=c.getX(h),L=c.getY(h),v=c.getZ(h),D=x[0]*w+x[3]*L+x[6]*v,p=x[1]*w+x[4]*L+x[7]*v,N=x[2]*w+x[5]*L+x[8]*v,H=Math.hypot(D,p,N)||1;o[h*3]=D/H,o[h*3+1]=p/H,o[h*3+2]=N/H}}let a;if(r.attributes.uv){let c=r.attributes.uv;a=new Float32Array(d*2);for(let x=0;x<d;x++)a[x*2]=c.getX(x),a[x*2+1]=c.getY(x)}let l;if(r.index)l=r.index.array;else{l=d>65535?new Uint32Array(d):new Uint16Array(d);for(let c=0;c<d;c++)l[c]=c}let g="DefaultMaterial",T=[.8,.8,.8],m=.5,E=.1,A=0,F=0,P=1.5,f=1,M=[0,0,0];if(i.material){let c=i.material;g=c.name||`Material_${t.length}`,c.color&&(T=[c.color.r,c.color.g,c.color.b]),typeof c.roughness=="number"&&(m=c.roughness),typeof c.metalness=="number"&&(E=c.metalness),typeof c.clearcoat=="number"&&(A=c.clearcoat),typeof c.clearcoatRoughness=="number"&&(F=c.clearcoatRoughness),typeof c.ior=="number"&&(P=c.ior);let x=typeof c.opacity=="number"?c.opacity:1,h=typeof c.transmission=="number"?c.transmission:0;if(f=x*(1-h),c.emissive&&(c.emissive.r>0||c.emissive.g>0||c.emissive.b>0)){let w=c.emissiveIntensity??1;M=[c.emissive.r*w,c.emissive.g*w,c.emissive.b*w]}}let b,I=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 I=="function"){let c=e?.duration??4,x=e?.fps??4,h=Math.max(2,Math.round(c*x)+1),w=[],L=[],v=[],D=[],p=[i.position.x,i.position.y,i.position.z],N=[i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w],H=[i.scale.x,i.scale.y,i.scale.z],O=!1;for(let V=0;V<h;V++){let S=V/(h-1)*c;w.push(S);try{I(S)}catch{}L.push([i.position.x,i.position.y,i.position.z]),v.push([i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w]),D.push([i.scale.x,i.scale.y,i.scale.z]),(Math.abs(i.position.x-p[0])>1e-4||Math.abs(i.position.y-p[1])>1e-4||Math.abs(i.position.z-p[2])>1e-4||Math.abs(i.quaternion.x-N[0])>1e-4||Math.abs(i.quaternion.y-N[1])>1e-4||Math.abs(i.quaternion.z-N[2])>1e-4||Math.abs(i.quaternion.w-N[3])>1e-4||Math.abs(i.scale.x-H[0])>1e-4)&&(O=!0)}i.position.set(p[0],p[1],p[2]),i.quaternion.set(N[0],N[1],N[2],N[3]),i.scale.set(H[0],H[1],H[2]),O&&(b={times:w,translations:L,rotations:v,scales:D})}t.push({name:i.name||`Mesh_${t.length}`,positions:y,indices:l,normals:o,uvs:a,materialName:g,color:T,roughness:m,metallic:E,clearcoat:A,clearcoatRoughness:F,ior:P,opacity:f,emissiveColor:M,xrTraits:i.userData?.xr,timeSamples:b})}}),t}function Fe(n){let e=[],t=n.gltf,i=n.bin,r=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=t.accessors||[],d=t.bufferViews||[],y=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(T){let m=s[T];if(!m)throw new Error(`Accessor ${T} not found`);let E=d[m.bufferView||0],A=(E.byteOffset||0)+(m.byteOffset||0),F=E.byteLength||0,P=r.slice(A,A+F);return{acc:m,buffer:P}}let l=new Map;if(o.length>0){let T=ge(t);for(let m=0;m<T.length;m++)l.set(m,T[m])}function g(T,m,E,A){let F=u[T];if(!F)return;let P=new Float32Array(9);ne(P,m);for(let f=0;f<(F.primitives||[]).length;f++){let M=F.primitives[f],b=M.attributes?.POSITION;if(b===void 0)continue;let{acc:I,buffer:c}=a(b),x=new Float32Array(c,0,I.count*3),h=new Float32Array(x.length);for(let _=0;_<I.count;_++){let G=x[_*3],W=x[_*3+1],$=x[_*3+2];h[_*3]=m[0]*G+m[4]*W+m[8]*$+m[12],h[_*3+1]=m[1]*G+m[5]*W+m[9]*$+m[13],h[_*3+2]=m[2]*G+m[6]*W+m[10]*$+m[14]}let w,L=M.attributes?.NORMAL;if(L!==void 0){let{acc:_,buffer:G}=a(L),W=new Float32Array(G,0,_.count*3);w=new Float32Array(W.length);for(let $=0;$<_.count;$++){let ee=W[$*3],Y=W[$*3+1],Z=W[$*3+2],re=P[0]*ee+P[3]*Y+P[6]*Z,se=P[1]*ee+P[4]*Y+P[7]*Z,te=P[2]*ee+P[5]*Y+P[8]*Z,j=Math.hypot(re,se,te)||1;w[$*3]=re/j,w[$*3+1]=se/j,w[$*3+2]=te/j}}let v,D=M.attributes?.TEXCOORD_0;if(D!==void 0){let{acc:_,buffer:G}=a(D);v=new Float32Array(G,0,_.count*2)}let p;if(M.indices!==void 0){let{acc:_,buffer:G}=a(M.indices);_.componentType===5125?p=new Uint32Array(G,0,_.count):p=new Uint16Array(G,0,_.count);let W=I.count;for(let $ of p)if($>=W)throw new Error(`SecurityError: Index buffer value (${$}) out of vertex bounds [0, ${W}).`)}else{let _=I.count;p=_>65535?new Uint32Array(_):new Uint16Array(_);for(let G=0;G<_;G++)p[G]=G}let N="DefaultMaterial",H=[.8,.8,.8],O=.5,V=.1,S=0,C=0,R=1.5,B=1,U=[0,0,0];if(M.material!==void 0&&y[M.material]){let _=y[M.material];N=_.name||`Material_${M.material}`;let G=_.pbrMetallicRoughness||{},W=1;Array.isArray(G.baseColorFactor)&&(H=[G.baseColorFactor[0],G.baseColorFactor[1],G.baseColorFactor[2]],typeof G.baseColorFactor[3]=="number"&&(W=G.baseColorFactor[3])),typeof G.roughnessFactor=="number"&&(O=G.roughnessFactor),typeof G.metallicFactor=="number"&&(V=G.metallicFactor),Array.isArray(_.emissiveFactor)&&_.emissiveFactor.length>=3&&(U=[_.emissiveFactor[0],_.emissiveFactor[1],_.emissiveFactor[2]]);let $=_.extensions||{};$.KHR_materials_clearcoat&&(S=$.KHR_materials_clearcoat.clearcoatFactor??0,C=$.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),$.KHR_materials_ior&&typeof $.KHR_materials_ior.ior=="number"&&(R=$.KHR_materials_ior.ior);let ee=$.KHR_materials_transmission?.transmissionFactor??0;B=W*(1-ee)}let k=(F.primitives||[]).length>1?`${E}_p${f}`:E;e.push({name:k,positions:h,indices:p,normals:w,uvs:v,materialName:N,color:H,roughness:O,metallic:V,clearcoat:S,clearcoatRoughness:C,ior:R,opacity:B,emissiveColor:U,xrTraits:A?.xr||F.extras?.xr})}}if(o.length>0)for(let T=0;T<o.length;T++){let m=o[T];if(m.mesh!==void 0&&m.mesh<u.length){let E=l.get(T)||q(),A=m.name||u[m.mesh].name||`Node_${T}`;g(m.mesh,E,A,m.extras)}}else{let T=q();for(let m=0;m<u.length;m++){let E=u[m].name||`Mesh_${m}`;g(m,T,E,u[m].extras)}}return e}function xe(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 Pe(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function z(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 Ke(n){let e=n.length/3,t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*3])}, ${z(n[i*3+1])}, ${z(n[i*3+2])})`;return t.join(", ")}function vt(n,e){let t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*2])}, ${z(1-n[i*2+1])})`;return t.join(", ")}function xt(n){return Array.from(n).join(", ")}function Te(n){let e=new Map;for(let u of n){let o=xe(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,i=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!i&&(i=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let r="";t>0&&(r=`startTimeCode = 0
|
|
208
|
+
void main(){fragColor=uColorId;}`;function ke(n,e,t){let i=n.createShader(e);if(n.shaderSource(i,t),n.compileShader(i),!n.getShaderParameter(i,35713)){let r=n.getShaderInfoLog(i);throw n.deleteShader(i),new Error(`Shader compile error: ${r}`)}return i}function Pe(n,e,t){let i=ke(n,35633,e),r=ke(n,35632,t),s=n.createProgram();if(n.attachShader(s,i),n.attachShader(s,r),n.linkProgram(s),!n.getProgramParameter(s,35714)){let l=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${l}`)}return s}function Se(n,e,t){let i={};for(let r of t)i[r]=n.getUniformLocation(e,r);return i}var Ge=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function $e(){let n=ee().xrDepthShader;return{fs:pt.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Ge,...n.uniformNames]:Ge}}function yt(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 Ee(n,e,t,i,r,s,l){if(i===void 0||!e.accessors?.[i])return null;let y=e.accessors[i],u=e.bufferViews[y.bufferView],a=(u.byteOffset||0)+(y.byteOffset||0),o=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,m;if(o===s)m=new Float32Array(t,a,y.count*s);else{m=new Float32Array(y.count*s);let M=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),h=(y.byteOffset||0)>>2;for(let E=0;E<y.count;E++){let D=h+E*o;for(let F=0;F<s;F++)m[E*s+F]=M[D+F]}}let T=n.createBuffer();return l.push(T),n.bindBuffer(34962,T),n.bufferData(34962,m,35044),n.enableVertexAttribArray(r),n.vertexAttribPointer(r,s,5126,!1,0,0),m}var Ct=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),We=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Oe(n,e,t=We,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r,bin:s}=e,l=[],y=ve(r),u=[];if(Array.isArray(r.nodes))for(let x=0;x<r.nodes.length;x++){let b=r.nodes[x];b.mesh!==void 0&&r.meshes&&r.meshes[b.mesh]&&u.push({node:b,nodeIdx:x,meshIdx:b.mesh})}let a=u.length>0?u:(r.meshes||[]).map((x,b)=>({node:x,nodeIdx:-1,meshIdx:b})),o=[];if(Array.isArray(e.lights)&&e.lights.length>0)o.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let x=r.extensions.KHR_lights_punctual.lights;for(let b of x){let A=b.type==="directional"?"directional":b.type==="point"?"point":"ambient";o.push({type:A,color:b.color||[1,1,1],intensity:b.intensity!==void 0?b.intensity:1})}}if(o.length===0&&(o.push({type:"ambient",color:[1,1,1],intensity:.35}),o.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),a.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${a.length}`);let m=[];if(r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let x=0;x<r.textures.length;x++){let b=r.textures[x],A=r.images[b.source];if(A){let P=n.createTexture();if(n.bindTexture(3553,P),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),A.bufferView!==void 0){let I=r.bufferViews[A.bufferView],g=s.slice(I.byteOffset||0,(I.byteOffset||0)+I.byteLength),d=new Blob([g],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(d).then(U=>{n.bindTexture(3553,P),n.texImage2D(3553,0,6408,6408,5121,U),n.generateMipmap(3553),i?.()}).catch(()=>{})}else if(A.uri){let I=yt(A.uri);if(I){let g=new Image;g.crossOrigin="anonymous",g.referrerPolicy="no-referrer",g.onload=()=>{n.bindTexture(3553,P),n.texImage2D(3553,0,6408,6408,5121,g),n.generateMipmap(3553),i?.()},g.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}m.push(P)}else m.push(null)}}let T=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],h=0,E=0;for(let x=0;x<a.length;x++){let b=a[x],A=r.meshes[b.meshIdx],P=b.nodeIdx>=0?y[b.nodeIdx]:q(),I=new Float32Array(9);te(I,P);let g={name:b.node.name||A.name||`Mesh_${b.meshIdx}`,nodeIndex:b.nodeIdx,transform:P,normalMatrix:I,primitives:[],extras:b.node.extras||A.extras};for(let d of A.primitives||[]){if(d.extensions?.KHR_draco_mesh_compression){let X=me("draco");X&&X.decodePrimitive(r,d,s)}let U=[],S=n.createVertexArray();n.bindVertexArray(S);let V=r.accessors[d.attributes.POSITION],G=Number(V?.count??0);if(!Number.isFinite(G)||G<0||h+G>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(h+=G,V?.min&&V?.max)for(let X=0;X<3;X++){let Q=P[12+X],ue=P[12+X];for(let ne=0;ne<3;ne++){let de=P[ne*4+X]*V.min[ne],pe=P[ne*4+X]*V.max[ne];Q+=de<pe?de:pe,ue+=de>pe?de:pe}Q<T[X]&&(T[X]=Q),ue>M[X]&&(M[X]=ue)}let L=Ee(n,r,s,d.attributes.POSITION,0,3,U);Ee(n,r,s,d.attributes.NORMAL,1,3,U),Ee(n,r,s,d.attributes.TEXCOORD_0,2,2,U);let _=0,R=5123,k=null;if(d.indices!==void 0){let X=r.accessors[d.indices],ue=(r.bufferViews[X.bufferView].byteOffset||0)+(X.byteOffset||0);if(_=Number(X.count??0),!Number.isFinite(_)||_<0||E+_>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);E+=_,R=X.componentType===5125?5125||5125:5123||5123;let ne=n.createBuffer();U.push(ne),n.bindBuffer(34963,ne),X.componentType===5125?(k=new Uint32Array(s,ue,X.count),n.bufferData(34963,k,35044)):(k=new Uint16Array(s,ue,X.count),n.bufferData(34963,k,35044))}else _=V.count;let N={};for(let X of Y)if(X.onBuildPrimitiveVAO){let Q=X.onBuildPrimitiveVAO(n,S,d,r,s);Q&&(N[X.name]=Q)}n.bindVertexArray(null);let O=r.materials&&d.material!==void 0?r.materials[d.material]:null,B=$e(),H=ze,W=B.fs,$=!1;for(let X of Y)if(X.onResolveShader){let Q=X.onResolveShader(d,O,H,W);Q&&(H=Q.vs,W=Q.fs,$=!0)}let j=$?Pe(n,H,W):null,ie=j?Se(n,j,B.uniforms):null,K=O?.pbrMetallicRoughness,re=K?.baseColorFactor||[.8,.8,.8,1],se=K?.metallicFactor??.1,ae=K?.roughnessFactor??.5,Z=O?.extensions?.KHR_materials_clearcoat,oe=Z?Z.clearcoatFactor??1:0,ce=Math.max(.04,Z?.clearcoatRoughnessFactor??.04),le=K?.baseColorTexture!==void 0&&m[K.baseColorTexture.index]?m[K.baseColorTexture.index]:null,et=K?.metallicRoughnessTexture!==void 0&&m[K.metallicRoughnessTexture.index]?m[K.metallicRoughnessTexture.index]:null,tt=O?.normalTexture!==void 0&&m[O.normalTexture.index]?m[O.normalTexture.index]:null,nt=O?.normalTexture?.scale??1,it=O?.occlusionTexture!==void 0&&m[O.occlusionTexture.index]?m[O.occlusionTexture.index]:null,rt=O?.occlusionTexture?.strength??1,st=!!(O?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive);g.primitives.push({vao:S,indexCount:_,indexType:R,baseColor:re,metallic:se,roughness:ae,clearcoat:oe,clearcoatRoughness:ce,positions:L,indices:k,texture:le,metallicRoughnessTexture:et,normalTexture:tt,occlusionTexture:it,normalScale:nt,occlusionStrength:rt,buffers:U,materialIndex:d.material,pluginData:N,customProgram:j,customUniforms:ie,isTransmissive:st})}l.push(g)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let D=[(T[0]+M[0])/2,(T[1]+M[1])/2,(T[2]+M[2])/2],F=M[0]-T[0],C=M[1]-T[1],f=M[2]-T[2],v=Math.max(Math.hypot(F,C,f)/2,.5),p=[T[0],T[1],T[2]],w=[M[0],M[1],M[2]],c=e.animations;if(!c){for(let x of Y)if(x.onParseGLB?.(e),e.animations){c=e.animations;break}}return c||(c=[]),{meshes:l,bounds:{center:D,radius:v,min:p,max:w},lights:o,animations:c,worldMatrices:y}}var xe=class{constructor(e,t,i){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=q();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=q();this.viewMatrix=q();this.modelMatrix=q();this.mvpMatrix=q();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:q(),rawValueToMeters:.001,format:0};this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let l=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!l:l&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let y=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!y)throw new Error("WebGL2 not supported");this.gl=y;let u=$e();this.renderProg=Pe(y,ze,u.fs),this.pickProg=Pe(y,bt,gt),this.uRender=Se(y,this.renderProg,u.uniforms),this.uPick=Se(y,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){ft(e,t)}static getDecoder(e){return me(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:l,worldMatrices:y}=Oe(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=l||[],this.worldMatrices=y||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let a of e.gltf.nodes)this.initialNodeTransforms.push({t:a.translation?[a.translation[0],a.translation[1],a.translation[2]]:[0,0,0],r:a.rotation?[a.rotation[0],a.rotation[1],a.rotation[2],a.rotation[3]]:[0,0,0,1],s:a.scale?[a.scale[0],a.scale[1],a.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let a of Y)a.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(He(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(he(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=he(e),{meshes:r}=Oe(this.gl,i,We,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],te(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),te(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],l=[],y=[];for(let u of this.lights){let a=u.color||[1,1,1],o=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")i=[a[0]*o,a[1]*o,a[2]*o];else if(u.type==="directional"&&r.length<6){let m=u.direction||[.5,1,.8];r.push(m[0],m[1],m[2]),s.push(a[0]*o,a[1]*o,a[2]*o)}else if(u.type==="point"&&l.length<6){let m=u.position||[0,0,0];l.push(m[0],m[1],m[2]),y.push(a[0]*o,a[1]*o,a[2]*o)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,l.length/3),l.length>0&&(t.uniform3fv(e.uPointLightPos,l),t.uniform3fv(e.uPointLightColor,y)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Y)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Y)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(o=>o.primitives.filter(m=>m.materialIndex===i||e.length===1&&m.materialIndex===void 0)),s=r[0],l=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],y=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:l,metallicFactor:y,roughnessFactor:u,setBaseColorFactor:o=>{let m=[o[0],o[1],o[2],o[3]??1];a.baseColorFactor=m,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=m);for(let T of r)T.baseColor=m;this.render()},setMetallicFactor:o=>{a.metallicFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=o);for(let m of r)m.metallic=o;this.render()},setRoughnessFactor:o=>{a.roughnessFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=o);for(let m of r)m.roughness=o;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}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 Y)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=q();J(i,this.projMatrix,this.viewMatrix);let[r,s,l]=e,y=t?t[0]:0,u=t?t[1]:0,a=t?t[2]:0,o=this.modelRootMatrix;o&&(r=o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],s=o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],l=o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14],t&&(y=o[0]*t[0]+o[4]*t[1]+o[8]*t[2],u=o[1]*t[0]+o[5]*t[1]+o[9]*t[2],a=o[2]*t[0]+o[6]*t[1]+o[10]*t[2]));let m=i[0]*r+i[4]*s+i[8]*l+i[12],T=i[1]*r+i[5]*s+i[9]*l+i[13],M=i[2]*r+i[6]*s+i[10]*l+i[14],h=i[3]*r+i[7]*s+i[11]*l+i[15];if(h<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=m/h,D=T/h,F=M/h,C=this.canvas.getBoundingClientRect(),f=C.width||this.canvas.clientWidth||this.canvas.width||300,v=C.height||this.canvas.clientHeight||this.canvas.height||150,p=(E*.5+.5)*f,w=(-D*.5+.5)*v,c=E>=-1.1&&E<=1.1&&D>=-1.1&&D<=1.1&&F>=-1&&F<=1;if(c&&t){let x=this.customTarget||this.bounds.center,b=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=x[1]+this.currDistance*Math.sin(this.currPhi),P=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),I=[r-b,s-A,l-P];y*I[0]+u*I[1]+a*I[2]>.05&&(c=!1)}return{x:p,y:w,z:F,visible:c}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let i=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},r=t.clientX-i.x,s=t.clientY-i.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(r,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],y=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],a=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-r*l[0]+s*y[0])*a,u[1]+=(-r*l[1]+s*y[1])*a,u[2]+=(-r*l[2]+s*y[2])*a,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-r*.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 i=e.getBoundingClientRect(),r=Math.floor((t.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((t.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(r,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 i=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let i=t.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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 i=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=i,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,l=i.height||300,y=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),u=r.height>0?Math.floor((t-r.top)*(l/r.height)):Math.floor(t);return this.performMeshPick(y,u,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),l=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let y=q();J(y,this.projMatrix,this.viewMatrix);let u=[],a=Math.max(0,Math.min(s-1,e)),o=Math.max(0,Math.min(l-1,l-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==l)&&this.resizePickingFbo(s,l),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,l),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16384|256),r.useProgram(this.pickProg);for(let c=0;c<this.meshes.length;c++){let x=this.meshes[c];if(x.visible===!1||x.isPluginMesh)continue;let b=c+1,A=(b&255)/255,P=(b>>8&255)/255,I=(b>>16&255)/255;r.uniform4f(this.uPick.uColorId,A,P,I,1),J(this.modelMatrix,this.modelRootMatrix,x.transform),J(this.mvpMatrix,y,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let g of x.primitives)r.bindVertexArray(g.vao),r.drawElements(4,g.indexCount,g.indexType,0)}let p=new Uint8Array(4);r.readPixels(a,o,1,1,6408,5121,p),r.bindFramebuffer(36160,null);let w=p[0]+(p[1]<<8)+(p[2]<<16);w>0&&w<=this.meshes.length&&(u=[this.meshes[w-1]])}u.length===0&&(u=this.meshes.filter(p=>p.visible!==!1));let m=null,T=1/0,M=[0,0,0],h=[0,1,0],E=this.customTarget||this.bounds.center,D=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),F=E[1]+this.currDistance*Math.sin(this.currPhi),C=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let p of u){J(this.modelMatrix,this.modelRootMatrix,p.transform),J(this.mvpMatrix,y,this.modelMatrix);let w=q();if(!Be(w,this.mvpMatrix))continue;let c=(a+.5)/s*2-1,x=(o+.5)/l*2-1,b=[0,0,0],A=[0,0,0];De(b,c,x,-1,w),De(A,c,x,1,w);let P=A[0]-b[0],I=A[1]-b[1],g=A[2]-b[2],d=Math.hypot(P,I,g)||1,U=P/d,S=I/d,V=g/d,G={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((_=>{for(let R of p.primitives){if(!R.positions)continue;let k=R.positions,N=R.indices,O=Math.floor(N?N.length/3:k.length/9);for(let B=0;B<O;B++){let H=N?N[B*3]:B*3,W=N?N[B*3+1]:B*3+1,$=N?N[B*3+2]:B*3+2;Ne(b[0],b[1],b[2],U,S,V,k[H*3],k[H*3+1],k[H*3+2],k[W*3],k[W*3+1],k[W*3+2],k[$*3],k[$*3+1],k[$*3+2],G,_)}}})(1e-4),isFinite(G.distance)){let _=G.point[0],R=G.point[1],k=G.point[2],N=this.modelMatrix,O=N[0]*_+N[4]*R+N[8]*k+N[12],B=N[1]*_+N[5]*R+N[9]*k+N[13],H=N[2]*_+N[6]*R+N[10]*k+N[14],W=O-D,$=B-F,j=H-C,ie=Math.hypot(W,$,j);if(ie<T){te(this.normalMatrix,this.modelMatrix);let K=this.normalMatrix,re=G.normal[0],se=G.normal[1],ae=G.normal[2],Z=K[0]*re+K[3]*se+K[6]*ae,oe=K[1]*re+K[4]*se+K[7]*ae,ce=K[2]*re+K[5]*se+K[8]*ae,le=Math.hypot(Z,oe,ce)||1;Z/=le,oe/=le,ce/=le,Z*W+oe*$+ce*j>0&&(Z=-Z,oe=-oe,ce=-ce),m=p,T=Math.round(ie*1e3)/1e3,M=[Math.round(O*1e3)/1e3,Math.round(B*1e3)/1e3,Math.round(H*1e3)/1e3],h=[Math.round(Z*1e3)/1e3,Math.round(oe*1e3)/1e3,Math.round(ce*1e3)/1e3]}}}if(!m)return null;let v={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:T,hitPoint:M,normal:h,screenX:e,screenY:t};if(i){for(let p of Y)p.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,l=r?Math.max(1,t-i):i,y=(s+.5)/l*2-1;return Math.floor((y*.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);ge(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center,r=i[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=i[1]+this.currDistance*Math.sin(this.currPhi),l=i[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);ye(this.viewMatrix,[r,s,l],i,[0,1,0]),J(this.mvpMatrix,this.projMatrix,this.viewMatrix),te(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of Y)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of Y)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let l of Y)l.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let l of Y)l.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let l={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(l),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:l}))}}renderXRView(e,t,i,r,s=!0,l=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let y=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,o=a?[a.x,a.y,a.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:y,projMatrix:u,eyePos:o,viewport:r,eye:e?.eye||"none",clear:l>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),w=Math.max(1,Math.floor(v*.5)),c=Math.max(1,v-w),x=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),b=this.customTarget||this.bounds.center,A=b[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=b[1]+this.currDistance*Math.sin(this.currPhi),I=b[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=Math.cos(this.currTheta),d=-Math.sin(this.currTheta),U=.032,S=q(),V=q(),G=[A-g*U,P,I-d*U],L=[b[0]-g*U*.25,b[1],b[2]-d*U*.25];ge(S,this.fov,w/p,.1,x),ye(V,G,L,[0,1,0]);let _=q(),R=q(),k=[A+g*U,P,I+d*U],N=[b[0]+g*U*.25,b[1],b[2]+d*U*.25];ge(_,this.fov,c/p,.1,x),ye(R,k,N,[0,1,0]),this.render({viewMatrix:V,projMatrix:S,eyePos:G,viewport:[0,0,w,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:R,projMatrix:_,eyePos:k,viewport:[w,0,c,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,i=0,r=0,s=this.canvas.width,l=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],l=e.viewport[3],t.viewport(i,r,s,l)):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 y=q(),u=e?.viewMatrix??this.viewMatrix;J(y,e?.projMatrix??this.projMatrix,u);let a=ee().xrDepthShader,o=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,T=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),M=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),h=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of Y)v.onBeforeDrawScene?.(this,t,y,[T,M,h],o);let E=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&E===0)return;let D=e?.eye||"none",F=!1,C=E>0?[...this.backdropMeshes,...this.meshes]:this.meshes,f=v=>{for(let p=0;p<C.length;p++){let w=C[p];if(w.visible===!1)continue;let c=this.selectedMeshName!==""&&w.name===this.selectedMeshName;p<E||w.worldSpace===!0||w.name==="__xr_reticle__"?this.modelMatrix.set(w.transform):J(this.modelMatrix,this.modelRootMatrix,w.transform),J(this.mvpMatrix,y,this.modelMatrix),te(w.normalMatrix,this.modelMatrix);let x=w.extras?.xr?.stereo||w.userData?.xr?.stereo,b=0,A=0,P=1,I=1;x==="sbs"?(P=.5,b=D==="right"?.5:0):x==="ou"&&(I=.5,A=D==="right"?.5:0);for(let g of w.primitives){let d=!!g.isTransmissive;if(!v&&d){F=!0;continue}if(v&&!d)continue;let U=g.customProgram||this.renderProg,S=g.customUniforms||this.uRender;t.useProgram(U),t.uniform1i(S.uToneMapping,o),t.uniform1f(S.uEnvIntensity,this.envIntensity),t.uniform3f(S.uCameraPos,T,M,h),t.uniform1f(S.uEmissive,c?1:0),t.uniformMatrix4fv(S.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(S.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(S.uNormalMatrix,!1,w.normalMatrix),S.uUvTransform&&t.uniform4f(S.uUvTransform,b,A,P,I),S.uViewportSize&&t.uniform2f(S.uViewportSize,Math.max(1,s),Math.max(1,l)),a?.bind(t,S,this.xrDepthState,u,[i,r,Math.max(1,s),Math.max(1,l)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(S.uEnvironmentMap,4),t.uniform1i(S.uHasEnvironmentMap,1)):t.uniform1i(S.uHasEnvironmentMap,0),this.bindLights(S),S.uSectionEnabled&&t.uniform1i(S.uSectionEnabled,0);for(let V of Y)V.onBeforeDrawPrimitive?.(t,U,g,w,this.worldMatrices||[],this.gltf);t.uniform4fv(S.uBaseColor,g.baseColor),t.uniform1f(S.uMetallic,g.metallic),t.uniform1f(S.uRoughness,g.roughness),S.uClearcoat&&t.uniform2f(S.uClearcoat,g.clearcoat??0,g.clearcoatRoughness??.04),g.texture?(t.activeTexture(33984),t.bindTexture(3553,g.texture),t.uniform1i(S.uBaseColorTexture,0),t.uniform1i(S.uHasTexture,1)):t.uniform1i(S.uHasTexture,0),g.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,g.metallicRoughnessTexture),t.uniform1i(S.uMetallicRoughnessTexture,1),t.uniform1i(S.uHasMetallicRoughnessTexture,1)):t.uniform1i(S.uHasMetallicRoughnessTexture,0),g.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,g.normalTexture),t.uniform1i(S.uNormalTexture,2),t.uniform1i(S.uHasNormalTexture,1),t.uniform1f(S.uNormalScale,g.normalScale)):t.uniform1i(S.uHasNormalTexture,0),g.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,g.occlusionTexture),t.uniform1i(S.uOcclusionTexture,3),t.uniform1i(S.uHasOcclusionTexture,1),t.uniform1f(S.uOcclusionStrength,g.occlusionStrength)):t.uniform1i(S.uHasOcclusionTexture,0),t.bindVertexArray(g.vao),t.drawElements(4,g.indexCount,g.indexType,0)}}};if(f(!1),F){for(let v of Y)v.onBeforeTransmissivePass?.(t,this);f(!0)}for(let v of Y)v.onAfterRender?.(t,this,y)}disposeMeshListGpuResources(e){let t=this.gl;for(let i of e)for(let r of i.primitives){if(r.vao&&t.deleteVertexArray(r.vao),r.buffers)for(let s of r.buffers)t.deleteBuffer(s);r.texture&&t.deleteTexture(r.texture),r.metallicRoughnessTexture&&t.deleteTexture(r.metallicRoughnessTexture),r.normalTexture&&t.deleteTexture(r.normalTexture),r.occlusionTexture&&t.deleteTexture(r.occlusionTexture),r.customProgram&&t.deleteProgram(r.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Y)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()}};xe.registerPlugin=Ie,xe.getRegisteredPlugins=_e;function vt(n){return n+3&-4}function xt(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 Ke(n,e){n.updateMatrixWorld(!0);let t=[],i=0,r=[],s=[],l=[],y=[],u=new Set,a=[],o=[],m=new Map,T=[];function M(c,x){let b=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),A=vt(b.byteLength),P=new Uint8Array(A);P.set(b),t.push(P);let I=r.length;return r.push({buffer:0,byteOffset:i,byteLength:b.byteLength,target:x}),i+=A,I}function h(c,x,b,A,P,I,g){let d=M(c,b),U=s.length,S={bufferView:d,byteOffset:0,componentType:A,count:P,type:x};return I&&(S.min=I),g&&(S.max=g),s.push(S),U}n.traverse(c=>{(c.isLight||c.color&&c.intensity!==void 0)&&T.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:[c.position.x,c.position.y,c.position.z]})});let E=[];function D(c){let x={name:c.name||""},b=c.position,A=c.quaternion,P=c.scale;if((b.x||b.y||b.z)&&(x.translation=[b.x,b.y,b.z]),(A.x||A.y||A.z||A.w!==1)&&(x.rotation=[A.x,A.y,A.z,A.w]),(P.x!==1||P.y!==1||P.z!==1)&&(x.scale=[P.x,P.y,P.z]),c.userData&&Object.keys(c.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(c.userData,(g,d)=>{if(!(g==="__proto__"||g==="prototype"||g==="constructor"))return typeof d=="function"?void 0:d})),c.userData.xr)){let g=xt(c.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:g,ANDROID_xr_scenecore:g},ee().xrTraitSerializer?.gltfNode(x,c.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(c.geometry){let g=c.geometry,d=g.attributes.position;if(d&&d.count>0){let U=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let _=0;_<d.count;_++){let R=d.getX(_),k=d.getY(_),N=d.getZ(_);R<U[0]&&(U[0]=R),R>S[0]&&(S[0]=R),k<U[1]&&(U[1]=k),k>S[1]&&(S[1]=k),N<U[2]&&(U[2]=N),N>S[2]&&(S[2]=N)}let G={attributes:{POSITION:h(d.array,"VEC3",34962,5126,d.count,U,S)}};if(g.attributes.normal&&(G.attributes.NORMAL=h(g.attributes.normal.array,"VEC3",34962,5126,g.attributes.normal.count)),g.attributes.uv&&(G.attributes.TEXCOORD_0=h(g.attributes.uv.array,"VEC2",34962,5126,g.attributes.uv.count)),g.index){let _=g.index.array instanceof Uint32Array;G.indices=h(g.index.array,"SCALAR",34963,_?5125:5123,g.index.count)}if(c.material){let _=m.get(c.material);if(_===void 0){_=o.length,m.set(c.material,_);let R=c.material,k={name:R.name||"",pbrMetallicRoughness:{baseColorFactor:[R.color.r,R.color.g,R.color.b,R.opacity],metallicFactor:R.metalness,roughnessFactor:R.roughness},doubleSided:R.side===2||R.doubleSided};if(R.emissive&&(R.emissive.r>0||R.emissive.g>0||R.emissive.b>0)){let O=R.emissiveIntensity??1;k.emissiveFactor=[R.emissive.r*O,R.emissive.g*O,R.emissive.b*O]}let N={};R.clearcoat>0&&(N.KHR_materials_clearcoat={clearcoatFactor:R.clearcoat,clearcoatRoughnessFactor:R.clearcoatRoughness||0}),R.sheen>0&&(N.KHR_materials_sheen={sheenColorFactor:R.sheenColor?[R.sheenColor.r,R.sheenColor.g,R.sheenColor.b]:[1,1,1],sheenRoughnessFactor:R.sheenRoughness||0}),R.transmission>0&&(N.KHR_materials_transmission={transmissionFactor:R.transmission}),R.thickness>0&&(N.KHR_materials_volume={thicknessFactor:R.thickness,attenuationDistance:R.attenuationDistance??1/0,attenuationColor:R.attenuationColor?[R.attenuationColor.r,R.attenuationColor.g,R.attenuationColor.b]:[1,1,1]}),R.ior!==void 0&&R.ior!==1.5&&(N.KHR_materials_ior={ior:R.ior}),R.dispersion>0&&(N.KHR_materials_dispersion={dispersion:R.dispersion}),R.iridescence>0&&(N.KHR_materials_iridescence={iridescenceFactor:R.iridescence,iridescenceIor:R.iridescenceIOR??1.3}),Object.keys(N).length>0&&(k.extensions=N),o.push(k)}G.material=_}let L=l.length;l.push({primitives:[G],name:c.name,...x.extras?{extras:x.extras}:{}}),x.mesh=L}}let I=y.length;if(y.push(x),a.push(c),c.children.length>0){x.children=[];for(let g of c.children)x.children.push(D(g))}return I}for(let c of n.children)E.push(D(c));let F=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),C=[];if(typeof F=="function"&&a.length>0){let c=e?.duration??4,x=e?.fps??15,b=Math.max(2,Math.round(c*x)+1),A=new Float32Array(b),P=a.map(L=>({px:L.position.x,py:L.position.y,pz:L.position.z,qx:L.quaternion.x,qy:L.quaternion.y,qz:L.quaternion.z,qw:L.quaternion.w,sx:L.scale.x,sy:L.scale.y,sz:L.scale.z})),I=a.map(()=>new Float32Array(b*3)),g=a.map(()=>new Float32Array(b*4)),d=a.map(()=>new Float32Array(b*3));for(let L=0;L<b;L++){let _=L/(b-1)*c;A[L]=_;try{F(_)}catch{}for(let R=0;R<a.length;R++){let k=a[R];I[R][L*3]=k.position.x,I[R][L*3+1]=k.position.y,I[R][L*3+2]=k.position.z,g[R][L*4]=k.quaternion.x,g[R][L*4+1]=k.quaternion.y,g[R][L*4+2]=k.quaternion.z,g[R][L*4+3]=k.quaternion.w,d[R][L*3]=k.scale.x,d[R][L*3+1]=k.scale.y,d[R][L*3+2]=k.scale.z}}for(let L=0;L<a.length;L++){let _=a[L],R=P[L];_.position.set(R.px,R.py,R.pz),_.quaternion.set(R.qx,R.qy,R.qz,R.qw),_.scale.set(R.sx,R.sy,R.sz)}n.updateMatrixWorld(!0);let U=null,S=()=>(U===null&&(U=h(A,"SCALAR",0,5126,b,[0],[c])),U),V=[],G=[];for(let L=0;L<a.length;L++){let _=P[L],R=!1,k=!1,N=!1;for(let O=0;O<b;O++)(Math.abs(I[L][O*3]-_.px)>1e-4||Math.abs(I[L][O*3+1]-_.py)>1e-4||Math.abs(I[L][O*3+2]-_.pz)>1e-4)&&(R=!0),(Math.abs(g[L][O*4]-_.qx)>1e-4||Math.abs(g[L][O*4+1]-_.qy)>1e-4||Math.abs(g[L][O*4+2]-_.qz)>1e-4||Math.abs(g[L][O*4+3]-_.qw)>1e-4)&&(k=!0),(Math.abs(d[L][O*3]-_.sx)>1e-4||Math.abs(d[L][O*3+1]-_.sy)>1e-4||Math.abs(d[L][O*3+2]-_.sz)>1e-4)&&(N=!0);if(R){let O=h(I[L],"VEC3",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"translation"}})}if(k){let O=h(g[L],"VEC4",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"rotation"}})}if(N){let O=h(d[L],"VEC3",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"scale"}})}}G.length>0&&C.push({name:"ProceduralLoop",samplers:V,channels:G})}let f=we(y,l,n.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:E}],scene:0,nodes:y,meshes:l,materials:o,accessors:s,bufferViews:r,buffers:[{byteLength:i}],...C.length>0?{animations:C}:{},...f||u.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...u]}:{},...f?{extensions:{KHR_interactivity:f}}:{}},p=new Uint8Array(i),w=0;for(let c of t)p.set(c,w),w+=c.byteLength;return{gltf:v,bin:p.buffer,lights:T,environmentIntensity:n.environmentIntensity}}function fe(n){return new TextEncoder().encode(n)}function Tt(n,e){let{gltf:t,bin:i}=Ke(n,e),r=JSON.stringify(t),s=fe(r),l=(4-s.byteLength%4)%4,y=s.byteLength+l,u=20+y+8+i.byteLength,a=new Uint8Array(u),o=new DataView(a.buffer);o.setUint32(0,1179937895,!0),o.setUint32(4,2,!0),o.setUint32(8,u,!0),o.setUint32(12,y,!0),o.setUint32(16,1313821514,!0),a.set(s,20);for(let T=0;T<l;T++)a[20+s.byteLength+T]=32;let m=20+y;return o.setUint32(m,i.byteLength,!0),o.setUint32(m+4,5130562,!0),a.set(new Uint8Array(i),m+8),a}function qe(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(i=>{if(i.geometry){let r=i.geometry,s=r.attributes.position;if(!s||s.count===0)return;let l=s.count,y=new Float32Array(l*3),u=i.matrixWorld.elements;for(let c=0;c<l;c++){let x=s.getX(c),b=s.getY(c),A=s.getZ(c);y[c*3]=u[0]*x+u[4]*b+u[8]*A+u[12],y[c*3+1]=u[1]*x+u[5]*b+u[9]*A+u[13],y[c*3+2]=u[2]*x+u[6]*b+u[10]*A+u[14]}let a;if(r.attributes.normal){let c=r.attributes.normal;a=new Float32Array(l*3);let x=new Float32Array(9);te(x,u);for(let b=0;b<l;b++){let A=c.getX(b),P=c.getY(b),I=c.getZ(b),g=x[0]*A+x[3]*P+x[6]*I,d=x[1]*A+x[4]*P+x[7]*I,U=x[2]*A+x[5]*P+x[8]*I,S=Math.hypot(g,d,U)||1;a[b*3]=g/S,a[b*3+1]=d/S,a[b*3+2]=U/S}}let o;if(r.attributes.uv){let c=r.attributes.uv;o=new Float32Array(l*2);for(let x=0;x<l;x++)o[x*2]=c.getX(x),o[x*2+1]=c.getY(x)}let m;if(r.index)m=r.index.array;else{m=l>65535?new Uint32Array(l):new Uint16Array(l);for(let c=0;c<l;c++)m[c]=c}let T="DefaultMaterial",M=[.8,.8,.8],h=.5,E=.1,D=0,F=0,C=1.5,f=1,v=[0,0,0];if(i.material){let c=i.material;T=c.name||`Material_${t.length}`,c.color&&(M=[c.color.r,c.color.g,c.color.b]),typeof c.roughness=="number"&&(h=c.roughness),typeof c.metalness=="number"&&(E=c.metalness),typeof c.clearcoat=="number"&&(D=c.clearcoat),typeof c.clearcoatRoughness=="number"&&(F=c.clearcoatRoughness),typeof c.ior=="number"&&(C=c.ior);let x=typeof c.opacity=="number"?c.opacity:1,b=typeof c.transmission=="number"?c.transmission:0;if(f=x*(1-b),c.emissive&&(c.emissive.r>0||c.emissive.g>0||c.emissive.b>0)){let A=c.emissiveIntensity??1;v=[c.emissive.r*A,c.emissive.g*A,c.emissive.b*A]}}let p,w=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 w=="function"){let c=e?.duration??4,x=e?.fps??4,b=Math.max(2,Math.round(c*x)+1),A=[],P=[],I=[],g=[],d=[i.position.x,i.position.y,i.position.z],U=[i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w],S=[i.scale.x,i.scale.y,i.scale.z],V=!1;for(let G=0;G<b;G++){let L=G/(b-1)*c;A.push(L);try{w(L)}catch{}P.push([i.position.x,i.position.y,i.position.z]),I.push([i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w]),g.push([i.scale.x,i.scale.y,i.scale.z]),(Math.abs(i.position.x-d[0])>1e-4||Math.abs(i.position.y-d[1])>1e-4||Math.abs(i.position.z-d[2])>1e-4||Math.abs(i.quaternion.x-U[0])>1e-4||Math.abs(i.quaternion.y-U[1])>1e-4||Math.abs(i.quaternion.z-U[2])>1e-4||Math.abs(i.quaternion.w-U[3])>1e-4||Math.abs(i.scale.x-S[0])>1e-4)&&(V=!0)}i.position.set(d[0],d[1],d[2]),i.quaternion.set(U[0],U[1],U[2],U[3]),i.scale.set(S[0],S[1],S[2]),V&&(p={times:A,translations:P,rotations:I,scales:g})}t.push({name:i.name||`Mesh_${t.length}`,positions:y,indices:m,normals:a,uvs:o,materialName:T,color:M,roughness:h,metallic:E,clearcoat:D,clearcoatRoughness:F,ior:C,opacity:f,emissiveColor:v,xrTraits:i.userData?.xr,timeSamples:p})}}),t}function Le(n){let e=[],t=n.gltf,i=n.bin,r=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=t.accessors||[],l=t.bufferViews||[],y=t.materials||[],u=t.meshes||[],a=t.nodes||[];function o(M){let h=s[M];if(!h)throw new Error(`Accessor ${M} not found`);let E=l[h.bufferView||0],D=(E.byteOffset||0)+(h.byteOffset||0),F=E.byteLength||0,C=r.slice(D,D+F);return{acc:h,buffer:C}}let m=new Map;if(a.length>0){let M=ve(t);for(let h=0;h<M.length;h++)m.set(h,M[h])}function T(M,h,E,D){let F=u[M];if(!F)return;let C=new Float32Array(9);te(C,h);for(let f=0;f<(F.primitives||[]).length;f++){let v=F.primitives[f],p=v.attributes?.POSITION;if(p===void 0)continue;let{acc:w,buffer:c}=o(p),x=new Float32Array(c,0,w.count*3),b=new Float32Array(x.length);for(let B=0;B<w.count;B++){let H=x[B*3],W=x[B*3+1],$=x[B*3+2];b[B*3]=h[0]*H+h[4]*W+h[8]*$+h[12],b[B*3+1]=h[1]*H+h[5]*W+h[9]*$+h[13],b[B*3+2]=h[2]*H+h[6]*W+h[10]*$+h[14]}let A,P=v.attributes?.NORMAL;if(P!==void 0){let{acc:B,buffer:H}=o(P),W=new Float32Array(H,0,B.count*3);A=new Float32Array(W.length);for(let $=0;$<B.count;$++){let j=W[$*3],ie=W[$*3+1],K=W[$*3+2],re=C[0]*j+C[3]*ie+C[6]*K,se=C[1]*j+C[4]*ie+C[7]*K,ae=C[2]*j+C[5]*ie+C[8]*K,Z=Math.hypot(re,se,ae)||1;A[$*3]=re/Z,A[$*3+1]=se/Z,A[$*3+2]=ae/Z}}let I,g=v.attributes?.TEXCOORD_0;if(g!==void 0){let{acc:B,buffer:H}=o(g);I=new Float32Array(H,0,B.count*2)}let d;if(v.indices!==void 0){let{acc:B,buffer:H}=o(v.indices);B.componentType===5125?d=new Uint32Array(H,0,B.count):d=new Uint16Array(H,0,B.count);let W=w.count;for(let $ of d)if($>=W)throw new Error(`SecurityError: Index buffer value (${$}) out of vertex bounds [0, ${W}).`)}else{let B=w.count;d=B>65535?new Uint32Array(B):new Uint16Array(B);for(let H=0;H<B;H++)d[H]=H}let U="DefaultMaterial",S=[.8,.8,.8],V=.5,G=.1,L=0,_=0,R=1.5,k=1,N=[0,0,0];if(v.material!==void 0&&y[v.material]){let B=y[v.material];U=B.name||`Material_${v.material}`;let H=B.pbrMetallicRoughness||{},W=1;Array.isArray(H.baseColorFactor)&&(S=[H.baseColorFactor[0],H.baseColorFactor[1],H.baseColorFactor[2]],typeof H.baseColorFactor[3]=="number"&&(W=H.baseColorFactor[3])),typeof H.roughnessFactor=="number"&&(V=H.roughnessFactor),typeof H.metallicFactor=="number"&&(G=H.metallicFactor),Array.isArray(B.emissiveFactor)&&B.emissiveFactor.length>=3&&(N=[B.emissiveFactor[0],B.emissiveFactor[1],B.emissiveFactor[2]]);let $=B.extensions||{};$.KHR_materials_clearcoat&&(L=$.KHR_materials_clearcoat.clearcoatFactor??0,_=$.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),$.KHR_materials_ior&&typeof $.KHR_materials_ior.ior=="number"&&(R=$.KHR_materials_ior.ior);let j=$.KHR_materials_transmission?.transmissionFactor??0;k=W*(1-j)}let O=(F.primitives||[]).length>1?`${E}_p${f}`:E;e.push({name:O,positions:b,indices:d,normals:A,uvs:I,materialName:U,color:S,roughness:V,metallic:G,clearcoat:L,clearcoatRoughness:_,ior:R,opacity:k,emissiveColor:N,xrTraits:D?.xr||F.extras?.xr})}}if(a.length>0)for(let M=0;M<a.length;M++){let h=a[M];if(h.mesh!==void 0&&h.mesh<u.length){let E=m.get(M)||q(),D=h.name||u[h.mesh].name||`Node_${M}`;T(h.mesh,E,D,h.extras)}}else{let M=q();for(let h=0;h<u.length;h++){let E=u[h].name||`Mesh_${h}`;T(h,M,E,u[h].extras)}}return e}function Me(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 Fe(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function z(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 Xe(n){let e=n.length/3,t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*3])}, ${z(n[i*3+1])}, ${z(n[i*3+2])})`;return t.join(", ")}function Mt(n,e){let t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*2])}, ${z(1-n[i*2+1])})`;return t.join(", ")}function Rt(n){return Array.from(n).join(", ")}function Re(n){let e=new Map;for(let u of n){let a=Me(u.materialName,"DefaultMaterial");e.has(a)||e.set(a,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,i=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let a=u.timeSamples.times[u.timeSamples.times.length-1];a>t&&(t=a)}u.xrTraits?.anchor&&!i&&(i=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let r="";t>0&&(r=`startTimeCode = 0
|
|
218
209
|
endTimeCode = ${z(t)}
|
|
219
210
|
timeCodesPerSecond = 1.0
|
|
220
211
|
`);let s="";i&&(s=`uniform token preliminary:anchoring:type = "plane"
|
|
221
212
|
uniform token preliminary:planeAnchoring:alignment = "${i}"
|
|
222
|
-
`);let
|
|
213
|
+
`);let l=`#usda 1.0
|
|
223
214
|
(
|
|
224
215
|
defaultPrim = "Root"
|
|
225
216
|
metersPerUnit = 1.0
|
|
@@ -232,55 +223,55 @@ kind = "component"
|
|
|
232
223
|
{
|
|
233
224
|
${s}def Scope "Materials"
|
|
234
225
|
{
|
|
235
|
-
`;for(let[u,
|
|
236
|
-
`,
|
|
237
|
-
`),
|
|
238
|
-
`),
|
|
239
|
-
`),(
|
|
240
|
-
`),
|
|
226
|
+
`;for(let[u,a]of e.entries()){let[o,m,T]=a.color,[M,h,E]=a.emissiveColor,D="";a.clearcoat>0&&(D+=`float inputs:clearcoat = ${z(a.clearcoat)}
|
|
227
|
+
`,D+=`float inputs:clearcoatRoughness = ${z(a.clearcoatRoughness)}
|
|
228
|
+
`),a.ior!==1.5&&(D+=`float inputs:ior = ${z(a.ior)}
|
|
229
|
+
`),a.opacity<1&&(D+=`float inputs:opacity = ${z(a.opacity)}
|
|
230
|
+
`),(M>0||h>0||E>0)&&(D+=`color3f inputs:emissiveColor = (${z(M)}, ${z(h)}, ${z(E)})
|
|
231
|
+
`),l+=`def Material "${u}"
|
|
241
232
|
{
|
|
242
233
|
def Shader "PBRShader"
|
|
243
234
|
{
|
|
244
235
|
uniform token info:id = "UsdPreviewSurface"
|
|
245
|
-
color3f inputs:diffuseColor = (${z(
|
|
246
|
-
float inputs:metallic = ${z(
|
|
247
|
-
float inputs:roughness = ${z(
|
|
248
|
-
${
|
|
236
|
+
color3f inputs:diffuseColor = (${z(o)}, ${z(m)}, ${z(T)})
|
|
237
|
+
float inputs:metallic = ${z(a.metallic)}
|
|
238
|
+
float inputs:roughness = ${z(a.roughness)}
|
|
239
|
+
${D}token outputs:surface
|
|
249
240
|
}
|
|
250
241
|
token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
|
|
251
242
|
}
|
|
252
|
-
`}
|
|
243
|
+
`}l+=`}
|
|
253
244
|
def Scope "Meshes"
|
|
254
245
|
{
|
|
255
|
-
`;let y=new Set;for(let u=0;u<n.length;u++){let
|
|
246
|
+
`;let y=new Set;for(let u=0;u<n.length;u++){let a=n[u],o=a.positions.length/3,m=1/0,T=1/0,M=1/0,h=-1/0,E=-1/0,D=-1/0;for(let c=0;c<o;c++){let x=a.positions[c*3],b=a.positions[c*3+1],A=a.positions[c*3+2];x<m&&(m=x),x>h&&(h=x),b<T&&(T=b),b>E&&(E=b),A<M&&(M=A),A>D&&(D=A)}isFinite(m)||(m=T=M=-1,h=E=D=1);let F=Math.floor(a.indices.length/3),C=Me(a.materialName,"DefaultMaterial"),f=Me(a.name,`Mesh_${u}`);y.has(f)&&(f=`${f}_${u}`),y.add(f);let v=F>0?F===1?"3":"3, ".repeat(F-1)+"3":"",p=a.xrTraits,w="";if(p){let c=[];p.physics&&p.physics!=="none"&&c.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let x=ee().xrTraitSerializer?.usdLines(p,Fe)??[];if(!x.length)for(let b of["grab","billboard","follow","anchor","physics"]){let A=b==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[b];A!==void 0&&x.push(`string ${b} = "${Fe(A)}"`)}x.length>0&&c.push(`customData = {
|
|
256
247
|
dictionary xr = {
|
|
257
248
|
${x.join(`
|
|
258
249
|
`)}
|
|
259
250
|
}
|
|
260
|
-
}`),c.length>0&&(
|
|
251
|
+
}`),c.length>0&&(w=` (
|
|
261
252
|
${c.join(`
|
|
262
253
|
`)}
|
|
263
|
-
)`)}if(
|
|
254
|
+
)`)}if(l+=`def Mesh "${f}"${w}
|
|
264
255
|
{
|
|
265
|
-
`,
|
|
256
|
+
`,p?.physics&&p.physics!=="none"){let c=p.physics==="static"?"true":"false";l+=`bool physics:rigidBodyEnabled = true
|
|
266
257
|
bool physics:kinematicEnabled = ${c}
|
|
267
258
|
bool physics:collisionEnabled = true
|
|
268
|
-
`}if(
|
|
269
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
270
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
259
|
+
`}if(a.timeSamples&&a.timeSamples.times.length>0){let c=a.timeSamples,x=c.times.map((P,I)=>{let g=c.translations?.[I]||[0,0,0];return`${z(P)}: (${z(g[0])}, ${z(g[1])}, ${z(g[2])})`}).join(", "),b=c.times.map((P,I)=>{let g=c.rotations?.[I]||[0,0,0,1];return`${z(P)}: (${z(g[3])}, ${z(g[0])}, ${z(g[1])}, ${z(g[2])})`}).join(", "),A=c.times.map((P,I)=>{let g=c.scales?.[I]||[1,1,1];return`${z(P)}: (${z(g[0])}, ${z(g[1])}, ${z(g[2])})`}).join(", ");l+=`double3 xformOp:translate.timeSamples = { ${x} }
|
|
260
|
+
quatf xformOp:orient.timeSamples = { ${b} }
|
|
261
|
+
double3 xformOp:scale.timeSamples = { ${A} }
|
|
271
262
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
272
|
-
`}
|
|
273
|
-
int[] faceVertexCounts = [${
|
|
274
|
-
int[] faceVertexIndices = [${
|
|
275
|
-
point3f[] points = [${
|
|
276
|
-
`,
|
|
263
|
+
`}l+=`float3[] extent = [(${z(m)}, ${z(T)}, ${z(M)}), (${z(h)}, ${z(E)}, ${z(D)})]
|
|
264
|
+
int[] faceVertexCounts = [${v}]
|
|
265
|
+
int[] faceVertexIndices = [${Rt(a.indices)}]
|
|
266
|
+
point3f[] points = [${Xe(a.positions)}]
|
|
267
|
+
`,a.normals&&a.normals.length===a.positions.length&&(l+=`normal3f[] normals = [${Xe(a.normals)}] (
|
|
277
268
|
interpolation = "vertex"
|
|
278
269
|
)
|
|
279
|
-
`),
|
|
270
|
+
`),a.uvs&&a.uvs.length===o*2&&(l+=`texCoord2f[] primvars:st = [${Mt(a.uvs,o)}] (
|
|
280
271
|
interpolation = "vertex"
|
|
281
272
|
)
|
|
282
|
-
`),
|
|
273
|
+
`),l+=`rel material:binding = </Root/Materials/${C}>
|
|
283
274
|
}
|
|
284
|
-
`}return
|
|
275
|
+
`}return l+=`}
|
|
285
276
|
}
|
|
286
|
-
`,
|
|
277
|
+
`,l}function Ye(n,e){if(n&&typeof n.traverse=="function"){let r=qe(n,e);return Re(r)}let t=he(n),i=Le(t);return Re(i)}var Te=null;function Ze(n){if(!Te){Te=new Uint32Array(256);for(let t=0;t<256;t++){let i=t;for(let r=0;r<8;r++)i=i&1?3988292384^i>>>1:i>>>1;Te[t]=i}}let e=4294967295;for(let t=0;t<n.length;t++)e=Te[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Ce(n){let e=[],t=0,i=[];for(let o of n){let m=fe(o.filename),T=Ze(o.data),M=o.data.length,h=30+m.length,E=t+h,D=0,F=E%64;F!==0&&(D=64-F);let C=new Uint8Array(h+D),f=new DataView(C.buffer);f.setUint32(0,67324752,!0),f.setUint16(4,20,!0),f.setUint16(6,0,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint32(14,T,!0),f.setUint32(18,M,!0),f.setUint32(22,M,!0),f.setUint16(26,m.length,!0),f.setUint16(28,D,!0),C.set(m,30),D>0&&C.fill(0,30+m.length),e.push({offset:t,size:M,crc:T,filenameBytes:m,entry:o}),i.push(C),i.push(o.data),t+=C.length+o.data.length}let r=t;for(let o of e){let m=new Uint8Array(46+o.filenameBytes.length),T=new DataView(m.buffer);T.setUint32(0,33639248,!0),T.setUint16(4,20,!0),T.setUint16(6,20,!0),T.setUint16(8,0,!0),T.setUint16(10,0,!0),T.setUint16(12,0,!0),T.setUint16(14,0,!0),T.setUint32(16,o.crc,!0),T.setUint32(20,o.size,!0),T.setUint32(24,o.size,!0),T.setUint16(28,o.filenameBytes.length,!0),T.setUint16(30,0,!0),T.setUint16(32,0,!0),T.setUint16(34,0,!0),T.setUint16(36,0,!0),T.setUint32(38,0,!0),T.setUint32(42,o.offset,!0),m.set(o.filenameBytes,46),i.push(m),t+=m.length}let s=t-r,l=new Uint8Array(22),y=new DataView(l.buffer);y.setUint32(0,101010256,!0),y.setUint16(4,0,!0),y.setUint16(6,0,!0),y.setUint16(8,e.length,!0),y.setUint16(10,e.length,!0),y.setUint32(12,s,!0),y.setUint32(16,r,!0),y.setUint16(20,0,!0),i.push(l),t+=22;let u=new Uint8Array(t),a=0;for(let o of i)u.set(o,a),a+=o.length;return u}function je(n){let e=Ye(n),t=fe(e);return Ce([{filename:"model.usda",data:t}])}function Je(n){let e=he(n),t=Le(e),i=Re(t),r=fe(i);return Ce([{filename:"model.usda",data:r}])}function Qe(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?je(n):Je(n)}function At(n){let e=Qe(n);return new Blob([e],{type:"model/vnd.usdz+zip"})}
|