three-live 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +6 -1
  2. package/dist/index.d.ts +66 -2
  3. package/dist/three-author-engine.js +85 -42
  4. package/dist/three-author.cjs +84 -42
  5. package/dist/three-author.d.ts +66 -2
  6. package/dist/three-author.js +84 -42
  7. package/dist/three-convert.cjs +84 -42
  8. package/dist/three-convert.d.ts +66 -2
  9. package/dist/three-convert.js +84 -42
  10. package/dist/three-live-animation.cjs +7 -7
  11. package/dist/three-live-animation.d.ts +66 -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} +66 -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 +48 -6
  19. package/dist/three-live-element.d.ts +66 -2
  20. package/dist/three-live-element.js +48 -6
  21. package/dist/three-live-full.cjs +176 -55
  22. package/dist/three-live-full.js +176 -55
  23. package/dist/three-live-full.min.js +176 -55
  24. package/dist/three-live-studio.cjs +120 -0
  25. package/dist/three-live-studio.d.ts +510 -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 +48 -6
  29. package/dist/three-live-viewer.d.ts +66 -2
  30. package/dist/three-live-viewer.js +48 -6
  31. package/dist/three-live-viewer.min.js +48 -6
  32. package/dist/three-live.cjs +86 -44
  33. package/dist/three-live.js +86 -44
  34. package/dist/three-live.min.js +86 -44
  35. package/dist/three-view.cjs +48 -6
  36. package/dist/three-view.d.ts +66 -2
  37. package/dist/three-view.js +48 -6
  38. package/dist/three-xr.cjs +83 -41
  39. package/dist/three-xr.d.ts +66 -2
  40. package/dist/three-xr.js +83 -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,16 +14,31 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- "use strict";var xe=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var $e=Object.prototype.hasOwnProperty;var qe=(i,e)=>{for(var t in e)xe(i,t,{get:e[t],enumerable:!0})},Ze=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ke(e))!$e.call(i,n)&&n!==t&&xe(i,n,{get:()=>e[n],enumerable:!(r=je(e,n))||r.enumerable});return i};var Je=i=>Ze(xe({},"__esModule",{value:!0}),i);var st={};qe(st,{MicroViewer:()=>se,SANDBOX_HOST_SCENE_LIMITS:()=>nt,ThreeView:()=>se,decodeUtf8:()=>Ie,default:()=>rt,getDecoder:()=>oe,getRegisteredPlugins:()=>Pe,isGLBData:()=>_e,mat3NormalFromMat4:()=>ee,mat4Create:()=>V,mat4FromRotationTranslationScale:()=>ge,mat4Invert:()=>ye,mat4LookAt:()=>me,mat4Multiply:()=>z,mat4Perspective:()=>le,parseGLB:()=>Le,rayIntersectsTriangle:()=>Te,readFloat32Array:()=>Qe,registerDecoder:()=>Be,registerPlugin:()=>Re,resolveNodeWorldMatrices:()=>Me,sanitizeTextureUri:()=>Ue,toGLBData:()=>Ee,unprojectPoint:()=>be});module.exports=Je(st);function V(){let i=new Float32Array(16);return i[0]=1,i[5]=1,i[10]=1,i[15]=1,i}function le(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 me(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 ge(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 ee(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 ye(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 be(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 Te(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,te=L*(r*D+n*W+s*G);if(te<-T||B+te>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 Me(i,e){let t=Array.isArray(i?.nodes)?i.nodes.length:0,r=[];for(let o=0;o<t;o++)r.push(V());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=V();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];ge(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 ve="__THREE_LIVE_REGISTRY__";function ie(){let i=typeof globalThis<"u"?globalThis:{};if(!i[ve]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(i,ve,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{i[ve]=e}}return i[ve]}var H=ie().plugins;function Re(i){let e=ie().plugins;e.some(t=>t.name===i.name)||e.push(i)}function Pe(){return ie().plugins}function Ie(i){return new TextDecoder().decode(i)}var Ne=ie().decoders;function Be(i,e){Ne.set(i.toLowerCase(),e)}function oe(i){return Ne.get(i.toLowerCase())}function Le(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=Ie(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")&&!oe("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(u.includes("EXT_meshopt_compression")&&!oe("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(u.includes("KHR_texture_basisu")&&!oe("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 H)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 _e(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 Ee(i){if(_e(i))return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return Le(i);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ke=`#version 300 es
17
+ "use strict";var Te=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(n,e)=>{for(var t in e)Te(n,t,{get:e[t],enumerable:!0})},nt=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Qe(e))!et.call(n,i)&&i!==t&&Te(n,i,{get:()=>e[i],enumerable:!(s=Je(e,i))||s.enumerable});return n};var it=n=>nt(Te({},"__esModule",{value:!0}),n);var pt={};tt(pt,{MicroViewer:()=>he,SANDBOX_HOST_SCENE_LIMITS:()=>mt,ThreeView:()=>he,decodeUtf8:()=>We,default:()=>ft,evaluateToneMapping:()=>at,getDecoder:()=>ce,getRegisteredPlugins:()=>De,isGLBData:()=>Xe,mat3NormalFromMat4:()=>oe,mat4Create:()=>X,mat4FromRotationTranslationScale:()=>ve,mat4Invert:()=>we,mat4LookAt:()=>de,mat4Multiply:()=>$,mat4Perspective:()=>me,normalizeToneMapping:()=>pe,parseGLB:()=>Ne,rayIntersectsTriangle:()=>Ee,readFloat32Array:()=>st,registerDecoder:()=>Oe,registerPlugin:()=>Ae,resolveNodeWorldMatrices:()=>Pe,sanitizeTextureUri:()=>Ye,toGLBData:()=>Ie,toneMappingShaderIndex:()=>Ue,unprojectPoint:()=>ge});module.exports=it(pt);var rt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Re(n,e,t,s){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let r=Number(t.count??0);if(!Number.isInteger(r)||r<=0)return null;let o=t.componentType??5126,c=rt[o];if(!c)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let a=c*s,l=i.byteStride&&i.byteStride>0?i.byteStride:a,u=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(u)||u<0||l<a||u+(r-1)*l+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&l===a&&u%4===0)return new Float32Array(e,u,r*s);let p=new DataView(e),m=t.normalized===!0,g=new Float32Array(r*s);for(let d=0;d<r;d++){let E=u+d*l;for(let b=0;b<s;b++){let x=E+b*c,R;switch(o){case 5126:R=p.getFloat32(x,!0);break;case 5120:R=p.getInt8(x),m&&(R=Math.max(R/127,-1));break;case 5121:R=p.getUint8(x),m&&(R/=255);break;case 5122:R=p.getInt16(x,!0),m&&(R=Math.max(R/32767,-1));break;case 5123:R=p.getUint16(x,!0),m&&(R/=65535);break;default:R=p.getUint32(x,!0),m&&(R/=4294967295)}g[d*s+b]=R}}return g}function Be(n,e){let t=Number(e.offset?.[0]??0)||0,s=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),r=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,c=Math.cos(o),a=Math.sin(o),l=(Number.isFinite(i)?i:1)*c,u=(Number.isFinite(i)?i:1)*a,p=-(Number.isFinite(r)?r:1)*a,m=(Number.isFinite(r)?r:1)*c;for(let g=0;g+1<n.length;g+=2){let d=n[g],E=n[g+1];n[g]=l*d+u*E+t,n[g+1]=p*d+m*E+s}}function X(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function me(n,e,t,s,i){let r=1/Math.tan(e/2);n.fill(0),n[0]=r/t,n[5]=r,n[11]=-1;let o=1/(s-i);return n[10]=(i+s)*o,n[14]=2*i*s*o,n}function de(n,e,t,s){let[i,r,o]=e,[c,a,l]=s,[u,p,m]=t,g=i-u,d=r-p,E=o-m,b=Math.hypot(g,d,E);b<=1e-5?(g=0,d=0,E=1):(g/=b,d/=b,E/=b);let x=a*E-l*d,R=l*g-c*E,y=c*d-a*g;b=Math.hypot(x,R,y),b<=1e-5?(x=0,R=0,y=0):(x/=b,R/=b,y/=b);let M=d*y-E*R,f=E*x-g*y,T=g*R-d*x;return b=Math.hypot(M,f,T),b<=1e-5?(M=0,f=0,T=0):(M/=b,f/=b,T/=b),n[0]=x,n[1]=M,n[2]=g,n[3]=0,n[4]=R,n[5]=f,n[6]=d,n[7]=0,n[8]=y,n[9]=T,n[10]=E,n[11]=0,n[12]=-(x*i+R*r+y*o),n[13]=-(M*i+f*r+T*o),n[14]=-(g*i+d*r+E*o),n[15]=1,n}function $(n,e,t){let s=e[0],i=e[1],r=e[2],o=e[3],c=e[4],a=e[5],l=e[6],u=e[7],p=e[8],m=e[9],g=e[10],d=e[11],E=e[12],b=e[13],x=e[14],R=e[15],y=t[0],M=t[1],f=t[2],T=t[3];return n[0]=y*s+M*c+f*p+T*E,n[1]=y*i+M*a+f*m+T*b,n[2]=y*r+M*l+f*g+T*x,n[3]=y*o+M*u+f*d+T*R,y=t[4],M=t[5],f=t[6],T=t[7],n[4]=y*s+M*c+f*p+T*E,n[5]=y*i+M*a+f*m+T*b,n[6]=y*r+M*l+f*g+T*x,n[7]=y*o+M*u+f*d+T*R,y=t[8],M=t[9],f=t[10],T=t[11],n[8]=y*s+M*c+f*p+T*E,n[9]=y*i+M*a+f*m+T*b,n[10]=y*r+M*l+f*g+T*x,n[11]=y*o+M*u+f*d+T*R,y=t[12],M=t[13],f=t[14],T=t[15],n[12]=y*s+M*c+f*p+T*E,n[13]=y*i+M*a+f*m+T*b,n[14]=y*r+M*l+f*g+T*x,n[15]=y*o+M*u+f*d+T*R,n}function ve(n,e,t,s){let i=e[0],r=e[1],o=e[2],c=e[3],a=i+i,l=r+r,u=o+o,p=i*a,m=i*l,g=i*u,d=r*l,E=r*u,b=o*u,x=c*a,R=c*l,y=c*u,M=s[0],f=s[1],T=s[2];return n[0]=(1-(d+b))*M,n[1]=(m+y)*M,n[2]=(g-R)*M,n[3]=0,n[4]=(m-y)*f,n[5]=(1-(p+b))*f,n[6]=(E+x)*f,n[7]=0,n[8]=(g+R)*T,n[9]=(E-x)*T,n[10]=(1-(p+d))*T,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function oe(n,e){let t=e[0],s=e[1],i=e[2],r=e[4],o=e[5],c=e[6],a=e[8],l=e[9],u=e[10],p=u*o-c*l,m=-u*r+c*a,g=l*r-o*a,d=t*p+s*m+i*g;return d&&(d=1/d,n[0]=p*d,n[1]=m*d,n[2]=g*d,n[3]=(-u*s+i*l)*d,n[4]=(u*t-i*a)*d,n[5]=(-l*t+s*a)*d,n[6]=(c*s-i*o)*d,n[7]=(-c*t+i*r)*d,n[8]=(o*t-s*r)*d),n}function we(n,e){let t=e[0],s=e[1],i=e[2],r=e[3],o=e[4],c=e[5],a=e[6],l=e[7],u=e[8],p=e[9],m=e[10],g=e[11],d=e[12],E=e[13],b=e[14],x=e[15],R=t*c-s*o,y=t*a-i*o,M=t*l-r*o,f=s*a-i*c,T=s*l-r*c,S=i*l-r*a,L=u*E-p*d,k=u*b-m*d,U=u*x-g*d,F=p*b-m*E,h=p*x-g*E,P=m*x-g*b,w=R*P-y*h+M*F+f*U-T*k+S*L;return w?(w=1/w,n[0]=(c*P-a*h+l*F)*w,n[1]=(i*h-s*P-r*F)*w,n[2]=(E*S-b*T+x*f)*w,n[3]=(m*T-p*S-g*f)*w,n[4]=(a*U-o*P-l*k)*w,n[5]=(t*P-i*U+r*k)*w,n[6]=(b*M-d*S-x*y)*w,n[7]=(u*S-m*M+g*y)*w,n[8]=(o*h-c*U+l*L)*w,n[9]=(s*U-t*h-r*L)*w,n[10]=(d*T-E*M+x*R)*w,n[11]=(p*M-u*T-g*R)*w,n[12]=(c*k-o*F-a*L)*w,n[13]=(t*F-s*k+i*L)*w,n[14]=(E*y-d*f-b*R)*w,n[15]=(u*f-p*y+m*R)*w,n):null}function ge(n,e,t,s,i){let r=i[0]*e+i[4]*t+i[8]*s+i[12],o=i[1]*e+i[5]*t+i[9]*s+i[13],c=i[2]*e+i[6]*t+i[10]*s+i[14],a=i[3]*e+i[7]*t+i[11]*s+i[15],l=a!==0?1/a:1;n[0]=r*l,n[1]=o*l,n[2]=c*l}function Ee(n,e,t,s,i,r,o,c,a,l,u,p,m,g,d,E,b=0){let x=l-o,R=u-c,y=p-a,M=m-o,f=g-c,T=d-a,S=i*T-r*f,L=r*M-s*T,k=s*f-i*M,U=x*S+R*L+y*k;if(U>-1e-7&&U<1e-7)return!1;let F=1/U,h=n-o,P=e-c,w=t-a,v=F*(h*S+P*L+w*k);if(v<-b||v>1+b)return!1;let B=P*y-w*R,D=w*x-h*y,K=h*R-P*x,A=F*(s*B+i*D+r*K);if(A<-b||v+A>1+b)return!1;let W=F*(M*B+f*D+T*K);if(W>1e-4&&W<E.distance){E.distance=W,E.point=[n+s*W,e+i*W,t+r*W];let _=R*T-y*f,q=y*M-x*T,Z=x*f-R*M,G=Math.hypot(_,q,Z)||1;return E.normal=[_/G,q/G,Z/G],!0}return!1}function Pe(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,s=[];for(let u=0;u<t;u++)s.push(X());if(t===0)return s;let i=new Set;for(let u of n.nodes)if(Array.isArray(u.children))for(let p of u.children)i.add(p);let r=new Set,o=128,c=(u,p,m=0)=>{if(m>o||u<0||u>=t||r.has(u))return;r.add(u);let g=n.nodes[u];if(!g)return;let d=X();if(e&&e[u])d.set(e[u]);else if(g.matrix&&g.matrix.length===16)d.set(g.matrix);else{let b=g.translation||[0,0,0],x=g.rotation||[0,0,0,1],R=g.scale||[1,1,1];ve(d,x,b,R)}let E=s[u];if(p?$(E,p,d):E.set(d),Array.isArray(g.children))for(let b of g.children)typeof b=="number"&&c(b,E,m+1)},a=[],l=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(l&&Array.isArray(l.nodes))a.push(...l.nodes);else for(let u=0;u<t;u++)i.has(u)||a.push(u);for(let u of a)c(u,null);for(let u=0;u<t;u++)!i.has(u)&&!a.includes(u)&&c(u,null);return s}var ye="__THREE_LIVE_REGISTRY__";function ue(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ye]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ye,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ye]=e}}return n[ye]}var Y=ue().plugins;function Ae(n){let e=ue().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function De(){return ue().plugins}var Ve=["neutral","reinhard","none","aces","agx"];function pe(n){let e=String(n??"").trim().toLowerCase();return Ve.includes(e)?e:"neutral"}function Ue(n){return Ve.indexOf(pe(n))}function We(n){return new TextDecoder().decode(n)}var He=ue().decoders;function Oe(n,e){He.set(n.toLowerCase(),e)}function ce(n){return He.get(n.toLowerCase())}function Ne(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let s=t.getUint32(0,!0);if(s!==1179937895){let m=t.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${s.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let r=t.getUint32(8,!0),o=12,c=null,a=null;for(;o+8<=r&&o+8<=e.byteLength;){let m=t.getUint32(o,!0),g=t.getUint32(o+4,!0),d=o+8;if(d+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+m} bytes, buffer has ${e.byteLength}`);if(g===1313821514){let E=new Uint8Array(e,d,m),b=We(E);c=JSON.parse(b,(x,R)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:R)}else g===5130562&&(a=e.slice(d,d+m));o=d+m}if(!c)throw new Error("Missing JSON chunk in GLB");let l=c.extensionsRequired||[];if(l.includes("KHR_draco_mesh_compression")&&!ce("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(l.includes(m)&&!ce("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!ce("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),p={gltf:c,bin:u,animations:[]};for(let m of Y)m.onParseGLB?.(p);return p}function st(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function Xe(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function Ie(n){if(Xe(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return Ne(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ze=`#version 300 es
18
18
  layout(location=0) in vec3 aPosition;
19
19
  layout(location=1) in vec3 aNormal;
20
20
  layout(location=2) in vec2 aUV;
21
21
  uniform mat4 uMVP,uModel;
22
22
  uniform mat3 uNormalMatrix;
23
23
  uniform vec4 uUvTransform;
24
+ layout(location=8) in vec4 aInst0;
25
+ layout(location=9) in vec4 aInst1;
26
+ layout(location=10) in vec4 aInst2;
27
+ layout(location=11) in vec4 aInst3;
28
+ layout(location=12) in vec4 aInstColor;
29
+ uniform int uInstanced;
30
+ uniform mat4 uViewProj;
31
+ out vec4 vInstTint;
32
+ mat4 xrModel(){return uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;}
33
+ mat4 xrMVP(){return uInstanced==1?uViewProj*xrModel():uMVP;}
34
+ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):uNormalMatrix;}
35
+ #define uModel xrModel()
36
+ #define uMVP xrMVP()
37
+ #define uNormalMatrix xrNormalMatrix()
24
38
  out vec3 vNormal,vWorldPos;
25
39
  out vec2 vUV;
26
40
  void main(){
41
+ vInstTint=uInstanced==1?aInstColor:vec4(1.0);
27
42
  vec3 rawN=uNormalMatrix*aNormal;
28
43
  vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
29
44
  vec4 world=uModel*vec4(aPosition,1.0);
@@ -32,12 +47,14 @@ vec2 scaleUV=uUvTransform.zw;
32
47
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
48
  vUV=aUV*scaleUV+uUvTransform.xy;
34
49
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,et=`#version 300 es
50
+ }`,ot=`#version 300 es
36
51
  precision highp float;
37
52
  in vec3 vNormal,vWorldPos;
38
53
  in vec2 vUV;
39
54
  uniform vec4 uBaseColor;
40
- uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
55
+ in vec4 vInstTint;
56
+ #define uBaseColor (uBaseColor*vInstTint)
57
+ uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
41
58
  uniform vec2 uClearcoat;
42
59
  uniform vec3 uCameraPos,uAmbientColor;
43
60
  uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
@@ -108,9 +125,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
108
125
  return mix(color,newPeak*vec3(1.0),g);
109
126
  }
110
127
 
128
+ vec3 acesToneMapping(vec3 color){
129
+ color*=0.6;
130
+ return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
131
+ }
132
+
133
+ vec3 agxToneMapping(vec3 color){
134
+ color=max(color,vec3(0.0));
135
+ vec3 inset=vec3(
136
+ 0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
137
+ 0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
138
+ 0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
139
+ vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
140
+ vec3 x2=ev*ev;
141
+ vec3 x4=x2*x2;
142
+ 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;
143
+ vec3 outset=vec3(
144
+ 1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
145
+ -0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
146
+ -0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
147
+ return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
148
+ }
149
+
111
150
  vec3 applyToneMapping(vec3 color,int mode){
112
151
  if(mode==0)return neutralToneMapping(color);
113
152
  if(mode==1)return color/(color+vec3(1.0));
153
+ if(mode==3)return acesToneMapping(color);
154
+ if(mode==4)return agxToneMapping(color);
114
155
  return color;
115
156
  }
116
157
 
@@ -194,15 +235,16 @@ if(uClearcoat.x>0.0){
194
235
  vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
195
236
  color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
196
237
  }
238
+ color*=uExposure;
197
239
  color=applyToneMapping(color,uToneMapping);
198
240
  float outAlpha=base.a;
199
241
  /*XRD_O*/
200
242
  fragColor=vec4(color,outAlpha);
201
- }`,tt=`#version 300 es
243
+ }`;function at(n,e,t=1){e=pe(e);let s=Number.isFinite(t)?Math.max(0,t):1,i=Math.max(0,(Number(n[0])||0)*s),r=Math.max(0,(Number(n[1])||0)*s),o=Math.max(0,(Number(n[2])||0)*s),c=x=>Math.max(0,Math.min(1,x));if(e==="none")return[c(i),c(r),c(o)];if(e==="reinhard")return[i/(i+1),r/(r+1),o/(o+1)];if(e==="aces"){let x=R=>{let y=R*.6;return c(y*(2.51*y+.03)/(y*(2.43*y+.59)+.14))};return[x(i),x(r),x(o)]}if(e==="agx"){let x=.84247906*i+.0784336*r+.07922375*o,R=.04232824*i+.87846864*r+.07916613*o,y=.04237565*i+.0784336*r+.87914297*o,M=F=>{let h=c((Math.log2(Math.max(F,1e-6))+12.47393)/16.5),P=h*h,w=P*P;return 15.5*w*P-40.14*w*h+31.96*w-6.868*P*h+.4298*P+.1191*h-.00232},f=M(x),T=M(R),S=M(y),L=1.196879*f-.09802088*T-.09902974*S,k=-.05289685*f+1.15190313*T-.09896118*S,U=-.05297164*f-.09804345*T+1.15107367*S;return[c(Math.pow(Math.max(L,0),2.2)),c(Math.pow(Math.max(k,0),2.2)),c(Math.max(0,Math.pow(Math.max(U,0),2.2)))]}let a=.76,l=.15,u=Math.min(i,r,o),p=u<.08?u-6.25*u*u:.04;i-=p,r-=p,o-=p;let m=Math.max(i,r,o);if(m<a)return[c(i),c(r),c(o)];let g=1-a,d=1-g*g/(m+g-a),E=d/m;i*=E,r*=E,o*=E;let b=1-1/(l*(m-d)+1);return[c(i+(d-i)*b),c(r+(d-r)*b),c(o+(d-o)*b)]}var ut=`#version 300 es
202
244
  layout(location=0) in vec3 aPosition;
203
245
  uniform mat4 uMVP;
204
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,it=`#version 300 es
246
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ct=`#version 300 es
205
247
  precision highp float;
206
248
  uniform vec4 uColorId;
207
249
  out vec4 fragColor;
208
- void main(){fragColor=uColorId;}`;function Ce(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 we(i,e,t){let r=Ce(i,35633,e),n=Ce(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 Ae(i,e,t){let r={};for(let n of t)r[n]=i.getUniformLocation(e,n);return r}var Fe=["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 Ge(){let i=ie().xrDepthShader;return{fs:et.replace("/*XRD_U*/",i?.uniformsGLSL||"").replace("/*XRD_O*/",i?.occlusionGLSL||""),uniforms:i?[...Fe,...i.uniformNames]:Fe}}function Ue(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 De(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 nt=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ve=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Se(i,e,t=Ve,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n,bin:s}=e,a=[],h=Me(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=Ue(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]:V(),C=new Float32Array(9);ee(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=oe("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 fe=L[Z*4+I]*W.min[Z],pe=L[Z*4+I]*W.max[Z];Y+=fe<pe?fe:pe,re+=fe>pe?fe:pe}Y<f[I]&&(f[I]=Y),re>b[I]&&(b[I]=re)}let te=De(i,n,s,M.attributes.POSITION,0,3,B);De(i,n,s,M.attributes.NORMAL,1,3,B),De(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 H)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=Ge(),j=ke,K=O.fs,q=!1;for(let I of H)if(I.onResolveShader){let Y=I.onResolveShader(M,k,j,K);Y&&(j=Y.vs,K=Y.fs,q=!0)}let ne=q?we(i,j,K):null,de=ne?Ae(i,ne,O.uniforms):null,U=k?.pbrMetallicRoughness,ae=U?.baseColorFactor||[.8,.8,.8,1],ue=U?.metallicFactor??.1,ce=U?.roughnessFactor??.5,$=k?.extensions?.KHR_materials_clearcoat,J=$?$.clearcoatFactor??1:0,Q=Math.max(.04,$?.clearcoatRoughnessFactor??.04),he=U?.baseColorTexture!==void 0&&l[U.baseColorTexture.index]?l[U.baseColorTexture.index]:null,He=U?.metallicRoughnessTexture!==void 0&&l[U.metallicRoughnessTexture.index]?l[U.metallicRoughnessTexture.index]:null,We=k?.normalTexture!==void 0&&l[k.normalTexture.index]?l[k.normalTexture.index]:null,Xe=k?.normalTexture?.scale??1,Oe=k?.occlusionTexture!==void 0&&l[k.occlusionTexture.index]?l[k.occlusionTexture.index]:null,ze=k?.occlusionTexture?.strength??1,Ye=!!(k?.extensions?.KHR_materials_transmission||S.materials?.isTransmissive);g.primitives.push({vao:D,indexCount:_,indexType:X,baseColor:ae,metallic:ue,roughness:ce,clearcoat:J,clearcoatRoughness:Q,positions:te,indices:N,texture:he,metallicRoughnessTexture:He,normalTexture:We,occlusionTexture:Oe,normalScale:Xe,occlusionStrength:ze,buffers:B,materialIndex:M.material,pluginData:S,customProgram:ne,customUniforms:de,isTransmissive:Ye})}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 H)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 se=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=V();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=V();this.viewMatrix=V();this.modelMatrix=V();this.mvpMatrix=V();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:V(),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=Ge();this.renderProg=we(h,ke,c.fs),this.pickProg=we(h,tt,it),this.uRender=Ae(h,this.renderProg,c.uniforms),this.uPick=Ae(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){Be(e,t)}static getDecoder(e){return oe(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}=Se(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 H)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(Le(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(Ee(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ee(e),{meshes:n}=Se(this.gl,r,Ve,()=>this.render());if(t)for(let s of n)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],ee(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),ee(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 H)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of H)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 H)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=V();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=V();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=V();if(!ye(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];be(x,F,E,-1,m),be(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;Te(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,de=Math.hypot(K,q,ne);if(de<f){ee(this.normalMatrix,this.modelMatrix);let U=this.normalMatrix,ae=G.normal[0],ue=G.normal[1],ce=G.normal[2],$=U[0]*ae+U[3]*ue+U[6]*ce,J=U[1]*ae+U[4]*ue+U[7]*ce,Q=U[2]*ae+U[5]*ue+U[8]*ce,he=Math.hypot($,J,Q)||1;$/=he,J/=he,Q/=he,$*K+J*q+Q*ne>0&&($=-$,J=-J,Q=-Q),l=d,f=Math.round(de*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 H)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);le(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);me(this.viewMatrix,[n,s,a],r,[0,1,0]),z(this.mvpMatrix,this.projMatrix,this.viewMatrix),ee(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 H)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 H)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 H)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 H)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=V(),W=V(),G=[A-g*B,L,C-M*B],te=[x[0]-g*B*.25,x[1],x[2]-M*B*.25];le(D,this.fov,m/d,.1,E),me(W,G,te,[0,1,0]);let _=V(),X=V(),N=[A+g*B,L,C+M*B],S=[x[0]+g*B*.25,x[1],x[2]+M*B*.25];le(_,this.fov,F/d,.1,E),me(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=V(),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 H)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),ee(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 H)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 H)v.onBeforeTransmissivePass?.(t,this);P(!0)}for(let v of H)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 H)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()}};se.registerPlugin=Re,se.getRegisteredPlugins=Pe;var rt=se;
250
+ void main(){fragColor=uColorId;}`;function Ge(n,e,t){let s=n.createShader(e);if(n.shaderSource(s,t),n.compileShader(s),!n.getShaderParameter(s,35713)){let i=n.getShaderInfoLog(s);throw n.deleteShader(s),new Error(`Shader compile error: ${i}`)}return s}function Fe(n,e,t){let s=Ge(n,35633,e),i=Ge(n,35632,t),r=n.createProgram();if(n.attachShader(r,s),n.attachShader(r,i),n.linkProgram(r),!n.getProgramParameter(r,35714)){let o=n.getProgramInfoLog(r);throw n.deleteProgram(r),new Error(`Program link error: ${o}`)}return r}function Se(n,e,t){let s={};for(let i of t)s[i]=n.getUniformLocation(e,i);return s}var ke=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function je(){let n=ue().xrDepthShader;return{fs:ot.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...ke,...n.uniformNames]:ke}}function Ye(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Le(n,e,t,s,i,r,o,c){if(s===void 0||!e.accessors?.[s])return null;let a=Re(e,t,e.accessors[s],r);if(!a)return null;c&&(a=a.slice(),Be(a,c));let l=n.createBuffer();return o.push(l),n.bindBuffer(34962,l),n.bufferData(34962,a,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,r,5126,!1,0,0),a}function Ce(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function $e(n,e,t){let s=je(),i=ze,r=s.fs,o=!1;for(let a of Y)if(a.onResolveShader){let l=a.onResolveShader(e,t,i,r);l&&(i=l.vs,r=l.fs,o=!0)}let c=o?Fe(n,i,r):null;return{program:c,uniforms:c?Se(n,c,s.uniforms):null}}function lt(n,e,t){let s=e.instanceMatrices;if(!s||s.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=s.length>>4,r=e.instanceColors,o=new Float32Array(i*20);for(let a=0;a<i;a++)o.set(s.subarray(a*16,a*16+16),a*20),o[a*20+16]=r?r[a*3]:1,o[a*20+17]=r?r[a*3+1]:1,o[a*20+18]=r?r[a*3+2]:1,o[a*20+19]=1;let c=n.createBuffer();t.push(c),n.bindBuffer(34962,c),n.bufferData(34962,o,35044);for(let a=0;a<5;a++)n.enableVertexAttribArray(8+a),n.vertexAttribPointer(8+a,4,5126,!1,80,a*16),n.vertexAttribDivisor(8+a,1);return!0}function ht(n,e){let t=n.materials?.[e?.material];if(!t)return null;let s=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of s){let r=i?.extensions?.KHR_texture_transform;if(r&&typeof r=="object")return r}return null}var mt=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ke=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Me(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function qe(n,e){let t=n?.pbrMetallicRoughness,s=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,r=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:s?[s[0],s[1],s[2],s[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:r(t?.baseColorTexture),metallicRoughnessTexture:r(t?.metallicRoughnessTexture),normalTexture:r(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:r(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ze(n,e,t){let s=new Set,i=r=>{r&&!s.has(r)&&(s.add(r),n.deleteTexture(r))};for(let r of e)for(let o of r.primitives){if(o.vao&&n.deleteVertexArray(o.vao),o.buffers)for(let a of o.buffers)n.deleteBuffer(a);i(o.texture),i(o.metallicRoughnessTexture),i(o.normalTexture),i(o.occlusionTexture);let c=new Set;o.customProgram&&c.add(o.customProgram);for(let a of o.programCache?.values()??[])a.program&&c.add(a.program);for(let a of c)n.deleteProgram(a)}if(t)for(let r of t)i(r)}function _e(n,e,t=Ke,s){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return dt(n,e,t,s,i)}catch(r){let o=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Ze(n,o,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let c of i.buffers)n.deleteBuffer(c);throw r}}function dt(n,e,t,s,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r}=e,o=ce("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(r,e);let c=e.bin,a=[];i.meshes=a;let l=[],u=r.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((h,P)=>{l.push(typeof h?.name=="string"&&h.name?h.name:`Variant_${P}`)});let p=Pe(r),m=[];if(Array.isArray(r.nodes))for(let h=0;h<r.nodes.length;h++){let P=r.nodes[h];P.mesh!==void 0&&r.meshes&&r.meshes[P.mesh]&&m.push({node:P,nodeIdx:h,meshIdx:P.mesh})}let g=m.length>0?m:(r.meshes||[]).map((h,P)=>({node:h,nodeIdx:-1,meshIdx:P})),d=[];if(Array.isArray(e.lights)&&e.lights.length>0)d.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let h=r.extensions.KHR_lights_punctual.lights;for(let P of h){let w=P.type==="directional"?"directional":P.type==="point"?"point":"ambient";d.push({type:w,color:P.color||[1,1,1],intensity:P.intensity!==void 0?P.intensity:1})}}if(d.length===0&&(d.push({type:"ambient",color:[1,1,1],intensity:.35}),d.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),g.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${g.length}`);let E=[];if(i.gpuTextures=E,r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let h=0;h<r.textures.length;h++){let P=r.textures[h],w=r.images[P.source];if(w){let v=n.createTexture();if(n.bindTexture(3553,v),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),w.bufferView!==void 0){let B=r.bufferViews[w.bufferView],D=c.slice(B.byteOffset||0,(B.byteOffset||0)+B.byteLength),K=new Blob([D],{type:w.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(K).then(A=>{n.bindTexture(3553,v),n.texImage2D(3553,0,6408,6408,5121,A),n.generateMipmap(3553),s?.()}).catch(()=>{})}else if(w.uri){let B=Ye(w.uri);if(B){let D=new Image;D.crossOrigin="anonymous",D.referrerPolicy="no-referrer",D.onload=()=>{n.bindTexture(3553,v),n.texImage2D(3553,0,6408,6408,5121,D),n.generateMipmap(3553),s?.()},D.src=B}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",w.uri)}E.push(v)}else E.push(null)}}let b=[1/0,1/0,1/0],x=[-1/0,-1/0,-1/0],R=0,y=0;for(let h=0;h<g.length;h++){let P=g[h],w=r.meshes[P.meshIdx],v=P.nodeIdx>=0?p[P.nodeIdx]:X(),B=new Float32Array(9);oe(B,v);let D={name:P.node.name||w.name||`Mesh_${P.meshIdx}`,nodeIndex:P.nodeIdx,transform:v,normalMatrix:B,primitives:[],extras:P.node.extras||w.extras};i.mesh=D;let K=P.node?.extensions?.EXT_mesh_gpu_instancing;if(K&&K.attributes&&typeof K.attributes=="object"){let A=K.attributes,W=A.TRANSLATION!==void 0?r.accessors?.[A.TRANSLATION]:null,_=A.ROTATION!==void 0?r.accessors?.[A.ROTATION]:null,q=A.SCALE!==void 0?r.accessors?.[A.SCALE]:null,Z=A._COLOR_0!==void 0?r.accessors?.[A._COLOR_0]:null,G=Number(W?.count??_?.count??q?.count??0);if(!Number.isFinite(G)||G<0||G>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${G}`);if(G>0){let z=(N,O)=>{if(!N||N.bufferView===void 0||!r.bufferViews?.[N.bufferView])return null;let te=N.componentType??5126,re=j=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${j})`),null);if(te!==5120&&te!==5121&&te!==5122&&te!==5123&&te!==5126)return re(`componentType ${te}`);if(!(Number(N.count)>=G))return re(`count ${N.count} < ${G}`);let C=null;try{C=Re(r,c,{...N,count:G},O)}catch{return re("out of bounds")}return!C||!C.every(Number.isFinite)?re("non-finite value"):C},I=z(W,3),ne=z(_,4),H=z(q,3),Q=Z?.type==="VEC4"?4:3,ee=z(Z,Q),ie=new Float32Array(G*16),ae=X();for(let N=0;N<G;N++){let O=I?[I[N*3],I[N*3+1],I[N*3+2]]:[0,0,0],te=ne?[ne[N*4],ne[N*4+1],ne[N*4+2],ne[N*4+3]]:[0,0,0,1],re=H?[H[N*3],H[N*3+1],H[N*3+2]]:[1,1,1];ve(ae,te,O,re),ie.set(ae,N*16)}if(D.instanceMatrices=ie,ee){let N=new Float32Array(G*3);for(let O=0;O<G;O++)N[O*3]=ee[O*Q],N[O*3+1]=ee[O*Q+1],N[O*3+2]=ee[O*Q+2];D.instanceColors=N}}}for(let A of w.primitives||[]){if(A.extensions?.KHR_draco_mesh_compression){let C=ce("draco");C&&C.decodePrimitive(r,A,c)}let W=[],_=n.createVertexArray();i.vao=_,i.buffers=W,n.bindVertexArray(_);let q=lt(n,D,W),Z=r.accessors[A.attributes.POSITION],G=Number(Z?.count??0);if(!Number.isFinite(G)||G<0||R+G>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(R+=G,Z?.min&&Z?.max){let C=j=>{for(let V=0;V<3;V++){let J=j[12+V],se=j[12+V];for(let le=0;le<3;le++){let be=j[le*4+V]*Z.min[le],xe=j[le*4+V]*Z.max[le];J+=be<xe?be:xe,se+=be>xe?be:xe}J<b[V]&&(b[V]=J),se>x[V]&&(x[V]=se)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let j=D.instanceMatrices.length>>4,V=X();for(let J=0;J<j;J++){let se=D.instanceMatrices.subarray(J*16,J*16+16);$(V,v,se),C(V)}}else C(v)}let z=Le(n,r,c,A.attributes.POSITION,0,3,W);Le(n,r,c,A.attributes.NORMAL,1,3,W),Le(n,r,c,A.attributes.TEXCOORD_0,2,2,W,ht(r,A));let I=0,ne=5123,H=null;if(A.indices!==void 0){let C=r.accessors[A.indices],V=(r.bufferViews[C.bufferView].byteOffset||0)+(C.byteOffset||0);if(I=Number(C.count??0),!Number.isFinite(I)||I<0||y+I>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);y+=I,ne=C.componentType===5125?5125||5125:5123||5123;let J=n.createBuffer();W.push(J),n.bindBuffer(34963,J),C.componentType===5125?(H=new Uint32Array(c,V,C.count),n.bufferData(34963,H,35044)):C.componentType===5121?(H=Uint16Array.from(new Uint8Array(c,V,C.count)),n.bufferData(34963,H,35044)):(H=V%2===0?new Uint16Array(c,V,C.count):new Uint16Array(c.slice(V,V+C.count*2)),n.bufferData(34963,H,35044))}else I=Z.count;let Q={};for(let C of Y)if(C.onBuildPrimitiveVAO){let j=C.onBuildPrimitiveVAO(n,_,A,r,c);j&&(Q[C.name]=j)}n.bindVertexArray(null);let ee=r.materials&&A.material!==void 0?r.materials[A.material]:null,{program:ie,uniforms:ae}=$e(n,A,ee),N=qe(ee,E),O=!!(ee?.extensions?.KHR_materials_transmission||Q.materials?.isTransmissive),te=A.extensions?.KHR_materials_variants?.mappings,re=Array.isArray(te)?te.filter(C=>C&&typeof C.material=="number"&&Array.isArray(C.variants)).map(C=>({material:C.material|0,variants:C.variants.map(j=>Number(j)|0)})):void 0;D.primitives.push({vao:_,instanced:q,indexCount:I,indexType:ne,...N,positions:z,indices:H,buffers:W,materialIndex:A.material,defaultMaterialIndex:A.material,variantMappings:re,primitiveDef:A,programCache:new Map([[A.material??-1,{program:ie,uniforms:ae}]]),pluginData:Q,customProgram:ie,customUniforms:ae,isTransmissive:O})}a.push(D)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(x[0])||(x=[1,1,1]);let M=[(b[0]+x[0])/2,(b[1]+x[1])/2,(b[2]+x[2])/2],f=x[0]-b[0],T=x[1]-b[1],S=x[2]-b[2],L=Math.max(Math.hypot(f,T,S)/2,.5),k=[b[0],b[1],b[2]],U=[x[0],x[1],x[2]],F=e.animations;if(!F){for(let h of Y)if(h.onParseGLB?.(e),e.animations){F=e.animations;break}}return F||(F=[]),{meshes:a,bounds:{center:M,radius:L,min:k,max:U},lights:d,animations:F,worldMatrices:p,gpuTextures:E,availableVariants:l}}function fe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var he=class{constructor(e,t,s){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=X();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=X();this.viewMatrix=X();this.activeViewMatrix=null;this.modelMatrix=X();this.mvpMatrix=X();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:X(),rawValueToMeters:.001,format:0};this.container=e;let i,r;if(t&&typeof t.getContext=="function"?(i=t,r=s):(r=t,i=r?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=r||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Ce(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=pe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let c=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!c)throw new Error("WebGL2 not supported");this.gl=c,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Oe(e,t)}static getDecoder(e){return ce(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=je();this.renderProg=Fe(e,ze,t.fs),this.pickProg=Fe(e,ut,ct),this.uRender=Se(e,this.renderProg,t.uniforms),this.uPick=Se(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of Y)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),s=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=s,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,s,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,s),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let s=this.gl,i=Math.max(1,e),r=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=r,s.bindTexture(3553,this.pickTexture),s.texImage2D(3553,0,6408,i,r,0,6408,5121,null),s.bindRenderbuffer(36161,this.pickDepth),s.renderbufferStorage(36161,33189,i,r)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:s,bounds:i,lights:r,animations:o,worldMatrices:c,gpuTextures:a,availableVariants:l}=_e(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=s,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=r,this.animations=o||[],this.worldMatrices=c||[],this.gpuTextures=a||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of Y)m.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=Ce(u));let p=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;p!==void 0&&(this.envIntensity=Math.max(0,Number(p)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Ne(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Ie(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let s=Ie(e),{meshes:i}=_e(this.gl,s,Ke,()=>this.render());if(t)for(let r of i)r.transform[12]+=t[0],r.transform[13]+=t[1],r.transform[14]+=t[2],oe(r.normalMatrix,r.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,s,i=1){this.clearColor=[e,t,s,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let s=this.meshes[t],i;e instanceof Map?i=e.get(s.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,s.name)?i=e[s.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(s.transform.set(i),oe(s.normalMatrix,s.transform))}}bindLights(e=this.uRender){let t=this.gl,s=[.28,.28,.28],i=[],r=[],o=[],c=[];for(let a of this.lights){let l=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")s=[l[0]*u,l[1]*u,l[2]*u];else if(a.type==="directional"&&i.length<6){let p=a.direction||[.5,1,.8];i.push(p[0],p[1],p[2]),r.push(l[0]*u,l[1]*u,l[2]*u)}else if(a.type==="point"&&o.length<6){let p=a.position||[0,0,0];o.push(p[0],p[1],p[2]),c.push(l[0]*u,l[1]*u,l[2]*u)}}i.length===0&&(i.push(.5,1,.8),r.push(1,1,1)),t.uniform3fv(e.uAmbientColor,s),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,r)),t.uniform1i(e.uNumPointLights,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,c)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Ce(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=pe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Y)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Y)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,s=this.currDistance;return{theta:e,phi:t,radius:s,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${s.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,s)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(p=>p.materialIndex===s||e.length===1&&p.materialIndex===void 0)),r=i[0],o=r?[...r.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],c=r?r.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=r?r.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:o,metallicFactor:c,roughnessFactor:a,setBaseColorFactor:u=>{let p=[u[0],u[1],u[2],u[3]??1];l.baseColorFactor=p,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=p);for(let m of i)m.baseColor=p;this.render()},setMetallicFactor:u=>{l.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let p of i)p.metallic=u;this.render()},setRoughnessFactor:u=>{l.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let p of i)p.roughness=u;this.render()}};return{name:t.name||`Material_${s}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(s=>s.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",s=-1;if(t)this.activeVariantName=null;else{if(s=this.availableVariants.indexOf(e),s<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let r of this.meshes)for(let o of r.primitives){let c=o.defaultMaterialIndex;if(!t&&Array.isArray(o.variantMappings)){for(let l of o.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(s)){c=l.material;break}}let a=c!==void 0?i[c]:void 0;o.materialIndex=a?c:void 0,Object.assign(o,qe(a,this.gpuTextures)),this.applyPrimitiveProgram(o,o.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,s){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,r=e.programCache.get(i);r||(r=$e(this.gl,{...e.primitiveDef,material:t},s),e.programCache.set(i,r)),e.customProgram=r.program,e.customUniforms=r.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of Y)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,s){this.customTarget=[e,t,s],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,s=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(s,e))}setCamera(e,t,s,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),s!==void 0&&s>0&&(this.targetDistance=this.clampDistance(s)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,s,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),s!==void 0&&s>0){let r=this.clampDistance(s);this.initialDistance=r,this.customDistance=!0,this.targetDistance=r,this.currDistance=r}else if(i!==void 0&&i>0){let r=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=r,this.customDistance=!0,this.targetDistance=r,this.currDistance=r}else{this.customDistance=!1;let r=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=r,this.targetDistance=r,this.currDistance=r}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let s=X();$(s,this.projMatrix,this.viewMatrix);let[i,r,o]=e,c=t?t[0]:0,a=t?t[1]:0,l=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],r=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],o=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(c=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],a=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],l=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let p=s[0]*i+s[4]*r+s[8]*o+s[12],m=s[1]*i+s[5]*r+s[9]*o+s[13],g=s[2]*i+s[6]*r+s[10]*o+s[14],d=s[3]*i+s[7]*r+s[11]*o+s[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=p/d,b=m/d,x=g/d,R=this.canvas.getBoundingClientRect(),y=R.width||this.canvas.clientWidth||this.canvas.width||300,M=R.height||this.canvas.clientHeight||this.canvas.height||150,f=(E*.5+.5)*y,T=(-b*.5+.5)*M,S=E>=-1.1&&E<=1.1&&b>=-1.1&&b<=1.1&&x>=-1&&x<=1;if(S&&t){let[L,k,U]=fe(this),F=[i-L,r-k,o-U];c*F[0]+a*F[1]+l*F[2]>.05&&(S=!1)}return{x:f,y:T,z:x,visible:S}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let s=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-s.x,r=t.clientY-s.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,r),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],c=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],l=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*o[0]+r*c[0])*l,a[1]+=(-i*o[1]+r*c[1])*l,a[2]+=(-i*o[2]+r*c[2])*l,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+r*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let s=e.getBoundingClientRect(),i=Math.floor((t.clientX-s.left)*(e.width/Math.max(s.width,1))),r=Math.floor((t.clientY-s.top)*(e.height/Math.max(s.height,1)));this.performMeshPick(i,r,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let s=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*s)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let s=t.detail||{};s.reset?this.resetCamera():this.setCamera(s.theta,s.phi,s.distance,s.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let s=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=s,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=s,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=s,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=s,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=s,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=s,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=s,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let s=this.canvas,i=s.getBoundingClientRect(),r=s.width||300,o=s.height||300,c=i.width>0?Math.floor((e-i.left)*(r/i.width)):Math.floor(e),a=i.height>0?Math.floor((t-i.top)*(o/i.height)):Math.floor(t);return this.performMeshPick(c,a,!1)}performMeshPick(e,t,s=!0){if(this.meshes.length===0)return null;let i=this.gl,r=Math.max(1,this.canvas.width||300),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,r);let c=X();$(c,this.projMatrix,this.viewMatrix);let a=[],l=Math.max(0,Math.min(r-1,e)),u=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==r||this.pickFboHeight!==o)&&this.resizePickingFbo(r,o),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,r,o),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let S=0;S<this.meshes.length;S++){let L=this.meshes[S];if(L.visible===!1||L.isPluginMesh)continue;let k=S+1,U=(k&255)/255,F=(k>>8&255)/255,h=(k>>16&255)/255;i.uniform4f(this.uPick.uColorId,U,F,h,1),$(this.modelMatrix,this.modelRootMatrix,L.transform);let P=L.instanceMatrices;if(P&&P.length>=16){let w=P.length>>4,v=X();for(let B of L.primitives){i.bindVertexArray(B.vao);for(let D=0;D<w;D++)$(v,this.modelMatrix,P.subarray(D*16,D*16+16)),$(this.mvpMatrix,c,v),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Me(i,B)}}else{$(this.mvpMatrix,c,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let w of L.primitives)i.bindVertexArray(w.vao),Me(i,w)}}let f=new Uint8Array(4);i.readPixels(l,u,1,1,6408,5121,f),i.bindFramebuffer(36160,null);let T=f[0]+(f[1]<<8)+(f[2]<<16);T>0&&T<=this.meshes.length&&(a=[this.meshes[T-1]])}a.length===0&&(a=this.meshes.filter(f=>f.visible!==!1));let p=null,m=1/0,g=[0,0,0],d=[0,1,0],[E,b,x]=fe(this),R=X();for(let f of a){$(R,this.modelRootMatrix,f.transform);let T=f.instanceMatrices,S=T&&T.length>=16?T.length>>4:1;for(let L=0;L<S;L++){T&&T.length>=16?$(this.modelMatrix,R,T.subarray(L*16,L*16+16)):this.modelMatrix.set(R),$(this.mvpMatrix,c,this.modelMatrix);let k=X();if(!we(k,this.mvpMatrix))continue;let U=(l+.5)/r*2-1,F=(u+.5)/o*2-1,h=[0,0,0],P=[0,0,0];ge(h,U,F,-1,k),ge(P,U,F,1,k);let w=P[0]-h[0],v=P[1]-h[1],B=P[2]-h[2],D=Math.hypot(w,v,B)||1,K=w/D,A=v/D,W=B/D,_={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Z=>{for(let G of f.primitives){if(!G.positions)continue;let z=G.positions,I=G.indices,ne=Math.floor(I?I.length/3:z.length/9);for(let H=0;H<ne;H++){let Q=I?I[H*3]:H*3,ee=I?I[H*3+1]:H*3+1,ie=I?I[H*3+2]:H*3+2;Ee(h[0],h[1],h[2],K,A,W,z[Q*3],z[Q*3+1],z[Q*3+2],z[ee*3],z[ee*3+1],z[ee*3+2],z[ie*3],z[ie*3+1],z[ie*3+2],_,Z)}}})(1e-4),isFinite(_.distance)){let Z=_.point[0],G=_.point[1],z=_.point[2],I=this.modelMatrix,ne=I[0]*Z+I[4]*G+I[8]*z+I[12],H=I[1]*Z+I[5]*G+I[9]*z+I[13],Q=I[2]*Z+I[6]*G+I[10]*z+I[14],ee=ne-E,ie=H-b,ae=Q-x,N=Math.hypot(ee,ie,ae);if(N<m){oe(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,te=_.normal[0],re=_.normal[1],C=_.normal[2],j=O[0]*te+O[3]*re+O[6]*C,V=O[1]*te+O[4]*re+O[7]*C,J=O[2]*te+O[5]*re+O[8]*C,se=Math.hypot(j,V,J)||1;j/=se,V/=se,J/=se,j*ee+V*ie+J*ae>0&&(j=-j,V=-V,J=-J),p=f,m=Math.round(N*1e3)/1e3,g=[Math.round(ne*1e3)/1e3,Math.round(H*1e3)/1e3,Math.round(Q*1e3)/1e3],d=[Math.round(j*1e3)/1e3,Math.round(V*1e3)/1e3,Math.round(J*1e3)/1e3]}}}}if(!p)return null;let M={meshIndex:this.meshes.indexOf(p),meshName:p.name,nodeIndex:p.nodeIndex,distance:m,hitPoint:g,normal:d,screenX:e,screenY:t};if(s){for(let f of Y)f.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let s=Math.max(1,Math.floor(t*.5)),i=e>=s,r=i?e-s:e,o=i?Math.max(1,t-s):s,c=(r+.5)/o*2-1;return Math.floor((c*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);me(this.projMatrix,this.fov,e,.1,t);let s=this.customTarget||this.bounds.center;de(this.viewMatrix,fe(this),s,[0,1,0]),$(this.mvpMatrix,this.projMatrix,this.viewMatrix),oe(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),s=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==s||this.canvas.height!==i?(this.canvas.width=s,this.canvas.height=i,this.resizePickingFbo(s,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let s of Y)s.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(s){this.reportRenderError(s)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of Y)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let s=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(s),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),s=this.bounds.center[0],i=this.bounds.center[2],r=this.modelRootMatrix;r[0]=e,r[1]=0,r[2]=-t,r[3]=0,r[4]=0,r[5]=1,r[6]=0,r[7]=0,r[8]=t,r[9]=0,r[10]=e,r[11]=0,r[12]=s-(e*s+t*i),r[13]=0,r[14]=i-(-t*s+e*i),r[15]=1}setVisible(e){this.isVisible=e}update(e){for(let o of Y)o.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let o of Y)o.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let s=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),r=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(s-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(r-this.lastReportedZoom)>=.02){this.lastReportedTheta=s,this.lastReportedPhi=i,this.lastReportedZoom=r;let o={theta:s,phi:i,zoom:r,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,s,i,r=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let c=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,u=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):s&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:c,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:r})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let y=Math.max(2,this.canvas.width||2),M=Math.max(1,this.canvas.height||1),f=Math.max(1,Math.floor(y*.5)),T=Math.max(1,y-f),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[k,U,F]=fe(this),h=Math.cos(this.currTheta),P=-Math.sin(this.currTheta),w=.032,v=X(),B=X(),D=[k-h*w,U,F-P*w],K=[L[0]-h*w*.25,L[1],L[2]-P*w*.25];me(v,this.fov,f/M,.1,S),de(B,D,K,[0,1,0]);let A=X(),W=X(),_=[k+h*w,U,F+P*w],q=[L[0]+h*w*.25,L[1],L[2]+P*w*.25];me(A,this.fov,T/M,.1,S),de(W,_,q,[0,1,0]),this.render({viewMatrix:B,projMatrix:v,eyePos:D,viewport:[0,0,f,M],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:W,projMatrix:A,eyePos:_,viewport:[f,0,T,M],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,y,M);return}let t=this.gl,s=0,i=0,r=this.canvas.width,o=this.canvas.height;e?.viewport?(s=e.viewport[0],i=e.viewport[1],r=e.viewport[2],o=e.viewport[3],t.viewport(s,i,r,o)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let c=X(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,$(c,e?.projMatrix??this.projMatrix,a);let l=ue().xrDepthShader,u=Ue(this.toneMapping),[p,m,g]=e?e.eyePos:fe(this);for(let y of Y)y.onBeforeDrawScene?.(this,t,c,[p,m,g],u);let d=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&d===0)return;let E=e?.eye||"none",b=!1,x=d>0?[...this.backdropMeshes,...this.meshes]:this.meshes,R=y=>{for(let M=0;M<x.length;M++){let f=x[M];if(f.visible===!1)continue;let T=this.selectedMeshName!==""&&f.name===this.selectedMeshName;M<d||f.worldSpace===!0||f.name==="__xr_reticle__"?this.modelMatrix.set(f.transform):$(this.modelMatrix,this.modelRootMatrix,f.transform),$(this.mvpMatrix,c,this.modelMatrix),oe(f.normalMatrix,this.modelMatrix);let S=f.extras?.xr?.stereo||f.userData?.xr?.stereo,L=0,k=0,U=1,F=1;S==="sbs"?(U=.5,L=E==="right"?.5:0):S==="ou"&&(F=.5,k=E==="right"?.5:0);for(let h of f.primitives){let P=!!h.isTransmissive;if(!y&&P){b=!0;continue}if(y&&!P)continue;let w=h.customProgram||this.renderProg,v=h.customUniforms||this.uRender;t.useProgram(w),t.uniform1i(v.uToneMapping,u),t.uniform1f(v.uEnvIntensity,this.envIntensity),v.uExposure&&t.uniform1f(v.uExposure,this.exposure),t.uniform3f(v.uCameraPos,p,m,g),t.uniform1f(v.uEmissive,T?1:0),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(v.uNormalMatrix,!1,f.normalMatrix),v.uUvTransform&&t.uniform4f(v.uUvTransform,L,k,U,F),v.uViewportSize&&t.uniform2f(v.uViewportSize,Math.max(1,r),Math.max(1,o)),l?.bind(t,v,this.xrDepthState,a,[s,i,Math.max(1,r),Math.max(1,o)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(v.uEnvironmentMap,4),t.uniform1i(v.uHasEnvironmentMap,1)):t.uniform1i(v.uHasEnvironmentMap,0),this.bindLights(v),v.uSectionEnabled&&t.uniform1i(v.uSectionEnabled,0);for(let D of Y)D.onBeforeDrawPrimitive?.(t,w,h,f,this.worldMatrices||[],this.gltf);t.uniform4fv(v.uBaseColor,h.baseColor),t.uniform1f(v.uMetallic,h.metallic),t.uniform1f(v.uRoughness,h.roughness),v.uClearcoat&&t.uniform2f(v.uClearcoat,h.clearcoat??0,h.clearcoatRoughness??.04),h.texture?(t.activeTexture(33984),t.bindTexture(3553,h.texture),t.uniform1i(v.uBaseColorTexture,0),t.uniform1i(v.uHasTexture,1)):t.uniform1i(v.uHasTexture,0),h.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,h.metallicRoughnessTexture),t.uniform1i(v.uMetallicRoughnessTexture,1),t.uniform1i(v.uHasMetallicRoughnessTexture,1)):t.uniform1i(v.uHasMetallicRoughnessTexture,0),h.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,h.normalTexture),t.uniform1i(v.uNormalTexture,2),t.uniform1i(v.uHasNormalTexture,1),t.uniform1f(v.uNormalScale,h.normalScale)):t.uniform1i(v.uHasNormalTexture,0),h.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,h.occlusionTexture),t.uniform1i(v.uOcclusionTexture,3),t.uniform1i(v.uHasOcclusionTexture,1),t.uniform1f(v.uOcclusionStrength,h.occlusionStrength)):t.uniform1i(v.uHasOcclusionTexture,0),t.bindVertexArray(h.vao);let B=f.instanceMatrices;if(B&&B.length>=16&&h.instanced&&v.uInstanced&&v.uViewProj){let D=B.length>>4;t.uniform1i(v.uInstanced,1),t.uniformMatrix4fv(v.uViewProj,!1,c),h.indices?t.drawElementsInstanced(4,h.indexCount,h.indexType,0,D):t.drawArraysInstanced(4,0,h.indexCount,D),t.uniform1i(v.uInstanced,0)}else if(B&&B.length>=16){let D=B.length>>4,K=f.instanceColors,A=X(),W=new Float32Array(9),_=[h.baseColor[0],h.baseColor[1],h.baseColor[2],h.baseColor[3]];for(let q=0;q<D;q++)$(A,this.modelMatrix,B.subarray(q*16,q*16+16)),$(this.mvpMatrix,c,A),oe(W,A),t.uniformMatrix4fv(v.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(v.uModel,!1,A),t.uniformMatrix3fv(v.uNormalMatrix,!1,W),K&&(_[0]=h.baseColor[0]*K[q*3],_[1]=h.baseColor[1]*K[q*3+1],_[2]=h.baseColor[2]*K[q*3+2],_[3]=h.baseColor[3],t.uniform4fv(v.uBaseColor,_)),Me(t,h)}else Me(t,h)}}};if(R(!1),b){for(let y of Y)y.onBeforeTransmissivePass?.(t,this);R(!0)}for(let y of Y)y.onAfterRender?.(t,this,c)}disposeMeshListGpuResources(e,t){Ze(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Y)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};he.registerPlugin=Ae,he.getRegisteredPlugins=De;var ft=he;
@@ -48,6 +48,30 @@ import type {
48
48
  } from './xr-live/src/xr-live-element';
49
49
 
50
50
  export * from './three-live/src/core';
51
+ export {
52
+ cadPlugin,
53
+ installCadExtension,
54
+ MAX_BSP_DEPTH,
55
+ MAX_CSG_TRIANGLES,
56
+ MAX_SHAPE_POINTS,
57
+ MAX_TEXT_GEOMETRY_CHARS,
58
+ type ExtrudeGeometryOptions,
59
+ type TextGeometryOptions,
60
+ } from './three-live/src/plugins/cad';
61
+ export {
62
+ ikPlugin,
63
+ IKSolver,
64
+ quatFromUnitVectors,
65
+ solveFABRIK,
66
+ solveTwoBoneIK,
67
+ type FABRIKSolution,
68
+ type IKQuat,
69
+ type TwoBoneIKSolution,
70
+ } from './three-live/src/plugins/ik';
71
+ export {
72
+ extractNodeInstancing,
73
+ instancingPlugin,
74
+ } from './three-live/src/plugins/instancing';
51
75
  export {
52
76
  getInteractivityVM,
53
77
  interactivityPlugin,
@@ -63,6 +87,30 @@ export {
63
87
  type InteractivityValueSocket,
64
88
  type InteractivityVariableDef,
65
89
  } from './three-live/src/plugins/interactivity';
90
+ export {
91
+ applyMeshoptFilter,
92
+ decodeMeshoptBuffer,
93
+ decodeMeshoptGLB,
94
+ encodeMeshoptBuffer,
95
+ meshoptDecoder,
96
+ meshoptPlugin,
97
+ type MeshoptFilter,
98
+ type MeshoptMode,
99
+ } from './three-live/src/plugins/meshopt';
100
+ export {
101
+ computeOutlineClipOffset,
102
+ evaluateKawaseBloom,
103
+ parseHexRgb,
104
+ postprocessingPlugin,
105
+ resolveViewerBloom,
106
+ } from './three-live/src/plugins/postprocessing';
107
+ export {
108
+ extractMaterialVariants,
109
+ extractPrimitiveVariantMappings,
110
+ selectMaterialVariant,
111
+ variantsPlugin,
112
+ type VariantMapping,
113
+ } from './three-live/src/plugins/variants';
66
114
  export {
67
115
  ThreeLiveElement,
68
116
  type ARLaunchOptions,
@@ -80,7 +128,7 @@ export {
80
128
  type XRProfile,
81
129
  type XRSimulatorRoom,
82
130
  } from './xr-live/src/xr-live-element';
83
- /** Optional spatial plugins (`xr-live/plugins`, `xr-live-plugins.min.js`). */
131
+ /** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
84
132
  export * from './xr-live/src/plugins/index';
85
133
 
86
134
  /**
@@ -119,7 +167,7 @@ export interface ThreeLiveAttributes {
119
167
  'shadow-intensity'?: number | string;
120
168
  /** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
121
169
  'shadow-softness'?: number | string;
122
- /** Tone mapping mode ("neutral", "reinhard", "none"). */
170
+ /** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
123
171
  'tone-mapping'?: string;
124
172
  /** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
125
173
  'camera-controls'?: boolean | string;
@@ -127,6 +175,8 @@ export interface ThreeLiveAttributes {
127
175
  'autoplay'?: boolean | string;
128
176
  /** Name of specific glTF animation clip to play. */
129
177
  'animation-name'?: string;
178
+ /** Name of the active KHR_materials_variants material variant. */
179
+ 'variant-name'?: string;
130
180
  /** Automatically rotate scene around the Y-axis when user is idle. */
131
181
  'auto-rotate'?: boolean | string;
132
182
  /** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
@@ -162,6 +212,7 @@ export interface ThreeLiveAttributes {
162
212
  onerror?: (e: CustomEvent<{error: any}>) => void;
163
213
  onmeshclick?: (e: CustomEvent<HitDetail>) => void;
164
214
  'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
215
+ 'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
165
216
  'onar-status'?: (
166
217
  e: CustomEvent<{
167
218
  status: 'session-started' | 'not-presenting' | 'failed';
@@ -248,6 +299,8 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
248
299
  'peer-name'?: string;
249
300
  /** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
250
301
  'peer-color'?: string;
302
+ /** Opt-in WebRTC voice signaling relay (offer/answer/ICE) and `voiceGain` helpers in `shared-room`. Apps own `RTCPeerConnection` and audio. */
303
+ 'shared-room-voice'?: boolean | string;
251
304
  /** xr-live-sim: character camera mode, or `none` to disable the character. */
252
305
  'character-controller'?:
253
306
  | 'third-person'
@@ -363,6 +416,17 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
363
416
  onpeergrabconflict?: (
364
417
  e: CustomEvent<{peerId: string; nodeId: string}>,
365
418
  ) => void;
419
+ onpeerrtcsignal?: (
420
+ e: CustomEvent<{
421
+ peerId: string;
422
+ targetPeerId: string;
423
+ signalType: 'offer' | 'answer' | 'ice';
424
+ sdp: string | null;
425
+ candidate: string | null;
426
+ sdpMid: string | null;
427
+ sdpMLineIndex: number | null;
428
+ }>,
429
+ ) => void;
366
430
  /** xr-live-sim events. */
367
431
  oncharacterjump?: (
368
432
  e: CustomEvent<{nodeId: string; position: [number, number, number]}>,