three-live 1.3.1 → 1.4.0

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 (58) hide show
  1. package/README.md +4 -1
  2. package/dist/index.d.ts +191 -0
  3. package/dist/three-author-engine.js +179 -144
  4. package/dist/three-author.cjs +153 -144
  5. package/dist/three-author.d.ts +191 -0
  6. package/dist/three-author.js +153 -144
  7. package/dist/three-convert.cjs +150 -141
  8. package/dist/three-convert.d.ts +191 -0
  9. package/dist/three-convert.js +150 -141
  10. package/dist/three-live-ai.cjs +41 -0
  11. package/dist/three-live-ai.d.ts +759 -0
  12. package/dist/three-live-ai.js +41 -0
  13. package/dist/three-live-ai.min.js +41 -0
  14. package/dist/three-live-animation.cjs +6 -6
  15. package/dist/three-live-animation.d.ts +191 -0
  16. package/dist/three-live-animation.js +5 -5
  17. package/dist/three-live-animation.min.js +5 -5
  18. package/dist/three-live-cad.cjs +2 -2
  19. package/dist/three-live-cad.d.ts +191 -0
  20. package/dist/three-live-cad.js +2 -2
  21. package/dist/three-live-cad.min.js +2 -2
  22. package/dist/three-live-element.cjs +50 -85
  23. package/dist/three-live-element.d.ts +191 -0
  24. package/dist/three-live-element.js +50 -85
  25. package/dist/three-live-full.cjs +915 -170
  26. package/dist/three-live-full.js +917 -172
  27. package/dist/three-live-full.min.js +915 -170
  28. package/dist/three-live-procedural.cjs +16 -0
  29. package/dist/three-live-procedural.d.ts +759 -0
  30. package/dist/three-live-procedural.js +16 -0
  31. package/dist/three-live-procedural.min.js +16 -0
  32. package/dist/three-live-sandbox.html +11 -1
  33. package/dist/three-live-studio.cjs +72 -17
  34. package/dist/three-live-studio.d.ts +191 -0
  35. package/dist/three-live-studio.js +72 -17
  36. package/dist/three-live-studio.min.js +73 -18
  37. package/dist/three-live-tsl.cjs +103 -0
  38. package/dist/three-live-tsl.d.ts +759 -0
  39. package/dist/three-live-tsl.js +103 -0
  40. package/dist/three-live-tsl.min.js +103 -0
  41. package/dist/three-live-viewer.cjs +50 -85
  42. package/dist/three-live-viewer.d.ts +191 -0
  43. package/dist/three-live-viewer.js +50 -85
  44. package/dist/three-live-viewer.min.js +50 -85
  45. package/dist/three-live-webgpu.cjs +585 -0
  46. package/dist/three-live-webgpu.d.ts +759 -0
  47. package/dist/three-live-webgpu.js +585 -0
  48. package/dist/three-live-webgpu.min.js +585 -0
  49. package/dist/three-live.cjs +155 -146
  50. package/dist/three-live.js +155 -146
  51. package/dist/three-live.min.js +155 -146
  52. package/dist/three-view.cjs +49 -84
  53. package/dist/three-view.d.ts +191 -0
  54. package/dist/three-view.js +50 -85
  55. package/dist/three-xr.cjs +150 -141
  56. package/dist/three-xr.d.ts +191 -0
  57. package/dist/three-xr.js +150 -141
  58. package/package.json +39 -1
@@ -13,13 +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
- */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];
16
+ */var ze="__THREE_LIVE_REGISTRY__";function de(){let e=typeof globalThis<"u"?globalThis:{};if(!e[ze]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,ze,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[ze]=t}}return e[ze]}var Gi=de().plugins;function Vr(e){let t=de();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function ue(e){let t=de().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function Cr(){return de().plugins}function fe(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Rr(e,t,r,i,a){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/r,e[5]=n,e[11]=-1;let f=1/(i-a);return e[10]=(a+i)*f,e[14]=2*a*i*f,e}function Dr(e,t,r,i,a,n,f){let c=1/(t-r),s=1/(i-a),d=1/(n-f);return e.fill(0),e[0]=-2*c,e[5]=-2*s,e[10]=2*d,e[12]=(t+r)*c,e[13]=(a+i)*s,e[14]=(f+n)*d,e[15]=1,e}function wt(e,t,r,i){let[a,n,f]=t,[c,s,d]=i,[o,l,u]=r,m=a-o,h=n-l,p=f-u,b=Math.hypot(m,h,p);b<=1e-5?(m=0,h=0,p=1):(m/=b,h/=b,p/=b);let v=s*p-d*h,M=d*m-c*p,g=c*h-s*m;b=Math.hypot(v,M,g),b<=1e-5?(v=0,M=0,g=0):(v/=b,M/=b,g/=b);let y=h*g-p*M,x=p*v-m*g,P=m*M-h*v;return b=Math.hypot(y,x,P),b<=1e-5?(y=0,x=0,P=0):(y/=b,x/=b,P/=b),e[0]=v,e[1]=y,e[2]=m,e[3]=0,e[4]=M,e[5]=x,e[6]=h,e[7]=0,e[8]=g,e[9]=P,e[10]=p,e[11]=0,e[12]=-(v*a+M*n+g*f),e[13]=-(y*a+x*n+P*f),e[14]=-(m*a+h*n+p*f),e[15]=1,e}function oe(e,t,r){let i=t[0],a=t[1],n=t[2],f=t[3],c=t[4],s=t[5],d=t[6],o=t[7],l=t[8],u=t[9],m=t[10],h=t[11],p=t[12],b=t[13],v=t[14],M=t[15],g=r[0],y=r[1],x=r[2],P=r[3];return e[0]=g*i+y*c+x*l+P*p,e[1]=g*a+y*s+x*u+P*b,e[2]=g*n+y*d+x*m+P*v,e[3]=g*f+y*o+x*h+P*M,g=r[4],y=r[5],x=r[6],P=r[7],e[4]=g*i+y*c+x*l+P*p,e[5]=g*a+y*s+x*u+P*b,e[6]=g*n+y*d+x*m+P*v,e[7]=g*f+y*o+x*h+P*M,g=r[8],y=r[9],x=r[10],P=r[11],e[8]=g*i+y*c+x*l+P*p,e[9]=g*a+y*s+x*u+P*b,e[10]=g*n+y*d+x*m+P*v,e[11]=g*f+y*o+x*h+P*M,g=r[12],y=r[13],x=r[14],P=r[15],e[12]=g*i+y*c+x*l+P*p,e[13]=g*a+y*s+x*u+P*b,e[14]=g*n+y*d+x*m+P*v,e[15]=g*f+y*o+x*h+P*M,e}function Fr(e,t,r,i){let a=t[0],n=t[1],f=t[2],c=t[3],s=a+a,d=n+n,o=f+f,l=a*s,u=a*d,m=a*o,h=n*d,p=n*o,b=f*o,v=c*s,M=c*d,g=c*o,y=i[0],x=i[1],P=i[2];return e[0]=(1-(h+b))*y,e[1]=(u+g)*y,e[2]=(m-M)*y,e[3]=0,e[4]=(u-g)*x,e[5]=(1-(l+b))*x,e[6]=(p+v)*x,e[7]=0,e[8]=(m+M)*P,e[9]=(p-v)*P,e[10]=(1-(l+h))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function $e(e,t,r=0){let i=t[0],a=t[1],n=t[2],f=t[4],c=t[5],s=t[6],d=t[8],o=t[9],l=t[10],u=l*c-s*o,m=-l*f+s*d,h=o*f-c*d,p=i*u+a*m+n*h;return!p||r>0&&(!Number.isFinite(p)||Math.abs(p)<=r)||(p=1/p,e[0]=u*p,e[1]=m*p,e[2]=h*p,e[3]=(-l*a+n*o)*p,e[4]=(l*i-n*d)*p,e[5]=(-o*i+a*d)*p,e[6]=(s*a-n*c)*p,e[7]=(-s*i+n*f)*p,e[8]=(c*i-a*f)*p),e}function Ur(e,t){let r=t[0],i=t[1],a=t[2],n=t[3],f=t[4],c=t[5],s=t[6],d=t[7],o=t[8],l=t[9],u=t[10],m=t[11],h=t[12],p=t[13],b=t[14],v=t[15],M=r*c-i*f,g=r*s-a*f,y=r*d-n*f,x=i*s-a*c,P=i*d-n*c,C=a*d-n*s,F=o*p-l*h,I=o*b-u*h,B=o*v-m*h,U=l*b-u*p,V=l*v-m*p,k=u*v-m*b,O=M*k-g*V+y*U+x*B-P*I+C*F;return O?(O=1/O,e[0]=(c*k-s*V+d*U)*O,e[1]=(a*V-i*k-n*U)*O,e[2]=(p*C-b*P+v*x)*O,e[3]=(u*P-l*C-m*x)*O,e[4]=(s*B-f*k-d*I)*O,e[5]=(r*k-a*B+n*I)*O,e[6]=(b*y-h*C-v*g)*O,e[7]=(o*C-u*y+m*g)*O,e[8]=(f*V-c*B+d*F)*O,e[9]=(i*B-r*V-n*F)*O,e[10]=(h*P-p*y+v*M)*O,e[11]=(l*y-o*P-m*M)*O,e[12]=(c*I-f*U-s*F)*O,e[13]=(r*U-i*I+a*F)*O,e[14]=(p*g-h*x-b*M)*O,e[15]=(o*x-l*g+u*M)*O,e):null}function St(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(fe());if(r===0)return i;let a=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let l of o.children)a.add(l);let n=new Set,f=128,c=(o,l,u=0)=>{if(u>f||o<0||o>=r||n.has(o))return;n.add(o);let m=e.nodes[o];if(!m)return;let h=fe();if(t&&t[o])h.set(t[o]);else if(m.matrix&&m.matrix.length===16)h.set(m.matrix);else{let b=m.translation||[0,0,0],v=m.rotation||[0,0,0,1],M=m.scale||[1,1,1];Fr(h,v,b,M)}let p=i[o];if(l?oe(p,l,h):p.set(h),Array.isArray(m.children))for(let b of m.children)typeof b=="number"&&c(b,p,u+1)},s=[],d=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(d&&Array.isArray(d.nodes))s.push(...d.nodes);else for(let o=0;o<r;o++)a.has(o)||s.push(o);for(let o of s)c(o,null);for(let o=0;o<r;o++)!a.has(o)&&!s.includes(o)&&c(o,null);return i}var tt=new WeakMap;function At(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);tt.set(e,r)}function kr(e){return tt.get(e)}async function Or(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let a=await(await fetch(t)).blob();r=await createImageBitmap(a)}else if(typeof Image<"u")r=await new Promise((a,n)=>{let f=new Image;f.crossOrigin="anonymous",f.onload=()=>a(f),f.onerror=n,f.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&&(i.__gpuImageSource=r),i}var rt=new WeakMap,It=new Float32Array(16);async function Nt(e,t,r){let i=r?await Or(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var Pt={name:"environment-map",onContextRestored(e){rt.delete(e)},setEnvironmentImage(e,t){return Nt(e,"environmentTexture",t)},setSkyboxImage(e,t){return Nt(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,a){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let n=rt.get(t);if(!n){let l=(h,p)=>{let b=t.createShader(h);return t.shaderSource(b,p),t.compileShader(b),b},u=t.createProgram();t.attachShader(u,l(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(u,l(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(u);let m=typeof t.createVertexArray=="function"?t.createVertexArray():null;n={program:u,vao:m},rt.set(t,n)}let f=Ur(It,r)||It;t.depthMask(!1),t.useProgram(n.program),n.vao&&t.bindVertexArray(n.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let c=t.getUniformLocation(n.program,"uSkyboxMap");c&&t.uniform1i(c,0);let s=t.getUniformLocation(n.program,"uInvVP");s&&t.uniformMatrix4fv(s,!1,f);let d=t.getUniformLocation(n.program,"uCameraPos");d&&t.uniform3f(d,i[0],i[1],i[2]);let o=t.getUniformLocation(n.program,"uExposure");o&&t.uniform1f(o,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let a=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
19
19
  uniform int uHasSH;
20
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);}
21
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));}
22
- void main(){`);return n=n.replace(`if(uHasEnvironmentMap==1){
22
+ void main(){`);return a=a.replace(`if(uHasEnvironmentMap==1){
23
23
  specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
24
24
  envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
25
25
  }`,`if(uHasEnvironmentMap==1){
@@ -28,15 +28,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
28
28
  }else if(uHasSH==1){
29
29
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
30
30
  envDiffuse=evalSHIrradiance(N);
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);
31
+ }`),{vs:r,fs:a}},onBeforeDrawPrimitive(e,t,r,i,a,n){let f=tt.get(e),c=e.getUniformLocation(t,"uHasSH");if(f&&f.length>=27){c&&e.uniform1i(c,1);let s=e.getUniformLocation(t,"uSH");s&&e.uniform3fv(s,f)}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)}},it=new WeakMap;function at(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 a=0;a<i.length;a++){let n=i[a],f=n.getAttribute("data-position");if(!f)continue;let c=f.trim().split(/\s+/).map(l=>parseFloat(l.replace(/m$/,"")));if(c.length<3||c.some(isNaN))continue;let s=n.getAttribute("data-normal"),d;if(s){let l=s.trim().split(/\s+/).map(u=>parseFloat(u));l.length>=3&&!l.some(isNaN)&&(d=[l[0],l[1],l[2]])}let o=r.projectPointToScreen([c[0],c[1],c[2]],d);n.style.position="absolute",n.style.left="0",n.style.top="0",n.style.transform=`translate(-50%, -50%) translate3d(${o.x}px, ${o.y}px, 0)`,n.style.zIndex="3",o.visible?(n.style.opacity="1",n.style.pointerEvents="auto",n.removeAttribute("data-occluded")):(n.style.opacity="0",n.style.pointerEvents="none",n.setAttribute("data-occluded",""))}}var Lt={name:"hotspots",updateHotspotsForElement:at,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{at(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),it.set(e,t)},onCameraChange(e,t){t&&at(t,e)},onElementDisconnected(e){let t=it.get(e);t&&(t.disconnect(),it.delete(e))}};function Ie(e,t,r,i){let a=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,a))}function Br(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function nt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function zr(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function $r(e){let t=nt(e);if(!t)return null;let r=t.target;return{target:Br(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:Ie(t.radius,.01,50,.5),speed:Ie(t.speed,-20,20,.5),height:Ie(t.height,-10,10,0),phase:Ie(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var Hr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],Gr=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],ji=new Set(Hr),Wi=new Set(Gr);function Tt(e,t){let r=zr(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 _t(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:nt(e);if(!t||t.enabled===!1)return null;let r=Ie(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:Ie(t.threshold,0,4,.8),radius:Ie(t.radius,0,2,.5)}:null}function ot(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:nt(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:Tt(t.color,"#38bdf8"),thickness:Ie(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function jr(e,t,r,i){let a=t[0],n=t[1],f=t[2],c=t[3],s=r[0],d=r[1],o=r[2],l=r[3],u=a*s+n*d+f*o+c*l;if(u<0&&(s=-s,d=-d,o=-o,l=-l,u=-u),Math.abs(u)>=1)return e[0]=a,e[1]=n,e[2]=f,e[3]=c,e;let m=Math.acos(u),h=Math.sqrt(1-u*u);if(Math.abs(h)<.001)return e[0]=.5*(a+s),e[1]=.5*(n+d),e[2]=.5*(f+o),e[3]=.5*(c+l),e;let p=Math.sin((1-i)*m)/h,b=Math.sin(i*m)/h;return e[0]=a*p+s*b,e[1]=n*p+d*b,e[2]=f*p+o*b,e[3]=c*p+l*b,e}var Et=1024,lt=256,He=2048,Wr=128,Kr=64,qr=16,Xr=1e4,Zr=8,pe=new Set(["__proto__","constructor","prototype"]),Vt={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))},Ct={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},Ge={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},je=(e,t)=>e!==null&&typeof e=="object"&&!pe.has(t)&&Object.prototype.hasOwnProperty.call(e,t),le=e=>Array.isArray(e)?[...e]:e,Rt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&je(e,"value")?e.value:e,X=(e,t)=>je(e.configuration,t)?Rt(e.configuration[t]):void 0,R=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},Ne=e=>Math.max(0,Math.min(1,e)),ce=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 r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||pe.has(i)||pe.has(r))return null;t.push(i)}return{segments:t}}var Le=(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},Dt=e=>{let t=R(e[0]),r=R(e[1]),i=R(e[2]),a=R(e[3],1),n=Math.hypot(t,r,i,a);return n>1e-8?[t/n,r/n,i/n,a/n]:[0,0,0,1]},Ft=(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 a=[0,0,0,1];return jr(a,Dt(e),Dt(t),r),a}return e.slice(0,t.length).map((a,n)=>a+(t[n]-a)*r)}return r>=.5?t:e},st=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,a)=>r(R(i),R(t[a]))):Array.isArray(e)?e.map(i=>r(R(i),R(t))):Array.isArray(t)?t.map(i=>r(R(e),R(i))):r(R(e),R(t)),Qr=(e,t)=>Array.isArray(e)?e.map(r=>t(R(r))):t(R(e)),Ut=(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,kt=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>Et)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Et})`);let a=Array.isArray(r.variables)?r.variables:[];if(a.length>lt)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${lt})`);let n=Array.isArray(r.declarations)?r.declarations:[],f=Array.isArray(r.events)?r.events:[],c=new Map,s=new Map,d=new Map,o=new Map,l=new Map,u=new Map,m=[],h=[],p=new Map,b=1,v=0,M=0,g=0,y=0,x=!1,P=!1,C=!1;a.forEach((L,w)=>{if(!L||typeof L!="object")return;let _=le(Rt(L.value));c.set(w,_);let E=L.id??L.name;typeof E=="string"&&E&&!pe.has(E)&&c.set(E,_)}),(t?.nodes||[]).forEach((L,w)=>{for(let _ of L?.children||[])typeof _=="number"&&p.set(_,w)});let F=L=>L.op||typeof L.declaration=="number"&&n[L.declaration]?.op||"",I=(L,w,_)=>{if(pe.has(w))return;let E=s.get(L);E||s.set(L,E=Object.create(null)),E[w]=_},B=(L,w)=>{if(typeof L!="number"&&typeof L!="string"||typeof L=="string"&&pe.has(L)||!c.has(L)&&c.size>=lt*2)return;let _=le(w);if(c.set(L,_),typeof L=="number"){let E=a[L]?.id??a[L]?.name;typeof E=="string"&&!pe.has(E)&&c.set(E,_)}},U=L=>typeof L=="number"?f[L]?.id??String(L):typeof L=="string"?/^\d+$/.test(L)&&f[Number(L)]?.id?f[Number(L)].id:L:"",V=(L,w)=>{for(let _=L,E=0;_!==void 0&&_>=0&&E<128;_=p.get(_),E++)if(_===w)return!0;return!1},k=L=>{for(let w=m.length-1;w>=0;w--)m[w].key===L&&m.splice(w,1)},O=L=>{k(L.key),m.length>=Wr&&m.shift(),m.push(L)},ee=L=>{let w=We(L)?.segments;if(w){if(w[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[Le(w[1],t.nodes.length)];if(!_)return;let E=w[2];if(E in Ge){let N=Ge[E],S=_[E]||N;return N.map((A,T)=>R(S[T],A))}if(E==="weights"){let N=Array.isArray(_.weights)?_.weights:[0],S=w.length===4?Le(w[3],64):-2;return S===-2?N.map(A=>R(A)):S>=0?R(N[S]):void 0}if(E==="visible"||E==="extensions"&&w[3]==="KHR_node_visibility"&&w[4]==="visible")return _.extensions?.KHR_node_visibility?.visible??_.visible??!0}else if(w[0]==="materials"&&Array.isArray(t?.materials)){let _=t.materials[Le(w[1],t.materials.length)];if(!_)return;let E=_.pbrMetallicRoughness||{};if(w[2]==="pbrMetallicRoughness"){if(w[3]==="baseColorFactor"){let N=E.baseColorFactor||[1,1,1,1];return[R(N[0],1),R(N[1],1),R(N[2],1),R(N[3],1)]}if(w[3]==="metallicFactor"||w[3]==="roughnessFactor")return R(E[w[3]],1)}if(w[2]==="emissiveFactor"){let N=_.emissiveFactor||[0,0,0];return[R(N[0]),R(N[1]),R(N[2])]}if(w[2]==="alphaCutoff")return R(_.alphaCutoff,.5)}}},J=(L,w)=>{let _=We(L)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let E=Le(_[1],t.nodes.length),N=t.nodes[E];if(!N)return!1;let S=_[2];if(S in Ge&&Array.isArray(w)){let A=Ge[S];if(w.length<A.length)return!1;let T=A.map((H,W)=>R(w[W],H));if(S==="rotation"){let H=Math.hypot(...T);T=H>1e-8?T.map(W=>W/H):[0,0,0,1]}N[S]=T,delete N.matrix;let $=e?.initialNodeTransforms?.[E];return $&&($[S[0]]=[...T]),x=!0,!0}if(S==="weights"){Array.isArray(N.weights)||(N.weights=[]);let A=(T,$)=>{for(let H of e?.meshes||[])if(H.nodeIndex===E)for(let W of H.primitives||[])W.pluginData?.morph?.weights&&(W.pluginData.morph.weights[T]=$)};if(_.length===4){let T=Le(_[3],64);if(T<0)return!1;A(T,N.weights[T]=R(w))}else if(Array.isArray(w))N.weights=w.slice(0,64).map(T=>R(T)),N.weights.forEach((T,$)=>A($,T));else return!1;return C=!0,!0}if(S==="visible"||S==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let A=ce(w);return N.visible=A,(!N.extensions||typeof N.extensions!="object")&&(N.extensions={}),N.extensions.KHR_node_visibility={visible:A},P=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let E=Le(_[1],t.materials.length),N=t.materials[E];if(!N)return!1;let S=N.pbrMetallicRoughness||(N.pbrMetallicRoughness={}),A=T=>{for(let $ of e?.meshes||[])for(let H of $.primitives||[])(H.materialIndex??0)===E&&T(H)};if(_[2]==="pbrMetallicRoughness"){if(_[3]==="baseColorFactor"&&Array.isArray(w)&&w.length>=3){let T=[Ne(R(w[0],1)),Ne(R(w[1],1)),Ne(R(w[2],1)),w[3]!==void 0?Ne(R(w[3],1)):S.baseColorFactor?.[3]??1];return S.baseColorFactor=T,A($=>$.baseColor=[...T]),C=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let T=_[3]==="metallicFactor",$=Ne(R(w,T?0:.5));return S[_[3]]=$,A(H=>H[T?"metallic":"roughness"]=$),C=!0}}if(_[2]==="emissiveFactor"&&Array.isArray(w)&&w.length>=3)return N.emissiveFactor=[0,1,2].map(T=>Math.max(0,R(w[T]))),C=!0;if(_[2]==="alphaCutoff")return N.alphaCutoff=Ne(R(w,.5)),C=!0}return!1},K=(L,w,_=new Set)=>{let E=X(w,"pointer");if(typeof E!="string"||!E.startsWith("/"))return null;let N=E.replace(/\{([a-zA-Z0-9_]+)\}/g,(S,A)=>{let T=Math.trunc(Number(re(L,A,void 0,_)??X(w,A)));return Number.isSafeInteger(T)&&T>=0?String(T):"-1"});return We(N)?N:null},re=(L,w,_,E)=>{let N=i[L]?.values;if(!je(N,w))return _;let S=N[w];if(S==null)return _;if(typeof S!="object"||Array.isArray(S))return le(S);let A=S;return typeof A.node=="number"?Pe(A.node,A.socket||"value",E):je(A,"value")?le(A.value):_},Pe=(L,w,_)=>{if(L<0||L>=i.length||_.has(L)||_.size>128||++g>Xr)return;let E=i[L],N=F(E);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(N))return le(s.get(L)?.[w]);_.add(L);try{let S=(A,T=0)=>re(L,A,T,_);if(N==="variable/get"){let A=X(E,"variable")??X(E,"id");return typeof A=="number"||typeof A=="string"?le(c.get(A)):void 0}if(N==="pointer/get"){let A=K(L,E,_);return A?ee(A):void 0}if(N.startsWith("math/")){let A=N.slice(5);if(A in Vt)return Qr(S("a"),Vt[A]);if(A in Ct){let T=/^(mul|div|rem|mod|pow)$/.test(A)?1:0;return st(S("a",A==="mul"?1:0),S("b",T),Ct[A])}if(A==="pi")return Math.PI;if(A==="e")return Math.E;if(A==="random")return Math.random();if(A==="clamp")return st(st(S("a"),S("b",S("min",0)),Math.max),S("c",S("max",1)),Math.min);if(A==="mix"||A==="quatSlerp")return Ft(S("a",0),S("b",1),R(S("c",S("t",.5)),.5),A==="quatSlerp");if(A==="dot"){let T=S("a"),$=S("b");return Array.isArray(T)&&Array.isArray($)?T.reduce((H,W,D)=>H+(W||0)*($[D]||0),0):R(T)*R($)}if(A==="cross"){let T=S("a",[0,0,0]),$=S("b",[0,0,0]);return Array.isArray(T)&&Array.isArray($)?[(T[1]||0)*($[2]||0)-(T[2]||0)*($[1]||0),(T[2]||0)*($[0]||0)-(T[0]||0)*($[2]||0),(T[0]||0)*($[1]||0)-(T[1]||0)*($[0]||0)]:[0,0,0]}if(A==="length"){let T=S("a");return Array.isArray(T)?Math.hypot(...T):Math.abs(R(T))}if(A==="distance"){let T=S("a"),$=S("b");return Array.isArray(T)&&Array.isArray($)?Math.hypot(...T.map((H,W)=>(H||0)-($[W]||0))):Math.abs(R(T)-R($))}if(A==="normalize"){let T=S("a");if(!Array.isArray(T))return R(T)>=0?1:-1;let $=Math.hypot(...T);return $>1e-8?T.map(H=>H/$):T.map(()=>0)}if(A.startsWith("combine"))return["a","b","c","d"].slice(0,Number(A[7])||2).map(T=>R(S(T)));if(A.startsWith("extract")){let T=S("a");return Array.isArray(T)?T[w==="0"||w==="x"?0:w==="1"||w==="y"?1:w==="2"||w==="z"?2:3]??0:0}if(A==="eq")return Ut(S("a"),S("b"));if(A==="ne")return!Ut(S("a"),S("b"));if(A==="lt")return R(S("a"))<R(S("b"));if(A==="le")return R(S("a"))<=R(S("b"));if(A==="gt")return R(S("a"))>R(S("b"));if(A==="ge")return R(S("a"))>=R(S("b"));if(A==="isNaN")return Number.isNaN(Number(S("a")));if(A==="isInf"){let T=Number(S("a"));return!Number.isFinite(T)&&!Number.isNaN(T)}return A==="and"?ce(S("a",!1))&&ce(S("b",!1)):A==="or"?ce(S("a",!1))||ce(S("b",!1)):A==="xor"?ce(S("a",!1))!==ce(S("b",!1)):A==="not"?!ce(S("a",!1)):A==="select"?le(ce(S("condition",!1))?S("a"):S("b")):void 0}return N==="type/boolToInt"||N==="type/boolToFloat"?ce(S("a",!1))?1:0:N==="type/intToBool"||N==="type/floatToBool"?R(S("a",0))!==0:N==="type/intToFloat"?R(S("a",0)):N==="type/floatToInt"?Math.trunc(R(S("a",0))):void 0}finally{_.delete(L)}},xe=()=>{if(x){x=!1,C=!0;let L=St(t);if(e){e.worldMatrices=L;for(let w of e.meshes||[])w.nodeIndex>=0&&w.nodeIndex<L.length&&(w.transform.set(L[w.nodeIndex]),$e(w.normalMatrix,w.transform))}}if(P){P=!1,C=!0;let L=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(L))for(let w of e.meshes){let _=!0;for(let E=w.nodeIndex,N=0;E!==void 0&&E>=0&&N<128;E=p.get(E),N++){let S=L[E];if(S?.visible===!1||S?.extensions?.KHR_node_visibility?.visible===!1){_=!1;break}}w.visible=_}}C&&(C=!1,e?.render?.())},Z=(L,w={steps:0})=>{if(!L||typeof L.node!="number")return;w.steps===0&&(g=0);let _=[L],E=N=>{_.length+w.steps<He&&_.push(N)};for(;_.length>0&&w.steps<He;){w.steps++;let N=_.shift();if(!N||N.node<0||N.node>=i.length)continue;let S=N.node,A=i[S];if(!A)continue;let T=N.socket||"in",$=F(A),H=(D,z=void 0)=>re(S,D,z,new Set),W=(D="out")=>{let z=A.flows?.[D];z&&E(z)};switch($){case"flow/branch":W(ce(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let D of Object.keys(A.flows||{}).sort((z,Y)=>Number(z)-Number(Y)||z.localeCompare(Y)))W(D);break;case"flow/switch":{let D=A.flows?.[String(H("selection",H("value",0)))]??A.flows?.default;D&&E(D);break}case"flow/for":{let D=Math.trunc(R(H("startIndex",0))),z=Math.trunc(R(H("endIndex",0))),Y=Math.max(1,Math.trunc(R(H("step",1),1))),te=A.flows?.body;if(te&&z>D&&y<Zr){let G=Math.min(Math.ceil((z-D)/Y),He);y++;try{for(let ae=0;ae<G&&w.steps<He;ae++)I(S,"index",D+ae*Y),Z(te,w)}finally{y--}}let Me=A.flows?.completed??A.flows?.out;Me&&E(Me);break}case"flow/doN":{let D=T==="reset"?0:(d.get(S)||0)+1;if(d.set(S,D),I(S,"currentCount",D),I(S,"count",D),T!=="reset"){let z=Math.trunc(R(H("n",X(A,"stopIterations")??X(A,"n")??1),1));D<=z&&W()}break}case"flow/multiGate":{if(T==="reset"){u.set(S,0);break}let D=Object.keys(A.flows||{}).sort();if(!D.length)break;let z=X(A,"isRandom")?Math.floor(Math.random()*D.length):u.get(S)||0;z<D.length&&(W(D[z]),u.set(S,X(A,"isLoop")!==!1?(z+1)%D.length:z+1));break}case"flow/waitAll":{if(T==="reset"){o.delete(S);break}let D=o.get(S);D||o.set(S,D=new Set),D.add(T),D.size>=Math.max(1,Math.trunc(Number(X(A,"inputFlows")??2)||2))&&(D.clear(),W("out"),W("completed"));break}case"flow/throttle":{if(T==="reset"){l.delete(S);break}let D=Math.max(0,R(H("duration",0))),z=l.get(S);z===void 0||v-z>=D?(l.set(S,v),I(S,"lastRemainingTime",0),W()):I(S,"lastRemainingTime",Math.max(0,D-(v-z)));break}case"flow/delay":case"flow/setDelay":{if(T==="cancel"){for(let te=h.length-1;te>=0;te--)h[te].nodeIdx===S&&h.splice(te,1);I(S,"lastDelayIndex",-1);break}let D=Math.max(0,R(H("duration",X(A,"duration")??0))),z=A.flows?.done??A.flows?.out;if(D<=0){I(S,"lastDelayIndex",-1),z&&E(z);break}h.length>=Kr&&h.shift();let Y=b++;I(S,"lastDelayIndex",Y),h.push({id:Y,nodeIdx:S,rem:D,done:z}),$==="flow/setDelay"&&A.flows?.out&&A.flows?.done&&W("out");break}case"flow/cancelDelay":{let D=Math.trunc(R(H("delayIndex",-1),-1));if(D<0)h.length=0;else for(let z=h.length-1;z>=0;z--)h[z].id===D&&h.splice(z,1);W();break}case"variable/set":B(X(A,"variable")??X(A,"id"),H("value")),W();break;case"variable/interpolate":{let D=X(A,"variable")??X(A,"id"),z=H("value",H("target")),Y=Math.max(0,R(H("duration",X(A,"duration")??.3),.3));D!==void 0&&z!==void 0&&O({key:`var:${String(D)}`,varKey:D,from:le(H("from")??c.get(D)??0),to:le(z),dur:Y,elapsed:0,quat:!1,linear:X(A,"easing")==="linear",done:A.flows?.done}),W();break}case"pointer/set":{let D=K(S,A),z=H("value");D&&z!==void 0&&(k(`ptr:${D}`),J(D,z)),W();break}case"pointer/interpolate":{let D=K(S,A),z=H("value",H("target")),Y=Math.max(0,R(H("duration",X(A,"duration")??.3),.3));if(D&&z!==void 0){let te=H("from")??ee(D);te!==void 0&&(Y<=0?(J(D,z),W("done")):O({key:`ptr:${D}`,ptr:D,from:le(te),to:le(z),dur:Y,elapsed:0,quat:D.endsWith("/rotation"),linear:X(A,"easing")==="linear",done:A.flows?.done}))}W();break}case"animation/start":{let D=H("animation")??X(A,"animation")??X(A,"clipName"),z=typeof D=="number"?e?.animations?.[D]?.name??t?.animations?.[D]?.name:typeof D=="string"?D:void 0;e?.playAnimation?.(z),C=!0,W();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),$==="animation/resetAt"&&e?.evaluateAnimation?.(R(H("time",0))),C=!0,W();break;case"event/send":case"customEvent/send":{let D=U(X(A,"event")??X(A,"id")),z={};for(let Y of Object.keys(A.values||{}))pe.has(Y)||(z[Y]=H(Y));D&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:D,values:z}})),Q(D,z,w)),W();break}default:W();break}}};this.readScenePointer=ee,this.writeScenePointer=J,this.fireOnStart=()=>{i.forEach(L=>{F(L)==="event/onStart"&&Z(L.flows?.out)}),xe()},this.fireOnSelect=L=>{if(!L)return;let w=typeof L.meshIndex=="number"?L.meshIndex:-1,_=typeof L.nodeIndex=="number"?L.nodeIndex:e?.meshes?.[w]?.nodeIndex??-1;i.forEach((E,N)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(F(E)))return;let S=X(E,"nodeIndex")??X(E,"node")??re(N,"nodeIndex",void 0,new Set),A=X(E,"meshName");if(typeof A=="string"&&A?L.meshName===A:S==null||Number(S)<0||Number.isNaN(Number(S))||V(_,Math.trunc(Number(S)))){if(I(N,"nodeIndex",_),I(N,"meshIndex",w),Array.isArray(L.hitPoint)){let T=[R(L.hitPoint[0]),R(L.hitPoint[1]),R(L.hitPoint[2])];I(N,"hitPoint",T),I(N,"point",T),I(N,"intersectionPoint",T)}if(Array.isArray(L.normal)){let T=[R(L.normal[0]),R(L.normal[1],1),R(L.normal[2])];I(N,"normal",T),I(N,"hitNormal",T)}typeof L.distance=="number"&&I(N,"distance",L.distance),Z(E.flows?.out)}}),xe()},this.receiveCustomEvent=(L,w={})=>Q(L,w,{steps:0});function Q(L,w,_){if(!(M>=qr)){M++;try{let E=U(L);i.forEach((N,S)=>{if(!/^(customE|e)vent\/receive$/.test(F(N)))return;let A=X(N,"event")??X(N,"id");if(!(U(A)!==E&&String(A)!==String(L))){for(let[T,$]of Object.entries(w))pe.has(T)||I(S,T,le($));Z(N.flows?.out,_)}}),xe()}finally{M--}}}this.tick=L=>{if(!Number.isFinite(L)||L<0)return;let w=Math.min(L,.25);v+=w,i.forEach((E,N)=>{F(E)==="event/onTick"&&(I(N,"timeDelta",w),I(N,"dt",w),I(N,"timeElapsed",v),Z(E.flows?.out))});let _=[];for(let E=m.length-1;E>=0;E--){let N=m[E];N.elapsed+=w;let S=N.dur>1e-6?Ne(N.elapsed/N.dur):1,A=N.linear?S:S*S*(3-2*S),T=Ft(N.from,N.to,A,N.quat);N.ptr?J(N.ptr,T):N.varKey!==void 0&&B(N.varKey,T),S>=1&&(m.splice(E,1),N.done&&_.push(N.done))}for(let E=h.length-1;E>=0;E--){let N=h[E];N.rem-=w,N.rem<=0&&(h.splice(E,1),N.done&&_.push(N.done))}for(let E of _)Z(E);xe()},this.dispose=()=>{m.length=0,h.length=0,c.clear(),s.clear(),d.clear(),o.clear(),l.clear(),u.clear()}}},he=new WeakMap,Ke=new WeakMap;function Yr(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Cr().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 a=Math.min(t,.1),n=(Ke.get(e)||0)+a,f=!1;for(let c=0;c<i.length;c++){let s=i[c],d=$r(s?.extras?.xr?.orbit);if(!d)continue;let o=0,l=0,u=0;if(Array.isArray(d.target))o=d.target[0],l=d.target[1],u=d.target[2];else if(typeof d.target=="string"&&d.target!=="head"){let v=i.find(M=>M?.name===d.target);Array.isArray(v?.translation)&&(o=R(v.translation[0]),l=R(v.translation[1]),u=R(v.translation[2]))}let m=d.phase+d.speed*n,h=o+Math.cos(m)*d.radius,p=l+d.height,b=u+Math.sin(m)*d.radius;if(s.translation=[h,p,b],d.faceCenter){let v=Math.atan2(o-h,u-b);s.rotation=[0,Math.sin(v*.5),0,Math.cos(v*.5)]}f=!0}if(f){Ke.set(e,n);let c=St(r);e.worldMatrices=c;for(let s of e.meshes||[])s.nodeIndex>=0&&s.nodeIndex<c.length&&(s.transform.set(c[s.nodeIndex]),$e(s.normalMatrix,s.transform))}}function ut(e){if(!(!e||typeof e!="object"))return he.get(e)||he.get(e.viewer)||he.get(e._view)}function Ot(e,t,r){let i=ut(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var Bt={name:"khr-interactivity",sendInteractivityEvent:Ot,getInteractivityVM:ut,onLoadModel(e,t){if(!e||typeof e!="object")return;he.get(e)?.dispose(),he.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 a=new kt(e,t,i);he.set(e,a),a.fireOnStart()},onMeshSelect(e,t){he.get(e)?.fireOnSelect(t)},onUpdate(e,t){he.get(e)?.tick(t),Yr(e,t)},onDestroy(e,t){he.get(t)?.dispose(),he.delete(t),Ke.delete(t)}};function qe(e,t){let r=(o,l,u,m)=>{let h=typeof o=="number"?o:Number(o);return Number.isFinite(h)?Math.max(l,Math.min(u,h)):m};function i(o,l,u=0,m=.05,h){if(!o||!o.length)return-1;let p=o[0]>0?[0,...o]:o,b=Number.isFinite(l)?Math.max(0,l):0,v=Number.isFinite(m)?Math.max(0,Math.min(.5,m)):.05;if(typeof h=="number"&&Number.isFinite(h)&&h>0){let y=u===-1?h*(1-v):h*(1+v);if(b>y)return-1}let M=0;for(let y=p.length-1;y>=1;y--)if(b>=p[y]){M=y;break}if(u<0||u>=p.length||u===M)return M;if(M>u){let y=u;for(let x=u+1;x<=M&&b>=p[x]*(1+v);x++)y=x;return y}let g=u;for(let y=u;y>M&&b<p[y]*(1-v);y--)g=y-1;return g}function a(o){if(!o)return null;let l=o===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(o)?{distances:o}:typeof o=="object"?o:null;if(!l||l.enabled===!1)return null;let u=r(l.hysteresis,0,.5,.05),m=[],h;if(Array.isArray(l.levels)&&l.levels.length>0){let M=l.levels.slice(0,8);for(let y=0;y<M.length;y++){let x=M[y];if(!x||typeof x!="object"||Array.isArray(x))continue;let P=x,C=r(P.distance,0,1e4,y===0?0:y*4),F=typeof P.hysteresis=="number"?r(P.hysteresis,0,.5,u):void 0,I=typeof P.ratio=="number"?r(P.ratio,.05,1,.5):void 0,B=typeof P.childIndex=="number"&&Number.isFinite(P.childIndex)?Math.max(0,Math.round(P.childIndex)):void 0,U=typeof P.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(P.node.trim())?P.node.trim().slice(0,64):void 0;m.push({distance:C,...F!==void 0?{hysteresis:F}:{},...I!==void 0?{ratio:I}:{},...B!==void 0?{childIndex:B}:{},...U?{node:U}:{}})}m.sort((y,x)=>y.distance-x.distance),m.length>0&&m[0].distance>0&&m.unshift({distance:0,childIndex:0});let g=0;m=m.slice(0,8).map((y,x)=>{let P=x===0?0:Math.max(g,y.distance);return g=P,{...y,distance:P,childIndex:y.childIndex??x}})}if(Array.isArray(l.ratios)&&l.ratios.length>0){let M=[];for(let g of l.ratios.slice(0,7))typeof g=="number"&&M.push(r(g,.05,1,.5));M.length>0&&(h=M)}if(m.length===0){let M=Array.isArray(l.distances)?l.distances:[],g=[];for(let x of M.slice(0,8))typeof x=="number"&&g.push(r(x,0,1e4,4));if(g.length===0&&h&&h.length>0)for(let x=0;x<h.length;x++)g.push((x+1)*4);if(g.length===0&&l.cullDistance===void 0)return null;g.length===0||g[0]>0?g.unshift(0):h&&h.length===g.length&&h[0]===1&&(h=h.slice(1));let y=0;for(let x=0;x<Math.min(8,g.length);x++){let P=x===0?0:Math.max(y,g[x]);y=P;let C=x>0&&h?h[x-1]:void 0;m.push({distance:P,childIndex:x,...C!==void 0?{ratio:C}:{}})}}else if(!h){let M=[];for(let g=1;g<m.length;g++)typeof m[g].ratio=="number"&&M.push(m[g].ratio);M.length>0&&(h=M)}let p=m.map(M=>M.distance),b=p[p.length-1]??0,v=l.cullDistance!==void 0&&l.cullDistance!==null&&l.cullDistance!==!1?r(l.cullDistance,Math.max(1,b),1e4,100):void 0;return{levels:m,distances:p,...h?{ratios:h}:{},hysteresis:u,...v!==void 0?{cullDistance:v}:{}}}function n(o,l){let u=o?.attributes?.position;if(!u||!u.array||u.count<3)return o;let m=r(l,.05,1,.5),h=u.array,p=u.count,b=o.attributes?.normal?.array,v=o.attributes?.uv?.array,M=o.index?.array,g=Math.floor((M?M.length:p)/3);if(g<1)return o;let y=Math.max(1,Math.min(g,Math.round(g*m))),x=1/0,P=1/0,C=1/0,F=-1/0,I=-1/0,B=-1/0;for(let w=0;w<p;w++){let _=h[w*3],E=h[w*3+1],N=h[w*3+2];_<x&&(x=_),E<P&&(P=E),N<C&&(C=N),_>F&&(F=_),E>I&&(I=E),N>B&&(B=N)}let U=Math.max(1e-5,F-x),V=Math.max(1e-5,I-P),k=Math.max(1e-5,B-C),O=Math.max(U,V,k),ee=w=>{let _=Math.max(1,Math.round(U/O*w)),E=Math.max(1,Math.round(V/O*w)),N=Math.max(1,Math.round(k/O*w)),S=new Map,A=new Int32Array(p),T=[],$=[],H=[],W=[];for(let G=0;G<p;G++){let ae=h[G*3],we=h[G*3+1],Se=h[G*3+2],se=Math.min(_-1,Math.max(0,Math.floor((ae-x)/U*_))),ne=Math.min(E-1,Math.max(0,Math.floor((we-P)/V*E))),Ae=Math.min(N-1,Math.max(0,Math.floor((Se-C)/k*N))),Ce=se+ne*_+Ae*_*E,ie=S.get(Ce);ie===void 0?(ie=W.length,S.set(Ce,ie),T.push(ae,we,Se),b&&$.push(b[G*3],b[G*3+1],b[G*3+2]),v&&H.push(v[G*2],v[G*2+1]),W.push(1)):(T[ie*3]+=ae,T[ie*3+1]+=we,T[ie*3+2]+=Se,b&&($[ie*3]+=b[G*3],$[ie*3+1]+=b[G*3+1],$[ie*3+2]+=b[G*3+2]),W[ie]++),A[G]=ie}let D=[],z=new Set;for(let G=0;G<g;G++){let ae=M?M[G*3]:G*3,we=M?M[G*3+1]:G*3+1,Se=M?M[G*3+2]:G*3+2,se=A[ae],ne=A[we],Ae=A[Se];if(se===ne||ne===Ae||Ae===se)continue;let Ce=Math.min(se,ne,Ae),ie=Math.max(se,ne,Ae),Er=se+ne+Ae-Ce-ie,Mt=`${Ce}_${Er}_${ie}`;z.has(Mt)||(z.add(Mt),D.push(se,ne,Ae))}let Y=W.length,te=new Float32Array(Y*3),Me=b?new Float32Array(Y*3):null;for(let G=0;G<Y;G++){let ae=1/W[G];if(te[G*3]=T[G*3]*ae,te[G*3+1]=T[G*3+1]*ae,te[G*3+2]=T[G*3+2]*ae,Me){let we=$[G*3],Se=$[G*3+1],se=$[G*3+2],ne=Math.hypot(we,Se,se)||1;Me[G*3]=we/ne,Me[G*3+1]=Se/ne,Me[G*3+2]=se/ne}}return{pos:te,norm:Me,uv:v?new Float32Array(H):null,tris:D,triCount:D.length/3,vertCount:Y}},J=Math.max(2,Math.round(Math.sqrt(y/4))),K=ee(J);if(K.triCount>y*1.25&&J>2){let w=Math.max(2,Math.round(J*Math.sqrt(y/K.triCount)));if(w!==J){let _=ee(w);_.triCount>=Math.min(4,y)&&(K=_)}}else if(K.triCount<Math.min(4,y)){let w=ee(Math.max(J*2,8));w.triCount>K.triCount&&(K=w)}let re=K.tris;if(m<1&&K.triCount>y){let w=[],_=K.triCount/y;for(let E=0;E<y;E++){let N=Math.min(K.triCount-1,Math.floor(E*_));w.push(K.tris[N*3],K.tris[N*3+1],K.tris[N*3+2])}re=w}if(re.length<3){re=[];for(let w=0;w<y*3;w++)re.push(M?M[w]:w);K={pos:h.slice(),norm:b?b.slice():null,uv:v?v.slice():null,tris:re,triCount:y,vertCount:p}}let Pe=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),xe=Pe?.BufferGeometry??o.constructor,Z=Pe?.BufferAttribute??u.constructor,Q=new xe;Q.setAttribute("position",new Z(K.pos,3)),K.norm&&Q.setAttribute("normal",new Z(K.norm,3)),K.uv&&Q.setAttribute("uv",new Z(K.uv,2));let L=K.vertCount>65535?new Uint32Array(re):new Uint16Array(re);return typeof Q.setIndex=="function"?Q.setIndex(new Z(L,1)):Q.index=new Z(L,1),Q}let f=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(...o){for(let l of o)l&&(l.parent=this,this.children.push(l));return this}};class c extends f{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(l,u=0,m=.05){if(!l)return this;let h=Math.max(0,Number.isFinite(Number(u))?Number(u):0),p=r(m,0,.5,.05),b=this.levels.length;for(let g=0;g<this.levels.length;g++)if(h<this.levels[g].distance){b=g;break}this.levels.splice(b,0,{object:l,distance:h,hysteresis:p}),this.add(l);let v=this.levels.map(g=>g.object),M=this.children.filter(g=>!v.includes(g));this.children=[...v,...M];for(let g=0;g<this.levels.length;g++)this.levels[g].object.visible=g===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(l){if(!this.levels.length)return null;let u=i(this.levels.map(m=>m.distance),l,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return u>=0&&u<this.levels.length?this.levels[u].object:null}update(l){if(this.levels.length===0||!l)return;let u=l.position??{x:0,y:0,z:0},m=this.position??{x:0,y:0,z:0},h=Math.hypot((Number(u.x)||0)-(Number(m.x)||0),(Number(u.y)||0)-(Number(m.y)||0),(Number(u.z)||0)-(Number(m.z)||0)),p=i(this.levels.map(b=>b.distance),h,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=p;for(let b=0;b<this.levels.length;b++)this.levels[b].object.visible=b===p}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let l=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((u,m)=>({distance:u.distance,hysteresis:u.hysteresis,childIndex:m,...u.object?.name?{node:u.object.name}:{}})),distances:this.levels.map(u=>u.distance),hysteresis:this.levels[0]?.hysteresis??.05,...l!==void 0?{cullDistance:l}:{}}}}function s(o){if(!o||o._lodMaterialized||!o.userData?.xr?.lod||o.isLOD||Array.isArray(o.children)&&o.children.length>0)return;let l=o.geometry?.attributes?.position;if(!l||!l.array||l.count<3)return;let u=a(o.userData.xr.lod);if(!u||u.levels.length<2)return;o._lodMaterialized=!0;let m=o.geometry;o._lodOriginalGeometry=m;let h=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),p=h?.Mesh??o.constructor,b=h?.BufferGeometry??m.constructor,v=typeof o.name=="string"&&o.name.trim()?o.name.trim():"Mesh",M=new p(m,o.material);M.name=`${v}_LOD0`,M.visible=!0,M.castShadow=!!o.castShadow,M.receiveShadow=!!o.receiveShadow,o.add(M);for(let g=1;g<u.levels.length;g++){let y=u.levels[g].ratio??u.ratios?.[g-1]??Math.max(.05,Math.pow(.5,g)),x=n(m,y),P=new p(x,o.material);P.name=`${v}_LOD${g}`,P.visible=!1,P.castShadow=!!o.castShadow,P.receiveShadow=!!o.receiveShadow,o.add(P)}o.geometry=new b,o.userData.xr.lod={...u,levels:u.levels.map((g,y)=>({...g,childIndex:y,node:`${v}_LOD${y}`}))}}let d={LOD:c,decimateGeometry:n,selectLodLevelIndex:i,parseLod:a,materializeLodGeometry:s};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:c,decimateGeometry:n}),t._lodMaterialize=s,t.materializeDeclarativeGeometry=o=>{t._cadMaterialize?.(o),t._lodMaterialize?.(o),t._procMaterialize?.(o)}),d}var Re=qe(),Jr=Re.decimateGeometry,ft=Re.selectLodLevelIndex,ct=Re.parseLod,Ki=Re.materializeLodGeometry,ei=Re.LOD,De=new WeakMap;function ti(e){return e&&typeof e=="object"?De.get(e):void 0}var zt=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 a=t.get(i.nodeIndex);a||(a=[],t.set(i.nodeIndex,a)),a.push(i)}let r=i=>{let a=[],n=new Set,f=[i];for(;f.length>0;){let c=f.pop();if(n.has(c)||c<0||c>=e.length)continue;n.add(c);let s=t.get(c);s&&a.push(...s);let d=e[c]?.children;if(Array.isArray(d))for(let o=d.length-1;o>=0;o--)typeof d[o]=="number"&&f.push(d[o])}return a};for(let i=0;i<e.length;i++){let a=e[i];if(!a||typeof a!="object")continue;let n=a.extras?.xr?.lod??a.extensions?.ANDROID_xr_scenecore?.lod??a.extensions?.MOZ_hubs_components?.lod,f=Array.isArray(a.extensions?.MSFT_lod?.ids)?a.extensions.MSFT_lod.ids.filter(m=>typeof m=="number"&&Number.isInteger(m)&&m>=0&&m<e.length):[],c=ct(n);if(!c&&f.length>0&&(c=ct({distances:f.map((m,h)=>h*4)})),!c)continue;let s=f.length>0?f:Array.isArray(a.children)?a.children.filter(m=>typeof m=="number"&&Number.isInteger(m)&&m>=0&&m<e.length):[],d=[],o=[];if(s.length>0){let m=Math.min(s.length,c.levels.length);for(let h=0;h<m;h++){let p=s[h];d.push(p),o.push(r(p))}}else{let m=t.get(i)??[];if(m.length===0)continue;d.push(i),o.push(m)}let l=c.distances.slice(0,o.length);l.length===0&&l.push(0);let u={nodeIndex:i,name:typeof a.name=="string"?a.name:`LOD_${i}`,distances:l,hysteresis:c.hysteresis,...c.cullDistance!==void 0?{cullDistance:c.cullDistance}:{},childNodeIndices:d,levelMeshes:o,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(u,0),this.groups.push(u)}}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 a=ft(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=a,this.applyGroupVisibility(r,a);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 a=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,n=a&&a[12]||0,f=a&&a[13]||0,c=a&&a[14]||0,s=r?r[0]*n+r[4]*f+r[8]*c+r[12]:n,d=r?r[1]*n+r[5]*f+r[9]*c+r[13]:f,o=r?r[2]*n+r[6]*f+r[10]*c+r[14]:c,l=Math.hypot((e[0]||0)-s,(e[1]||0)-d,(e[2]||0)-o);if(i.lastDistance=l,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let u=ft(i.distances,l,i.activeLevelIndex,i.hysteresis,i.cullDistance);u!==i.activeLevelIndex&&(i.activeLevelIndex=u,this.applyGroupVisibility(i,u))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let a=i===t;for(let c of e.levelMeshes[i])c.visible=a;let n=e.childNodeIndices[i],f=Array.isArray(r)?r[n]:null;f&&typeof f=="object"&&(f.visible=a,f.extensions=f.extensions||{},f.extensions.KHR_node_visibility={visible:a})}}},$t={name:"lod",onRegister(){Vr(qe);let e=de(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);qe(t,e)},onLoadModel(e,t){!e||typeof e!="object"||De.set(e,new zt(e,t))},onUpdate(e){let t=De.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},a=r?.radius??3,n=r?.phi??0,f=r?.theta??0,c=Math.cos(n),s=(i.x||0)+a*c*Math.sin(f),d=(i.y||0)+a*Math.sin(n),o=(i.z||0)+a*c*Math.cos(f);t.update([s,d,o])},onBeforeDrawScene(e,t,r,i){let a=De.get(e);a&&a.update(i)},onDestroy(e,t){t&&typeof t=="object"&&De.delete(t)}},Fe=new Map,Xe=new WeakMap;function ri(e,t){Fe.set(e,t)}var Ht={name:"materials",onContextRestored(e){Xe.delete(e)},onBuildPrimitiveVAO(e,t,r,i,a){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=Xe.get(e);r||(r=e.createTexture(),Xe.set(e,r));let i=Math.max(1,t.canvas.width),a=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,a,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&&Fe.has(t.name)){let h=Fe.get(t.name);return{vs:h.vs||r,fs:h.fs||i}}let a=t.extensions||{},n=a.KHR_materials_clearcoat,f=a.KHR_materials_sheen,c=!!a.KHR_materials_transmission,s=!!a.KHR_materials_ior,d=a.KHR_materials_iridescence;if(!n&&!f&&!a.KHR_materials_unlit&&!c&&!a.KHR_materials_volume&&!s&&!a.KHR_materials_dispersion&&!d)return null;if(a.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 o=i;if(c){let h=o.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
32
+ `;o=o.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
33
+ ${h}out vec4 fragColor;`)}let l=(h,p,b=0,v=1e6,M=3)=>{let g=Number(h);return(Number.isFinite(g)?Math.min(v,Math.max(b,g)):p).toFixed(M)},u=Number(a.KHR_materials_ior?.ior??1.5),m=Number.isFinite(u)?Math.min(10,Math.max(1,u)):1.5;if(s){let h=Math.pow((m-1)/(m+1),2);o=o.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${l(h,.04,0,1,4)}),base.rgb,metallic);`)}if(d){let h=l(d.iridescenceFactor,1,0,1),p=l(d.iridescenceIor,1.3,1,10);o=o.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${p}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${h}*pow(1.-NoV,2.));`)}if(c){let h=l(a.KHR_materials_transmission?.transmissionFactor,1,0,1),p=a.KHR_materials_volume||{},b=l(p.thicknessFactor,.5,0,1e4),v=l(p.attenuationDistance,1,.001,1e6),M=Array.isArray(p.attenuationColor)?p.attenuationColor:[1,1,1],g=l(a.KHR_materials_dispersion?.dispersion,0,0,10);o=o.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=${l(m,1.5,1,10)},dV=${g},tV=${b},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
35
35
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
36
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);
37
- vec3 aCol=vec3(${u(S[0],1,0,1)},${u(S[1],1,0,1)},${u(S[2],1,0,1)});
37
+ vec3 aCol=vec3(${l(M[0],1,0,1)},${l(M[1],1,0,1)},${l(M[2],1,0,1)});
38
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
39
+ diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${h});`)}if(n&&!i.includes("uClearcoat")){let h=l(n.clearcoatFactor,1,0,1),p=l(n.clearcoatRoughnessFactor,0,0,1);o=o.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${p},NoV)*${h};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${p})*ccF;fragColor=vec4(color,base.a);`)}if(f){let h=Array.isArray(f.sheenColorFactor)?f.sheenColorFactor:[1,1,1],p=`color+=vec3(${l(h[0],1,0,1)},${l(h[1],1,0,1)},${l(h[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;o.includes("color=applyToneMapping(color,uToneMapping);")?o=o.replace("color=applyToneMapping(color,uToneMapping);",`${p}color=applyToneMapping(color,uToneMapping);`):o=o.replace("fragColor=vec4(color,base.a);",`${p}fragColor=vec4(color,base.a);`)}return{vs:r,fs:o}},onBeforeDrawPrimitive(e,t,r,i,a,n){let f=r.materialIndex;if(f!==void 0&&n?.materials){let c=n.materials[f];c?.name&&Fe.has(c.name)&&Fe.get(c.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let c=Xe.get(e);if(c){e.activeTexture(33990),e.bindTexture(3553,c);let s=e.getUniformLocation(t,"uTransmissionTex");s&&e.uniform1i(s,6);let d=e.getUniformLocation(t,"uViewportSize");d&&e.uniform2f(d,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},Gt=64*1024*1024,jt=128*1024*1024,ii=16777216;function ai(e){return(e>>>1^-(e&1))&255}function ni(e){return(e>>>1^-(e&1))&65535}function oi(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Wt(e){return(e<<1^e>>31)>>>0}function Kt(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 Te(e){return Math.trunc(j(e+(e>=0?.5:-.5)))}function qt(e,t,r,i="NONE"){if(Kt(i),!i||i==="NONE"||t<=0)return;let a=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 l=r===8,u=l?32767:127,m=b=>l?a.getInt16(b,!0):a.getInt8(b),h=(b,v)=>l?a.setInt16(b,v,!0):a.setInt8(b,v<<24>>24),p=l?2:1;for(let b=0;b<t;b++){let v=b*r,M=m(v),g=m(v+p),y=j(m(v+2*p)-Math.abs(M)-Math.abs(g)),x=y>=0?0:y;M=j(M+(M>=0?x:-x)),g=j(g+(g>=0?x:-x));let P=j(Math.sqrt(j(j(j(M*M)+j(g*g))+j(y*y))));if(P===0){h(v,0),h(v+p,0),h(v+2*p,u);continue}let C=j(u/P);h(v,Te(j(M*C))),h(v+p,Te(j(g*C))),h(v+2*p,Te(j(y*C)))}return}if(i==="QUATERNION"){if(r!==8)throw q(`QUATERNION filter requires byteStride 8 (got ${r})`);let l=j(32767/j(Math.SQRT2));for(let u=0;u<t;u++){let m=u*8,h=a.getInt16(m+6,!0),p=h|3,b=a.getInt16(m,!0),v=a.getInt16(m+2,!0),M=a.getInt16(m+4,!0),g=j(p*p),y=j(j(j(j(g*2)-j(b*b))-j(v*v))-j(M*M)),x=j(Math.sqrt(y>=0?y:0)),P=j(l/p),C=h&3,F=[0,0,0,0];F[C+1&3]=Te(j(b*P)),F[C+2&3]=Te(j(v*P)),F[C+3&3]=Te(j(M*P)),F[C]=Math.trunc(j(j(x*P)+.5));for(let I=0;I<4;I++)a.setInt16(m+I*2,F[I]<<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 l=t*r>>>2;for(let u=0;u<l;u++){let m=u*4,h=a.getUint32(m,!0),p=h<<8>>8,b=h>>24;a.setUint32(m,b+127<<23>>>0,!0);let v=a.getFloat32(m,!0);a.setFloat32(m,j(v*p),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let n=r===8,f=n?65535:255,c=l=>n?a.getUint16(l,!0):a.getUint8(l),s=l=>n?a.getInt16(l,!0):a.getInt8(l),d=(l,u)=>n?a.setUint16(l,u&65535,!0):a.setUint8(l,u&255),o=n?2:1;for(let l=0;l<t;l++){let u=l*r,m=c(u+3*o);m|=m>>1,m|=m>>2,m|=m>>4,m|=m>>8;let h=c(u),p=s(u+o),b=s(u+2*o),v=h+p-b,M=h+b,g=h-p-b,y=c(u+3*o);y=y<<1&m|y&1;let x=m===0?0:j(f/m);d(u,Math.trunc(j(j(v*x)+.5))),d(u+o,Math.trunc(j(j(M*x)+.5))),d(u+2*o,Math.trunc(j(j(g*x)+.5))),d(u+3*o,Math.trunc(j(j(y*x)+.5)))}}var Xt=160,me=16,li=24,Zt=32,si=24,ui=[0,2,4,8],fi=[0,1,2,4,8];function Qt(e){let t=Math.floor(8192/e)&~(me-1);return t<256?t:256}function q(e){return new Error(`EXT_meshopt_compression: ${e}`)}function ci(e,t,r,i,a){if(a===0)return r.fill(0,i,i+me),t;if(a===8)return r.set(e.subarray(t,t+me),i),t+me;let n=(1<<a)-1,f=8/a,c=t+me*a/8;for(let s=0;s<me;s++){let d=e[t+Math.floor(s/f)],o=s%f,l=a===1?d>>o&1:d>>8-a-o*a&n;r[i+s]=l===n?e[c++]:l}return c}function Yt(e,t,r,i,a,n,f,c){let s=n/me,d=s+3>>2;if(r-t<d)throw q("truncated ATTRIBUTES stream");let o=t;t+=d;for(let l=0;l<s;l++){if(r-t<li)throw q("truncated ATTRIBUTES stream");let u=e[o+(l>>2)]>>(l&3)*2&3;t=ci(e,t,i,a+l*me,f[c+u])}return t}function hi(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 a=e.byteLength;if(a<1)throw q("truncated ATTRIBUTES stream");let n=e[0];if((n&240)!==Xt)throw q(`unsupported ATTRIBUTES header 0x${n.toString(16)}`);let f=n&15;if(f>1)throw q(`unsupported ATTRIBUTES codec version ${f}`);let c=r+(f===0?0:r/4),s=f===0?Zt:si,d=c<s?s:c;if(a-1<d)throw q("truncated ATTRIBUTES stream");let o=a-c,l=e.slice(o,o+r),u=o+r,m=Qt(r),h=new Uint8Array(256*4),p=1;for(let b=0;b<t;){let v=Math.min(m,t-b),M=v+me-1&~(me-1),g=f===0?0:r/4;if(a-p<g)throw q("truncated ATTRIBUTES stream");let y=p;p+=g;for(let x=0;x<r;x+=4){let P=f===0?0:e[y+x/4];for(let I=0;I<4;I++){let B=P>>I*2&3;if(B===3){if(a-p<v)throw q("truncated ATTRIBUTES stream");h.set(e.subarray(p,p+v),I*v),p+=v}else B===2?h.fill(0,I*v,I*v+v):p=f===0?Yt(e,p,a,h,I*v,M,ui,0):Yt(e,p,a,h,I*v,M,fi,B)}let C=f===0?0:e[u+x/4],F=C&3;if(F===0)for(let I=0;I<4;I++){let B=l[x+I];for(let U=0;U<v;U++)B=ai(h[I*v+U])+B&255,i[(b+U)*r+x+I]=B}else if(F===1)for(let I=0;I<4;I+=2){let B=l[x+I]|l[x+I+1]<<8,U=I*v;for(let V=0;V<v;V++){let k=h[U+V]|h[U+v+V]<<8;B=ni(k)+B&65535;let O=(b+V)*r+x+I;i[O]=B&255,i[O+1]=B>>8}}else if(F===2){let I=32-(C>>4)&31,B=(l[x]|l[x+1]<<8|l[x+2]<<16|l[x+3]<<24)>>>0;for(let U=0;U<v;U++){let V=(h[U]|h[v+U]<<8|h[2*v+U]<<16|h[3*v+U]<<24)>>>0;V=((V<<I|V>>>(32-I&31))^B)>>>0,B=V;let k=(b+U)*r+x;i[k]=V&255,i[k+1]=V>>>8&255,i[k+2]=V>>>16&255,i[k+3]=V>>>24}}else throw q(`invalid ATTRIBUTES channel ${C}`)}l.set(i.subarray((b+v-1)*r,(b+v)*r)),b+=v}if(a-p!==d)throw q("ATTRIBUTES trailing data")}var Jt=224,er=208;function tr(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,a=7;for(let n=0;n<4;n++){let f=e[t.pos++]??0;if(i=(i|(f&127)<<a)>>>0,a+=7,f<128)break}return i>>>0}function Ze(e,t,r){let i=tr(e,t),a=i>>>1^-(i&1);return r+a>>>0}function mi(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 a=e[0];if((a&240)!==Jt)throw q(`unsupported TRIANGLES header 0x${a.toString(16)}`);let n=a&15;if(n>1)throw q(`unsupported TRIANGLES codec version ${n}`);let f=new Uint32Array(16).fill(4294967295),c=new Uint32Array(16).fill(4294967295),s=new Uint32Array(16).fill(4294967295),d=0,o=0,l=(P,C)=>{f[d]=P,c[d]=C,d=d+1&15},u=(P,C=1)=>{s[o]=P,o=o+C&15},m=0,h=0,p=n>=1?13:15,b=1+i,v=e.byteLength-16,M=v,g={pos:b},y=0,x=(P,C,F)=>{r(y++,P),r(y++,C),r(y++,F)};for(let P=1;P<b;P++){let C=e[P];if(C<240){let F=C>>4,I=d-1-F&15,B=f[I],U=c[I],V=0,k=C&15;if(k<p){let O=s[o-1-k&15];V=k===0?m:O;let ee=k===0?1:0;m=m+ee>>>0,u(V,ee)}else{if(g.pos>v)throw q("truncated TRIANGLES stream");V=k!==15?h+(k*2-27)>>>0:Ze(e,g,h),h=V,u(V)}l(V,U),l(B,V),x(B,U,V)}else if(C<254){let F=e[M+(C&15)],I=F>>4,B=F&15,U=m;m=m+1>>>0;let V=s[o-I&15],k=I===0?m:V,O=I===0?1:0;m=m+O>>>0;let ee=s[o-B&15],J=B===0?m:ee,K=B===0?1:0;m=m+K>>>0,x(U,k,J),u(U),u(k,O),u(J,K),l(k,U),l(J,k),l(U,J)}else{if(g.pos>v)throw q("truncated TRIANGLES stream");let F=e[g.pos++],I=C===254?0:15,B=F>>4,U=F&15;F===0&&(m=0);let V=0;I===0&&(V=m,m=m+1>>>0);let k;B===0?(k=m,m=m+1>>>0):k=s[o-B&15];let O;U===0?(O=m,m=m+1>>>0):O=s[o-U&15],I===15&&(h=V=Ze(e,g,h)),B===15&&(h=k=Ze(e,g,h)),U===15&&(h=O=Ze(e,g,h)),x(V,k,O),u(V),u(k,B===0||B===15?1:0),u(O,U===0||U===15?1:0),l(k,V),l(O,k),l(V,O)}}if(g.pos!==v)throw q("TRIANGLES trailing data")}function di(e,t,r){if(e.byteLength<1+t+4)throw q("truncated INDICES stream");let i=e[0];if((i&240)!==er)throw q(`unsupported INDICES header 0x${i.toString(16)}`);let a=i&15;if(a>1)throw q(`unsupported INDICES codec version ${a}`);let n=e.byteLength-4,f=[0,0],c={pos:1};for(let s=0;s<t;s++){if(c.pos>=n)throw q("truncated INDICES stream");let d=tr(e,c),o=d&1;d>>>=1;let l=d>>>1^-(d&1),u=f[o]+l>>>0;f[o]=u,r(s,u)}if(c.pos!==n)throw q("INDICES trailing data")}function rr(e,t,r,i,a="NONE"){if(Kt(a),!Number.isInteger(t)||t<0||t>ii||!Number.isInteger(r)||r<=0||r>256)throw q(`invalid count (${t}) or byteStride (${r})`);let n=t*r;if(n>Gt)throw q(`decompressed size (${n}) exceeds MAX_MESHOPT_BUFFER_BYTES (${Gt})`);if(t===0)return new Uint8Array(0);let f=new Uint8Array(n);if(i==="ATTRIBUTES")return hi(e,t,r,f),qt(f,t,r,a),f;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw q(`${i} byteStride must be 2 or 4 (got ${r})`);if(a&&a!=="NONE")throw q(`filter ${a} is only valid for ATTRIBUTES`);let c=new DataView(f.buffer),s=r===2?(d,o)=>c.setUint16(d*2,o&65535,!0):(d,o)=>c.setUint32(d*4,o>>>0,!0);return i==="TRIANGLES"?mi(e,t,s):di(e,t,s),f}throw q(`unknown mode "${String(i)}"`)}function ir(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function pi(e,t,r,i){let a=t*r;if(e.byteLength<a)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${a})`);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=[Xt],s=Qt(r),d=new Uint8Array(r);t>0&&d.set(e.subarray(0,r));let o=d.slice(),l=new Uint8Array(256);for(let u=0;u<t;){let m=Math.min(s,t-u),h=m+15&-16;for(let p=0;p<r;p++){l.fill(0);let b=d[p];for(let g=0;g<m;g++){let y=e[(u+g)*r+p];l[g]=oi(y-b&255),b=y}d[p]=b;let v=h/16,M=c.length;for(let g=0;g<v+3>>2;g++)c.push(0);for(let g=0;g<v;g++){let y=l.subarray(g*16,g*16+16);if(!y.every(x=>x===0)){c[M+(g>>2)]|=3<<(g&3)*2;for(let x of y)c.push(x)}}}u+=m}for(let u=r;u<Zt;u++)c.push(0);for(let u=0;u<r;u++)c.push(o[u]);return new Uint8Array(c)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),f=c=>r===2?n.getUint16(c*2,!0):n.getUint32(c*4,!0);if(i==="INDICES"){let c=[er|1],s=0;for(let d=0;d<t;d++){let o=f(d),l=o-s|0;s=o,ir(c,Wt(l)<<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,s=[Jt|1];for(let o=0;o<c;o++)s.push(255);let d=0;for(let o=0;o<c;o++){s.push(255);for(let l=0;l<3;l++){let u=f(o*3+l);ir(s,Wt(u-d|0)),d=u}}for(let o=0;o<16;o++)s.push(0);return new Uint8Array(s)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function ht(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 a=new Uint8Array(r.bin),n=[],f=0;for(let l=0;l<i.bufferViews.length;l++){let u=i.bufferViews[l],m=u?.extensions?.KHR_meshopt_compression,h=m??u?.extensions?.EXT_meshopt_compression;if(!h||typeof h!="object")continue;let p=m?"KHR_meshopt_compression":"EXT_meshopt_compression",b=Number(h.count),v=Number(h.byteStride),M=Number(h.byteOffset??0),g=Number(h.byteLength??0),y=h.mode||"ATTRIBUTES",x=h.filter||"NONE";if(x==="COLOR"&&!m)throw q(`bufferView ${l} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(h.buffer??0)!==0)throw new Error(`${p}: bufferView ${l} references buffer ${String(h.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(M)||M<0||!Number.isInteger(g)||g<0||M+g>a.byteLength)throw new Error(`${p}: bufferView ${l} compressed range [${M}, ${M+g}] out of bounds (${a.byteLength})`);let P=b*v;if(f+=P,f>jt)throw q(`total decompressed size (${f}) exceeds MAX_MESHOPT_TOTAL_BYTES (${jt})`);let C=a.subarray(M,M+g),F=rr(C,b,v,y,x);n.push({index:l,bytes:F,ext:h})}if(n.length===0)return;let c=a.byteLength+3&-4,s=0;for(let l of n)s+=l.bytes.byteLength+3&-4;let d=new Uint8Array(c+s);d.set(a,0);let o=c;for(let l of n){d.set(l.bytes,o);let u=i.bufferViews[l.index];u.buffer=0,u.byteOffset=o,u.byteLength=l.bytes.byteLength,u._decoded=l.bytes,l.ext.mode==="ATTRIBUTES"&&u.byteStride===void 0&&(u.byteStride=Number(l.ext.byteStride)),u.extensions&&(delete u.extensions.EXT_meshopt_compression,delete u.extensions.KHR_meshopt_compression),o+=l.bytes.byteLength+3&-4}r.bin=d.buffer}var mt={decodeBufferViews(e,t){ht(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}};de().decoders.set("meshopt",mt);var ar={name:"meshopt",onParseGLB(e){de().decoders.set("meshopt",mt),ht(e)}};function dt(e,t,r,i=!0){let a=[],n=null;try{for(let[f,c]of[[35633,t],[35632,r]]){let s=e.createShader(f);if(!s){if(i)throw new Error("Shader allocation failed");return null}if(a.push(s),e.shaderSource(s,c),e.compileShader(s),e.getShaderParameter&&!e.getShaderParameter(s,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(s)}`);return null}}if(n=e.createProgram(),!n){if(i)throw new Error("Program allocation failed");return null}for(let f of a)e.attachShader(n,f);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let f=i?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,i)throw new Error(`Program link error: ${f}`);return null}return n}finally{for(let f of a)n&&e.detachShader?.(n,f),e.deleteShader?.(f)}}function nr(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var gi=`#version 300 es
40
40
  layout(location=0) in vec3 aPosition;
41
41
  layout(location=1) in vec3 aNormal;
42
42
  uniform mat4 uMVP,uVP;
@@ -57,19 +57,19 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
57
57
  clipPos.xy+=pxOffset;
58
58
  clipPos.z+=1e-4*clipPos.w;
59
59
  gl_Position=clipPos;
60
- }`,Ur=`#version 300 es
60
+ }`,bi=`#version 300 es
61
61
  precision highp float;
62
62
  uniform vec4 uOutlineColor;
63
63
  out vec4 fragColor;
64
64
  void main(){
65
65
  fragColor=uOutlineColor;
66
- }`,Ht=`#version 300 es
66
+ }`,or=`#version 300 es
67
67
  out vec2 vUV;
68
68
  void main(){
69
69
  vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
70
70
  vUV=pos;
71
71
  gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
72
- }`,kr=`#version 300 es
72
+ }`,yi=`#version 300 es
73
73
  precision highp float;
74
74
  in vec2 vUV;
75
75
  uniform sampler2D uSourceTex;
@@ -92,7 +92,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
92
92
  c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
93
93
  c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
94
94
  fragColor=vec4(c,1.0);
95
- }`,Or=`#version 300 es
95
+ }`,vi=`#version 300 es
96
96
  precision highp float;
97
97
  in vec2 vUV;
98
98
  uniform sampler2D uBloomTex;
@@ -114,6 +114,61 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
114
114
  vec3 bloom=(sum/12.0)*uStrength;
115
115
  float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
116
116
  fragColor=vec4(bloom,a);
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};
117
+ }`,Qe=3,Ue=new WeakMap;function lr(e,t=[.22,.74,.97]){let r=Tt(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let a=+("0x"+i[0]+i[0])/255,n=+("0x"+i[1]+i[1])/255,f=+("0x"+i[2]+i[2])/255;return[a,n,f]}if(i.length===6){let a=+("0x"+i.slice(0,2))/255,n=+("0x"+i.slice(2,4))/255,f=+("0x"+i.slice(4,6))/255;return[a,n,f]}return[t[0],t[1],t[2]]}function xi(e,t,r=.8,i=.5){let a=Number.isFinite(t)?Math.max(0,t):0;if(a<=0)return[0,0,0];let n=Math.max(0,Number(e[0])||0),f=Math.max(0,Number(e[1])||0),c=Math.max(0,Number(e[2])||0),s=Math.max(n,f,c);if(s<=1e-6)return[0,0,0];let d=Number.isFinite(r)?Math.max(0,r):.8,o=Math.max(d*Math.max(0,i),1e-4),l=Math.max(0,Math.min(2*o,s-d+o)),u=l*l/(4*o+1e-4),m=Math.min(1,Math.max(0,Math.max(u,s-d)/Math.max(s,1e-4)))*a;return[n*m,f*m,c*m]}function Mi(e,t,r,i){let a=Number(e[0])||0,n=Number(e[1])||0,f=Math.hypot(a,n);if(f<=1e-5||t<=0||r<=0)return[0,0];let c=Math.max(1,Number(i[0])||1),s=Math.max(1,Number(i[1])||1),d=Math.max(0,r)*2*t;return[a/f*(d/c),n/f*(d/s)]}var sr=new WeakSet;function ur(e){let t=Ue.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Ue.delete(e)}if(sr.has(e)||e.isContextLost?.())return null;let r=dt(e,gi,bi,!1),i=dt(e,or,yi,!1),a=dt(e,or,vi,!1);if(!r||!i||!a){for(let f of[r,i,a])f&&e.deleteProgram(f);return sr.add(e),null}let n=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:a,uUpBloomTex:e.getUniformLocation(a,"uBloomTex"),uUpTexelSize:e.getUniformLocation(a,"uTexelSize"),uUpRadius:e.getUniformLocation(a,"uRadius"),uUpStrength:e.getUniformLocation(a,"uStrength"),fsVao:n,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Ue.set(e,t),t}function wi(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let a=Math.max(2,r|0),n=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===Qe&&t.texWidth===a&&t.texHeight===n)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,a,n,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 f=a,c=n;for(let s=0;s<Qe;s++)f=Math.max(1,f>>1),c=Math.max(1,c>>1),t.mipWidth[s]=f,t.mipHeight[s]=c,t.bloomTex[s]||(t.bloomTex[s]=e.createTexture()),e.bindTexture(3553,t.bloomTex[s]),e.texImage2D(3553,0,6408,f,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[s]||(t.bloomFbo[s]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[s]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[s],0);return e.bindFramebuffer(36160,null),t.texWidth=a,t.texHeight=n,!0}function Si(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let a=i.trim().toLowerCase();if(a==="false"||a==="0"||a==="none")return null;let n=a===""||a==="true"?.35:Number(a);if(!Number.isFinite(n)||n<=0)return null;let f=_t({strength:n,threshold:nr(t.getAttribute("bloom-threshold"),.62),radius:nr(t.getAttribute("bloom-radius"),.75)});if(f)return f}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let a=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,n=_t(a);n&&(!r||n.strength>r.strength)&&(r=n)}return r}function Ai(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let a=t,n=3.5,f=!1;if(r&&i!=="true"){let c=r.split(/\s+/);for(let s of c)if(s.startsWith("#"))a=s;else if(s.toLowerCase()==="pulse")f=!0;else{let d=Number(s);Number.isFinite(d)&&d>0&&(n=d)}}return ot({color:a,thickness:n,pulse:f})}var Ii=new Set(["floor","pedestal","ground","table","grid","pad"]);function Ni(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Ii.has(t))}function Pi(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let o=i.trim().toLowerCase();if(o==="false"||o==="0"||o==="none")return null}let a=t?.extras?.xr?.outline??t?.userData?.xr?.outline,n=ot(a);if(n)return n;let f=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=Ai(i,f),s=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||(s?ot({color:f,thickness:3,pulse:!1}):null);if(c){let o=t.name||"";return Ni(o)?null:c}return null}var fr={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),a=Math.max(1,t.canvas?.height||150),n=[];for(let u of t.meshes){if(u.visible===!1)continue;let m=Pi(t,u);m&&n.push({mesh:u,trait:m})}let f=n.length>0?ur(e):null;if(f){let u=f,m=fe(),h=fe(),p=new Float32Array(9),b=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof e.getParameter=="function"?e.getParameter(2978):null,M=Math.max(1,v?.[2]||i),g=Math.max(1,v?.[3]||a);e.useProgram(u.outlineProg),u.uOutlineViewportSize&&e.uniform2f(u.uOutlineViewportSize,M,g),u.uOutlineVP&&e.uniformMatrix4fv(u.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(515),e.depthMask(!1);for(let{mesh:y,trait:x}of n){let[P,C,F]=lr(x.color),I=x.pulse?.8+.25*Math.sin(b*4):1;u.uOutlineColor&&e.uniform4f(u.uOutlineColor,P,C,F,1),u.uOutlineThickness&&e.uniform1f(u.uOutlineThickness,x.thickness*I),y.worldSpace===!0?m.set(y.transform):oe(m,t.modelRootMatrix,y.transform);let B=y.instanceMatrices;for(let U of y.primitives)if(!(U.pluginData?.skinning?.hasSkin||U.pluginData?.morph?.hasMorph))if(e.bindVertexArray(U.vao),B&&B.length>=16){let V=B.length>>4,k=fe();for(let O=0;O<V;O++)oe(k,m,B.subarray(O*16,O*16+16)),oe(h,r,k),$e(p,k),e.uniformMatrix4fv(u.uOutlineMVP,!1,h),e.uniformMatrix3fv(u.uOutlineNormalMatrix,!1,p),U.indices?e.drawElements(4,U.indexCount,U.indexType,0):e.drawArrays(4,0,U.indexCount)}else oe(h,r,m),$e(p,m),e.uniformMatrix4fv(u.uOutlineMVP,!1,h),e.uniformMatrix3fv(u.uOutlineNormalMatrix,!1,p),U.indices?e.drawElements(4,U.indexCount,U.indexType,0):e.drawArrays(4,0,U.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=Si(t);if(!c||c.strength<=0)return;let s=ur(e);if(!s||!wi(e,s,i,a)||!s.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,s.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,a),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(s.downProg),e.uniform1i(s.uDownSourceTex,0),e.bindVertexArray(s.fsVao);let d=s.sceneTex,o=i,l=a;for(let u=0;u<Qe;u++){let m=s.mipWidth[u],h=s.mipHeight[u];e.bindFramebuffer(36160,s.bloomFbo[u]),e.viewport(0,0,m,h),e.bindTexture(3553,d),e.uniform2f(s.uDownTexelSize,1/o,1/l),e.uniform1f(s.uDownThreshold,u===0?c.threshold:0),e.drawArrays(4,0,3),d=s.bloomTex[u],o=m,l=h}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(s.upProg),e.uniform1i(s.uUpBloomTex,0),e.uniform1f(s.uUpRadius,c.radius);for(let u=Qe-1;u>=1;u--){let m=u-1;e.bindFramebuffer(36160,s.bloomFbo[m]),e.viewport(0,0,s.mipWidth[m],s.mipHeight[m]),e.bindTexture(3553,s.bloomTex[u]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[u],1/s.mipHeight[u]),e.uniform1f(s.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,a),e.bindTexture(3553,s.bloomTex[0]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[0],1/s.mipHeight[0]),e.uniform1f(s.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=Ue.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);Ue.delete(e)}}},pt=4,cr=9,Li=32*1024*1024,Ye=fe(),hr=new Int32Array([-1,-1]);function gt(e,t,r,i){let a=Number(e);return Number.isFinite(a)?Math.max(t,Math.min(r,a)):i}var mr=new WeakMap,ge=new WeakMap,ke=new WeakMap,_e=fe(),Je=fe(),be=fe(),Ee=fe(),dr=new Float32Array(1),Ti=new Uint32Array(dr.buffer);function pr(e){if(typeof e!="string")return"auto";let t=e.trim().toLowerCase();return t==="pcf"||t==="off"?t:"auto"}function _i(e){let t=mr.get(e);if(t)return t;let r=1/0,i=1/0,a=1/0,n=-1/0,f=-1/0,c=-1/0;for(let d=0;d+2<e.length;d+=3){let o=e[d],l=e[d+1],u=e[d+2];o<r&&(r=o),o>n&&(n=o),l<i&&(i=l),l>f&&(f=l),u<a&&(a=u),u>c&&(c=u)}let s=Number.isFinite(r)?[r,i,a,n,f,c]:[-.5,-.5,-.5,.5,.5,.5];return mr.set(e,s),s}function Ve(e,t,r,i){let a=(e[0]+e[3])*.5,n=(e[1]+e[4])*.5,f=(e[2]+e[5])*.5,c=Math.max(0,(e[3]-e[0])*.5),s=Math.max(0,(e[4]-e[1])*.5),d=Math.max(0,(e[5]-e[2])*.5),o=t[0]*a+t[4]*n+t[8]*f+t[12],l=t[1]*a+t[5]*n+t[9]*f+t[13],u=t[2]*a+t[6]*n+t[10]*f+t[14],m=Math.abs(t[0])*c+Math.abs(t[4])*s+Math.abs(t[8])*d,h=Math.abs(t[1])*c+Math.abs(t[5])*s+Math.abs(t[9])*d,p=Math.abs(t[2])*c+Math.abs(t[6])*s+Math.abs(t[10])*d;o-m<r[0]&&(r[0]=o-m),l-h<r[1]&&(r[1]=l-h),u-p<r[2]&&(r[2]=u-p),o+m>i[0]&&(i[0]=o+m),l+h>i[1]&&(i[1]=l+h),u+p>i[2]&&(i[2]=u+p)}function gr(e){let t=e||{},r=t.modelRootMatrix??Ye,i=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let l of t.meshes??[]){if(!yt(l))continue;l.worldSpace===!0?be.set(l.transform):oe(be,r,l.transform);let u=l.instanceMatrices;for(let m of l.primitives??[]){if(!m.positions||m.positions.length<3)continue;let h=_i(m.positions);if(u&&u.length>=16){let p=u.length>>4,b=p>64?Math.ceil(p/64):1;for(let v=0;v<p;v+=b)oe(Ee,be,u.subarray(v*16,v*16+16)),Ve(h,Ee,i,a);if(b>1){let v=p-1;oe(Ee,be,u.subarray(v*16,v*16+16)),Ve(h,Ee,i,a)}}else Ve(h,be,i,a)}}if(!Number.isFinite(i[0])){let l=t.bounds;l&&Array.isArray(l.min)&&Array.isArray(l.max)&&Ve([l.min[0],l.min[1],l.min[2],l.max[0],l.max[1],l.max[2]],r,i,a)}Number.isFinite(i[0])||(i[0]=i[1]=i[2]=-1,a[0]=a[1]=a[2]=1);let n=(i[0]+a[0])*.5,f=(i[1]+a[1])*.5,c=(i[2]+a[2])*.5,s=Math.max(.03,(a[0]-i[0])*.5),d=Math.max(.03,(a[1]-i[1])*.5),o=Math.max(.03,(a[2]-i[2])*.5);return{center:[n,f,c],radius:Math.max(.05,Math.hypot(s,d,o)),min:[n-s,f-d,c-o],max:[n+s,f+d,c+o]}}function br(e,t,r){let i=Number(t[0])||0,a=Number(t[1])||0,n=Number(t[2])||0,f=Math.hypot(i,a,n);f>1e-6?(i/=f,a/=f,n/=f):(i=.37139067,a=.74278135,n=.59422508);let c=Math.max(.05,r.radius),[s,d,o]=r.center,l=c*2.2,u=[s+i*l,d+a*l,o+n*l],m=Math.abs(a)>.99?[0,0,1]:[0,1,0];wt(_e,u,r.center,m);let h=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0];Ve([...r.min,...r.max],_e,h,p);let b=Math.max(.02,c*.05),v=Math.max(.01,-p[2]-b),M=Math.max(v+.1,-h[2]+b);return Dr(Je,h[0]-b,Math.max(h[0]+.05,p[0])+b,h[1]-b,Math.max(h[1]+.05,p[1])+b,v,M),oe(e,Je,_e)}function bt(e,t,r,i,a,n){let f=Number(t[0])||0,c=Number(t[1])||0,s=Number(t[2])||0,d=Number(r[0])||0,o=Number(r[1])||0,l=Number(r[2])||0,u=Math.hypot(d,o,l);u<=1e-6&&(d=n.center[0]-f,o=n.center[1]-c,l=n.center[2]-s,u=Math.hypot(d,o,l)),u>1e-6?(d/=u,o/=u,l/=u):(d=0,o=-1,l=0);let m=Math.abs(o)>.99?[0,0,1]:[0,1,0];wt(_e,[f,c,s],[f+d,c+o,s+l],m);let h=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0];Ve([...n.min,...n.max],_e,h,p);let b=-p[2],v=-h[2],M=Math.max(.05,n.radius),g=Math.hypot(n.center[0]-f,n.center[1]-c,n.center[2]-s),y=Math.max(.5,v+M*.25,g+M),x=a&&a>0?Math.max(.25,Math.min(a,y)):y,P=Math.max(.02,x/1500),C=Math.min(x*.4,Math.max(P,Number.isFinite(b)?b-M*.05:P)),F=Math.max(.08,Math.min(2.35,i*2*1.04));return Rr(Je,F,1,C,Math.max(C+.1,x)),oe(e,Je,_e)}function Ei(e){let t=e||{};for(let g of t.meshes??[])if(g.name==="__xr_section_gizmo__"&&g.visible!==!1&&g.worldMatrix&&g.worldMatrix.length>=16){let y=g.worldMatrix,x=Math.hypot(y[8],y[9],y[10])||1,P=y[8]/x,C=y[9]/x,F=y[10]/x;return{enabled:!0,normal:[P,C,F],constant:P*y[12]+C*y[13]+F*y[14]}}let r=(t.container?.getAttribute?.("section-plane")??"").trim().toLowerCase();if(!r||r==="none"||r==="false")return null;let i=[1,0,0],a=0;if(r==="interactive")a=t.bounds?.center[0]??0;else{let g=/^([+-]?[xyz])\s*:\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)$/.exec(r);if(!g)return null;let y=g[1].startsWith("-")?-1:1,x=g[1].replace(/^[+-]/,""),P=Math.max(-1e3,Math.min(1e3,Number(g[2])||0));i=x==="x"?[y,0,0]:x==="y"?[0,y,0]:[0,0,y],a=P*y}let n=t.modelRootMatrix??Ye,f=n[0]*i[0]+n[4]*i[1]+n[8]*i[2],c=n[1]*i[0]+n[5]*i[1]+n[9]*i[2],s=n[2]*i[0]+n[6]*i[1]+n[10]*i[2],d=Math.hypot(f,c,s)||1,o=f/d,l=c/d,u=s/d,m=i[0]*a,h=i[1]*a,p=i[2]*a,b=n[0]*m+n[4]*h+n[8]*p+n[12],v=n[1]*m+n[5]*h+n[9]*p+n[13],M=n[2]*m+n[6]*h+n[10]*p+n[14];return{enabled:!0,normal:[o,l,u],constant:o*b+l*v+u*M}}function yt(e){if(e.visible===!1||e.isPluginMesh||e.name==="__contact_shadow__"||e.name==="__xr_reticle__"||e.name==="__xr_section_gizmo__")return!1;let t=e.extras?.xr??e.userData?.xr;return!(t?.splatUrl||t?.splat)}function et(e,t){if(!yt(e))return!1;let r=e.castShadow??e.extras?.shadow?.cast;return r===!1?!1:t?!0:r===!0}function yr(e,t){if(!e||typeof e!="object")return!1;let r=e;if(!yt(r))return!1;let i=r.receiveShadow??r.extras?.shadow?.receive;return i!==void 0?!!i:t}function vt(e){return!(e.isTransmissive||e.alphaMode==="BLEND"||(e.baseColor?.[3]??1)<.98)}function ye(e,t){return Math.imul((e^t>>>0)>>>0,16777619)>>>0}function ve(e,t){return dr[0]=t||0,ye(e,Ti[0])}function Oe(e,t,r=64){let i=t.length;if(e=ye(e,i),i<=r)for(let a=0;a<i;a++)e=ve(e,t[a]);else{let a=Math.max(1,Math.floor(i/r));for(let n=0;n<i;n+=a)e=ve(e,t[n]);e=ve(e,t[i-1])}return e}function vr(e){let t=e||{},r=t.shadowMaps??t.container?.getAttribute?.("shadow-maps")??"auto",i=pr(r),a=[-1,-1],n=[-1,-1],f=(V=!1)=>({mode:i,mapSize:0,slices:[],dirSlots:a,ptSlots:n,promoteAllCasters:V,promoteAllReceivers:V,digest:0,sectionPlane:null});if(i==="off")return f();let c=[],s=null,d=null,o=!1,l=0,u=0;for(let V of t.lights??[])V.type==="hemisphere"?o=!0:V.type==="directional"&&l<2?(s||(s=V),V.shadow?.cast&&c.length<pt&&c.push({kind:"directional",subIdx:l,light:V}),l++):(V.type==="spot"||V.type==="point")&&u<2&&(d||(d={kind:V.type,light:V}),V.shadow?.cast&&c.length<pt&&c.push({kind:V.type,subIdx:u,light:V}),u++);if(i==="pcf"&&c.length===0&&(s?c.push({kind:"directional",subIdx:0,light:s}):o?d&&c.push({kind:d.kind,subIdx:0,light:d.light}):c.push({kind:"directional",subIdx:0,light:{type:"directional",direction:[.5,1,.8]}})),c.length===0)return f();let m=t.meshes??[],h=!1;for(let V of m)if(V.castShadow!==void 0||V.receiveShadow!==void 0||V.extras?.shadow!==void 0){h=!0;break}let p=i==="pcf"||!h,b=p,v=!1;for(let V of m)if(et(V,p)){for(let k of V.primitives??[])if(vt(k)&&k.indexCount>0){v=!0;break}if(v)break}if(!v)return f(p);let M=1024;for(let V of c){let k=V.light.shadow?.mapSize;typeof k=="number"&&Number.isFinite(k)&&(M=Math.max(M,Math.round(k)))}let g=Math.max(256,Math.min(2048,M)),y=c.length;for(;g>256&&g*g*y*4>Li;)g=Math.max(256,g>>1);let x=gr(t),P=x.radius*2.2/g,C=[];for(let V=0;V<c.length;V++){let k=c[V],O=k.light,ee=O.shadow,J=fe(),K;if(k.kind==="directional"){a[k.subIdx]=V;let Z=O.direction??[.5,1,.8],Q=Math.hypot(Z[0]??.5,Z[1]??1,Z[2]??.8)||1;K=[-(Z[0]??.5)/Q,-(Z[1]??1)/Q,-(Z[2]??.8)/Q],br(J,Z,x)}else{n[k.subIdx]=V;let Z=O.position??[0,2,0];if(k.kind==="spot"){let Q=O.direction??[0,-1,0],L=Math.hypot(Q[0]??0,Q[1]??-1,Q[2]??0)||1;K=[(Q[0]??0)/L,(Q[1]??-1)/L,(Q[2]??0)/L];let w=Math.max(.02,Math.min(Math.PI/2,O.outerConeAngle??Math.PI/3));bt(J,Z,K,w,O.range,x)}else{let Q=x.center[0]-(Z[0]??0),L=x.center[1]-(Z[1]??0),w=x.center[2]-(Z[2]??0),_=Math.hypot(Q,L,w);K=_>1e-6?[Q/_,L/_,w/_]:[0,-1,0],bt(J,Z,K,Math.PI/3,O.range,x)}}let re=gt(ee?.bias,-.05,.05,-5e-4),Pe=gt(ee?.normalBias,0,.5,.015),xe=gt(ee?.radius,0,16,1.5);C.push({slot:V,viewProj:J,rayDir:K,depthBias:re,normalBiasWorld:Pe/.015*1.75*P,uvRadius:xe*1.35/g})}let F=Ei(t),I=2166136261;I=ye(I,i==="pcf"?2:1),I=ye(I,g),I=ye(I,C.length);for(let V of C)I=Oe(I,V.viewProj,16),I=ve(I,V.depthBias),I=ve(I,V.normalBiasWorld);F?.enabled?(I=ye(I,1),I=ve(I,F.normal[0]),I=ve(I,F.normal[1]),I=ve(I,F.normal[2]),I=ve(I,F.constant)):I=ye(I,0);let B=t.modelRootMatrix??Ye;I=Oe(I,B,16);let U=0;for(let V of m){if(!et(V,p)){U++;continue}I=ye(I,U++),I=Oe(I,V.transform,16),V.instanceMatrices&&(I=Oe(I,V.instanceMatrices,64));for(let k of V.primitives??[])vt(k)&&(I=ye(I,k.indexCount),k.translations&&(I=Oe(I,k.translations,48)))}return I===0&&(I=1),{mode:i,mapSize:g,slices:C,dirSlots:a,ptSlots:n,promoteAllCasters:p,promoteAllReceivers:b,digest:I,sectionPlane:F}}function Vi(e){let t=ge.get(e);return t?{renderedPasses:t.renderedPasses,cacheHits:t.cacheHits,activeLights:t.activeLights,mapSize:t.allocSize}:{renderedPasses:0,cacheHits:0,activeLights:0,mapSize:0}}var Ci=`#version 300 es
118
+ layout(location=0) in vec3 aPos;
119
+ layout(location=1) in vec3 aNormal;
120
+ layout(location=3) in vec3 aOff;
121
+ layout(location=8) in vec4 aInst0;
122
+ layout(location=9) in vec4 aInst1;
123
+ layout(location=10) in vec4 aInst2;
124
+ layout(location=11) in vec4 aInst3;
125
+ uniform mat4 uLightVP,uModel;
126
+ uniform vec4 uBiasRay;
127
+ uniform int uInstanced;
128
+ out vec3 vWorldPos;
129
+ void main(){
130
+ mat4 m=uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;
131
+ vec4 wp=m*vec4(aPos+aOff,1.0);
132
+ vec3 wn=mat3(m)*aNormal;
133
+ float nl=length(wn);
134
+ if(nl>1e-5&&uBiasRay.w>0.0){
135
+ wn/=nl;
136
+ wp.xyz+=wn*(uBiasRay.w*max(1.0-abs(dot(wn,uBiasRay.xyz)),0.15));
137
+ }
138
+ vWorldPos=wp.xyz;
139
+ gl_Position=uLightVP*wp;
140
+ }`,Ri=`#version 300 es
141
+ precision highp float;
142
+ in vec3 vWorldPos;
143
+ uniform vec4 uSecPlane;
144
+ uniform int uSecOn;
145
+ void main(){
146
+ if(uSecOn==1&&dot(vWorldPos,uSecPlane.xyz)>uSecPlane.w)discard;
147
+ }`,Di=`
148
+ uniform highp sampler2DArrayShadow uShadowMap;
149
+ uniform mat4 uShadowVP[4];
150
+ uniform vec4 uShadowParams[4];
151
+ uniform int uDirShdSlot[2],uPtShdSlot[2],uReceiveShadow;
152
+ const vec2 _VD[8]=vec2[8](
153
+ vec2(0.1768,0.0),vec2(-0.2265,0.2078),vec2(0.0355,-0.4150),vec2(0.3204,0.3888),
154
+ vec2(-0.5562,-0.1455),vec2(0.4916,-0.3806),vec2(-0.1419,0.6596),vec2(-0.5177,-0.5150));
155
+ float shdEval(int s,vec3 wp,vec3 N,vec3 L){
156
+ if(s<0||uReceiveShadow==0)return 1.0;
157
+ float nl=dot(N,L);
158
+ if(nl<=0.0)return 0.0;
159
+ mat4 vp=s==0?uShadowVP[0]:s==1?uShadowVP[1]:s==2?uShadowVP[2]:uShadowVP[3];
160
+ vec4 p=s==0?uShadowParams[0]:s==1?uShadowParams[1]:s==2?uShadowParams[2]:uShadowParams[3];
161
+ vec4 sc=vp*vec4(wp+N*(p.y*(1.0-nl)),1.0);
162
+ if(sc.w<=1e-6)return 1.0;
163
+ vec3 u=sc.xyz/sc.w*0.5+0.5;
164
+ if(u.x<=0.002||u.x>=0.998||u.y<=0.002||u.y>=0.998||u.z>1.0||u.z<0.0)return 1.0;
165
+ float rz=clamp(u.z+p.x,0.0,1.0);
166
+ if(p.z<=1e-6)return texture(uShadowMap,vec4(u.xy,float(s),rz));
167
+ float a=fract(52.9829189*fract(dot(gl_FragCoord.xy,vec2(0.06711056,0.00583715))))*6.2831853;
168
+ float ca=cos(a),sa=sin(a),sum=0.0;
169
+ mat2 rot=mat2(ca,sa,-sa,ca);
170
+ for(int k=0;k<8;k++)sum+=texture(uShadowMap,vec4(u.xy+rot*_VD[k]*p.z,float(s),rz));
171
+ return sum*0.125;
172
+ }`,Fi=["uShadowMap","uShadowVP","uShadowParams","uDirShdSlot","uPtShdSlot","uReceiveShadow"];function Ui(e){let t=ge.get(e);return t||(t={texArray:null,fbo:null,allocSize:0,allocLayers:0,lastDigest:0,renderedPasses:0,cacheHits:0,activeLights:0,vpFlat:new Float32Array(64),paramsFlat:new Float32Array(16),dirSlots:new Int32Array([-1,-1]),ptSlots:new Int32Array([-1,-1]),promoteAllReceivers:!1},ge.set(e,t)),t}function xr(e,t,r){let i=e.createTexture?.();if(!i)return null;let a=35866;if(e.bindTexture(a,i),typeof e.texStorage3D=="function")e.texStorage3D(a,1,33190,t,t,r);else if(typeof e.texImage3D=="function")e.texImage3D(a,0,33190,t,t,r,0,6402,5125,null);else return e.deleteTexture?.(i),null;return e.texParameteri(a,10241,9729),e.texParameteri(a,10240,9729),e.texParameteri(a,10242,33071),e.texParameteri(a,10243,33071),e.texParameteri(a,34892,34894),e.texParameteri(a,34893,515),i}function Mr(e){let t=ke.get(e);if(t&&(t.prog===null||e.isProgram?.(t.prog)!==!1))return t;let r=null,i=e.createShader?.(35633),a=e.createShader?.(35632);if(i&&a){e.shaderSource(i,Ci),e.compileShader(i),e.shaderSource(a,Ri),e.compileShader(a);let n=e.createProgram();n&&(e.attachShader(n,i),e.attachShader(n,a),e.linkProgram(n),e.detachShader?.(n,i),e.detachShader?.(n,a),e.getProgramParameter(n,35714)!==!1?r=n:e.deleteProgram(n)),e.deleteShader(i),e.deleteShader(a)}return t={prog:r,uLightVP:r?e.getUniformLocation(r,"uLightVP"):null,uModel:r?e.getUniformLocation(r,"uModel"):null,uBiasRay:r?e.getUniformLocation(r,"uBiasRay"):null,uInstanced:r?e.getUniformLocation(r,"uInstanced"):null,uSecPlane:r?e.getUniformLocation(r,"uSecPlane"):null,uSecOn:r?e.getUniformLocation(r,"uSecOn"):null,dummyArrayTex:xr(e,1,1)},ke.set(e,t),t}var wr={uniformsGLSL:Di,dirGLSL:"*shdEval(uDirShdSlot[i],vWorldPos,N,normalize(uDirLightDir[i]))",ptGLSL:"*shdEval(uPtShdSlot[i],vWorldPos,N,L)",uniformNames:Fi,bind(e,t,r,i){let a=t.uShadowMap;if(a===void 0)return;let n=r&&typeof r=="object"?ge.get(r):void 0,f=Mr(e),c=!!(n&&n.activeLights>0&&n.texArray),s=c?n.texArray:f.dummyArrayTex;s&&(e.activeTexture(33993),e.bindTexture(35866,s)),a&&e.uniform1i(a,cr);let d=t.uDirShdSlot,o=t.uPtShdSlot,l=t.uReceiveShadow;if(!c){d&&e.uniform1iv?.(d,hr),o&&e.uniform1iv?.(o,hr),l&&e.uniform1i?.(l,0);return}d&&e.uniform1iv?.(d,n.dirSlots),o&&e.uniform1iv?.(o,n.ptSlots);let u=t.uShadowVP;u&&e.uniformMatrix4fv?.(u,!1,n.vpFlat);let m=t.uShadowParams;m&&e.uniform4fv?.(m,n.paramsFlat),l&&e.uniform1i?.(l,yr(i,n.promoteAllReceivers)?1:0)}};function Sr(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}var Ar={name:"shadow-maps",onRegister(){de().shadowMapShader=wr},onLoadModel(e){if(e&&typeof e=="object"){let t=ge.get(e);t&&(t.lastDigest=0)}},onClearScene(e){if(e&&typeof e=="object"){let t=ge.get(e);t&&(t.lastDigest=0,t.activeLights=0)}},onContextRestored(e,t){if(ke.delete(e),t&&typeof t=="object"){let r=ge.get(t);r&&(r.texArray=null,r.fbo=null,r.allocSize=0,r.allocLayers=0,r.lastDigest=0,r.activeLights=0)}},onDestroy(e,t){if(t&&typeof t=="object"){let r=ge.get(t);r&&(r.texArray&&e.deleteTexture?.(r.texArray),r.fbo&&e.deleteFramebuffer?.(r.fbo),ge.delete(t))}else if(e){let r=ke.get(e);r&&(r.prog&&e.deleteProgram?.(r.prog),r.dummyArrayTex&&e.deleteTexture?.(r.dummyArrayTex),ke.delete(e))}},onBeforeDrawScene(e,t){if(!e||typeof e!="object")return;let r=e,i=de();if(i.shadowMapShader||(i.shadowMapShader=wr),r.uRender&&!("uShadowMap"in r.uRender)&&r.recompileRenderProgram?.(),i.gpuSceneAccelerator?.willRenderScene?.(e))return;let a=Ui(e),n=vr(r);if(a.promoteAllReceivers=n.promoteAllReceivers,a.dirSlots[0]=n.dirSlots[0],a.dirSlots[1]=n.dirSlots[1],a.ptSlots[0]=n.ptSlots[0],a.ptSlots[1]=n.ptSlots[1],n.slices.length===0||typeof t.framebufferTextureLayer!="function"){a.activeLights=0;return}let f=Mr(t);if(!f.prog){a.activeLights=0;return}let c=n.slices.length;if(!a.texArray||!a.fbo||a.allocSize!==n.mapSize||a.allocLayers<c){a.texArray&&t.deleteTexture?.(a.texArray);let m=Math.max(a.allocLayers,c);if(a.texArray=xr(t,n.mapSize,m),a.fbo||(a.fbo=t.createFramebuffer?.()??null),!a.texArray||!a.fbo){a.activeLights=0;return}a.allocSize=n.mapSize,a.allocLayers=m,a.lastDigest=0}a.activeLights=c,a.vpFlat.fill(0),a.paramsFlat.fill(0);for(let m of n.slices){a.vpFlat.set(m.viewProj,m.slot*16);let h=m.slot*4;a.paramsFlat[h]=m.depthBias,a.paramsFlat[h+1]=m.normalBiasWorld*.5,a.paramsFlat[h+2]=m.uvRadius}if(a.lastDigest===n.digest){a.cacheHits++;return}a.lastDigest=n.digest;let s=t.getParameter?.(36006)??null,d=t.getParameter?.(2978),o=d&&d.length>=4?[d[0],d[1],d[2],d[3]]:[0,0,Math.max(1,r.canvas?.width||1),Math.max(1,r.canvas?.height||1)],l=r.modelRootMatrix??Ye,u=r.meshes??[];t.bindFramebuffer(36160,a.fbo),t.drawBuffers?.([0]),t.readBuffer?.(0),t.viewport(0,0,n.mapSize,n.mapSize),t.colorMask?.(!1,!1,!1,!1),t.depthMask?.(!0),t.enable(2929),t.enable(32823),t.polygonOffset?.(1.5,4),t.useProgram(f.prog),f.uSecOn&&(n.sectionPlane?.enabled?(t.uniform1i(f.uSecOn,1),f.uSecPlane&&t.uniform4f(f.uSecPlane,n.sectionPlane.normal[0],n.sectionPlane.normal[1],n.sectionPlane.normal[2],n.sectionPlane.constant)):t.uniform1i(f.uSecOn,0));for(let m of n.slices){t.framebufferTextureLayer(36160,36096,a.texArray,0,m.slot),t.clear(256),f.uLightVP&&t.uniformMatrix4fv(f.uLightVP,!1,m.viewProj),f.uBiasRay&&t.uniform4f(f.uBiasRay,m.rayDir[0],m.rayDir[1],m.rayDir[2],m.normalBiasWorld);for(let h of u){if(!et(h,n.promoteAllCasters))continue;h.worldSpace===!0?be.set(h.transform):oe(be,l,h.transform);let p=h.instanceMatrices;for(let b of h.primitives??[])if(!(!b.vao||b.indexCount<=0||!vt(b)))if(t.bindVertexArray(b.vao),t.vertexAttrib3f?.(3,0,0,0),f.uInstanced&&t.uniform1i(f.uInstanced,0),f.uModel&&t.uniformMatrix4fv(f.uModel,!1,be),b.instanceCount!==void 0)t.drawElementsInstanced(4,b.indexCount,b.indexType,0,b.instanceCount);else if(p&&p.length>=16&&b.instanced&&f.uInstanced){let v=p.length>>4;t.uniform1i(f.uInstanced,1),b.indices?t.drawElementsInstanced(4,b.indexCount,b.indexType,0,v):t.drawArraysInstanced(4,0,b.indexCount,v),t.uniform1i(f.uInstanced,0)}else if(p&&p.length>=16){let v=p.length>>4;for(let M=0;M<v;M++)oe(Ee,be,p.subarray(M*16,M*16+16)),f.uModel&&t.uniformMatrix4fv(f.uModel,!1,Ee),Sr(t,b)}else Sr(t,b)}a.renderedPasses++}t.bindVertexArray(null),t.disable(32823),t.colorMask?.(!0,!0,!0,!0),t.bindFramebuffer(36160,s),t.viewport(o[0],o[1],o[2],o[3])}},ki=`#version 300 es
173
+ 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.);}`,Oi=`#version 300 es
174
+ 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);}`,Be=new WeakMap,Ir=new Float32Array(20);function xt(e,t){let[r,i,a,n,f,c]=t;return[e[0]*r+e[4]*i+e[8]*a+e[12],e[1]*r+e[5]*i+e[9]*a+e[13],e[2]*r+e[6]*i+e[10]*a+e[14],Math.abs(e[0])*n+Math.abs(e[4])*f+Math.abs(e[8])*c,Math.abs(e[1])*n+Math.abs(e[5])*f+Math.abs(e[9])*c,Math.abs(e[2])*n+Math.abs(e[6])*f+Math.abs(e[10])*c]}function Bi(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,a=-1e9,n=-1e9,f=-1e9;for(let c of e.primitives||[]){let s=c.positions;if(s)for(let d=0;d<s.length;d+=3)s[d]<t&&(t=s[d]),s[d+1]<r&&(r=s[d+1]),s[d+2]<i&&(i=s[d+2]),s[d]>a&&(a=s[d]),s[d+1]>n&&(n=s[d+1]),s[d+2]>f&&(f=s[d+2])}return e._lb=t<=a?[(t+a)*.5,(r+n)*.5,(i+f)*.5,(a-t)*.5,(n-r)*.5,(f-i)*.5]:null}function zi(e){let t=Be.get(e);if(t)return t;let r=(c,s)=>{let d=e.createShader(c);return e.shaderSource(d,s),e.compileShader(d),d},i=e.createProgram();e.attachShader(i,r(35633,ki)),e.attachShader(i,r(35632,Oi)),e.linkProgram(i);let a=e.createVertexArray(),n=e.createBuffer(),f=e.createBuffer();return e.bindVertexArray(a),e.bindBuffer(34962,n),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,f),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:a,vbo:n,ibo:f,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},Be.set(e,t),t}var Nr={name:"contact-shadow",onContextRestored(e){Be.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let a=zi(e),n=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,f=[],c=[];for(let h of t.meshes||[]){if(!h||h.visible===!1||h.isPluginMesh||h.name==="__xr_reticle__"||h.name?.startsWith("__xr_slot_"))continue;let p=Bi(h);if(!p)continue;h.transform&&(p=xt(h.transform,p)),t.modelRootMatrix&&(p=xt(t.modelRootMatrix,p));let[b,v,M,g,y,x]=p,P=[b,M,g,x,v-y,v+y];/floor|table|pedestal|ground|base|plane/i.test(h.name||"")||y<.14&&Math.min(g,x)>.45?c.push(P):f.push(P)}let s=[],d=t.bounds.center||[0,0,0],o=Math.max(.05,Number(t.bounds.radius)||.5),l=t.bounds.min,u=l?[d[0],d[1],d[2],o,Math.max(.01,d[1]-l[1]),o]:[d[0],d[1],d[2],o,o,o];t.modelRootMatrix&&(u=xt(t.modelRootMatrix,u));let m=t.xrSessionActive&&c.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:u[1]-u[4]+.002;for(let[h,p,b,v,M]of f){let g=-1/0;for(let[x,P,C,F,,I]of c)M>=I-.08&&Math.abs(h-x)<=C&&Math.abs(p-P)<=F&&I+.002>g&&(g=I+.002);n&&(g=Math.max(g,h>=.04&&h<=.36&&p>=-.34&&p<=-.04&&M>=.01?.036:Math.hypot(h,p)<=.66&&M>=-.06?.003:-.477)),isFinite(g)||(g=m);let y=s.find(x=>Math.hypot(h-x[0],p-x[1])<.06&&Math.abs(g-x[5])<.05);y?(y[2]=Math.max(y[2],b*.78),y[3]=Math.max(y[3],v*.78),y[4]=Math.min(y[4],M)):s.push([h,p,b,v,M,g])}if(s.length===0){let h=Math.max(.1,u[3]*1.5)/1.45;s.push([u[0],u[2],h,h,m,m])}e.useProgram(a.prog),e.uniformMatrix4fv(a.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(a.vao),e.bindBuffer(34962,a.vbo);for(let[h,p,b,v,M,g]of s){let y=Math.max(0,M-g),x=i/(1+y*2);if(x<.02)continue;let P=1+Math.min(.75,y*.85),C=Math.max(.045,b*1.45*P),F=Math.max(.045,v*1.45*P);Ir.set([h-C,g,p-F,0,0,h+C,g,p-F,1,0,h+C,g,p+F,1,1,h-C,g,p+F,0,1]),e.bufferSubData(34962,0,Ir),e.uniform1f(a.uIntensity,x),e.uniform1f(a.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,y*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Be.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Be.delete(e))}};function Pr(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 a=t[i]?.name;r.push(typeof a=="string"&&a.length>0?a:`Variant_${i}`)}return r}function $i(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 a=i,n=Number(a.material);if(!Number.isInteger(n)||n<0)continue;let f=[];if(Array.isArray(a.variants))for(let c of a.variants){let s=Number(c);Number.isInteger(s)&&s>=0&&f.push(s)}f.length>0&&r.push({material:n,variants:f})}return r}function Hi(e,t,r,i=0){let a=e;if(a&&typeof a.selectVariant=="function"&&!Array.isArray(t))return a.selectVariant(typeof t=="string"?t:null);let n=e,f=Array.isArray(t)?t:[],c=r??null;if(!c)return i;let s=Pr(n).indexOf(c);if(s<0)return i;for(let d of f)if(d.variants.includes(s))return d.material;return i}var Lr={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},Tr=new WeakMap,_r={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",a=>{a.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let a=Tr.get(t);if(a||(a={lightProbe:null},Tr.set(t,a),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(n=>{a&&n&&(a.lightProbe=n)}).catch(()=>{})),a.lightProbe&&typeof r.getLightEstimate=="function"){let n=r.getLightEstimate(a.lightProbe);if(n){let f=n.primaryLightDirection,c=n.primaryLightIntensity;if(f&&c&&Array.isArray(e.lights)){let s=e.lights.find(o=>o.type==="directional");s||(s={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(s)),s.direction=[f.x,f.y,f.z];let d=Math.max(c.x,c.y,c.z,.001);s.color=[c.x/d,c.y/d,c.z/d],s.intensity=d}n.sphericalHarmonicsCoefficients&&e.gl&&At(e.gl,n.sphericalHarmonicsCoefficients)}}}};ue(Nr),ue(Ar),ue(Lt),ue(Pt),ue(Ht),ue(_r),ue(Bt),ue(ar),ue(Lr),ue(fr),ue($t);export{kt as InteractivityVM,ei as LOD,zt as LodController,pt as MAX_SHADOW_LIGHTS,cr as SHADOW_MAP_TEXTURE_UNIT,qt as applyMeshoptFilter,Mi as computeOutlineClipOffset,gr as computeWorldSceneBounds,Nr as contactShadowPlugin,Jr as decimateGeometry,rr as decodeMeshoptBuffer,ht as decodeMeshoptGLB,et as doesMeshCastShadow,yr as doesMeshReceiveShadow,pi as encodeMeshoptBuffer,Pt as environmentMapPlugin,xi as evaluateKawaseBloom,Pr as extractMaterialVariants,$i as extractPrimitiveVariantMappings,br as fitDirectionalShadowMatrix,bt as fitSpotShadowMatrix,kr as getEnvironmentSH,ut as getInteractivityVM,ti as getLodController,Vi as getShadowMapStats,Lt as hotspotPlugin,qe as installLodExtension,Bt as interactivityPlugin,$t as lodPlugin,Ht as materialsPlugin,mt as meshoptDecoder,ar as meshoptPlugin,pr as normalizeShadowMapsMode,lr as parseHexRgb,ct as parseLod,We as parseSafeGltfPointer,fr as postprocessingPlugin,ri as registerMaterialShader,vr as resolveActiveShadowLights,ft as selectLodLevelIndex,Hi as selectMaterialVariant,Ot as sendInteractivityEvent,At as setEnvironmentSH,Ar as shadowMapsPlugin,Lr as variantsPlugin,_r as webxrPlugin};