three-live 1.2.1 → 1.2.2

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 (44) hide show
  1. package/README.md +6 -1
  2. package/dist/index.d.ts +65 -2
  3. package/dist/three-author-engine.js +66 -41
  4. package/dist/three-author.cjs +63 -39
  5. package/dist/three-author.d.ts +65 -2
  6. package/dist/three-author.js +63 -39
  7. package/dist/three-convert.cjs +61 -37
  8. package/dist/three-convert.d.ts +65 -2
  9. package/dist/three-convert.js +61 -37
  10. package/dist/three-live-animation.cjs +7 -7
  11. package/dist/three-live-animation.d.ts +65 -2
  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 +18 -0
  15. package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +65 -2
  16. package/dist/three-live-cad.js +18 -0
  17. package/dist/three-live-cad.min.js +18 -0
  18. package/dist/three-live-element.cjs +29 -5
  19. package/dist/three-live-element.d.ts +65 -2
  20. package/dist/three-live-element.js +29 -5
  21. package/dist/three-live-full.cjs +159 -56
  22. package/dist/three-live-full.js +159 -56
  23. package/dist/three-live-full.min.js +159 -56
  24. package/dist/three-live-studio.cjs +120 -0
  25. package/dist/three-live-studio.d.ts +509 -0
  26. package/dist/three-live-studio.js +120 -0
  27. package/dist/three-live-studio.min.js +120 -0
  28. package/dist/three-live-viewer.cjs +29 -5
  29. package/dist/three-live-viewer.d.ts +65 -2
  30. package/dist/three-live-viewer.js +29 -5
  31. package/dist/three-live-viewer.min.js +29 -5
  32. package/dist/three-live.cjs +66 -42
  33. package/dist/three-live.js +66 -42
  34. package/dist/three-live.min.js +66 -42
  35. package/dist/three-view.cjs +29 -5
  36. package/dist/three-view.d.ts +65 -2
  37. package/dist/three-view.js +29 -5
  38. package/dist/three-xr.cjs +65 -41
  39. package/dist/three-xr.d.ts +65 -2
  40. package/dist/three-xr.js +65 -41
  41. package/package.json +10 -5
  42. package/dist/three-live-extras.cjs +0 -42
  43. package/dist/three-live-extras.js +0 -42
  44. package/dist/three-live-extras.min.js +0 -42
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- function H(){let i=new Float32Array(16);return i[0]=1,i[5]=1,i[10]=1,i[15]=1,i}function fe(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 pe(i,e,t,r){let[n,s,a]=e,[h,c,u]=r,[o,l,f]=t,b=n-o,p=s-l,y=a-f,T=Math.hypot(b,p,y);T<=1e-5?(b=0,p=0,y=1):(b/=T,p/=T,y/=T);let R=c*y-u*p,w=u*b-h*y,P=h*p-c*b;T=Math.hypot(R,w,P),T<=1e-5?(R=0,w=0,P=0):(R/=T,w/=T,P/=T);let v=p*P-y*w,d=y*R-b*P,m=b*w-p*R;return T=Math.hypot(v,d,m),T<=1e-5?(v=0,d=0,m=0):(v/=T,d/=T,m/=T),i[0]=R,i[1]=v,i[2]=b,i[3]=0,i[4]=w,i[5]=d,i[6]=p,i[7]=0,i[8]=P,i[9]=m,i[10]=y,i[11]=0,i[12]=-(R*n+w*s+P*a),i[13]=-(v*n+d*s+m*a),i[14]=-(b*n+p*s+y*a),i[15]=1,i}function z(i,e,t){let r=e[0],n=e[1],s=e[2],a=e[3],h=e[4],c=e[5],u=e[6],o=e[7],l=e[8],f=e[9],b=e[10],p=e[11],y=e[12],T=e[13],R=e[14],w=e[15],P=t[0],v=t[1],d=t[2],m=t[3];return i[0]=P*r+v*h+d*l+m*y,i[1]=P*n+v*c+d*f+m*T,i[2]=P*s+v*u+d*b+m*R,i[3]=P*a+v*o+d*p+m*w,P=t[4],v=t[5],d=t[6],m=t[7],i[4]=P*r+v*h+d*l+m*y,i[5]=P*n+v*c+d*f+m*T,i[6]=P*s+v*u+d*b+m*R,i[7]=P*a+v*o+d*p+m*w,P=t[8],v=t[9],d=t[10],m=t[11],i[8]=P*r+v*h+d*l+m*y,i[9]=P*n+v*c+d*f+m*T,i[10]=P*s+v*u+d*b+m*R,i[11]=P*a+v*o+d*p+m*w,P=t[12],v=t[13],d=t[14],m=t[15],i[12]=P*r+v*h+d*l+m*y,i[13]=P*n+v*c+d*f+m*T,i[14]=P*s+v*u+d*b+m*R,i[15]=P*a+v*o+d*p+m*w,i}function Te(i,e,t,r){let n=e[0],s=e[1],a=e[2],h=e[3],c=n+n,u=s+s,o=a+a,l=n*c,f=n*u,b=n*o,p=s*u,y=s*o,T=a*o,R=h*c,w=h*u,P=h*o,v=r[0],d=r[1],m=r[2];return i[0]=(1-(p+T))*v,i[1]=(f+P)*v,i[2]=(b-w)*v,i[3]=0,i[4]=(f-P)*d,i[5]=(1-(l+T))*d,i[6]=(y+R)*d,i[7]=0,i[8]=(b+w)*m,i[9]=(y-R)*m,i[10]=(1-(l+p))*m,i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i}function te(i,e){let t=e[0],r=e[1],n=e[2],s=e[4],a=e[5],h=e[6],c=e[8],u=e[9],o=e[10],l=o*a-h*u,f=-o*s+h*c,b=u*s-a*c,p=t*l+r*f+n*b;return p&&(p=1/p,i[0]=l*p,i[1]=(-o*r+n*u)*p,i[2]=(h*r-n*a)*p,i[3]=f*p,i[4]=(o*t-n*c)*p,i[5]=(-h*t+n*s)*p,i[6]=b*p,i[7]=(-u*t+r*c)*p,i[8]=(a*t-r*s)*p),i}function Me(i,e){let t=e[0],r=e[1],n=e[2],s=e[3],a=e[4],h=e[5],c=e[6],u=e[7],o=e[8],l=e[9],f=e[10],b=e[11],p=e[12],y=e[13],T=e[14],R=e[15],w=t*h-r*a,P=t*c-n*a,v=t*u-s*a,d=r*c-n*h,m=r*u-s*h,F=n*u-s*c,E=o*y-l*p,x=o*T-f*p,A=o*R-b*p,L=l*T-f*y,C=l*R-b*y,g=f*R-b*T,M=w*g-P*C+v*L+d*A-m*x+F*E;return M?(M=1/M,i[0]=(h*g-c*C+u*L)*M,i[1]=(n*C-r*g-s*L)*M,i[2]=(y*F-T*m+R*d)*M,i[3]=(f*m-l*F-b*d)*M,i[4]=(c*A-a*g-u*x)*M,i[5]=(t*g-n*A+s*x)*M,i[6]=(T*v-p*F-R*P)*M,i[7]=(o*F-f*v+b*P)*M,i[8]=(a*C-h*A+u*E)*M,i[9]=(r*A-t*C-s*E)*M,i[10]=(p*m-y*v+R*w)*M,i[11]=(l*v-o*m-b*w)*M,i[12]=(h*x-a*L-c*E)*M,i[13]=(t*L-r*x+n*E)*M,i[14]=(y*P-p*d-T*w)*M,i[15]=(o*d-l*P+f*w)*M,i):null}function ve(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],h=n[2]*e+n[6]*t+n[10]*r+n[14],c=n[3]*e+n[7]*t+n[11]*r+n[15],u=c!==0?1/c:1;i[0]=s*u,i[1]=a*u,i[2]=h*u}function Re(i,e,t,r,n,s,a,h,c,u,o,l,f,b,p,y,T=0){let R=u-a,w=o-h,P=l-c,v=f-a,d=b-h,m=p-c,F=n*m-s*d,E=s*v-r*m,x=r*d-n*v,A=R*F+w*E+P*x;if(A>-1e-7&&A<1e-7)return!1;let L=1/A,C=i-a,g=e-h,M=t-c,B=L*(C*F+g*E+M*x);if(B<-T||B>1+T)return!1;let D=g*P-M*w,W=M*R-C*P,G=C*w-g*R,ee=L*(r*D+n*W+s*G);if(ee<-T||B+ee>1+T)return!1;let _=L*(v*D+d*W+m*G);if(_>1e-4&&_<y.distance){y.distance=_,y.point=[i+r*_,e+n*_,t+s*_];let X=w*m-P*d,N=P*v-R*m,S=R*d-w*v,k=Math.hypot(X,N,S)||1;return y.normal=[X/k,N/k,S/k],!0}return!1}function Pe(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 l of o.children)n.add(l);let s=new Set,a=128,h=(o,l,f=0)=>{if(f>a||o<0||o>=t||s.has(o))return;s.add(o);let b=i.nodes[o];if(!b)return;let p=H();if(e&&e[o])p.set(e[o]);else if(b.matrix&&b.matrix.length===16)p.set(b.matrix);else{let T=b.translation||[0,0,0],R=b.rotation||[0,0,0,1],w=b.scale||[1,1,1];Te(p,R,T,w)}let y=r[o];if(l?z(y,l,p):y.set(p),Array.isArray(b.children))for(let T of b.children)typeof T=="number"&&h(T,y,f+1)},c=[],u=i.scenes&&i.scenes[i.scene!==void 0?i.scene:0];if(u&&Array.isArray(u.nodes))c.push(...u.nodes);else for(let o=0;o<t;o++)n.has(o)||c.push(o);for(let o of c)h(o,null);for(let o=0;o<t;o++)!n.has(o)&&!c.includes(o)&&h(o,null);return r}var be="__THREE_LIVE_REGISTRY__";function ie(){let i=typeof globalThis<"u"?globalThis:{};if(!i[be]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(i,be,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{i[be]=e}}return i[be]}var V=ie().plugins;function De(i){let e=ie().plugins;e.some(t=>t.name===i.name)||e.push(i)}function Ee(){return ie().plugins}function We(i){return new TextDecoder().decode(i)}var Fe=ie().decoders;function Xe(i,e){Fe.set(i.toLowerCase(),e)}function he(i){return Fe.get(i.toLowerCase())}function Se(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 f=t.getUint8(0);throw f===123||f===32||f===10||f===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,h=null,c=null;for(;a+8<=s&&a+8<=e.byteLength;){let f=t.getUint32(a,!0),b=t.getUint32(a+4,!0),p=a+8;if(p+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${p+f} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let y=new Uint8Array(e,p,f),T=We(y);h=JSON.parse(T,(R,w)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:w)}else b===5130562&&(c=e.slice(p,p+f));a=p+f}if(!h)throw new Error("Missing JSON chunk in GLB");let u=h.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!he("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(u.includes("EXT_meshopt_compression")&&!he("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(u.includes("KHR_texture_basisu")&&!he("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let o=c||new ArrayBuffer(0),l={gltf:h,bin:o,animations:[]};for(let f of V)f.onParseGLB?.(l);return l}function Qe(i,e,t){return e%4===0?new Float32Array(i,e,t):new Float32Array(i.slice(e,e+t*4))}function Oe(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 we(i){if(Oe(i))return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return Se(i);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ie=`#version 300 es
17
+ function O(){let i=new Float32Array(16);return i[0]=1,i[5]=1,i[10]=1,i[15]=1,i}function ye(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 Te(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 Z(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 Re(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 oe(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 Ce(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 we(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 Le(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 H=P*(T*x+v*G+d*A);if(H>1e-4&&H<p.distance){p.distance=H,p.point=[i+r*H,e+n*H,t+s*H];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 Fe(i,e){let t=Array.isArray(i?.nodes)?i.nodes.length:0,r=[];for(let o=0;o<t;o++)r.push(O());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=O();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];Re(m,R,b,D)}let p=r[o];if(h?Z(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 Me="__THREE_LIVE_REGISTRY__";function ce(){let i=typeof globalThis<"u"?globalThis:{};if(!i[Me]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(i,Me,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{i[Me]=e}}return i[Me]}var q=ce().plugins;function Ie(i){let e=ce().plugins;e.some(t=>t.name===i.name)||e.push(i),i.onRegister?.()}function Se(){return ce().plugins}function qe(i){return new TextDecoder().decode(i)}var Ge=ce().decoders;function Ze(i,e){Ge.set(i.toLowerCase(),e)}function he(i){return Ge.get(i.toLowerCase())}function Ve(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=qe(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")&&!he("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(c.includes("EXT_meshopt_compression")&&!he("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(c.includes("KHR_texture_basisu")&&!he("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 q)g.onParseGLB?.(h);return h}function Je(i,e,t){return e%4===0?new Float32Array(i,e,t):new Float32Array(i.slice(e,e+t*4))}function Qe(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 Ne(i){if(Qe(i))return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return Ve(i);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ue=`#version 300 es
18
18
  layout(location=0) in vec3 aPosition;
19
19
  layout(location=1) in vec3 aNormal;
20
20
  layout(location=2) in vec2 aUV;
@@ -32,7 +32,7 @@ vec2 scaleUV=uUvTransform.zw;
32
32
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
33
  vUV=aUV*scaleUV+uUvTransform.xy;
34
34
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,ze=`#version 300 es
35
+ }`,et=`#version 300 es
36
36
  precision highp float;
37
37
  in vec3 vNormal,vWorldPos;
38
38
  in vec2 vUV;
@@ -108,9 +108,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
108
108
  return mix(color,newPeak*vec3(1.0),g);
109
109
  }
110
110
 
111
+ vec3 acesToneMapping(vec3 color){
112
+ color*=0.6;
113
+ return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
114
+ }
115
+
116
+ vec3 agxToneMapping(vec3 color){
117
+ color=max(color,vec3(0.0));
118
+ vec3 inset=vec3(
119
+ 0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
120
+ 0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
121
+ 0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
122
+ vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
123
+ vec3 x2=ev*ev;
124
+ vec3 x4=x2*x2;
125
+ vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
126
+ vec3 outset=vec3(
127
+ 1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
128
+ -0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
129
+ -0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
130
+ return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
131
+ }
132
+
111
133
  vec3 applyToneMapping(vec3 color,int mode){
112
134
  if(mode==0)return neutralToneMapping(color);
113
135
  if(mode==1)return color/(color+vec3(1.0));
136
+ if(mode==3)return acesToneMapping(color);
137
+ if(mode==4)return agxToneMapping(color);
114
138
  return color;
115
139
  }
116
140
 
@@ -198,11 +222,11 @@ color=applyToneMapping(color,uToneMapping);
198
222
  float outAlpha=base.a;
199
223
  /*XRD_O*/
200
224
  fragColor=vec4(color,outAlpha);
201
- }`,Ye=`#version 300 es
225
+ }`;function ut(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 tt=`#version 300 es
202
226
  layout(location=0) in vec3 aPosition;
203
227
  uniform mat4 uMVP;
204
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,je=`#version 300 es
228
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,it=`#version 300 es
205
229
  precision highp float;
206
230
  uniform vec4 uColorId;
207
231
  out vec4 fragColor;
208
- void main(){fragColor=uColorId;}`;function Ae(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 ge(i,e,t){let r=Ae(i,35633,e),n=Ae(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 ye(i,e,t){let r={};for(let n of t)r[n]=i.getUniformLocation(e,n);return r}var Le=["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 Ne(){let i=ie().xrDepthShader;return{fs:ze.replace("/*XRD_U*/",i?.uniformsGLSL||"").replace("/*XRD_O*/",i?.occlusionGLSL||""),uniforms:i?[...Le,...i.uniformNames]:Le}}function Ke(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 xe(i,e,t,r,n,s,a){if(r===void 0||!e.accessors?.[r])return null;let h=e.accessors[r],c=e.bufferViews[h.bufferView],u=(c.byteOffset||0)+(h.byteOffset||0),o=c.byteStride&&c.byteStride>s*4?c.byteStride>>2:s,l;if(o===s)l=new Float32Array(t,u,h.count*s);else{l=new Float32Array(h.count*s);let b=new Float32Array(t,c.byteOffset||0,Math.floor(c.byteLength/4)),p=(h.byteOffset||0)>>2;for(let y=0;y<h.count;y++){let T=p+y*o;for(let R=0;R<s;R++)l[y*s+R]=b[T+R]}}let f=i.createBuffer();return a.push(f),i.bindBuffer(34962,f),i.bufferData(34962,l,35044),i.enableVertexAttribArray(n),i.vertexAttribPointer(n,s,5126,!1,0,0),l}var et=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Be=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ce(i,e,t=Be,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n,bin:s}=e,a=[],h=Pe(n),c=[];if(Array.isArray(n.nodes))for(let E=0;E<n.nodes.length;E++){let x=n.nodes[E];x.mesh!==void 0&&n.meshes&&n.meshes[x.mesh]&&c.push({node:x,nodeIdx:E,meshIdx:x.mesh})}let u=c.length>0?c:(n.meshes||[]).map((E,x)=>({node:E,nodeIdx:-1,meshIdx:x})),o=[];if(Array.isArray(e.lights)&&e.lights.length>0)o.push(...e.lights);else if(n.extensions?.KHR_lights_punctual?.lights){let E=n.extensions.KHR_lights_punctual.lights;for(let x of E){let A=x.type==="directional"?"directional":x.type==="point"?"point":"ambient";o.push({type:A,color:x.color||[1,1,1],intensity:x.intensity!==void 0?x.intensity:1})}}if(o.length===0&&(o.push({type:"ambient",color:[1,1,1],intensity:.35}),o.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),u.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${u.length}`);let l=[];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 E=0;E<n.textures.length;E++){let x=n.textures[E],A=n.images[x.source];if(A){let L=i.createTexture();if(i.bindTexture(3553,L),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),A.bufferView!==void 0){let C=n.bufferViews[A.bufferView],g=s.slice(C.byteOffset||0,(C.byteOffset||0)+C.byteLength),M=new Blob([g],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(M).then(B=>{i.bindTexture(3553,L),i.texImage2D(3553,0,6408,6408,5121,B),i.generateMipmap(3553),r?.()}).catch(()=>{})}else if(A.uri){let C=Ke(A.uri);if(C){let g=new Image;g.crossOrigin="anonymous",g.referrerPolicy="no-referrer",g.onload=()=>{i.bindTexture(3553,L),i.texImage2D(3553,0,6408,6408,5121,g),i.generateMipmap(3553),r?.()},g.src=C}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}l.push(L)}else l.push(null)}}let f=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],p=0,y=0;for(let E=0;E<u.length;E++){let x=u[E],A=n.meshes[x.meshIdx],L=x.nodeIdx>=0?h[x.nodeIdx]:H(),C=new Float32Array(9);te(C,L);let g={name:x.node.name||A.name||`Mesh_${x.meshIdx}`,nodeIndex:x.nodeIdx,transform:L,normalMatrix:C,primitives:[],extras:x.node.extras||A.extras};for(let M of A.primitives||[]){if(M.extensions?.KHR_draco_mesh_compression){let I=he("draco");I&&I.decodePrimitive(n,M,s)}let B=[],D=i.createVertexArray();i.bindVertexArray(D);let W=n.accessors[M.attributes.POSITION],G=Number(W?.count??0);if(!Number.isFinite(G)||G<0||p+G>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(p+=G,W?.min&&W?.max)for(let I=0;I<3;I++){let Y=L[12+I],re=L[12+I];for(let Z=0;Z<3;Z++){let me=L[Z*4+I]*W.min[Z],de=L[Z*4+I]*W.max[Z];Y+=me<de?me:de,re+=me>de?me:de}Y<f[I]&&(f[I]=Y),re>b[I]&&(b[I]=re)}let ee=xe(i,n,s,M.attributes.POSITION,0,3,B);xe(i,n,s,M.attributes.NORMAL,1,3,B),xe(i,n,s,M.attributes.TEXCOORD_0,2,2,B);let _=0,X=5123,N=null;if(M.indices!==void 0){let I=n.accessors[M.indices],re=(n.bufferViews[I.bufferView].byteOffset||0)+(I.byteOffset||0);if(_=Number(I.count??0),!Number.isFinite(_)||_<0||y+_>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);y+=_,X=I.componentType===5125?5125||5125:5123||5123;let Z=i.createBuffer();B.push(Z),i.bindBuffer(34963,Z),I.componentType===5125?(N=new Uint32Array(s,re,I.count),i.bufferData(34963,N,35044)):(N=new Uint16Array(s,re,I.count),i.bufferData(34963,N,35044))}else _=W.count;let S={};for(let I of V)if(I.onBuildPrimitiveVAO){let Y=I.onBuildPrimitiveVAO(i,D,M,n,s);Y&&(S[I.name]=Y)}i.bindVertexArray(null);let k=n.materials&&M.material!==void 0?n.materials[M.material]:null,O=Ne(),j=Ie,K=O.fs,q=!1;for(let I of V)if(I.onResolveShader){let Y=I.onResolveShader(M,k,j,K);Y&&(j=Y.vs,K=Y.fs,q=!0)}let ne=q?ge(i,j,K):null,le=ne?ye(i,ne,O.uniforms):null,U=k?.pbrMetallicRoughness,se=U?.baseColorFactor||[.8,.8,.8,1],oe=U?.metallicFactor??.1,ae=U?.roughnessFactor??.5,$=k?.extensions?.KHR_materials_clearcoat,J=$?$.clearcoatFactor??1:0,Q=Math.max(.04,$?.clearcoatRoughnessFactor??.04),ue=U?.baseColorTexture!==void 0&&l[U.baseColorTexture.index]?l[U.baseColorTexture.index]:null,_e=U?.metallicRoughnessTexture!==void 0&&l[U.metallicRoughnessTexture.index]?l[U.metallicRoughnessTexture.index]:null,ke=k?.normalTexture!==void 0&&l[k.normalTexture.index]?l[k.normalTexture.index]:null,Ge=k?.normalTexture?.scale??1,Ue=k?.occlusionTexture!==void 0&&l[k.occlusionTexture.index]?l[k.occlusionTexture.index]:null,Ve=k?.occlusionTexture?.strength??1,He=!!(k?.extensions?.KHR_materials_transmission||S.materials?.isTransmissive);g.primitives.push({vao:D,indexCount:_,indexType:X,baseColor:se,metallic:oe,roughness:ae,clearcoat:J,clearcoatRoughness:Q,positions:ee,indices:N,texture:ue,metallicRoughnessTexture:_e,normalTexture:ke,occlusionTexture:Ue,normalScale:Ge,occlusionStrength:Ve,buffers:B,materialIndex:M.material,pluginData:S,customProgram:ne,customUniforms:le,isTransmissive:He})}a.push(g)}isFinite(f[0])||(f=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let T=[(f[0]+b[0])/2,(f[1]+b[1])/2,(f[2]+b[2])/2],R=b[0]-f[0],w=b[1]-f[1],P=b[2]-f[2],v=Math.max(Math.hypot(R,w,P)/2,.5),d=[f[0],f[1],f[2]],m=[b[0],b[1],b[2]],F=e.animations;if(!F){for(let E of V)if(E.onParseGLB?.(e),e.animations){F=e.animations;break}}return F||(F=[]),{meshes:a,bounds:{center:T,radius:v,min:d,max:m},lights:o,animations:F,worldMatrices:h}}var ce=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.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 u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),n=u}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.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 h=n.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h;let c=Ne();this.renderProg=ge(h,Ie,c.fs),this.pickProg=ge(h,Ye,je),this.uRender=ye(h,this.renderProg,c.uniforms),this.uPick=ye(h,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){Xe(e,t)}static getDecoder(e){return he(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:h}=Ce(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=h||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let u of e.gltf.nodes)this.initialNodeTransforms.push({t:u.translation?[u.translation[0],u.translation[1],u.translation[2]]:[0,0,0],r:u.rotation?[u.rotation[0],u.rotation[1],u.rotation[2],u.rotation[3]]:[0,0,0,1],s:u.scale?[u.scale[0],u.scale[1],u.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let u of V)u.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 c=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c))),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(Se(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(we(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=we(e),{meshes:n}=Ce(this.gl,r,Be,()=>this.render());if(t)for(let s of n)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],te(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),te(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],n=[],s=[],a=[],h=[];for(let c of this.lights){let u=c.color||[1,1,1],o=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")r=[u[0]*o,u[1]*o,u[2]*o];else if(c.type==="directional"&&n.length<6){let l=c.direction||[.5,1,.8];n.push(l[0],l[1],l[2]),s.push(u[0]*o,u[1]*o,u[2]*o)}else if(c.type==="point"&&a.length<6){let l=c.position||[0,0,0];a.push(l[0],l[1],l[2]),h.push(u[0]*o,u[1]*o,u[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,h)),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 V)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of V)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(l=>l.materialIndex===r||e.length===1&&l.materialIndex===void 0)),s=n[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],h=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,c=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:a,metallicFactor:h,roughnessFactor:c,setBaseColorFactor:o=>{let l=[o[0],o[1],o[2],o[3]??1];u.baseColorFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=l);for(let f of n)f.baseColor=l;this.render()},setMetallicFactor:o=>{u.metallicFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=o);for(let l of n)l.metallic=o;this.render()},setRoughnessFactor:o=>{u.roughnessFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=o);for(let l of n)l.roughness=o;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:u}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of V)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();z(r,this.projMatrix,this.viewMatrix);let[n,s,a]=e,h=t?t[0]:0,c=t?t[1]:0,u=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&&(h=o[0]*t[0]+o[4]*t[1]+o[8]*t[2],c=o[1]*t[0]+o[5]*t[1]+o[9]*t[2],u=o[2]*t[0]+o[6]*t[1]+o[10]*t[2]));let l=r[0]*n+r[4]*s+r[8]*a+r[12],f=r[1]*n+r[5]*s+r[9]*a+r[13],b=r[2]*n+r[6]*s+r[10]*a+r[14],p=r[3]*n+r[7]*s+r[11]*a+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let y=l/p,T=f/p,R=b/p,w=this.canvas.getBoundingClientRect(),P=w.width||this.canvas.clientWidth||this.canvas.width||300,v=w.height||this.canvas.clientHeight||this.canvas.height||150,d=(y*.5+.5)*P,m=(-T*.5+.5)*v,F=y>=-1.1&&y<=1.1&&T>=-1.1&&T<=1.1&&R>=-1&&R<=1;if(F&&t){let E=this.customTarget||this.bounds.center,x=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=E[1]+this.currDistance*Math.sin(this.currPhi),L=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),C=[n-x,s-A,a-L];h*C[0]+c*C[1]+u*C[2]>.05&&(F=!1)}return{x:d,y:m,z:R,visible:F}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},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]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-n*a[0]+s*h[0])*u,c[1]+=(-n*a[1]+s*h[1])*u,c[2]+=(-n*a[2]+s*h[2])*u,this.customTarget=c}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,h=n.width>0?Math.floor((e-n.left)*(s/n.width)):Math.floor(e),c=n.height>0?Math.floor((t-n.top)*(a/n.height)):Math.floor(t);return this.performMeshPick(h,c,!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 h=H();z(h,this.projMatrix,this.viewMatrix);let c=[],u=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 F=0;F<this.meshes.length;F++){let E=this.meshes[F];if(E.visible===!1||E.isPluginMesh)continue;let x=F+1,A=(x&255)/255,L=(x>>8&255)/255,C=(x>>16&255)/255;n.uniform4f(this.uPick.uColorId,A,L,C,1),z(this.modelMatrix,this.modelRootMatrix,E.transform),z(this.mvpMatrix,h,this.modelMatrix),n.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let g of E.primitives)n.bindVertexArray(g.vao),n.drawElements(4,g.indexCount,g.indexType,0)}let d=new Uint8Array(4);n.readPixels(u,o,1,1,6408,5121,d),n.bindFramebuffer(36160,null);let m=d[0]+(d[1]<<8)+(d[2]<<16);m>0&&m<=this.meshes.length&&(c=[this.meshes[m-1]])}c.length===0&&(c=this.meshes.filter(d=>d.visible!==!1));let l=null,f=1/0,b=[0,0,0],p=[0,1,0],y=this.customTarget||this.bounds.center,T=y[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=y[1]+this.currDistance*Math.sin(this.currPhi),w=y[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let d of c){z(this.modelMatrix,this.modelRootMatrix,d.transform),z(this.mvpMatrix,h,this.modelMatrix);let m=H();if(!Me(m,this.mvpMatrix))continue;let F=(u+.5)/s*2-1,E=(o+.5)/a*2-1,x=[0,0,0],A=[0,0,0];ve(x,F,E,-1,m),ve(A,F,E,1,m);let L=A[0]-x[0],C=A[1]-x[1],g=A[2]-x[2],M=Math.hypot(L,C,g)||1,B=L/M,D=C/M,W=g/M,G={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((_=>{for(let X of d.primitives){if(!X.positions)continue;let N=X.positions,S=X.indices,k=Math.floor(S?S.length/3:N.length/9);for(let O=0;O<k;O++){let j=S?S[O*3]:O*3,K=S?S[O*3+1]:O*3+1,q=S?S[O*3+2]:O*3+2;Re(x[0],x[1],x[2],B,D,W,N[j*3],N[j*3+1],N[j*3+2],N[K*3],N[K*3+1],N[K*3+2],N[q*3],N[q*3+1],N[q*3+2],G,_)}}})(1e-4),isFinite(G.distance)){let _=G.point[0],X=G.point[1],N=G.point[2],S=this.modelMatrix,k=S[0]*_+S[4]*X+S[8]*N+S[12],O=S[1]*_+S[5]*X+S[9]*N+S[13],j=S[2]*_+S[6]*X+S[10]*N+S[14],K=k-T,q=O-R,ne=j-w,le=Math.hypot(K,q,ne);if(le<f){te(this.normalMatrix,this.modelMatrix);let U=this.normalMatrix,se=G.normal[0],oe=G.normal[1],ae=G.normal[2],$=U[0]*se+U[3]*oe+U[6]*ae,J=U[1]*se+U[4]*oe+U[7]*ae,Q=U[2]*se+U[5]*oe+U[8]*ae,ue=Math.hypot($,J,Q)||1;$/=ue,J/=ue,Q/=ue,$*K+J*q+Q*ne>0&&($=-$,J=-J,Q=-Q),l=d,f=Math.round(le*1e3)/1e3,b=[Math.round(k*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(j*1e3)/1e3],p=[Math.round($*1e3)/1e3,Math.round(J*1e3)/1e3,Math.round(Q*1e3)/1e3]}}}if(!l)return null;let v={meshIndex:this.meshes.indexOf(l),meshName:l.name,nodeIndex:l.nodeIndex,distance:f,hitPoint:b,normal:p,screenX:e,screenY:t};if(r){for(let d of V)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,h=(s+.5)/a*2-1;return Math.floor((h*.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);fe(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);pe(this.viewMatrix,[n,s,a],r,[0,1,0]),z(this.mvpMatrix,this.projMatrix,this.viewMatrix),te(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),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 V)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 V)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 V)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 V)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 h=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,o=u?[u.x,u.y,u.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:h,projMatrix:c,eyePos:o,viewport:n,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),d=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(v*.5)),F=Math.max(1,v-m),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),x=this.customTarget||this.bounds.center,A=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),L=x[1]+this.currDistance*Math.sin(this.currPhi),C=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=Math.cos(this.currTheta),M=-Math.sin(this.currTheta),B=.032,D=H(),W=H(),G=[A-g*B,L,C-M*B],ee=[x[0]-g*B*.25,x[1],x[2]-M*B*.25];fe(D,this.fov,m/d,.1,E),pe(W,G,ee,[0,1,0]);let _=H(),X=H(),N=[A+g*B,L,C+M*B],S=[x[0]+g*B*.25,x[1],x[2]+M*B*.25];fe(_,this.fov,F/d,.1,E),pe(X,N,S,[0,1,0]),this.render({viewMatrix:W,projMatrix:D,eyePos:G,viewport:[0,0,m,d],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:X,projMatrix:_,eyePos:N,viewport:[m,0,F,d],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,d);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 h=H(),c=e?.viewMatrix??this.viewMatrix;z(h,e?.projMatrix??this.projMatrix,c);let u=ie().xrDepthShader,o=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,l=this.customTarget||this.bounds.center,f=e?e.eyePos[0]:l[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),b=e?e.eyePos[1]:l[1]+this.currDistance*Math.sin(this.currPhi),p=e?e.eyePos[2]:l[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of V)v.onBeforeDrawScene?.(this,t,h,[f,b,p],o);let y=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&y===0)return;let T=e?.eye||"none",R=!1,w=y>0?[...this.backdropMeshes,...this.meshes]:this.meshes,P=v=>{for(let d=0;d<w.length;d++){let m=w[d];if(m.visible===!1)continue;let F=this.selectedMeshName!==""&&m.name===this.selectedMeshName;d<y||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):z(this.modelMatrix,this.modelRootMatrix,m.transform),z(this.mvpMatrix,h,this.modelMatrix),te(m.normalMatrix,this.modelMatrix);let E=m.extras?.xr?.stereo||m.userData?.xr?.stereo,x=0,A=0,L=1,C=1;E==="sbs"?(L=.5,x=T==="right"?.5:0):E==="ou"&&(C=.5,A=T==="right"?.5:0);for(let g of m.primitives){let M=!!g.isTransmissive;if(!v&&M){R=!0;continue}if(v&&!M)continue;let B=g.customProgram||this.renderProg,D=g.customUniforms||this.uRender;t.useProgram(B),t.uniform1i(D.uToneMapping,o),t.uniform1f(D.uEnvIntensity,this.envIntensity),t.uniform3f(D.uCameraPos,f,b,p),t.uniform1f(D.uEmissive,F?1:0),t.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(D.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(D.uNormalMatrix,!1,m.normalMatrix),D.uUvTransform&&t.uniform4f(D.uUvTransform,x,A,L,C),D.uViewportSize&&t.uniform2f(D.uViewportSize,Math.max(1,s),Math.max(1,a)),u?.bind(t,D,this.xrDepthState,c,[r,n,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(D.uEnvironmentMap,4),t.uniform1i(D.uHasEnvironmentMap,1)):t.uniform1i(D.uHasEnvironmentMap,0),this.bindLights(D),D.uSectionEnabled&&t.uniform1i(D.uSectionEnabled,0);for(let W of V)W.onBeforeDrawPrimitive?.(t,B,g,m,this.worldMatrices||[],this.gltf);t.uniform4fv(D.uBaseColor,g.baseColor),t.uniform1f(D.uMetallic,g.metallic),t.uniform1f(D.uRoughness,g.roughness),D.uClearcoat&&t.uniform2f(D.uClearcoat,g.clearcoat??0,g.clearcoatRoughness??.04),g.texture?(t.activeTexture(33984),t.bindTexture(3553,g.texture),t.uniform1i(D.uBaseColorTexture,0),t.uniform1i(D.uHasTexture,1)):t.uniform1i(D.uHasTexture,0),g.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,g.metallicRoughnessTexture),t.uniform1i(D.uMetallicRoughnessTexture,1),t.uniform1i(D.uHasMetallicRoughnessTexture,1)):t.uniform1i(D.uHasMetallicRoughnessTexture,0),g.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,g.normalTexture),t.uniform1i(D.uNormalTexture,2),t.uniform1i(D.uHasNormalTexture,1),t.uniform1f(D.uNormalScale,g.normalScale)):t.uniform1i(D.uHasNormalTexture,0),g.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,g.occlusionTexture),t.uniform1i(D.uOcclusionTexture,3),t.uniform1i(D.uHasOcclusionTexture,1),t.uniform1f(D.uOcclusionStrength,g.occlusionStrength)):t.uniform1i(D.uHasOcclusionTexture,0),t.bindVertexArray(g.vao),t.drawElements(4,g.indexCount,g.indexType,0)}}};if(P(!1),R){for(let v of V)v.onBeforeTransmissivePass?.(t,this);P(!0)}for(let v of V)v.onAfterRender?.(t,this,h)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let n of r.primitives){if(n.vao&&t.deleteVertexArray(n.vao),n.buffers)for(let s of n.buffers)t.deleteBuffer(s);n.texture&&t.deleteTexture(n.texture),n.metallicRoughnessTexture&&t.deleteTexture(n.metallicRoughnessTexture),n.normalTexture&&t.deleteTexture(n.normalTexture),n.occlusionTexture&&t.deleteTexture(n.occlusionTexture),n.customProgram&&t.deleteProgram(n.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of V)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()}};ce.registerPlugin=De,ce.getRegisteredPlugins=Ee;var tt=ce;export{ce as MicroViewer,et as SANDBOX_HOST_SCENE_LIMITS,ce as ThreeView,We as decodeUtf8,tt as default,he as getDecoder,Ee as getRegisteredPlugins,Oe as isGLBData,te as mat3NormalFromMat4,H as mat4Create,Te as mat4FromRotationTranslationScale,Me as mat4Invert,pe as mat4LookAt,z as mat4Multiply,fe as mat4Perspective,Se as parseGLB,Re as rayIntersectsTriangle,Qe as readFloat32Array,Xe as registerDecoder,De as registerPlugin,Pe as resolveNodeWorldMatrices,Ke as sanitizeTextureUri,we as toGLBData,ve as unprojectPoint};
232
+ void main(){fragColor=uColorId;}`;function Be(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 Pe(i,e,t){let r=Be(i,35633,e),n=Be(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 De(i,e,t){let r={};for(let n of t)r[n]=i.getUniformLocation(e,n);return r}var _e=["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 He(){let i=ce().xrDepthShader;return{fs:et.replace("/*XRD_U*/",i?.uniformsGLSL||"").replace("/*XRD_O*/",i?.occlusionGLSL||""),uniforms:i?[..._e,...i.uniformNames]:_e}}function nt(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 Ee(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 ct=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),We=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ke(i,e,t=We,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=e,s=he("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=Fe(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=nt(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]:O(),L=new Float32Array(9);oe(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,H=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??H?.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 W=(n.bufferViews[I.bufferView].byteOffset||0)+(I.byteOffset||0);return Je(a,W,V*$)},ee=X(j,3),U=X(H,4),N=X(Y,3),z=_?.type==="VEC4"?4:3,K=X(_,z),te=new Float32Array(V*16),ie=O();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],W=N?[N[I*3],N[I*3+1],N[I*3+2]]:[1,1,1];Re(ie,ue,$,W),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=he("draco");k&&k.decodePrimitive(n,A,a)}let j=[],H=i.createVertexArray();i.bindVertexArray(H);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],be=J[12+Q];for(let le=0;le<3;le++){let ve=J[le*4+Q]*Y.min[le],ge=J[le*4+Q]*Y.max[le];ne+=ve<ge?ve:ge,be+=ve>ge?ve:ge}ne<p[Q]&&(p[Q]=ne),be>b[Q]&&(b[Q]=be)}};if(x.instanceMatrices&&x.instanceMatrices.length>=16){let J=x.instanceMatrices.length>>4,Q=O();for(let ne=0;ne<J;ne++){let be=x.instanceMatrices.subarray(ne*16,ne*16+16);Z(Q,w,be),k(Q)}}else k(w)}let V=Ee(i,n,a,A.attributes.POSITION,0,3,j);Ee(i,n,a,A.attributes.NORMAL,1,3,j),Ee(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 q)if(k.onBuildPrimitiveVAO){let J=k.onBuildPrimitiveVAO(i,H,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=He(),te=Ue,ie=K.fs,I=!1;for(let k of q)if(k.onResolveShader){let J=k.onResolveShader(A,z,te,ie);J&&(te=J.vs,ie=J.fs,I=!0)}let $=I?Pe(i,te,ie):null,ue=$?De(i,$,K.uniforms):null,W=z?.pbrMetallicRoughness,me=W?.baseColorFactor||[.8,.8,.8,1],de=W?.metallicFactor??.1,fe=W?.roughnessFactor??.5,re=z?.extensions?.KHR_materials_clearcoat,se=re?re.clearcoatFactor??1:0,ae=Math.max(.04,re?.clearcoatRoughnessFactor??.04),pe=W?.baseColorTexture!==void 0&&m[W.baseColorTexture.index]?m[W.baseColorTexture.index]:null,Oe=W?.metallicRoughnessTexture!==void 0&&m[W.metallicRoughnessTexture.index]?m[W.metallicRoughnessTexture.index]:null,Xe=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,Ye=z?.occlusionTexture?.strength??1,Ke=!!(z?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive),Ae=A.extensions?.KHR_materials_variants?.mappings,$e=Array.isArray(Ae)?Ae.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:H,indexCount:X,indexType:ee,baseColor:me,metallic:de,roughness:fe,clearcoat:se,clearcoatRoughness:ae,positions:V,indices:U,texture:pe,metallicRoughnessTexture:Oe,normalTexture:Xe,occlusionTexture:je,normalScale:ze,occlusionStrength:Ye,buffers:j,materialIndex:A.material,defaultMaterialIndex:A.material,variantMappings:$e,pluginData:N,customProgram:$,customUniforms:ue,isTransmissive:Ke})}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 q)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 xe=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=O();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=O();this.viewMatrix=O();this.modelMatrix=O();this.mvpMatrix=O();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:O(),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=He();this.renderProg=Pe(u,Ue,l.fs),this.pickProg=Pe(u,tt,it),this.uRender=De(u,this.renderProg,l.uniforms),this.uPick=De(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){Ze(e,t)}static getDecoder(e){return he(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}=ke(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 q)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(Ve(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(Ne(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ne(e),{meshes:n}=ke(this.gl,r,We,()=>this.render());if(t)for(let s of n)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],oe(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),oe(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 q)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of q)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let 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 q)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,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=O();Z(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=O();Z(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),Z(this.modelMatrix,this.modelRootMatrix,C.transform);let w=C.instanceMatrices;if(w&&w.length>=16){let L=w.length>>4,x=O();for(let G of C.primitives){n.bindVertexArray(G.vao);for(let A=0;A<L;A++)Z(x,this.modelMatrix,w.subarray(A*16,A*16+16)),Z(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{Z(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=O();for(let d of l){Z(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?Z(this.modelMatrix,M,F.subarray(C*16,C*16+16)):this.modelMatrix.set(M),Z(this.mvpMatrix,u,this.modelMatrix);let S=O();if(!Ce(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];we(f,P,E,-1,S),we(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,H=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;Le(f[0],f[1],f[2],j,H,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){oe(this.normalMatrix,this.modelMatrix);let W=this.normalMatrix,me=_.normal[0],de=_.normal[1],fe=_.normal[2],re=W[0]*me+W[3]*de+W[6]*fe,se=W[1]*me+W[4]*de+W[7]*fe,ae=W[2]*me+W[5]*de+W[8]*fe,pe=Math.hypot(re,se,ae)||1;re/=pe,se/=pe,ae/=pe,re*ie+se*I+ae*$>0&&(re=-re,se=-se,ae=-ae),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(se*1e3)/1e3,Math.round(ae*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 q)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);ye(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);Te(this.viewMatrix,[n,s,a],r,[0,1,0]),Z(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(),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 q)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of q)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(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 q)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 q)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=O(),G=O(),A=[S-f*L,P,E-w*L],j=[C[0]-f*L*.25,C[1],C[2]-w*L*.25];ye(x,this.fov,d/v,.1,B),Te(G,A,j,[0,1,0]);let H=O(),Y=O(),_=[S+f*L,P,E+w*L],V=[C[0]+f*L*.25,C[1],C[2]+w*L*.25];ye(H,this.fov,F/v,.1,B),Te(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:H,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=O(),l=e?.viewMatrix??this.viewMatrix;Z(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 q)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):Z(this.modelMatrix,this.modelRootMatrix,d.transform),Z(this.mvpMatrix,u,this.modelMatrix),oe(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 q)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,H=O(),Y=new Float32Array(9),_=[f.baseColor[0],f.baseColor[1],f.baseColor[2],f.baseColor[3]];for(let V=0;V<A;V++)Z(H,this.modelMatrix,G.subarray(V*16,V*16+16)),Z(this.mvpMatrix,u,H),oe(Y,H),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,H),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 q)T.onBeforeTransmissivePass?.(t,this);M(!0)}for(let T of q)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 q)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};xe.registerPlugin=Ie,xe.getRegisteredPlugins=Se;var lt=xe;export{xe as MicroViewer,ct as SANDBOX_HOST_SCENE_LIMITS,xe as ThreeView,qe as decodeUtf8,lt as default,ut as evaluateToneMapping,he as getDecoder,Se as getRegisteredPlugins,Qe as isGLBData,oe as mat3NormalFromMat4,O as mat4Create,Re as mat4FromRotationTranslationScale,Ce as mat4Invert,Te as mat4LookAt,Z as mat4Multiply,ye as mat4Perspective,Ve as parseGLB,Le as rayIntersectsTriangle,Je as readFloat32Array,Ze as registerDecoder,Ie as registerPlugin,Fe as resolveNodeWorldMatrices,nt as sanitizeTextureUri,Ne as toGLBData,we as unprojectPoint};