three-live 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +36 -0
- package/dist/three-author-engine.js +86 -62
- package/dist/three-author.cjs +84 -60
- package/dist/three-author.d.ts +36 -0
- package/dist/three-author.js +83 -59
- package/dist/three-convert.cjs +78 -58
- package/dist/three-convert.d.ts +36 -0
- package/dist/three-convert.js +77 -57
- package/dist/three-live-animation.cjs +8 -9
- package/dist/three-live-animation.d.ts +36 -0
- package/dist/three-live-animation.js +7 -8
- package/dist/three-live-animation.min.js +6 -7
- package/dist/three-live-cad.cjs +3 -4
- package/dist/three-live-cad.d.ts +36 -0
- package/dist/three-live-cad.js +2 -3
- package/dist/three-live-cad.min.js +3 -4
- package/dist/three-live-cli.js +231 -0
- package/dist/three-live-element.cjs +17 -20
- package/dist/three-live-element.d.ts +36 -0
- package/dist/three-live-element.js +16 -19
- package/dist/three-live-full.cjs +110 -86
- package/dist/three-live-full.js +107 -83
- package/dist/three-live-full.min.js +110 -86
- package/dist/three-live-studio.cjs +19 -20
- package/dist/three-live-studio.d.ts +36 -0
- package/dist/three-live-studio.js +18 -19
- package/dist/three-live-studio.min.js +18 -19
- package/dist/three-live-viewer.cjs +17 -20
- package/dist/three-live-viewer.d.ts +36 -0
- package/dist/three-live-viewer.js +16 -19
- package/dist/three-live-viewer.min.js +17 -20
- package/dist/three-live.cjs +87 -63
- package/dist/three-live.js +86 -62
- package/dist/three-live.min.js +86 -62
- package/dist/three-view.cjs +17 -20
- package/dist/three-view.d.ts +36 -0
- package/dist/three-view.js +16 -19
- package/dist/three-xr.cjs +78 -58
- package/dist/three-xr.d.ts +36 -0
- package/dist/three-xr.js +77 -57
- package/package.json +7 -1
package/dist/three-convert.js
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
function _e(n,e,t){let r=[],i=new Map,s=[],a=[],d=[],o=new Map,c=h=>{let w=i.get(h);return w===void 0&&(w=r.length,r.push({op:h}),i.set(h,w)),w},u=h=>{let w=o.get(h);return w===void 0&&(w=d.length,d.push({id:h}),o.set(h,w)),w},b=(h,w={})=>s.push({declaration:c(h),...w})-1,v=(h,w,f)=>a.push({id:h,type:w,value:f})-1,L=h=>({node:h,socket:"value"}),E=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(E&&typeof E=="object"){let h=Array.isArray(E.graphs)?E.graphs[E.graph??0]:E;if(h&&Array.isArray(h.nodes)){let w=Array.isArray(h.declarations)?h.declarations:[];for(let f of w)f?.op&&c(f.op);Array.isArray(h.variables)&&a.push(...h.variables);for(let f of h.events||[])f?.id&&u(f.id);for(let f of h.nodes){if(!f||typeof f!="object")continue;let S=f.op||(typeof f.declaration=="number"?w[f.declaration]?.op:"");s.push(S?{...f,declaration:c(S)}:{...f})}}}let x=(h,w,f="translation")=>f==="baseColorFactor"||f==="metallicFactor"||f==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${f}`:f==="emissiveFactor"||f==="alphaCutoff"?`/materials/${Math.max(0,w)}/${f}`:f==="visible"?`/nodes/${h}/extensions/KHR_node_visibility/visible`:`/nodes/${h}/${f}`,T=new Map;n.forEach((h,w)=>{typeof h?.name=="string"&&!T.has(h.name)&&T.set(h.name,w)});let I=(h,w)=>typeof h.target=="string"&&T.has(h.target)?T.get(h.target):typeof h.targetNode=="number"?h.targetNode:w,F=h=>{let w=n[h];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let h=0;h<n.length;h++){let w=n[h],f=w?.extras?.interactivity;if(!f||typeof f!="object")continue;let S=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,U=y=>{let D=Array.isArray(y)?y:[y],l=[];for(let R=0;R<D.length;R++){let p=D[R];if(!p||typeof p!="object")continue;let g=p.action||"interpolate",_=typeof p.duration=="number"?p.duration:.35;if(g==="toggleTransform"){let P=p.property==="rotation"||p.property==="scale"?p.property:"translation",G=P==="rotation"?w.rotation||[0,0,0,1]:P==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],N=`/nodes/${h}/${P}`,k=v(`__toggle_${h}_${R}`,"bool",!1),M=b("variable/get",{configuration:{variable:k}}),H=b("math/not",{values:{a:L(M)}}),O=b("variable/set",{configuration:{variable:k},values:{value:L(H)}}),B=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.to)?p.to:G},duration:{value:_}}}),z=b("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(p.from)?p.from:G},duration:{value:_}}});s[O].flows={out:{node:b("flow/branch",{values:{condition:L(M)},flows:{true:{node:B},false:{node:z}}})}},l.push(O)}else if(g==="interpolate"){let P=p.to??p.value;if(P===void 0)continue;let G={value:{value:P},duration:{value:_}};p.from!==void 0&&(G.from={value:p.from}),l.push(b("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(I(p,h),F(I(p,h)),p.property)},values:G}))}else if(g==="setProperty"){if(p.value===void 0)continue;l.push(b("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(I(p,h),F(I(p,h)),p.property)},values:{value:{value:p.value}}}))}else if(g==="toggleVisibility"){let P=I(p,h),G=v(`__vis_${P}_${R}`,"bool",!0),N=b("variable/get",{configuration:{variable:G}}),k=b("math/not",{values:{a:L(N)}}),M=b("variable/set",{configuration:{variable:G},values:{value:L(k)}});s[M].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${P}/extensions/KHR_node_visibility/visible`},values:{value:L(N)}})}},l.push(M)}else if(g==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let P=typeof p.duration=="number"?p.duration:.25,G=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,N=v(`__color_idx_${h}_${R}`,"int",0),k=b("variable/get",{configuration:{variable:N}}),M=b("math/add",{values:{a:L(k),b:{value:1}}}),H=b("math/rem",{values:{a:L(M),b:{value:p.colors.length}}}),O=b("variable/set",{configuration:{variable:N},values:{value:L(H)}}),B={};for(let z=0;z<p.colors.length;z++){let C=p.colors[z],V=Array.isArray(C)&&C.length>=3?[C[0],C[1],C[2],C[3]??1]:[1,1,1,1];B[String(z)]={node:P>0?b("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:V},duration:{value:P}}}):b("pointer/set",{configuration:{pointer:G},values:{value:{value:V}}})}}s[O].flows={out:{node:b("flow/switch",{values:{selection:L(k)},flows:B})}},l.push(O)}else if(g==="playAnimation")l.push(b("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(g==="stopAnimation")l.push(b("animation/stop"));else if(g==="sendEvent"){let P={};for(let[G,N]of Object.entries(p.values||{}))P[G]={value:N};l.push(b("event/send",{configuration:{event:u(String(p.event??p.id??"custom"))},values:P}))}}if(!l.length)return null;if(l.length===1)return l[0];let m={};return l.forEach((R,p)=>{m[String(p)]={node:R}}),b("flow/sequence",{flows:m})},A=(y,D,l)=>{let m=U(D);m!==null&&b(y,{...l?{configuration:l}:{},flows:{out:{node:m}}})};if(f.onSelect&&A("pointer/onSelect",f.onSelect,{nodeIndex:h}),f.onHoverIn&&A("pointer/onHoverIn",f.onHoverIn,{nodeIndex:h}),f.onHoverOut&&A("pointer/onHoverOut",f.onHoverOut,{nodeIndex:h}),f.onStart&&A("event/onStart",f.onStart),f.onReceive&&typeof f.onReceive=="object")for(let[y,D]of Object.entries(f.onReceive))A("event/receive",D,{event:u(y)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:d}],graph:0}:null}var ge="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ge]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ge,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ge]=e}}return n[ge]}var ne=ue().plugins;function Ne(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function Be(){return ue().plugins}function ye(n,e,t,r=!0){let i=[],s=null;try{for(let[a,d]of[[35633,e],[35632,t]]){let o=n.createShader(a);if(!o){if(r)throw new Error("Shader allocation failed");return null}if(i.push(o),n.shaderSource(o,d),n.compileShader(o),n.getShaderParameter&&!n.getShaderParameter(o,35713)){if(r)throw new Error(`Shader compile error: ${n.getShaderInfoLog(o)}`);return null}}if(s=n.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let a of i)n.attachShader(s,a);if(n.linkProgram(s),n.getProgramParameter&&!n.getProgramParameter(s,35714)){let a=r?n.getProgramInfoLog(s):null;if(n.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${a}`);return null}return s}finally{for(let a of i)s&&n.detachShader?.(s,a),n.deleteShader?.(a)}}var tt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ee(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=t.componentType??5126,d=tt[a];if(!d)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let o=d*r,c=i.byteStride&&i.byteStride>0?i.byteStride:o,u=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(u)||u<0||c<o||u+(s-1)*c+o>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&c===o&&u%4===0)return new Float32Array(e,u,s*r);let b=new DataView(e),v=t.normalized===!0,L=new Float32Array(s*r);for(let E=0;E<s;E++){let x=u+E*c;for(let T=0;T<r;T++){let I=x+T*d,F;switch(a){case 5126:F=b.getFloat32(I,!0);break;case 5120:F=b.getInt8(I),v&&(F=Math.max(F/127,-1));break;case 5121:F=b.getUint8(I),v&&(F/=255);break;case 5122:F=b.getInt16(I,!0),v&&(F=Math.max(F/32767,-1));break;case 5123:F=b.getUint16(I,!0),v&&(F/=65535);break;default:F=b.getUint32(I,!0),v&&(F/=4294967295)}L[E*r+T]=F}}return L}function Ue(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,d=Math.cos(a),o=Math.sin(a),c=(Number.isFinite(i)?i:1)*d,u=(Number.isFinite(i)?i:1)*o,b=-(Number.isFinite(s)?s:1)*o,v=(Number.isFinite(s)?s:1)*d;for(let L=0;L+1<n.length;L+=2){let E=n[L],x=n[L+1];n[L]=c*E+u*x+t,n[L+1]=b*E+v*x+r}}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function ve(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let a=1/(r-i);return n[10]=(i+r)*a,n[14]=2*i*r*a,n}function xe(n,e,t,r){let[i,s,a]=e,[d,o,c]=r,[u,b,v]=t,L=i-u,E=s-b,x=a-v,T=Math.hypot(L,E,x);T<=1e-5?(L=0,E=0,x=1):(L/=T,E/=T,x/=T);let I=o*x-c*E,F=c*L-d*x,h=d*E-o*L;T=Math.hypot(I,F,h),T<=1e-5?(I=0,F=0,h=0):(I/=T,F/=T,h/=T);let w=E*h-x*F,f=x*I-L*h,S=L*F-E*I;return T=Math.hypot(w,f,S),T<=1e-5?(w=0,f=0,S=0):(w/=T,f/=T,S/=T),n[0]=I,n[1]=w,n[2]=L,n[3]=0,n[4]=F,n[5]=f,n[6]=E,n[7]=0,n[8]=h,n[9]=S,n[10]=x,n[11]=0,n[12]=-(I*i+F*s+h*a),n[13]=-(w*i+f*s+S*a),n[14]=-(L*i+E*s+x*a),n[15]=1,n}function ee(n,e,t){let r=e[0],i=e[1],s=e[2],a=e[3],d=e[4],o=e[5],c=e[6],u=e[7],b=e[8],v=e[9],L=e[10],E=e[11],x=e[12],T=e[13],I=e[14],F=e[15],h=t[0],w=t[1],f=t[2],S=t[3];return n[0]=h*r+w*d+f*b+S*x,n[1]=h*i+w*o+f*v+S*T,n[2]=h*s+w*c+f*L+S*I,n[3]=h*a+w*u+f*E+S*F,h=t[4],w=t[5],f=t[6],S=t[7],n[4]=h*r+w*d+f*b+S*x,n[5]=h*i+w*o+f*v+S*T,n[6]=h*s+w*c+f*L+S*I,n[7]=h*a+w*u+f*E+S*F,h=t[8],w=t[9],f=t[10],S=t[11],n[8]=h*r+w*d+f*b+S*x,n[9]=h*i+w*o+f*v+S*T,n[10]=h*s+w*c+f*L+S*I,n[11]=h*a+w*u+f*E+S*F,h=t[12],w=t[13],f=t[14],S=t[15],n[12]=h*r+w*d+f*b+S*x,n[13]=h*i+w*o+f*v+S*T,n[14]=h*s+w*c+f*L+S*I,n[15]=h*a+w*u+f*E+S*F,n}function he(n,e,t,r){let i=e[0],s=e[1],a=e[2],d=e[3],o=i+i,c=s+s,u=a+a,b=i*o,v=i*c,L=i*u,E=s*c,x=s*u,T=a*u,I=d*o,F=d*c,h=d*u,w=r[0],f=r[1],S=r[2];return n[0]=(1-(E+T))*w,n[1]=(v+h)*w,n[2]=(L-F)*w,n[3]=0,n[4]=(v-h)*f,n[5]=(1-(b+T))*f,n[6]=(x+I)*f,n[7]=0,n[8]=(L+F)*S,n[9]=(x-I)*S,n[10]=(1-(b+E))*S,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ae(n,e,t=0){let r=e[0],i=e[1],s=e[2],a=e[4],d=e[5],o=e[6],c=e[8],u=e[9],b=e[10],v=b*d-o*u,L=-b*a+o*c,E=u*a-d*c,x=r*v+i*L+s*E;return!x||t>0&&(!Number.isFinite(x)||Math.abs(x)<=t)||(x=1/x,n[0]=v*x,n[1]=L*x,n[2]=E*x,n[3]=(-b*i+s*u)*x,n[4]=(b*r-s*c)*x,n[5]=(-u*r+i*c)*x,n[6]=(o*i-s*d)*x,n[7]=(-o*r+s*a)*x,n[8]=(d*r-i*a)*x),n}function ke(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],d=e[5],o=e[6],c=e[7],u=e[8],b=e[9],v=e[10],L=e[11],E=e[12],x=e[13],T=e[14],I=e[15],F=t*d-r*a,h=t*o-i*a,w=t*c-s*a,f=r*o-i*d,S=r*c-s*d,U=i*c-s*o,A=u*x-b*E,y=u*T-v*E,D=u*I-L*E,l=b*T-v*x,m=b*I-L*x,R=v*I-L*T,p=F*R-h*m+w*l+f*D-S*y+U*A;return p?(p=1/p,n[0]=(d*R-o*m+c*l)*p,n[1]=(i*m-r*R-s*l)*p,n[2]=(x*U-T*S+I*f)*p,n[3]=(v*S-b*U-L*f)*p,n[4]=(o*D-a*R-c*y)*p,n[5]=(t*R-i*D+s*y)*p,n[6]=(T*w-E*U-I*h)*p,n[7]=(u*U-v*w+L*h)*p,n[8]=(a*m-d*D+c*A)*p,n[9]=(r*D-t*m-s*A)*p,n[10]=(E*S-x*w+I*F)*p,n[11]=(b*w-u*S-L*F)*p,n[12]=(d*y-a*l-o*A)*p,n[13]=(t*l-r*y+i*A)*p,n[14]=(x*h-E*f-T*F)*p,n[15]=(u*f-b*h+v*F)*p,n):null}function De(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],a=i[1]*e+i[5]*t+i[9]*r+i[13],d=i[2]*e+i[6]*t+i[10]*r+i[14],o=i[3]*e+i[7]*t+i[11]*r+i[15],c=o!==0?1/o:1;n[0]=s*c,n[1]=a*c,n[2]=d*c}function Ge(n,e,t,r,i,s,a,d,o,c,u,b,v,L,E,x,T=0){let I=c-a,F=u-d,h=b-o,w=v-a,f=L-d,S=E-o,U=i*S-s*f,A=s*w-r*S,y=r*f-i*w,D=I*U+F*A+h*y;if(D>-1e-7&&D<1e-7)return!1;let l=1/D,m=n-a,R=e-d,p=t-o,g=l*(m*U+R*A+p*y);if(g<-T||g>1+T)return!1;let _=R*h-p*F,P=p*I-m*h,G=m*F-R*I,N=l*(r*_+i*P+s*G);if(N<-T||g+N>1+T)return!1;let k=l*(w*_+f*P+S*G);if(k>1e-4&&k<x.distance){x.distance=k,x.point=[n+r*k,e+i*k,t+s*k];let M=F*S-h*f,H=h*w-I*S,O=I*f-F*w,B=Math.hypot(M,H,O)||1;return x.normal=[M/B,H/B,O/B],!0}return!1}function Me(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let u=0;u<t;u++)r.push(J());if(t===0)return r;let i=new Set;for(let u of n.nodes)if(Array.isArray(u.children))for(let b of u.children)i.add(b);let s=new Set,a=128,d=(u,b,v=0)=>{if(v>a||u<0||u>=t||s.has(u))return;s.add(u);let L=n.nodes[u];if(!L)return;let E=J();if(e&&e[u])E.set(e[u]);else if(L.matrix&&L.matrix.length===16)E.set(L.matrix);else{let T=L.translation||[0,0,0],I=L.rotation||[0,0,0,1],F=L.scale||[1,1,1];he(E,I,T,F)}let x=r[u];if(b?ee(x,b,E):x.set(E),Array.isArray(L.children))for(let T of L.children)typeof T=="number"&&d(T,x,v+1)},o=[],c=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(c&&Array.isArray(c.nodes))o.push(...c.nodes);else for(let u=0;u<t;u++)i.has(u)||o.push(u);for(let u of o)d(u,null);for(let u=0;u<t;u++)!i.has(u)&&!o.includes(u)&&d(u,null);return r}var He=["neutral","reinhard","none","aces","agx"];function Pe(n){let e=String(n??"").trim().toLowerCase();return He.includes(e)?e:"neutral"}function nt(n){return He.indexOf(Pe(n))}function rt(n){return new TextDecoder().decode(n)}var ze=ue().decoders;function it(n,e){ze.set(n.toLowerCase(),e)}function me(n){return ze.get(n.toLowerCase())}function $e(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let v=t.getUint8(0);throw v===123||v===32||v===10||v===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),a=12,d=null,o=null;for(;a+8<=s&&a+8<=e.byteLength;){let v=t.getUint32(a,!0),L=t.getUint32(a+4,!0),E=a+8;if(E+v>e.byteLength)throw new Error(`Truncated GLB chunk: required ${E+v} bytes, buffer has ${e.byteLength}`);if(L===1313821514){let x=new Uint8Array(e,E,v),T=rt(x);d=JSON.parse(T,(I,F)=>I==="__proto__"||I==="constructor"||I==="prototype"?void 0:F)}else L===5130562&&(o=e.slice(E,E+v));a=E+v}if(!d)throw new Error("Missing JSON chunk in GLB");let c=d.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let v of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(v)&&!me("meshopt"))throw new Error(`Model requires ${v}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=o||new ArrayBuffer(0),b={gltf:d,bin:u,animations:[]};for(let v of ne)v.onParseGLB?.(b);return b}function st(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function de(n){if(st(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return $e(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var We=`#version 300 es
|
|
16
|
+
*/function Bt(t,e,i){let r=[],a=new Map,s=[],m=[],f=[],p=new Map,u=h=>{let n=a.get(h);return n===void 0&&(n=r.length,r.push({op:h}),a.set(h,n)),n},d=h=>{let n=p.get(h);return n===void 0&&(n=f.length,f.push({id:h}),p.set(h,n)),n},y=(h,n={})=>s.push({declaration:u(h),...n})-1,R=(h,n,b)=>m.push({id:h,type:n,value:b})-1,S=h=>({node:h,socket:"value"}),l=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(l&&typeof l=="object"){let h=Array.isArray(l.graphs)?l.graphs[l.graph??0]:l;if(h&&Array.isArray(h.nodes)){let n=Array.isArray(h.declarations)?h.declarations:[];for(let b of n)b?.op&&u(b.op);Array.isArray(h.variables)&&m.push(...h.variables);for(let b of h.events||[])b?.id&&d(b.id);for(let b of h.nodes){if(!b||typeof b!="object")continue;let A=b.op||(typeof b.declaration=="number"?n[b.declaration]?.op:"");s.push(A?{...b,declaration:u(A)}:{...b})}}}let x=(h,n,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,n)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,n)}/${b}`:b==="visible"?`/nodes/${h}/extensions/KHR_node_visibility/visible`:`/nodes/${h}/${b}`,T=new Map;t.forEach((h,n)=>{typeof h?.name=="string"&&!T.has(h.name)&&T.set(h.name,n)});let w=(h,n)=>typeof h.target=="string"&&T.has(h.target)?T.get(h.target):typeof h.targetNode=="number"?h.targetNode:n,v=h=>{let n=t[h];return(typeof n?.mesh=="number"?e[n.mesh]?.primitives?.[0]?.material:0)??0};for(let h=0;h<t.length;h++){let n=t[h],b=n?.extras?.interactivity;if(!b||typeof b!="object")continue;let A=(typeof n.mesh=="number"?e[n.mesh]?.primitives?.[0]?.material:0)??0,$=_=>{let L=Array.isArray(_)?_:[_],C=[];for(let M=0;M<L.length;M++){let o=L[M];if(!o||typeof o!="object")continue;let V=o.action||"interpolate",X=typeof o.duration=="number"?o.duration:.35;if(V==="toggleTransform"){let g=o.property==="rotation"||o.property==="scale"?o.property:"translation",I=g==="rotation"?n.rotation||[0,0,0,1]:g==="scale"?n.scale||[1,1,1]:n.translation||[0,0,0],c=`/nodes/${h}/${g}`,P=R(`__toggle_${h}_${M}`,"bool",!1),j=y("variable/get",{configuration:{variable:P}}),G=y("math/not",{values:{a:S(j)}}),U=y("variable/set",{configuration:{variable:P},values:{value:S(G)}}),Z=y("pointer/interpolate",{configuration:{pointer:c},values:{value:{value:Array.isArray(o.to)?o.to:I},duration:{value:X}}}),E=y("pointer/interpolate",{configuration:{pointer:c},values:{value:{value:Array.isArray(o.from)?o.from:I},duration:{value:X}}});s[U].flows={out:{node:y("flow/branch",{values:{condition:S(j)},flows:{true:{node:Z},false:{node:E}}})}},C.push(U)}else if(V==="interpolate"){let g=o.to??o.value;if(g===void 0)continue;let I={value:{value:g},duration:{value:X}};o.from!==void 0&&(I.from={value:o.from}),C.push(y("pointer/interpolate",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(w(o,h),v(w(o,h)),o.property)},values:I}))}else if(V==="setProperty"){if(o.value===void 0)continue;C.push(y("pointer/set",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(w(o,h),v(w(o,h)),o.property)},values:{value:{value:o.value}}}))}else if(V==="toggleVisibility"){let g=w(o,h),I=R(`__vis_${g}_${M}`,"bool",!0),c=y("variable/get",{configuration:{variable:I}}),P=y("math/not",{values:{a:S(c)}}),j=y("variable/set",{configuration:{variable:I},values:{value:S(P)}});s[j].flows={out:{node:y("pointer/set",{configuration:{pointer:`/nodes/${g}/extensions/KHR_node_visibility/visible`},values:{value:S(c)}})}},C.push(j)}else if(V==="cycleMaterialColor"&&Array.isArray(o.colors)&&o.colors.length>0){let g=typeof o.duration=="number"?o.duration:.25,I=`/materials/${Math.max(0,A)}/pbrMetallicRoughness/baseColorFactor`,c=R(`__color_idx_${h}_${M}`,"int",0),P=y("variable/get",{configuration:{variable:c}}),j=y("math/add",{values:{a:S(P),b:{value:1}}}),G=y("math/rem",{values:{a:S(j),b:{value:o.colors.length}}}),U=y("variable/set",{configuration:{variable:c},values:{value:S(G)}}),Z={};for(let E=0;E<o.colors.length;E++){let q=o.colors[E],O=Array.isArray(q)&&q.length>=3?[q[0],q[1],q[2],q[3]??1]:[1,1,1,1];Z[String(E)]={node:g>0?y("pointer/interpolate",{configuration:{pointer:I},values:{value:{value:O},duration:{value:g}}}):y("pointer/set",{configuration:{pointer:I},values:{value:{value:O}}})}}s[U].flows={out:{node:y("flow/switch",{values:{selection:S(P)},flows:Z})}},C.push(U)}else if(V==="playAnimation")C.push(y("animation/start",{configuration:{animation:o.animation??o.clip??0}}));else if(V==="stopAnimation")C.push(y("animation/stop"));else if(V==="sendEvent"){let g={};for(let[I,c]of Object.entries(o.values||{}))g[I]={value:c};C.push(y("event/send",{configuration:{event:d(String(o.event??o.id??"custom"))},values:g}))}}if(!C.length)return null;if(C.length===1)return C[0];let D={};return C.forEach((M,o)=>{D[String(o)]={node:M}}),y("flow/sequence",{flows:D})},B=(_,L,C)=>{let D=$(L);D!==null&&y(_,{...C?{configuration:C}:{},flows:{out:{node:D}}})};if(b.onSelect&&B("pointer/onSelect",b.onSelect,{nodeIndex:h}),b.onHoverIn&&B("pointer/onHoverIn",b.onHoverIn,{nodeIndex:h}),b.onHoverOut&&B("pointer/onHoverOut",b.onHoverOut,{nodeIndex:h}),b.onStart&&B("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[_,L]of Object.entries(b.onReceive))B("event/receive",L,{event:d(_)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:m,events:f}],graph:0}:null}var Pt="__THREE_LIVE_REGISTRY__";function pt(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Pt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Pt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Pt]=e}}return t[Pt]}var ht=pt().plugins;function ve(t){let e=pt().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function xe(){return pt().plugins}var be={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ht(t,e,i,r){if(!i||i.bufferView===void 0)return null;let a=t.bufferViews?.[i.bufferView];if(!a)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let m=i.componentType??5126,f=be[m];if(!f)throw new RangeError(`glTF accessor has unsupported componentType ${m}`);let p=f*r,u=a.byteStride&&a.byteStride>0?a.byteStride:p,d=(a.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(d)||d<0||u<p||d+(s-1)*u+p>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(m===5126&&u===p&&d%4===0)return new Float32Array(e,d,s*r);let y=new DataView(e),R=i.normalized===!0,S=new Float32Array(s*r);for(let l=0;l<s;l++){let x=d+l*u;for(let T=0;T<r;T++){let w=x+T*f,v;switch(m){case 5126:v=y.getFloat32(w,!0);break;case 5120:v=y.getInt8(w),R&&(v=Math.max(v/127,-1));break;case 5121:v=y.getUint8(w),R&&(v/=255);break;case 5122:v=y.getInt16(w,!0),R&&(v=Math.max(v/32767,-1));break;case 5123:v=y.getUint16(w,!0),R&&(v/=65535);break;default:v=y.getUint32(w,!0),R&&(v/=4294967295)}S[l*r+T]=v}}return S}function ye(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,a=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),m=Number(e.rotation??0)||0,f=Math.cos(m),p=Math.sin(m),u=(Number.isFinite(a)?a:1)*f,d=(Number.isFinite(a)?a:1)*p,y=-(Number.isFinite(s)?s:1)*p,R=(Number.isFinite(s)?s:1)*f;for(let S=0;S+1<t.length;S+=2){let l=t[S],x=t[S+1];t[S]=u*l+d*x+i,t[S+1]=y*l+R*x+r}}function Nt(t,e,i,r=!0){let a=[],s=null;try{for(let[m,f]of[[35633,e],[35632,i]]){let p=t.createShader(m);if(!p){if(r)throw new Error("Shader allocation failed");return null}if(a.push(p),t.shaderSource(p,f),t.compileShader(p),t.getShaderParameter&&!t.getShaderParameter(p,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(p)}`);return null}}if(s=t.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let m of a)t.attachShader(s,m);if(t.linkProgram(s),t.getProgramParameter&&!t.getProgramParameter(s,35714)){let m=r?t.getProgramInfoLog(s):null;if(t.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${m}`);return null}return s}finally{for(let m of a)s&&t.detachShader?.(s,m),t.deleteShader?.(m)}}function nt(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Et(t,e,i,r,a){let s=1/Math.tan(e/2);t.fill(0),t[0]=s/i,t[5]=s,t[11]=-1;let m=1/(r-a);return t[10]=(a+r)*m,t[14]=2*a*r*m,t}function kt(t,e,i,r){let[a,s,m]=e,[f,p,u]=r,[d,y,R]=i,S=a-d,l=s-y,x=m-R,T=Math.hypot(S,l,x);T<=1e-5?(S=0,l=0,x=1):(S/=T,l/=T,x/=T);let w=p*x-u*l,v=u*S-f*x,h=f*l-p*S;T=Math.hypot(w,v,h),T<=1e-5?(w=0,v=0,h=0):(w/=T,v/=T,h/=T);let n=l*h-x*v,b=x*w-S*h,A=S*v-l*w;return T=Math.hypot(n,b,A),T<=1e-5?(n=0,b=0,A=0):(n/=T,b/=T,A/=T),t[0]=w,t[1]=n,t[2]=S,t[3]=0,t[4]=v,t[5]=b,t[6]=l,t[7]=0,t[8]=h,t[9]=A,t[10]=x,t[11]=0,t[12]=-(w*a+v*s+h*m),t[13]=-(n*a+b*s+A*m),t[14]=-(S*a+l*s+x*m),t[15]=1,t}function ct(t,e,i){let r=e[0],a=e[1],s=e[2],m=e[3],f=e[4],p=e[5],u=e[6],d=e[7],y=e[8],R=e[9],S=e[10],l=e[11],x=e[12],T=e[13],w=e[14],v=e[15],h=i[0],n=i[1],b=i[2],A=i[3];return t[0]=h*r+n*f+b*y+A*x,t[1]=h*a+n*p+b*R+A*T,t[2]=h*s+n*u+b*S+A*w,t[3]=h*m+n*d+b*l+A*v,h=i[4],n=i[5],b=i[6],A=i[7],t[4]=h*r+n*f+b*y+A*x,t[5]=h*a+n*p+b*R+A*T,t[6]=h*s+n*u+b*S+A*w,t[7]=h*m+n*d+b*l+A*v,h=i[8],n=i[9],b=i[10],A=i[11],t[8]=h*r+n*f+b*y+A*x,t[9]=h*a+n*p+b*R+A*T,t[10]=h*s+n*u+b*S+A*w,t[11]=h*m+n*d+b*l+A*v,h=i[12],n=i[13],b=i[14],A=i[15],t[12]=h*r+n*f+b*y+A*x,t[13]=h*a+n*p+b*R+A*T,t[14]=h*s+n*u+b*S+A*w,t[15]=h*m+n*d+b*l+A*v,t}function jt(t,e,i,r){let a=e[0],s=e[1],m=e[2],f=e[3],p=a+a,u=s+s,d=m+m,y=a*p,R=a*u,S=a*d,l=s*u,x=s*d,T=m*d,w=f*p,v=f*u,h=f*d,n=r[0],b=r[1],A=r[2];return t[0]=(1-(l+T))*n,t[1]=(R+h)*n,t[2]=(S-v)*n,t[3]=0,t[4]=(R-h)*b,t[5]=(1-(y+T))*b,t[6]=(x+w)*b,t[7]=0,t[8]=(S+v)*A,t[9]=(x-w)*A,t[10]=(1-(y+l))*A,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function bt(t,e,i=0){let r=e[0],a=e[1],s=e[2],m=e[4],f=e[5],p=e[6],u=e[8],d=e[9],y=e[10],R=y*f-p*d,S=-y*m+p*u,l=d*m-f*u,x=r*R+a*S+s*l;return!x||i>0&&(!Number.isFinite(x)||Math.abs(x)<=i)||(x=1/x,t[0]=R*x,t[1]=S*x,t[2]=l*x,t[3]=(-y*a+s*d)*x,t[4]=(y*r-s*u)*x,t[5]=(-d*r+a*u)*x,t[6]=(p*a-s*f)*x,t[7]=(-p*r+s*m)*x,t[8]=(f*r-a*m)*x),t}function Me(t,e){let i=e[0],r=e[1],a=e[2],s=e[3],m=e[4],f=e[5],p=e[6],u=e[7],d=e[8],y=e[9],R=e[10],S=e[11],l=e[12],x=e[13],T=e[14],w=e[15],v=i*f-r*m,h=i*p-a*m,n=i*u-s*m,b=r*p-a*f,A=r*u-s*f,$=a*u-s*p,B=d*x-y*l,_=d*T-R*l,L=d*w-S*l,C=y*T-R*x,D=y*w-S*x,M=R*w-S*T,o=v*M-h*D+n*C+b*L-A*_+$*B;return o?(o=1/o,t[0]=(f*M-p*D+u*C)*o,t[1]=(a*D-r*M-s*C)*o,t[2]=(x*$-T*A+w*b)*o,t[3]=(R*A-y*$-S*b)*o,t[4]=(p*L-m*M-u*_)*o,t[5]=(i*M-a*L+s*_)*o,t[6]=(T*n-l*$-w*h)*o,t[7]=(d*$-R*n+S*h)*o,t[8]=(m*D-f*L+u*B)*o,t[9]=(r*L-i*D-s*B)*o,t[10]=(l*A-x*n+w*v)*o,t[11]=(y*n-d*A-S*v)*o,t[12]=(f*_-m*C-p*B)*o,t[13]=(i*C-r*_+a*B)*o,t[14]=(x*h-l*b-T*v)*o,t[15]=(d*b-y*h+R*v)*o,t):null}function zt(t,e,i,r,a){let s=a[0]*e+a[4]*i+a[8]*r+a[12],m=a[1]*e+a[5]*i+a[9]*r+a[13],f=a[2]*e+a[6]*i+a[10]*r+a[14],p=a[3]*e+a[7]*i+a[11]*r+a[15],u=p!==0?1/p:1;t[0]=s*u,t[1]=m*u,t[2]=f*u}function we(t,e,i,r,a,s,m,f,p,u,d,y,R,S,l,x,T=0){let w=u-m,v=d-f,h=y-p,n=R-m,b=S-f,A=l-p,$=a*A-s*b,B=s*n-r*A,_=r*b-a*n,L=w*$+v*B+h*_;if(L>-1e-7&&L<1e-7)return!1;let C=1/L,D=t-m,M=e-f,o=i-p,V=C*(D*$+M*B+o*_);if(V<-T||V>1+T)return!1;let X=M*h-o*v,g=o*w-D*h,I=D*v-M*w,c=C*(r*X+a*g+s*I);if(c<-T||V+c>1+T)return!1;let P=C*(n*X+b*g+A*I);if(P>1e-4&&P<x.distance){x.distance=P,x.point=[t+r*P,e+a*P,i+s*P];let j=v*A-h*b,G=h*n-w*A,U=w*b-v*n,Z=Math.hypot(j,G,U)||1;return x.normal=[j/Z,G/Z,U/Z],!0}return!1}function Te(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let d=0;d<i;d++)r.push(nt());if(i===0)return r;let a=new Set;for(let d of t.nodes)if(Array.isArray(d.children))for(let y of d.children)a.add(y);let s=new Set,m=128,f=(d,y,R=0)=>{if(R>m||d<0||d>=i||s.has(d))return;s.add(d);let S=t.nodes[d];if(!S)return;let l=nt();if(e&&e[d])l.set(e[d]);else if(S.matrix&&S.matrix.length===16)l.set(S.matrix);else{let T=S.translation||[0,0,0],w=S.rotation||[0,0,0,1],v=S.scale||[1,1,1];jt(l,w,T,v)}let x=r[d];if(y?ct(x,y,l):x.set(l),Array.isArray(S.children))for(let T of S.children)typeof T=="number"&&f(T,x,R+1)},p=[],u=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(u&&Array.isArray(u.nodes))p.push(...u.nodes);else for(let d=0;d<i;d++)a.has(d)||p.push(d);for(let d of p)f(d,null);for(let d=0;d<i;d++)!a.has(d)&&!p.includes(d)&&f(d,null);return r}var Gt=["neutral","reinhard","none","aces","agx"];function Vt(t){let e=String(t??"").trim().toLowerCase();return Gt.includes(e)?e:"neutral"}function Pe(t){return Gt.indexOf(Vt(t))}function Ae(t){return new TextDecoder().decode(t)}var Kt=pt().decoders;function Ce(t,e){Kt.set(t.toLowerCase(),e)}function yt(t){return Kt.get(t.toLowerCase())}function qt(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let R=i.getUint8(0);throw R===123||R===32||R===10||R===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let a=i.getUint32(4,!0);if(a!==2)throw new Error(`Unsupported GLB version: ${a}`);let s=i.getUint32(8,!0),m=12,f=null,p=null;for(;m+8<=s&&m+8<=e.byteLength;){let R=i.getUint32(m,!0),S=i.getUint32(m+4,!0),l=m+8;if(l+R>e.byteLength)throw new Error(`Truncated GLB chunk: required ${l+R} bytes, buffer has ${e.byteLength}`);if(S===1313821514){let x=new Uint8Array(e,l,R),T=Ae(x);f=JSON.parse(T,(w,v)=>w==="__proto__"||w==="constructor"||w==="prototype"?void 0:v)}else S===5130562&&(p=e.slice(l,l+R));m=l+R}if(!f)throw new Error("Missing JSON chunk in GLB");let u=f.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!yt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let R of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(R)&&!yt("meshopt"))throw new Error(`Model requires ${R}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!yt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let d=p||new ArrayBuffer(0),y={gltf:f,bin:d,animations:[]};for(let R of ht)R.onParseGLB?.(y);return y}function Re(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function At(t){if(Re(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return qt(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xt=`#version 300 es
|
|
18
17
|
layout(location=0) in vec3 aPos;
|
|
19
18
|
layout(location=3) in vec3 aOff;
|
|
20
19
|
layout(location=1) in vec3 aNormal;
|
|
@@ -49,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
49
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
50
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
51
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
52
|
-
}`,
|
|
51
|
+
}`,De=`#version 300 es
|
|
53
52
|
precision highp float;
|
|
54
53
|
in vec3 vNormal,vWorldPos;
|
|
55
54
|
in vec2 vUV;
|
|
@@ -66,7 +65,8 @@ uniform float uNormalScale,uOcclusionStrength;
|
|
|
66
65
|
uniform vec2 uViewportSize;
|
|
67
66
|
uniform vec4 uSectionPlane;
|
|
68
67
|
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
69
|
-
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
|
|
68
|
+
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
|
|
69
|
+
uniform vec2 uPointLightSpotCone[2];
|
|
70
70
|
out vec4 fragColor;
|
|
71
71
|
|
|
72
72
|
vec2 envBRDF(float r,float n){
|
|
@@ -157,6 +157,11 @@ if(mode==4)return agxToneMapping(color);
|
|
|
157
157
|
return color;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 base,float specExp,float specWeight){
|
|
161
|
+
float NoH=max(dot(N,normalize(L+V)),0.0);
|
|
162
|
+
return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
163
|
+
}
|
|
164
|
+
|
|
160
165
|
void main(){
|
|
161
166
|
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
162
167
|
vec4 base=uBaseColor;
|
|
@@ -194,24 +199,16 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
|
194
199
|
vec3 directLight=vec3(0.0);
|
|
195
200
|
for(int i=0;i<2;i++){
|
|
196
201
|
if(i>=uNumDirLights)break;
|
|
197
|
-
|
|
198
|
-
float NdotL=max(dot(N,L),0.0);
|
|
199
|
-
vec3 H=normalize(L+V);
|
|
200
|
-
float NoH=max(dot(N,H),0.0);
|
|
201
|
-
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
202
|
-
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
|
|
202
|
+
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i];
|
|
203
203
|
}
|
|
204
204
|
for(int i=0;i<2;i++){
|
|
205
205
|
if(i>=uNumPointLights)break;
|
|
206
206
|
vec3 toLight=uPointLightPos[i]-vWorldPos;
|
|
207
207
|
float dist=length(toLight);
|
|
208
208
|
vec3 L=toLight/max(dist,0.0001);
|
|
209
|
-
float
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
float NoH=max(dot(N,H),0.0);
|
|
213
|
-
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
214
|
-
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
|
|
209
|
+
float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
|
|
210
|
+
spotAtt*=spotAtt;
|
|
211
|
+
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist);
|
|
215
212
|
}
|
|
216
213
|
|
|
217
214
|
vec3 R=reflect(-V,N);
|
|
@@ -242,80 +239,103 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
242
239
|
float outAlpha=base.a;
|
|
243
240
|
/*XRD_O*/
|
|
244
241
|
fragColor=vec4(color,outAlpha);
|
|
245
|
-
}
|
|
242
|
+
}`,Se=`#version 300 es
|
|
246
243
|
layout(location=0) in vec3 aPosition;
|
|
247
244
|
uniform mat4 uMVP;
|
|
248
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
245
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Ie=`#version 300 es
|
|
249
246
|
precision highp float;
|
|
250
247
|
uniform vec4 uColorId;
|
|
251
248
|
out vec4 fragColor;
|
|
252
|
-
void main(){fragColor=uColorId;}`;function Ie(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var Ve=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Xe(){let n=ue().xrDepthShader;return{fs:ot.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Ve,...n.uniformNames]:Ve}}function ct(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Ce(n,e,t,r,i,s,a,d){if(r===void 0||!e.accessors?.[r])return null;let o=Ee(e,t,e.accessors[r],s);if(!o)return null;d&&(o=o.slice(),Ue(o,d));let c=n.createBuffer();return a.push(c),n.bindBuffer(34962,c),n.bufferData(34962,o,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),o}function Le(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function qe(n,e,t){let r=Xe(),i=We,s=r.fs,a=!1;for(let o of ne)if(o.onResolveShader){let c=o.onResolveShader(e,t,i,s);c&&(i=c.vs,s=c.fs,a=!0)}let d=a?ye(n,i,s):null;return{program:d,uniforms:d?Ie(n,d,r.uniforms):null}}function lt(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,a=new Float32Array(i*20);for(let o=0;o<i;o++)a.set(r.subarray(o*16,o*16+16),o*20),a[o*20+16]=s?s[o*3]:1,a[o*20+17]=s?s[o*3+1]:1,a[o*20+18]=s?s[o*3+2]:1,a[o*20+19]=1;let d=n.createBuffer();t.push(d),n.bindBuffer(34962,d),n.bufferData(34962,a,35044);for(let o=0;o<5;o++)n.enableVertexAttribArray(8+o),n.vertexAttribPointer(8+o,4,5126,!1,80,o*16),n.vertexAttribDivisor(8+o,1);return!0}function mt(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var _t=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ke=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Te(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function Ye(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=a=>a!==void 0&&e[a.index]?e[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ze(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&n.deleteVertexArray(a.vao),a.buffers)for(let o of a.buffers)n.deleteBuffer(o);i(a.texture),i(a.metallicRoughnessTexture),i(a.normalTexture),i(a.occlusionTexture);let d=new Set;a.customProgram&&d.add(a.customProgram);for(let o of a.programCache?.values()??[])o.program&&d.add(o.program);for(let o of d)n.deleteProgram(o)}if(t)for(let s of t)i(s)}function Oe(n,e,t=Ke,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ht(n,e,t,r,i)}catch(s){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Ze(n,a,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let d of i.buffers)n.deleteBuffer(d);throw s}}function ht(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=me("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let d=e.bin,o=[];i.meshes=o;let c=[],u=s.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((m,R)=>{c.push(typeof m?.name=="string"&&m.name?m.name:`Variant_${R}`)});let b=Me(s),v=[];if(Array.isArray(s.nodes))for(let m=0;m<s.nodes.length;m++){let R=s.nodes[m];R.mesh!==void 0&&s.meshes&&s.meshes[R.mesh]&&v.push({node:R,nodeIdx:m,meshIdx:R.mesh})}let L=v.length>0?v:(s.meshes||[]).map((m,R)=>({node:m,nodeIdx:-1,meshIdx:R})),E=[];if(Array.isArray(e.lights)&&e.lights.length>0)E.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let m=s.extensions.KHR_lights_punctual.lights;for(let R of m){let p=R.type==="directional"?"directional":R.type==="point"?"point":"ambient";E.push({type:p,color:R.color||[1,1,1],intensity:R.intensity!==void 0?R.intensity:1})}}if(E.length===0&&(E.push({type:"ambient",color:[1,1,1],intensity:.35}),E.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),L.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${L.length}`);let x=[];if(i.gpuTextures=x,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let m=0;m<s.textures.length;m++){let R=s.textures[m],p=s.images[R.source];if(p){let g=n.createTexture();if(n.bindTexture(3553,g),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),p.bufferView!==void 0){let _=s.bufferViews[p.bufferView],P=d.slice(_.byteOffset||0,(_.byteOffset||0)+_.byteLength),G=new Blob([P],{type:p.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(G).then(N=>{n.bindTexture(3553,g),n.texImage2D(3553,0,6408,6408,5121,N),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(p.uri){let _=ct(p.uri);if(_){let P=new Image;P.crossOrigin="anonymous",P.referrerPolicy="no-referrer",P.onload=()=>{n.bindTexture(3553,g),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()},P.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",p.uri)}x.push(g)}else x.push(null)}}let T=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0],F=0,h=0;for(let m=0;m<L.length;m++){let R=L[m],p=s.meshes[R.meshIdx],g=R.nodeIdx>=0?b[R.nodeIdx]:J(),_=new Float32Array(9);ae(_,g);let P={name:R.node.name||p.name||`Mesh_${R.meshIdx}`,nodeIndex:R.nodeIdx,transform:g,normalMatrix:_,primitives:[],extras:R.node.extras||p.extras};i.mesh=P;let G=R.node?.extensions?.EXT_mesh_gpu_instancing;if(G&&G.attributes&&typeof G.attributes=="object"){let N=G.attributes,k=N.TRANSLATION!==void 0?s.accessors?.[N.TRANSLATION]:null,M=N.ROTATION!==void 0?s.accessors?.[N.ROTATION]:null,H=N.SCALE!==void 0?s.accessors?.[N.SCALE]:null,O=N._COLOR_0!==void 0?s.accessors?.[N._COLOR_0]:null,B=Number(k?.count??M?.count??H?.count??0);if(!Number.isFinite(B)||B<0||B>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${B}`);if(B>0){let z=(X,Z)=>{if(!X||X.bufferView===void 0||!s.bufferViews?.[X.bufferView])return null;let re=X.componentType??5126,oe=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(re!==5120&&re!==5121&&re!==5122&&re!==5123&&re!==5126)return oe(`componentType ${re}`);if(!(Number(X.count)>=B))return oe(`count ${X.count} < ${B}`);let Y=null;try{Y=Ee(s,d,{...X,count:B},Z)}catch{return oe("out of bounds")}return!Y||!Y.every(Number.isFinite)?oe("non-finite value"):Y},C=z(k,3),V=z(M,4),$=z(H,3),W=O?.type==="VEC4"?4:3,q=z(O,W),te=new Float32Array(B*16),se=J();for(let X=0;X<B;X++){let Z=C?[C[X*3],C[X*3+1],C[X*3+2]]:[0,0,0],re=V?[V[X*4],V[X*4+1],V[X*4+2],V[X*4+3]]:[0,0,0,1],oe=$?[$[X*3],$[X*3+1],$[X*3+2]]:[1,1,1];he(se,re,Z,oe),te.set(se,X*16)}if(P.instanceMatrices=te,q){let X=new Float32Array(B*3);for(let Z=0;Z<B;Z++)X[Z*3]=q[Z*W],X[Z*3+1]=q[Z*W+1],X[Z*3+2]=q[Z*W+2];P.instanceColors=X}}}for(let N of p.primitives||[]){if(N.extensions?.KHR_draco_mesh_compression){let Y=me("draco");Y&&Y.decodePrimitive(s,N,d)}let k=[],M=n.createVertexArray();i.vao=M,i.buffers=k,n.bindVertexArray(M);let H=lt(n,P,k),O=s.accessors[N.attributes.POSITION],B=Number(O?.count??0);if(!Number.isFinite(B)||B<0||F+B>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(F+=B,O?.min&&O?.max){let Y=Q=>{for(let j=0;j<3;j++){let ie=Q[12+j],ce=Q[12+j];for(let le=0;le<3;le++){let pe=Q[le*4+j]*O.min[le],be=Q[le*4+j]*O.max[le];ie+=pe<be?pe:be,ce+=pe>be?pe:be}ie<T[j]&&(T[j]=ie),ce>I[j]&&(I[j]=ce)}};if(P.instanceMatrices&&P.instanceMatrices.length>=16){let Q=P.instanceMatrices.length>>4,j=J();for(let ie=0;ie<Q;ie++){let ce=P.instanceMatrices.subarray(ie*16,ie*16+16);ee(j,g,ce),Y(j)}}else Y(g)}let z=Ce(n,s,d,N.attributes.POSITION,0,3,k);Ce(n,s,d,N.attributes.NORMAL,1,3,k),Ce(n,s,d,N.attributes.TEXCOORD_0,2,2,k,mt(s,N));let C=0,V=5123,$=null;if(N.indices!==void 0){let Y=s.accessors[N.indices],j=(s.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(C=Number(Y.count??0),!Number.isFinite(C)||C<0||h+C>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);h+=C,V=Y.componentType===5125?5125||5125:5123||5123;let ie=n.createBuffer();k.push(ie),n.bindBuffer(34963,ie),Y.componentType===5125?($=new Uint32Array(d,j,Y.count),n.bufferData(34963,$,35044)):Y.componentType===5121?($=Uint16Array.from(new Uint8Array(d,j,Y.count)),n.bufferData(34963,$,35044)):($=j%2===0?new Uint16Array(d,j,Y.count):new Uint16Array(d.slice(j,j+Y.count*2)),n.bufferData(34963,$,35044))}else C=O.count;let W={};for(let Y of ne)if(Y.onBuildPrimitiveVAO){let Q=Y.onBuildPrimitiveVAO(n,M,N,s,d);Q&&(W[Y.name]=Q)}n.bindVertexArray(null);let q=s.materials&&N.material!==void 0?s.materials[N.material]:null,{program:te,uniforms:se}=qe(n,N,q),X=Ye(q,x),Z=!!(q?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),re=N.extensions?.KHR_materials_variants?.mappings,oe=Array.isArray(re)?re.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(Q=>Number(Q)|0)})):void 0;P.primitives.push({vao:M,instanced:H,indexCount:C,indexType:V,...X,positions:z,indices:$,buffers:k,materialIndex:N.material,defaultMaterialIndex:N.material,variantMappings:oe,primitiveDef:N,programCache:new Map([[N.material??-1,{program:te,uniforms:se}]]),pluginData:W,customProgram:te,customUniforms:se,isTransmissive:Z})}o.push(P)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(I[0])||(I=[1,1,1]);let w=[(T[0]+I[0])/2,(T[1]+I[1])/2,(T[2]+I[2])/2],f=I[0]-T[0],S=I[1]-T[1],U=I[2]-T[2],A=Math.max(Math.hypot(f,S,U)/2,.5),y=[T[0],T[1],T[2]],D=[I[0],I[1],I[2]],l=e.animations;if(!l){for(let m of ne)if(m.onParseGLB?.(e),e.animations){l=e.animations;break}}return l||(l=[]),{meshes:o,bounds:{center:w,radius:A,min:y,max:D},lights:E,animations:l,worldMatrices:b,gpuTextures:x,availableVariants:c}}function fe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var Ae=class{constructor(e,t,r){this.supportsInstanceOffsets=!0;this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.activeViewMatrix=null;this.modelMatrix=J();this.mvpMatrix=J();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:J(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Le(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=Pe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let d=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!d)throw new Error("WebGL2 not supported");this.gl=d,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){it(e,t)}static getDecoder(e){return me(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=Xe();this.renderProg=ye(e,We,t.fs),this.pickProg=ye(e,at,ut),this.uRender=Ie(e,this.renderProg,t.uniforms),this.uPick=Ie(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ne)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:a,worldMatrices:d,gpuTextures:o,availableVariants:c}=Oe(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=a||[],this.worldMatrices=d||[],this.gpuTextures=o||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let v of e.gltf.nodes)this.initialNodeTransforms.push({t:v.translation?[v.translation[0],v.translation[1],v.translation[2]]:[0,0,0],r:v.rotation?[v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]]:[0,0,0,1],s:v.scale?[v.scale[0],v.scale[1],v.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let v of ne)v.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Le(u));let b=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;b!==void 0&&(this.envIntensity=Math.max(0,Number(b)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData($e(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(de(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=de(e),{meshes:i}=Oe(this.gl,r,Ke,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],ae(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),ae(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],a=[],d=[];for(let o of this.lights){let c=o.color||[1,1,1],u=o.intensity!==void 0?o.intensity:1;if(o.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(o.type==="directional"&&i.length<6){let b=o.direction||[.5,1,.8];i.push(b[0],b[1],b[2]),s.push(c[0]*u,c[1]*u,c[2]*u)}else if(o.type==="point"&&a.length<6){let b=o.position||[0,0,0];a.push(b[0],b[1],b[2]),d.push(c[0]*u,c[1]*u,c[2]*u)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,a.length/3),a.length>0&&(t.uniform3fv(e.uPointLightPos,a),t.uniform3fv(e.uPointLightColor,d)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Le(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Pe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ne)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ne)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(b=>b.materialIndex===r||e.length===1&&b.materialIndex===void 0)),s=i[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],d=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:d,roughnessFactor:o,setBaseColorFactor:u=>{let b=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=b,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=b);for(let v of i)v.baseColor=b;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let b of i)b.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let b of i)b.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let s of this.meshes)for(let a of s.primitives){let d=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){d=c.material;break}}let o=d!==void 0?i[d]:void 0;a.materialIndex=o?d:void 0,Object.assign(a,Ye(o,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=qe(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of ne)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=J();ee(r,this.projMatrix,this.viewMatrix);let[i,s,a]=e,d=t?t[0]:0,o=t?t[1]:0,c=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],s=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],a=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(d=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],c=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let b=r[0]*i+r[4]*s+r[8]*a+r[12],v=r[1]*i+r[5]*s+r[9]*a+r[13],L=r[2]*i+r[6]*s+r[10]*a+r[14],E=r[3]*i+r[7]*s+r[11]*a+r[15];if(E<=1e-4)return{x:0,y:0,z:1,visible:!1};let x=b/E,T=v/E,I=L/E,F=this.canvas.getBoundingClientRect(),h=F.width||this.canvas.clientWidth||this.canvas.width||300,w=F.height||this.canvas.clientHeight||this.canvas.height||150,f=(x*.5+.5)*h,S=(-T*.5+.5)*w,U=x>=-1.1&&x<=1.1&&T>=-1.1&&T<=1.1&&I>=-1&&I<=1;if(U&&t){let[A,y,D]=fe(this),l=[i-A,s-y,a-D];d*l[0]+o*l[1]+c*l[2]>.05&&(U=!1)}return{x:f,y:S,z:I,visible:U}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],d=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],o=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;o[0]+=(-i*a[0]+s*d[0])*c,o[1]+=(-i*a[1]+s*d[1])*c,o[2]+=(-i*a[2]+s*d[2])*c,this.customTarget=o}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,a=r.height||300,d=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(a/i.height)):Math.floor(t);return this.performMeshPick(d,o,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let d=J();ee(d,this.projMatrix,this.viewMatrix);let o=[],c=Math.max(0,Math.min(s-1,e)),u=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,a),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let U=0;U<this.meshes.length;U++){let A=this.meshes[U];if(A.visible===!1||A.isPluginMesh)continue;let y=U+1,D=(y&255)/255,l=(y>>8&255)/255,m=(y>>16&255)/255;i.uniform4f(this.uPick.uColorId,D,l,m,1),ee(this.modelMatrix,this.modelRootMatrix,A.transform);let R=A.instanceMatrices;if(R&&R.length>=16){let p=R.length>>4,g=J();for(let _ of A.primitives){i.bindVertexArray(_.vao);for(let P=0;P<p;P++)ee(g,this.modelMatrix,R.subarray(P*16,P*16+16)),ee(this.mvpMatrix,d,g),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Te(i,_)}}else{ee(this.mvpMatrix,d,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let p of A.primitives)i.bindVertexArray(p.vao),Te(i,p)}}let f=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,f),i.bindFramebuffer(36160,null);let S=f[0]+(f[1]<<8)+(f[2]<<16);S>0&&S<=this.meshes.length&&(o=[this.meshes[S-1]])}o.length===0&&(o=this.meshes.filter(f=>f.visible!==!1));let b=null,v=1/0,L=[0,0,0],E=[0,1,0],[x,T,I]=fe(this),F=J();for(let f of o){ee(F,this.modelRootMatrix,f.transform);let S=f.instanceMatrices,U=S&&S.length>=16?S.length>>4:1;for(let A=0;A<U;A++){S&&S.length>=16?ee(this.modelMatrix,F,S.subarray(A*16,A*16+16)):this.modelMatrix.set(F),ee(this.mvpMatrix,d,this.modelMatrix);let y=J();if(!ke(y,this.mvpMatrix))continue;let D=(c+.5)/s*2-1,l=(u+.5)/a*2-1,m=[0,0,0],R=[0,0,0];De(m,D,l,-1,y),De(R,D,l,1,y);let p=R[0]-m[0],g=R[1]-m[1],_=R[2]-m[2],P=Math.hypot(p,g,_)||1,G=p/P,N=g/P,k=_/P,M={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((O=>{for(let B of f.primitives){if(!B.positions)continue;let z=B.positions,C=B.indices,V=Math.floor(C?C.length/3:z.length/9);for(let $=0;$<V;$++){let W=C?C[$*3]:$*3,q=C?C[$*3+1]:$*3+1,te=C?C[$*3+2]:$*3+2;Ge(m[0],m[1],m[2],G,N,k,z[W*3],z[W*3+1],z[W*3+2],z[q*3],z[q*3+1],z[q*3+2],z[te*3],z[te*3+1],z[te*3+2],M,O)}}})(1e-4),isFinite(M.distance)){let O=M.point[0],B=M.point[1],z=M.point[2],C=this.modelMatrix,V=C[0]*O+C[4]*B+C[8]*z+C[12],$=C[1]*O+C[5]*B+C[9]*z+C[13],W=C[2]*O+C[6]*B+C[10]*z+C[14],q=V-x,te=$-T,se=W-I,X=Math.hypot(q,te,se);if(X<v){ae(this.normalMatrix,this.modelMatrix);let Z=this.normalMatrix,re=M.normal[0],oe=M.normal[1],Y=M.normal[2],Q=Z[0]*re+Z[3]*oe+Z[6]*Y,j=Z[1]*re+Z[4]*oe+Z[7]*Y,ie=Z[2]*re+Z[5]*oe+Z[8]*Y,ce=Math.hypot(Q,j,ie)||1;Q/=ce,j/=ce,ie/=ce,Q*q+j*te+ie*se>0&&(Q=-Q,j=-j,ie=-ie),b=f,v=Math.round(X*1e3)/1e3,L=[Math.round(V*1e3)/1e3,Math.round($*1e3)/1e3,Math.round(W*1e3)/1e3],E=[Math.round(Q*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(ie*1e3)/1e3]}}}}if(!b)return null;let w={meshIndex:this.meshes.indexOf(b),meshName:b.name,nodeIndex:b.nodeIndex,distance:v,hitPoint:L,normal:E,screenX:e,screenY:t};if(r){for(let f of ne)f.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,a=i?Math.max(1,t-r):r,d=(s+.5)/a*2-1;return Math.floor((d*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);ve(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;xe(this.viewMatrix,fe(this),r,[0,1,0]),ee(this.mvpMatrix,this.projMatrix,this.viewMatrix),ae(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of ne)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of ne)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let a of ne)a.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let a of ne)a.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let a={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,t,r,i,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let d=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:d,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let h=Math.max(2,this.canvas.width||2),w=Math.max(1,this.canvas.height||1),f=Math.max(1,Math.floor(h*.5)),S=Math.max(1,h-f),U=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),A=this.customTarget||this.bounds.center,[y,D,l]=fe(this),m=Math.cos(this.currTheta),R=-Math.sin(this.currTheta),p=.032,g=J(),_=J(),P=[y-m*p,D,l-R*p],G=[A[0]-m*p*.25,A[1],A[2]-R*p*.25];ve(g,this.fov,f/w,.1,U),xe(_,P,G,[0,1,0]);let N=J(),k=J(),M=[y+m*p,D,l+R*p],H=[A[0]+m*p*.25,A[1],A[2]+R*p*.25];ve(N,this.fov,S/w,.1,U),xe(k,M,H,[0,1,0]),this.render({viewMatrix:_,projMatrix:g,eyePos:P,viewport:[0,0,f,w],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:k,projMatrix:N,eyePos:M,viewport:[f,0,S,w],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,h,w);return}let t=this.gl,r=0,i=0,s=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],a=e.viewport[3],t.viewport(r,i,s,a)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let d=J(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,ee(d,e?.projMatrix??this.projMatrix,o);let c=ue().xrDepthShader,u=nt(this.toneMapping),[b,v,L]=e?e.eyePos:fe(this);for(let h of ne)h.onBeforeDrawScene?.(this,t,d,[b,v,L],u);let E=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&E===0)return;let x=e?.eye||"none",T=!1,I=E>0?[...this.backdropMeshes,...this.meshes]:this.meshes,F=h=>{for(let w=0;w<I.length;w++){let f=I[w];if(f.visible===!1)continue;let S=this.selectedMeshName!==""&&f.name===this.selectedMeshName;w<E||f.worldSpace===!0||f.name==="__xr_reticle__"?this.modelMatrix.set(f.transform):ee(this.modelMatrix,this.modelRootMatrix,f.transform),ee(this.mvpMatrix,d,this.modelMatrix),ae(f.normalMatrix,this.modelMatrix);let U=f.extras?.xr?.stereo||f.userData?.xr?.stereo,A=0,y=0,D=1,l=1;U==="sbs"?(D=.5,A=x==="right"?.5:0):U==="ou"&&(l=.5,y=x==="right"?.5:0);for(let m of f.primitives){let R=!!m.isTransmissive;if(!h&&R){T=!0;continue}if(h&&!R)continue;let p=m.customProgram||this.renderProg,g=m.customUniforms||this.uRender;t.useProgram(p),t.vertexAttrib3f(3,0,0,0),g.uInstanced&&t.uniform1i(g.uInstanced,0),t.uniform1i(g.uToneMapping,u),t.uniform1f(g.uEnvIntensity,this.envIntensity),g.uExposure&&t.uniform1f(g.uExposure,this.exposure),t.uniform3f(g.uCameraPos,b,v,L),t.uniform1f(g.uEmissive,S?1:0),t.uniformMatrix4fv(g.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(g.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(g.uNormalMatrix,!1,f.normalMatrix),g.uUvTransform&&t.uniform4f(g.uUvTransform,A,y,D,l),g.uViewportSize&&t.uniform2f(g.uViewportSize,Math.max(1,s),Math.max(1,a)),c?.bind(t,g,this.xrDepthState,o,[r,i,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(g.uEnvironmentMap,4),t.uniform1i(g.uHasEnvironmentMap,1)):t.uniform1i(g.uHasEnvironmentMap,0),this.bindLights(g),g.uSectionEnabled&&t.uniform1i(g.uSectionEnabled,0);for(let P of ne)P.onBeforeDrawPrimitive?.(t,p,m,f,this.worldMatrices||[],this.gltf);t.uniform4fv(g.uBaseColor,m.baseColor),t.uniform1f(g.uMetallic,m.metallic),t.uniform1f(g.uRoughness,m.roughness),g.uClearcoat&&t.uniform2f(g.uClearcoat,m.clearcoat??0,m.clearcoatRoughness??.04),m.texture?(t.activeTexture(33984),t.bindTexture(3553,m.texture),t.uniform1i(g.uBaseColorTexture,0),t.uniform1i(g.uHasTexture,1)):t.uniform1i(g.uHasTexture,0),m.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,m.metallicRoughnessTexture),t.uniform1i(g.uMetallicRoughnessTexture,1),t.uniform1i(g.uHasMetallicRoughnessTexture,1)):t.uniform1i(g.uHasMetallicRoughnessTexture,0),m.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,m.normalTexture),t.uniform1i(g.uNormalTexture,2),t.uniform1i(g.uHasNormalTexture,1),t.uniform1f(g.uNormalScale,m.normalScale)):t.uniform1i(g.uHasNormalTexture,0),m.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,m.occlusionTexture),t.uniform1i(g.uOcclusionTexture,3),t.uniform1i(g.uHasOcclusionTexture,1),t.uniform1f(g.uOcclusionStrength,m.occlusionStrength)):t.uniform1i(g.uHasOcclusionTexture,0),t.bindVertexArray(m.vao);let _=f.instanceMatrices;if(m.instanceCount!==void 0)t.drawElementsInstanced(4,m.indexCount,m.indexType,0,m.instanceCount);else if(_&&_.length>=16&&m.instanced&&g.uInstanced&&g.uViewProj){let P=_.length>>4;t.uniform1i(g.uInstanced,1),t.uniformMatrix4fv(g.uViewProj,!1,d),m.indices?t.drawElementsInstanced(4,m.indexCount,m.indexType,0,P):t.drawArraysInstanced(4,0,m.indexCount,P),t.uniform1i(g.uInstanced,0)}else if(_&&_.length>=16){let P=_.length>>4,G=f.instanceColors,N=J(),k=new Float32Array(9),M=[m.baseColor[0],m.baseColor[1],m.baseColor[2],m.baseColor[3]];for(let H=0;H<P;H++)ee(N,this.modelMatrix,_.subarray(H*16,H*16+16)),ee(this.mvpMatrix,d,N),ae(k,N),t.uniformMatrix4fv(g.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(g.uModel,!1,N),t.uniformMatrix3fv(g.uNormalMatrix,!1,k),G&&(M[0]=m.baseColor[0]*G[H*3],M[1]=m.baseColor[1]*G[H*3+1],M[2]=m.baseColor[2]*G[H*3+2],M[3]=m.baseColor[3],t.uniform4fv(g.uBaseColor,M)),Te(t,m)}else Te(t,m)}}};if(F(!1),T){for(let h of ne)h.onBeforeTransmissivePass?.(t,this);F(!0)}for(let h of ne)h.onAfterRender?.(t,this,d,e?.eye??"none",[r,i,s,a],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){Ze(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of ne)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Ae.registerPlugin=Ne,Ae.getRegisteredPlugins=Be;function ft(n){return n+3&-4}function dt(n,e=0){let t=(M,H)=>typeof M=="number"&&Number.isFinite(M)?M:H,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),a=t(n[e+0],1),d=t(n[e+1],0),o=t(n[e+2],0),c=t(n[e+4],0),u=t(n[e+5],1),b=t(n[e+6],0),v=t(n[e+8],0),L=t(n[e+9],0),E=t(n[e+10],1),x=Math.hypot(a,d,o),T=Math.hypot(c,u,b),I=Math.hypot(v,L,E);a*(u*E-L*b)-c*(d*E-L*o)+v*(d*b-u*o)<0&&(x=-x);let h=Math.abs(x)>1e-8?1/x:0,w=Math.abs(T)>1e-8?1/T:0,f=Math.abs(I)>1e-8?1/I:0,S=a*h,U=d*h,A=o*h,y=c*w,D=u*w,l=b*w,m=v*f,R=L*f,p=E*f,g=S+D+p,_=0,P=0,G=0,N=1;if(g>0){let M=.5/Math.sqrt(g+1);N=.25/M,_=(l-R)*M,P=(m-A)*M,G=(U-y)*M}else if(S>D&&S>p){let M=2*Math.sqrt(Math.max(0,1+S-D-p));M>1e-8&&(N=(l-R)/M,_=.25*M,P=(y+U)/M,G=(m+A)/M)}else if(D>p){let M=2*Math.sqrt(Math.max(0,1+D-S-p));M>1e-8&&(N=(m-A)/M,_=(y+U)/M,P=.25*M,G=(l+R)/M)}else{let M=2*Math.sqrt(Math.max(0,1+p-S-D));M>1e-8&&(N=(U-y)/M,_=(m+A)/M,P=(l+R)/M,G=.25*M)}let k=Math.hypot(_,P,G,N);return k>1e-8&&Number.isFinite(k)?(_/=k,P/=k,G/=k,N/=k):(_=0,P=0,G=0,N=1),{t:[r,i,s],r:[_,P,G,N],s:[x,T,I]}}function pt(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function bt(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],a=[],d=[],o=new Set,c=[],u=[],b=new Map,v=[],L=[];function E(y){let D=b.get(y);if(D!==void 0)return D;D=u.length,b.set(y,D);let l=y,m=l.color?.r??.8,R=l.color?.g??.8,p=l.color?.b??.8,g=l.opacity??1,_={name:l.name||"",pbrMetallicRoughness:{baseColorFactor:[m,R,p,g],metallicFactor:l.metalness??.1,roughnessFactor:l.roughness??.5},doubleSided:l.side===2||!!l.doubleSided};if(l.emissive&&(l.emissive.r>0||l.emissive.g>0||l.emissive.b>0)){let G=l.emissiveIntensity??1;_.emissiveFactor=[l.emissive.r*G,l.emissive.g*G,l.emissive.b*G]}let P={};return l.clearcoat&&l.clearcoat>0&&(P.KHR_materials_clearcoat={clearcoatFactor:l.clearcoat,clearcoatRoughnessFactor:l.clearcoatRoughness||0}),l.sheen&&l.sheen>0&&(P.KHR_materials_sheen={sheenColorFactor:l.sheenColor?[l.sheenColor.r,l.sheenColor.g,l.sheenColor.b]:[1,1,1],sheenRoughnessFactor:l.sheenRoughness||0}),l.transmission&&l.transmission>0&&(P.KHR_materials_transmission={transmissionFactor:l.transmission}),l.thickness&&l.thickness>0&&(P.KHR_materials_volume={thicknessFactor:l.thickness,attenuationDistance:l.attenuationDistance??1/0,attenuationColor:l.attenuationColor?[l.attenuationColor.r,l.attenuationColor.g,l.attenuationColor.b]:[1,1,1]}),l.ior!==void 0&&l.ior!==1.5&&(P.KHR_materials_ior={ior:l.ior}),l.dispersion&&l.dispersion>0&&(P.KHR_materials_dispersion={dispersion:l.dispersion}),l.iridescence&&l.iridescence>0&&(P.KHR_materials_iridescence={iridescenceFactor:l.iridescence,iridescenceIor:l.iridescenceIOR??1.3}),Object.keys(P).length>0&&(_.extensions=P),u.push(_),D}function x(y,D){let l=new Uint8Array(y.buffer,y.byteOffset,y.byteLength),m=ft(l.byteLength),R=new Uint8Array(m);R.set(l),t.push(R);let p=i.length;return i.push({buffer:0,byteOffset:r,byteLength:l.byteLength,target:D}),r+=m,p}function T(y,D,l,m,R,p,g){let _=x(y,l),P=s.length,G={bufferView:_,byteOffset:0,componentType:m,count:R,type:D};return p&&(G.min=p),g&&(G.max=g),s.push(G),P}n.traverse(y=>{(y.isLight||y.color&&y.intensity!==void 0)&&L.push({type:y.type,color:[y.color.r,y.color.g,y.color.b],intensity:y.intensity,position:[y.position.x,y.position.y,y.position.z]})});let I=[];function F(y){let D={name:y.name||""},l=y.position,m=y.quaternion,R=y.scale;if((l.x||l.y||l.z)&&(D.translation=[l.x,l.y,l.z]),(m.x||m.y||m.z||m.w!==1)&&(D.rotation=[m.x,m.y,m.z,m.w]),(R.x!==1||R.y!==1||R.z!==1)&&(D.scale=[R.x,R.y,R.z]),y.userData&&Object.keys(y.userData).length>0&&(D.extras=JSON.parse(JSON.stringify(y.userData,(g,_)=>{if(!(g==="__proto__"||g==="prototype"||g==="constructor"))return typeof _=="function"?void 0:_})),y.userData.xr)){let g=pt(y.userData.xr);D.extensions={...D.extensions||{},MOZ_hubs_components:g,ANDROID_xr_scenecore:g},ue().xrTraitSerializer?.gltfNode(D,y.userData.xr),o.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(y.geometry){let g=y.geometry,_=g.attributes.position;if(_&&_.count>0){let P=[1/0,1/0,1/0],G=[-1/0,-1/0,-1/0];for(let B=0;B<_.count;B++){let z=_.getX(B),C=_.getY(B),V=_.getZ(B);z<P[0]&&(P[0]=z),z>G[0]&&(G[0]=z),C<P[1]&&(P[1]=C),C>G[1]&&(G[1]=C),V<P[2]&&(P[2]=V),V>G[2]&&(G[2]=V)}let k={attributes:{POSITION:T(_.array,"VEC3",34962,5126,_.count,P,G)}};if(g.attributes.normal&&(k.attributes.NORMAL=T(g.attributes.normal.array,"VEC3",34962,5126,g.attributes.normal.count)),g.attributes.uv&&(k.attributes.TEXCOORD_0=T(g.attributes.uv.array,"VEC2",34962,5126,g.attributes.uv.count)),g.index){let B=g.index.array instanceof Uint32Array;k.indices=T(g.index.array,"SCALAR",34963,B?5125:5123,g.index.count)}y.material&&(k.material=E(y.material));let M=y.userData?.variants;if(M&&typeof M=="object"){let B=new Map;for(let z of Object.keys(M)){if(!z||z==="__proto__"||z==="constructor"||z==="prototype")continue;let C=M[z];if(!C||typeof C!="object")continue;let V=v.indexOf(z);if(V===-1&&v.length<256&&(V=v.length,v.push(z)),V===-1)continue;let $=E(C),W=B.get($);W||(W=[],B.set($,W)),W.push(V)}if(B.size>0){let z=[];for(let[C,V]of B.entries())z.push({material:C,variants:V});k.extensions={...k.extensions||{},KHR_materials_variants:{mappings:z}},o.add("KHR_materials_variants")}}let H=y;if(H.isInstancedMesh&&typeof H.count=="number"&&H.count>0&&H.instanceMatrix?.array){let B=Math.min(1e4,Math.floor(H.count)),z=H.instanceMatrix.array,C=new Float32Array(B*3),V=new Float32Array(B*4),$=new Float32Array(B*3);for(let q=0;q<B;q++){let{t:te,r:se,s:X}=dt(z,q*16);C[q*3]=te[0],C[q*3+1]=te[1],C[q*3+2]=te[2],V[q*4]=se[0],V[q*4+1]=se[1],V[q*4+2]=se[2],V[q*4+3]=se[3],$[q*3]=X[0],$[q*3+1]=X[1],$[q*3+2]=X[2]}let W={TRANSLATION:T(C,"VEC3",0,5126,B),ROTATION:T(V,"VEC4",0,5126,B),SCALE:T($,"VEC3",0,5126,B)};if(H.instanceColor?.array&&H.instanceColor.array.length>=B*3){let q=new Float32Array(H.instanceColor.array.subarray(0,B*3));W._COLOR_0=T(q,"VEC3",0,5126,B)}D.extensions={...D.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},o.add("EXT_mesh_gpu_instancing")}let O=a.length;a.push({primitives:[k],name:y.name,...D.extras?{extras:D.extras}:{}}),D.mesh=O}}let p=d.length;if(d.push(D),c.push(y),y.children.length>0){D.children=[];for(let g of y.children)D.children.push(F(g))}return p}for(let y of n.children)I.push(F(y));let h=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),w=[];if(typeof h=="function"&&c.length>0){let y=e?.duration??4,D=e?.fps??15,l=Math.max(2,Math.round(y*D)+1),m=new Float32Array(l),R=c.map(M=>({px:M.position.x,py:M.position.y,pz:M.position.z,qx:M.quaternion.x,qy:M.quaternion.y,qz:M.quaternion.z,qw:M.quaternion.w,sx:M.scale.x,sy:M.scale.y,sz:M.scale.z})),p=c.map(()=>new Float32Array(l*3)),g=c.map(()=>new Float32Array(l*4)),_=c.map(()=>new Float32Array(l*3));for(let M=0;M<l;M++){let H=M/(l-1)*y;m[M]=H;try{h(H)}catch{}for(let O=0;O<c.length;O++){let B=c[O];p[O][M*3]=B.position.x,p[O][M*3+1]=B.position.y,p[O][M*3+2]=B.position.z,g[O][M*4]=B.quaternion.x,g[O][M*4+1]=B.quaternion.y,g[O][M*4+2]=B.quaternion.z,g[O][M*4+3]=B.quaternion.w,_[O][M*3]=B.scale.x,_[O][M*3+1]=B.scale.y,_[O][M*3+2]=B.scale.z}}for(let M=0;M<c.length;M++){let H=c[M],O=R[M];H.position.set(O.px,O.py,O.pz),H.quaternion.set(O.qx,O.qy,O.qz,O.qw),H.scale.set(O.sx,O.sy,O.sz)}n.updateMatrixWorld(!0);let P=null,G=()=>(P===null&&(P=T(m,"SCALAR",0,5126,l,[0],[y])),P),N=[],k=[];for(let M=0;M<c.length;M++){let H=R[M],O=!1,B=!1,z=!1;for(let C=0;C<l;C++)(Math.abs(p[M][C*3]-H.px)>1e-4||Math.abs(p[M][C*3+1]-H.py)>1e-4||Math.abs(p[M][C*3+2]-H.pz)>1e-4)&&(O=!0),(Math.abs(g[M][C*4]-H.qx)>1e-4||Math.abs(g[M][C*4+1]-H.qy)>1e-4||Math.abs(g[M][C*4+2]-H.qz)>1e-4||Math.abs(g[M][C*4+3]-H.qw)>1e-4)&&(B=!0),(Math.abs(_[M][C*3]-H.sx)>1e-4||Math.abs(_[M][C*3+1]-H.sy)>1e-4||Math.abs(_[M][C*3+2]-H.sz)>1e-4)&&(z=!0);if(O){let C=T(p[M],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"translation"}})}if(B){let C=T(g[M],"VEC4",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"rotation"}})}if(z){let C=T(_[M],"VEC3",0,5126,l),V=N.length;N.push({input:G(),interpolation:"LINEAR",output:C}),k.push({sampler:V,target:{node:M,path:"scale"}})}}k.length>0&&w.push({name:"ProceduralLoop",samplers:N,channels:k})}let f=_e(d,a,n.userData),S={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:I}],scene:0,nodes:d,meshes:a,materials:u,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...w.length>0?{animations:w}:{},...f||o.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...o]}:{},...f||v.length>0?{extensions:{...f?{KHR_interactivity:f}:{},...v.length>0?{KHR_materials_variants:{variants:v.map(y=>({name:y}))}}:{}}}:{}},U=new Uint8Array(r),A=0;for(let y of t)U.set(y,A),A+=y.byteLength;return{gltf:S,bin:U.buffer,lights:L,environmentIntensity:n.environmentIntensity}}function we(n){return new TextEncoder().encode(n)}function Gt(n,e){let{gltf:t,bin:r}=bt(n,e),i=JSON.stringify(t),s=we(i),a=(4-s.byteLength%4)%4,d=s.byteLength+a,o=20+d+8+r.byteLength,c=new Uint8Array(o),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,o,!0),u.setUint32(12,d,!0),u.setUint32(16,1313821514,!0),c.set(s,20);for(let v=0;v<a;v++)c[20+s.byteLength+v]=32;let b=20+d;return u.setUint32(b,r.byteLength,!0),u.setUint32(b+4,5130562,!0),c.set(new Uint8Array(r),b+8),c}function gt(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let a=s.count,d=new Float32Array(a*3),o=r.matrixWorld.elements;for(let A=0;A<a;A++){let y=s.getX(A),D=s.getY(A),l=s.getZ(A);d[A*3]=o[0]*y+o[4]*D+o[8]*l+o[12],d[A*3+1]=o[1]*y+o[5]*D+o[9]*l+o[13],d[A*3+2]=o[2]*y+o[6]*D+o[10]*l+o[14]}let c;if(i.attributes.normal){let A=i.attributes.normal;c=new Float32Array(a*3);let y=new Float32Array(9);ae(y,o);for(let D=0;D<a;D++){let l=A.getX(D),m=A.getY(D),R=A.getZ(D),p=y[0]*l+y[3]*m+y[6]*R,g=y[1]*l+y[4]*m+y[7]*R,_=y[2]*l+y[5]*m+y[8]*R,P=Math.hypot(p,g,_)||1;c[D*3]=p/P,c[D*3+1]=g/P,c[D*3+2]=_/P}}let u;if(i.attributes.uv){let A=i.attributes.uv;u=new Float32Array(a*2);for(let y=0;y<a;y++)u[y*2]=A.getX(y),u[y*2+1]=A.getY(y)}let b;if(i.index)b=i.index.array;else{b=a>65535?new Uint32Array(a):new Uint16Array(a);for(let A=0;A<a;A++)b[A]=A}let v="DefaultMaterial",L=[.8,.8,.8],E=.5,x=.1,T=0,I=0,F=1.5,h=1,w=[0,0,0];if(r.material){let A=r.material;v=A.name||`Material_${t.length}`,A.color&&(L=[A.color.r,A.color.g,A.color.b]),typeof A.roughness=="number"&&(E=A.roughness),typeof A.metalness=="number"&&(x=A.metalness),typeof A.clearcoat=="number"&&(T=A.clearcoat),typeof A.clearcoatRoughness=="number"&&(I=A.clearcoatRoughness),typeof A.ior=="number"&&(F=A.ior);let y=typeof A.opacity=="number"?A.opacity:1,D=typeof A.transmission=="number"?A.transmission:0;if(h=y*(1-D),A.emissive&&(A.emissive.r>0||A.emissive.g>0||A.emissive.b>0)){let l=A.emissiveIntensity??1;w=[A.emissive.r*l,A.emissive.g*l,A.emissive.b*l]}}let f,S=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof S=="function"){let A=e?.duration??4,y=e?.fps??4,D=Math.max(2,Math.round(A*y)+1),l=[],m=[],R=[],p=[],g=[r.position.x,r.position.y,r.position.z],_=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],P=[r.scale.x,r.scale.y,r.scale.z],G=!1;for(let N=0;N<D;N++){let k=N/(D-1)*A;l.push(k);try{S(k)}catch{}m.push([r.position.x,r.position.y,r.position.z]),R.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),p.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-g[0])>1e-4||Math.abs(r.position.y-g[1])>1e-4||Math.abs(r.position.z-g[2])>1e-4||Math.abs(r.quaternion.x-_[0])>1e-4||Math.abs(r.quaternion.y-_[1])>1e-4||Math.abs(r.quaternion.z-_[2])>1e-4||Math.abs(r.quaternion.w-_[3])>1e-4||Math.abs(r.scale.x-P[0])>1e-4)&&(G=!0)}r.position.set(g[0],g[1],g[2]),r.quaternion.set(_[0],_[1],_[2],_[3]),r.scale.set(P[0],P[1],P[2]),G&&(f={times:l,translations:m,rotations:R,scales:p})}let U=r;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let A=Math.min(1e3,Math.floor(U.count)),y=U.instanceMatrix.array,D=U.instanceColor?.array,l=r.name||`Mesh_${t.length}`,m=new Float32Array(16),R=new Float32Array(9);for(let p=0;p<A;p++){let g=y.subarray(p*16,(p+1)*16);ee(m,o,g);let _=new Float32Array(a*3);for(let k=0;k<a;k++){let M=s.getX(k),H=s.getY(k),O=s.getZ(k);_[k*3]=m[0]*M+m[4]*H+m[8]*O+m[12],_[k*3+1]=m[1]*M+m[5]*H+m[9]*O+m[13],_[k*3+2]=m[2]*M+m[6]*H+m[10]*O+m[14]}let P;if(i.attributes.normal){let k=i.attributes.normal;P=new Float32Array(a*3),ae(R,m);for(let M=0;M<a;M++){let H=k.getX(M),O=k.getY(M),B=k.getZ(M),z=R[0]*H+R[3]*O+R[6]*B,C=R[1]*H+R[4]*O+R[7]*B,V=R[2]*H+R[5]*O+R[8]*B,$=Math.hypot(z,C,V)||1;P[M*3]=z/$,P[M*3+1]=C/$,P[M*3+2]=V/$}}let G=L,N=v;D&&D.length>=(p+1)*3&&(G=[L[0]*D[p*3],L[1]*D[p*3+1],L[2]*D[p*3+2]],N=`${v}_inst_${p}`),t.push({name:`${l}_${p}`,positions:_,indices:b,normals:P,uvs:u,materialName:N,color:G,roughness:E,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:h,emissiveColor:w,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:d,indices:b,normals:c,uvs:u,materialName:v,color:L,roughness:E,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:F,opacity:h,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:f})}}),t}function Qe(n){let e=[],t=n.gltf,r=ue().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),a=t.accessors||[],d=t.bufferViews||[],o=t.materials||[],c=t.meshes||[],u=t.nodes||[];function b(E){let x=a[E];if(!x)throw new Error(`Accessor ${E} not found`);let T=d[x.bufferView||0],I=(T.byteOffset||0)+(x.byteOffset||0),F=T.byteLength||0,h=s.slice(I,I+F);return{acc:x,buffer:h}}let v=new Map;if(u.length>0){let E=Me(t);for(let x=0;x<E.length;x++)v.set(x,E[x])}function L(E,x,T,I){let F=c[E];if(!F)return;let h=new Float32Array(9);ae(h,x);for(let w=0;w<(F.primitives||[]).length;w++){let f=F.primitives[w],S=f.attributes?.POSITION;if(S===void 0)continue;let{acc:U,buffer:A}=b(S),y=new Float32Array(A,0,U.count*3),D=new Float32Array(y.length);for(let C=0;C<U.count;C++){let V=y[C*3],$=y[C*3+1],W=y[C*3+2];D[C*3]=x[0]*V+x[4]*$+x[8]*W+x[12],D[C*3+1]=x[1]*V+x[5]*$+x[9]*W+x[13],D[C*3+2]=x[2]*V+x[6]*$+x[10]*W+x[14]}let l,m=f.attributes?.NORMAL;if(m!==void 0){let{acc:C,buffer:V}=b(m),$=new Float32Array(V,0,C.count*3);l=new Float32Array($.length);for(let W=0;W<C.count;W++){let q=$[W*3],te=$[W*3+1],se=$[W*3+2],X=h[0]*q+h[3]*te+h[6]*se,Z=h[1]*q+h[4]*te+h[7]*se,re=h[2]*q+h[5]*te+h[8]*se,oe=Math.hypot(X,Z,re)||1;l[W*3]=X/oe,l[W*3+1]=Z/oe,l[W*3+2]=re/oe}}let R,p=f.attributes?.TEXCOORD_0;if(p!==void 0){let{acc:C,buffer:V}=b(p);R=new Float32Array(V,0,C.count*2)}let g;if(f.indices!==void 0){let{acc:C,buffer:V}=b(f.indices);C.componentType===5125?g=new Uint32Array(V,0,C.count):g=new Uint16Array(V,0,C.count);let $=U.count;for(let W of g)if(W>=$)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${$}).`)}else{let C=U.count;g=C>65535?new Uint32Array(C):new Uint16Array(C);for(let V=0;V<C;V++)g[V]=V}let _="DefaultMaterial",P=[.8,.8,.8],G=.5,N=.1,k=0,M=0,H=1.5,O=1,B=[0,0,0];if(f.material!==void 0&&o[f.material]){let C=o[f.material];_=C.name||`Material_${f.material}`;let V=C.pbrMetallicRoughness||{},$=1;Array.isArray(V.baseColorFactor)&&(P=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&($=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(G=V.roughnessFactor),typeof V.metallicFactor=="number"&&(N=V.metallicFactor),Array.isArray(C.emissiveFactor)&&C.emissiveFactor.length>=3&&(B=[C.emissiveFactor[0],C.emissiveFactor[1],C.emissiveFactor[2]]);let W=C.extensions||{};W.KHR_materials_clearcoat&&(k=W.KHR_materials_clearcoat.clearcoatFactor??0,M=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(H=W.KHR_materials_ior.ior);let q=W.KHR_materials_transmission?.transmissionFactor??0;O=$*(1-q)}let z=(F.primitives||[]).length>1?`${T}_p${w}`:T;e.push({name:z,positions:D,indices:g,normals:l,uvs:R,materialName:_,color:P,roughness:G,metallic:N,clearcoat:k,clearcoatRoughness:M,ior:H,opacity:O,emissiveColor:B,xrTraits:I?.xr||F.extras?.xr})}}if(u.length>0)for(let E=0;E<u.length;E++){let x=u[E];if(x.mesh!==void 0&&x.mesh<c.length){let T=v.get(E)||J(),I=x.name||c[x.mesh].name||`Node_${E}`,F=x.extensions?.EXT_mesh_gpu_instancing?.attributes;if(F&&typeof F=="object"){let h=F.TRANSLATION,w=F.ROTATION,f=F.SCALE,S=h!==void 0?(()=>{let{acc:D,buffer:l}=b(h);return new Float32Array(l,0,D.count*3)})():null,U=w!==void 0?(()=>{let{acc:D,buffer:l}=b(w);return new Float32Array(l,0,D.count*4)})():null,A=f!==void 0?(()=>{let{acc:D,buffer:l}=b(f);return new Float32Array(l,0,D.count*3)})():null,y=Math.min(1e3,S?S.length/3:U?U.length/4:A?A.length/3:0);if(y>0){let D=new Float32Array(16),l=new Float32Array(16);for(let m=0;m<y;m++){let R=S?[S[m*3],S[m*3+1],S[m*3+2]]:[0,0,0],p=U?[U[m*4],U[m*4+1],U[m*4+2],U[m*4+3]]:[0,0,0,1],g=A?[A[m*3],A[m*3+1],A[m*3+2]]:[1,1,1];he(D,p,R,g),ee(l,T,D),L(x.mesh,l,`${I}_${m}`,x.extras)}continue}}L(x.mesh,T,I,x.extras)}}else{let E=J();for(let x=0;x<c.length;x++){let T=c[x].name||`Mesh_${x}`;L(x,E,T,c[x].extras)}}return e}function Fe(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function je(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function K(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function Je(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*3])}, ${K(n[r*3+1])}, ${K(n[r*3+2])})`;return t.join(", ")}function yt(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${K(n[r*2])}, ${K(1-n[r*2+1])})`;return t.join(", ")}function vt(n){return Array.from(n).join(", ")}function Se(n){let e=new Map;for(let o of n){let c=Fe(o.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:o.color||[.8,.8,.8],roughness:o.roughness??.5,metallic:o.metallic??0,clearcoat:o.clearcoat??0,clearcoatRoughness:o.clearcoatRoughness??0,ior:o.ior??1.5,opacity:o.opacity??1,emissiveColor:o.emissiveColor||[0,0,0]})}let t=0,r=null;for(let o of n){if(o.timeSamples&&o.timeSamples.times.length>0){let c=o.timeSamples.times[o.timeSamples.times.length-1];c>t&&(t=c)}o.xrTraits?.anchor&&!r&&(r=o.xrTraits.anchor==="vertical"||o.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
|
|
253
|
-
endTimeCode = ${
|
|
249
|
+
void main(){fragColor=uColorId;}`;function Ot(t,e,i){let r={};for(let a of i)r[a]=t.getUniformLocation(e,a);return r}var Wt=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Yt(){let t=pt().xrDepthShader;return{fs:De.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Wt,...t.uniformNames]:Wt}}function Fe(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function $t(t,e,i,r,a,s,m,f){if(r===void 0||!e.accessors?.[r])return null;let p=Ht(e,i,e.accessors[r],s);if(!p)return null;f&&(p=p.slice(),ye(p,f));let u=t.createBuffer();return m.push(u),t.bindBuffer(34962,u),t.bufferData(34962,p,35044),t.enableVertexAttribArray(a),t.vertexAttribPointer(a,s,5126,!1,0,0),p}function Ut(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Zt(t,e,i){let r=Yt(),a=Xt,s=r.fs,m=!1;for(let p of ht)if(p.onResolveShader){let u=p.onResolveShader(e,i,a,s);u&&(a=u.vs,s=u.fs,m=!0)}let f=m?Nt(t,a,s):null;return{program:f,uniforms:f?Ot(t,f,r.uniforms):null}}function _e(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let a=r.length>>4,s=e.instanceColors,m=new Float32Array(a*20);for(let p=0;p<a;p++)m.set(r.subarray(p*16,p*16+16),p*20),m[p*20+16]=s?s[p*3]:1,m[p*20+17]=s?s[p*3+1]:1,m[p*20+18]=s?s[p*3+2]:1,m[p*20+19]=1;let f=t.createBuffer();i.push(f),t.bindBuffer(34962,f),t.bufferData(34962,m,35044);for(let p=0;p<5;p++)t.enableVertexAttribArray(8+p),t.vertexAttribPointer(8+p,4,5126,!1,80,p*16),t.vertexAttribDivisor(8+p,1);return!0}function Le(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let a of r){let s=a?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var He=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Jt=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ct(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Qt(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,a=t?.extensions?.KHR_materials_clearcoat,s=m=>m!==void 0&&e[m.index]?e[m.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:a?a.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,a?.clearcoatRoughnessFactor??.04),texture:s(i?.baseColorTexture),metallicRoughnessTexture:s(i?.metallicRoughnessTexture),normalTexture:s(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:s(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function te(t,e,i){let r=new Set,a=s=>{s&&!r.has(s)&&(r.add(s),t.deleteTexture(s))};for(let s of e)for(let m of s.primitives){if(m.vao&&t.deleteVertexArray(m.vao),m.buffers)for(let p of m.buffers)t.deleteBuffer(p);a(m.texture),a(m.metallicRoughnessTexture),a(m.normalTexture),a(m.occlusionTexture);let f=new Set;m.customProgram&&f.add(m.customProgram);for(let p of m.programCache?.values()??[])p.program&&f.add(p.program);for(let p of f)t.deleteProgram(p)}if(i)for(let s of i)a(s)}function ee(t,e,i=Jt,r){let a={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Ne(t,e,i,r,a)}catch(s){let m=a.mesh&&!a.meshes.includes(a.mesh)?[...a.meshes,a.mesh]:a.meshes;te(t,m,a.gpuTextures),a.vao&&t.deleteVertexArray(a.vao);for(let f of a.buffers)t.deleteBuffer(f);throw s}}function Ne(t,e,i,r,a){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,m=yt("meshopt");m?.decodeBufferViews&&m.decodeBufferViews(s,e);let f=e.bin,p=[];a.meshes=p;let u=[],d=s.extensions?.KHR_materials_variants;d&&Array.isArray(d.variants)&&d.variants.forEach((M,o)=>{u.push(typeof M?.name=="string"&&M.name?M.name:`Variant_${o}`)});let y=Te(s),R=[];if(Array.isArray(s.nodes))for(let M=0;M<s.nodes.length;M++){let o=s.nodes[M];o.mesh!==void 0&&s.meshes&&s.meshes[o.mesh]&&R.push({node:o,nodeIdx:M,meshIdx:o.mesh})}let S=R.length>0?R:(s.meshes||[]).map((M,o)=>({node:M,nodeIdx:-1,meshIdx:o})),l=[],x=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(x)for(let M of x)l.push({...M,type:M.type||M.light_type||"point",innerConeAngle:M.innerConeAngle??M.inner_cone_angle,outerConeAngle:M.outerConeAngle??M.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let M=s.extensions.KHR_lights_punctual.lights;for(let o of M){let V=o.type==="directional"?"directional":o.type==="point"?"point":o.type==="spot"?"spot":"ambient";l.push({type:V,color:o.color||[1,1,1],intensity:o.intensity!==void 0?o.intensity:1})}}if(l.length===0&&(l.push({type:"ambient",color:[1,1,1],intensity:.35}),l.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),S.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${S.length}`);let T=[];if(a.gpuTextures=T,s.textures&&s.images){if(s.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${s.textures.length}`);for(let M=0;M<s.textures.length;M++){let o=s.textures[M],V=s.images[o.source];if(V){let X=t.createTexture();t.bindTexture(3553,X),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729);let g=I=>{t.bindTexture(3553,X),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()};if(V.bufferView!==void 0){let I=s.bufferViews[V.bufferView],c=I.byteOffset||0,P=new Blob([f.slice(c,c+I.byteLength)],{type:V.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(P).then(g).catch(()=>{})}else if(V.uri){let I=Fe(V.uri);if(I){let c=new Image;c.crossOrigin="anonymous",c.referrerPolicy="no-referrer",c.onload=()=>g(c),c.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",V.uri)}T.push(X)}else T.push(null)}}let w=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],h=0,n=0;for(let M=0;M<S.length;M++){let o=S[M],V=s.meshes[o.meshIdx],X=o.nodeIdx>=0?y[o.nodeIdx]:nt(),g=new Float32Array(9);bt(g,X);let I={name:o.node.name||V.name||`Mesh_${o.meshIdx}`,nodeIndex:o.nodeIdx,transform:X,normalMatrix:g,primitives:[],extras:o.node.extras||V.extras,...o.node?.visible===!1||o.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};a.mesh=I;let c=o.node?.extensions?.EXT_mesh_gpu_instancing;if(c&&c.attributes&&typeof c.attributes=="object"){let P=c.attributes,j=P.TRANSLATION!==void 0?s.accessors?.[P.TRANSLATION]:null,G=P.ROTATION!==void 0?s.accessors?.[P.ROTATION]:null,U=P.SCALE!==void 0?s.accessors?.[P.SCALE]:null,Z=P._COLOR_0!==void 0?s.accessors?.[P._COLOR_0]:null,E=Number(j?.count??G?.count??U?.count??0);if(!Number.isFinite(E)||E<0||E>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${E}`);if(E>0){let q=(N,Q)=>{if(!N||N.bufferView===void 0||!s.bufferViews?.[N.bufferView])return null;let tt=N.componentType??5126,it=et=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${et})`),null);if(tt!==5120&&tt!==5121&&tt!==5122&&tt!==5123&&tt!==5126)return it(`componentType ${tt}`);if(!(Number(N.count)>=E))return it(`count ${N.count} < ${E}`);let Y=null;try{Y=Ht(s,f,{...N,count:E},Q)}catch{return it("out of bounds")}return!Y||!Y.every(Number.isFinite)?it("non-finite value"):Y},O=q(j,3),H=q(G,4),F=q(U,3),K=Z?.type==="VEC4"?4:3,k=q(Z,K),W=new Float32Array(E*16),z=nt();for(let N=0;N<E;N++){let Q=O?[O[N*3],O[N*3+1],O[N*3+2]]:[0,0,0],tt=H?[H[N*4],H[N*4+1],H[N*4+2],H[N*4+3]]:[0,0,0,1],it=F?[F[N*3],F[N*3+1],F[N*3+2]]:[1,1,1];jt(z,tt,Q,it),W.set(z,N*16)}if(I.instanceMatrices=W,k){let N=new Float32Array(E*3);for(let Q=0;Q<E;Q++)N[Q*3]=k[Q*K],N[Q*3+1]=k[Q*K+1],N[Q*3+2]=k[Q*K+2];I.instanceColors=N}}}for(let P of V.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let Y=yt("draco");Y&&Y.decodePrimitive(s,P,f)}let j=[],G=t.createVertexArray();a.vao=G,a.buffers=j,t.bindVertexArray(G);let U=_e(t,I,j),Z=s.accessors[P.attributes.POSITION],E=Number(Z?.count??0);if(!Number.isFinite(E)||E<0||h+E>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(h+=E,Z?.min&&Z?.max){let Y=et=>{for(let rt=0;rt<3;rt++){let ft=et[12+rt],at=et[12+rt];for(let st=0;st<3;st++){let lt=et[st*4+rt]*Z.min[st],ot=et[st*4+rt]*Z.max[st];ft+=lt<ot?lt:ot,at+=lt>ot?lt:ot}ft<w[rt]&&(w[rt]=ft),at>v[rt]&&(v[rt]=at)}};if(I.instanceMatrices&&I.instanceMatrices.length>=16){let et=I.instanceMatrices.length>>4,rt=nt();for(let ft=0;ft<et;ft++){let at=I.instanceMatrices.subarray(ft*16,ft*16+16);ct(rt,X,at),Y(rt)}}else Y(X)}let q=$t(t,s,f,P.attributes.POSITION,0,3,j);$t(t,s,f,P.attributes.NORMAL,1,3,j),$t(t,s,f,P.attributes.TEXCOORD_0,2,2,j,Le(s,P));let O=0,H=5123,F=null;if(P.indices!==void 0){let Y=s.accessors[P.indices],et=(s.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(O=Number(Y.count??0),!Number.isFinite(O)||O<0||n+O>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);n+=O,H=Y.componentType===5125?5125:5123;let rt=t.createBuffer();j.push(rt),t.bindBuffer(34963,rt),Y.componentType===5125?F=new Uint32Array(f,et,Y.count):Y.componentType===5121?F=Uint16Array.from(new Uint8Array(f,et,Y.count)):F=et%2===0?new Uint16Array(f,et,Y.count):new Uint16Array(f.slice(et,et+Y.count*2)),t.bufferData(34963,F,35044)}else O=Z.count;let K={};for(let Y of ht)if(Y.onBuildPrimitiveVAO){let et=Y.onBuildPrimitiveVAO(t,G,P,s,f);et&&(K[Y.name]=et)}t.bindVertexArray(null);let k=s.materials&&P.material!==void 0?s.materials[P.material]:null,{program:W,uniforms:z}=Zt(t,P,k),N=Qt(k,T),Q=!!(k?.extensions?.KHR_materials_transmission||K.materials?.isTransmissive),tt=P.extensions?.KHR_materials_variants?.mappings,it=Array.isArray(tt)?tt.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(et=>Number(et)|0)})):void 0;I.primitives.push({vao:G,instanced:U,indexCount:O,indexType:H,...N,positions:q,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:it,primitiveDef:P,programCache:new Map([[P.material??-1,{program:W,uniforms:z}]]),pluginData:K,customProgram:W,customUniforms:z,isTransmissive:Q})}p.push(I)}isFinite(w[0])||(w=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let b=[(w[0]+v[0])/2,(w[1]+v[1])/2,(w[2]+v[2])/2],A=v[0]-w[0],$=v[1]-w[1],B=v[2]-w[2],_=Math.max(Math.hypot(A,$,B)/2,.5),L=[w[0],w[1],w[2]],C=[v[0],v[1],v[2]],D=e.animations;if(!D){for(let M of ht)if(M.onParseGLB?.(e),e.animations){D=e.animations;break}}return D||(D=[]),{meshes:p,bounds:{center:b,radius:_,min:L,max:C},lights:l,animations:D,worldMatrices:y,gpuTextures:T,availableVariants:u}}function Mt(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var ie=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=nt(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=nt(),this.viewMatrix=nt(),this.activeViewMatrix=null,this.modelMatrix=nt(),this.mvpMatrix=nt(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:nt(),rawValueToMeters:.001,format:0},this.container=t;let r,a;if(e&&typeof e.getContext=="function"?(r=e,a=i):(a=e,r=a?.canvas),!r){let f=t.querySelector("canvas");f||(f=document.createElement("canvas"),f.style.width="100%",f.style.height="100%",f.style.display="block",f.style.touchAction="none",t.prepend(f)),r=f}this.canvas=r,this.opts=a||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Ut(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=Vt(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(t,e){Ce(t,e)}static getDecoder(t){return yt(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=Yt();this.renderProg=Nt(t,Xt,e.fs),this.pickProg=Nt(t,Se,Ie),this.uRender=Ot(t,this.renderProg,e.uniforms),this.uPick=Ot(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of ht)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let e=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=e,this.pickFboHeight=i,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,e,i,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,e,i),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null)}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),a=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=a,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,a,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,a)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:a,animations:s,worldMatrices:m,gpuTextures:f,availableVariants:p}=ee(this.gl,t,e,()=>this.render());if(this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=a,this.animations=s||[],this.worldMatrices=m||[],this.gpuTextures=f||[],this.availableVariants=p||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let y of t.gltf.nodes)this.initialNodeTransforms.push({t:y.translation?[y.translation[0],y.translation[1],y.translation[2]]:[0,0,0],r:y.rotation?[y.rotation[0],y.rotation[1],y.rotation[2],y.rotation[3]]:[0,0,0,1],s:y.scale?[y.scale[0],y.scale[1],y.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let y of ht)y.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=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Ut(u));let d=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;d!==void 0&&(this.envIntensity=Math.max(0,Number(d)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(qt(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of ht)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(At(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=At(t),{meshes:r}=ee(this.gl,i,Jt,()=>this.render());if(e)for(let a of r)a.transform[12]+=e[0],a.transform[13]+=e[1],a.transform[14]+=e[2],bt(a.normalMatrix,a.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r;t instanceof Map?r=t.get(i.name)??t.get(e):Array.isArray(t)?r=t[e]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,i.name)?r=t[i.name]:Object.prototype.hasOwnProperty.call(t,e)&&(r=t[e])),r&&r.length===16&&(i.transform.set(r),bt(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[],a=[],s=[],m=[],f=[],p=[];for(let u of this.lights){let d=u.color||[1,1,1],y=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")i=[d[0]*y,d[1]*y,d[2]*y];else if(u.type==="directional"&&r.length<6){let R=u.direction||[.5,1,.8];r.push(R[0],R[1],R[2]),a.push(d[0]*y,d[1]*y,d[2]*y)}else if((u.type==="point"||u.type==="spot")&&s.length<6){let R=u.position||[0,0,0];if(s.push(R[0],R[1],R[2]),m.push(d[0]*y,d[1]*y,d[2]*y),u.type==="spot"){let S=u.direction||[0,-1,0],l=Math.max(.01,Math.min(Math.PI/2,u.outerConeAngle??Math.PI/3)),x=Math.max(0,Math.min(l-1e-4,u.innerConeAngle??0));f.push(S[0],S[1],S[2]),p.push(Math.cos(x),Math.cos(l))}else f.push(0,-1,0),p.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),a.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),e.uniform1i(t.uNumDirLights,r.length/3),r.length>0&&(e.uniform3fv(t.uDirLightDir,r),e.uniform3fv(t.uDirLightColor,a)),e.uniform1i(t.uNumPointLights,s.length/3),s.length>0&&(e.uniform3fv(t.uPointLightPos,s),e.uniform3fv(t.uPointLightColor,m),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,f),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,p)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Ut(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Vt(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let e of ht)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let e of ht)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(u=>u.primitives.filter(d=>d.materialIndex===i||t.length===1&&d.materialIndex===void 0)),a=r[0],s=a?[...a.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=a?a.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,f=a?a.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,p={baseColorFactor:s,metallicFactor:m,roughnessFactor:f,setBaseColorFactor:u=>{let d=[u[0],u[1],u[2],u[3]??1];p.baseColorFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.baseColorFactor=d);for(let y of r)y.baseColor=d;this.render()},setMetallicFactor:u=>{p.metallicFactor=u,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.metallicFactor=u);for(let d of r)d.metallic=u;this.render()},setRoughnessFactor:u=>{p.roughnessFactor=u,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.roughnessFactor=u);for(let d of r)d.roughness=u;this.render()}};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:p}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let a of this.meshes)for(let s of a.primitives){let m=s.defaultMaterialIndex;if(!e&&Array.isArray(s.variantMappings)){for(let p of s.variantMappings)if(Array.isArray(p.variants)&&p.variants.includes(i)){m=p.material;break}}let f=m!==void 0?r[m]:void 0;s.materialIndex=f?m:void 0,Object.assign(s,Qt(f,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,f??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,a=t.programCache.get(r);a||(a=Zt(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,a)),t.customProgram=a.program,t.customUniforms=a.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of ht)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){t.minTheta!==void 0&&(this.minTheta=t.minTheta*Math.PI/180),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*Math.PI/180),t.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,t.minPhi*Math.PI/180)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,t.maxPhi*Math.PI/180)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.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(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=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(e,Math.min(i,t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*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(t,e,i,r){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),e!==void 0&&(this.initialPhi=this.clampPhi(e*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let a=this.clampDistance(i);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else if(r!==void 0&&r>0){let a=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else{this.customDistance=!1;let a=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=a,this.targetDistance=a,this.currDistance=a}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(t,e){let i=nt();ct(i,this.projMatrix,this.viewMatrix);let[r,a,s]=t,m=e?e[0]:0,f=e?e[1]:0,p=e?e[2]:0,u=this.modelRootMatrix;u&&(r=u[0]*t[0]+u[4]*t[1]+u[8]*t[2]+u[12],a=u[1]*t[0]+u[5]*t[1]+u[9]*t[2]+u[13],s=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]+u[14],e&&(m=u[0]*e[0]+u[4]*e[1]+u[8]*e[2],f=u[1]*e[0]+u[5]*e[1]+u[9]*e[2],p=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]));let d=i[0]*r+i[4]*a+i[8]*s+i[12],y=i[1]*r+i[5]*a+i[9]*s+i[13],R=i[2]*r+i[6]*a+i[10]*s+i[14],S=i[3]*r+i[7]*a+i[11]*s+i[15];if(S<=1e-4)return{x:0,y:0,z:1,visible:!1};let l=d/S,x=y/S,T=R/S,w=this.canvas.getBoundingClientRect(),v=w.width||this.canvas.clientWidth||this.canvas.width||300,h=w.height||this.canvas.clientHeight||this.canvas.height||150,n=(l*.5+.5)*v,b=(-x*.5+.5)*h,A=l>=-1.1&&l<=1.1&&x>=-1.1&&x<=1.1&&T>=-1&&T<=1;if(A&&e){let[$,B,_]=Mt(this),L=[r-$,a-B,s-_];m*L[0]+f*L[1]+p*L[2]>.05&&(A=!1)}return{x:n,y:b,z:T,visible:A}}setSelectedMesh(t){this.selectedMeshName=t||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let t=this.canvas,e=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},a=i.clientX-r.x,s=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(a,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let m=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],f=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],p=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;p[0]+=(-a*m[0]+s*f[0])*u,p[1]+=(-a*m[1]+s*f[1])*u,p[2]+=(-a*m[2]+s*f[2])*u,this.customTarget=p}else this.targetTheta=this.clampTheta(this.targetTheta-a*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),a=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),s=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(a,s,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,a)=>{this[a]&&(i.removeEventListener(r,this[a]),this[a]=null)},e=this.canvas;t(e,"webglcontextlost","boundContextLost"),t(e,"webglcontextrestored","boundContextRestored"),t(e,"contextmenu","boundContextMenu"),t(e,"pointerdown","boundPointerDown"),t(e,"pointermove","boundPointerMove"),t(e,"pointerup","boundPointerUp"),t(e,"wheel","boundWheel"),t(e,"keydown","boundKeyDown"),t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),a=i.width||300,s=i.height||300,m=r.width>0?Math.floor((t-r.left)*(a/r.width)):Math.floor(t),f=r.height>0?Math.floor((e-r.top)*(s/r.height)):Math.floor(e);return this.performMeshPick(m,f,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,a=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,a);let m=nt();ct(m,this.projMatrix,this.viewMatrix);let f=[],p=Math.max(0,Math.min(a-1,t)),u=Math.max(0,Math.min(s-1,s-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==a||this.pickFboHeight!==s)&&this.resizePickingFbo(a,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,a,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let b=0;b<this.meshes.length;b++){let A=this.meshes[b];if(A.visible===!1||A.isPluginMesh)continue;let $=b+1,B=($&255)/255,_=($>>8&255)/255,L=($>>16&255)/255;r.uniform4f(this.uPick.uColorId,B,_,L,1),ct(this.modelMatrix,this.modelRootMatrix,A.transform);let C=A.instanceMatrices;if(C&&C.length>=16){let D=C.length>>4,M=nt();for(let o of A.primitives){r.bindVertexArray(o.vao);for(let V=0;V<D;V++)ct(M,this.modelMatrix,C.subarray(V*16,V*16+16)),ct(this.mvpMatrix,m,M),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ct(r,o)}}else{ct(this.mvpMatrix,m,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let D of A.primitives)r.bindVertexArray(D.vao),Ct(r,D)}}let h=new Uint8Array(4);r.readPixels(p,u,1,1,6408,5121,h),r.bindFramebuffer(36160,null);let n=h[0]+(h[1]<<8)+(h[2]<<16);n>0&&n<=this.meshes.length&&(f=[this.meshes[n-1]])}f.length===0&&(f=this.meshes.filter(h=>h.visible!==!1));let d=null,y=1/0,R=[0,0,0],S=[0,1,0],[l,x,T]=Mt(this),w=nt();for(let h of f){ct(w,this.modelRootMatrix,h.transform);let n=h.instanceMatrices,b=n&&n.length>=16?n.length>>4:1;for(let A=0;A<b;A++){n&&n.length>=16?ct(this.modelMatrix,w,n.subarray(A*16,A*16+16)):this.modelMatrix.set(w),ct(this.mvpMatrix,m,this.modelMatrix);let $=nt();if(!Me($,this.mvpMatrix))continue;let B=(p+.5)/a*2-1,_=(u+.5)/s*2-1,L=[0,0,0],C=[0,0,0];zt(L,B,_,-1,$),zt(C,B,_,1,$);let D=C[0]-L[0],M=C[1]-L[1],o=C[2]-L[2],V=Math.hypot(D,M,o)||1,X=D/V,g=M/V,I=o/V,c={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let j of h.primitives){if(!j.positions)continue;let G=j.positions,U=j.indices,Z=Math.floor(U?U.length/3:G.length/9);for(let E=0;E<Z;E++){let q=U?U[E*3]:E*3,O=U?U[E*3+1]:E*3+1,H=U?U[E*3+2]:E*3+2;we(L[0],L[1],L[2],X,g,I,G[q*3],G[q*3+1],G[q*3+2],G[O*3],G[O*3+1],G[O*3+2],G[H*3],G[H*3+1],G[H*3+2],c,P)}}})(1e-4),isFinite(c.distance)){let P=c.point[0],j=c.point[1],G=c.point[2],U=this.modelMatrix,Z=U[0]*P+U[4]*j+U[8]*G+U[12],E=U[1]*P+U[5]*j+U[9]*G+U[13],q=U[2]*P+U[6]*j+U[10]*G+U[14],O=Z-l,H=E-x,F=q-T,K=Math.hypot(O,H,F);if(K<y){bt(this.normalMatrix,this.modelMatrix);let k=this.normalMatrix,W=c.normal[0],z=c.normal[1],N=c.normal[2],Q=k[0]*W+k[3]*z+k[6]*N,tt=k[1]*W+k[4]*z+k[7]*N,it=k[2]*W+k[5]*z+k[8]*N,Y=Math.hypot(Q,tt,it)||1;Q/=Y,tt/=Y,it/=Y,Q*O+tt*H+it*F>0&&(Q=-Q,tt=-tt,it=-it),d=h,y=Math.round(K*1e3)/1e3,R=[Math.round(Z*1e3)/1e3,Math.round(E*1e3)/1e3,Math.round(q*1e3)/1e3],S=[Math.round(Q*1e3)/1e3,Math.round(tt*1e3)/1e3,Math.round(it*1e3)/1e3]}}}}if(!d)return null;let v={meshIndex:this.meshes.indexOf(d),meshName:d.name,nodeIndex:d.nodeIndex,distance:y,hitPoint:R,normal:S,screenX:t,screenY:e};if(i){for(let h of ht)h.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(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,a=r?t-i:t,s=r?Math.max(1,e-i):i,m=(a+.5)/s*2-1;return Math.floor((m*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Et(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;kt(this.viewMatrix,Mt(this),i,[0,1,0]),ct(this.mvpMatrix,this.projMatrix,this.viewMatrix),bt(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));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(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of ht)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(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of ht)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],a=this.modelRootMatrix;a[0]=t,a[1]=0,a[2]=-e,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=e,a[9]=0,a[10]=t,a[11]=0,a[12]=i-(t*i+e*r),a[13]=0,a[14]=r-(-e*i+t*r),a[15]=1}setVisible(t){this.isVisible=t}update(t){for(let s of ht)s.onUpdate?.(this,t);let e=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of ht)s.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),a=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(a-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=a;let s={theta:i,phi:r,zoom:a,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(t,e,i,r,a=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let m=t?.transform?.inverse?.matrix||this.viewMatrix,f=t?.projectionMatrix||this.projMatrix,p=t?.transform?.position,u=p?[p.x,p.y,p.z]:[0,1.6,0];e?this.modelRootMatrix.set(e):i&&e&&this.modelRootMatrix.set(e),this.render({viewMatrix:m,projMatrix:f,eyePos:u,viewport:r,eye:t?.eye||"none",clear:s>0?!1:t?.eye!=="right",isAR:a})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),h=Math.max(1,this.canvas.height||1),n=Math.max(1,Math.floor(v*.5)),b=Math.max(1,v-n),A=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),$=this.customTarget||this.bounds.center,[B,_,L]=Mt(this),C=Math.cos(this.currTheta),D=-Math.sin(this.currTheta),M=.032,o=nt(),V=nt(),X=[B-C*M,_,L-D*M],g=[$[0]-C*M*.25,$[1],$[2]-D*M*.25];Et(o,this.fov,n/h,.1,A),kt(V,X,g,[0,1,0]);let I=nt(),c=nt(),P=[B+C*M,_,L+D*M],j=[$[0]+C*M*.25,$[1],$[2]+D*M*.25];Et(I,this.fov,b/h,.1,A),kt(c,P,j,[0,1,0]),this.render({viewMatrix:V,projMatrix:o,eyePos:X,viewport:[0,0,n,h],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:c,projMatrix:I,eyePos:P,viewport:[n,0,b,h],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,h);return}let e=this.gl,i=0,r=0,a=this.canvas.width,s=this.canvas.height;t?.viewport?(i=t.viewport[0],r=t.viewport[1],a=t.viewport[2],s=t.viewport[3],e.viewport(i,r,a,s)):e.viewport(0,0,this.canvas.width,this.canvas.height),e.enable(2929),(!t||t.clear!==!1)&&(t?.isAR?e.clearColor(0,0,0,0):e.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),e.clear(16640));let m=nt(),f=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=f,ct(m,t?.projMatrix??this.projMatrix,f);let p=pt().xrDepthShader,u=Pe(this.toneMapping),[d,y,R]=t?t.eyePos:Mt(this);for(let v of ht)v.onBeforeDrawScene?.(this,e,m,[d,y,R],u);let S=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let l=t?.eye||"none",x=!1,T=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,w=v=>{for(let h=0;h<T.length;h++){let n=T[h];if(n.visible===!1)continue;let b=this.selectedMeshName!==""&&n.name===this.selectedMeshName;h<S||n.worldSpace===!0||n.name==="__xr_reticle__"?this.modelMatrix.set(n.transform):ct(this.modelMatrix,this.modelRootMatrix,n.transform),ct(this.mvpMatrix,m,this.modelMatrix),bt(n.normalMatrix,this.modelMatrix);let A=n.extras?.xr?.stereo||n.userData?.xr?.stereo,$=0,B=0,_=1,L=1;A==="sbs"?(_=.5,$=l==="right"?.5:0):A==="ou"&&(L=.5,B=l==="right"?.5:0);for(let C of n.primitives){let D=!!C.isTransmissive;if(!v&&D){x=!0;continue}if(v&&!D)continue;let M=C.customProgram||this.renderProg,o=C.customUniforms||this.uRender;e.useProgram(M),e.vertexAttrib3f(3,0,0,0),o.uInstanced&&e.uniform1i(o.uInstanced,0),e.uniform1i(o.uToneMapping,u),e.uniform1f(o.uEnvIntensity,this.envIntensity),o.uExposure&&e.uniform1f(o.uExposure,this.exposure),e.uniform3f(o.uCameraPos,d,y,R),e.uniform1f(o.uEmissive,b?1:0),e.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(o.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(o.uNormalMatrix,!1,n.normalMatrix),o.uUvTransform&&e.uniform4f(o.uUvTransform,$,B,_,L),o.uViewportSize&&e.uniform2f(o.uViewportSize,Math.max(1,a),Math.max(1,s)),p?.bind(e,o,this.xrDepthState,f,[i,r,Math.max(1,a),Math.max(1,s)]),this.environmentTexture?(e.activeTexture(33988),e.bindTexture(3553,this.environmentTexture),e.uniform1i(o.uEnvironmentMap,4),e.uniform1i(o.uHasEnvironmentMap,1)):e.uniform1i(o.uHasEnvironmentMap,0),this.bindLights(o),o.uSectionEnabled&&e.uniform1i(o.uSectionEnabled,0);for(let X of ht)X.onBeforeDrawPrimitive?.(e,M,C,n,this.worldMatrices||[],this.gltf);e.uniform4fv(o.uBaseColor,C.baseColor),e.uniform1f(o.uMetallic,C.metallic),e.uniform1f(o.uRoughness,C.roughness),o.uClearcoat&&e.uniform2f(o.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(e.activeTexture(33984),e.bindTexture(3553,C.texture),e.uniform1i(o.uBaseColorTexture,0),e.uniform1i(o.uHasTexture,1)):e.uniform1i(o.uHasTexture,0),C.metallicRoughnessTexture?(e.activeTexture(33985),e.bindTexture(3553,C.metallicRoughnessTexture),e.uniform1i(o.uMetallicRoughnessTexture,1),e.uniform1i(o.uHasMetallicRoughnessTexture,1)):e.uniform1i(o.uHasMetallicRoughnessTexture,0),C.normalTexture?(e.activeTexture(33986),e.bindTexture(3553,C.normalTexture),e.uniform1i(o.uNormalTexture,2),e.uniform1i(o.uHasNormalTexture,1),e.uniform1f(o.uNormalScale,C.normalScale)):e.uniform1i(o.uHasNormalTexture,0),C.occlusionTexture?(e.activeTexture(33987),e.bindTexture(3553,C.occlusionTexture),e.uniform1i(o.uOcclusionTexture,3),e.uniform1i(o.uHasOcclusionTexture,1),e.uniform1f(o.uOcclusionStrength,C.occlusionStrength)):e.uniform1i(o.uHasOcclusionTexture,0),e.bindVertexArray(C.vao);let V=n.instanceMatrices;if(C.instanceCount!==void 0)e.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(V&&V.length>=16&&C.instanced&&o.uInstanced&&o.uViewProj){let X=V.length>>4;e.uniform1i(o.uInstanced,1),e.uniformMatrix4fv(o.uViewProj,!1,m),C.indices?e.drawElementsInstanced(4,C.indexCount,C.indexType,0,X):e.drawArraysInstanced(4,0,C.indexCount,X),e.uniform1i(o.uInstanced,0)}else if(V&&V.length>=16){let X=V.length>>4,g=n.instanceColors,I=nt(),c=new Float32Array(9),P=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let j=0;j<X;j++)ct(I,this.modelMatrix,V.subarray(j*16,j*16+16)),ct(this.mvpMatrix,m,I),bt(c,I),e.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(o.uModel,!1,I),e.uniformMatrix3fv(o.uNormalMatrix,!1,c),g&&(P[0]=C.baseColor[0]*g[j*3],P[1]=C.baseColor[1]*g[j*3+1],P[2]=C.baseColor[2]*g[j*3+2],P[3]=C.baseColor[3],e.uniform4fv(o.uBaseColor,P)),Ct(e,C)}else Ct(e,C)}}};if(w(!1),x){for(let v of ht)v.onBeforeTransmissivePass?.(e,this);w(!0)}for(let v of ht)v.onAfterRender?.(e,this,m,t?.eye??"none",[i,r,a,s],t?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(t,e){te(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of ht)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};ie.registerPlugin=ve,ie.getRegisteredPlugins=xe;function Ee(t){return t+3&-4}var J=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function re(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function ae(t,e=0){let[i,r,a,,s,m,f,,p,u,d,,y,R,S]=Array.from({length:15},(c,P)=>J(t[e+P],P%5===0?1:0)),l=Math.hypot(i,r,a),x=Math.hypot(s,m,f),T=Math.hypot(p,u,d);i*(m*d-u*f)-s*(r*d-u*a)+p*(r*f-m*a)<0&&(l=-l);let w=Math.abs(l)>1e-8?1/l:0,v=Math.abs(x)>1e-8?1/x:0,h=Math.abs(T)>1e-8?1/T:0,n=i*w,b=r*w,A=a*w,$=s*v,B=m*v,_=f*v,L=p*h,C=u*h,D=d*h,M=n+B+D,o=0,V=0,X=0,g=1;if(M>0){let c=.5/Math.sqrt(M+1);g=.25/c,o=(_-C)*c,V=(L-A)*c,X=(b-$)*c}else if(n>B&&n>D){let c=2*Math.sqrt(Math.max(0,1+n-B-D));c>1e-8&&(g=(_-C)/c,o=.25*c,V=($+b)/c,X=(L+A)/c)}else if(B>D){let c=2*Math.sqrt(Math.max(0,1+B-n-D));c>1e-8&&(g=(L-A)/c,o=($+b)/c,V=.25*c,X=(_+C)/c)}else{let c=2*Math.sqrt(Math.max(0,1+D-n-B));c>1e-8&&(g=(b-$)/c,o=(L+A)/c,V=(_+C)/c,X=.25*c)}let I=Math.hypot(o,V,X,g);return I>1e-8&&Number.isFinite(I)?(o/=I,V/=I,X/=I,g/=I):(o=0,V=0,X=0,g=1),{t:[y,R,S],r:[o,V,X,g],s:[l,x,T]}}function ke(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var gt=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function se(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,a=typeof i.preset=="string"?i.preset:void 0;return!r&&!a?null:{ae:i,src:r,preset:a,volume:gt(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function oe(t,e){return ne(t,e)[0]}function ne(t,e){t.updateMatrixWorld(!0);let i=[],r=0,a=[],s=[],m=[],f=[],p=new Set,u=[],d=[],y=new Map,R=[],S=[],l=[],x=new Map,T=[],w=[];function v(g){let I=y.get(g);if(I!==void 0)return I;I=d.length,y.set(g,I);let c=g,P=c.color?.r??.8,j=c.color?.g??.8,G=c.color?.b??.8,U=c.opacity??1,Z={baseColorFactor:[P,j,G,U],metallicFactor:c.metalness??0,roughnessFactor:c.roughness??.5},E={};if(c.map){let H="";typeof c.map=="string"?H=c.map:typeof c.map.source=="string"?H=c.map.source:typeof c.map.image=="string"&&(H=c.map.image);let F=H.trim(),K=F&&!/[\x00-\x1f\x7f\\]|\.\./.test(F)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(F)||!F.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(F))?F:null;if(K){let W=x.get(K);if(W===void 0){let z=R.length;R.push({uri:K}),S.length===0&&S.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),W=l.length,l.push({sampler:0,source:z}),x.set(K,W)}Z.baseColorTexture={index:W}}let k=c.map.avgColor;Array.isArray(k)&&k.length>=3&&(E.avgColor=[k[0],k[1],k[2]])}let q={name:c.name||"",pbrMetallicRoughness:Z,doubleSided:c.side===2||!!c.doubleSided,...Object.keys(E).length>0?{extras:E}:{}};if(c.emissive&&(c.emissive.r>0||c.emissive.g>0||c.emissive.b>0)){let H=c.emissiveIntensity??1;q.emissiveFactor=[c.emissive.r*H,c.emissive.g*H,c.emissive.b*H]}let O={};return c.clearcoat&&c.clearcoat>0&&(O.KHR_materials_clearcoat={clearcoatFactor:c.clearcoat,clearcoatRoughnessFactor:c.clearcoatRoughness||0}),c.sheen&&c.sheen>0&&(O.KHR_materials_sheen={sheenColorFactor:c.sheenColor?[c.sheenColor.r,c.sheenColor.g,c.sheenColor.b]:[1,1,1],sheenRoughnessFactor:c.sheenRoughness||0}),c.transmission&&c.transmission>0&&(O.KHR_materials_transmission={transmissionFactor:c.transmission}),c.thickness&&c.thickness>0&&(O.KHR_materials_volume={thicknessFactor:c.thickness,attenuationDistance:c.attenuationDistance??1/0,attenuationColor:c.attenuationColor?[c.attenuationColor.r,c.attenuationColor.g,c.attenuationColor.b]:[1,1,1]}),c.ior!==void 0&&c.ior!==1.5&&(O.KHR_materials_ior={ior:c.ior}),c.dispersion&&c.dispersion>0&&(O.KHR_materials_dispersion={dispersion:c.dispersion}),c.iridescence&&c.iridescence>0&&(O.KHR_materials_iridescence={iridescenceFactor:c.iridescence,iridescenceIor:c.iridescenceIOR??1.3}),Object.keys(O).length>0&&(q.extensions=O),d.push(q),I}function h(g,I){let c=new Uint8Array(g.buffer,g.byteOffset,g.byteLength),P=Ee(c.byteLength),j=new Uint8Array(P);j.set(c),i.push(j);let G=a.length;return a.push({buffer:0,byteOffset:r,byteLength:c.byteLength,target:I}),r+=P,G}function n(g,I,c,P,j,G,U){let Z=h(g,c),E=s.length,q={bufferView:Z,byteOffset:0,componentType:P,count:j,type:I};return G&&(q.min=G),U&&(q.max=U),s.push(q),E}t.traverse(g=>{if(g.isLight||g.color&&g.intensity!==void 0){let I=g.matrixWorld?.elements,c=J(I?I[12]:g.position?.x,0),P=J(I?I[13]:g.position?.y,0),j=J(I?I[14]:g.position?.z,0),G=g.target,U=G?.parent?G?.matrixWorld?.elements:void 0,Z=J(U?U[12]:G?.position?.x,0),E=J(U?U[13]:G?.position?.y,0),q=J(U?U[14]:G?.position?.z,0),O=Z-c,H=E-P,F=q-j,K=Math.hypot(O,H,F),k=Math.max(.01,Math.min(Math.PI/2,J(g.angle,Math.PI/3))),W=Math.max(0,Math.min(1,J(g.penumbra,0)));w.push({type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[c,P,j],...g.type==="spot"?{direction:K>1e-6?[O/K,H/K,F/K]:[0,-1,0],outerConeAngle:k,innerConeAngle:Math.max(0,k*(1-W)),range:Math.max(0,J(g.distance,0))}:g.type==="point"?{range:Math.max(0,J(g.distance,0))}:{}})}});let b=[],A=new Set([t]),$=[];if(Array.isArray(t.children))for(let g=t.children.length-1;g>=0;g--)$.push({obj:t.children[g],parentKids:b});for(;$.length>0;){let{obj:g,parentKids:I}=$.pop();if(!g||typeof g!="object"||A.has(g))continue;A.add(g),g._bakeAuthorGeometry?.(),pt().materializeDeclarativeGeometry?.(g);let c=!!(g.userData&&(g.userData.xr&&typeof g.userData.xr=="object"&&Object.keys(g.userData.xr).length>0||g.userData.interactivity&&typeof g.userData.interactivity=="object"&&Object.keys(g.userData.interactivity).length>0)),P={name:g.name||(c?`Node_${f.length}`:"")},j=J(g.position?.x,0),G=J(g.position?.y,0),U=J(g.position?.z,0),Z=J(g.quaternion?.x,0),E=J(g.quaternion?.y,0),q=J(g.quaternion?.z,0),O=J(g.quaternion?.w,1),H=J(g.scale?.x,1),F=J(g.scale?.y,1),K=J(g.scale?.z,1);if((j||G||U)&&(P.translation=[j,G,U]),(Z||E||q||O!==1)&&(P.rotation=[Z,E,q,O]),(H!==1||F!==1||K!==1)&&(P.scale=[H,F,K]),g.visible===!1&&(P.extensions={...P.extensions||{},KHR_node_visibility:{visible:!1}},p.add("KHR_node_visibility")),g.userData&&Object.keys(g.userData).length>0&&(P.extras=JSON.parse(JSON.stringify(g.userData,(z,N)=>{if(!(z==="__proto__"||z==="prototype"||z==="constructor"))return typeof N=="function"?void 0:N})),g.userData.xr)){let z=ke(g.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:z,ANDROID_xr_scenecore:z},pt().xrTraitSerializer?.gltfNode(P,g.userData.xr),p.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(g.geometry){let z=g.geometry,N=z.attributes.position;if(N&&N.count>0){let Q=[1/0,1/0,1/0],tt=[-1/0,-1/0,-1/0];for(let at=0;at<N.count;at++){let st=N.getX(at),lt=N.getY(at),ot=N.getZ(at);st<Q[0]&&(Q[0]=st),st>tt[0]&&(tt[0]=st),lt<Q[1]&&(Q[1]=lt),lt>tt[1]&&(tt[1]=lt),ot<Q[2]&&(Q[2]=ot),ot>tt[2]&&(tt[2]=ot)}let it={attributes:{POSITION:n(N.array,"VEC3",34962,5126,N.count,Q,tt)}};if(z.attributes.normal&&(it.attributes.NORMAL=n(z.attributes.normal.array,"VEC3",34962,5126,z.attributes.normal.count)),z.attributes.uv&&(it.attributes.TEXCOORD_0=n(z.attributes.uv.array,"VEC2",34962,5126,z.attributes.uv.count)),z.index){let at=z.index.array instanceof Uint32Array;it.indices=n(z.index.array,"SCALAR",34963,at?5125:5123,z.index.count)}let Y=Array.isArray(g.material)?g.material[0]:g.material;Y&&(it.material=v(Y));let et=g.userData?.variants;if(et&&typeof et=="object"){let at=new Map;for(let st of Object.keys(et)){if(!st||st==="__proto__"||st==="constructor"||st==="prototype")continue;let lt=et[st];if(!lt||typeof lt!="object")continue;let ot=T.indexOf(st);if(ot===-1&&T.length<256&&(ot=T.length,T.push(st)),ot===-1)continue;let vt=v(lt),xt=at.get(vt);xt||(xt=[],at.set(vt,xt)),xt.push(ot)}if(at.size>0){let st=[];for(let[lt,ot]of at.entries())st.push({material:lt,variants:ot});it.extensions={...it.extensions||{},KHR_materials_variants:{mappings:st}},p.add("KHR_materials_variants")}}let rt=g;if(rt.isInstancedMesh&&typeof rt.count=="number"&&rt.count>0&&rt.instanceMatrix?.array){let at=Math.min(1e4,Math.floor(rt.count)),st=rt.instanceMatrix.array,lt=new Float32Array(at*3),ot=new Float32Array(at*4),vt=new Float32Array(at*3);for(let mt=0;mt<at;mt++){let{t:_t,r:Tt,s:Lt}=ae(st,mt*16);lt[mt*3]=_t[0],lt[mt*3+1]=_t[1],lt[mt*3+2]=_t[2],ot[mt*4]=Tt[0],ot[mt*4+1]=Tt[1],ot[mt*4+2]=Tt[2],ot[mt*4+3]=Tt[3],vt[mt*3]=Lt[0],vt[mt*3+1]=Lt[1],vt[mt*3+2]=Lt[2]}let xt={TRANSLATION:n(lt,"VEC3",0,5126,at),ROTATION:n(ot,"VEC4",0,5126,at),SCALE:n(vt,"VEC3",0,5126,at)};if(rt.instanceColor?.array&&rt.instanceColor.array.length>=at*3){let mt=new Float32Array(rt.instanceColor.array.subarray(0,at*3));xt._COLOR_0=n(mt,"VEC3",0,5126,at)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:xt}},p.add("EXT_mesh_gpu_instancing")}let ft=m.length;m.push({primitives:[it],name:g.name,...P.extras?{extras:P.extras}:{}}),P.mesh=ft}}let k=f.length;f.push(P),u.push(g),I.push(k);let W=g.children;if(Array.isArray(W)&&W.length>0){let z=[];P.children=z;for(let N=W.length-1;N>=0;N--)$.push({obj:W[N],parentKids:z})}}for(let g=0;g<f.length;g++){let I=f[g];I.children&&I.children.length===0?delete I.children:I.children&&I.children.length>0&&(I.extras?.xr?.lod||I.extensions?.ANDROID_xr_scenecore?.lod||u[g]?.isLOD)&&(I.extensions={...I.extensions||{},MSFT_lod:{ids:[...I.children]}},p.add("MSFT_lod"))}let B=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),_=[];if(typeof B=="function"&&u.length>0){let g=e?.duration??4,I=e?.fps??15,c=Math.max(2,Math.round(g*I)+1),P=new Float32Array(c),j=u.map(F=>[J(F.position?.x,0),J(F.position?.y,0),J(F.position?.z,0),J(F.quaternion?.x,0),J(F.quaternion?.y,0),J(F.quaternion?.z,0),J(F.quaternion?.w,1),J(F.scale?.x,1),J(F.scale?.y,1),J(F.scale?.z,1)]),G=u.map(()=>new Float32Array(c*3)),U=u.map(()=>new Float32Array(c*4)),Z=u.map(()=>new Float32Array(c*3));for(let F=0;F<c;F++){let K=F/(c-1)*g;P[F]=K;try{B(K)}catch{}for(let k=0;k<u.length;k++){let W=u[k];G[k][F*3]=J(W.position?.x,0),G[k][F*3+1]=J(W.position?.y,0),G[k][F*3+2]=J(W.position?.z,0);let z=J(W.quaternion?.x,0),N=J(W.quaternion?.y,0),Q=J(W.quaternion?.z,0),tt=J(W.quaternion?.w,1),it=Math.hypot(z,N,Q,tt)||1;if(z/=it,N/=it,Q/=it,tt/=it,F>0){let Y=(F-1)*4,et=U[k];et[Y]*z+et[Y+1]*N+et[Y+2]*Q+et[Y+3]*tt<0&&(z=-z,N=-N,Q=-Q,tt=-tt)}U[k][F*4]=z,U[k][F*4+1]=N,U[k][F*4+2]=Q,U[k][F*4+3]=tt,Z[k][F*3]=J(W.scale?.x,1),Z[k][F*3+1]=J(W.scale?.y,1),Z[k][F*3+2]=J(W.scale?.z,1)}}for(let F=0;F<u.length;F++){let K=u[F],k=j[F];K.position?.set(k[0],k[1],k[2]),K.quaternion?.set(k[3],k[4],k[5],k[6]),K.scale?.set(k[7],k[8],k[9])}t.updateMatrixWorld(!0);let E=null,q=()=>(E===null&&(E=n(P,"SCALAR",0,5126,c,[0],[g])),E),O=[],H=[];for(let F=0;F<u.length;F++){let K=j[F],k=(z,N,Q)=>z.some((tt,it)=>Math.abs(tt-K[Q+it%N])>1e-4),W=(z,N,Q,tt)=>{z&&H.push({sampler:O.push({input:q(),interpolation:"LINEAR",output:n(N,Q,0,5126,c)})-1,target:{node:F,path:tt}})};W(k(G[F],3,0),G[F],"VEC3","translation"),W(k(U[F],4,3),U[F],"VEC4","rotation"),W(k(Z[F],3,7),Z[F],"VEC3","scale")}H.length>0&&_.push({name:"ProceduralLoop",samplers:O,channels:H})}let L=Bt(f,m,t.userData),C=[],D=[],M=[];for(let g=0;g<f.length;g++){let I=f[g],c=se(I.extras?.xr);if(!c)continue;let{ae:P,src:j,preset:G,volume:U,loop:Z,isGlobal:E}=c,q=I.name||`Node_${g}`,O=D.length;D.push({name:`${q}_source`,gain:U,loop:Z,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:C.push({uri:j})-1}:{},...G?{extras:{preset:G,pitch:gt(P.pitch,.25,4,1)}}:{}});let H=M.length,F=gt(P.refDistance,.05,100,1),K=gt(P.coneInnerAngle,0,360,360),k=gt(P.coneOuterAngle,K,360,360);M.push({name:`${q}_emitter`,type:E?"global":"positional",gain:U,sources:[O],...E?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:gt(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:gt(P.rolloffFactor,0,10,1),coneInnerAngle:+(K*Math.PI/180).toFixed(6),coneOuterAngle:+(k*Math.PI/180).toFixed(6),coneOuterGain:gt(P.coneOuterGain,0,1,0)}}}),I.extensions={...I.extensions||{},KHR_audio_emitter:{emitter:H}},p.add("KHR_audio_emitter")}let o={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:b}],scene:0,nodes:f,meshes:m,materials:d,...R.length>0?{images:R}:{},...S.length>0?{samplers:S}:{},...l.length>0?{textures:l}:{},accessors:s,bufferViews:a,buffers:[{byteLength:r}],..._.length>0?{animations:_}:{},...L||p.size>0?{extensionsUsed:[...L?["KHR_interactivity"]:[],...p]}:{},...L||T.length>0||M.length>0?{extensions:{...L?{KHR_interactivity:L}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(g=>({name:g}))}}:{},...M.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:D,emitters:M}}:{}}}:{}},V=new Uint8Array(r),X=0;for(let g of i)V.set(g,X),X+=g.byteLength;return[{gltf:o,bin:V.buffer,lights:w,environmentIntensity:t.environmentIntensity},u]}function Rt(t){return new TextEncoder().encode(t)}function Ve(t,e){let{gltf:i,bin:r}=oe(t,e),a=JSON.stringify(i),s=Rt(a),m=(4-s.byteLength%4)%4,f=s.byteLength+m,p=20+f+8+r.byteLength,u=new Uint8Array(p),d=new DataView(u.buffer);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,p,!0),d.setUint32(12,f,!0),d.setUint32(16,1313821514,!0),u.set(s,20);for(let R=0;R<m;R++)u[20+s.byteLength+R]=32;let y=20+f;return d.setUint32(y,r.byteLength,!0),d.setUint32(y+4,5130562,!0),u.set(new Uint8Array(r),y+8),u}function le(t,e){let[i,r]=ne(t,e);return Dt(i,r)}function Dt(t,e){let i=[],r=t.gltf,a=pt().decoders.get("meshopt");a&&typeof a.decodeBufferViews=="function"&&a.decodeBufferViews(r,t);let s=t.bin,m=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),f=r.accessors||[],p=r.bufferViews||[],u=r.materials||[],d=r.meshes||[],y=r.nodes||[],R=new Set,S=u.map((T,w)=>re(R,wt(T?.name,`Material_${w}`)));function l(T){let w=f[T];if(!w)throw new Error(`Accessor ${T} not found`);let v=p[w.bufferView||0],h=(v.byteOffset||0)+(w.byteOffset||0),n=v.byteLength||0;return{acc:w,buffer:m.slice(h,h+n)}}function x(T,w,v,h){let n=[],b=d[T];if(!b)return n;let A=b.primitives||[];for(let $=0;$<A.length;$++){let B=A[$],_=B.attributes?.POSITION;if(_===void 0)continue;let{acc:L,buffer:C}=l(_),D=new Float32Array(C,0,L.count*3),M,o=B.attributes?.NORMAL;if(o!==void 0){let{acc:O,buffer:H}=l(o),F=new Float32Array(H,0,O.count*3);M=new Float32Array(F.length);for(let K=0;K<O.count;K++){let k=F[K*3],W=F[K*3+1],z=F[K*3+2],N=Math.hypot(k,W,z)||1;M[K*3]=k/N,M[K*3+1]=W/N,M[K*3+2]=z/N}}let V,X=B.attributes?.TEXCOORD_0;if(X!==void 0){let{acc:O,buffer:H}=l(X);V=new Float32Array(H,0,O.count*2)}let g;if(B.indices!==void 0){let{acc:O,buffer:H}=l(B.indices);g=O.componentType===5125?new Uint32Array(H,0,O.count):new Uint16Array(H,0,O.count);let F=L.count;for(let K of g)if(K>=F)throw new Error(`SecurityError: Index buffer value (${K}) out of vertex bounds [0, ${F}).`)}else{let O=L.count;g=O>65535?new Uint32Array(O):new Uint16Array(O);for(let H=0;H<O;H++)g[H]=H}let I="DefaultMaterial",c=[.8,.8,.8],P=.5,j=0,G=0,U=0,Z=1.5,E=1,q=[0,0,0];if(B.material!==void 0&&u[B.material]){let O=u[B.material];I=S[B.material]||`Material_${B.material}`;let H=O.pbrMetallicRoughness||{},F=(z,N)=>Array.isArray(z)&&z.length>=3?[z[0],z[1],z[2]]:N;c=F(H.baseColorFactor,[1,1,1]);let K=O.extras?.avgColor;Array.isArray(K)&&K.length>=3&&(c=[c[0]*K[0],c[1]*K[1],c[2]*K[2]]);let k=Array.isArray(H.baseColorFactor)&&typeof H.baseColorFactor[3]=="number"?H.baseColorFactor[3]:1;typeof H.roughnessFactor=="number"&&(P=H.roughnessFactor),typeof H.metallicFactor=="number"&&(j=H.metallicFactor),q=F(O.emissiveFactor,[0,0,0]);let W=O.extensions||{};W.KHR_materials_clearcoat&&(G=W.KHR_materials_clearcoat.clearcoatFactor??0,U=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof W.KHR_materials_ior?.ior=="number"&&(Z=W.KHR_materials_ior.ior),E=k*(1-(W.KHR_materials_transmission?.transmissionFactor??0))}n.push({name:A.length>1?`${w}_p${$}`:w,positions:D,indices:g,normals:M,uvs:V,materialName:I,color:c,roughness:P,metallic:j,clearcoat:G,clearcoatRoughness:U,ior:Z,opacity:E,emissiveColor:q,xrTraits:v||b.extras?.xr,...h?{invisible:!0}:{}})}return n}if(y.length>0){let T=new Float32Array(0),w=new Uint16Array(0),v=(D,M)=>{if(D===void 0)return null;let{acc:o,buffer:V}=l(D);return new Float32Array(V,0,o.count*M)},h=(D,M)=>Array.isArray(D)&&D.length>=3?[J(D[0],M),J(D[1],M),J(D[2],M)]:[M,M,M],n=(D,M,o)=>D&&D.length>=(M+1)*3?[D[M*3],D[M*3+1],D[M*3+2]]:o,b=(D,M,o)=>D&&D.length>=(M+1)*4?[D[M*4],D[M*4+1],D[M*4+2],D[M*4+3]]:o,A=new Map,$=r.animations?.[0];if($&&Array.isArray($.channels)&&Array.isArray($.samplers))for(let D of $.channels){let M=$.samplers[D?.sampler],o=D?.target?.node,V=D?.target?.path;if(!M||typeof o!="number"||M.input===void 0)continue;let X=A.get(o);X||(X={input:M.input},A.set(o,X)),V==="translation"?X.t=M.output:V==="rotation"?X.r=M.output:V==="scale"&&(X.s=M.output)}let B=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(B)||B.length===0){let D=new Set;for(let M of y)if(Array.isArray(M?.children))for(let o of M.children)D.add(o);B=[];for(let M=0;M<y.length;M++)D.has(M)||B.push(M);B.length===0&&(B=[0])}let _=new Set,L=[],C=(D,M)=>{if(Array.isArray(D))for(let o=D.length-1;o>=0;o--)L.push({idx:D[o],out:M})};for(C(B,i);L.length>0;){let{idx:D,out:M}=L.pop();if(typeof D!="number"||D<0||D>=y.length||_.has(D))continue;_.add(D);let o=y[D];if(!o)continue;let V=[0,0,0],X=[0,0,0,1],g=[1,1,1];if(Array.isArray(o.matrix)&&o.matrix.length===16){let E=ae(o.matrix);V=E.t,X=E.r,g=E.s}else V=h(o.translation,0),Array.isArray(o.rotation)&&o.rotation.length>=4&&(X=[J(o.rotation[0],0),J(o.rotation[1],0),J(o.rotation[2],0),J(o.rotation[3],1)]),g=h(o.scale,1);let I,c=A.get(D);if(c){let E=v(c.input,1);if(E&&E.length>0){let q=v(c.t,3),O=v(c.r,4),H=v(c.s,3),F=Array.from(E),K=[],k=[],W=[];for(let z=0;z<E.length;z++)K.push(n(q,z,V)),k.push(b(O,z,X)),W.push(n(H,z,g));I={times:F,translations:K,rotations:k,scales:W}}}let P=Array.isArray(o.children)?o.children:[],j=typeof o.mesh=="number"&&o.mesh>=0&&o.mesh<d.length,G=e?.[D]?.userData?.xr??o.extras?.xr;if(!j&&P.length===0&&(o.camera!==void 0||o.extensions?.KHR_lights_punctual||!o.name&&!o.extras&&!G&&!I))continue;let U=(E,q,O)=>({name:E,positions:T,indices:w,isXform:!0,xrTraits:G,timeSamples:I,translation:V,rotation:X,scale:g,children:q,...O?{invisible:!0}:{}}),Z=o.visible===!1||o.extensions?.KHR_node_visibility?.visible===!1||e?.[D]?.visible===!1;if(j){let E=o.name||d[o.mesh]?.name||`Mesh_${D}`,q=x(o.mesh,E,G,Z),O=o.extensions?.EXT_mesh_gpu_instancing?.attributes;if(O&&typeof O=="object"&&q.length>0){let H=v(O.TRANSLATION,3),F=v(O.ROTATION,4),K=v(O.SCALE,3),k=v(O._COLOR_0,3),W=Math.min(1e3,H?H.length/3:F?F.length/4:K?K.length/3:0);if(W>0){let z=[];for(let N=0;N<W;N++){let Q=n(H,N,[0,0,0]),tt=b(F,N,[0,0,0,1]),it=n(K,N,[1,1,1]);for(let Y of q){let et=Y.color||[.8,.8,.8],rt=k&&k.length>=(N+1)*3;z.push({...Y,name:`${Y.name}_${N}`,materialName:rt?`${Y.materialName}_inst_${N}`:Y.materialName,color:rt?[et[0]*k[N*3],et[1]*k[N*3+1],et[2]*k[N*3+2]]:Y.color,translation:Q,rotation:tt,scale:it})}}C(P,z),M.push(U(E,z,Z));continue}}if(q.length===1)q[0].translation=V,q[0].rotation=X,q[0].scale=g,q[0].timeSamples=I,P.length>0&&(q[0].children=[],C(P,q[0].children)),M.push(q[0]);else{let H=[...q];C(P,H),M.push(U(E,H,Z))}}else{let E=[];C(P,E),M.push(U(o.name||`Group_${D}`,E,Z))}}}else for(let T=0;T<d.length;T++){let w=d[T].name||`Mesh_${T}`;i.push(...x(T,w,d[T].extras?.xr))}return i}function wt(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function St(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ut(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var dt=(t,e,i)=>`(${ut(t)}, ${ut(e)}, ${ut(i)})`,he=(t,e,i,r)=>`(${ut(t)}, ${ut(e)}, ${ut(i)}, ${ut(r)})`;function ue(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=dt(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Oe(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${ut(t[r*2])}, ${ut(1-t[r*2+1])})`;return i.join(", ")}function $e(t){return Array.from(t).join(", ")}function It(t){let e=new Map,i=0,r=null,a=[...t];for(;a.length>0;){let l=a.pop();if(!l.isXform&&l.positions&&l.positions.length>0){let x=wt(l.materialName,"DefaultMaterial");e.has(x)||e.set(x,{color:l.color||[.8,.8,.8],roughness:l.roughness??.5,metallic:l.metallic??0,clearcoat:l.clearcoat??0,clearcoatRoughness:l.clearcoatRoughness??0,ior:l.ior??1.5,opacity:l.opacity??1,emissiveColor:l.emissiveColor||[0,0,0]})}if(l.timeSamples&&l.timeSamples.times.length>0){let x=l.timeSamples.times[l.timeSamples.times.length-1];x>i&&(i=x)}if(l.xrTraits?.anchor&&!r&&(r=l.xrTraits.anchor==="vertical"||l.xrTraits.anchor==="wall"?"vertical":"horizontal"),l.children)for(let x=l.children.length-1;x>=0;x--)a.push(l.children[x])}let s="";i>0&&(s=`startTimeCode = 0
|
|
250
|
+
endTimeCode = ${ut(i)}
|
|
254
251
|
timeCodesPerSecond = 1.0
|
|
255
|
-
`);let
|
|
252
|
+
`);let m="";r&&(m=`uniform token preliminary:anchoring:type = "plane"
|
|
256
253
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
257
|
-
`);let
|
|
254
|
+
`);let f=`#usda 1.0
|
|
258
255
|
(
|
|
259
256
|
defaultPrim = "Root"
|
|
260
257
|
metersPerUnit = 1.0
|
|
261
258
|
upAxis = "Y"
|
|
262
|
-
${
|
|
259
|
+
${s})
|
|
263
260
|
|
|
264
261
|
def Xform "Root" (
|
|
265
262
|
kind = "component"
|
|
266
263
|
)
|
|
267
264
|
{
|
|
268
|
-
${
|
|
265
|
+
${m}def Scope "Materials"
|
|
269
266
|
{
|
|
270
|
-
`;for(let[
|
|
271
|
-
`,
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
274
|
-
`),(
|
|
275
|
-
`),
|
|
267
|
+
`;for(let[l,x]of e.entries()){let[T,w,v]=x.color,[h,n,b]=x.emissiveColor,A="";x.clearcoat>0&&(A+=`float inputs:clearcoat = ${ut(x.clearcoat)}
|
|
268
|
+
`,A+=`float inputs:clearcoatRoughness = ${ut(x.clearcoatRoughness)}
|
|
269
|
+
`),x.ior!==1.5&&(A+=`float inputs:ior = ${ut(x.ior)}
|
|
270
|
+
`),x.opacity<1&&(A+=`float inputs:opacity = ${ut(x.opacity)}
|
|
271
|
+
`),(h>0||n>0||b>0)&&(A+=`color3f inputs:emissiveColor = ${dt(h,n,b)}
|
|
272
|
+
`),f+=`def Material "${l}"
|
|
276
273
|
{
|
|
277
274
|
def Shader "PBRShader"
|
|
278
275
|
{
|
|
279
276
|
uniform token info:id = "UsdPreviewSurface"
|
|
280
|
-
color3f inputs:diffuseColor =
|
|
281
|
-
float inputs:metallic = ${
|
|
282
|
-
float inputs:roughness = ${
|
|
283
|
-
${
|
|
277
|
+
color3f inputs:diffuseColor = ${dt(T,w,v)}
|
|
278
|
+
float inputs:metallic = ${ut(x.metallic)}
|
|
279
|
+
float inputs:roughness = ${ut(x.roughness)}
|
|
280
|
+
${A}token outputs:surface
|
|
284
281
|
}
|
|
285
|
-
token outputs:surface.connect = </Root/Materials/${
|
|
282
|
+
token outputs:surface.connect = </Root/Materials/${l}/PBRShader.outputs:surface>
|
|
286
283
|
}
|
|
287
|
-
`}
|
|
284
|
+
`}f+=`}
|
|
288
285
|
def Scope "Meshes"
|
|
289
286
|
{
|
|
290
|
-
`;let
|
|
287
|
+
`;let p=(l,x,T)=>{let w=[];x&&w.push('"MaterialBindingAPI"');let v=!!(l?.rigidBody&&l.rigidBody!=="none"&&(typeof l.rigidBody!="object"||l.rigidBody.enabled!==!1)),h=!!(l?.physics&&l.physics!=="none"||v);h&&w.push(...v?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let n=[];if(w.length>0&&n.push(`prepend apiSchemas = [${w.join(", ")}]`),l){let _=pt().xrTraitSerializer?.usdLines(l,St)??[];if(!_.length)for(let L of["grab","billboard","follow","anchor","physics"]){let C=L==="follow"&&typeof l.follow=="object"?l.follow.mode??"head":l[L];C!==void 0&&_.push(`string ${L} = "${St(C)}"`)}_.length>0&&n.push(`customData = {
|
|
291
288
|
dictionary xr = {
|
|
292
|
-
${
|
|
289
|
+
${_.join(`
|
|
293
290
|
`)}
|
|
294
291
|
}
|
|
295
|
-
}`)
|
|
296
|
-
${
|
|
292
|
+
}`)}let b=n.length>0?` (
|
|
293
|
+
${n.join(`
|
|
297
294
|
`)}
|
|
298
|
-
)
|
|
299
|
-
{
|
|
300
|
-
|
|
301
|
-
bool physics:kinematicEnabled = ${U}
|
|
295
|
+
)`:"",A=T?`uniform token visibility = "invisible"
|
|
296
|
+
`:"";if(h){let _=l?.rigidBody??l?.physics,L=_?.body??_?.mode??_;A+=`bool physics:rigidBodyEnabled = true
|
|
297
|
+
bool physics:kinematicEnabled = ${L==="static"||L==="kinematic"}
|
|
302
298
|
bool physics:collisionEnabled = true
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
299
|
+
`,_?.mass>0&&Number.isFinite(_.mass)&&(A+=`float physics:mass = ${ut(_.mass)}
|
|
300
|
+
`)}let $=se(l),B=$?`def SpatialAudio "AudioEmitter"
|
|
301
|
+
{
|
|
302
|
+
${$.src?`asset inputs:file = @${St($.src)}@
|
|
303
|
+
`:""}uniform token inputs:auralMode = "${$.isGlobal?"nonSpatial":"spatial"}"
|
|
304
|
+
uniform token inputs:playbackMode = "${$.loop?"loopFromStart":"onceFromStart"}"
|
|
305
|
+
double gain = ${ut($.volume)}
|
|
306
|
+
}
|
|
307
|
+
`:"";return{header:b,body:A,tail:B}},u=l=>{if(l.timeSamples&&l.timeSamples.times.length>0){let n=l.timeSamples,b=(_,L,C)=>n.times.map((D,M)=>`${ut(D)}: ${C(_?.[M]||L)}`).join(", "),A=b(n.translations,[0,0,0],_=>dt(_[0],_[1],_[2])),$=b(n.rotations,[0,0,0,1],_=>{let L=Math.hypot(_[0],_[1],_[2],_[3])||1;return he(_[3]/L,_[0]/L,_[1]/L,_[2]/L)}),B=b(n.scales,[1,1,1],_=>dt(_[0],_[1],_[2]));return`double3 xformOp:translate.timeSamples = { ${A} }
|
|
308
|
+
quatf xformOp:orient.timeSamples = { ${$} }
|
|
309
|
+
double3 xformOp:scale.timeSamples = { ${B} }
|
|
306
310
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
307
|
-
`}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
311
|
+
`}let x=[],T="",w=l.translation;w&&(Math.abs(w[0])>1e-7||Math.abs(w[1])>1e-7||Math.abs(w[2])>1e-7)&&(T+=`double3 xformOp:translate = ${dt(w[0],w[1],w[2])}
|
|
312
|
+
`,x.push('"xformOp:translate"'));let v=l.rotation;if(v){let n=Math.hypot(v[0],v[1],v[2],v[3])||1,b=v[0]/n,A=v[1]/n,$=v[2]/n,B=v[3]/n;(1-Math.abs(B)>1e-7||Math.hypot(b,A,$)>1e-7)&&(T+=`quatf xformOp:orient = ${he(B,b,A,$)}
|
|
313
|
+
`,x.push('"xformOp:orient"'))}let h=l.scale;return h&&(Math.abs(h[0]-1)>1e-7||Math.abs(h[1]-1)>1e-7||Math.abs(h[2]-1)>1e-7)&&(T+=`float3 xformOp:scale = ${dt(h[0],h[1],h[2])}
|
|
314
|
+
`,x.push('"xformOp:scale"')),x.length>0&&(T+=`uniform token[] xformOpOrder = [${x.join(", ")}]
|
|
315
|
+
`),T},d=l=>{let x=l.positions.length/3,T=1/0,w=1/0,v=1/0,h=-1/0,n=-1/0,b=-1/0;for(let L=0;L<x;L++){let C=l.positions[L*3],D=l.positions[L*3+1],M=l.positions[L*3+2];C<T&&(T=C),C>h&&(h=C),D<w&&(w=D),D>n&&(n=D),M<v&&(v=M),M>b&&(b=M)}isFinite(T)||(T=w=v=-1,h=n=b=1);let A=Math.floor(l.indices.length/3),$=wt(l.materialName,"DefaultMaterial"),B=A>0?A===1?"3":"3, ".repeat(A-1)+"3":"",_=`float3[] extent = [${dt(T,w,v)}, ${dt(h,n,b)}]
|
|
316
|
+
int[] faceVertexCounts = [${B}]
|
|
317
|
+
int[] faceVertexIndices = [${$e(l.indices)}]
|
|
318
|
+
point3f[] points = [${ue(l.positions)}]
|
|
319
|
+
`;return l.normals&&l.normals.length===l.positions.length&&(_+=`normal3f[] normals = [${ue(l.normals)}] (
|
|
312
320
|
interpolation = "vertex"
|
|
313
321
|
)
|
|
314
|
-
`),
|
|
322
|
+
`),l.uvs&&l.uvs.length===x*2&&(_+=`texCoord2f[] primvars:st = [${Oe(l.uvs,x)}] (
|
|
315
323
|
interpolation = "vertex"
|
|
316
324
|
)
|
|
317
|
-
`),
|
|
318
|
-
}
|
|
319
|
-
`
|
|
325
|
+
`),_+=`rel material:binding = </Root/Materials/${$}>
|
|
326
|
+
`,_},y=new Set,R=[];for(let l=t.length-1;l>=0;l--)R.push({node:t[l],siblings:y});let S=0;for(;R.length>0;){let l=R.pop();if(l.close){f+=`}
|
|
327
|
+
`;continue}let{node:x,siblings:T}=l,w=!!(x.isXform||x.positions.length===0),v=re(T,wt(x.name,w?`Group_${S}`:`Mesh_${S}`));S++;let h=x.children||[];if(w){let n=p(x.xrTraits,!1,x.invisible);f+=`def Xform "${v}"${n.header}
|
|
328
|
+
{
|
|
329
|
+
${n.body}${u(x)}${n.tail}`,R.push({close:!0});let b=new Set;for(let A=h.length-1;A>=0;A--)R.push({node:h[A],siblings:b})}else if(h.length>0){let n=p(x.xrTraits,!1,x.invisible),b=`${v}_mesh`;f+=`def Xform "${v}"${n.header}
|
|
330
|
+
{
|
|
331
|
+
${n.body}${u(x)}${n.tail}`,f+=`def Mesh "${b}" (
|
|
332
|
+
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
333
|
+
)
|
|
334
|
+
{
|
|
335
|
+
${d(x)}}
|
|
336
|
+
`,R.push({close:!0});let A=new Set([b]);for(let $=h.length-1;$>=0;$--)R.push({node:h[$],siblings:A})}else{let n=p(x.xrTraits,!0,x.invisible);f+=`def Mesh "${v}"${n.header}
|
|
337
|
+
{
|
|
338
|
+
${n.body}${u(x)}${d(x)}${n.tail}}
|
|
339
|
+
`}}return f+=`}
|
|
320
340
|
}
|
|
321
|
-
`,
|
|
341
|
+
`,f}function ce(t,e){if(t&&typeof t.traverse=="function"){let a=le(t,e);return It(a)}let i=At(t),r=Dt(i);return It(r)}var Ft=null;function me(t){if(!Ft){Ft=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let a=0;a<8;a++)r=r&1?3988292384^r>>>1:r>>>1;Ft[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=Ft[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function fe(t){let e=[],i=0,r=[];for(let d of t){let y=Rt(d.filename),R=me(d.data),S=d.data.length,l=30+y.length,x=(i+l)%64,T=x!==0?64-x:0,w=new Uint8Array(l+T),v=new DataView(w.buffer);v.setUint32(0,67324752,!0),v.setUint16(4,20,!0),v.setUint32(14,R,!0),v.setUint32(18,S,!0),v.setUint32(22,S,!0),v.setUint16(26,y.length,!0),v.setUint16(28,T,!0),w.set(y,30),e.push({offset:i,size:S,crc:R,filenameBytes:y,entry:d}),r.push(w,d.data),i+=w.length+d.data.length}let a=i;for(let d of e){let y=new Uint8Array(46+d.filenameBytes.length),R=new DataView(y.buffer);R.setUint32(0,33639248,!0),R.setUint16(4,20,!0),R.setUint16(6,20,!0),R.setUint32(16,d.crc,!0),R.setUint32(20,d.size,!0),R.setUint32(24,d.size,!0),R.setUint16(28,d.filenameBytes.length,!0),R.setUint32(42,d.offset,!0),y.set(d.filenameBytes,46),r.push(y),i+=y.length}let s=i-a,m=new Uint8Array(22),f=new DataView(m.buffer);f.setUint32(0,101010256,!0),f.setUint16(8,e.length,!0),f.setUint16(10,e.length,!0),f.setUint32(12,s,!0),f.setUint32(16,a,!0),r.push(m),i+=22;let p=new Uint8Array(i),u=0;for(let d of r)p.set(d,u),u+=d.length;return p}var pe=t=>fe([{filename:"model.usda",data:Rt(t)}]);function Ue(t){return pe(ce(t))}function de(t){return pe(It(Dt(At(t))))}function ge(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():de(t)}function Be(t){let e=ge(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}export{fe as buildUSDZZip,me as calculateCRC32,Bt as compileInteractivityGraph,Be as createUSDZBlob,Rt as encodeUtf8,Dt as extractMeshesFromGLB,le as extractMeshesFromScene,ce as generateUSDA,It as generateUSDAFromMeshes,ge as generateUSDZ,de as glbToUSDZ,wt as sanitizeUsdIdentifier,St as sanitizeUsdStringLiteral,oe as sceneToCanvas3D,Ve as sceneToGLB,Ue as sceneToUSDZ};
|