three-live 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +37 -0
  3. package/dist/three-author-engine.js +112 -61
  4. package/dist/three-author.cjs +110 -59
  5. package/dist/three-author.d.ts +37 -0
  6. package/dist/three-author.js +109 -58
  7. package/dist/three-convert.cjs +106 -59
  8. package/dist/three-convert.d.ts +37 -0
  9. package/dist/three-convert.js +105 -58
  10. package/dist/three-live-animation.cjs +8 -9
  11. package/dist/three-live-animation.d.ts +37 -0
  12. package/dist/three-live-animation.js +7 -8
  13. package/dist/three-live-animation.min.js +6 -7
  14. package/dist/three-live-cad.cjs +3 -4
  15. package/dist/three-live-cad.d.ts +37 -0
  16. package/dist/three-live-cad.js +2 -3
  17. package/dist/three-live-cad.min.js +3 -4
  18. package/dist/three-live-cli.js +231 -0
  19. package/dist/three-live-element.cjs +17 -20
  20. package/dist/three-live-element.d.ts +37 -0
  21. package/dist/three-live-element.js +16 -19
  22. package/dist/three-live-full.cjs +138 -87
  23. package/dist/three-live-full.js +137 -86
  24. package/dist/three-live-full.min.js +138 -87
  25. package/dist/three-live-studio.cjs +19 -20
  26. package/dist/three-live-studio.d.ts +37 -0
  27. package/dist/three-live-studio.js +18 -19
  28. package/dist/three-live-studio.min.js +18 -19
  29. package/dist/three-live-viewer.cjs +17 -20
  30. package/dist/three-live-viewer.d.ts +37 -0
  31. package/dist/three-live-viewer.js +16 -19
  32. package/dist/three-live-viewer.min.js +17 -20
  33. package/dist/three-live.cjs +115 -64
  34. package/dist/three-live.js +113 -62
  35. package/dist/three-live.min.js +115 -64
  36. package/dist/three-view.cjs +17 -20
  37. package/dist/three-view.d.ts +37 -0
  38. package/dist/three-view.js +16 -19
  39. package/dist/three-xr.cjs +105 -58
  40. package/dist/three-xr.d.ts +37 -0
  41. package/dist/three-xr.js +104 -57
  42. package/package.json +25 -1
@@ -13,14 +13,13 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */
17
- var xe="__THREE_LIVE_REGISTRY__";function ce(){let e=typeof globalThis<"u"?globalThis:{};if(!e[xe]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,xe,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[xe]=t}}return e[xe]}var Vn=ce().plugins;function Z(e){let t=ce().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function Qe(){return ce().plugins}function le(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ue(e,t,n){let r=t[0],o=t[1],a=t[2],l=t[3],u=t[4],i=t[5],c=t[6],s=t[7],d=t[8],f=t[9],b=t[10],p=t[11],m=t[12],x=t[13],E=t[14],I=t[15],v=n[0],S=n[1],w=n[2],U=n[3];return e[0]=v*r+S*u+w*d+U*m,e[1]=v*o+S*i+w*f+U*x,e[2]=v*a+S*c+w*b+U*E,e[3]=v*l+S*s+w*p+U*I,v=n[4],S=n[5],w=n[6],U=n[7],e[4]=v*r+S*u+w*d+U*m,e[5]=v*o+S*i+w*f+U*x,e[6]=v*a+S*c+w*b+U*E,e[7]=v*l+S*s+w*p+U*I,v=n[8],S=n[9],w=n[10],U=n[11],e[8]=v*r+S*u+w*d+U*m,e[9]=v*o+S*i+w*f+U*x,e[10]=v*a+S*c+w*b+U*E,e[11]=v*l+S*s+w*p+U*I,v=n[12],S=n[13],w=n[14],U=n[15],e[12]=v*r+S*u+w*d+U*m,e[13]=v*o+S*i+w*f+U*x,e[14]=v*a+S*c+w*b+U*E,e[15]=v*l+S*s+w*p+U*I,e}function Ht(e,t,n,r){let o=t[0],a=t[1],l=t[2],u=t[3],i=o+o,c=a+a,s=l+l,d=o*i,f=o*c,b=o*s,p=a*c,m=a*s,x=l*s,E=u*i,I=u*c,v=u*s,S=r[0],w=r[1],U=r[2];return e[0]=(1-(p+x))*S,e[1]=(f+v)*S,e[2]=(b-I)*S,e[3]=0,e[4]=(f-v)*w,e[5]=(1-(d+x))*w,e[6]=(m+E)*w,e[7]=0,e[8]=(b+I)*U,e[9]=(m-E)*U,e[10]=(1-(d+p))*U,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function fe(e,t,n=0){let r=t[0],o=t[1],a=t[2],l=t[4],u=t[5],i=t[6],c=t[8],s=t[9],d=t[10],f=d*u-i*s,b=-d*l+i*c,p=s*l-u*c,m=r*f+o*b+a*p;return!m||n>0&&(!Number.isFinite(m)||Math.abs(m)<=n)||(m=1/m,e[0]=f*m,e[1]=b*m,e[2]=p*m,e[3]=(-d*o+a*s)*m,e[4]=(d*r-a*c)*m,e[5]=(-s*r+o*c)*m,e[6]=(i*o-a*u)*m,e[7]=(-i*r+a*l)*m,e[8]=(u*r-o*l)*m),e}function Ze(e,t){let n=t[0],r=t[1],o=t[2],a=t[3],l=t[4],u=t[5],i=t[6],c=t[7],s=t[8],d=t[9],f=t[10],b=t[11],p=t[12],m=t[13],x=t[14],E=t[15],I=n*u-r*l,v=n*i-o*l,S=n*c-a*l,w=r*i-o*u,U=r*c-a*u,V=o*c-a*i,O=s*m-d*p,N=s*x-f*p,P=s*E-b*p,C=d*x-f*m,z=d*E-b*m,W=f*E-b*x,B=I*W-v*z+S*C+w*P-U*N+V*O;return B?(B=1/B,e[0]=(u*W-i*z+c*C)*B,e[1]=(o*z-r*W-a*C)*B,e[2]=(m*V-x*U+E*w)*B,e[3]=(f*U-d*V-b*w)*B,e[4]=(i*P-l*W-c*N)*B,e[5]=(n*W-o*P+a*N)*B,e[6]=(x*S-p*V-E*v)*B,e[7]=(s*V-f*S+b*v)*B,e[8]=(l*z-u*P+c*O)*B,e[9]=(r*P-n*z-a*O)*B,e[10]=(p*U-m*S+E*I)*B,e[11]=(d*S-s*U-b*I)*B,e[12]=(u*N-l*C-i*O)*B,e[13]=(n*C-r*N+o*O)*B,e[14]=(m*v-p*w-x*I)*B,e[15]=(s*w-d*v+f*I)*B,e):null}function Pe(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let s=0;s<n;s++)r.push(le());if(n===0)return r;let o=new Set;for(let s of e.nodes)if(Array.isArray(s.children))for(let d of s.children)o.add(d);let a=new Set,l=128,u=(s,d,f=0)=>{if(f>l||s<0||s>=n||a.has(s))return;a.add(s);let b=e.nodes[s];if(!b)return;let p=le();if(t&&t[s])p.set(t[s]);else if(b.matrix&&b.matrix.length===16)p.set(b.matrix);else{let x=b.translation||[0,0,0],E=b.rotation||[0,0,0,1],I=b.scale||[1,1,1];Ht(p,E,x,I)}let m=r[s];if(d?ue(m,d,p):m.set(p),Array.isArray(b.children))for(let x of b.children)typeof x=="number"&&u(x,m,f+1)},i=[],c=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(c&&Array.isArray(c.nodes))i.push(...c.nodes);else for(let s=0;s<n;s++)o.has(s)||i.push(s);for(let s of i)u(s,null);for(let s=0;s<n;s++)!o.has(s)&&!i.includes(s)&&u(s,null);return r}var Ce=new WeakMap;function Oe(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Ce.set(e,n)}function Wt(e){return Ce.get(e)}async function Xt(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let a=await(await fetch(t)).blob();n=await createImageBitmap(a)}else if(typeof Image<"u")n=await new Promise((o,a)=>{let l=new Image;l.crossOrigin="anonymous",l.onload=()=>o(l),l.onerror=a,l.src=t});else return null;else n=t;let r=e.createTexture();return e.bindTexture(3553,r),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),r}var Ne=new WeakMap,Je=new Float32Array(16);async function et(e,t,n){let r=n?await Xt(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=r}var tt={name:"environment-map",onContextRestored(e){Ne.delete(e)},setEnvironmentImage(e,t){return et(e,"environmentTexture",t)},setSkyboxImage(e,t){return et(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,r,o){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let a=Ne.get(t);if(!a){let d=(p,m)=>{let x=t.createShader(p);return t.shaderSource(x,m),t.compileShader(x),x},f=t.createProgram();t.attachShader(f,d(35633,`#version 300 es
18
- out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(f,d(35632,`#version 300 es
19
- precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(f);let b=typeof t.createVertexArray=="function"?t.createVertexArray():null;a={program:f,vao:b},Ne.set(t,a)}let l=Ze(Je,n)||Je;t.depthMask(!1),t.useProgram(a.program),a.vao&&t.bindVertexArray(a.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let u=t.getUniformLocation(a.program,"uSkyboxMap");u&&t.uniform1i(u,0);let i=t.getUniformLocation(a.program,"uInvVP");i&&t.uniformMatrix4fv(i,!1,l);let c=t.getUniformLocation(a.program,"uCameraPos");c&&t.uniform3f(c,r[0],r[1],r[2]);let s=t.getUniformLocation(a.program,"uExposure");s&&t.uniform1f(s,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,r){if(r.includes("evalSHIrradiance"))return null;let o=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
16
+ */var Ve="__THREE_LIVE_REGISTRY__";function ye(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Ve]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Ve,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Ve]=t}}return e[Ve]}var ei=ye().plugins;function er(e){let t=ye();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function ue(e){let t=ye().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function tr(){return ye().plugins}function Te(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Se(e,t,r){let i=t[0],n=t[1],s=t[2],m=t[3],c=t[4],o=t[5],d=t[6],a=t[7],u=t[8],l=t[9],h=t[10],f=t[11],g=t[12],A=t[13],v=t[14],S=t[15],p=r[0],b=r[1],y=r[2],L=r[3];return e[0]=p*i+b*c+y*u+L*g,e[1]=p*n+b*o+y*l+L*A,e[2]=p*s+b*d+y*h+L*v,e[3]=p*m+b*a+y*f+L*S,p=r[4],b=r[5],y=r[6],L=r[7],e[4]=p*i+b*c+y*u+L*g,e[5]=p*n+b*o+y*l+L*A,e[6]=p*s+b*d+y*h+L*v,e[7]=p*m+b*a+y*f+L*S,p=r[8],b=r[9],y=r[10],L=r[11],e[8]=p*i+b*c+y*u+L*g,e[9]=p*n+b*o+y*l+L*A,e[10]=p*s+b*d+y*h+L*v,e[11]=p*m+b*a+y*f+L*S,p=r[12],b=r[13],y=r[14],L=r[15],e[12]=p*i+b*c+y*u+L*g,e[13]=p*n+b*o+y*l+L*A,e[14]=p*s+b*d+y*h+L*v,e[15]=p*m+b*a+y*f+L*S,e}function rr(e,t,r,i){let n=t[0],s=t[1],m=t[2],c=t[3],o=n+n,d=s+s,a=m+m,u=n*o,l=n*d,h=n*a,f=s*d,g=s*a,A=m*a,v=c*o,S=c*d,p=c*a,b=i[0],y=i[1],L=i[2];return e[0]=(1-(f+A))*b,e[1]=(l+p)*b,e[2]=(h-S)*b,e[3]=0,e[4]=(l-p)*y,e[5]=(1-(u+A))*y,e[6]=(g+v)*y,e[7]=0,e[8]=(h+S)*L,e[9]=(g-v)*L,e[10]=(1-(u+f))*L,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function Re(e,t,r=0){let i=t[0],n=t[1],s=t[2],m=t[4],c=t[5],o=t[6],d=t[8],a=t[9],u=t[10],l=u*c-o*a,h=-u*m+o*d,f=a*m-c*d,g=i*l+n*h+s*f;return!g||r>0&&(!Number.isFinite(g)||Math.abs(g)<=r)||(g=1/g,e[0]=l*g,e[1]=h*g,e[2]=f*g,e[3]=(-u*n+s*a)*g,e[4]=(u*i-s*d)*g,e[5]=(-a*i+n*d)*g,e[6]=(o*n-s*c)*g,e[7]=(-o*i+s*m)*g,e[8]=(c*i-n*m)*g),e}function ir(e,t){let r=t[0],i=t[1],n=t[2],s=t[3],m=t[4],c=t[5],o=t[6],d=t[7],a=t[8],u=t[9],l=t[10],h=t[11],f=t[12],g=t[13],A=t[14],v=t[15],S=r*c-i*m,p=r*o-n*m,b=r*d-s*m,y=i*o-n*c,L=i*d-s*c,C=n*d-s*o,F=a*g-u*f,_=a*A-l*f,U=a*v-h*f,D=u*A-l*g,$=u*v-h*g,z=l*v-h*A,O=S*z-p*$+b*D+y*U-L*_+C*F;return O?(O=1/O,e[0]=(c*z-o*$+d*D)*O,e[1]=(n*$-i*z-s*D)*O,e[2]=(g*C-A*L+v*y)*O,e[3]=(l*L-u*C-h*y)*O,e[4]=(o*U-m*z-d*_)*O,e[5]=(r*z-n*U+s*_)*O,e[6]=(A*b-f*C-v*p)*O,e[7]=(a*C-l*b+h*p)*O,e[8]=(m*$-c*U+d*F)*O,e[9]=(i*U-r*$-s*F)*O,e[10]=(f*L-g*b+v*S)*O,e[11]=(u*b-a*L-h*S)*O,e[12]=(c*_-m*D-o*F)*O,e[13]=(r*D-i*_+n*F)*O,e[14]=(g*p-f*y-A*S)*O,e[15]=(a*y-u*p+l*S)*O,e):null}function at(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let a=0;a<r;a++)i.push(Te());if(r===0)return i;let n=new Set;for(let a of e.nodes)if(Array.isArray(a.children))for(let u of a.children)n.add(u);let s=new Set,m=128,c=(a,u,l=0)=>{if(l>m||a<0||a>=r||s.has(a))return;s.add(a);let h=e.nodes[a];if(!h)return;let f=Te();if(t&&t[a])f.set(t[a]);else if(h.matrix&&h.matrix.length===16)f.set(h.matrix);else{let A=h.translation||[0,0,0],v=h.rotation||[0,0,0,1],S=h.scale||[1,1,1];rr(f,v,A,S)}let g=i[a];if(u?Se(g,u,f):g.set(f),Array.isArray(h.children))for(let A of h.children)typeof A=="number"&&c(A,g,l+1)},o=[],d=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(d&&Array.isArray(d.nodes))o.push(...d.nodes);else for(let a=0;a<r;a++)n.has(a)||o.push(a);for(let a of o)c(a,null);for(let a=0;a<r;a++)!n.has(a)&&!o.includes(a)&&c(a,null);return i}var ze=new WeakMap;function ot(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);ze.set(e,r)}function nr(e){return ze.get(e)}async function ar(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let n=await(await fetch(t)).blob();r=await createImageBitmap(n)}else if(typeof Image<"u")r=await new Promise((n,s)=>{let m=new Image;m.crossOrigin="anonymous",m.onload=()=>n(m),m.onerror=s,m.src=t});else return null;else r=t;let i=e.createTexture();return e.bindTexture(3553,i),e.texImage2D(3553,0,6408,6408,5121,r),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),i}var Ge=new WeakMap,lt=new Float32Array(16);async function st(e,t,r){let i=r?await ar(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var ut={name:"environment-map",onContextRestored(e){Ge.delete(e)},setEnvironmentImage(e,t){return st(e,"environmentTexture",t)},setSkyboxImage(e,t){return st(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,n){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=Ge.get(t);if(!s){let u=(f,g)=>{let A=t.createShader(f);return t.shaderSource(A,g),t.compileShader(A),A},l=t.createProgram();t.attachShader(l,u(35633,`#version 300 es
17
+ out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(l,u(35632,`#version 300 es
18
+ precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(l);let h=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:l,vao:h},Ge.set(t,s)}let m=ir(lt,r)||lt;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let c=t.getUniformLocation(s.program,"uSkyboxMap");c&&t.uniform1i(c,0);let o=t.getUniformLocation(s.program,"uInvVP");o&&t.uniformMatrix4fv(o,!1,m);let d=t.getUniformLocation(s.program,"uCameraPos");d&&t.uniform3f(d,i[0],i[1],i[2]);let a=t.getUniformLocation(s.program,"uExposure");a&&t.uniform1f(a,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let n=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
20
19
  uniform int uHasSH;
21
20
  out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
22
21
  vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
23
- void main(){`);return o=o.replace(`if(uHasEnvironmentMap==1){
22
+ void main(){`);return n=n.replace(`if(uHasEnvironmentMap==1){
24
23
  specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
25
24
  envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
26
25
  }`,`if(uHasEnvironmentMap==1){
@@ -29,15 +28,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
29
28
  }else if(uHasSH==1){
30
29
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
31
30
  envDiffuse=evalSHIrradiance(N);
32
- }`),{vs:n,fs:o}},onBeforeDrawPrimitive(e,t,n,r,o,a){let l=Ce.get(e),u=e.getUniformLocation(t,"uHasSH");if(l&&l.length>=27){u&&e.uniform1i(u,1);let i=e.getUniformLocation(t,"uSH");i&&e.uniform3fv(i,l)}else u&&e.uniform1i(u,0)},onAttributeChanged(e,t,n,r){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,r):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,r)}};var Ve=new WeakMap;function De(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let o=0;o<r.length;o++){let a=r[o],l=a.getAttribute("data-position");if(!l)continue;let u=l.trim().split(/\s+/).map(d=>parseFloat(d.replace(/m$/,"")));if(u.length<3||u.some(isNaN))continue;let i=a.getAttribute("data-normal"),c;if(i){let d=i.trim().split(/\s+/).map(f=>parseFloat(f));d.length>=3&&!d.some(isNaN)&&(c=[d[0],d[1],d[2]])}let s=n.projectPointToScreen([u[0],u[1],u[2]],c);a.style.position="absolute",a.style.left="0",a.style.top="0",a.style.transform=`translate(-50%, -50%) translate3d(${s.x}px, ${s.y}px, 0)`,a.style.zIndex="3",s.visible?(a.style.opacity="1",a.style.pointerEvents="auto",a.removeAttribute("data-occluded")):(a.style.opacity="0",a.style.pointerEvents="none",a.setAttribute("data-occluded",""))}}var nt={name:"hotspots",updateHotspotsForElement:De,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{De(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ve.set(e,t)},onCameraChange(e,t){t&&De(t,e)},onElementDisconnected(e){let t=Ve.get(e);t&&(t.disconnect(),Ve.delete(e))}};function re(e,t,n,r){let o=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(t,Math.min(n,o))}function $t(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Fe(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function jt(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function rt(e){let t=Fe(e);if(!t)return null;let n=t.target;return{target:$t(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:re(t.radius,.01,50,.5),speed:re(t.speed,-20,20,.5),height:re(t.height,-10,10,0),phase:re(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function ze(e,t){let n=jt(e,16)?.trim();if(!n)return t;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:t}function Be(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:Fe(e);if(!t||t.enabled===!1)return null;let n=re(t.strength??t.intensity,0,5,.35);return n>0?{enabled:!0,strength:n,threshold:re(t.threshold,0,4,.8),radius:re(t.radius,0,2,.5)}:null}function Te(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:Fe(e);if(!t||t.enabled===!1)return null;let n=t.thickness??t.width;return{enabled:!0,color:ze(t.color,"#38bdf8"),thickness:re(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:t.pulse===!0}}function ot(e,t,n,r){let o=t[0],a=t[1],l=t[2],u=t[3],i=n[0],c=n[1],s=n[2],d=n[3],f=o*i+a*c+l*s+u*d;if(f<0&&(i=-i,c=-c,s=-s,d=-d,f=-f),Math.abs(f)>=1)return e[0]=o,e[1]=a,e[2]=l,e[3]=u,e;let b=Math.acos(f),p=Math.sqrt(1-f*f);if(Math.abs(p)<.001)return e[0]=.5*(o+i),e[1]=.5*(a+c),e[2]=.5*(l+s),e[3]=.5*(u+d),e;let m=Math.sin((1-r)*b)/p,x=Math.sin(r*b)/p;return e[0]=o*m+i*x,e[1]=a*m+c*x,e[2]=l*m+s*x,e[3]=u*m+d*x,e}var it=1024,Ge=256,Ae=2048,Kt=128,Yt=64,qt=16,Qt=1e4,Zt=8,te=new Set(["__proto__","constructor","prototype"]),at={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},st={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},ve={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Ee=(e,t)=>e!==null&&typeof e=="object"&&!te.has(t)&&Object.prototype.hasOwnProperty.call(e,t),Y=e=>Array.isArray(e)?[...e]:e,ft=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Ee(e,"value")?e.value:e,j=(e,t)=>Ee(e.configuration,t)?ft(e.configuration[t]):void 0,L=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},ae=e=>Math.max(0,Math.min(1,e)),q=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function we(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||te.has(r)||te.has(n))return null;t.push(r)}return{segments:t}}var de=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},ct=e=>{let t=L(e[0]),n=L(e[1]),r=L(e[2]),o=L(e[3],1),a=Math.hypot(t,n,r,o);return a>1e-8?[t/a,n/a,r/a,o/a]:[0,0,0,1]},lt=(e,t,n,r)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(r&&e.length===4&&t.length===4){let o=[0,0,0,1];return ot(o,ct(e),ct(t),n),o}return e.slice(0,t.length).map((o,a)=>o+(t[a]-o)*n)}return n>=.5?t:e},He=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((r,o)=>n(L(r),L(t[o]))):Array.isArray(e)?e.map(r=>n(L(r),L(t))):Array.isArray(t)?t.map(r=>n(L(e),L(r))):n(L(e),L(t)),Jt=(e,t)=>Array.isArray(e)?e.map(n=>t(L(n))):t(L(e)),ut=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,r)=>Math.abs(n-t[r])<=1e-6):e===t,Se=class{constructor(t,n,r){let o=Array.isArray(r.nodes)?r.nodes:[];if(o.length>it)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${it})`);let a=Array.isArray(r.variables)?r.variables:[];if(a.length>Ge)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Ge})`);let l=Array.isArray(r.declarations)?r.declarations:[],u=Array.isArray(r.events)?r.events:[],i=new Map,c=new Map,s=new Map,d=new Map,f=new Map,b=new Map,p=[],m=[],x=new Map,E=1,I=0,v=0,S=0,w=0,U=!1,V=!1,O=!1;a.forEach((T,A)=>{if(!T||typeof T!="object")return;let R=Y(ft(T.value));i.set(A,R);let _=T.id??T.name;typeof _=="string"&&_&&!te.has(_)&&i.set(_,R)}),(n?.nodes||[]).forEach((T,A)=>{for(let R of T?.children||[])typeof R=="number"&&x.set(R,A)});let N=T=>T.op||typeof T.declaration=="number"&&l[T.declaration]?.op||"",P=(T,A,R)=>{if(te.has(A))return;let _=c.get(T);_||c.set(T,_=Object.create(null)),_[A]=R},C=(T,A)=>{if(typeof T!="number"&&typeof T!="string"||typeof T=="string"&&te.has(T)||!i.has(T)&&i.size>=Ge*2)return;let R=Y(A);if(i.set(T,R),typeof T=="number"){let _=a[T]?.id??a[T]?.name;typeof _=="string"&&!te.has(_)&&i.set(_,R)}},z=T=>typeof T=="number"?u[T]?.id??String(T):typeof T=="string"?/^\d+$/.test(T)&&u[Number(T)]?.id?u[Number(T)].id:T:"",W=(T,A)=>{for(let R=T,_=0;R!==void 0&&R>=0&&_<128;R=x.get(R),_++)if(R===A)return!0;return!1},B=T=>{for(let A=p.length-1;A>=0;A--)p[A].key===T&&p.splice(A,1)},oe=T=>{B(T.key),p.length>=Kt&&p.shift(),p.push(T)},ne=T=>{let A=we(T)?.segments;if(A){if(A[0]==="nodes"&&Array.isArray(n?.nodes)){let R=n.nodes[de(A[1],n.nodes.length)];if(!R)return;let _=A[2];if(_ in ve){let g=ve[_],h=R[_]||g;return g.map((y,M)=>L(h[M],y))}if(_==="weights"){let g=Array.isArray(R.weights)?R.weights:[0],h=A.length===4?de(A[3],64):-2;return h===-2?g.map(y=>L(y)):h>=0?L(g[h]):void 0}if(_==="visible"||_==="extensions"&&A[3]==="KHR_node_visibility"&&A[4]==="visible")return R.extensions?.KHR_node_visibility?.visible??R.visible??!0}else if(A[0]==="materials"&&Array.isArray(n?.materials)){let R=n.materials[de(A[1],n.materials.length)];if(!R)return;let _=R.pbrMetallicRoughness||{};if(A[2]==="pbrMetallicRoughness"){if(A[3]==="baseColorFactor"){let g=_.baseColorFactor||[1,1,1,1];return[L(g[0],1),L(g[1],1),L(g[2],1),L(g[3],1)]}if(A[3]==="metallicFactor"||A[3]==="roughnessFactor")return L(_[A[3]],1)}if(A[2]==="emissiveFactor"){let g=R.emissiveFactor||[0,0,0];return[L(g[0]),L(g[1]),L(g[2])]}if(A[2]==="alphaCutoff")return L(R.alphaCutoff,.5)}}},ie=(T,A)=>{let R=we(T)?.segments;if(!R)return!1;if(R[0]==="nodes"&&Array.isArray(n?.nodes)){let _=de(R[1],n.nodes.length),g=n.nodes[_];if(!g)return!1;let h=R[2];if(h in ve&&Array.isArray(A)){let y=ve[h];if(A.length<y.length)return!1;let M=y.map((G,$)=>L(A[$],G));if(h==="rotation"){let G=Math.hypot(...M);M=G>1e-8?M.map($=>$/G):[0,0,0,1]}g[h]=M,delete g.matrix;let F=t?.initialNodeTransforms?.[_];return F&&(F[h[0]]=[...M]),U=!0,!0}if(h==="weights"){Array.isArray(g.weights)||(g.weights=[]);let y=(M,F)=>{for(let G of t?.meshes||[])if(G.nodeIndex===_)for(let $ of G.primitives||[])$.pluginData?.morph?.weights&&($.pluginData.morph.weights[M]=F)};if(R.length===4){let M=de(R[3],64);if(M<0)return!1;y(M,g.weights[M]=L(A))}else if(Array.isArray(A))g.weights=A.slice(0,64).map(M=>L(M)),g.weights.forEach((M,F)=>y(F,M));else return!1;return O=!0,!0}if(h==="visible"||h==="extensions"&&R[3]==="KHR_node_visibility"&&R[4]==="visible"){let y=q(A);return g.visible=y,(!g.extensions||typeof g.extensions!="object")&&(g.extensions={}),g.extensions.KHR_node_visibility={visible:y},V=!0,!0}}else if(R[0]==="materials"&&Array.isArray(n?.materials)){let _=de(R[1],n.materials.length),g=n.materials[_];if(!g)return!1;let h=g.pbrMetallicRoughness||(g.pbrMetallicRoughness={}),y=M=>{for(let F of t?.meshes||[])for(let G of F.primitives||[])(G.materialIndex??0)===_&&M(G)};if(R[2]==="pbrMetallicRoughness"){if(R[3]==="baseColorFactor"&&Array.isArray(A)&&A.length>=3){let M=[ae(L(A[0],1)),ae(L(A[1],1)),ae(L(A[2],1)),A[3]!==void 0?ae(L(A[3],1)):h.baseColorFactor?.[3]??1];return h.baseColorFactor=M,y(F=>F.baseColor=[...M]),O=!0}if(R[3]==="metallicFactor"||R[3]==="roughnessFactor"){let M=R[3]==="metallicFactor",F=ae(L(A,M?0:.5));return h[R[3]]=F,y(G=>G[M?"metallic":"roughness"]=F),O=!0}}if(R[2]==="emissiveFactor"&&Array.isArray(A)&&A.length>=3)return g.emissiveFactor=[0,1,2].map(M=>Math.max(0,L(A[M]))),O=!0;if(R[2]==="alphaCutoff")return g.alphaCutoff=ae(L(A,.5)),O=!0}return!1},Ue=(T,A,R=new Set)=>{let _=j(A,"pointer");if(typeof _!="string"||!_.startsWith("/"))return null;let g=_.replace(/\{([a-zA-Z0-9_]+)\}/g,(h,y)=>{let M=Math.trunc(Number(ye(T,y,void 0,R)??j(A,y)));return Number.isSafeInteger(M)&&M>=0?String(M):"-1"});return we(g)?g:null},ye=(T,A,R,_)=>{let g=o[T]?.values;if(!Ee(g,A))return R;let h=g[A];if(h==null)return R;if(typeof h!="object"||Array.isArray(h))return Y(h);let y=h;return typeof y.node=="number"?Bt(y.node,y.socket||"value",_):Ee(y,"value")?Y(y.value):R},Bt=(T,A,R)=>{if(T<0||T>=o.length||R.has(T)||R.size>128||++S>Qt)return;let _=o[T],g=N(_);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(g))return Y(c.get(T)?.[A]);R.add(T);try{let h=(y,M=0)=>ye(T,y,M,R);if(g==="variable/get"){let y=j(_,"variable")??j(_,"id");return typeof y=="number"||typeof y=="string"?Y(i.get(y)):void 0}if(g==="pointer/get"){let y=Ue(T,_,R);return y?ne(y):void 0}if(g.startsWith("math/")){let y=g.slice(5);if(y in at)return Jt(h("a"),at[y]);if(y in st){let M=/^(mul|div|rem|mod|pow)$/.test(y)?1:0;return He(h("a",y==="mul"?1:0),h("b",M),st[y])}if(y==="pi")return Math.PI;if(y==="e")return Math.E;if(y==="random")return Math.random();if(y==="clamp")return He(He(h("a"),h("b",h("min",0)),Math.max),h("c",h("max",1)),Math.min);if(y==="mix"||y==="quatSlerp")return lt(h("a",0),h("b",1),L(h("c",h("t",.5)),.5),y==="quatSlerp");if(y==="dot"){let M=h("a"),F=h("b");return Array.isArray(M)&&Array.isArray(F)?M.reduce((G,$,k)=>G+($||0)*(F[k]||0),0):L(M)*L(F)}if(y==="cross"){let M=h("a",[0,0,0]),F=h("b",[0,0,0]);return Array.isArray(M)&&Array.isArray(F)?[(M[1]||0)*(F[2]||0)-(M[2]||0)*(F[1]||0),(M[2]||0)*(F[0]||0)-(M[0]||0)*(F[2]||0),(M[0]||0)*(F[1]||0)-(M[1]||0)*(F[0]||0)]:[0,0,0]}if(y==="length"){let M=h("a");return Array.isArray(M)?Math.hypot(...M):Math.abs(L(M))}if(y==="distance"){let M=h("a"),F=h("b");return Array.isArray(M)&&Array.isArray(F)?Math.hypot(...M.map((G,$)=>(G||0)-(F[$]||0))):Math.abs(L(M)-L(F))}if(y==="normalize"){let M=h("a");if(!Array.isArray(M))return L(M)>=0?1:-1;let F=Math.hypot(...M);return F>1e-8?M.map(G=>G/F):M.map(()=>0)}if(y.startsWith("combine"))return["a","b","c","d"].slice(0,Number(y[7])||2).map(M=>L(h(M)));if(y.startsWith("extract")){let M=h("a");return Array.isArray(M)?M[A==="0"||A==="x"?0:A==="1"||A==="y"?1:A==="2"||A==="z"?2:3]??0:0}if(y==="eq")return ut(h("a"),h("b"));if(y==="ne")return!ut(h("a"),h("b"));if(y==="lt")return L(h("a"))<L(h("b"));if(y==="le")return L(h("a"))<=L(h("b"));if(y==="gt")return L(h("a"))>L(h("b"));if(y==="ge")return L(h("a"))>=L(h("b"));if(y==="isNaN")return Number.isNaN(Number(h("a")));if(y==="isInf"){let M=Number(h("a"));return!Number.isFinite(M)&&!Number.isNaN(M)}return y==="and"?q(h("a",!1))&&q(h("b",!1)):y==="or"?q(h("a",!1))||q(h("b",!1)):y==="xor"?q(h("a",!1))!==q(h("b",!1)):y==="not"?!q(h("a",!1)):y==="select"?Y(q(h("condition",!1))?h("a"):h("b")):void 0}return g==="type/boolToInt"||g==="type/boolToFloat"?q(h("a",!1))?1:0:g==="type/intToBool"||g==="type/floatToBool"?L(h("a",0))!==0:g==="type/intToFloat"?L(h("a",0)):g==="type/floatToInt"?Math.trunc(L(h("a",0))):void 0}finally{R.delete(T)}},ge=()=>{if(U){U=!1,O=!0;let T=Pe(n);if(t){t.worldMatrices=T;for(let A of t.meshes||[])A.nodeIndex>=0&&A.nodeIndex<T.length&&(A.transform.set(T[A.nodeIndex]),fe(A.normalMatrix,A.transform))}}if(V){V=!1,O=!0;let T=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(T))for(let A of t.meshes){let R=!0;for(let _=A.nodeIndex,g=0;_!==void 0&&_>=0&&g<128;_=x.get(_),g++){let h=T[_];if(h?.visible===!1||h?.extensions?.KHR_node_visibility?.visible===!1){R=!1;break}}A.visible=R}}O&&(O=!1,t?.render?.())},se=(T,A={steps:0})=>{if(!T||typeof T.node!="number")return;A.steps===0&&(S=0);let R=[T],_=g=>{R.length+A.steps<Ae&&R.push(g)};for(;R.length>0&&A.steps<Ae;){A.steps++;let g=R.shift();if(!g||g.node<0||g.node>=o.length)continue;let h=g.node,y=o[h];if(!y)continue;let M=g.socket||"in",F=N(y),G=(k,D=void 0)=>ye(h,k,D,new Set),$=(k="out")=>{let D=y.flows?.[k];D&&_(D)};switch(F){case"flow/branch":$(q(G("condition",!1))?"true":"false");break;case"flow/sequence":for(let k of Object.keys(y.flows||{}).sort((D,K)=>Number(D)-Number(K)||D.localeCompare(K)))$(k);break;case"flow/switch":{let k=y.flows?.[String(G("selection",G("value",0)))]??y.flows?.default;k&&_(k);break}case"flow/for":{let k=Math.trunc(L(G("startIndex",0))),D=Math.trunc(L(G("endIndex",0))),K=Math.max(1,Math.trunc(L(G("step",1),1))),Q=y.flows?.body;if(Q&&D>k&&w<Zt){let Gt=Math.min(Math.ceil((D-k)/K),Ae);w++;try{for(let ke=0;ke<Gt&&A.steps<Ae;ke++)P(h,"index",k+ke*K),se(Q,A)}finally{w--}}let qe=y.flows?.completed??y.flows?.out;qe&&_(qe);break}case"flow/doN":{let k=M==="reset"?0:(s.get(h)||0)+1;if(s.set(h,k),P(h,"currentCount",k),P(h,"count",k),M!=="reset"){let D=Math.trunc(L(G("n",j(y,"stopIterations")??j(y,"n")??1),1));k<=D&&$()}break}case"flow/multiGate":{if(M==="reset"){b.set(h,0);break}let k=Object.keys(y.flows||{}).sort();if(!k.length)break;let D=j(y,"isRandom")?Math.floor(Math.random()*k.length):b.get(h)||0;D<k.length&&($(k[D]),b.set(h,j(y,"isLoop")!==!1?(D+1)%k.length:D+1));break}case"flow/waitAll":{if(M==="reset"){d.delete(h);break}let k=d.get(h);k||d.set(h,k=new Set),k.add(M),k.size>=Math.max(1,Math.trunc(Number(j(y,"inputFlows")??2)||2))&&(k.clear(),$("out"),$("completed"));break}case"flow/throttle":{if(M==="reset"){f.delete(h);break}let k=Math.max(0,L(G("duration",0))),D=f.get(h);D===void 0||I-D>=k?(f.set(h,I),P(h,"lastRemainingTime",0),$()):P(h,"lastRemainingTime",Math.max(0,k-(I-D)));break}case"flow/delay":case"flow/setDelay":{if(M==="cancel"){for(let Q=m.length-1;Q>=0;Q--)m[Q].nodeIdx===h&&m.splice(Q,1);P(h,"lastDelayIndex",-1);break}let k=Math.max(0,L(G("duration",j(y,"duration")??0))),D=y.flows?.done??y.flows?.out;if(k<=0){P(h,"lastDelayIndex",-1),D&&_(D);break}m.length>=Yt&&m.shift();let K=E++;P(h,"lastDelayIndex",K),m.push({id:K,nodeIdx:h,rem:k,done:D}),F==="flow/setDelay"&&y.flows?.out&&y.flows?.done&&$("out");break}case"flow/cancelDelay":{let k=Math.trunc(L(G("delayIndex",-1),-1));if(k<0)m.length=0;else for(let D=m.length-1;D>=0;D--)m[D].id===k&&m.splice(D,1);$();break}case"variable/set":C(j(y,"variable")??j(y,"id"),G("value")),$();break;case"variable/interpolate":{let k=j(y,"variable")??j(y,"id"),D=G("value",G("target")),K=Math.max(0,L(G("duration",j(y,"duration")??.3),.3));k!==void 0&&D!==void 0&&oe({key:`var:${String(k)}`,varKey:k,from:Y(G("from")??i.get(k)??0),to:Y(D),dur:K,elapsed:0,quat:!1,linear:j(y,"easing")==="linear",done:y.flows?.done}),$();break}case"pointer/set":{let k=Ue(h,y),D=G("value");k&&D!==void 0&&(B(`ptr:${k}`),ie(k,D)),$();break}case"pointer/interpolate":{let k=Ue(h,y),D=G("value",G("target")),K=Math.max(0,L(G("duration",j(y,"duration")??.3),.3));if(k&&D!==void 0){let Q=G("from")??ne(k);Q!==void 0&&(K<=0?(ie(k,D),$("done")):oe({key:`ptr:${k}`,ptr:k,from:Y(Q),to:Y(D),dur:K,elapsed:0,quat:k.endsWith("/rotation"),linear:j(y,"easing")==="linear",done:y.flows?.done}))}$();break}case"animation/start":{let k=G("animation")??j(y,"animation")??j(y,"clipName"),D=typeof k=="number"?t?.animations?.[k]?.name??n?.animations?.[k]?.name:typeof k=="string"?k:void 0;t?.playAnimation?.(D),O=!0,$();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),F==="animation/resetAt"&&t?.evaluateAnimation?.(L(G("time",0))),O=!0,$();break;case"event/send":case"customEvent/send":{let k=z(j(y,"event")??j(y,"id")),D={};for(let K of Object.keys(y.values||{}))te.has(K)||(D[K]=G(K));k&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:k,values:D}})),Ye(k,D,A)),$();break}default:$();break}}};this.readScenePointer=ne,this.writeScenePointer=ie,this.fireOnStart=()=>{o.forEach(T=>{N(T)==="event/onStart"&&se(T.flows?.out)}),ge()},this.fireOnSelect=T=>{if(!T)return;let A=typeof T.meshIndex=="number"?T.meshIndex:-1,R=typeof T.nodeIndex=="number"?T.nodeIndex:t?.meshes?.[A]?.nodeIndex??-1;o.forEach((_,g)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(N(_)))return;let h=j(_,"nodeIndex")??j(_,"node")??ye(g,"nodeIndex",void 0,new Set),y=j(_,"meshName");if(typeof y=="string"&&y?T.meshName===y:h==null||Number(h)<0||Number.isNaN(Number(h))||W(R,Math.trunc(Number(h)))){if(P(g,"nodeIndex",R),P(g,"meshIndex",A),Array.isArray(T.hitPoint)){let F=[L(T.hitPoint[0]),L(T.hitPoint[1]),L(T.hitPoint[2])];P(g,"hitPoint",F),P(g,"point",F),P(g,"intersectionPoint",F)}if(Array.isArray(T.normal)){let F=[L(T.normal[0]),L(T.normal[1],1),L(T.normal[2])];P(g,"normal",F),P(g,"hitNormal",F)}typeof T.distance=="number"&&P(g,"distance",T.distance),se(_.flows?.out)}}),ge()},this.receiveCustomEvent=(T,A={})=>Ye(T,A,{steps:0});function Ye(T,A,R){if(!(v>=qt)){v++;try{let _=z(T);o.forEach((g,h)=>{if(!/^(customE|e)vent\/receive$/.test(N(g)))return;let y=j(g,"event")??j(g,"id");if(!(z(y)!==_&&String(y)!==String(T))){for(let[M,F]of Object.entries(A))te.has(M)||P(h,M,Y(F));se(g.flows?.out,R)}}),ge()}finally{v--}}}this.tick=T=>{if(!Number.isFinite(T)||T<0)return;let A=Math.min(T,.25);I+=A,o.forEach((_,g)=>{N(_)==="event/onTick"&&(P(g,"timeDelta",A),P(g,"dt",A),P(g,"timeElapsed",I),se(_.flows?.out))});let R=[];for(let _=p.length-1;_>=0;_--){let g=p[_];g.elapsed+=A;let h=g.dur>1e-6?ae(g.elapsed/g.dur):1,y=g.linear?h:h*h*(3-2*h),M=lt(g.from,g.to,y,g.quat);g.ptr?ie(g.ptr,M):g.varKey!==void 0&&C(g.varKey,M),h>=1&&(p.splice(_,1),g.done&&R.push(g.done))}for(let _=m.length-1;_>=0;_--){let g=m[_];g.rem-=A,g.rem<=0&&(m.splice(_,1),g.done&&R.push(g.done))}for(let _ of R)se(_);ge()},this.dispose=()=>{p.length=0,m.length=0,i.clear(),c.clear(),s.clear(),d.clear(),f.clear(),b.clear()}}},J=new WeakMap,Me=new WeakMap;function en(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Qe().some(i=>i.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,o=r?.nodes;if(!Array.isArray(o)||o.length===0)return;let a=Math.min(t,.1),l=(Me.get(e)||0)+a,u=!1;for(let i=0;i<o.length;i++){let c=o[i],s=rt(c?.extras?.xr?.orbit);if(!s)continue;let d=0,f=0,b=0;if(Array.isArray(s.target))d=s.target[0],f=s.target[1],b=s.target[2];else if(typeof s.target=="string"&&s.target!=="head"){let I=o.find(v=>v?.name===s.target);Array.isArray(I?.translation)&&(d=L(I.translation[0]),f=L(I.translation[1]),b=L(I.translation[2]))}let p=s.phase+s.speed*l,m=d+Math.cos(p)*s.radius,x=f+s.height,E=b+Math.sin(p)*s.radius;if(c.translation=[m,x,E],s.faceCenter){let I=Math.atan2(d-m,b-E);c.rotation=[0,Math.sin(I*.5),0,Math.cos(I*.5)]}u=!0}if(u){Me.set(e,l);let i=Pe(r);e.worldMatrices=i;for(let c of e.meshes||[])c.nodeIndex>=0&&c.nodeIndex<i.length&&(c.transform.set(i[c.nodeIndex]),fe(c.normalMatrix,c.transform))}}function We(e){if(!(!e||typeof e!="object"))return J.get(e)||J.get(e.viewer)||J.get(e._view)}function dt(e,t,n){let r=We(e);return r?(r.receiveCustomEvent(t,n),!0):!1}var mt={name:"khr-interactivity",sendInteractivityEvent:dt,getInteractivityVM:We,onLoadModel(e,t){if(!e||typeof e!="object")return;J.get(e)?.dispose(),J.delete(e),Me.delete(e);let n=t?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let o=new Se(e,t,r);J.set(e,o),o.fireOnStart()},onMeshSelect(e,t){J.get(e)?.fireOnSelect(t)},onUpdate(e,t){J.get(e)?.tick(t),en(e,t)},onDestroy(e,t){J.get(t)?.dispose(),J.delete(t),Me.delete(t)}};var pe=new Map,Re=new WeakMap;function tn(e,t){pe.set(e,t)}var pt={name:"materials",onContextRestored(e){Re.delete(e)},onBuildPrimitiveVAO(e,t,n,r,o){return(((r?.materials&&n.material!==void 0?r.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let n=Re.get(e);n||(n=e.createTexture(),Re.set(e,n));let r=Math.max(1,t.canvas.width),o=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,r,o,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,n,r){if(!t)return null;if(t.name&&pe.has(t.name)){let p=pe.get(t.name);return{vs:p.vs||n,fs:p.fs||r}}let o=t.extensions||{},a=o.KHR_materials_clearcoat,l=o.KHR_materials_sheen,u=!!o.KHR_materials_transmission,i=!!o.KHR_materials_ior,c=o.KHR_materials_iridescence;if(!a&&!l&&!o.KHR_materials_unlit&&!u&&!o.KHR_materials_volume&&!i&&!o.KHR_materials_dispersion&&!c)return null;if(o.KHR_materials_unlit)return{vs:n,fs:r.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let s=r;if(u){let p=s.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
33
- `;s=s.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
34
- ${p}out vec4 fragColor;`)}let d=(p,m,x=0,E=1e6,I=3)=>{let v=Number(p);return(Number.isFinite(v)?Math.min(E,Math.max(x,v)):m).toFixed(I)},f=Number(o.KHR_materials_ior?.ior??1.5),b=Number.isFinite(f)?Math.min(10,Math.max(1,f)):1.5;if(i){let p=Math.pow((b-1)/(b+1),2);s=s.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${d(p,.04,0,1,4)}),base.rgb,metallic);`)}if(c){let p=d(c.iridescenceFactor,1,0,1),m=d(c.iridescenceIor,1.3,1,10);s=s.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${m}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${p}*pow(1.-NoV,2.));`)}if(u){let p=d(o.KHR_materials_transmission?.transmissionFactor,1,0,1),m=o.KHR_materials_volume||{},x=d(m.thicknessFactor,.5,0,1e4),E=d(m.attenuationDistance,1,.001,1e6),I=Array.isArray(m.attenuationColor)?m.attenuationColor:[1,1,1],v=d(o.KHR_materials_dispersion?.dispersion,0,0,10);s=s.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
35
- vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${d(b,1.5,1,10)},dV=${v},tV=${x},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
31
+ }`),{vs:r,fs:n}},onBeforeDrawPrimitive(e,t,r,i,n,s){let m=ze.get(e),c=e.getUniformLocation(t,"uHasSH");if(m&&m.length>=27){c&&e.uniform1i(c,1);let o=e.getUniformLocation(t,"uSH");o&&e.uniform3fv(o,m)}else c&&e.uniform1i(c,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},je=new WeakMap;function Ke(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let n=0;n<i.length;n++){let s=i[n],m=s.getAttribute("data-position");if(!m)continue;let c=m.trim().split(/\s+/).map(u=>parseFloat(u.replace(/m$/,"")));if(c.length<3||c.some(isNaN))continue;let o=s.getAttribute("data-normal"),d;if(o){let u=o.trim().split(/\s+/).map(l=>parseFloat(l));u.length>=3&&!u.some(isNaN)&&(d=[u[0],u[1],u[2]])}let a=r.projectPointToScreen([c[0],c[1],c[2]],d);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${a.x}px, ${a.y}px, 0)`,s.style.zIndex="3",a.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var ft={name:"hotspots",updateHotspotsForElement:Ke,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Ke(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),je.set(e,t)},onCameraChange(e,t){t&&Ke(t,e)},onElementDisconnected(e){let t=je.get(e);t&&(t.disconnect(),je.delete(e))}};function be(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function or(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function qe(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function lr(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function sr(e){let t=qe(e);if(!t)return null;let r=t.target;return{target:or(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:be(t.radius,.01,50,.5),speed:be(t.speed,-20,20,.5),height:be(t.height,-10,10,0),phase:be(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var ur=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],fr=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],ti=new Set(ur),ri=new Set(fr);function ct(e,t){let r=lr(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function ht(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:qe(e);if(!t||t.enabled===!1)return null;let r=be(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:be(t.threshold,0,4,.8),radius:be(t.radius,0,2,.5)}:null}function We(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:qe(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:ct(t.color,"#38bdf8"),thickness:be(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function cr(e,t,r,i){let n=t[0],s=t[1],m=t[2],c=t[3],o=r[0],d=r[1],a=r[2],u=r[3],l=n*o+s*d+m*a+c*u;if(l<0&&(o=-o,d=-d,a=-a,u=-u,l=-l),Math.abs(l)>=1)return e[0]=n,e[1]=s,e[2]=m,e[3]=c,e;let h=Math.acos(l),f=Math.sqrt(1-l*l);if(Math.abs(f)<.001)return e[0]=.5*(n+o),e[1]=.5*(s+d),e[2]=.5*(m+a),e[3]=.5*(c+u),e;let g=Math.sin((1-i)*h)/f,A=Math.sin(i*h)/f;return e[0]=n*g+o*A,e[1]=s*g+d*A,e[2]=m*g+a*A,e[3]=c*g+u*A,e}var mt=1024,Xe=256,Ce=2048,hr=128,mr=64,dr=16,pr=1e4,gr=8,he=new Set(["__proto__","constructor","prototype"]),dt={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},pt={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},De={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Fe=(e,t)=>e!==null&&typeof e=="object"&&!he.has(t)&&Object.prototype.hasOwnProperty.call(e,t),ae=e=>Array.isArray(e)?[...e]:e,gt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Fe(e,"value")?e.value:e,X=(e,t)=>Fe(e.configuration,t)?gt(e.configuration[t]):void 0,V=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},ve=e=>Math.max(0,Math.min(1,e)),le=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function Ue(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||he.has(i)||he.has(r))return null;t.push(i)}return{segments:t}}var Me=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},bt=e=>{let t=V(e[0]),r=V(e[1]),i=V(e[2]),n=V(e[3],1),s=Math.hypot(t,r,i,n);return s>1e-8?[t/s,r/s,i/s,n/s]:[0,0,0,1]},yt=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let n=[0,0,0,1];return cr(n,bt(e),bt(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},Qe=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(V(i),V(t[n]))):Array.isArray(e)?e.map(i=>r(V(i),V(t))):Array.isArray(t)?t.map(i=>r(V(e),V(i))):r(V(e),V(t)),br=(e,t)=>Array.isArray(e)?e.map(r=>t(V(r))):t(V(e)),vt=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,xt=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>mt)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${mt})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>Xe)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Xe})`);let s=Array.isArray(r.declarations)?r.declarations:[],m=Array.isArray(r.events)?r.events:[],c=new Map,o=new Map,d=new Map,a=new Map,u=new Map,l=new Map,h=[],f=[],g=new Map,A=1,v=0,S=0,p=0,b=0,y=!1,L=!1,C=!1;n.forEach((N,x)=>{if(!N||typeof N!="object")return;let E=ae(gt(N.value));c.set(x,E);let P=N.id??N.name;typeof P=="string"&&P&&!he.has(P)&&c.set(P,E)}),(t?.nodes||[]).forEach((N,x)=>{for(let E of N?.children||[])typeof E=="number"&&g.set(E,x)});let F=N=>N.op||typeof N.declaration=="number"&&s[N.declaration]?.op||"",_=(N,x,E)=>{if(he.has(x))return;let P=o.get(N);P||o.set(N,P=Object.create(null)),P[x]=E},U=(N,x)=>{if(typeof N!="number"&&typeof N!="string"||typeof N=="string"&&he.has(N)||!c.has(N)&&c.size>=Xe*2)return;let E=ae(x);if(c.set(N,E),typeof N=="number"){let P=n[N]?.id??n[N]?.name;typeof P=="string"&&!he.has(P)&&c.set(P,E)}},D=N=>typeof N=="number"?m[N]?.id??String(N):typeof N=="string"?/^\d+$/.test(N)&&m[Number(N)]?.id?m[Number(N)].id:N:"",$=(N,x)=>{for(let E=N,P=0;E!==void 0&&E>=0&&P<128;E=g.get(E),P++)if(E===x)return!0;return!1},z=N=>{for(let x=h.length-1;x>=0;x--)h[x].key===N&&h.splice(x,1)},O=N=>{z(N.key),h.length>=hr&&h.shift(),h.push(N)},te=N=>{let x=Ue(N)?.segments;if(x){if(x[0]==="nodes"&&Array.isArray(t?.nodes)){let E=t.nodes[Me(x[1],t.nodes.length)];if(!E)return;let P=x[2];if(P in De){let T=De[P],M=E[P]||T;return T.map((w,I)=>V(M[I],w))}if(P==="weights"){let T=Array.isArray(E.weights)?E.weights:[0],M=x.length===4?Me(x[3],64):-2;return M===-2?T.map(w=>V(w)):M>=0?V(T[M]):void 0}if(P==="visible"||P==="extensions"&&x[3]==="KHR_node_visibility"&&x[4]==="visible")return E.extensions?.KHR_node_visibility?.visible??E.visible??!0}else if(x[0]==="materials"&&Array.isArray(t?.materials)){let E=t.materials[Me(x[1],t.materials.length)];if(!E)return;let P=E.pbrMetallicRoughness||{};if(x[2]==="pbrMetallicRoughness"){if(x[3]==="baseColorFactor"){let T=P.baseColorFactor||[1,1,1,1];return[V(T[0],1),V(T[1],1),V(T[2],1),V(T[3],1)]}if(x[3]==="metallicFactor"||x[3]==="roughnessFactor")return V(P[x[3]],1)}if(x[2]==="emissiveFactor"){let T=E.emissiveFactor||[0,0,0];return[V(T[0]),V(T[1]),V(T[2])]}if(x[2]==="alphaCutoff")return V(E.alphaCutoff,.5)}}},Z=(N,x)=>{let E=Ue(N)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(t?.nodes)){let P=Me(E[1],t.nodes.length),T=t.nodes[P];if(!T)return!1;let M=E[2];if(M in De&&Array.isArray(x)){let w=De[M];if(x.length<w.length)return!1;let I=w.map((H,K)=>V(x[K],H));if(M==="rotation"){let H=Math.hypot(...I);I=H>1e-8?I.map(K=>K/H):[0,0,0,1]}T[M]=I,delete T.matrix;let B=e?.initialNodeTransforms?.[P];return B&&(B[M[0]]=[...I]),y=!0,!0}if(M==="weights"){Array.isArray(T.weights)||(T.weights=[]);let w=(I,B)=>{for(let H of e?.meshes||[])if(H.nodeIndex===P)for(let K of H.primitives||[])K.pluginData?.morph?.weights&&(K.pluginData.morph.weights[I]=B)};if(E.length===4){let I=Me(E[3],64);if(I<0)return!1;w(I,T.weights[I]=V(x))}else if(Array.isArray(x))T.weights=x.slice(0,64).map(I=>V(I)),T.weights.forEach((I,B)=>w(B,I));else return!1;return C=!0,!0}if(M==="visible"||M==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let w=le(x);return T.visible=w,(!T.extensions||typeof T.extensions!="object")&&(T.extensions={}),T.extensions.KHR_node_visibility={visible:w},L=!0,!0}}else if(E[0]==="materials"&&Array.isArray(t?.materials)){let P=Me(E[1],t.materials.length),T=t.materials[P];if(!T)return!1;let M=T.pbrMetallicRoughness||(T.pbrMetallicRoughness={}),w=I=>{for(let B of e?.meshes||[])for(let H of B.primitives||[])(H.materialIndex??0)===P&&I(H)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(x)&&x.length>=3){let I=[ve(V(x[0],1)),ve(V(x[1],1)),ve(V(x[2],1)),x[3]!==void 0?ve(V(x[3],1)):M.baseColorFactor?.[3]??1];return M.baseColorFactor=I,w(B=>B.baseColor=[...I]),C=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let I=E[3]==="metallicFactor",B=ve(V(x,I?0:.5));return M[E[3]]=B,w(H=>H[I?"metallic":"roughness"]=B),C=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(x)&&x.length>=3)return T.emissiveFactor=[0,1,2].map(I=>Math.max(0,V(x[I]))),C=!0;if(E[2]==="alphaCutoff")return T.alphaCutoff=ve(V(x,.5)),C=!0}return!1},W=(N,x,E=new Set)=>{let P=X(x,"pointer");if(typeof P!="string"||!P.startsWith("/"))return null;let T=P.replace(/\{([a-zA-Z0-9_]+)\}/g,(M,w)=>{let I=Math.trunc(Number(re(N,w,void 0,E)??X(x,w)));return Number.isSafeInteger(I)&&I>=0?String(I):"-1"});return Ue(T)?T:null},re=(N,x,E,P)=>{let T=i[N]?.values;if(!Fe(T,x))return E;let M=T[x];if(M==null)return E;if(typeof M!="object"||Array.isArray(M))return ae(M);let w=M;return typeof w.node=="number"?_e(w.node,w.socket||"value",P):Fe(w,"value")?ae(w.value):E},_e=(N,x,E)=>{if(N<0||N>=i.length||E.has(N)||E.size>128||++p>pr)return;let P=i[N],T=F(P);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(T))return ae(o.get(N)?.[x]);E.add(N);try{let M=(w,I=0)=>re(N,w,I,E);if(T==="variable/get"){let w=X(P,"variable")??X(P,"id");return typeof w=="number"||typeof w=="string"?ae(c.get(w)):void 0}if(T==="pointer/get"){let w=W(N,P,E);return w?te(w):void 0}if(T.startsWith("math/")){let w=T.slice(5);if(w in dt)return br(M("a"),dt[w]);if(w in pt){let I=/^(mul|div|rem|mod|pow)$/.test(w)?1:0;return Qe(M("a",w==="mul"?1:0),M("b",I),pt[w])}if(w==="pi")return Math.PI;if(w==="e")return Math.E;if(w==="random")return Math.random();if(w==="clamp")return Qe(Qe(M("a"),M("b",M("min",0)),Math.max),M("c",M("max",1)),Math.min);if(w==="mix"||w==="quatSlerp")return yt(M("a",0),M("b",1),V(M("c",M("t",.5)),.5),w==="quatSlerp");if(w==="dot"){let I=M("a"),B=M("b");return Array.isArray(I)&&Array.isArray(B)?I.reduce((H,K,R)=>H+(K||0)*(B[R]||0),0):V(I)*V(B)}if(w==="cross"){let I=M("a",[0,0,0]),B=M("b",[0,0,0]);return Array.isArray(I)&&Array.isArray(B)?[(I[1]||0)*(B[2]||0)-(I[2]||0)*(B[1]||0),(I[2]||0)*(B[0]||0)-(I[0]||0)*(B[2]||0),(I[0]||0)*(B[1]||0)-(I[1]||0)*(B[0]||0)]:[0,0,0]}if(w==="length"){let I=M("a");return Array.isArray(I)?Math.hypot(...I):Math.abs(V(I))}if(w==="distance"){let I=M("a"),B=M("b");return Array.isArray(I)&&Array.isArray(B)?Math.hypot(...I.map((H,K)=>(H||0)-(B[K]||0))):Math.abs(V(I)-V(B))}if(w==="normalize"){let I=M("a");if(!Array.isArray(I))return V(I)>=0?1:-1;let B=Math.hypot(...I);return B>1e-8?I.map(H=>H/B):I.map(()=>0)}if(w.startsWith("combine"))return["a","b","c","d"].slice(0,Number(w[7])||2).map(I=>V(M(I)));if(w.startsWith("extract")){let I=M("a");return Array.isArray(I)?I[x==="0"||x==="x"?0:x==="1"||x==="y"?1:x==="2"||x==="z"?2:3]??0:0}if(w==="eq")return vt(M("a"),M("b"));if(w==="ne")return!vt(M("a"),M("b"));if(w==="lt")return V(M("a"))<V(M("b"));if(w==="le")return V(M("a"))<=V(M("b"));if(w==="gt")return V(M("a"))>V(M("b"));if(w==="ge")return V(M("a"))>=V(M("b"));if(w==="isNaN")return Number.isNaN(Number(M("a")));if(w==="isInf"){let I=Number(M("a"));return!Number.isFinite(I)&&!Number.isNaN(I)}return w==="and"?le(M("a",!1))&&le(M("b",!1)):w==="or"?le(M("a",!1))||le(M("b",!1)):w==="xor"?le(M("a",!1))!==le(M("b",!1)):w==="not"?!le(M("a",!1)):w==="select"?ae(le(M("condition",!1))?M("a"):M("b")):void 0}return T==="type/boolToInt"||T==="type/boolToFloat"?le(M("a",!1))?1:0:T==="type/intToBool"||T==="type/floatToBool"?V(M("a",0))!==0:T==="type/intToFloat"?V(M("a",0)):T==="type/floatToInt"?Math.trunc(V(M("a",0))):void 0}finally{E.delete(N)}},xe=()=>{if(y){y=!1,C=!0;let N=at(t);if(e){e.worldMatrices=N;for(let x of e.meshes||[])x.nodeIndex>=0&&x.nodeIndex<N.length&&(x.transform.set(N[x.nodeIndex]),Re(x.normalMatrix,x.transform))}}if(L){L=!1,C=!0;let N=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(N))for(let x of e.meshes){let E=!0;for(let P=x.nodeIndex,T=0;P!==void 0&&P>=0&&T<128;P=g.get(P),T++){let M=N[P];if(M?.visible===!1||M?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}x.visible=E}}C&&(C=!1,e?.render?.())},ie=(N,x={steps:0})=>{if(!N||typeof N.node!="number")return;x.steps===0&&(p=0);let E=[N],P=T=>{E.length+x.steps<Ce&&E.push(T)};for(;E.length>0&&x.steps<Ce;){x.steps++;let T=E.shift();if(!T||T.node<0||T.node>=i.length)continue;let M=T.node,w=i[M];if(!w)continue;let I=T.socket||"in",B=F(w),H=(R,k=void 0)=>re(M,R,k,new Set),K=(R="out")=>{let k=w.flows?.[R];k&&P(k)};switch(B){case"flow/branch":K(le(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let R of Object.keys(w.flows||{}).sort((k,Q)=>Number(k)-Number(Q)||k.localeCompare(Q)))K(R);break;case"flow/switch":{let R=w.flows?.[String(H("selection",H("value",0)))]??w.flows?.default;R&&P(R);break}case"flow/for":{let R=Math.trunc(V(H("startIndex",0))),k=Math.trunc(V(H("endIndex",0))),Q=Math.max(1,Math.trunc(V(H("step",1),1))),Y=w.flows?.body;if(Y&&k>R&&b<gr){let G=Math.min(Math.ceil((k-R)/Q),Ce);b++;try{for(let ee=0;ee<G&&x.steps<Ce;ee++)_(M,"index",R+ee*Q),ie(Y,x)}finally{b--}}let me=w.flows?.completed??w.flows?.out;me&&P(me);break}case"flow/doN":{let R=I==="reset"?0:(d.get(M)||0)+1;if(d.set(M,R),_(M,"currentCount",R),_(M,"count",R),I!=="reset"){let k=Math.trunc(V(H("n",X(w,"stopIterations")??X(w,"n")??1),1));R<=k&&K()}break}case"flow/multiGate":{if(I==="reset"){l.set(M,0);break}let R=Object.keys(w.flows||{}).sort();if(!R.length)break;let k=X(w,"isRandom")?Math.floor(Math.random()*R.length):l.get(M)||0;k<R.length&&(K(R[k]),l.set(M,X(w,"isLoop")!==!1?(k+1)%R.length:k+1));break}case"flow/waitAll":{if(I==="reset"){a.delete(M);break}let R=a.get(M);R||a.set(M,R=new Set),R.add(I),R.size>=Math.max(1,Math.trunc(Number(X(w,"inputFlows")??2)||2))&&(R.clear(),K("out"),K("completed"));break}case"flow/throttle":{if(I==="reset"){u.delete(M);break}let R=Math.max(0,V(H("duration",0))),k=u.get(M);k===void 0||v-k>=R?(u.set(M,v),_(M,"lastRemainingTime",0),K()):_(M,"lastRemainingTime",Math.max(0,R-(v-k)));break}case"flow/delay":case"flow/setDelay":{if(I==="cancel"){for(let Y=f.length-1;Y>=0;Y--)f[Y].nodeIdx===M&&f.splice(Y,1);_(M,"lastDelayIndex",-1);break}let R=Math.max(0,V(H("duration",X(w,"duration")??0))),k=w.flows?.done??w.flows?.out;if(R<=0){_(M,"lastDelayIndex",-1),k&&P(k);break}f.length>=mr&&f.shift();let Q=A++;_(M,"lastDelayIndex",Q),f.push({id:Q,nodeIdx:M,rem:R,done:k}),B==="flow/setDelay"&&w.flows?.out&&w.flows?.done&&K("out");break}case"flow/cancelDelay":{let R=Math.trunc(V(H("delayIndex",-1),-1));if(R<0)f.length=0;else for(let k=f.length-1;k>=0;k--)f[k].id===R&&f.splice(k,1);K();break}case"variable/set":U(X(w,"variable")??X(w,"id"),H("value")),K();break;case"variable/interpolate":{let R=X(w,"variable")??X(w,"id"),k=H("value",H("target")),Q=Math.max(0,V(H("duration",X(w,"duration")??.3),.3));R!==void 0&&k!==void 0&&O({key:`var:${String(R)}`,varKey:R,from:ae(H("from")??c.get(R)??0),to:ae(k),dur:Q,elapsed:0,quat:!1,linear:X(w,"easing")==="linear",done:w.flows?.done}),K();break}case"pointer/set":{let R=W(M,w),k=H("value");R&&k!==void 0&&(z(`ptr:${R}`),Z(R,k)),K();break}case"pointer/interpolate":{let R=W(M,w),k=H("value",H("target")),Q=Math.max(0,V(H("duration",X(w,"duration")??.3),.3));if(R&&k!==void 0){let Y=H("from")??te(R);Y!==void 0&&(Q<=0?(Z(R,k),K("done")):O({key:`ptr:${R}`,ptr:R,from:ae(Y),to:ae(k),dur:Q,elapsed:0,quat:R.endsWith("/rotation"),linear:X(w,"easing")==="linear",done:w.flows?.done}))}K();break}case"animation/start":{let R=H("animation")??X(w,"animation")??X(w,"clipName"),k=typeof R=="number"?e?.animations?.[R]?.name??t?.animations?.[R]?.name:typeof R=="string"?R:void 0;e?.playAnimation?.(k),C=!0,K();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),B==="animation/resetAt"&&e?.evaluateAnimation?.(V(H("time",0))),C=!0,K();break;case"event/send":case"customEvent/send":{let R=D(X(w,"event")??X(w,"id")),k={};for(let Q of Object.keys(w.values||{}))he.has(Q)||(k[Q]=H(Q));R&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:R,values:k}})),se(R,k,x)),K();break}default:K();break}}};this.readScenePointer=te,this.writeScenePointer=Z,this.fireOnStart=()=>{i.forEach(N=>{F(N)==="event/onStart"&&ie(N.flows?.out)}),xe()},this.fireOnSelect=N=>{if(!N)return;let x=typeof N.meshIndex=="number"?N.meshIndex:-1,E=typeof N.nodeIndex=="number"?N.nodeIndex:e?.meshes?.[x]?.nodeIndex??-1;i.forEach((P,T)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(F(P)))return;let M=X(P,"nodeIndex")??X(P,"node")??re(T,"nodeIndex",void 0,new Set),w=X(P,"meshName");if(typeof w=="string"&&w?N.meshName===w:M==null||Number(M)<0||Number.isNaN(Number(M))||$(E,Math.trunc(Number(M)))){if(_(T,"nodeIndex",E),_(T,"meshIndex",x),Array.isArray(N.hitPoint)){let I=[V(N.hitPoint[0]),V(N.hitPoint[1]),V(N.hitPoint[2])];_(T,"hitPoint",I),_(T,"point",I),_(T,"intersectionPoint",I)}if(Array.isArray(N.normal)){let I=[V(N.normal[0]),V(N.normal[1],1),V(N.normal[2])];_(T,"normal",I),_(T,"hitNormal",I)}typeof N.distance=="number"&&_(T,"distance",N.distance),ie(P.flows?.out)}}),xe()},this.receiveCustomEvent=(N,x={})=>se(N,x,{steps:0});function se(N,x,E){if(!(S>=dr)){S++;try{let P=D(N);i.forEach((T,M)=>{if(!/^(customE|e)vent\/receive$/.test(F(T)))return;let w=X(T,"event")??X(T,"id");if(!(D(w)!==P&&String(w)!==String(N))){for(let[I,B]of Object.entries(x))he.has(I)||_(M,I,ae(B));ie(T.flows?.out,E)}}),xe()}finally{S--}}}this.tick=N=>{if(!Number.isFinite(N)||N<0)return;let x=Math.min(N,.25);v+=x,i.forEach((P,T)=>{F(P)==="event/onTick"&&(_(T,"timeDelta",x),_(T,"dt",x),_(T,"timeElapsed",v),ie(P.flows?.out))});let E=[];for(let P=h.length-1;P>=0;P--){let T=h[P];T.elapsed+=x;let M=T.dur>1e-6?ve(T.elapsed/T.dur):1,w=T.linear?M:M*M*(3-2*M),I=yt(T.from,T.to,w,T.quat);T.ptr?Z(T.ptr,I):T.varKey!==void 0&&U(T.varKey,I),M>=1&&(h.splice(P,1),T.done&&E.push(T.done))}for(let P=f.length-1;P>=0;P--){let T=f[P];T.rem-=x,T.rem<=0&&(f.splice(P,1),T.done&&E.push(T.done))}for(let P of E)ie(P);xe()},this.dispose=()=>{h.length=0,f.length=0,c.clear(),o.clear(),d.clear(),a.clear(),u.clear(),l.clear()}}},fe=new WeakMap,ke=new WeakMap;function yr(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||tr().some(c=>c.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let n=Math.min(t,.1),s=(ke.get(e)||0)+n,m=!1;for(let c=0;c<i.length;c++){let o=i[c],d=sr(o?.extras?.xr?.orbit);if(!d)continue;let a=0,u=0,l=0;if(Array.isArray(d.target))a=d.target[0],u=d.target[1],l=d.target[2];else if(typeof d.target=="string"&&d.target!=="head"){let v=i.find(S=>S?.name===d.target);Array.isArray(v?.translation)&&(a=V(v.translation[0]),u=V(v.translation[1]),l=V(v.translation[2]))}let h=d.phase+d.speed*s,f=a+Math.cos(h)*d.radius,g=u+d.height,A=l+Math.sin(h)*d.radius;if(o.translation=[f,g,A],d.faceCenter){let v=Math.atan2(a-f,l-A);o.rotation=[0,Math.sin(v*.5),0,Math.cos(v*.5)]}m=!0}if(m){ke.set(e,s);let c=at(r);e.worldMatrices=c;for(let o of e.meshes||[])o.nodeIndex>=0&&o.nodeIndex<c.length&&(o.transform.set(c[o.nodeIndex]),Re(o.normalMatrix,o.transform))}}function Ze(e){if(!(!e||typeof e!="object"))return fe.get(e)||fe.get(e.viewer)||fe.get(e._view)}function Mt(e,t,r){let i=Ze(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var wt={name:"khr-interactivity",sendInteractivityEvent:Mt,getInteractivityVM:Ze,onLoadModel(e,t){if(!e||typeof e!="object")return;fe.get(e)?.dispose(),fe.delete(e),ke.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let n=new xt(e,t,i);fe.set(e,n),n.fireOnStart()},onMeshSelect(e,t){fe.get(e)?.fireOnSelect(t)},onUpdate(e,t){fe.get(e)?.tick(t),yr(e,t)},onDestroy(e,t){fe.get(t)?.dispose(),fe.delete(t),ke.delete(t)}};function Oe(e,t){let r=(a,u,l,h)=>{let f=typeof a=="number"?a:Number(a);return Number.isFinite(f)?Math.max(u,Math.min(l,f)):h};function i(a,u,l=0,h=.05,f){if(!a||!a.length)return-1;let g=a[0]>0?[0,...a]:a,A=Number.isFinite(u)?Math.max(0,u):0,v=Number.isFinite(h)?Math.max(0,Math.min(.5,h)):.05;if(typeof f=="number"&&Number.isFinite(f)&&f>0){let b=l===-1?f*(1-v):f*(1+v);if(A>b)return-1}let S=0;for(let b=g.length-1;b>=1;b--)if(A>=g[b]){S=b;break}if(l<0||l>=g.length||l===S)return S;if(S>l){let b=l;for(let y=l+1;y<=S&&A>=g[y]*(1+v);y++)b=y;return b}let p=l;for(let b=l;b>S&&A<g[b]*(1-v);b--)p=b-1;return p}function n(a){if(!a)return null;let u=a===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(a)?{distances:a}:typeof a=="object"?a:null;if(!u||u.enabled===!1)return null;let l=r(u.hysteresis,0,.5,.05),h=[],f;if(Array.isArray(u.levels)&&u.levels.length>0){let S=u.levels.slice(0,8);for(let b=0;b<S.length;b++){let y=S[b];if(!y||typeof y!="object"||Array.isArray(y))continue;let L=y,C=r(L.distance,0,1e4,b===0?0:b*4),F=typeof L.hysteresis=="number"?r(L.hysteresis,0,.5,l):void 0,_=typeof L.ratio=="number"?r(L.ratio,.05,1,.5):void 0,U=typeof L.childIndex=="number"&&Number.isFinite(L.childIndex)?Math.max(0,Math.round(L.childIndex)):void 0,D=typeof L.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(L.node.trim())?L.node.trim().slice(0,64):void 0;h.push({distance:C,...F!==void 0?{hysteresis:F}:{},..._!==void 0?{ratio:_}:{},...U!==void 0?{childIndex:U}:{},...D?{node:D}:{}})}h.sort((b,y)=>b.distance-y.distance),h.length>0&&h[0].distance>0&&h.unshift({distance:0,childIndex:0});let p=0;h=h.slice(0,8).map((b,y)=>{let L=y===0?0:Math.max(p,b.distance);return p=L,{...b,distance:L,childIndex:b.childIndex??y}})}if(Array.isArray(u.ratios)&&u.ratios.length>0){let S=[];for(let p of u.ratios.slice(0,7))typeof p=="number"&&S.push(r(p,.05,1,.5));S.length>0&&(f=S)}if(h.length===0){let S=Array.isArray(u.distances)?u.distances:[],p=[];for(let y of S.slice(0,8))typeof y=="number"&&p.push(r(y,0,1e4,4));if(p.length===0&&f&&f.length>0)for(let y=0;y<f.length;y++)p.push((y+1)*4);if(p.length===0&&u.cullDistance===void 0)return null;p.length===0||p[0]>0?p.unshift(0):f&&f.length===p.length&&f[0]===1&&(f=f.slice(1));let b=0;for(let y=0;y<Math.min(8,p.length);y++){let L=y===0?0:Math.max(b,p[y]);b=L;let C=y>0&&f?f[y-1]:void 0;h.push({distance:L,childIndex:y,...C!==void 0?{ratio:C}:{}})}}else if(!f){let S=[];for(let p=1;p<h.length;p++)typeof h[p].ratio=="number"&&S.push(h[p].ratio);S.length>0&&(f=S)}let g=h.map(S=>S.distance),A=g[g.length-1]??0,v=u.cullDistance!==void 0&&u.cullDistance!==null&&u.cullDistance!==!1?r(u.cullDistance,Math.max(1,A),1e4,100):void 0;return{levels:h,distances:g,...f?{ratios:f}:{},hysteresis:l,...v!==void 0?{cullDistance:v}:{}}}function s(a,u){let l=a?.attributes?.position;if(!l||!l.array||l.count<3)return a;let h=r(u,.05,1,.5),f=l.array,g=l.count,A=a.attributes?.normal?.array,v=a.attributes?.uv?.array,S=a.index?.array,p=Math.floor((S?S.length:g)/3);if(p<1)return a;let b=Math.max(1,Math.min(p,Math.round(p*h))),y=1/0,L=1/0,C=1/0,F=-1/0,_=-1/0,U=-1/0;for(let x=0;x<g;x++){let E=f[x*3],P=f[x*3+1],T=f[x*3+2];E<y&&(y=E),P<L&&(L=P),T<C&&(C=T),E>F&&(F=E),P>_&&(_=P),T>U&&(U=T)}let D=Math.max(1e-5,F-y),$=Math.max(1e-5,_-L),z=Math.max(1e-5,U-C),O=Math.max(D,$,z),te=x=>{let E=Math.max(1,Math.round(D/O*x)),P=Math.max(1,Math.round($/O*x)),T=Math.max(1,Math.round(z/O*x)),M=new Map,w=new Int32Array(g),I=[],B=[],H=[],K=[];for(let G=0;G<g;G++){let ee=f[G*3],de=f[G*3+1],pe=f[G*3+2],oe=Math.min(E-1,Math.max(0,Math.floor((ee-y)/D*E))),ne=Math.min(P-1,Math.max(0,Math.floor((de-L)/$*P))),ge=Math.min(T-1,Math.max(0,Math.floor((pe-C)/z*T))),Ae=oe+ne*E+ge*E*P,J=M.get(Ae);J===void 0?(J=K.length,M.set(Ae,J),I.push(ee,de,pe),A&&B.push(A[G*3],A[G*3+1],A[G*3+2]),v&&H.push(v[G*2],v[G*2+1]),K.push(1)):(I[J*3]+=ee,I[J*3+1]+=de,I[J*3+2]+=pe,A&&(B[J*3]+=A[G*3],B[J*3+1]+=A[G*3+1],B[J*3+2]+=A[G*3+2]),K[J]++),w[G]=J}let R=[],k=new Set;for(let G=0;G<p;G++){let ee=S?S[G*3]:G*3,de=S?S[G*3+1]:G*3+1,pe=S?S[G*3+2]:G*3+2,oe=w[ee],ne=w[de],ge=w[pe];if(oe===ne||ne===ge||ge===oe)continue;let Ae=Math.min(oe,ne,ge),J=Math.max(oe,ne,ge),Jt=oe+ne+ge-Ae-J,nt=`${Ae}_${Jt}_${J}`;k.has(nt)||(k.add(nt),R.push(oe,ne,ge))}let Q=K.length,Y=new Float32Array(Q*3),me=A?new Float32Array(Q*3):null;for(let G=0;G<Q;G++){let ee=1/K[G];if(Y[G*3]=I[G*3]*ee,Y[G*3+1]=I[G*3+1]*ee,Y[G*3+2]=I[G*3+2]*ee,me){let de=B[G*3],pe=B[G*3+1],oe=B[G*3+2],ne=Math.hypot(de,pe,oe)||1;me[G*3]=de/ne,me[G*3+1]=pe/ne,me[G*3+2]=oe/ne}}return{pos:Y,norm:me,uv:v?new Float32Array(H):null,tris:R,triCount:R.length/3,vertCount:Q}},Z=Math.max(2,Math.round(Math.sqrt(b/4))),W=te(Z);if(W.triCount>b*1.25&&Z>2){let x=Math.max(2,Math.round(Z*Math.sqrt(b/W.triCount)));if(x!==Z){let E=te(x);E.triCount>=Math.min(4,b)&&(W=E)}}else if(W.triCount<Math.min(4,b)){let x=te(Math.max(Z*2,8));x.triCount>W.triCount&&(W=x)}let re=W.tris;if(h<1&&W.triCount>b){let x=[],E=W.triCount/b;for(let P=0;P<b;P++){let T=Math.min(W.triCount-1,Math.floor(P*E));x.push(W.tris[T*3],W.tris[T*3+1],W.tris[T*3+2])}re=x}if(re.length<3){re=[];for(let x=0;x<b*3;x++)re.push(S?S[x]:x);W={pos:f.slice(),norm:A?A.slice():null,uv:v?v.slice():null,tris:re,triCount:b,vertCount:g}}let _e=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),xe=_e?.BufferGeometry??a.constructor,ie=_e?.BufferAttribute??l.constructor,se=new xe;se.setAttribute("position",new ie(W.pos,3)),W.norm&&se.setAttribute("normal",new ie(W.norm,3)),W.uv&&se.setAttribute("uv",new ie(W.uv,2));let N=W.vertCount>65535?new Uint32Array(re):new Uint16Array(re);return typeof se.setIndex=="function"?se.setIndex(new ie(N,1)):se.index=new ie(N,1),se}let m=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...a){for(let u of a)u&&(u.parent=this,this.children.push(u));return this}};class c extends m{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(u,l=0,h=.05){if(!u)return this;let f=Math.max(0,Number.isFinite(Number(l))?Number(l):0),g=r(h,0,.5,.05),A=this.levels.length;for(let p=0;p<this.levels.length;p++)if(f<this.levels[p].distance){A=p;break}this.levels.splice(A,0,{object:u,distance:f,hysteresis:g}),this.add(u);let v=this.levels.map(p=>p.object),S=this.children.filter(p=>!v.includes(p));this.children=[...v,...S];for(let p=0;p<this.levels.length;p++)this.levels[p].object.visible=p===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(u){if(!this.levels.length)return null;let l=i(this.levels.map(h=>h.distance),u,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return l>=0&&l<this.levels.length?this.levels[l].object:null}update(u){if(this.levels.length===0||!u)return;let l=u.position??{x:0,y:0,z:0},h=this.position??{x:0,y:0,z:0},f=Math.hypot((Number(l.x)||0)-(Number(h.x)||0),(Number(l.y)||0)-(Number(h.y)||0),(Number(l.z)||0)-(Number(h.z)||0)),g=i(this.levels.map(A=>A.distance),f,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=g;for(let A=0;A<this.levels.length;A++)this.levels[A].object.visible=A===g}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let u=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((l,h)=>({distance:l.distance,hysteresis:l.hysteresis,childIndex:h,...l.object?.name?{node:l.object.name}:{}})),distances:this.levels.map(l=>l.distance),hysteresis:this.levels[0]?.hysteresis??.05,...u!==void 0?{cullDistance:u}:{}}}}function o(a){if(!a||a._lodMaterialized||!a.userData?.xr?.lod||a.isLOD||Array.isArray(a.children)&&a.children.length>0)return;let u=a.geometry?.attributes?.position;if(!u||!u.array||u.count<3)return;let l=n(a.userData.xr.lod);if(!l||l.levels.length<2)return;a._lodMaterialized=!0;let h=a.geometry;a._lodOriginalGeometry=h;let f=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),g=f?.Mesh??a.constructor,A=f?.BufferGeometry??h.constructor,v=typeof a.name=="string"&&a.name.trim()?a.name.trim():"Mesh",S=new g(h,a.material);S.name=`${v}_LOD0`,S.visible=!0,S.castShadow=!!a.castShadow,S.receiveShadow=!!a.receiveShadow,a.add(S);for(let p=1;p<l.levels.length;p++){let b=l.levels[p].ratio??l.ratios?.[p-1]??Math.max(.05,Math.pow(.5,p)),y=s(h,b),L=new g(y,a.material);L.name=`${v}_LOD${p}`,L.visible=!1,L.castShadow=!!a.castShadow,L.receiveShadow=!!a.receiveShadow,a.add(L)}a.geometry=new A,a.userData.xr.lod={...l,levels:l.levels.map((p,b)=>({...p,childIndex:b,node:`${v}_LOD${b}`}))}}let d={LOD:c,decimateGeometry:s,selectLodLevelIndex:i,parseLod:n,materializeLodGeometry:o};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:c,decimateGeometry:s}),t._lodMaterialize=o,t.materializeDeclarativeGeometry=a=>{t._cadMaterialize?.(a),t._lodMaterialize?.(a)}),d}var Ne=Oe(),vr=Ne.decimateGeometry,Ye=Ne.selectLodLevelIndex,Je=Ne.parseLod,ii=Ne.materializeLodGeometry,xr=Ne.LOD,Ie=new WeakMap;function Mr(e){return e&&typeof e=="object"?Ie.get(e):void 0}var At=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let n=t.get(i.nodeIndex);n||(n=[],t.set(i.nodeIndex,n)),n.push(i)}let r=i=>{let n=[],s=new Set,m=[i];for(;m.length>0;){let c=m.pop();if(s.has(c)||c<0||c>=e.length)continue;s.add(c);let o=t.get(c);o&&n.push(...o);let d=e[c]?.children;if(Array.isArray(d))for(let a=d.length-1;a>=0;a--)typeof d[a]=="number"&&m.push(d[a])}return n};for(let i=0;i<e.length;i++){let n=e[i];if(!n||typeof n!="object")continue;let s=n.extras?.xr?.lod??n.extensions?.ANDROID_xr_scenecore?.lod??n.extensions?.MOZ_hubs_components?.lod,m=Array.isArray(n.extensions?.MSFT_lod?.ids)?n.extensions.MSFT_lod.ids.filter(h=>typeof h=="number"&&Number.isInteger(h)&&h>=0&&h<e.length):[],c=Je(s);if(!c&&m.length>0&&(c=Je({distances:m.map((h,f)=>f*4)})),!c)continue;let o=m.length>0?m:Array.isArray(n.children)?n.children.filter(h=>typeof h=="number"&&Number.isInteger(h)&&h>=0&&h<e.length):[],d=[],a=[];if(o.length>0){let h=Math.min(o.length,c.levels.length);for(let f=0;f<h;f++){let g=o[f];d.push(g),a.push(r(g))}}else{let h=t.get(i)??[];if(h.length===0)continue;d.push(i),a.push(h)}let u=c.distances.slice(0,a.length);u.length===0&&u.push(0);let l={nodeIndex:i,name:typeof n.name=="string"?n.name:`LOD_${i}`,distances:u,hysteresis:c.hysteresis,...c.cullDistance!==void 0?{cullDistance:c.cullDistance}:{},childNodeIndices:d,levelMeshes:a,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(l,0),this.groups.push(l)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let n=Ye(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=n,this.applyGroupVisibility(r,n);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let n=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,s=n&&n[12]||0,m=n&&n[13]||0,c=n&&n[14]||0,o=r?r[0]*s+r[4]*m+r[8]*c+r[12]:s,d=r?r[1]*s+r[5]*m+r[9]*c+r[13]:m,a=r?r[2]*s+r[6]*m+r[10]*c+r[14]:c,u=Math.hypot((e[0]||0)-o,(e[1]||0)-d,(e[2]||0)-a);if(i.lastDistance=u,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let l=Ye(i.distances,u,i.activeLevelIndex,i.hysteresis,i.cullDistance);l!==i.activeLevelIndex&&(i.activeLevelIndex=l,this.applyGroupVisibility(i,l))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let n=i===t;for(let c of e.levelMeshes[i])c.visible=n;let s=e.childNodeIndices[i],m=Array.isArray(r)?r[s]:null;m&&typeof m=="object"&&(m.visible=n,m.extensions=m.extensions||{},m.extensions.KHR_node_visibility={visible:n})}}},Tt={name:"lod",onRegister(){er(Oe);let e=ye(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);Oe(t,e)},onLoadModel(e,t){!e||typeof e!="object"||Ie.set(e,new At(e,t))},onUpdate(e){let t=Ie.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},n=r?.radius??3,s=r?.phi??0,m=r?.theta??0,c=Math.cos(s),o=(i.x||0)+n*c*Math.sin(m),d=(i.y||0)+n*Math.sin(s),a=(i.z||0)+n*c*Math.cos(m);t.update([o,d,a])},onBeforeDrawScene(e,t,r,i){let n=Ie.get(e);n&&n.update(i)},onDestroy(e,t){t&&typeof t=="object"&&Ie.delete(t)}},Le=new Map,$e=new WeakMap;function wr(e,t){Le.set(e,t)}var St={name:"materials",onContextRestored(e){$e.delete(e)},onBuildPrimitiveVAO(e,t,r,i,n){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=$e.get(e);r||(r=e.createTexture(),$e.set(e,r));let i=Math.max(1,t.canvas.width),n=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,n,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&Le.has(t.name)){let f=Le.get(t.name);return{vs:f.vs||r,fs:f.fs||i}}let n=t.extensions||{},s=n.KHR_materials_clearcoat,m=n.KHR_materials_sheen,c=!!n.KHR_materials_transmission,o=!!n.KHR_materials_ior,d=n.KHR_materials_iridescence;if(!s&&!m&&!n.KHR_materials_unlit&&!c&&!n.KHR_materials_volume&&!o&&!n.KHR_materials_dispersion&&!d)return null;if(n.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let a=i;if(c){let f=a.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
32
+ `;a=a.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
33
+ ${f}out vec4 fragColor;`)}let u=(f,g,A=0,v=1e6,S=3)=>{let p=Number(f);return(Number.isFinite(p)?Math.min(v,Math.max(A,p)):g).toFixed(S)},l=Number(n.KHR_materials_ior?.ior??1.5),h=Number.isFinite(l)?Math.min(10,Math.max(1,l)):1.5;if(o){let f=Math.pow((h-1)/(h+1),2);a=a.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${u(f,.04,0,1,4)}),base.rgb,metallic);`)}if(d){let f=u(d.iridescenceFactor,1,0,1),g=u(d.iridescenceIor,1.3,1,10);a=a.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${g}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${f}*pow(1.-NoV,2.));`)}if(c){let f=u(n.KHR_materials_transmission?.transmissionFactor,1,0,1),g=n.KHR_materials_volume||{},A=u(g.thicknessFactor,.5,0,1e4),v=u(g.attenuationDistance,1,.001,1e6),S=Array.isArray(g.attenuationColor)?g.attenuationColor:[1,1,1],p=u(n.KHR_materials_dispersion?.dispersion,0,0,10);a=a.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
34
+ vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${u(h,1.5,1,10)},dV=${p},tV=${A},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
36
35
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
37
36
  vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
38
- vec3 aCol=vec3(${d(I[0],1,0,1)},${d(I[1],1,0,1)},${d(I[2],1,0,1)});
39
- vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${E},.001));
40
- diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${p});`)}if(a&&!r.includes("uClearcoat")){let p=d(a.clearcoatFactor,1,0,1),m=d(a.clearcoatRoughnessFactor,0,0,1);s=s.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${m},NoV)*${p};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${m})*ccF;fragColor=vec4(color,base.a);`)}if(l){let p=Array.isArray(l.sheenColorFactor)?l.sheenColorFactor:[1,1,1],m=`color+=vec3(${d(p[0],1,0,1)},${d(p[1],1,0,1)},${d(p[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;s.includes("color=applyToneMapping(color,uToneMapping);")?s=s.replace("color=applyToneMapping(color,uToneMapping);",`${m}color=applyToneMapping(color,uToneMapping);`):s=s.replace("fragColor=vec4(color,base.a);",`${m}fragColor=vec4(color,base.a);`)}return{vs:n,fs:s}},onBeforeDrawPrimitive(e,t,n,r,o,a){let l=n.materialIndex;if(l!==void 0&&a?.materials){let u=a.materials[l];u?.name&&pe.has(u.name)&&pe.get(u.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let u=Re.get(e);if(u){e.activeTexture(33990),e.bindTexture(3553,u);let i=e.getUniformLocation(t,"uTransmissionTex");i&&e.uniform1i(i,6);let c=e.getUniformLocation(t,"uViewportSize");c&&e.uniform2f(c,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var bt=64*1024*1024,ht=128*1024*1024,nn=16777216;function rn(e){return(e>>>1^-(e&1))&255}function on(e){return(e>>>1^-(e&1))&65535}function an(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function yt(e){return(e<<1^e>>31)>>>0}function Tt(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw X(`unknown filter "${String(e)}"`)}var H=Math.fround;function me(e){return Math.trunc(H(e+(e>=0?.5:-.5)))}function At(e,t,n,r="NONE"){if(Tt(r),!r||r==="NONE"||t<=0)return;let o=new DataView(e.buffer,e.byteOffset,e.byteLength);if(r==="OCTAHEDRAL"){if(n!==4&&n!==8)throw X(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let d=n===8,f=d?32767:127,b=x=>d?o.getInt16(x,!0):o.getInt8(x),p=(x,E)=>d?o.setInt16(x,E,!0):o.setInt8(x,E<<24>>24),m=d?2:1;for(let x=0;x<t;x++){let E=x*n,I=b(E),v=b(E+m),S=H(b(E+2*m)-Math.abs(I)-Math.abs(v)),w=S>=0?0:S;I=H(I+(I>=0?w:-w)),v=H(v+(v>=0?w:-w));let U=H(Math.sqrt(H(H(H(I*I)+H(v*v))+H(S*S))));if(U===0){p(E,0),p(E+m,0),p(E+2*m,f);continue}let V=H(f/U);p(E,me(H(I*V))),p(E+m,me(H(v*V))),p(E+2*m,me(H(S*V)))}return}if(r==="QUATERNION"){if(n!==8)throw X(`QUATERNION filter requires byteStride 8 (got ${n})`);let d=H(32767/H(Math.SQRT2));for(let f=0;f<t;f++){let b=f*8,p=o.getInt16(b+6,!0),m=p|3,x=o.getInt16(b,!0),E=o.getInt16(b+2,!0),I=o.getInt16(b+4,!0),v=H(m*m),S=H(H(H(H(v*2)-H(x*x))-H(E*E))-H(I*I)),w=H(Math.sqrt(S>=0?S:0)),U=H(d/m),V=p&3,O=[0,0,0,0];O[V+1&3]=me(H(x*U)),O[V+2&3]=me(H(E*U)),O[V+3&3]=me(H(I*U)),O[V]=Math.trunc(H(H(w*U)+.5));for(let N=0;N<4;N++)o.setInt16(b+N*2,O[N]<<16>>16,!0)}return}if(r==="EXPONENTIAL"){if(n<4||n%4!==0)throw X(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let d=t*n>>>2;for(let f=0;f<d;f++){let b=f*4,p=o.getUint32(b,!0),m=p<<8>>8,x=p>>24;o.setUint32(b,x+127<<23>>>0,!0);let E=o.getFloat32(b,!0);o.setFloat32(b,H(E*m),!0)}return}if(n!==4&&n!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${n})`);let a=n===8,l=a?65535:255,u=d=>a?o.getUint16(d,!0):o.getUint8(d),i=d=>a?o.getInt16(d,!0):o.getInt8(d),c=(d,f)=>a?o.setUint16(d,f&65535,!0):o.setUint8(d,f&255),s=a?2:1;for(let d=0;d<t;d++){let f=d*n,b=u(f+3*s);b|=b>>1,b|=b>>2,b|=b>>4,b|=b>>8;let p=u(f),m=i(f+s),x=i(f+2*s),E=p+m-x,I=p+x,v=p-m-x,S=u(f+3*s);S=S<<1&b|S&1;let w=b===0?0:H(l/b);c(f,Math.trunc(H(H(E*w)+.5))),c(f+s,Math.trunc(H(H(I*w)+.5))),c(f+2*s,Math.trunc(H(H(v*w)+.5))),c(f+3*s,Math.trunc(H(H(S*w)+.5)))}}var vt=160,ee=16,sn=24,wt=32,cn=24,ln=[0,2,4,8],un=[0,1,2,4,8];function Et(e){let t=Math.floor(8192/e)&~(ee-1);return t<256?t:256}function X(e){return new Error(`EXT_meshopt_compression: ${e}`)}function fn(e,t,n,r,o){if(o===0)return n.fill(0,r,r+ee),t;if(o===8)return n.set(e.subarray(t,t+ee),r),t+ee;let a=(1<<o)-1,l=8/o,u=t+ee*o/8;for(let i=0;i<ee;i++){let c=e[t+Math.floor(i/l)],s=i%l,d=o===1?c>>s&1:c>>8-o-s*o&a;n[r+i]=d===a?e[u++]:d}return u}function gt(e,t,n,r,o,a,l,u){let i=a/ee,c=i+3>>2;if(n-t<c)throw X("truncated ATTRIBUTES stream");let s=t;t+=c;for(let d=0;d<i;d++){if(n-t<sn)throw X("truncated ATTRIBUTES stream");let f=e[s+(d>>2)]>>(d&3)*2&3;t=fn(e,t,r,o+d*ee,l[u+f])}return t}function dn(e,t,n,r){if(n%4!==0||n>256)throw X(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let o=e.byteLength;if(o<1)throw X("truncated ATTRIBUTES stream");let a=e[0];if((a&240)!==vt)throw X(`unsupported ATTRIBUTES header 0x${a.toString(16)}`);let l=a&15;if(l>1)throw X(`unsupported ATTRIBUTES codec version ${l}`);let u=n+(l===0?0:n/4),i=l===0?wt:cn,c=u<i?i:u;if(o-1<c)throw X("truncated ATTRIBUTES stream");let s=o-u,d=e.slice(s,s+n),f=s+n,b=Et(n),p=new Uint8Array(256*4),m=1;for(let x=0;x<t;){let E=Math.min(b,t-x),I=E+ee-1&~(ee-1),v=l===0?0:n/4;if(o-m<v)throw X("truncated ATTRIBUTES stream");let S=m;m+=v;for(let w=0;w<n;w+=4){let U=l===0?0:e[S+w/4];for(let N=0;N<4;N++){let P=U>>N*2&3;if(P===3){if(o-m<E)throw X("truncated ATTRIBUTES stream");p.set(e.subarray(m,m+E),N*E),m+=E}else P===2?p.fill(0,N*E,N*E+E):m=l===0?gt(e,m,o,p,N*E,I,ln,0):gt(e,m,o,p,N*E,I,un,P)}let V=l===0?0:e[f+w/4],O=V&3;if(O===0)for(let N=0;N<4;N++){let P=d[w+N];for(let C=0;C<E;C++)P=rn(p[N*E+C])+P&255,r[(x+C)*n+w+N]=P}else if(O===1)for(let N=0;N<4;N+=2){let P=d[w+N]|d[w+N+1]<<8,C=N*E;for(let z=0;z<E;z++){let W=p[C+z]|p[C+E+z]<<8;P=on(W)+P&65535;let B=(x+z)*n+w+N;r[B]=P&255,r[B+1]=P>>8}}else if(O===2){let N=32-(V>>4)&31,P=(d[w]|d[w+1]<<8|d[w+2]<<16|d[w+3]<<24)>>>0;for(let C=0;C<E;C++){let z=(p[C]|p[E+C]<<8|p[2*E+C]<<16|p[3*E+C]<<24)>>>0;z=((z<<N|z>>>(32-N&31))^P)>>>0,P=z;let W=(x+C)*n+w;r[W]=z&255,r[W+1]=z>>>8&255,r[W+2]=z>>>16&255,r[W+3]=z>>>24}}else throw X(`invalid ATTRIBUTES channel ${V}`)}d.set(r.subarray((x+E-1)*n,(x+E)*n)),x+=E}if(o-m!==c)throw X("ATTRIBUTES trailing data")}var St=224,Mt=208;function Rt(e,t){let n=e[t.pos++]??0;if(n<128)return n;let r=n&127,o=7;for(let a=0;a<4;a++){let l=e[t.pos++]??0;if(r=(r|(l&127)<<o)>>>0,o+=7,l<128)break}return r>>>0}function _e(e,t,n){let r=Rt(e,t),o=r>>>1^-(r&1);return n+o>>>0}function mn(e,t,n){if(t%3!==0)throw X(`TRIANGLES count must be divisible by 3 (got ${t})`);let r=t/3;if(e.byteLength<1+r+16)throw X("truncated TRIANGLES stream");let o=e[0];if((o&240)!==St)throw X(`unsupported TRIANGLES header 0x${o.toString(16)}`);let a=o&15;if(a>1)throw X(`unsupported TRIANGLES codec version ${a}`);let l=new Uint32Array(16).fill(4294967295),u=new Uint32Array(16).fill(4294967295),i=new Uint32Array(16).fill(4294967295),c=0,s=0,d=(U,V)=>{l[c]=U,u[c]=V,c=c+1&15},f=(U,V=1)=>{i[s]=U,s=s+V&15},b=0,p=0,m=a>=1?13:15,x=1+r,E=e.byteLength-16,I=E,v={pos:x},S=0,w=(U,V,O)=>{n(S++,U),n(S++,V),n(S++,O)};for(let U=1;U<x;U++){let V=e[U];if(V<240){let O=V>>4,N=c-1-O&15,P=l[N],C=u[N],z=0,W=V&15;if(W<m){let B=i[s-1-W&15];z=W===0?b:B;let oe=W===0?1:0;b=b+oe>>>0,f(z,oe)}else{if(v.pos>E)throw X("truncated TRIANGLES stream");z=W!==15?p+(W*2-27)>>>0:_e(e,v,p),p=z,f(z)}d(z,C),d(P,z),w(P,C,z)}else if(V<254){let O=e[I+(V&15)],N=O>>4,P=O&15,C=b;b=b+1>>>0;let z=i[s-N&15],W=N===0?b:z,B=N===0?1:0;b=b+B>>>0;let oe=i[s-P&15],ne=P===0?b:oe,ie=P===0?1:0;b=b+ie>>>0,w(C,W,ne),f(C),f(W,B),f(ne,ie),d(W,C),d(ne,W),d(C,ne)}else{if(v.pos>E)throw X("truncated TRIANGLES stream");let O=e[v.pos++],N=V===254?0:15,P=O>>4,C=O&15;O===0&&(b=0);let z=0;N===0&&(z=b,b=b+1>>>0);let W;P===0?(W=b,b=b+1>>>0):W=i[s-P&15];let B;C===0?(B=b,b=b+1>>>0):B=i[s-C&15],N===15&&(p=z=_e(e,v,p)),P===15&&(p=W=_e(e,v,p)),C===15&&(p=B=_e(e,v,p)),w(z,W,B),f(z),f(W,P===0||P===15?1:0),f(B,C===0||C===15?1:0),d(W,z),d(B,W),d(z,B)}}if(v.pos!==E)throw X("TRIANGLES trailing data")}function pn(e,t,n){if(e.byteLength<1+t+4)throw X("truncated INDICES stream");let r=e[0];if((r&240)!==Mt)throw X(`unsupported INDICES header 0x${r.toString(16)}`);let o=r&15;if(o>1)throw X(`unsupported INDICES codec version ${o}`);let a=e.byteLength-4,l=[0,0],u={pos:1};for(let i=0;i<t;i++){if(u.pos>=a)throw X("truncated INDICES stream");let c=Rt(e,u),s=c&1;c>>>=1;let d=c>>>1^-(c&1),f=l[s]+d>>>0;l[s]=f,n(i,f)}if(u.pos!==a)throw X("INDICES trailing data")}function _t(e,t,n,r,o="NONE"){if(Tt(o),!Number.isInteger(t)||t<0||t>nn||!Number.isInteger(n)||n<=0||n>256)throw X(`invalid count (${t}) or byteStride (${n})`);let a=t*n;if(a>bt)throw X(`decompressed size (${a}) exceeds MAX_MESHOPT_BUFFER_BYTES (${bt})`);if(t===0)return new Uint8Array(0);let l=new Uint8Array(a);if(r==="ATTRIBUTES")return dn(e,t,n,l),At(l,t,n,o),l;if(r==="TRIANGLES"||r==="INDICES"){if(n!==2&&n!==4)throw X(`${r} byteStride must be 2 or 4 (got ${n})`);if(o&&o!=="NONE")throw X(`filter ${o} is only valid for ATTRIBUTES`);let u=new DataView(l.buffer),i=n===2?(c,s)=>u.setUint16(c*2,s&65535,!0):(c,s)=>u.setUint32(c*4,s>>>0,!0);return r==="TRIANGLES"?mn(e,t,i):pn(e,t,i),l}throw X(`unknown mode "${String(r)}"`)}function xt(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function bn(e,t,n,r){let o=t*n;if(e.byteLength<o)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${o})`);if(r==="ATTRIBUTES"){if(n%4!==0||n>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let u=[vt],i=Et(n),c=new Uint8Array(n);t>0&&c.set(e.subarray(0,n));let s=c.slice(),d=new Uint8Array(256);for(let f=0;f<t;){let b=Math.min(i,t-f),p=b+15&-16;for(let m=0;m<n;m++){d.fill(0);let x=c[m];for(let v=0;v<b;v++){let S=e[(f+v)*n+m];d[v]=an(S-x&255),x=S}c[m]=x;let E=p/16,I=u.length;for(let v=0;v<E+3>>2;v++)u.push(0);for(let v=0;v<E;v++){let S=d.subarray(v*16,v*16+16);if(!S.every(w=>w===0)){u[I+(v>>2)]|=3<<(v&3)*2;for(let w of S)u.push(w)}}}f+=b}for(let f=n;f<wt;f++)u.push(0);for(let f=0;f<n;f++)u.push(s[f]);return new Uint8Array(u)}if(n!==2&&n!==4)throw new Error(`encodeMeshoptBuffer: ${r} byteStride must be 2 or 4 (got ${n})`);let a=new DataView(e.buffer,e.byteOffset,e.byteLength),l=u=>n===2?a.getUint16(u*2,!0):a.getUint32(u*4,!0);if(r==="INDICES"){let u=[Mt|1],i=0;for(let c=0;c<t;c++){let s=l(c),d=s-i|0;i=s,xt(u,yt(d)<<1>>>0)}return u.push(0,0,0,0),new Uint8Array(u)}if(r==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let u=t/3,i=[St|1];for(let s=0;s<u;s++)i.push(255);let c=0;for(let s=0;s<u;s++){i.push(255);for(let d=0;d<3;d++){let f=l(s*3+d);xt(i,yt(f-c|0)),c=f}}for(let s=0;s<16;s++)i.push(0);return new Uint8Array(i)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(r)}"`)}function Xe(e,t){let n=t&&typeof t=="object"?t:e,r=t&&typeof t=="object"?e:n?.gltf;if(!r||!Array.isArray(r.bufferViews))return;let o=new Uint8Array(n.bin),a=[],l=0;for(let d=0;d<r.bufferViews.length;d++){let f=r.bufferViews[d],b=f?.extensions?.KHR_meshopt_compression,p=b??f?.extensions?.EXT_meshopt_compression;if(!p||typeof p!="object")continue;let m=b?"KHR_meshopt_compression":"EXT_meshopt_compression",x=Number(p.count),E=Number(p.byteStride),I=Number(p.byteOffset??0),v=Number(p.byteLength??0),S=p.mode||"ATTRIBUTES",w=p.filter||"NONE";if(w==="COLOR"&&!b)throw X(`bufferView ${d} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(p.buffer??0)!==0)throw new Error(`${m}: bufferView ${d} references buffer ${String(p.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(I)||I<0||!Number.isInteger(v)||v<0||I+v>o.byteLength)throw new Error(`${m}: bufferView ${d} compressed range [${I}, ${I+v}] out of bounds (${o.byteLength})`);let U=x*E;if(l+=U,l>ht)throw X(`total decompressed size (${l}) exceeds MAX_MESHOPT_TOTAL_BYTES (${ht})`);let V=o.subarray(I,I+v),O=_t(V,x,E,S,w);a.push({index:d,bytes:O,ext:p})}if(a.length===0)return;let u=o.byteLength+3&-4,i=0;for(let d of a)i+=d.bytes.byteLength+3&-4;let c=new Uint8Array(u+i);c.set(o,0);let s=u;for(let d of a){c.set(d.bytes,s);let f=r.bufferViews[d.index];f.buffer=0,f.byteOffset=s,f.byteLength=d.bytes.byteLength,f._decoded=d.bytes,d.ext.mode==="ATTRIBUTES"&&f.byteStride===void 0&&(f.byteStride=Number(d.ext.byteStride)),f.extensions&&(delete f.extensions.EXT_meshopt_compression,delete f.extensions.KHR_meshopt_compression),s+=d.bytes.byteLength+3&-4}n.bin=c.buffer}var $e={decodeBufferViews(e,t){Xe(t)},decodePrimitive(e,t,n){let r=t?.extensions;r?.EXT_meshopt_compression&&delete r.EXT_meshopt_compression,r?.KHR_meshopt_compression&&delete r.KHR_meshopt_compression}};ce().decoders.set("meshopt",$e);var It={name:"meshopt",onParseGLB(e){ce().decoders.set("meshopt",$e),Xe(e)}};function Ie(e,t,n,r=!0){let o=[],a=null;try{for(let[l,u]of[[35633,t],[35632,n]]){let i=e.createShader(l);if(!i){if(r)throw new Error("Shader allocation failed");return null}if(o.push(i),e.shaderSource(i,u),e.compileShader(i),e.getShaderParameter&&!e.getShaderParameter(i,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(i)}`);return null}}if(a=e.createProgram(),!a){if(r)throw new Error("Program allocation failed");return null}for(let l of o)e.attachShader(a,l);if(e.linkProgram(a),e.getProgramParameter&&!e.getProgramParameter(a,35714)){let l=r?e.getProgramInfoLog(a):null;if(e.deleteProgram?.(a),a=null,r)throw new Error(`Program link error: ${l}`);return null}return a}finally{for(let l of o)a&&e.detachShader?.(a,l),e.deleteShader?.(l)}}function je(e,t){let n=e?.trim(),r=n?Number(n):NaN;return Number.isFinite(r)?r:t}var gn=`#version 300 es
37
+ vec3 aCol=vec3(${u(S[0],1,0,1)},${u(S[1],1,0,1)},${u(S[2],1,0,1)});
38
+ vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${v},.001));
39
+ diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${f});`)}if(s&&!i.includes("uClearcoat")){let f=u(s.clearcoatFactor,1,0,1),g=u(s.clearcoatRoughnessFactor,0,0,1);a=a.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${g},NoV)*${f};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${g})*ccF;fragColor=vec4(color,base.a);`)}if(m){let f=Array.isArray(m.sheenColorFactor)?m.sheenColorFactor:[1,1,1],g=`color+=vec3(${u(f[0],1,0,1)},${u(f[1],1,0,1)},${u(f[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;a.includes("color=applyToneMapping(color,uToneMapping);")?a=a.replace("color=applyToneMapping(color,uToneMapping);",`${g}color=applyToneMapping(color,uToneMapping);`):a=a.replace("fragColor=vec4(color,base.a);",`${g}fragColor=vec4(color,base.a);`)}return{vs:r,fs:a}},onBeforeDrawPrimitive(e,t,r,i,n,s){let m=r.materialIndex;if(m!==void 0&&s?.materials){let c=s.materials[m];c?.name&&Le.has(c.name)&&Le.get(c.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let c=$e.get(e);if(c){e.activeTexture(33990),e.bindTexture(3553,c);let o=e.getUniformLocation(t,"uTransmissionTex");o&&e.uniform1i(o,6);let d=e.getUniformLocation(t,"uViewportSize");d&&e.uniform2f(d,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},Nt=64*1024*1024,It=128*1024*1024,Ar=16777216;function Tr(e){return(e>>>1^-(e&1))&255}function Sr(e){return(e>>>1^-(e&1))&65535}function Nr(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Lt(e){return(e<<1^e>>31)>>>0}function Et(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw q(`unknown filter "${String(e)}"`)}var j=Math.fround;function we(e){return Math.trunc(j(e+(e>=0?.5:-.5)))}function Pt(e,t,r,i="NONE"){if(Et(i),!i||i==="NONE"||t<=0)return;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw q(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let u=r===8,l=u?32767:127,h=A=>u?n.getInt16(A,!0):n.getInt8(A),f=(A,v)=>u?n.setInt16(A,v,!0):n.setInt8(A,v<<24>>24),g=u?2:1;for(let A=0;A<t;A++){let v=A*r,S=h(v),p=h(v+g),b=j(h(v+2*g)-Math.abs(S)-Math.abs(p)),y=b>=0?0:b;S=j(S+(S>=0?y:-y)),p=j(p+(p>=0?y:-y));let L=j(Math.sqrt(j(j(j(S*S)+j(p*p))+j(b*b))));if(L===0){f(v,0),f(v+g,0),f(v+2*g,l);continue}let C=j(l/L);f(v,we(j(S*C))),f(v+g,we(j(p*C))),f(v+2*g,we(j(b*C)))}return}if(i==="QUATERNION"){if(r!==8)throw q(`QUATERNION filter requires byteStride 8 (got ${r})`);let u=j(32767/j(Math.SQRT2));for(let l=0;l<t;l++){let h=l*8,f=n.getInt16(h+6,!0),g=f|3,A=n.getInt16(h,!0),v=n.getInt16(h+2,!0),S=n.getInt16(h+4,!0),p=j(g*g),b=j(j(j(j(p*2)-j(A*A))-j(v*v))-j(S*S)),y=j(Math.sqrt(b>=0?b:0)),L=j(u/g),C=f&3,F=[0,0,0,0];F[C+1&3]=we(j(A*L)),F[C+2&3]=we(j(v*L)),F[C+3&3]=we(j(S*L)),F[C]=Math.trunc(j(j(y*L)+.5));for(let _=0;_<4;_++)n.setInt16(h+_*2,F[_]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw q(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let u=t*r>>>2;for(let l=0;l<u;l++){let h=l*4,f=n.getUint32(h,!0),g=f<<8>>8,A=f>>24;n.setUint32(h,A+127<<23>>>0,!0);let v=n.getFloat32(h,!0);n.setFloat32(h,j(v*g),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let s=r===8,m=s?65535:255,c=u=>s?n.getUint16(u,!0):n.getUint8(u),o=u=>s?n.getInt16(u,!0):n.getInt8(u),d=(u,l)=>s?n.setUint16(u,l&65535,!0):n.setUint8(u,l&255),a=s?2:1;for(let u=0;u<t;u++){let l=u*r,h=c(l+3*a);h|=h>>1,h|=h>>2,h|=h>>4,h|=h>>8;let f=c(l),g=o(l+a),A=o(l+2*a),v=f+g-A,S=f+A,p=f-g-A,b=c(l+3*a);b=b<<1&h|b&1;let y=h===0?0:j(m/h);d(l,Math.trunc(j(j(v*y)+.5))),d(l+a,Math.trunc(j(j(S*y)+.5))),d(l+2*a,Math.trunc(j(j(p*y)+.5))),d(l+3*a,Math.trunc(j(j(b*y)+.5)))}}var _t=160,ce=16,Ir=24,Vt=32,Lr=24,Er=[0,2,4,8],Pr=[0,1,2,4,8];function Rt(e){let t=Math.floor(8192/e)&~(ce-1);return t<256?t:256}function q(e){return new Error(`EXT_meshopt_compression: ${e}`)}function _r(e,t,r,i,n){if(n===0)return r.fill(0,i,i+ce),t;if(n===8)return r.set(e.subarray(t,t+ce),i),t+ce;let s=(1<<n)-1,m=8/n,c=t+ce*n/8;for(let o=0;o<ce;o++){let d=e[t+Math.floor(o/m)],a=o%m,u=n===1?d>>a&1:d>>8-n-a*n&s;r[i+o]=u===s?e[c++]:u}return c}function Ct(e,t,r,i,n,s,m,c){let o=s/ce,d=o+3>>2;if(r-t<d)throw q("truncated ATTRIBUTES stream");let a=t;t+=d;for(let u=0;u<o;u++){if(r-t<Ir)throw q("truncated ATTRIBUTES stream");let l=e[a+(u>>2)]>>(u&3)*2&3;t=_r(e,t,i,n+u*ce,m[c+l])}return t}function Vr(e,t,r,i){if(r%4!==0||r>256)throw q(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw q("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==_t)throw q(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let m=s&15;if(m>1)throw q(`unsupported ATTRIBUTES codec version ${m}`);let c=r+(m===0?0:r/4),o=m===0?Vt:Lr,d=c<o?o:c;if(n-1<d)throw q("truncated ATTRIBUTES stream");let a=n-c,u=e.slice(a,a+r),l=a+r,h=Rt(r),f=new Uint8Array(256*4),g=1;for(let A=0;A<t;){let v=Math.min(h,t-A),S=v+ce-1&~(ce-1),p=m===0?0:r/4;if(n-g<p)throw q("truncated ATTRIBUTES stream");let b=g;g+=p;for(let y=0;y<r;y+=4){let L=m===0?0:e[b+y/4];for(let _=0;_<4;_++){let U=L>>_*2&3;if(U===3){if(n-g<v)throw q("truncated ATTRIBUTES stream");f.set(e.subarray(g,g+v),_*v),g+=v}else U===2?f.fill(0,_*v,_*v+v):g=m===0?Ct(e,g,n,f,_*v,S,Er,0):Ct(e,g,n,f,_*v,S,Pr,U)}let C=m===0?0:e[l+y/4],F=C&3;if(F===0)for(let _=0;_<4;_++){let U=u[y+_];for(let D=0;D<v;D++)U=Tr(f[_*v+D])+U&255,i[(A+D)*r+y+_]=U}else if(F===1)for(let _=0;_<4;_+=2){let U=u[y+_]|u[y+_+1]<<8,D=_*v;for(let $=0;$<v;$++){let z=f[D+$]|f[D+v+$]<<8;U=Sr(z)+U&65535;let O=(A+$)*r+y+_;i[O]=U&255,i[O+1]=U>>8}}else if(F===2){let _=32-(C>>4)&31,U=(u[y]|u[y+1]<<8|u[y+2]<<16|u[y+3]<<24)>>>0;for(let D=0;D<v;D++){let $=(f[D]|f[v+D]<<8|f[2*v+D]<<16|f[3*v+D]<<24)>>>0;$=(($<<_|$>>>(32-_&31))^U)>>>0,U=$;let z=(A+D)*r+y;i[z]=$&255,i[z+1]=$>>>8&255,i[z+2]=$>>>16&255,i[z+3]=$>>>24}}else throw q(`invalid ATTRIBUTES channel ${C}`)}u.set(i.subarray((A+v-1)*r,(A+v)*r)),A+=v}if(n-g!==d)throw q("ATTRIBUTES trailing data")}var Dt=224,Ft=208;function Ut(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,n=7;for(let s=0;s<4;s++){let m=e[t.pos++]??0;if(i=(i|(m&127)<<n)>>>0,n+=7,m<128)break}return i>>>0}function Be(e,t,r){let i=Ut(e,t),n=i>>>1^-(i&1);return r+n>>>0}function Rr(e,t,r){if(t%3!==0)throw q(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw q("truncated TRIANGLES stream");let n=e[0];if((n&240)!==Dt)throw q(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw q(`unsupported TRIANGLES codec version ${s}`);let m=new Uint32Array(16).fill(4294967295),c=new Uint32Array(16).fill(4294967295),o=new Uint32Array(16).fill(4294967295),d=0,a=0,u=(L,C)=>{m[d]=L,c[d]=C,d=d+1&15},l=(L,C=1)=>{o[a]=L,a=a+C&15},h=0,f=0,g=s>=1?13:15,A=1+i,v=e.byteLength-16,S=v,p={pos:A},b=0,y=(L,C,F)=>{r(b++,L),r(b++,C),r(b++,F)};for(let L=1;L<A;L++){let C=e[L];if(C<240){let F=C>>4,_=d-1-F&15,U=m[_],D=c[_],$=0,z=C&15;if(z<g){let O=o[a-1-z&15];$=z===0?h:O;let te=z===0?1:0;h=h+te>>>0,l($,te)}else{if(p.pos>v)throw q("truncated TRIANGLES stream");$=z!==15?f+(z*2-27)>>>0:Be(e,p,f),f=$,l($)}u($,D),u(U,$),y(U,D,$)}else if(C<254){let F=e[S+(C&15)],_=F>>4,U=F&15,D=h;h=h+1>>>0;let $=o[a-_&15],z=_===0?h:$,O=_===0?1:0;h=h+O>>>0;let te=o[a-U&15],Z=U===0?h:te,W=U===0?1:0;h=h+W>>>0,y(D,z,Z),l(D),l(z,O),l(Z,W),u(z,D),u(Z,z),u(D,Z)}else{if(p.pos>v)throw q("truncated TRIANGLES stream");let F=e[p.pos++],_=C===254?0:15,U=F>>4,D=F&15;F===0&&(h=0);let $=0;_===0&&($=h,h=h+1>>>0);let z;U===0?(z=h,h=h+1>>>0):z=o[a-U&15];let O;D===0?(O=h,h=h+1>>>0):O=o[a-D&15],_===15&&(f=$=Be(e,p,f)),U===15&&(f=z=Be(e,p,f)),D===15&&(f=O=Be(e,p,f)),y($,z,O),l($),l(z,U===0||U===15?1:0),l(O,D===0||D===15?1:0),u(z,$),u(O,z),u($,O)}}if(p.pos!==v)throw q("TRIANGLES trailing data")}function Cr(e,t,r){if(e.byteLength<1+t+4)throw q("truncated INDICES stream");let i=e[0];if((i&240)!==Ft)throw q(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw q(`unsupported INDICES codec version ${n}`);let s=e.byteLength-4,m=[0,0],c={pos:1};for(let o=0;o<t;o++){if(c.pos>=s)throw q("truncated INDICES stream");let d=Ut(e,c),a=d&1;d>>>=1;let u=d>>>1^-(d&1),l=m[a]+u>>>0;m[a]=l,r(o,l)}if(c.pos!==s)throw q("INDICES trailing data")}function kt(e,t,r,i,n="NONE"){if(Et(n),!Number.isInteger(t)||t<0||t>Ar||!Number.isInteger(r)||r<=0||r>256)throw q(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>Nt)throw q(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${Nt})`);if(t===0)return new Uint8Array(0);let m=new Uint8Array(s);if(i==="ATTRIBUTES")return Vr(e,t,r,m),Pt(m,t,r,n),m;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw q(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw q(`filter ${n} is only valid for ATTRIBUTES`);let c=new DataView(m.buffer),o=r===2?(d,a)=>c.setUint16(d*2,a&65535,!0):(d,a)=>c.setUint32(d*4,a>>>0,!0);return i==="TRIANGLES"?Rr(e,t,o):Cr(e,t,o),m}throw q(`unknown mode "${String(i)}"`)}function Ot(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Dr(e,t,r,i){let n=t*r;if(e.byteLength<n)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${n})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let c=[_t],o=Rt(r),d=new Uint8Array(r);t>0&&d.set(e.subarray(0,r));let a=d.slice(),u=new Uint8Array(256);for(let l=0;l<t;){let h=Math.min(o,t-l),f=h+15&-16;for(let g=0;g<r;g++){u.fill(0);let A=d[g];for(let p=0;p<h;p++){let b=e[(l+p)*r+g];u[p]=Nr(b-A&255),A=b}d[g]=A;let v=f/16,S=c.length;for(let p=0;p<v+3>>2;p++)c.push(0);for(let p=0;p<v;p++){let b=u.subarray(p*16,p*16+16);if(!b.every(y=>y===0)){c[S+(p>>2)]|=3<<(p&3)*2;for(let y of b)c.push(y)}}}l+=h}for(let l=r;l<Vt;l++)c.push(0);for(let l=0;l<r;l++)c.push(a[l]);return new Uint8Array(c)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let s=new DataView(e.buffer,e.byteOffset,e.byteLength),m=c=>r===2?s.getUint16(c*2,!0):s.getUint32(c*4,!0);if(i==="INDICES"){let c=[Ft|1],o=0;for(let d=0;d<t;d++){let a=m(d),u=a-o|0;o=a,Ot(c,Lt(u)<<1>>>0)}return c.push(0,0,0,0),new Uint8Array(c)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let c=t/3,o=[Dt|1];for(let a=0;a<c;a++)o.push(255);let d=0;for(let a=0;a<c;a++){o.push(255);for(let u=0;u<3;u++){let l=m(a*3+u);Ot(o,Lt(l-d|0)),d=l}}for(let a=0;a<16;a++)o.push(0);return new Uint8Array(o)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function et(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let n=new Uint8Array(r.bin),s=[],m=0;for(let u=0;u<i.bufferViews.length;u++){let l=i.bufferViews[u],h=l?.extensions?.KHR_meshopt_compression,f=h??l?.extensions?.EXT_meshopt_compression;if(!f||typeof f!="object")continue;let g=h?"KHR_meshopt_compression":"EXT_meshopt_compression",A=Number(f.count),v=Number(f.byteStride),S=Number(f.byteOffset??0),p=Number(f.byteLength??0),b=f.mode||"ATTRIBUTES",y=f.filter||"NONE";if(y==="COLOR"&&!h)throw q(`bufferView ${u} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(f.buffer??0)!==0)throw new Error(`${g}: bufferView ${u} references buffer ${String(f.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(S)||S<0||!Number.isInteger(p)||p<0||S+p>n.byteLength)throw new Error(`${g}: bufferView ${u} compressed range [${S}, ${S+p}] out of bounds (${n.byteLength})`);let L=A*v;if(m+=L,m>It)throw q(`total decompressed size (${m}) exceeds MAX_MESHOPT_TOTAL_BYTES (${It})`);let C=n.subarray(S,S+p),F=kt(C,A,v,b,y);s.push({index:u,bytes:F,ext:f})}if(s.length===0)return;let c=n.byteLength+3&-4,o=0;for(let u of s)o+=u.bytes.byteLength+3&-4;let d=new Uint8Array(c+o);d.set(n,0);let a=c;for(let u of s){d.set(u.bytes,a);let l=i.bufferViews[u.index];l.buffer=0,l.byteOffset=a,l.byteLength=u.bytes.byteLength,l._decoded=u.bytes,u.ext.mode==="ATTRIBUTES"&&l.byteStride===void 0&&(l.byteStride=Number(u.ext.byteStride)),l.extensions&&(delete l.extensions.EXT_meshopt_compression,delete l.extensions.KHR_meshopt_compression),a+=u.bytes.byteLength+3&-4}r.bin=d.buffer}var tt={decodeBufferViews(e,t){et(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};ye().decoders.set("meshopt",tt);var $t={name:"meshopt",onParseGLB(e){ye().decoders.set("meshopt",tt),et(e)}};function rt(e,t,r,i=!0){let n=[],s=null;try{for(let[m,c]of[[35633,t],[35632,r]]){let o=e.createShader(m);if(!o){if(i)throw new Error("Shader allocation failed");return null}if(n.push(o),e.shaderSource(o,c),e.compileShader(o),e.getShaderParameter&&!e.getShaderParameter(o,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(o)}`);return null}}if(s=e.createProgram(),!s){if(i)throw new Error("Program allocation failed");return null}for(let m of n)e.attachShader(s,m);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let m=i?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,i)throw new Error(`Program link error: ${m}`);return null}return s}finally{for(let m of n)s&&e.detachShader?.(s,m),e.deleteShader?.(m)}}function Bt(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var Fr=`#version 300 es
41
40
  layout(location=0) in vec3 aPosition;
42
41
  layout(location=1) in vec3 aNormal;
43
42
  uniform mat4 uMVP,uVP;
@@ -58,19 +57,19 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
58
57
  clipPos.xy+=pxOffset;
59
58
  clipPos.z+=1e-4*clipPos.w;
60
59
  gl_Position=clipPos;
61
- }`,xn=`#version 300 es
60
+ }`,Ur=`#version 300 es
62
61
  precision highp float;
63
62
  uniform vec4 uOutlineColor;
64
63
  out vec4 fragColor;
65
64
  void main(){
66
65
  fragColor=uOutlineColor;
67
- }`,Lt=`#version 300 es
66
+ }`,Ht=`#version 300 es
68
67
  out vec2 vUV;
69
68
  void main(){
70
69
  vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
71
70
  vUV=pos;
72
71
  gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
73
- }`,Tn=`#version 300 es
72
+ }`,kr=`#version 300 es
74
73
  precision highp float;
75
74
  in vec2 vUV;
76
75
  uniform sampler2D uSourceTex;
@@ -93,7 +92,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
93
92
  c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
94
93
  c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
95
94
  fragColor=vec4(c,1.0);
96
- }`,An=`#version 300 es
95
+ }`,Or=`#version 300 es
97
96
  precision highp float;
98
97
  in vec2 vUV;
99
98
  uniform sampler2D uBloomTex;
@@ -115,6 +114,6 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
115
114
  vec3 bloom=(sum/12.0)*uStrength;
116
115
  float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
117
116
  fragColor=vec4(bloom,a);
118
- }`,Le=3,be=new WeakMap;function Pt(e,t=[.22,.74,.97]){let n=ze(e,"");if(!n.startsWith("#"))return[t[0],t[1],t[2]];let r=n.slice(1);if(r.length===3){let o=+("0x"+r[0]+r[0])/255,a=+("0x"+r[1]+r[1])/255,l=+("0x"+r[2]+r[2])/255;return[o,a,l]}if(r.length===6){let o=+("0x"+r.slice(0,2))/255,a=+("0x"+r.slice(2,4))/255,l=+("0x"+r.slice(4,6))/255;return[o,a,l]}return[t[0],t[1],t[2]]}function vn(e,t,n=.8,r=.5){let o=Number.isFinite(t)?Math.max(0,t):0;if(o<=0)return[0,0,0];let a=Math.max(0,Number(e[0])||0),l=Math.max(0,Number(e[1])||0),u=Math.max(0,Number(e[2])||0),i=Math.max(a,l,u);if(i<=1e-6)return[0,0,0];let c=Number.isFinite(n)?Math.max(0,n):.8,s=Math.max(c*Math.max(0,r),1e-4),d=Math.max(0,Math.min(2*s,i-c+s)),f=d*d/(4*s+1e-4),p=Math.min(1,Math.max(0,Math.max(f,i-c)/Math.max(i,1e-4)))*o;return[a*p,l*p,u*p]}function wn(e,t,n,r){let o=Number(e[0])||0,a=Number(e[1])||0,l=Math.hypot(o,a);if(l<=1e-5||t<=0||n<=0)return[0,0];let u=Math.max(1,Number(r[0])||1),i=Math.max(1,Number(r[1])||1),c=Math.max(0,n)*2*t;return[o/l*(c/u),a/l*(c/i)]}var Ut=new WeakSet;function kt(e){let t=be.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;be.delete(e)}if(Ut.has(e)||e.isContextLost?.())return null;let n=Ie(e,gn,xn,!1),r=Ie(e,Lt,Tn,!1),o=Ie(e,Lt,An,!1);if(!n||!r||!o){for(let l of[n,r,o])l&&e.deleteProgram(l);return Ut.add(e),null}let a=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:n,uOutlineMVP:e.getUniformLocation(n,"uMVP"),uOutlineVP:e.getUniformLocation(n,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(n,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(n,"uViewportSize"),uOutlineThickness:e.getUniformLocation(n,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(n,"uOutlineColor"),downProg:r,uDownSourceTex:e.getUniformLocation(r,"uSourceTex"),uDownTexelSize:e.getUniformLocation(r,"uTexelSize"),uDownThreshold:e.getUniformLocation(r,"uThreshold"),upProg:o,uUpBloomTex:e.getUniformLocation(o,"uBloomTex"),uUpTexelSize:e.getUniformLocation(o,"uTexelSize"),uUpRadius:e.getUniformLocation(o,"uRadius"),uUpStrength:e.getUniformLocation(o,"uStrength"),fsVao:a,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},be.set(e,t),t}function En(e,t,n,r){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let o=Math.max(2,n|0),a=Math.max(2,r|0);if(t.sceneTex&&t.bloomFbo.length===Le&&t.texWidth===o&&t.texHeight===a)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,o,a,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let l=o,u=a;for(let i=0;i<Le;i++)l=Math.max(1,l>>1),u=Math.max(1,u>>1),t.mipWidth[i]=l,t.mipHeight[i]=u,t.bloomTex[i]||(t.bloomTex[i]=e.createTexture()),e.bindTexture(3553,t.bloomTex[i]),e.texImage2D(3553,0,6408,l,u,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[i]||(t.bloomFbo[i]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[i]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[i],0);return e.bindFramebuffer(36160,null),t.texWidth=o,t.texHeight=a,!0}function Sn(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let r=t.getAttribute("bloom");if(r!==null){let o=r.trim().toLowerCase();if(o==="false"||o==="0"||o==="none")return null;let a=o===""||o==="true"?.35:Number(o);if(!Number.isFinite(a)||a<=0)return null;let l=Be({strength:a,threshold:je(t.getAttribute("bloom-threshold"),.62),radius:je(t.getAttribute("bloom-radius"),.75)});if(l)return l}}let n=null;for(let r of e.meshes||[]){if(r.visible===!1)continue;let o=r?.extras?.xr?.bloom??r?.userData?.xr?.bloom,a=Be(o);a&&(!n||a.strength>n.strength)&&(n=a)}return n}function Mn(e,t){if(e==null)return null;let n=e.trim(),r=n.toLowerCase();if(r==="false"||r==="0"||r==="none")return null;let o=t,a=3.5,l=!1;if(n&&r!=="true"){let u=n.split(/\s+/);for(let i of u)if(i.startsWith("#"))o=i;else if(i.toLowerCase()==="pulse")l=!0;else{let c=Number(i);Number.isFinite(c)&&c>0&&(a=c)}}return Te({color:o,thickness:a,pulse:l})}var Rn=new Set(["floor","pedestal","ground","table","grid","pad"]);function _n(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Rn.has(t))}function In(e,t){let n=e.container,r=typeof n?.getAttribute=="function"?n.getAttribute("outline"):null;if(r!=null){let s=r.trim().toLowerCase();if(s==="false"||s==="0"||s==="none")return null}let o=t?.extras?.xr?.outline??t?.userData?.xr?.outline,a=Te(o);if(a)return a;let l=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",u=Mn(r,l),i=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",c=e.getSelectedMesh?.()||"";if(c)return t.name!==c?null:u||(i?Te({color:l,thickness:3,pulse:!1}):null);if(u){let s=t.name||"";return _n(s)?null:u}return null}var Nt={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,n){if(!t.meshes||t.meshes.length===0)return;let r=Math.max(1,t.canvas?.width||300),o=Math.max(1,t.canvas?.height||150),a=[];for(let f of t.meshes){if(f.visible===!1)continue;let b=In(t,f);b&&a.push({mesh:f,trait:b})}let l=a.length>0?kt(e):null;if(l){let f=l,b=le(),p=le(),m=new Float32Array(9),x=(typeof performance<"u"?performance.now():Date.now())*.001,E=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,I=Math.max(1,E?.[2]||r),v=Math.max(1,E?.[3]||o);e.useProgram(f.outlineProg),f.uOutlineViewportSize&&e.uniform2f(f.uOutlineViewportSize,I,v),f.uOutlineVP&&e.uniformMatrix4fv(f.uOutlineVP,!1,n),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:S,trait:w}of a){let[U,V,O]=Pt(w.color),N=w.pulse?.8+.25*Math.sin(x*4):1;f.uOutlineColor&&e.uniform4f(f.uOutlineColor,U,V,O,1),f.uOutlineThickness&&e.uniform1f(f.uOutlineThickness,w.thickness*N),S.worldSpace===!0?b.set(S.transform):ue(b,t.modelRootMatrix,S.transform);let P=S.instanceMatrices;for(let C of S.primitives)if(!(C.pluginData?.skinning?.hasSkin||C.pluginData?.morph?.hasMorph))if(e.bindVertexArray(C.vao),P&&P.length>=16){let z=P.length>>4,W=le();for(let B=0;B<z;B++)ue(W,b,P.subarray(B*16,B*16+16)),ue(p,n,W),fe(m,W),e.uniformMatrix4fv(f.uOutlineMVP,!1,p),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,m),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}else ue(p,n,b),fe(m,b),e.uniformMatrix4fv(f.uOutlineMVP,!1,p),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,m),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let u=Sn(t);if(!u||u.strength<=0)return;let i=kt(e);if(!i||!En(e,i,r,o)||!i.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,i.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,r,o),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(i.downProg),e.uniform1i(i.uDownSourceTex,0),e.bindVertexArray(i.fsVao);let c=i.sceneTex,s=r,d=o;for(let f=0;f<Le;f++){let b=i.mipWidth[f],p=i.mipHeight[f];e.bindFramebuffer(36160,i.bloomFbo[f]),e.viewport(0,0,b,p),e.bindTexture(3553,c),e.uniform2f(i.uDownTexelSize,1/s,1/d),e.uniform1f(i.uDownThreshold,f===0?u.threshold:0),e.drawArrays(4,0,3),c=i.bloomTex[f],s=b,d=p}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(i.upProg),e.uniform1i(i.uUpBloomTex,0),e.uniform1f(i.uUpRadius,u.radius);for(let f=Le-1;f>=1;f--){let b=f-1;e.bindFramebuffer(36160,i.bloomFbo[b]),e.viewport(0,0,i.mipWidth[b],i.mipHeight[b]),e.bindTexture(3553,i.bloomTex[f]),e.uniform2f(i.uUpTexelSize,1/i.mipWidth[f],1/i.mipHeight[f]),e.uniform1f(i.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,r,o),e.bindTexture(3553,i.bloomTex[0]),e.uniform2f(i.uUpTexelSize,1/i.mipWidth[0],1/i.mipHeight[0]),e.uniform1f(i.uUpStrength,u.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=be.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let n of t.bloomTex)n&&e.deleteTexture(n);for(let n of t.bloomFbo)n&&e.deleteFramebuffer(n);be.delete(e)}}};var Un=`#version 300 es
119
- layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,kn=`#version 300 es
120
- precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,he=new WeakMap,Ct=new Float32Array(20);function Ke(e,t){let[n,r,o,a,l,u]=t;return[e[0]*n+e[4]*r+e[8]*o+e[12],e[1]*n+e[5]*r+e[9]*o+e[13],e[2]*n+e[6]*r+e[10]*o+e[14],Math.abs(e[0])*a+Math.abs(e[4])*l+Math.abs(e[8])*u,Math.abs(e[1])*a+Math.abs(e[5])*l+Math.abs(e[9])*u,Math.abs(e[2])*a+Math.abs(e[6])*l+Math.abs(e[10])*u]}function Pn(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,r=1e9,o=-1e9,a=-1e9,l=-1e9;for(let u of e.primitives||[]){let i=u.positions;if(i)for(let c=0;c<i.length;c+=3)i[c]<t&&(t=i[c]),i[c+1]<n&&(n=i[c+1]),i[c+2]<r&&(r=i[c+2]),i[c]>o&&(o=i[c]),i[c+1]>a&&(a=i[c+1]),i[c+2]>l&&(l=i[c+2])}return e._lb=t<=o?[(t+o)*.5,(n+a)*.5,(r+l)*.5,(o-t)*.5,(a-n)*.5,(l-r)*.5]:null}function Nn(e){let t=he.get(e);if(t)return t;let n=(u,i)=>{let c=e.createShader(u);return e.shaderSource(c,i),e.compileShader(c),c},r=e.createProgram();e.attachShader(r,n(35633,Un)),e.attachShader(r,n(35632,kn)),e.linkProgram(r);let o=e.createVertexArray(),a=e.createBuffer(),l=e.createBuffer();return e.bindVertexArray(o),e.bindBuffer(34962,a),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,l),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:r,vao:o,vbo:a,ibo:l,uMVP:e.getUniformLocation(r,"uMVP"),uIntensity:e.getUniformLocation(r,"uShadowIntensity"),uSoftness:e.getUniformLocation(r,"uShadowSoftness")},he.set(e,t),t}var Ot={name:"contact-shadow",onContextRestored(e){he.delete(e)},onAfterRender(e,t,n){let r=t.shadowIntensity;if(r<=0||!t.bounds)return;let o=Nn(e),a=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,l=[],u=[];for(let m of t.meshes||[]){if(!m||m.visible===!1||m.isPluginMesh||m.name==="__xr_reticle__"||m.name?.startsWith("__xr_slot_"))continue;let x=Pn(m);if(!x)continue;m.transform&&(x=Ke(m.transform,x)),t.modelRootMatrix&&(x=Ke(t.modelRootMatrix,x));let[E,I,v,S,w,U]=x,V=[E,v,S,U,I-w,I+w];/floor|table|pedestal|ground|base|plane/i.test(m.name||"")||w<.14&&Math.min(S,U)>.45?u.push(V):l.push(V)}let i=[],c=t.bounds.center||[0,0,0],s=Math.max(.05,Number(t.bounds.radius)||.5),d=t.bounds.min,f=d?[c[0],c[1],c[2],s,Math.max(.01,c[1]-d[1]),s]:[c[0],c[1],c[2],s,s,s];t.modelRootMatrix&&(f=Ke(t.modelRootMatrix,f));let p=t.xrSessionActive&&u.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:f[1]-f[4]+.002;for(let[m,x,E,I,v]of l){let S=-1/0;for(let[U,V,O,N,,P]of u)v>=P-.08&&Math.abs(m-U)<=O&&Math.abs(x-V)<=N&&P+.002>S&&(S=P+.002);a&&(S=Math.max(S,m>=.04&&m<=.36&&x>=-.34&&x<=-.04&&v>=.01?.036:Math.hypot(m,x)<=.66&&v>=-.06?.003:-.477)),isFinite(S)||(S=p);let w=i.find(U=>Math.hypot(m-U[0],x-U[1])<.06&&Math.abs(S-U[5])<.05);w?(w[2]=Math.max(w[2],E*.78),w[3]=Math.max(w[3],I*.78),w[4]=Math.min(w[4],v)):i.push([m,x,E,I,v,S])}if(i.length===0){let m=Math.max(.1,f[3]*1.5)/1.45;i.push([f[0],f[2],m,m,p,p])}e.useProgram(o.prog),e.uniformMatrix4fv(o.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(o.vao),e.bindBuffer(34962,o.vbo);for(let[m,x,E,I,v,S]of i){let w=Math.max(0,v-S),U=r/(1+w*2);if(U<.02)continue;let V=1+Math.min(.75,w*.85),O=Math.max(.045,E*1.45*V),N=Math.max(.045,I*1.45*V);Ct.set([m-O,S,x-N,0,0,m+O,S,x-N,1,0,m+O,S,x+N,1,1,m-O,S,x+N,0,1]),e.bufferSubData(34962,0,Ct),e.uniform1f(o.uIntensity,U),e.uniform1f(o.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,w*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=he.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),he.delete(e))}};function Vt(e){let n=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(n))return[];let r=[];for(let o=0;o<n.length&&r.length<256;o++){let a=n[o]?.name;r.push(typeof a=="string"&&a.length>0?a:`Variant_${o}`)}return r}function Cn(e){let n=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(n))return[];let r=[];for(let o of n){if(!o||typeof o!="object")continue;let a=o,l=Number(a.material);if(!Number.isInteger(l)||l<0)continue;let u=[];if(Array.isArray(a.variants))for(let i of a.variants){let c=Number(i);Number.isInteger(c)&&c>=0&&u.push(c)}u.length>0&&r.push({material:l,variants:u})}return r}function On(e,t,n,r=0){let o=e;if(o&&typeof o.selectVariant=="function"&&!Array.isArray(t))return o.selectVariant(typeof t=="string"?t:null);let a=e,l=Array.isArray(t)?t:[],u=n??null;if(!u)return r;let c=Vt(a).indexOf(u);if(c<0)return r;for(let s of l)if(s.variants.includes(c))return s.material;return r}var Dt={name:"variants",onLoadModel(e,t){let n=e.getVariantName?.();n&&e.selectVariant(n)}};var Ft=new WeakMap,zt={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=e?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),t.domOverlay={root:r},r.addEventListener?.("beforexrselect",o=>{o.preventDefault()})),t.optionalFeatures=Array.from(n)},onXRFrame(e,t,n,r){if(!e||!t||!n||!r)return;let o=Ft.get(t);if(o||(o={lightProbe:null},Ft.set(t,o),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(a=>{o&&a&&(o.lightProbe=a)}).catch(()=>{})),o.lightProbe&&typeof n.getLightEstimate=="function"){let a=n.getLightEstimate(o.lightProbe);if(a){let l=a.primaryLightDirection,u=a.primaryLightIntensity;if(l&&u&&Array.isArray(e.lights)){let i=e.lights.find(s=>s.type==="directional");i||(i={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(i)),i.direction=[l.x,l.y,l.z];let c=Math.max(u.x,u.y,u.z,.001);i.color=[u.x/c,u.y/c,u.z/c],i.intensity=c}a.sphericalHarmonicsCoefficients&&e.gl&&Oe(e.gl,a.sphericalHarmonicsCoefficients)}}}};Z(Ot);Z(nt);Z(tt);Z(pt);Z(zt);Z(mt);Z(It);Z(Dt);Z(Nt);export{Se as InteractivityVM,At as applyMeshoptFilter,wn as computeOutlineClipOffset,Ot as contactShadowPlugin,_t as decodeMeshoptBuffer,Xe as decodeMeshoptGLB,bn as encodeMeshoptBuffer,tt as environmentMapPlugin,vn as evaluateKawaseBloom,Vt as extractMaterialVariants,Cn as extractPrimitiveVariantMappings,Wt as getEnvironmentSH,We as getInteractivityVM,nt as hotspotPlugin,mt as interactivityPlugin,pt as materialsPlugin,$e as meshoptDecoder,It as meshoptPlugin,Pt as parseHexRgb,we as parseSafeGltfPointer,Nt as postprocessingPlugin,tn as registerMaterialShader,On as selectMaterialVariant,dt as sendInteractivityEvent,Oe as setEnvironmentSH,Dt as variantsPlugin,zt as webxrPlugin};
117
+ }`,He=3,Ee=new WeakMap;function zt(e,t=[.22,.74,.97]){let r=ct(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let n=+("0x"+i[0]+i[0])/255,s=+("0x"+i[1]+i[1])/255,m=+("0x"+i[2]+i[2])/255;return[n,s,m]}if(i.length===6){let n=+("0x"+i.slice(0,2))/255,s=+("0x"+i.slice(2,4))/255,m=+("0x"+i.slice(4,6))/255;return[n,s,m]}return[t[0],t[1],t[2]]}function $r(e,t,r=.8,i=.5){let n=Number.isFinite(t)?Math.max(0,t):0;if(n<=0)return[0,0,0];let s=Math.max(0,Number(e[0])||0),m=Math.max(0,Number(e[1])||0),c=Math.max(0,Number(e[2])||0),o=Math.max(s,m,c);if(o<=1e-6)return[0,0,0];let d=Number.isFinite(r)?Math.max(0,r):.8,a=Math.max(d*Math.max(0,i),1e-4),u=Math.max(0,Math.min(2*a,o-d+a)),l=u*u/(4*a+1e-4),h=Math.min(1,Math.max(0,Math.max(l,o-d)/Math.max(o,1e-4)))*n;return[s*h,m*h,c*h]}function Br(e,t,r,i){let n=Number(e[0])||0,s=Number(e[1])||0,m=Math.hypot(n,s);if(m<=1e-5||t<=0||r<=0)return[0,0];let c=Math.max(1,Number(i[0])||1),o=Math.max(1,Number(i[1])||1),d=Math.max(0,r)*2*t;return[n/m*(d/c),s/m*(d/o)]}var Gt=new WeakSet;function jt(e){let t=Ee.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Ee.delete(e)}if(Gt.has(e)||e.isContextLost?.())return null;let r=rt(e,Fr,Ur,!1),i=rt(e,Ht,kr,!1),n=rt(e,Ht,Or,!1);if(!r||!i||!n){for(let m of[r,i,n])m&&e.deleteProgram(m);return Gt.add(e),null}let s=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:n,uUpBloomTex:e.getUniformLocation(n,"uBloomTex"),uUpTexelSize:e.getUniformLocation(n,"uTexelSize"),uUpRadius:e.getUniformLocation(n,"uRadius"),uUpStrength:e.getUniformLocation(n,"uStrength"),fsVao:s,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Ee.set(e,t),t}function Hr(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let n=Math.max(2,r|0),s=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===He&&t.texWidth===n&&t.texHeight===s)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,n,s,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let m=n,c=s;for(let o=0;o<He;o++)m=Math.max(1,m>>1),c=Math.max(1,c>>1),t.mipWidth[o]=m,t.mipHeight[o]=c,t.bloomTex[o]||(t.bloomTex[o]=e.createTexture()),e.bindTexture(3553,t.bloomTex[o]),e.texImage2D(3553,0,6408,m,c,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[o]||(t.bloomFbo[o]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[o]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[o],0);return e.bindFramebuffer(36160,null),t.texWidth=n,t.texHeight=s,!0}function zr(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let n=i.trim().toLowerCase();if(n==="false"||n==="0"||n==="none")return null;let s=n===""||n==="true"?.35:Number(n);if(!Number.isFinite(s)||s<=0)return null;let m=ht({strength:s,threshold:Bt(t.getAttribute("bloom-threshold"),.62),radius:Bt(t.getAttribute("bloom-radius"),.75)});if(m)return m}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let n=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,s=ht(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function Gr(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let n=t,s=3.5,m=!1;if(r&&i!=="true"){let c=r.split(/\s+/);for(let o of c)if(o.startsWith("#"))n=o;else if(o.toLowerCase()==="pulse")m=!0;else{let d=Number(o);Number.isFinite(d)&&d>0&&(s=d)}}return We({color:n,thickness:s,pulse:m})}var jr=new Set(["floor","pedestal","ground","table","grid","pad"]);function Kr(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>jr.has(t))}function qr(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let a=i.trim().toLowerCase();if(a==="false"||a==="0"||a==="none")return null}let n=t?.extras?.xr?.outline??t?.userData?.xr?.outline,s=We(n);if(s)return s;let m=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=Gr(i,m),o=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",d=e.getSelectedMesh?.()||"";if(d)return t.name!==d?null:c||(o?We({color:m,thickness:3,pulse:!1}):null);if(c){let a=t.name||"";return Kr(a)?null:c}return null}var Kt={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),n=Math.max(1,t.canvas?.height||150),s=[];for(let l of t.meshes){if(l.visible===!1)continue;let h=qr(t,l);h&&s.push({mesh:l,trait:h})}let m=s.length>0?jt(e):null;if(m){let l=m,h=Te(),f=Te(),g=new Float32Array(9),A=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,S=Math.max(1,v?.[2]||i),p=Math.max(1,v?.[3]||n);e.useProgram(l.outlineProg),l.uOutlineViewportSize&&e.uniform2f(l.uOutlineViewportSize,S,p),l.uOutlineVP&&e.uniformMatrix4fv(l.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:b,trait:y}of s){let[L,C,F]=zt(y.color),_=y.pulse?.8+.25*Math.sin(A*4):1;l.uOutlineColor&&e.uniform4f(l.uOutlineColor,L,C,F,1),l.uOutlineThickness&&e.uniform1f(l.uOutlineThickness,y.thickness*_),b.worldSpace===!0?h.set(b.transform):Se(h,t.modelRootMatrix,b.transform);let U=b.instanceMatrices;for(let D of b.primitives)if(!(D.pluginData?.skinning?.hasSkin||D.pluginData?.morph?.hasMorph))if(e.bindVertexArray(D.vao),U&&U.length>=16){let $=U.length>>4,z=Te();for(let O=0;O<$;O++)Se(z,h,U.subarray(O*16,O*16+16)),Se(f,r,z),Re(g,z),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),D.indices?e.drawElements(4,D.indexCount,D.indexType,0):e.drawArrays(4,0,D.indexCount)}else Se(f,r,h),Re(g,h),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),D.indices?e.drawElements(4,D.indexCount,D.indexType,0):e.drawArrays(4,0,D.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let c=zr(t);if(!c||c.strength<=0)return;let o=jt(e);if(!o||!Hr(e,o,i,n)||!o.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,o.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,n),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(o.downProg),e.uniform1i(o.uDownSourceTex,0),e.bindVertexArray(o.fsVao);let d=o.sceneTex,a=i,u=n;for(let l=0;l<He;l++){let h=o.mipWidth[l],f=o.mipHeight[l];e.bindFramebuffer(36160,o.bloomFbo[l]),e.viewport(0,0,h,f),e.bindTexture(3553,d),e.uniform2f(o.uDownTexelSize,1/a,1/u),e.uniform1f(o.uDownThreshold,l===0?c.threshold:0),e.drawArrays(4,0,3),d=o.bloomTex[l],a=h,u=f}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(o.upProg),e.uniform1i(o.uUpBloomTex,0),e.uniform1f(o.uUpRadius,c.radius);for(let l=He-1;l>=1;l--){let h=l-1;e.bindFramebuffer(36160,o.bloomFbo[h]),e.viewport(0,0,o.mipWidth[h],o.mipHeight[h]),e.bindTexture(3553,o.bloomTex[l]),e.uniform2f(o.uUpTexelSize,1/o.mipWidth[l],1/o.mipHeight[l]),e.uniform1f(o.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,n),e.bindTexture(3553,o.bloomTex[0]),e.uniform2f(o.uUpTexelSize,1/o.mipWidth[0],1/o.mipHeight[0]),e.uniform1f(o.uUpStrength,c.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Ee.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Ee.delete(e)}}},Wr=`#version 300 es
118
+ layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,Xr=`#version 300 es
119
+ precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Pe=new WeakMap,qt=new Float32Array(20);function it(e,t){let[r,i,n,s,m,c]=t;return[e[0]*r+e[4]*i+e[8]*n+e[12],e[1]*r+e[5]*i+e[9]*n+e[13],e[2]*r+e[6]*i+e[10]*n+e[14],Math.abs(e[0])*s+Math.abs(e[4])*m+Math.abs(e[8])*c,Math.abs(e[1])*s+Math.abs(e[5])*m+Math.abs(e[9])*c,Math.abs(e[2])*s+Math.abs(e[6])*m+Math.abs(e[10])*c]}function Qr(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,n=-1e9,s=-1e9,m=-1e9;for(let c of e.primitives||[]){let o=c.positions;if(o)for(let d=0;d<o.length;d+=3)o[d]<t&&(t=o[d]),o[d+1]<r&&(r=o[d+1]),o[d+2]<i&&(i=o[d+2]),o[d]>n&&(n=o[d]),o[d+1]>s&&(s=o[d+1]),o[d+2]>m&&(m=o[d+2])}return e._lb=t<=n?[(t+n)*.5,(r+s)*.5,(i+m)*.5,(n-t)*.5,(s-r)*.5,(m-i)*.5]:null}function Zr(e){let t=Pe.get(e);if(t)return t;let r=(c,o)=>{let d=e.createShader(c);return e.shaderSource(d,o),e.compileShader(d),d},i=e.createProgram();e.attachShader(i,r(35633,Wr)),e.attachShader(i,r(35632,Xr)),e.linkProgram(i);let n=e.createVertexArray(),s=e.createBuffer(),m=e.createBuffer();return e.bindVertexArray(n),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,m),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:n,vbo:s,ibo:m,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},Pe.set(e,t),t}var Wt={name:"contact-shadow",onContextRestored(e){Pe.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let n=Zr(e),s=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,m=[],c=[];for(let f of t.meshes||[]){if(!f||f.visible===!1||f.isPluginMesh||f.name==="__xr_reticle__"||f.name?.startsWith("__xr_slot_"))continue;let g=Qr(f);if(!g)continue;f.transform&&(g=it(f.transform,g)),t.modelRootMatrix&&(g=it(t.modelRootMatrix,g));let[A,v,S,p,b,y]=g,L=[A,S,p,y,v-b,v+b];/floor|table|pedestal|ground|base|plane/i.test(f.name||"")||b<.14&&Math.min(p,y)>.45?c.push(L):m.push(L)}let o=[],d=t.bounds.center||[0,0,0],a=Math.max(.05,Number(t.bounds.radius)||.5),u=t.bounds.min,l=u?[d[0],d[1],d[2],a,Math.max(.01,d[1]-u[1]),a]:[d[0],d[1],d[2],a,a,a];t.modelRootMatrix&&(l=it(t.modelRootMatrix,l));let h=t.xrSessionActive&&c.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:l[1]-l[4]+.002;for(let[f,g,A,v,S]of m){let p=-1/0;for(let[y,L,C,F,,_]of c)S>=_-.08&&Math.abs(f-y)<=C&&Math.abs(g-L)<=F&&_+.002>p&&(p=_+.002);s&&(p=Math.max(p,f>=.04&&f<=.36&&g>=-.34&&g<=-.04&&S>=.01?.036:Math.hypot(f,g)<=.66&&S>=-.06?.003:-.477)),isFinite(p)||(p=h);let b=o.find(y=>Math.hypot(f-y[0],g-y[1])<.06&&Math.abs(p-y[5])<.05);b?(b[2]=Math.max(b[2],A*.78),b[3]=Math.max(b[3],v*.78),b[4]=Math.min(b[4],S)):o.push([f,g,A,v,S,p])}if(o.length===0){let f=Math.max(.1,l[3]*1.5)/1.45;o.push([l[0],l[2],f,f,h,h])}e.useProgram(n.prog),e.uniformMatrix4fv(n.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(n.vao),e.bindBuffer(34962,n.vbo);for(let[f,g,A,v,S,p]of o){let b=Math.max(0,S-p),y=i/(1+b*2);if(y<.02)continue;let L=1+Math.min(.75,b*.85),C=Math.max(.045,A*1.45*L),F=Math.max(.045,v*1.45*L);qt.set([f-C,p,g-F,0,0,f+C,p,g-F,1,0,f+C,p,g+F,1,1,f-C,p,g+F,0,1]),e.bufferSubData(34962,0,qt),e.uniform1f(n.uIntensity,y),e.uniform1f(n.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,b*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Pe.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Pe.delete(e))}};function Xt(e){let t=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(t))return[];let r=[];for(let i=0;i<t.length&&r.length<256;i++){let n=t[i]?.name;r.push(typeof n=="string"&&n.length>0?n:`Variant_${i}`)}return r}function Yr(e){let t=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let n=i,s=Number(n.material);if(!Number.isInteger(s)||s<0)continue;let m=[];if(Array.isArray(n.variants))for(let c of n.variants){let o=Number(c);Number.isInteger(o)&&o>=0&&m.push(o)}m.length>0&&r.push({material:s,variants:m})}return r}function Jr(e,t,r,i=0){let n=e;if(n&&typeof n.selectVariant=="function"&&!Array.isArray(t))return n.selectVariant(typeof t=="string"?t:null);let s=e,m=Array.isArray(t)?t:[],c=r??null;if(!c)return i;let o=Xt(s).indexOf(c);if(o<0)return i;for(let d of m)if(d.variants.includes(o))return d.material;return i}var Qt={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},Zt=new WeakMap,Yt={name:"webxr-suite",onConfigureXRSessionInit(e,t){let r=new Set(t.optionalFeatures||[]);r.add("hit-test"),r.add("light-estimation");let i=e?.querySelector?.('[slot="ar-overlay"]')||null;i&&(r.add("dom-overlay"),t.domOverlay={root:i},i.addEventListener?.("beforexrselect",n=>{n.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let n=Zt.get(t);if(n||(n={lightProbe:null},Zt.set(t,n),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(s=>{n&&s&&(n.lightProbe=s)}).catch(()=>{})),n.lightProbe&&typeof r.getLightEstimate=="function"){let s=r.getLightEstimate(n.lightProbe);if(s){let m=s.primaryLightDirection,c=s.primaryLightIntensity;if(m&&c&&Array.isArray(e.lights)){let o=e.lights.find(a=>a.type==="directional");o||(o={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(o)),o.direction=[m.x,m.y,m.z];let d=Math.max(c.x,c.y,c.z,.001);o.color=[c.x/d,c.y/d,c.z/d],o.intensity=d}s.sphericalHarmonicsCoefficients&&e.gl&&ot(e.gl,s.sphericalHarmonicsCoefficients)}}}};ue(Wt),ue(ft),ue(ut),ue(St),ue(Yt),ue(wt),ue($t),ue(Qt),ue(Kt),ue(Tt);export{xt as InteractivityVM,xr as LOD,At as LodController,Pt as applyMeshoptFilter,Br as computeOutlineClipOffset,Wt as contactShadowPlugin,vr as decimateGeometry,kt as decodeMeshoptBuffer,et as decodeMeshoptGLB,Dr as encodeMeshoptBuffer,ut as environmentMapPlugin,$r as evaluateKawaseBloom,Xt as extractMaterialVariants,Yr as extractPrimitiveVariantMappings,nr as getEnvironmentSH,Ze as getInteractivityVM,Mr as getLodController,ft as hotspotPlugin,Oe as installLodExtension,wt as interactivityPlugin,Tt as lodPlugin,St as materialsPlugin,tt as meshoptDecoder,$t as meshoptPlugin,zt as parseHexRgb,Je as parseLod,Ue as parseSafeGltfPointer,Kt as postprocessingPlugin,wr as registerMaterialShader,Ye as selectLodLevelIndex,Jr as selectMaterialVariant,Mt as sendInteractivityEvent,ot as setEnvironmentSH,Qt as variantsPlugin,Yt as webxrPlugin};