three-live 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +2 -1
  3. package/dist/three-author-engine.js +57 -39
  4. package/dist/three-author.cjs +52 -34
  5. package/dist/three-author.d.ts +2 -1
  6. package/dist/three-author.js +52 -34
  7. package/dist/three-convert.cjs +55 -37
  8. package/dist/three-convert.d.ts +2 -1
  9. package/dist/three-convert.js +55 -37
  10. package/dist/three-live-animation.cjs +7 -7
  11. package/dist/three-live-animation.d.ts +2 -1
  12. package/dist/three-live-animation.js +7 -7
  13. package/dist/three-live-animation.min.js +7 -7
  14. package/dist/three-live-cad.cjs +2 -2
  15. package/dist/three-live-cad.d.ts +2 -1
  16. package/dist/three-live-cad.js +2 -2
  17. package/dist/three-live-cad.min.js +2 -2
  18. package/dist/three-live-element.cjs +24 -6
  19. package/dist/three-live-element.d.ts +2 -1
  20. package/dist/three-live-element.js +24 -6
  21. package/dist/three-live-full.cjs +81 -63
  22. package/dist/three-live-full.js +81 -63
  23. package/dist/three-live-full.min.js +81 -63
  24. package/dist/three-live-studio.cjs +18 -18
  25. package/dist/three-live-studio.d.ts +2 -1
  26. package/dist/three-live-studio.js +18 -18
  27. package/dist/three-live-studio.min.js +18 -18
  28. package/dist/three-live-viewer.cjs +24 -6
  29. package/dist/three-live-viewer.d.ts +2 -1
  30. package/dist/three-live-viewer.js +24 -6
  31. package/dist/three-live-viewer.min.js +24 -6
  32. package/dist/three-live.cjs +55 -37
  33. package/dist/three-live.js +55 -37
  34. package/dist/three-live.min.js +55 -37
  35. package/dist/three-view.cjs +24 -6
  36. package/dist/three-view.d.ts +2 -1
  37. package/dist/three-view.js +24 -6
  38. package/dist/three-xr.cjs +49 -31
  39. package/dist/three-xr.d.ts +2 -1
  40. package/dist/three-xr.js +49 -31
  41. package/package.json +1 -1
@@ -14,16 +14,31 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- "use strict";var Ee=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var st=(i,e)=>{for(var t in e)Ee(i,t,{get:e[t],enumerable:!0})},at=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of nt(e))!rt.call(i,n)&&n!==t&&Ee(i,n,{get:()=>e[n],enumerable:!(r=it(e,n))||r.enumerable});return i};var ot=i=>at(Ee({},"__esModule",{value:!0}),i);var ft={};st(ft,{MicroViewer:()=>me,SANDBOX_HOST_SCENE_LIMITS:()=>mt,ThreeView:()=>me,decodeUtf8:()=>Ue,default:()=>dt,evaluateToneMapping:()=>ct,getDecoder:()=>le,getRegisteredPlugins:()=>Le,isGLBData:()=>Xe,mat3NormalFromMat4:()=>se,mat4Create:()=>H,mat4FromRotationTranslationScale:()=>Me,mat4Invert:()=>Pe,mat4LookAt:()=>ge,mat4Multiply:()=>q,mat4Perspective:()=>ve,parseGLB:()=>Be,rayIntersectsTriangle:()=>De,readFloat32Array:()=>Oe,registerDecoder:()=>We,registerPlugin:()=>Ce,resolveNodeWorldMatrices:()=>Ae,sanitizeTextureUri:()=>Ye,toGLBData:()=>Ie,unprojectPoint:()=>Re});module.exports=ot(ft);function H(){let i=new Float32Array(16);return i[0]=1,i[5]=1,i[10]=1,i[15]=1,i}function ve(i,e,t,r,n){let s=1/Math.tan(e/2);i.fill(0),i[0]=s/t,i[5]=s,i[11]=-1;let a=1/(r-n);return i[10]=(n+r)*a,i[14]=2*n*r*a,i}function ge(i,e,t,r){let[n,s,a]=e,[u,l,c]=r,[o,h,g]=t,y=n-o,m=s-h,p=a-g,b=Math.hypot(y,m,p);b<=1e-5?(y=0,m=0,p=1):(y/=b,m/=b,p/=b);let R=l*p-c*m,D=c*y-u*p,M=u*m-l*y;b=Math.hypot(R,D,M),b<=1e-5?(R=0,D=0,M=0):(R/=b,D/=b,M/=b);let T=m*M-p*D,v=p*R-y*M,d=y*D-m*R;return b=Math.hypot(T,v,d),b<=1e-5?(T=0,v=0,d=0):(T/=b,v/=b,d/=b),i[0]=R,i[1]=T,i[2]=y,i[3]=0,i[4]=D,i[5]=v,i[6]=m,i[7]=0,i[8]=M,i[9]=d,i[10]=p,i[11]=0,i[12]=-(R*n+D*s+M*a),i[13]=-(T*n+v*s+d*a),i[14]=-(y*n+m*s+p*a),i[15]=1,i}function q(i,e,t){let r=e[0],n=e[1],s=e[2],a=e[3],u=e[4],l=e[5],c=e[6],o=e[7],h=e[8],g=e[9],y=e[10],m=e[11],p=e[12],b=e[13],R=e[14],D=e[15],M=t[0],T=t[1],v=t[2],d=t[3];return i[0]=M*r+T*u+v*h+d*p,i[1]=M*n+T*l+v*g+d*b,i[2]=M*s+T*c+v*y+d*R,i[3]=M*a+T*o+v*m+d*D,M=t[4],T=t[5],v=t[6],d=t[7],i[4]=M*r+T*u+v*h+d*p,i[5]=M*n+T*l+v*g+d*b,i[6]=M*s+T*c+v*y+d*R,i[7]=M*a+T*o+v*m+d*D,M=t[8],T=t[9],v=t[10],d=t[11],i[8]=M*r+T*u+v*h+d*p,i[9]=M*n+T*l+v*g+d*b,i[10]=M*s+T*c+v*y+d*R,i[11]=M*a+T*o+v*m+d*D,M=t[12],T=t[13],v=t[14],d=t[15],i[12]=M*r+T*u+v*h+d*p,i[13]=M*n+T*l+v*g+d*b,i[14]=M*s+T*c+v*y+d*R,i[15]=M*a+T*o+v*m+d*D,i}function Me(i,e,t,r){let n=e[0],s=e[1],a=e[2],u=e[3],l=n+n,c=s+s,o=a+a,h=n*l,g=n*c,y=n*o,m=s*c,p=s*o,b=a*o,R=u*l,D=u*c,M=u*o,T=r[0],v=r[1],d=r[2];return i[0]=(1-(m+b))*T,i[1]=(g+M)*T,i[2]=(y-D)*T,i[3]=0,i[4]=(g-M)*v,i[5]=(1-(h+b))*v,i[6]=(p+R)*v,i[7]=0,i[8]=(y+D)*d,i[9]=(p-R)*d,i[10]=(1-(h+m))*d,i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i}function se(i,e){let t=e[0],r=e[1],n=e[2],s=e[4],a=e[5],u=e[6],l=e[8],c=e[9],o=e[10],h=o*a-u*c,g=-o*s+u*l,y=c*s-a*l,m=t*h+r*g+n*y;return m&&(m=1/m,i[0]=h*m,i[1]=g*m,i[2]=y*m,i[3]=(-o*r+n*c)*m,i[4]=(o*t-n*l)*m,i[5]=(-c*t+r*l)*m,i[6]=(u*r-n*a)*m,i[7]=(-u*t+n*s)*m,i[8]=(a*t-r*s)*m),i}function Pe(i,e){let t=e[0],r=e[1],n=e[2],s=e[3],a=e[4],u=e[5],l=e[6],c=e[7],o=e[8],h=e[9],g=e[10],y=e[11],m=e[12],p=e[13],b=e[14],R=e[15],D=t*u-r*a,M=t*l-n*a,T=t*c-s*a,v=r*l-n*u,d=r*c-s*u,F=n*c-s*l,B=o*p-h*m,C=o*b-g*m,S=o*R-y*m,P=h*b-g*p,E=h*R-y*p,f=g*R-y*b,w=D*f-M*E+T*P+v*S-d*C+F*B;return w?(w=1/w,i[0]=(u*f-l*E+c*P)*w,i[1]=(n*E-r*f-s*P)*w,i[2]=(p*F-b*d+R*v)*w,i[3]=(g*d-h*F-y*v)*w,i[4]=(l*S-a*f-c*C)*w,i[5]=(t*f-n*S+s*C)*w,i[6]=(b*T-m*F-R*M)*w,i[7]=(o*F-g*T+y*M)*w,i[8]=(a*E-u*S+c*B)*w,i[9]=(r*S-t*E-s*B)*w,i[10]=(m*d-p*T+R*D)*w,i[11]=(h*T-o*d-y*D)*w,i[12]=(u*C-a*P-l*B)*w,i[13]=(t*P-r*C+n*B)*w,i[14]=(p*M-m*v-b*D)*w,i[15]=(o*v-h*M+g*D)*w,i):null}function Re(i,e,t,r,n){let s=n[0]*e+n[4]*t+n[8]*r+n[12],a=n[1]*e+n[5]*t+n[9]*r+n[13],u=n[2]*e+n[6]*t+n[10]*r+n[14],l=n[3]*e+n[7]*t+n[11]*r+n[15],c=l!==0?1/l:1;i[0]=s*c,i[1]=a*c,i[2]=u*c}function De(i,e,t,r,n,s,a,u,l,c,o,h,g,y,m,p,b=0){let R=c-a,D=o-u,M=h-l,T=g-a,v=y-u,d=m-l,F=n*d-s*v,B=s*T-r*d,C=r*v-n*T,S=R*F+D*B+M*C;if(S>-1e-7&&S<1e-7)return!1;let P=1/S,E=i-a,f=e-u,w=t-l,L=P*(E*F+f*B+w*C);if(L<-b||L>1+b)return!1;let x=f*M-w*D,G=w*R-E*M,A=E*D-f*R,j=P*(r*x+n*G+s*A);if(j<-b||L+j>1+b)return!1;let W=P*(T*x+v*G+d*A);if(W>1e-4&&W<p.distance){p.distance=W,p.point=[i+r*W,e+n*W,t+s*W];let Y=D*d-M*v,_=M*T-R*d,V=R*v-D*T,X=Math.hypot(Y,_,V)||1;return p.normal=[Y/X,_/X,V/X],!0}return!1}function Ae(i,e){let t=Array.isArray(i?.nodes)?i.nodes.length:0,r=[];for(let o=0;o<t;o++)r.push(H());if(t===0)return r;let n=new Set;for(let o of i.nodes)if(Array.isArray(o.children))for(let h of o.children)n.add(h);let s=new Set,a=128,u=(o,h,g=0)=>{if(g>a||o<0||o>=t||s.has(o))return;s.add(o);let y=i.nodes[o];if(!y)return;let m=H();if(e&&e[o])m.set(e[o]);else if(y.matrix&&y.matrix.length===16)m.set(y.matrix);else{let b=y.translation||[0,0,0],R=y.rotation||[0,0,0,1],D=y.scale||[1,1,1];Me(m,R,b,D)}let p=r[o];if(h?q(p,h,m):p.set(m),Array.isArray(y.children))for(let b of y.children)typeof b=="number"&&u(b,p,g+1)},l=[],c=i.scenes&&i.scenes[i.scene!==void 0?i.scene:0];if(c&&Array.isArray(c.nodes))l.push(...c.nodes);else for(let o=0;o<t;o++)n.has(o)||l.push(o);for(let o of l)u(o,null);for(let o=0;o<t;o++)!n.has(o)&&!l.includes(o)&&u(o,null);return r}var we="__THREE_LIVE_REGISTRY__";function ce(){let i=typeof globalThis<"u"?globalThis:{};if(!i[we]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(i,we,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{i[we]=e}}return i[we]}var Z=ce().plugins;function Ce(i){let e=ce().plugins;e.some(t=>t.name===i.name)||e.push(i),i.onRegister?.()}function Le(){return ce().plugins}function Ue(i){return new TextDecoder().decode(i)}var He=ce().decoders;function We(i,e){He.set(i.toLowerCase(),e)}function le(i){return He.get(i.toLowerCase())}function Be(i){let e=ArrayBuffer.isView(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i,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 g=t.getUint8(0);throw g===123||g===32||g===10||g===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let n=t.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=t.getUint32(8,!0),a=12,u=null,l=null;for(;a+8<=s&&a+8<=e.byteLength;){let g=t.getUint32(a,!0),y=t.getUint32(a+4,!0),m=a+8;if(m+g>e.byteLength)throw new Error(`Truncated GLB chunk: required ${m+g} bytes, buffer has ${e.byteLength}`);if(y===1313821514){let p=new Uint8Array(e,m,g),b=Ue(p);u=JSON.parse(b,(R,D)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:D)}else y===5130562&&(l=e.slice(m,m+g));a=m+g}if(!u)throw new Error("Missing JSON chunk in GLB");let c=u.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!le("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(c.includes("EXT_meshopt_compression")&&!le("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(c.includes("KHR_texture_basisu")&&!le("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let o=l||new ArrayBuffer(0),h={gltf:u,bin:o,animations:[]};for(let g of Z)g.onParseGLB?.(h);return h}function Oe(i,e,t){return e%4===0?new Float32Array(i,e,t):new Float32Array(i.slice(e,e+t*4))}function Xe(i){return typeof i=="object"&&i!==null&&"gltf"in i&&typeof i.gltf=="object"&&i.gltf!==null&&"bin"in i&&(i.bin instanceof ArrayBuffer||ArrayBuffer.isView(i.bin))}function Ie(i){if(Xe(i))return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return Be(i);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ze=`#version 300 es
17
+ "use strict";var Te=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(n,e)=>{for(var t in e)Te(n,t,{get:e[t],enumerable:!0})},nt=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Qe(e))!et.call(n,i)&&i!==t&&Te(n,i,{get:()=>e[i],enumerable:!(s=Je(e,i))||s.enumerable});return n};var it=n=>nt(Te({},"__esModule",{value:!0}),n);var pt={};tt(pt,{MicroViewer:()=>he,SANDBOX_HOST_SCENE_LIMITS:()=>mt,ThreeView:()=>he,decodeUtf8:()=>We,default:()=>ft,evaluateToneMapping:()=>at,getDecoder:()=>ce,getRegisteredPlugins:()=>De,isGLBData:()=>Xe,mat3NormalFromMat4:()=>oe,mat4Create:()=>X,mat4FromRotationTranslationScale:()=>ve,mat4Invert:()=>we,mat4LookAt:()=>de,mat4Multiply:()=>$,mat4Perspective:()=>me,normalizeToneMapping:()=>pe,parseGLB:()=>Ne,rayIntersectsTriangle:()=>Ee,readFloat32Array:()=>st,registerDecoder:()=>Oe,registerPlugin:()=>Ae,resolveNodeWorldMatrices:()=>Pe,sanitizeTextureUri:()=>Ye,toGLBData:()=>Ie,toneMappingShaderIndex:()=>Ue,unprojectPoint:()=>ge});module.exports=it(pt);var rt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Re(n,e,t,s){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let r=Number(t.count??0);if(!Number.isInteger(r)||r<=0)return null;let o=t.componentType??5126,c=rt[o];if(!c)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let a=c*s,l=i.byteStride&&i.byteStride>0?i.byteStride:a,u=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(u)||u<0||l<a||u+(r-1)*l+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&l===a&&u%4===0)return new Float32Array(e,u,r*s);let p=new DataView(e),m=t.normalized===!0,g=new Float32Array(r*s);for(let d=0;d<r;d++){let E=u+d*l;for(let b=0;b<s;b++){let x=E+b*c,R;switch(o){case 5126:R=p.getFloat32(x,!0);break;case 5120:R=p.getInt8(x),m&&(R=Math.max(R/127,-1));break;case 5121:R=p.getUint8(x),m&&(R/=255);break;case 5122:R=p.getInt16(x,!0),m&&(R=Math.max(R/32767,-1));break;case 5123:R=p.getUint16(x,!0),m&&(R/=65535);break;default:R=p.getUint32(x,!0),m&&(R/=4294967295)}g[d*s+b]=R}}return g}function Be(n,e){let t=Number(e.offset?.[0]??0)||0,s=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),r=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,c=Math.cos(o),a=Math.sin(o),l=(Number.isFinite(i)?i:1)*c,u=(Number.isFinite(i)?i:1)*a,p=-(Number.isFinite(r)?r:1)*a,m=(Number.isFinite(r)?r:1)*c;for(let g=0;g+1<n.length;g+=2){let d=n[g],E=n[g+1];n[g]=l*d+u*E+t,n[g+1]=p*d+m*E+s}}function X(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function me(n,e,t,s,i){let r=1/Math.tan(e/2);n.fill(0),n[0]=r/t,n[5]=r,n[11]=-1;let o=1/(s-i);return n[10]=(i+s)*o,n[14]=2*i*s*o,n}function de(n,e,t,s){let[i,r,o]=e,[c,a,l]=s,[u,p,m]=t,g=i-u,d=r-p,E=o-m,b=Math.hypot(g,d,E);b<=1e-5?(g=0,d=0,E=1):(g/=b,d/=b,E/=b);let x=a*E-l*d,R=l*g-c*E,y=c*d-a*g;b=Math.hypot(x,R,y),b<=1e-5?(x=0,R=0,y=0):(x/=b,R/=b,y/=b);let M=d*y-E*R,f=E*x-g*y,T=g*R-d*x;return b=Math.hypot(M,f,T),b<=1e-5?(M=0,f=0,T=0):(M/=b,f/=b,T/=b),n[0]=x,n[1]=M,n[2]=g,n[3]=0,n[4]=R,n[5]=f,n[6]=d,n[7]=0,n[8]=y,n[9]=T,n[10]=E,n[11]=0,n[12]=-(x*i+R*r+y*o),n[13]=-(M*i+f*r+T*o),n[14]=-(g*i+d*r+E*o),n[15]=1,n}function $(n,e,t){let s=e[0],i=e[1],r=e[2],o=e[3],c=e[4],a=e[5],l=e[6],u=e[7],p=e[8],m=e[9],g=e[10],d=e[11],E=e[12],b=e[13],x=e[14],R=e[15],y=t[0],M=t[1],f=t[2],T=t[3];return n[0]=y*s+M*c+f*p+T*E,n[1]=y*i+M*a+f*m+T*b,n[2]=y*r+M*l+f*g+T*x,n[3]=y*o+M*u+f*d+T*R,y=t[4],M=t[5],f=t[6],T=t[7],n[4]=y*s+M*c+f*p+T*E,n[5]=y*i+M*a+f*m+T*b,n[6]=y*r+M*l+f*g+T*x,n[7]=y*o+M*u+f*d+T*R,y=t[8],M=t[9],f=t[10],T=t[11],n[8]=y*s+M*c+f*p+T*E,n[9]=y*i+M*a+f*m+T*b,n[10]=y*r+M*l+f*g+T*x,n[11]=y*o+M*u+f*d+T*R,y=t[12],M=t[13],f=t[14],T=t[15],n[12]=y*s+M*c+f*p+T*E,n[13]=y*i+M*a+f*m+T*b,n[14]=y*r+M*l+f*g+T*x,n[15]=y*o+M*u+f*d+T*R,n}function ve(n,e,t,s){let i=e[0],r=e[1],o=e[2],c=e[3],a=i+i,l=r+r,u=o+o,p=i*a,m=i*l,g=i*u,d=r*l,E=r*u,b=o*u,x=c*a,R=c*l,y=c*u,M=s[0],f=s[1],T=s[2];return n[0]=(1-(d+b))*M,n[1]=(m+y)*M,n[2]=(g-R)*M,n[3]=0,n[4]=(m-y)*f,n[5]=(1-(p+b))*f,n[6]=(E+x)*f,n[7]=0,n[8]=(g+R)*T,n[9]=(E-x)*T,n[10]=(1-(p+d))*T,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function oe(n,e){let t=e[0],s=e[1],i=e[2],r=e[4],o=e[5],c=e[6],a=e[8],l=e[9],u=e[10],p=u*o-c*l,m=-u*r+c*a,g=l*r-o*a,d=t*p+s*m+i*g;return d&&(d=1/d,n[0]=p*d,n[1]=m*d,n[2]=g*d,n[3]=(-u*s+i*l)*d,n[4]=(u*t-i*a)*d,n[5]=(-l*t+s*a)*d,n[6]=(c*s-i*o)*d,n[7]=(-c*t+i*r)*d,n[8]=(o*t-s*r)*d),n}function we(n,e){let t=e[0],s=e[1],i=e[2],r=e[3],o=e[4],c=e[5],a=e[6],l=e[7],u=e[8],p=e[9],m=e[10],g=e[11],d=e[12],E=e[13],b=e[14],x=e[15],R=t*c-s*o,y=t*a-i*o,M=t*l-r*o,f=s*a-i*c,T=s*l-r*c,S=i*l-r*a,L=u*E-p*d,k=u*b-m*d,U=u*x-g*d,F=p*b-m*E,h=p*x-g*E,P=m*x-g*b,w=R*P-y*h+M*F+f*U-T*k+S*L;return w?(w=1/w,n[0]=(c*P-a*h+l*F)*w,n[1]=(i*h-s*P-r*F)*w,n[2]=(E*S-b*T+x*f)*w,n[3]=(m*T-p*S-g*f)*w,n[4]=(a*U-o*P-l*k)*w,n[5]=(t*P-i*U+r*k)*w,n[6]=(b*M-d*S-x*y)*w,n[7]=(u*S-m*M+g*y)*w,n[8]=(o*h-c*U+l*L)*w,n[9]=(s*U-t*h-r*L)*w,n[10]=(d*T-E*M+x*R)*w,n[11]=(p*M-u*T-g*R)*w,n[12]=(c*k-o*F-a*L)*w,n[13]=(t*F-s*k+i*L)*w,n[14]=(E*y-d*f-b*R)*w,n[15]=(u*f-p*y+m*R)*w,n):null}function ge(n,e,t,s,i){let r=i[0]*e+i[4]*t+i[8]*s+i[12],o=i[1]*e+i[5]*t+i[9]*s+i[13],c=i[2]*e+i[6]*t+i[10]*s+i[14],a=i[3]*e+i[7]*t+i[11]*s+i[15],l=a!==0?1/a:1;n[0]=r*l,n[1]=o*l,n[2]=c*l}function Ee(n,e,t,s,i,r,o,c,a,l,u,p,m,g,d,E,b=0){let x=l-o,R=u-c,y=p-a,M=m-o,f=g-c,T=d-a,S=i*T-r*f,L=r*M-s*T,k=s*f-i*M,U=x*S+R*L+y*k;if(U>-1e-7&&U<1e-7)return!1;let F=1/U,h=n-o,P=e-c,w=t-a,v=F*(h*S+P*L+w*k);if(v<-b||v>1+b)return!1;let B=P*y-w*R,D=w*x-h*y,K=h*R-P*x,A=F*(s*B+i*D+r*K);if(A<-b||v+A>1+b)return!1;let W=F*(M*B+f*D+T*K);if(W>1e-4&&W<E.distance){E.distance=W,E.point=[n+s*W,e+i*W,t+r*W];let _=R*T-y*f,q=y*M-x*T,Z=x*f-R*M,G=Math.hypot(_,q,Z)||1;return E.normal=[_/G,q/G,Z/G],!0}return!1}function Pe(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,s=[];for(let u=0;u<t;u++)s.push(X());if(t===0)return s;let i=new Set;for(let u of n.nodes)if(Array.isArray(u.children))for(let p of u.children)i.add(p);let r=new Set,o=128,c=(u,p,m=0)=>{if(m>o||u<0||u>=t||r.has(u))return;r.add(u);let g=n.nodes[u];if(!g)return;let d=X();if(e&&e[u])d.set(e[u]);else if(g.matrix&&g.matrix.length===16)d.set(g.matrix);else{let b=g.translation||[0,0,0],x=g.rotation||[0,0,0,1],R=g.scale||[1,1,1];ve(d,x,b,R)}let E=s[u];if(p?$(E,p,d):E.set(d),Array.isArray(g.children))for(let b of g.children)typeof b=="number"&&c(b,E,m+1)},a=[],l=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(l&&Array.isArray(l.nodes))a.push(...l.nodes);else for(let u=0;u<t;u++)i.has(u)||a.push(u);for(let u of a)c(u,null);for(let u=0;u<t;u++)!i.has(u)&&!a.includes(u)&&c(u,null);return s}var ye="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ye]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ye,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ye]=e}}return n[ye]}var Y=ue().plugins;function Ae(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function De(){return ue().plugins}var Ve=["neutral","reinhard","none","aces","agx"];function pe(n){let e=String(n??"").trim().toLowerCase();return Ve.includes(e)?e:"neutral"}function Ue(n){return Ve.indexOf(pe(n))}function We(n){return new TextDecoder().decode(n)}var He=ue().decoders;function Oe(n,e){He.set(n.toLowerCase(),e)}function ce(n){return He.get(n.toLowerCase())}function Ne(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 s=t.getUint32(0,!0);if(s!==1179937895){let m=t.getUint8(0);throw m===123||m===32||m===10||m===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${s.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let r=t.getUint32(8,!0),o=12,c=null,a=null;for(;o+8<=r&&o+8<=e.byteLength;){let m=t.getUint32(o,!0),g=t.getUint32(o+4,!0),d=o+8;if(d+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+m} bytes, buffer has ${e.byteLength}`);if(g===1313821514){let E=new Uint8Array(e,d,m),b=We(E);c=JSON.parse(b,(x,R)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:R)}else g===5130562&&(a=e.slice(d,d+m));o=d+m}if(!c)throw new Error("Missing JSON chunk in GLB");let l=c.extensionsRequired||[];if(l.includes("KHR_draco_mesh_compression")&&!ce("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(l.includes(m)&&!ce("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!ce("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),p={gltf:c,bin:u,animations:[]};for(let m of Y)m.onParseGLB?.(p);return p}function st(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function Xe(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 Ie(n){if(Xe(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return Ne(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ze=`#version 300 es
18
18
  layout(location=0) in vec3 aPosition;
19
19
  layout(location=1) in vec3 aNormal;
20
20
  layout(location=2) in vec2 aUV;
21
21
  uniform mat4 uMVP,uModel;
22
22
  uniform mat3 uNormalMatrix;
23
23
  uniform vec4 uUvTransform;
24
+ layout(location=8) in vec4 aInst0;
25
+ layout(location=9) in vec4 aInst1;
26
+ layout(location=10) in vec4 aInst2;
27
+ layout(location=11) in vec4 aInst3;
28
+ layout(location=12) in vec4 aInstColor;
29
+ uniform int uInstanced;
30
+ uniform mat4 uViewProj;
31
+ out vec4 vInstTint;
32
+ mat4 xrModel(){return uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;}
33
+ mat4 xrMVP(){return uInstanced==1?uViewProj*xrModel():uMVP;}
34
+ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):uNormalMatrix;}
35
+ #define uModel xrModel()
36
+ #define uMVP xrMVP()
37
+ #define uNormalMatrix xrNormalMatrix()
24
38
  out vec3 vNormal,vWorldPos;
25
39
  out vec2 vUV;
26
40
  void main(){
41
+ vInstTint=uInstanced==1?aInstColor:vec4(1.0);
27
42
  vec3 rawN=uNormalMatrix*aNormal;
28
43
  vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
29
44
  vec4 world=uModel*vec4(aPosition,1.0);
@@ -32,12 +47,14 @@ vec2 scaleUV=uUvTransform.zw;
32
47
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
48
  vUV=aUV*scaleUV+uUvTransform.xy;
34
49
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,ut=`#version 300 es
50
+ }`,ot=`#version 300 es
36
51
  precision highp float;
37
52
  in vec3 vNormal,vWorldPos;
38
53
  in vec2 vUV;
39
54
  uniform vec4 uBaseColor;
40
- uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
55
+ in vec4 vInstTint;
56
+ #define uBaseColor (uBaseColor*vInstTint)
57
+ uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
41
58
  uniform vec2 uClearcoat;
42
59
  uniform vec3 uCameraPos,uAmbientColor;
43
60
  uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
@@ -218,15 +235,16 @@ if(uClearcoat.x>0.0){
218
235
  vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
219
236
  color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
220
237
  }
238
+ color*=uExposure;
221
239
  color=applyToneMapping(color,uToneMapping);
222
240
  float outAlpha=base.a;
223
241
  /*XRD_O*/
224
242
  fragColor=vec4(color,outAlpha);
225
- }`;function ct(i,e,t=1){let r=Number.isFinite(t)?Math.max(0,t):1,n=Math.max(0,(Number(i[0])||0)*r),s=Math.max(0,(Number(i[1])||0)*r),a=Math.max(0,(Number(i[2])||0)*r),u=R=>Math.max(0,Math.min(1,R));if(e==="none")return[u(n),u(s),u(a)];if(e==="reinhard")return[n/(n+1),s/(s+1),a/(a+1)];if(e==="aces"){let R=D=>{let M=D*.6;return u(M*(2.51*M+.03)/(M*(2.43*M+.59)+.14))};return[R(n),R(s),R(a)]}if(e==="agx"){let R=.84247906*n+.0784336*s+.07922375*a,D=.04232824*n+.87846864*s+.07916613*a,M=.04237565*n+.0784336*s+.87914297*a,T=P=>{let E=u((Math.log2(Math.max(P,1e-6))+12.47393)/16.5),f=E*E,w=f*f;return 15.5*w*f-40.14*w*E+31.96*w-6.868*f*E+.4298*f+.1191*E-.00232},v=T(R),d=T(D),F=T(M),B=1.196879*v-.09802088*d-.09902974*F,C=-.05289685*v+1.15190313*d-.09896118*F,S=-.05297164*v-.09804345*d+1.15107367*F;return[u(Math.pow(Math.max(B,0),2.2)),u(Math.pow(Math.max(C,0),2.2)),u(Math.max(0,Math.pow(Math.max(S,0),2.2)))]}let l=.76,c=.15,o=Math.min(n,s,a),h=o<.08?o-6.25*o*o:.04;n-=h,s-=h,a-=h;let g=Math.max(n,s,a);if(g<l)return[u(n),u(s),u(a)];let y=1-l,m=1-y*y/(g+y-l),p=m/g;n*=p,s*=p,a*=p;let b=1-1/(c*(g-m)+1);return[u(n+(m-n)*b),u(s+(m-s)*b),u(a+(m-a)*b)]}var lt=`#version 300 es
243
+ }`;function at(n,e,t=1){e=pe(e);let s=Number.isFinite(t)?Math.max(0,t):1,i=Math.max(0,(Number(n[0])||0)*s),r=Math.max(0,(Number(n[1])||0)*s),o=Math.max(0,(Number(n[2])||0)*s),c=x=>Math.max(0,Math.min(1,x));if(e==="none")return[c(i),c(r),c(o)];if(e==="reinhard")return[i/(i+1),r/(r+1),o/(o+1)];if(e==="aces"){let x=R=>{let y=R*.6;return c(y*(2.51*y+.03)/(y*(2.43*y+.59)+.14))};return[x(i),x(r),x(o)]}if(e==="agx"){let x=.84247906*i+.0784336*r+.07922375*o,R=.04232824*i+.87846864*r+.07916613*o,y=.04237565*i+.0784336*r+.87914297*o,M=F=>{let h=c((Math.log2(Math.max(F,1e-6))+12.47393)/16.5),P=h*h,w=P*P;return 15.5*w*P-40.14*w*h+31.96*w-6.868*P*h+.4298*P+.1191*h-.00232},f=M(x),T=M(R),S=M(y),L=1.196879*f-.09802088*T-.09902974*S,k=-.05289685*f+1.15190313*T-.09896118*S,U=-.05297164*f-.09804345*T+1.15107367*S;return[c(Math.pow(Math.max(L,0),2.2)),c(Math.pow(Math.max(k,0),2.2)),c(Math.max(0,Math.pow(Math.max(U,0),2.2)))]}let a=.76,l=.15,u=Math.min(i,r,o),p=u<.08?u-6.25*u*u:.04;i-=p,r-=p,o-=p;let m=Math.max(i,r,o);if(m<a)return[c(i),c(r),c(o)];let g=1-a,d=1-g*g/(m+g-a),E=d/m;i*=E,r*=E,o*=E;let b=1-1/(l*(m-d)+1);return[c(i+(d-i)*b),c(r+(d-r)*b),c(o+(d-o)*b)]}var ut=`#version 300 es
226
244
  layout(location=0) in vec3 aPosition;
227
245
  uniform mat4 uMVP;
228
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ht=`#version 300 es
246
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ct=`#version 300 es
229
247
  precision highp float;
230
248
  uniform vec4 uColorId;
231
249
  out vec4 fragColor;
232
- void main(){fragColor=uColorId;}`;function ke(i,e,t){let r=i.createShader(e);if(i.shaderSource(r,t),i.compileShader(r),!i.getShaderParameter(r,35713)){let n=i.getShaderInfoLog(r);throw i.deleteShader(r),new Error(`Shader compile error: ${n}`)}return r}function Se(i,e,t){let r=ke(i,35633,e),n=ke(i,35632,t),s=i.createProgram();if(i.attachShader(s,r),i.attachShader(s,n),i.linkProgram(s),!i.getProgramParameter(s,35714)){let a=i.getProgramInfoLog(s);throw i.deleteProgram(s),new Error(`Program link error: ${a}`)}return s}function Ne(i,e,t){let r={};for(let n of t)r[n]=i.getUniformLocation(e,n);return r}var Ge=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function je(){let i=ce().xrDepthShader;return{fs:ut.replace("/*XRD_U*/",i?.uniformsGLSL||"").replace("/*XRD_O*/",i?.occlusionGLSL||""),uniforms:i?[...Ge,...i.uniformNames]:Ge}}function Ye(i){if(typeof i!="string")return null;let e=i.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 Fe(i,e,t,r,n,s,a){if(r===void 0||!e.accessors?.[r])return null;let u=e.accessors[r],l=e.bufferViews[u.bufferView],c=(l.byteOffset||0)+(u.byteOffset||0),o=l.byteStride&&l.byteStride>s*4?l.byteStride>>2:s,h;if(o===s)h=new Float32Array(t,c,u.count*s);else{h=new Float32Array(u.count*s);let y=new Float32Array(t,l.byteOffset||0,Math.floor(l.byteLength/4)),m=(u.byteOffset||0)>>2;for(let p=0;p<u.count;p++){let b=m+p*o;for(let R=0;R<s;R++)h[p*s+R]=y[b+R]}}let g=i.createBuffer();return a.push(g),i.bindBuffer(34962,g),i.bufferData(34962,h,35044),i.enableVertexAttribArray(n),i.vertexAttribPointer(n,s,5126,!1,0,0),h}var mt=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 Ve(i,e,t=Ke,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=e,s=le("meshopt");s?.decodeBufferViews&&s.decodeBufferViews(n,e);let a=e.bin,u=[],l=[],c=n.extensions?.KHR_materials_variants;if(c&&Array.isArray(c.variants))for(let P of c.variants)P&&typeof P.name=="string"&&l.push(P.name);let o=Ae(n),h=[];if(Array.isArray(n.nodes))for(let P=0;P<n.nodes.length;P++){let E=n.nodes[P];E.mesh!==void 0&&n.meshes&&n.meshes[E.mesh]&&h.push({node:E,nodeIdx:P,meshIdx:E.mesh})}let g=h.length>0?h:(n.meshes||[]).map((P,E)=>({node:P,nodeIdx:-1,meshIdx:E})),y=[];if(Array.isArray(e.lights)&&e.lights.length>0)y.push(...e.lights);else if(n.extensions?.KHR_lights_punctual?.lights){let P=n.extensions.KHR_lights_punctual.lights;for(let E of P){let f=E.type==="directional"?"directional":E.type==="point"?"point":"ambient";y.push({type:f,color:E.color||[1,1,1],intensity:E.intensity!==void 0?E.intensity:1})}}if(y.length===0&&(y.push({type:"ambient",color:[1,1,1],intensity:.35}),y.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),g.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${g.length}`);let m=[];if(n.textures&&n.images){if(n.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${n.textures.length}`);for(let P=0;P<n.textures.length;P++){let E=n.textures[P],f=n.images[E.source];if(f){let w=i.createTexture();if(i.bindTexture(3553,w),i.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),i.texParameteri(3553,10242,10497),i.texParameteri(3553,10243,10497),i.texParameteri(3553,10241,9729),i.texParameteri(3553,10240,9729),f.bufferView!==void 0){let L=n.bufferViews[f.bufferView],x=a.slice(L.byteOffset||0,(L.byteOffset||0)+L.byteLength),G=new Blob([x],{type:f.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(G).then(A=>{i.bindTexture(3553,w),i.texImage2D(3553,0,6408,6408,5121,A),i.generateMipmap(3553),r?.()}).catch(()=>{})}else if(f.uri){let L=Ye(f.uri);if(L){let x=new Image;x.crossOrigin="anonymous",x.referrerPolicy="no-referrer",x.onload=()=>{i.bindTexture(3553,w),i.texImage2D(3553,0,6408,6408,5121,x),i.generateMipmap(3553),r?.()},x.src=L}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",f.uri)}m.push(w)}else m.push(null)}}let p=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],R=0,D=0;for(let P=0;P<g.length;P++){let E=g[P],f=n.meshes[E.meshIdx],w=E.nodeIdx>=0?o[E.nodeIdx]:H(),L=new Float32Array(9);se(L,w);let x={name:E.node.name||f.name||`Mesh_${E.meshIdx}`,nodeIndex:E.nodeIdx,transform:w,normalMatrix:L,primitives:[],extras:E.node.extras||f.extras},G=E.node?.extensions?.EXT_mesh_gpu_instancing;if(G&&G.attributes&&typeof G.attributes=="object"){let A=G.attributes,j=A.TRANSLATION!==void 0?n.accessors?.[A.TRANSLATION]:null,W=A.ROTATION!==void 0?n.accessors?.[A.ROTATION]:null,Y=A.SCALE!==void 0?n.accessors?.[A.SCALE]:null,_=A._COLOR_0!==void 0?n.accessors?.[A._COLOR_0]:null,V=Number(j?.count??W?.count??Y?.count??0);if(!Number.isFinite(V)||V<0||V>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${V}`);if(V>0){let X=(I,$)=>{if(!I||I.bufferView===void 0||!n.bufferViews?.[I.bufferView])return null;let O=(n.bufferViews[I.bufferView].byteOffset||0)+(I.byteOffset||0);return Oe(a,O,V*$)},ee=X(j,3),U=X(W,4),N=X(Y,3),z=_?.type==="VEC4"?4:3,K=X(_,z),te=new Float32Array(V*16),ie=H();for(let I=0;I<V;I++){let $=ee?[ee[I*3],ee[I*3+1],ee[I*3+2]]:[0,0,0],ue=U?[U[I*4],U[I*4+1],U[I*4+2],U[I*4+3]]:[0,0,0,1],O=N?[N[I*3],N[I*3+1],N[I*3+2]]:[1,1,1];Me(ie,ue,$,O),te.set(ie,I*16)}if(x.instanceMatrices=te,K){let I=new Float32Array(V*3);for(let $=0;$<V;$++)I[$*3]=K[$*z],I[$*3+1]=K[$*z+1],I[$*3+2]=K[$*z+2];x.instanceColors=I}}}for(let A of f.primitives||[]){if(A.extensions?.KHR_draco_mesh_compression){let k=le("draco");k&&k.decodePrimitive(n,A,a)}let j=[],W=i.createVertexArray();i.bindVertexArray(W);let Y=n.accessors[A.attributes.POSITION],_=Number(Y?.count??0);if(!Number.isFinite(_)||_<0||R+_>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(R+=_,Y?.min&&Y?.max){let k=J=>{for(let Q=0;Q<3;Q++){let ne=J[12+Q],xe=J[12+Q];for(let he=0;he<3;he++){let ye=J[he*4+Q]*Y.min[he],Te=J[he*4+Q]*Y.max[he];ne+=ye<Te?ye:Te,xe+=ye>Te?ye:Te}ne<p[Q]&&(p[Q]=ne),xe>b[Q]&&(b[Q]=xe)}};if(x.instanceMatrices&&x.instanceMatrices.length>=16){let J=x.instanceMatrices.length>>4,Q=H();for(let ne=0;ne<J;ne++){let xe=x.instanceMatrices.subarray(ne*16,ne*16+16);q(Q,w,xe),k(Q)}}else k(w)}let V=Fe(i,n,a,A.attributes.POSITION,0,3,j);Fe(i,n,a,A.attributes.NORMAL,1,3,j),Fe(i,n,a,A.attributes.TEXCOORD_0,2,2,j);let X=0,ee=5123,U=null;if(A.indices!==void 0){let k=n.accessors[A.indices],Q=(n.bufferViews[k.bufferView].byteOffset||0)+(k.byteOffset||0);if(X=Number(k.count??0),!Number.isFinite(X)||X<0||D+X>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);D+=X,ee=k.componentType===5125?5125||5125:5123||5123;let ne=i.createBuffer();j.push(ne),i.bindBuffer(34963,ne),k.componentType===5125?(U=new Uint32Array(a,Q,k.count),i.bufferData(34963,U,35044)):(U=new Uint16Array(a,Q,k.count),i.bufferData(34963,U,35044))}else X=Y.count;let N={};for(let k of Z)if(k.onBuildPrimitiveVAO){let J=k.onBuildPrimitiveVAO(i,W,A,n,a);J&&(N[k.name]=J)}i.bindVertexArray(null);let z=n.materials&&A.material!==void 0?n.materials[A.material]:null,K=je(),te=ze,ie=K.fs,I=!1;for(let k of Z)if(k.onResolveShader){let J=k.onResolveShader(A,z,te,ie);J&&(te=J.vs,ie=J.fs,I=!0)}let $=I?Se(i,te,ie):null,ue=$?Ne(i,$,K.uniforms):null,O=z?.pbrMetallicRoughness,de=O?.baseColorFactor||[.8,.8,.8,1],fe=O?.metallicFactor??.1,pe=O?.roughnessFactor??.5,re=z?.extensions?.KHR_materials_clearcoat,ae=re?re.clearcoatFactor??1:0,oe=Math.max(.04,re?.clearcoatRoughnessFactor??.04),be=O?.baseColorTexture!==void 0&&m[O.baseColorTexture.index]?m[O.baseColorTexture.index]:null,$e=O?.metallicRoughnessTexture!==void 0&&m[O.metallicRoughnessTexture.index]?m[O.metallicRoughnessTexture.index]:null,qe=z?.normalTexture!==void 0&&m[z.normalTexture.index]?m[z.normalTexture.index]:null,Ze=z?.normalTexture?.scale??1,Je=z?.occlusionTexture!==void 0&&m[z.occlusionTexture.index]?m[z.occlusionTexture.index]:null,Qe=z?.occlusionTexture?.strength??1,et=!!(z?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive),_e=A.extensions?.KHR_materials_variants?.mappings,tt=Array.isArray(_e)?_e.filter(k=>k&&typeof k.material=="number"&&Array.isArray(k.variants)).map(k=>({material:k.material|0,variants:k.variants.map(J=>Number(J)|0)})):void 0;x.primitives.push({vao:W,indexCount:X,indexType:ee,baseColor:de,metallic:fe,roughness:pe,clearcoat:ae,clearcoatRoughness:oe,positions:V,indices:U,texture:be,metallicRoughnessTexture:$e,normalTexture:qe,occlusionTexture:Je,normalScale:Ze,occlusionStrength:Qe,buffers:j,materialIndex:A.material,defaultMaterialIndex:A.material,variantMappings:tt,pluginData:N,customProgram:$,customUniforms:ue,isTransmissive:et})}u.push(x)}isFinite(p[0])||(p=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let M=[(p[0]+b[0])/2,(p[1]+b[1])/2,(p[2]+b[2])/2],T=b[0]-p[0],v=b[1]-p[1],d=b[2]-p[2],F=Math.max(Math.hypot(T,v,d)/2,.5),B=[p[0],p[1],p[2]],C=[b[0],b[1],b[2]],S=e.animations;if(!S){for(let P of Z)if(P.onParseGLB?.(e),e.animations){S=e.animations;break}}return S||(S=[]),{meshes:u,bounds:{center:M,radius:F,min:B,max:C},lights:y,animations:S,worldMatrices:o,gpuTextures:m,availableVariants:l}}var me=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=H();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=H();this.viewMatrix=H();this.modelMatrix=H();this.mvpMatrix=H();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:H(),rawValueToMeters:.001,format:0};this.container=e;let n,s;if(t&&typeof t.getContext=="function"?(n=t,s=r):(s=t,n=s?.canvas),!n){let c=e.querySelector("canvas");c||(c=document.createElement("canvas"),c.style.width="100%",c.style.height="100%",c.style.display="block",c.style.touchAction="none",e.prepend(c)),n=c}this.canvas=n,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.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.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 u=n.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!u)throw new Error("WebGL2 not supported");this.gl=u;let l=je();this.renderProg=Se(u,ze,l.fs),this.pickProg=Se(u,lt,ht),this.uRender=Ne(u,this.renderProg,l.uniforms),this.uPick=Ne(u,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){We(e,t)}static getDecoder(e){return le(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,n=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=n,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,n,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,n,s)}loadGLBData(e,t){let{meshes:r,bounds:n,lights:s,animations:a,worldMatrices:u,gpuTextures:l,availableVariants:c}=Ve(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=n,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=a||[],this.worldMatrices=u||[],this.gpuTextures=l||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&this.applyVariantMaterial(this.activeVariantName),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let h of e.gltf.nodes)this.initialNodeTransforms.push({t:h.translation?[h.translation[0],h.translation[1],h.translation[2]]:[0,0,0],r:h.rotation?[h.rotation[0],h.rotation[1],h.rotation[2],h.rotation[3]]:[0,0,0,1],s:h.scale?[h.scale[0],h.scale[1],h.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let h of Z)h.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:n.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let o=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;o!==void 0&&(this.envIntensity=Math.max(0,Number(o))),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(Be(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(Ie(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ie(e),{meshes:n}=Ve(this.gl,r,Ke,()=>this.render());if(t)for(let s of n)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],se(s.normalMatrix,s.transform);this.backdropMeshes=n,this.update(0),this.render()}setClearColor(e,t,r,n=1){this.clearColor=[e,t,r,n]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],n;e instanceof Map?n=e.get(r.name)??e.get(t):Array.isArray(e)?n=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?n=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(n=e[t])),n&&n.length===16&&(r.transform.set(n),se(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],n=[],s=[],a=[],u=[];for(let l of this.lights){let c=l.color||[1,1,1],o=l.intensity!==void 0?l.intensity:1;if(l.type==="ambient")r=[c[0]*o,c[1]*o,c[2]*o];else if(l.type==="directional"&&n.length<6){let h=l.direction||[.5,1,.8];n.push(h[0],h[1],h[2]),s.push(c[0]*o,c[1]*o,c[2]*o)}else if(l.type==="point"&&a.length<6){let h=l.position||[0,0,0];a.push(h[0],h[1],h[2]),u.push(c[0]*o,c[1]*o,c[2]*o)}}n.length===0&&(n.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,n.length/3),n.length>0&&(t.uniform3fv(e.uDirLightDir,n),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,a.length/3),a.length>0&&(t.uniform3fv(e.uPointLightPos,a),t.uniform3fv(e.uPointLightColor,u)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Z)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Z)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let n=this.meshes.flatMap(o=>o.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=n[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],u=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,l=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:u,roughnessFactor:l,setBaseColorFactor:o=>{let h=[o[0],o[1],o[2],o[3]??1];c.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let g of n)g.baseColor=h;this.render()},setMetallicFactor:o=>{c.metallicFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=o);for(let h of n)h.metallic=o;this.render()},setRoughnessFactor:o=>{c.roughnessFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=o);for(let h of n)h.roughness=o;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===""||e==="default",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let n=this.gltf?.materials;if(!Array.isArray(n))return t;for(let s of this.meshes)for(let a of s.primitives){let u=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let h of a.variantMappings)if(Array.isArray(h.variants)&&h.variants.includes(r)){u=h.material;break}}if(u===void 0||!n[u]){a.materialIndex=void 0,a.baseColor=[.8,.8,.8,1],a.metallic=.1,a.roughness=.5,a.clearcoat=0,a.clearcoatRoughness=.04,a.texture=null,a.metallicRoughnessTexture=null,a.normalTexture=null,a.normalScale=1,a.occlusionTexture=null,a.occlusionStrength=1,a.isTransmissive=!1;continue}let l=n[u];a.materialIndex=u;let c=l.pbrMetallicRoughness;a.baseColor=c?.baseColorFactor?[c.baseColorFactor[0],c.baseColorFactor[1],c.baseColorFactor[2],c.baseColorFactor[3]??1]:[.8,.8,.8,1],a.metallic=c?.metallicFactor??.1,a.roughness=c?.roughnessFactor??.5;let o=l.extensions?.KHR_materials_clearcoat;a.clearcoat=o?o.clearcoatFactor??1:0,a.clearcoatRoughness=Math.max(.04,o?.clearcoatRoughnessFactor??.04),a.texture=c?.baseColorTexture!==void 0&&this.gpuTextures[c.baseColorTexture.index]?this.gpuTextures[c.baseColorTexture.index]:null,a.metallicRoughnessTexture=c?.metallicRoughnessTexture!==void 0&&this.gpuTextures[c.metallicRoughnessTexture.index]?this.gpuTextures[c.metallicRoughnessTexture.index]:null,a.normalTexture=l.normalTexture!==void 0&&this.gpuTextures[l.normalTexture.index]?this.gpuTextures[l.normalTexture.index]:null,a.normalScale=l.normalTexture?.scale??1,a.occlusionTexture=l.occlusionTexture!==void 0&&this.gpuTextures[l.occlusionTexture.index]?this.gpuTextures[l.occlusionTexture.index]:null,a.occlusionStrength=l.occlusionTexture?.strength??1,a.isTransmissive=!!(l.extensions?.KHR_materials_transmission||a.pluginData?.materials?.isTransmissive)}return!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 Z)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,n){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)),n!==void 0&&n>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/n))}setInitialCamera(e,t,r,n){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(n!==void 0&&n>0){let s=this.clampDistance(this.bounds.radius*2.5/n);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=H();q(r,this.projMatrix,this.viewMatrix);let[n,s,a]=e,u=t?t[0]:0,l=t?t[1]:0,c=t?t[2]:0,o=this.modelRootMatrix;o&&(n=o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],s=o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],a=o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14],t&&(u=o[0]*t[0]+o[4]*t[1]+o[8]*t[2],l=o[1]*t[0]+o[5]*t[1]+o[9]*t[2],c=o[2]*t[0]+o[6]*t[1]+o[10]*t[2]));let h=r[0]*n+r[4]*s+r[8]*a+r[12],g=r[1]*n+r[5]*s+r[9]*a+r[13],y=r[2]*n+r[6]*s+r[10]*a+r[14],m=r[3]*n+r[7]*s+r[11]*a+r[15];if(m<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=h/m,b=g/m,R=y/m,D=this.canvas.getBoundingClientRect(),M=D.width||this.canvas.clientWidth||this.canvas.width||300,T=D.height||this.canvas.clientHeight||this.canvas.height||150,v=(p*.5+.5)*M,d=(-b*.5+.5)*T,F=p>=-1.1&&p<=1.1&&b>=-1.1&&b<=1.1&&R>=-1&&R<=1;if(F&&t){let B=this.customTarget||this.bounds.center,C=B[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),S=B[1]+this.currDistance*Math.sin(this.currPhi),P=B[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),E=[n-C,s-S,a-P];u*E[0]+l*E[1]+c*E[2]>.05&&(F=!1)}return{x:v,y:d,z:R,visible:F}}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},n=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(n,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],u=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-n*a[0]+s*u[0])*c,l[1]+=(-n*a[1]+s*u[1])*c,l[2]+=(-n*a[2]+s*u[2])*c,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-n*.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(),n=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(n,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,n=r.getBoundingClientRect(),s=r.width||300,a=r.height||300,u=n.width>0?Math.floor((e-n.left)*(s/n.width)):Math.floor(e),l=n.height>0?Math.floor((t-n.top)*(a/n.height)):Math.floor(t);return this.performMeshPick(u,l,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let n=this.gl,s=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let u=H();q(u,this.projMatrix,this.viewMatrix);let l=[],c=Math.max(0,Math.min(s-1,e)),o=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&n&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),n.bindFramebuffer(36160,this.pickFbo),n.viewport(0,0,s,a),n.enable(2929),n.clearColor(0,0,0,0),n.clear(16384|256),n.useProgram(this.pickProg);for(let B=0;B<this.meshes.length;B++){let C=this.meshes[B];if(C.visible===!1||C.isPluginMesh)continue;let S=B+1,P=(S&255)/255,E=(S>>8&255)/255,f=(S>>16&255)/255;n.uniform4f(this.uPick.uColorId,P,E,f,1),q(this.modelMatrix,this.modelRootMatrix,C.transform);let w=C.instanceMatrices;if(w&&w.length>=16){let L=w.length>>4,x=H();for(let G of C.primitives){n.bindVertexArray(G.vao);for(let A=0;A<L;A++)q(x,this.modelMatrix,w.subarray(A*16,A*16+16)),q(this.mvpMatrix,u,x),n.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),G.indices?n.drawElements(4,G.indexCount,G.indexType,0):n.drawArrays(4,0,G.indexCount)}}else{q(this.mvpMatrix,u,this.modelMatrix),n.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of C.primitives)n.bindVertexArray(L.vao),L.indices?n.drawElements(4,L.indexCount,L.indexType,0):n.drawArrays(4,0,L.indexCount)}}let d=new Uint8Array(4);n.readPixels(c,o,1,1,6408,5121,d),n.bindFramebuffer(36160,null);let F=d[0]+(d[1]<<8)+(d[2]<<16);F>0&&F<=this.meshes.length&&(l=[this.meshes[F-1]])}l.length===0&&(l=this.meshes.filter(d=>d.visible!==!1));let h=null,g=1/0,y=[0,0,0],m=[0,1,0],p=this.customTarget||this.bounds.center,b=p[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=p[1]+this.currDistance*Math.sin(this.currPhi),D=p[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),M=H();for(let d of l){q(M,this.modelRootMatrix,d.transform);let F=d.instanceMatrices,B=F&&F.length>=16?F.length>>4:1;for(let C=0;C<B;C++){F&&F.length>=16?q(this.modelMatrix,M,F.subarray(C*16,C*16+16)):this.modelMatrix.set(M),q(this.mvpMatrix,u,this.modelMatrix);let S=H();if(!Pe(S,this.mvpMatrix))continue;let P=(c+.5)/s*2-1,E=(o+.5)/a*2-1,f=[0,0,0],w=[0,0,0];Re(f,P,E,-1,S),Re(w,P,E,1,S);let L=w[0]-f[0],x=w[1]-f[1],G=w[2]-f[2],A=Math.hypot(L,x,G)||1,j=L/A,W=x/A,Y=G/A,_={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((X=>{for(let ee of d.primitives){if(!ee.positions)continue;let U=ee.positions,N=ee.indices,z=Math.floor(N?N.length/3:U.length/9);for(let K=0;K<z;K++){let te=N?N[K*3]:K*3,ie=N?N[K*3+1]:K*3+1,I=N?N[K*3+2]:K*3+2;De(f[0],f[1],f[2],j,W,Y,U[te*3],U[te*3+1],U[te*3+2],U[ie*3],U[ie*3+1],U[ie*3+2],U[I*3],U[I*3+1],U[I*3+2],_,X)}}})(1e-4),isFinite(_.distance)){let X=_.point[0],ee=_.point[1],U=_.point[2],N=this.modelMatrix,z=N[0]*X+N[4]*ee+N[8]*U+N[12],K=N[1]*X+N[5]*ee+N[9]*U+N[13],te=N[2]*X+N[6]*ee+N[10]*U+N[14],ie=z-b,I=K-R,$=te-D,ue=Math.hypot(ie,I,$);if(ue<g){se(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,de=_.normal[0],fe=_.normal[1],pe=_.normal[2],re=O[0]*de+O[3]*fe+O[6]*pe,ae=O[1]*de+O[4]*fe+O[7]*pe,oe=O[2]*de+O[5]*fe+O[8]*pe,be=Math.hypot(re,ae,oe)||1;re/=be,ae/=be,oe/=be,re*ie+ae*I+oe*$>0&&(re=-re,ae=-ae,oe=-oe),h=d,g=Math.round(ue*1e3)/1e3,y=[Math.round(z*1e3)/1e3,Math.round(K*1e3)/1e3,Math.round(te*1e3)/1e3],m=[Math.round(re*1e3)/1e3,Math.round(ae*1e3)/1e3,Math.round(oe*1e3)/1e3]}}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:g,hitPoint:y,normal:m,screenX:e,screenY:t};if(r){for(let d of Z)d.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),n=e>=r,s=n?e-r:e,a=n?Math.max(1,t-r):r,u=(s+.5)/a*2-1;return Math.floor((u*.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,n=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),a=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);ge(this.viewMatrix,[n,s,a],r,[0,1,0]),q(this.mvpMatrix,this.projMatrix,this.viewMatrix),se(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)),n=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==n?(this.canvas.width=r,this.canvas.height=n,this.resizePickingFbo(r,n),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 Z)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 Z)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(n){this.reportRenderError(n)}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],n=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*n),s[13]=0,s[14]=n-(-t*r+e*n),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let a of Z)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 Z)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),n=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(n-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=n,this.lastReportedZoom=s;let a={theta:r,phi:n,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,n,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let u=e?.transform?.inverse?.matrix||this.viewMatrix,l=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,o=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:u,projMatrix:l,eyePos:o,viewport:n,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let T=Math.max(2,this.canvas.width||2),v=Math.max(1,this.canvas.height||1),d=Math.max(1,Math.floor(T*.5)),F=Math.max(1,T-d),B=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),C=this.customTarget||this.bounds.center,S=C[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=C[1]+this.currDistance*Math.sin(this.currPhi),E=C[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),f=Math.cos(this.currTheta),w=-Math.sin(this.currTheta),L=.032,x=H(),G=H(),A=[S-f*L,P,E-w*L],j=[C[0]-f*L*.25,C[1],C[2]-w*L*.25];ve(x,this.fov,d/v,.1,B),ge(G,A,j,[0,1,0]);let W=H(),Y=H(),_=[S+f*L,P,E+w*L],V=[C[0]+f*L*.25,C[1],C[2]+w*L*.25];ve(W,this.fov,F/v,.1,B),ge(Y,_,V,[0,1,0]),this.render({viewMatrix:G,projMatrix:x,eyePos:A,viewport:[0,0,d,v],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:Y,projMatrix:W,eyePos:_,viewport:[d,0,F,v],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,T,v);return}let t=this.gl,r=0,n=0,s=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],n=e.viewport[1],s=e.viewport[2],a=e.viewport[3],t.viewport(r,n,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 u=H(),l=e?.viewMatrix??this.viewMatrix;q(u,e?.projMatrix??this.projMatrix,l);let c=ce().xrDepthShader,o=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:this.toneMapping==="aces"?3:this.toneMapping==="agx"?4:0,h=this.customTarget||this.bounds.center,g=e?e.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),y=e?e.eyePos[1]:h[1]+this.currDistance*Math.sin(this.currPhi),m=e?e.eyePos[2]:h[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let T of Z)T.onBeforeDrawScene?.(this,t,u,[g,y,m],o);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let b=e?.eye||"none",R=!1,D=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,M=T=>{for(let v=0;v<D.length;v++){let d=D[v];if(d.visible===!1)continue;let F=this.selectedMeshName!==""&&d.name===this.selectedMeshName;v<p||d.worldSpace===!0||d.name==="__xr_reticle__"?this.modelMatrix.set(d.transform):q(this.modelMatrix,this.modelRootMatrix,d.transform),q(this.mvpMatrix,u,this.modelMatrix),se(d.normalMatrix,this.modelMatrix);let B=d.extras?.xr?.stereo||d.userData?.xr?.stereo,C=0,S=0,P=1,E=1;B==="sbs"?(P=.5,C=b==="right"?.5:0):B==="ou"&&(E=.5,S=b==="right"?.5:0);for(let f of d.primitives){let w=!!f.isTransmissive;if(!T&&w){R=!0;continue}if(T&&!w)continue;let L=f.customProgram||this.renderProg,x=f.customUniforms||this.uRender;t.useProgram(L),t.uniform1i(x.uToneMapping,o),t.uniform1f(x.uEnvIntensity,this.envIntensity),t.uniform3f(x.uCameraPos,g,y,m),t.uniform1f(x.uEmissive,F?1:0),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(x.uNormalMatrix,!1,d.normalMatrix),x.uUvTransform&&t.uniform4f(x.uUvTransform,C,S,P,E),x.uViewportSize&&t.uniform2f(x.uViewportSize,Math.max(1,s),Math.max(1,a)),c?.bind(t,x,this.xrDepthState,l,[r,n,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(x.uEnvironmentMap,4),t.uniform1i(x.uHasEnvironmentMap,1)):t.uniform1i(x.uHasEnvironmentMap,0),this.bindLights(x),x.uSectionEnabled&&t.uniform1i(x.uSectionEnabled,0);for(let A of Z)A.onBeforeDrawPrimitive?.(t,L,f,d,this.worldMatrices||[],this.gltf);t.uniform4fv(x.uBaseColor,f.baseColor),t.uniform1f(x.uMetallic,f.metallic),t.uniform1f(x.uRoughness,f.roughness),x.uClearcoat&&t.uniform2f(x.uClearcoat,f.clearcoat??0,f.clearcoatRoughness??.04),f.texture?(t.activeTexture(33984),t.bindTexture(3553,f.texture),t.uniform1i(x.uBaseColorTexture,0),t.uniform1i(x.uHasTexture,1)):t.uniform1i(x.uHasTexture,0),f.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,f.metallicRoughnessTexture),t.uniform1i(x.uMetallicRoughnessTexture,1),t.uniform1i(x.uHasMetallicRoughnessTexture,1)):t.uniform1i(x.uHasMetallicRoughnessTexture,0),f.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,f.normalTexture),t.uniform1i(x.uNormalTexture,2),t.uniform1i(x.uHasNormalTexture,1),t.uniform1f(x.uNormalScale,f.normalScale)):t.uniform1i(x.uHasNormalTexture,0),f.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,f.occlusionTexture),t.uniform1i(x.uOcclusionTexture,3),t.uniform1i(x.uHasOcclusionTexture,1),t.uniform1f(x.uOcclusionStrength,f.occlusionStrength)):t.uniform1i(x.uHasOcclusionTexture,0),t.bindVertexArray(f.vao);let G=d.instanceMatrices;if(G&&G.length>=16){let A=G.length>>4,j=d.instanceColors,W=H(),Y=new Float32Array(9),_=[f.baseColor[0],f.baseColor[1],f.baseColor[2],f.baseColor[3]];for(let V=0;V<A;V++)q(W,this.modelMatrix,G.subarray(V*16,V*16+16)),q(this.mvpMatrix,u,W),se(Y,W),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,W),t.uniformMatrix3fv(x.uNormalMatrix,!1,Y),j&&(_[0]=f.baseColor[0]*j[V*3],_[1]=f.baseColor[1]*j[V*3+1],_[2]=f.baseColor[2]*j[V*3+2],_[3]=f.baseColor[3],t.uniform4fv(x.uBaseColor,_)),f.indices?t.drawElements(4,f.indexCount,f.indexType,0):t.drawArrays(4,0,f.indexCount)}else f.indices?t.drawElements(4,f.indexCount,f.indexType,0):t.drawArrays(4,0,f.indexCount)}}};if(M(!1),R){for(let T of Z)T.onBeforeTransmissivePass?.(t,this);M(!0)}for(let T of Z)T.onAfterRender?.(t,this,u)}disposeMeshListGpuResources(e,t){let r=this.gl,n=new Set,s=a=>{a&&!n.has(a)&&(n.add(a),r.deleteTexture(a))};for(let a of e)for(let u of a.primitives){if(u.vao&&r.deleteVertexArray(u.vao),u.buffers)for(let l of u.buffers)r.deleteBuffer(l);s(u.texture),s(u.metallicRoughnessTexture),s(u.normalTexture),s(u.occlusionTexture),u.customProgram&&r.deleteProgram(u.customProgram)}if(t)for(let a of t)s(a)}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 Z)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};me.registerPlugin=Ce,me.getRegisteredPlugins=Le;var dt=me;
250
+ void main(){fragColor=uColorId;}`;function Ge(n,e,t){let s=n.createShader(e);if(n.shaderSource(s,t),n.compileShader(s),!n.getShaderParameter(s,35713)){let i=n.getShaderInfoLog(s);throw n.deleteShader(s),new Error(`Shader compile error: ${i}`)}return s}function Fe(n,e,t){let s=Ge(n,35633,e),i=Ge(n,35632,t),r=n.createProgram();if(n.attachShader(r,s),n.attachShader(r,i),n.linkProgram(r),!n.getProgramParameter(r,35714)){let o=n.getProgramInfoLog(r);throw n.deleteProgram(r),new Error(`Program link error: ${o}`)}return r}function Se(n,e,t){let s={};for(let i of t)s[i]=n.getUniformLocation(e,i);return s}var ke=["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 je(){let n=ue().xrDepthShader;return{fs:ot.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...ke,...n.uniformNames]:ke}}function Ye(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 Le(n,e,t,s,i,r,o,c){if(s===void 0||!e.accessors?.[s])return null;let a=Re(e,t,e.accessors[s],r);if(!a)return null;c&&(a=a.slice(),Be(a,c));let l=n.createBuffer();return o.push(l),n.bindBuffer(34962,l),n.bufferData(34962,a,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,r,5126,!1,0,0),a}function Ce(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function $e(n,e,t){let s=je(),i=ze,r=s.fs,o=!1;for(let a of Y)if(a.onResolveShader){let l=a.onResolveShader(e,t,i,r);l&&(i=l.vs,r=l.fs,o=!0)}let c=o?Fe(n,i,r):null;return{program:c,uniforms:c?Se(n,c,s.uniforms):null}}function lt(n,e,t){let s=e.instanceMatrices;if(!s||s.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=s.length>>4,r=e.instanceColors,o=new Float32Array(i*20);for(let a=0;a<i;a++)o.set(s.subarray(a*16,a*16+16),a*20),o[a*20+16]=r?r[a*3]:1,o[a*20+17]=r?r[a*3+1]:1,o[a*20+18]=r?r[a*3+2]:1,o[a*20+19]=1;let c=n.createBuffer();t.push(c),n.bindBuffer(34962,c),n.bufferData(34962,o,35044);for(let a=0;a<5;a++)n.enableVertexAttribArray(8+a),n.vertexAttribPointer(8+a,4,5126,!1,80,a*16),n.vertexAttribDivisor(8+a,1);return!0}function ht(n,e){let t=n.materials?.[e?.material];if(!t)return null;let s=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of s){let r=i?.extensions?.KHR_texture_transform;if(r&&typeof r=="object")return r}return null}var mt=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 Me(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function qe(n,e){let t=n?.pbrMetallicRoughness,s=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,r=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:s?[s[0],s[1],s[2],s[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:r(t?.baseColorTexture),metallicRoughnessTexture:r(t?.metallicRoughnessTexture),normalTexture:r(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:r(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ze(n,e,t){let s=new Set,i=r=>{r&&!s.has(r)&&(s.add(r),n.deleteTexture(r))};for(let r of e)for(let o of r.primitives){if(o.vao&&n.deleteVertexArray(o.vao),o.buffers)for(let a of o.buffers)n.deleteBuffer(a);i(o.texture),i(o.metallicRoughnessTexture),i(o.normalTexture),i(o.occlusionTexture);let c=new Set;o.customProgram&&c.add(o.customProgram);for(let a of o.programCache?.values()??[])a.program&&c.add(a.program);for(let a of c)n.deleteProgram(a)}if(t)for(let r of t)i(r)}function _e(n,e,t=Ke,s){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return dt(n,e,t,s,i)}catch(r){let o=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Ze(n,o,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let c of i.buffers)n.deleteBuffer(c);throw r}}function dt(n,e,t,s,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r}=e,o=ce("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(r,e);let c=e.bin,a=[];i.meshes=a;let l=[],u=r.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((h,P)=>{l.push(typeof h?.name=="string"&&h.name?h.name:`Variant_${P}`)});let p=Pe(r),m=[];if(Array.isArray(r.nodes))for(let h=0;h<r.nodes.length;h++){let P=r.nodes[h];P.mesh!==void 0&&r.meshes&&r.meshes[P.mesh]&&m.push({node:P,nodeIdx:h,meshIdx:P.mesh})}let g=m.length>0?m:(r.meshes||[]).map((h,P)=>({node:h,nodeIdx:-1,meshIdx:P})),d=[];if(Array.isArray(e.lights)&&e.lights.length>0)d.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let h=r.extensions.KHR_lights_punctual.lights;for(let P of h){let w=P.type==="directional"?"directional":P.type==="point"?"point":"ambient";d.push({type:w,color:P.color||[1,1,1],intensity:P.intensity!==void 0?P.intensity:1})}}if(d.length===0&&(d.push({type:"ambient",color:[1,1,1],intensity:.35}),d.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),g.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${g.length}`);let E=[];if(i.gpuTextures=E,r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let h=0;h<r.textures.length;h++){let P=r.textures[h],w=r.images[P.source];if(w){let v=n.createTexture();if(n.bindTexture(3553,v),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),w.bufferView!==void 0){let B=r.bufferViews[w.bufferView],D=c.slice(B.byteOffset||0,(B.byteOffset||0)+B.byteLength),K=new Blob([D],{type:w.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(K).then(A=>{n.bindTexture(3553,v),n.texImage2D(3553,0,6408,6408,5121,A),n.generateMipmap(3553),s?.()}).catch(()=>{})}else if(w.uri){let B=Ye(w.uri);if(B){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{n.bindTexture(3553,v),n.texImage2D(3553,0,6408,6408,5121,D),n.generateMipmap(3553),s?.()},D.src=B}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",w.uri)}E.push(v)}else E.push(null)}}let b=[1/0,1/0,1/0],x=[-1/0,-1/0,-1/0],R=0,y=0;for(let h=0;h<g.length;h++){let P=g[h],w=r.meshes[P.meshIdx],v=P.nodeIdx>=0?p[P.nodeIdx]:X(),B=new Float32Array(9);oe(B,v);let D={name:P.node.name||w.name||`Mesh_${P.meshIdx}`,nodeIndex:P.nodeIdx,transform:v,normalMatrix:B,primitives:[],extras:P.node.extras||w.extras};i.mesh=D;let K=P.node?.extensions?.EXT_mesh_gpu_instancing;if(K&&K.attributes&&typeof K.attributes=="object"){let A=K.attributes,W=A.TRANSLATION!==void 0?r.accessors?.[A.TRANSLATION]:null,_=A.ROTATION!==void 0?r.accessors?.[A.ROTATION]:null,q=A.SCALE!==void 0?r.accessors?.[A.SCALE]:null,Z=A._COLOR_0!==void 0?r.accessors?.[A._COLOR_0]:null,G=Number(W?.count??_?.count??q?.count??0);if(!Number.isFinite(G)||G<0||G>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${G}`);if(G>0){let z=(N,O)=>{if(!N||N.bufferView===void 0||!r.bufferViews?.[N.bufferView])return null;let te=N.componentType??5126,re=j=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${j})`),null);if(te!==5120&&te!==5121&&te!==5122&&te!==5123&&te!==5126)return re(`componentType ${te}`);if(!(Number(N.count)>=G))return re(`count ${N.count} < ${G}`);let C=null;try{C=Re(r,c,{...N,count:G},O)}catch{return re("out of bounds")}return!C||!C.every(Number.isFinite)?re("non-finite value"):C},I=z(W,3),ne=z(_,4),H=z(q,3),Q=Z?.type==="VEC4"?4:3,ee=z(Z,Q),ie=new Float32Array(G*16),ae=X();for(let N=0;N<G;N++){let O=I?[I[N*3],I[N*3+1],I[N*3+2]]:[0,0,0],te=ne?[ne[N*4],ne[N*4+1],ne[N*4+2],ne[N*4+3]]:[0,0,0,1],re=H?[H[N*3],H[N*3+1],H[N*3+2]]:[1,1,1];ve(ae,te,O,re),ie.set(ae,N*16)}if(D.instanceMatrices=ie,ee){let N=new Float32Array(G*3);for(let O=0;O<G;O++)N[O*3]=ee[O*Q],N[O*3+1]=ee[O*Q+1],N[O*3+2]=ee[O*Q+2];D.instanceColors=N}}}for(let A of w.primitives||[]){if(A.extensions?.KHR_draco_mesh_compression){let C=ce("draco");C&&C.decodePrimitive(r,A,c)}let W=[],_=n.createVertexArray();i.vao=_,i.buffers=W,n.bindVertexArray(_);let q=lt(n,D,W),Z=r.accessors[A.attributes.POSITION],G=Number(Z?.count??0);if(!Number.isFinite(G)||G<0||R+G>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(R+=G,Z?.min&&Z?.max){let C=j=>{for(let V=0;V<3;V++){let J=j[12+V],se=j[12+V];for(let le=0;le<3;le++){let be=j[le*4+V]*Z.min[le],xe=j[le*4+V]*Z.max[le];J+=be<xe?be:xe,se+=be>xe?be:xe}J<b[V]&&(b[V]=J),se>x[V]&&(x[V]=se)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let j=D.instanceMatrices.length>>4,V=X();for(let J=0;J<j;J++){let se=D.instanceMatrices.subarray(J*16,J*16+16);$(V,v,se),C(V)}}else C(v)}let z=Le(n,r,c,A.attributes.POSITION,0,3,W);Le(n,r,c,A.attributes.NORMAL,1,3,W),Le(n,r,c,A.attributes.TEXCOORD_0,2,2,W,ht(r,A));let I=0,ne=5123,H=null;if(A.indices!==void 0){let C=r.accessors[A.indices],V=(r.bufferViews[C.bufferView].byteOffset||0)+(C.byteOffset||0);if(I=Number(C.count??0),!Number.isFinite(I)||I<0||y+I>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);y+=I,ne=C.componentType===5125?5125||5125:5123||5123;let J=n.createBuffer();W.push(J),n.bindBuffer(34963,J),C.componentType===5125?(H=new Uint32Array(c,V,C.count),n.bufferData(34963,H,35044)):C.componentType===5121?(H=Uint16Array.from(new Uint8Array(c,V,C.count)),n.bufferData(34963,H,35044)):(H=V%2===0?new Uint16Array(c,V,C.count):new Uint16Array(c.slice(V,V+C.count*2)),n.bufferData(34963,H,35044))}else I=Z.count;let Q={};for(let C of Y)if(C.onBuildPrimitiveVAO){let j=C.onBuildPrimitiveVAO(n,_,A,r,c);j&&(Q[C.name]=j)}n.bindVertexArray(null);let ee=r.materials&&A.material!==void 0?r.materials[A.material]:null,{program:ie,uniforms:ae}=$e(n,A,ee),N=qe(ee,E),O=!!(ee?.extensions?.KHR_materials_transmission||Q.materials?.isTransmissive),te=A.extensions?.KHR_materials_variants?.mappings,re=Array.isArray(te)?te.filter(C=>C&&typeof C.material=="number"&&Array.isArray(C.variants)).map(C=>({material:C.material|0,variants:C.variants.map(j=>Number(j)|0)})):void 0;D.primitives.push({vao:_,instanced:q,indexCount:I,indexType:ne,...N,positions:z,indices:H,buffers:W,materialIndex:A.material,defaultMaterialIndex:A.material,variantMappings:re,primitiveDef:A,programCache:new Map([[A.material??-1,{program:ie,uniforms:ae}]]),pluginData:Q,customProgram:ie,customUniforms:ae,isTransmissive:O})}a.push(D)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(x[0])||(x=[1,1,1]);let M=[(b[0]+x[0])/2,(b[1]+x[1])/2,(b[2]+x[2])/2],f=x[0]-b[0],T=x[1]-b[1],S=x[2]-b[2],L=Math.max(Math.hypot(f,T,S)/2,.5),k=[b[0],b[1],b[2]],U=[x[0],x[1],x[2]],F=e.animations;if(!F){for(let h of Y)if(h.onParseGLB?.(e),e.animations){F=e.animations;break}}return F||(F=[]),{meshes:a,bounds:{center:M,radius:L,min:k,max:U},lights:d,animations:F,worldMatrices:p,gpuTextures:E,availableVariants:l}}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 he=class{constructor(e,t,s){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=X();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=X();this.viewMatrix=X();this.activeViewMatrix=null;this.modelMatrix=X();this.mvpMatrix=X();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:X(),rawValueToMeters:.001,format:0};this.container=e;let i,r;if(t&&typeof t.getContext=="function"?(i=t,r=s):(r=t,i=r?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=r||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Ce(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=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 c=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!c)throw new Error("WebGL2 not supported");this.gl=c,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){Oe(e,t)}static getDecoder(e){return ce(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=je();this.renderProg=Fe(e,ze,t.fs),this.pickProg=Fe(e,ut,ct),this.uRender=Se(e,this.renderProg,t.uniforms),this.uPick=Se(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of Y)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),s=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=s,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,s,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,s),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 s=this.gl,i=Math.max(1,e),r=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=r,s.bindTexture(3553,this.pickTexture),s.texImage2D(3553,0,6408,i,r,0,6408,5121,null),s.bindRenderbuffer(36161,this.pickDepth),s.renderbufferStorage(36161,33189,i,r)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:s,bounds:i,lights:r,animations:o,worldMatrices:c,gpuTextures:a,availableVariants:l}=_e(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=s,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=r,this.animations=o||[],this.worldMatrices=c||[],this.gpuTextures=a||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of Y)m.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Ce(u));let p=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;p!==void 0&&(this.envIntensity=Math.max(0,Number(p)||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(Ne(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(Ie(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let s=Ie(e),{meshes:i}=_e(this.gl,s,Ke,()=>this.render());if(t)for(let r of i)r.transform[12]+=t[0],r.transform[13]+=t[1],r.transform[14]+=t[2],oe(r.normalMatrix,r.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,s,i=1){this.clearColor=[e,t,s,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let s=this.meshes[t],i;e instanceof Map?i=e.get(s.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,s.name)?i=e[s.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(s.transform.set(i),oe(s.normalMatrix,s.transform))}}bindLights(e=this.uRender){let t=this.gl,s=[.28,.28,.28],i=[],r=[],o=[],c=[];for(let a of this.lights){let l=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")s=[l[0]*u,l[1]*u,l[2]*u];else if(a.type==="directional"&&i.length<6){let p=a.direction||[.5,1,.8];i.push(p[0],p[1],p[2]),r.push(l[0]*u,l[1]*u,l[2]*u)}else if(a.type==="point"&&o.length<6){let p=a.position||[0,0,0];o.push(p[0],p[1],p[2]),c.push(l[0]*u,l[1]*u,l[2]*u)}}i.length===0&&(i.push(.5,1,.8),r.push(1,1,1)),t.uniform3fv(e.uAmbientColor,s),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,r)),t.uniform1i(e.uNumPointLights,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,c)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Ce(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=pe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Y)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Y)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,s=this.currDistance;return{theta:e,phi:t,radius:s,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${s.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,s)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(p=>p.materialIndex===s||e.length===1&&p.materialIndex===void 0)),r=i[0],o=r?[...r.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],c=r?r.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=r?r.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:o,metallicFactor:c,roughnessFactor:a,setBaseColorFactor:u=>{let p=[u[0],u[1],u[2],u[3]??1];l.baseColorFactor=p,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=p);for(let m of i)m.baseColor=p;this.render()},setMetallicFactor:u=>{l.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let p of i)p.metallic=u;this.render()},setRoughnessFactor:u=>{l.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let p of i)p.roughness=u;this.render()}};return{name:t.name||`Material_${s}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(s=>s.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==="",s=-1;if(t)this.activeVariantName=null;else{if(s=this.availableVariants.indexOf(e),s<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let r of this.meshes)for(let o of r.primitives){let c=o.defaultMaterialIndex;if(!t&&Array.isArray(o.variantMappings)){for(let l of o.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(s)){c=l.material;break}}let a=c!==void 0?i[c]:void 0;o.materialIndex=a?c:void 0,Object.assign(o,qe(a,this.gpuTextures)),this.applyPrimitiveProgram(o,o.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,s){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,r=e.programCache.get(i);r||(r=$e(this.gl,{...e.primitiveDef,material:t},s),e.programCache.set(i,r)),e.customProgram=r.program,e.customUniforms=r.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 Y)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,s){this.customTarget=[e,t,s],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,s=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(s,e))}setCamera(e,t,s,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),s!==void 0&&s>0&&(this.targetDistance=this.clampDistance(s)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,s,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),s!==void 0&&s>0){let r=this.clampDistance(s);this.initialDistance=r,this.customDistance=!0,this.targetDistance=r,this.currDistance=r}else if(i!==void 0&&i>0){let r=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=r,this.customDistance=!0,this.targetDistance=r,this.currDistance=r}else{this.customDistance=!1;let r=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=r,this.targetDistance=r,this.currDistance=r}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 s=X();$(s,this.projMatrix,this.viewMatrix);let[i,r,o]=e,c=t?t[0]:0,a=t?t[1]:0,l=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],r=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],o=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(c=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],a=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],l=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let p=s[0]*i+s[4]*r+s[8]*o+s[12],m=s[1]*i+s[5]*r+s[9]*o+s[13],g=s[2]*i+s[6]*r+s[10]*o+s[14],d=s[3]*i+s[7]*r+s[11]*o+s[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=p/d,b=m/d,x=g/d,R=this.canvas.getBoundingClientRect(),y=R.width||this.canvas.clientWidth||this.canvas.width||300,M=R.height||this.canvas.clientHeight||this.canvas.height||150,f=(E*.5+.5)*y,T=(-b*.5+.5)*M,S=E>=-1.1&&E<=1.1&&b>=-1.1&&b<=1.1&&x>=-1&&x<=1;if(S&&t){let[L,k,U]=fe(this),F=[i-L,r-k,o-U];c*F[0]+a*F[1]+l*F[2]>.05&&(S=!1)}return{x:f,y:T,z:x,visible:S}}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 s=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-s.x,r=t.clientY-s.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,r),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],c=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],l=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*o[0]+r*c[0])*l,a[1]+=(-i*o[1]+r*c[1])*l,a[2]+=(-i*o[2]+r*c[2])*l,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+r*.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 s=e.getBoundingClientRect(),i=Math.floor((t.clientX-s.left)*(e.width/Math.max(s.width,1))),r=Math.floor((t.clientY-s.top)*(e.height/Math.max(s.height,1)));this.performMeshPick(i,r,!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 s=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*s)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let s=t.detail||{};s.reset?this.resetCamera():this.setCamera(s.theta,s.phi,s.distance,s.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 s=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=s,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=s,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=s,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=s,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=s,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=s,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=s,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 s=this.canvas,i=s.getBoundingClientRect(),r=s.width||300,o=s.height||300,c=i.width>0?Math.floor((e-i.left)*(r/i.width)):Math.floor(e),a=i.height>0?Math.floor((t-i.top)*(o/i.height)):Math.floor(t);return this.performMeshPick(c,a,!1)}performMeshPick(e,t,s=!0){if(this.meshes.length===0)return null;let i=this.gl,r=Math.max(1,this.canvas.width||300),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,r);let c=X();$(c,this.projMatrix,this.viewMatrix);let a=[],l=Math.max(0,Math.min(r-1,e)),u=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==r||this.pickFboHeight!==o)&&this.resizePickingFbo(r,o),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,r,o),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let S=0;S<this.meshes.length;S++){let L=this.meshes[S];if(L.visible===!1||L.isPluginMesh)continue;let k=S+1,U=(k&255)/255,F=(k>>8&255)/255,h=(k>>16&255)/255;i.uniform4f(this.uPick.uColorId,U,F,h,1),$(this.modelMatrix,this.modelRootMatrix,L.transform);let P=L.instanceMatrices;if(P&&P.length>=16){let w=P.length>>4,v=X();for(let B of L.primitives){i.bindVertexArray(B.vao);for(let D=0;D<w;D++)$(v,this.modelMatrix,P.subarray(D*16,D*16+16)),$(this.mvpMatrix,c,v),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Me(i,B)}}else{$(this.mvpMatrix,c,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let w of L.primitives)i.bindVertexArray(w.vao),Me(i,w)}}let f=new Uint8Array(4);i.readPixels(l,u,1,1,6408,5121,f),i.bindFramebuffer(36160,null);let T=f[0]+(f[1]<<8)+(f[2]<<16);T>0&&T<=this.meshes.length&&(a=[this.meshes[T-1]])}a.length===0&&(a=this.meshes.filter(f=>f.visible!==!1));let p=null,m=1/0,g=[0,0,0],d=[0,1,0],[E,b,x]=fe(this),R=X();for(let f of a){$(R,this.modelRootMatrix,f.transform);let T=f.instanceMatrices,S=T&&T.length>=16?T.length>>4:1;for(let L=0;L<S;L++){T&&T.length>=16?$(this.modelMatrix,R,T.subarray(L*16,L*16+16)):this.modelMatrix.set(R),$(this.mvpMatrix,c,this.modelMatrix);let k=X();if(!we(k,this.mvpMatrix))continue;let U=(l+.5)/r*2-1,F=(u+.5)/o*2-1,h=[0,0,0],P=[0,0,0];ge(h,U,F,-1,k),ge(P,U,F,1,k);let w=P[0]-h[0],v=P[1]-h[1],B=P[2]-h[2],D=Math.hypot(w,v,B)||1,K=w/D,A=v/D,W=B/D,_={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Z=>{for(let G of f.primitives){if(!G.positions)continue;let z=G.positions,I=G.indices,ne=Math.floor(I?I.length/3:z.length/9);for(let H=0;H<ne;H++){let Q=I?I[H*3]:H*3,ee=I?I[H*3+1]:H*3+1,ie=I?I[H*3+2]:H*3+2;Ee(h[0],h[1],h[2],K,A,W,z[Q*3],z[Q*3+1],z[Q*3+2],z[ee*3],z[ee*3+1],z[ee*3+2],z[ie*3],z[ie*3+1],z[ie*3+2],_,Z)}}})(1e-4),isFinite(_.distance)){let Z=_.point[0],G=_.point[1],z=_.point[2],I=this.modelMatrix,ne=I[0]*Z+I[4]*G+I[8]*z+I[12],H=I[1]*Z+I[5]*G+I[9]*z+I[13],Q=I[2]*Z+I[6]*G+I[10]*z+I[14],ee=ne-E,ie=H-b,ae=Q-x,N=Math.hypot(ee,ie,ae);if(N<m){oe(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,te=_.normal[0],re=_.normal[1],C=_.normal[2],j=O[0]*te+O[3]*re+O[6]*C,V=O[1]*te+O[4]*re+O[7]*C,J=O[2]*te+O[5]*re+O[8]*C,se=Math.hypot(j,V,J)||1;j/=se,V/=se,J/=se,j*ee+V*ie+J*ae>0&&(j=-j,V=-V,J=-J),p=f,m=Math.round(N*1e3)/1e3,g=[Math.round(ne*1e3)/1e3,Math.round(H*1e3)/1e3,Math.round(Q*1e3)/1e3],d=[Math.round(j*1e3)/1e3,Math.round(V*1e3)/1e3,Math.round(J*1e3)/1e3]}}}}if(!p)return null;let M={meshIndex:this.meshes.indexOf(p),meshName:p.name,nodeIndex:p.nodeIndex,distance:m,hitPoint:g,normal:d,screenX:e,screenY:t};if(s){for(let f of Y)f.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let s=Math.max(1,Math.floor(t*.5)),i=e>=s,r=i?e-s:e,o=i?Math.max(1,t-s):s,c=(r+.5)/o*2-1;return Math.floor((c*.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);me(this.projMatrix,this.fov,e,.1,t);let s=this.customTarget||this.bounds.center;de(this.viewMatrix,fe(this),s,[0,1,0]),$(this.mvpMatrix,this.projMatrix,this.viewMatrix),oe(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),s=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==s||this.canvas.height!==i?(this.canvas.width=s,this.canvas.height=i,this.resizePickingFbo(s,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 s of Y)s.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(s){this.reportRenderError(s)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of Y)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let s=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(s),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),s=this.bounds.center[0],i=this.bounds.center[2],r=this.modelRootMatrix;r[0]=e,r[1]=0,r[2]=-t,r[3]=0,r[4]=0,r[5]=1,r[6]=0,r[7]=0,r[8]=t,r[9]=0,r[10]=e,r[11]=0,r[12]=s-(e*s+t*i),r[13]=0,r[14]=i-(-t*s+e*i),r[15]=1}setVisible(e){this.isVisible=e}update(e){for(let o of Y)o.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 o of Y)o.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 s=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),r=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(s-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(r-this.lastReportedZoom)>=.02){this.lastReportedTheta=s,this.lastReportedPhi=i,this.lastReportedZoom=r;let o={theta:s,phi:i,zoom:r,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,s,i,r=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let c=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,u=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):s&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:c,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:r})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let y=Math.max(2,this.canvas.width||2),M=Math.max(1,this.canvas.height||1),f=Math.max(1,Math.floor(y*.5)),T=Math.max(1,y-f),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[k,U,F]=fe(this),h=Math.cos(this.currTheta),P=-Math.sin(this.currTheta),w=.032,v=X(),B=X(),D=[k-h*w,U,F-P*w],K=[L[0]-h*w*.25,L[1],L[2]-P*w*.25];me(v,this.fov,f/M,.1,S),de(B,D,K,[0,1,0]);let A=X(),W=X(),_=[k+h*w,U,F+P*w],q=[L[0]+h*w*.25,L[1],L[2]+P*w*.25];me(A,this.fov,T/M,.1,S),de(W,_,q,[0,1,0]),this.render({viewMatrix:B,projMatrix:v,eyePos:D,viewport:[0,0,f,M],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:W,projMatrix:A,eyePos:_,viewport:[f,0,T,M],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,y,M);return}let t=this.gl,s=0,i=0,r=this.canvas.width,o=this.canvas.height;e?.viewport?(s=e.viewport[0],i=e.viewport[1],r=e.viewport[2],o=e.viewport[3],t.viewport(s,i,r,o)):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 c=X(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,$(c,e?.projMatrix??this.projMatrix,a);let l=ue().xrDepthShader,u=Ue(this.toneMapping),[p,m,g]=e?e.eyePos:fe(this);for(let y of Y)y.onBeforeDrawScene?.(this,t,c,[p,m,g],u);let d=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&d===0)return;let E=e?.eye||"none",b=!1,x=d>0?[...this.backdropMeshes,...this.meshes]:this.meshes,R=y=>{for(let M=0;M<x.length;M++){let f=x[M];if(f.visible===!1)continue;let T=this.selectedMeshName!==""&&f.name===this.selectedMeshName;M<d||f.worldSpace===!0||f.name==="__xr_reticle__"?this.modelMatrix.set(f.transform):$(this.modelMatrix,this.modelRootMatrix,f.transform),$(this.mvpMatrix,c,this.modelMatrix),oe(f.normalMatrix,this.modelMatrix);let S=f.extras?.xr?.stereo||f.userData?.xr?.stereo,L=0,k=0,U=1,F=1;S==="sbs"?(U=.5,L=E==="right"?.5:0):S==="ou"&&(F=.5,k=E==="right"?.5:0);for(let h of f.primitives){let P=!!h.isTransmissive;if(!y&&P){b=!0;continue}if(y&&!P)continue;let w=h.customProgram||this.renderProg,v=h.customUniforms||this.uRender;t.useProgram(w),t.uniform1i(v.uToneMapping,u),t.uniform1f(v.uEnvIntensity,this.envIntensity),v.uExposure&&t.uniform1f(v.uExposure,this.exposure),t.uniform3f(v.uCameraPos,p,m,g),t.uniform1f(v.uEmissive,T?1:0),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(v.uNormalMatrix,!1,f.normalMatrix),v.uUvTransform&&t.uniform4f(v.uUvTransform,L,k,U,F),v.uViewportSize&&t.uniform2f(v.uViewportSize,Math.max(1,r),Math.max(1,o)),l?.bind(t,v,this.xrDepthState,a,[s,i,Math.max(1,r),Math.max(1,o)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(v.uEnvironmentMap,4),t.uniform1i(v.uHasEnvironmentMap,1)):t.uniform1i(v.uHasEnvironmentMap,0),this.bindLights(v),v.uSectionEnabled&&t.uniform1i(v.uSectionEnabled,0);for(let D of Y)D.onBeforeDrawPrimitive?.(t,w,h,f,this.worldMatrices||[],this.gltf);t.uniform4fv(v.uBaseColor,h.baseColor),t.uniform1f(v.uMetallic,h.metallic),t.uniform1f(v.uRoughness,h.roughness),v.uClearcoat&&t.uniform2f(v.uClearcoat,h.clearcoat??0,h.clearcoatRoughness??.04),h.texture?(t.activeTexture(33984),t.bindTexture(3553,h.texture),t.uniform1i(v.uBaseColorTexture,0),t.uniform1i(v.uHasTexture,1)):t.uniform1i(v.uHasTexture,0),h.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,h.metallicRoughnessTexture),t.uniform1i(v.uMetallicRoughnessTexture,1),t.uniform1i(v.uHasMetallicRoughnessTexture,1)):t.uniform1i(v.uHasMetallicRoughnessTexture,0),h.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,h.normalTexture),t.uniform1i(v.uNormalTexture,2),t.uniform1i(v.uHasNormalTexture,1),t.uniform1f(v.uNormalScale,h.normalScale)):t.uniform1i(v.uHasNormalTexture,0),h.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,h.occlusionTexture),t.uniform1i(v.uOcclusionTexture,3),t.uniform1i(v.uHasOcclusionTexture,1),t.uniform1f(v.uOcclusionStrength,h.occlusionStrength)):t.uniform1i(v.uHasOcclusionTexture,0),t.bindVertexArray(h.vao);let B=f.instanceMatrices;if(B&&B.length>=16&&h.instanced&&v.uInstanced&&v.uViewProj){let D=B.length>>4;t.uniform1i(v.uInstanced,1),t.uniformMatrix4fv(v.uViewProj,!1,c),h.indices?t.drawElementsInstanced(4,h.indexCount,h.indexType,0,D):t.drawArraysInstanced(4,0,h.indexCount,D),t.uniform1i(v.uInstanced,0)}else if(B&&B.length>=16){let D=B.length>>4,K=f.instanceColors,A=X(),W=new Float32Array(9),_=[h.baseColor[0],h.baseColor[1],h.baseColor[2],h.baseColor[3]];for(let q=0;q<D;q++)$(A,this.modelMatrix,B.subarray(q*16,q*16+16)),$(this.mvpMatrix,c,A),oe(W,A),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,A),t.uniformMatrix3fv(v.uNormalMatrix,!1,W),K&&(_[0]=h.baseColor[0]*K[q*3],_[1]=h.baseColor[1]*K[q*3+1],_[2]=h.baseColor[2]*K[q*3+2],_[3]=h.baseColor[3],t.uniform4fv(v.uBaseColor,_)),Me(t,h)}else Me(t,h)}}};if(R(!1),b){for(let y of Y)y.onBeforeTransmissivePass?.(t,this);R(!0)}for(let y of Y)y.onAfterRender?.(t,this,c)}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 Y)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};he.registerPlugin=Ae,he.getRegisteredPlugins=De;var ft=he;
@@ -53,6 +53,7 @@ export {
53
53
  installCadExtension,
54
54
  MAX_BSP_DEPTH,
55
55
  MAX_CSG_TRIANGLES,
56
+ MAX_SHAPE_POINTS,
56
57
  MAX_TEXT_GEOMETRY_CHARS,
57
58
  type ExtrudeGeometryOptions,
58
59
  type TextGeometryOptions,
@@ -298,7 +299,7 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
298
299
  'peer-name'?: string;
299
300
  /** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
300
301
  'peer-color'?: string;
301
- /** Opt-in WebRTC spatial voice chat signaling and HRTF distance attenuation in `shared-room`. */
302
+ /** Opt-in WebRTC voice signaling relay (offer/answer/ICE) and `voiceGain` helpers in `shared-room`. Apps own `RTCPeerConnection` and audio. */
302
303
  'shared-room-voice'?: boolean | string;
303
304
  /** xr-live-sim: character camera mode, or `none` to disable the character. */
304
305
  'character-controller'?: