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 Je=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,gn=Object.getOwnPropertyNames,xn=Object.prototype.hasOwnProperty,vn=(e,t)=>{for(var r in t)Je(e,r,{get:t[r],enumerable:!0})},Tn=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of gn(t))!xn.call(e,n)&&n!==r&&Je(e,n,{get:()=>t[n],enumerable:!(i=yn(t,n))||i.enumerable});return e},An=e=>Tn(Je({},"__esModule",{value:!0}),e),dr={};vn(dr,{InteractivityVM:()=>Le,LOD:()=>$t,LodController:()=>Ue,applyMeshoptFilter:()=>bt,computeOutlineClipOffset:()=>dn,contactShadowPlugin:()=>Mt,decimateGeometry:()=>Ht,decodeMeshoptBuffer:()=>yt,decodeMeshoptGLB:()=>Ke,encodeMeshoptBuffer:()=>an,environmentMapPlugin:()=>rt,evaluateKawaseBloom:()=>un,extractMaterialVariants:()=>wt,extractPrimitiveVariantMappings:()=>mn,getEnvironmentSH:()=>kt,getInteractivityVM:()=>He,getLodController:()=>Wt,hotspotPlugin:()=>at,installLodExtension:()=>_e,interactivityPlugin:()=>mt,lodPlugin:()=>pt,materialsPlugin:()=>ht,meshoptDecoder:()=>Ye,meshoptPlugin:()=>gt,parseHexRgb:()=>vt,parseLod:()=>We,parseSafeGltfPointer:()=>Re,postprocessingPlugin:()=>Tt,registerMaterialShader:()=>Xt,selectLodLevelIndex:()=>$e,selectMaterialVariant:()=>pn,sendInteractivityEvent:()=>ft,setEnvironmentSH:()=>Ce,variantsPlugin:()=>Et,webxrPlugin:()=>St}),module.exports=An(dr);var Pe="__THREE_LIVE_REGISTRY__";function me(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Pe]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Pe,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Pe]=t}}return e[Pe]}var mr=me().plugins;function Lt(e){let t=me();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function le(e){let t=me().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function It(){return me().plugins}function ve(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Te(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],T=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*T,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*T,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*T,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*T,e}function Mn(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,T=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-T)*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+T)*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 Ae(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 _t(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],T=r*c-i*m,p=r*o-n*m,b=r*d-s*m,y=i*o-n*c,L=i*d-s*c,R=n*d-s*o,D=a*g-u*f,_=a*A-l*f,F=a*v-h*f,C=u*A-l*g,$=u*v-h*g,z=l*v-h*A,k=T*z-p*$+b*C+y*F-L*_+R*D;return k?(k=1/k,e[0]=(c*z-o*$+d*C)*k,e[1]=(n*$-i*z-s*C)*k,e[2]=(g*R-A*L+v*y)*k,e[3]=(l*L-u*R-h*y)*k,e[4]=(o*F-m*z-d*_)*k,e[5]=(r*z-n*F+s*_)*k,e[6]=(A*b-f*R-v*p)*k,e[7]=(a*R-l*b+h*p)*k,e[8]=(m*$-c*F+d*D)*k,e[9]=(i*F-r*$-s*D)*k,e[10]=(f*L-g*b+v*T)*k,e[11]=(u*b-a*L-h*T)*k,e[12]=(c*_-m*C-o*D)*k,e[13]=(r*C-i*_+n*D)*k,e[14]=(g*p-f*y-A*T)*k,e[15]=(a*y-u*p+l*T)*k,e):null}function et(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let a=0;a<r;a++)i.push(ve());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=ve();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],T=h.scale||[1,1,1];Mn(f,v,A,T)}let g=i[a];if(u?Te(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 nt=new WeakMap;function Ce(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);nt.set(e,r)}function kt(e){return nt.get(e)}async function wn(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 tt=new WeakMap,Ut=new Float32Array(16);async function Dt(e,t,r){let i=r?await wn(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var rt={name:"environment-map",onContextRestored(e){tt.delete(e)},setEnvironmentImage(e,t){return Dt(e,"environmentTexture",t)},setSkyboxImage(e,t){return Dt(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,n){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=tt.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},tt.set(t,s)}let m=_t(Ut,r)||Ut;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 mt=Object.defineProperty,Zn=Object.getOwnPropertyDescriptor,Jn=Object.getOwnPropertyNames,er=Object.prototype.hasOwnProperty,tr=(e,t)=>{for(var r in t)mt(e,r,{get:t[r],enumerable:!0})},nr=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Jn(t))!er.call(e,a)&&a!==r&&mt(e,a,{get:()=>t[a],enumerable:!(i=Zn(t,a))||i.enumerable});return e},rr=e=>nr(mt({},"__esModule",{value:!0}),e),to={};tr(to,{InteractivityVM:()=>Oe,LOD:()=>gn,LodController:()=>Ve,MAX_SHADOW_LIGHTS:()=>ct,SHADOW_MAP_TEXTURE_UNIT:()=>Vt,applyMeshoptFilter:()=>Pt,computeOutlineClipOffset:()=>Fn,computeWorldSceneBounds:()=>Gt,contactShadowPlugin:()=>Kt,decimateGeometry:()=>yn,decodeMeshoptBuffer:()=>Ut,decodeMeshoptGLB:()=>it,doesMeshCastShadow:()=>je,doesMeshReceiveShadow:()=>Ht,encodeMeshoptBuffer:()=>Dn,environmentMapPlugin:()=>gt,evaluateKawaseBloom:()=>Cn,extractMaterialVariants:()=>Yt,extractPrimitiveVariantMappings:()=>Kn,fitDirectionalShadowMatrix:()=>Bt,fitSpotShadowMatrix:()=>dt,getEnvironmentSH:()=>sn,getInteractivityVM:()=>et,getLodController:()=>xn,getShadowMapStats:()=>Hn,hotspotPlugin:()=>At,installLodExtension:()=>Fe,interactivityPlugin:()=>Rt,lodPlugin:()=>It,materialsPlugin:()=>_t,meshoptDecoder:()=>at,meshoptPlugin:()=>Dt,normalizeShadowMapsMode:()=>zt,parseHexRgb:()=>Nt,parseLod:()=>nt,parseSafeGltfPointer:()=>Ne,postprocessingPlugin:()=>Ot,registerMaterialShader:()=>vn,resolveActiveShadowLights:()=>jt,selectLodLevelIndex:()=>tt,selectMaterialVariant:()=>Yn,sendInteractivityEvent:()=>Lt,setEnvironmentSH:()=>Ke,shadowMapsPlugin:()=>$t,variantsPlugin:()=>qt,webxrPlugin:()=>Qt}),module.exports=rr(to);var Xe="__THREE_LIVE_REGISTRY__";function ce(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Xe]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Xe,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Xe]=t}}return e[Xe]}var ro=ce().plugins;function Jt(e){let t=ce();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function ue(e){let t=ce().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function en(){return ce().plugins}function ie(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function tn(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 nn(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 pt(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 re(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 or(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 Le(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 rn(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 ht(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(ie());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=ie();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];or(h,v,b,M)}let p=i[o];if(l?re(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 yt=new WeakMap;function Ke(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);yt.set(e,r)}function sn(e){return yt.get(e)}async function ir(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 bt=new WeakMap,on=new Float32Array(16);async function an(e,t,r){let i=r?await ir(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var gt={name:"environment-map",onContextRestored(e){bt.delete(e)},setEnvironmentImage(e,t){return an(e,"environmentTexture",t)},setSkyboxImage(e,t){return an(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,a){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let n=bt.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},bt.set(t,n)}let f=rn(on,r)||on;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=nt.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)}},ot=new WeakMap;function it(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 at={name:"hotspots",updateHotspotsForElement:it,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{it(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),ot.set(e,t)},onCameraChange(e,t){t&&it(t,e)},onElementDisconnected(e){let t=ot.get(e);t&&(t.disconnect(),ot.delete(e))}};function ye(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function En(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function st(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Sn(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function Ot(e){let t=st(e);if(!t)return null;let r=t.target;return{target:En(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:ye(t.radius,.01,50,.5),speed:ye(t.speed,-20,20,.5),height:ye(t.height,-10,10,0),phase:ye(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var Rn=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],Ln=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],xr=new Set(Rn),vr=new Set(Ln);function lt(e,t){let r=Sn(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 ct(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:st(e);if(!t||t.enabled===!1)return null;let r=ye(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:ye(t.threshold,0,4,.8),radius:ye(t.radius,0,2,.5)}:null}function Ve(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:st(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:lt(t.color,"#38bdf8"),thickness:ye(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function Nt(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 Pt=1024,ut=256,Fe=2048,In=128,_n=64,Un=16,Dn=1e4,kn=8,pe=new Set(["__proto__","constructor","prototype"]),Ct={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))},Vt={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},ze={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Be=(e,t)=>e!==null&&typeof e=="object"&&!pe.has(t)&&Object.prototype.hasOwnProperty.call(e,t),re=e=>Array.isArray(e)?[...e]:e,Gt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Be(e,"value")?e.value:e,Y=(e,t)=>Be(e.configuration,t)?Gt(e.configuration[t]):void 0,U=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},xe=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 Re(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 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},Ft=e=>{let t=U(e[0]),r=U(e[1]),i=U(e[2]),n=U(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]},zt=(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 Nt(n,Ft(e),Ft(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},dt=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(U(i),U(t[n]))):Array.isArray(e)?e.map(i=>r(U(i),U(t))):Array.isArray(t)?t.map(i=>r(U(e),U(i))):r(U(e),U(t)),On=(e,t)=>Array.isArray(e)?e.map(r=>t(U(r))):t(U(e)),Bt=(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,Le=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>Pt)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Pt})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>ut)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${ut})`);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,T=0,p=0,b=0,y=!1,L=!1,R=!1;n.forEach((N,x)=>{if(!N||typeof N!="object")return;let E=re(Gt(N.value));c.set(x,E);let P=N.id??N.name;typeof P=="string"&&P&&!pe.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 D=N=>N.op||typeof N.declaration=="number"&&s[N.declaration]?.op||"",_=(N,x,E)=>{if(pe.has(x))return;let P=o.get(N);P||o.set(N,P=Object.create(null)),P[x]=E},F=(N,x)=>{if(typeof N!="number"&&typeof N!="string"||typeof N=="string"&&pe.has(N)||!c.has(N)&&c.size>=ut*2)return;let E=re(x);if(c.set(N,E),typeof N=="number"){let P=n[N]?.id??n[N]?.name;typeof P=="string"&&!pe.has(P)&&c.set(P,E)}},C=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)},k=N=>{z(N.key),h.length>=In&&h.shift(),h.push(N)},te=N=>{let x=Re(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 ze){let S=ze[P],M=E[P]||S;return S.map((w,I)=>U(M[I],w))}if(P==="weights"){let S=Array.isArray(E.weights)?E.weights:[0],M=x.length===4?Me(x[3],64):-2;return M===-2?S.map(w=>U(w)):M>=0?U(S[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 S=P.baseColorFactor||[1,1,1,1];return[U(S[0],1),U(S[1],1),U(S[2],1),U(S[3],1)]}if(x[3]==="metallicFactor"||x[3]==="roughnessFactor")return U(P[x[3]],1)}if(x[2]==="emissiveFactor"){let S=E.emissiveFactor||[0,0,0];return[U(S[0]),U(S[1]),U(S[2])]}if(x[2]==="alphaCutoff")return U(E.alphaCutoff,.5)}}},Q=(N,x)=>{let E=Re(N)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(t?.nodes)){let P=Me(E[1],t.nodes.length),S=t.nodes[P];if(!S)return!1;let M=E[2];if(M in ze&&Array.isArray(x)){let w=ze[M];if(x.length<w.length)return!1;let I=w.map((H,G)=>U(x[G],H));if(M==="rotation"){let H=Math.hypot(...I);I=H>1e-8?I.map(G=>G/H):[0,0,0,1]}S[M]=I,delete S.matrix;let B=e?.initialNodeTransforms?.[P];return B&&(B[M[0]]=[...I]),y=!0,!0}if(M==="weights"){Array.isArray(S.weights)||(S.weights=[]);let w=(I,B)=>{for(let H of e?.meshes||[])if(H.nodeIndex===P)for(let G of H.primitives||[])G.pluginData?.morph?.weights&&(G.pluginData.morph.weights[I]=B)};if(E.length===4){let I=Me(E[3],64);if(I<0)return!1;w(I,S.weights[I]=U(x))}else if(Array.isArray(x))S.weights=x.slice(0,64).map(I=>U(I)),S.weights.forEach((I,B)=>w(B,I));else return!1;return R=!0,!0}if(M==="visible"||M==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let w=ce(x);return S.visible=w,(!S.extensions||typeof S.extensions!="object")&&(S.extensions={}),S.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),S=t.materials[P];if(!S)return!1;let M=S.pbrMetallicRoughness||(S.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=[xe(U(x[0],1)),xe(U(x[1],1)),xe(U(x[2],1)),x[3]!==void 0?xe(U(x[3],1)):M.baseColorFactor?.[3]??1];return M.baseColorFactor=I,w(B=>B.baseColor=[...I]),R=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let I=E[3]==="metallicFactor",B=xe(U(x,I?0:.5));return M[E[3]]=B,w(H=>H[I?"metallic":"roughness"]=B),R=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(x)&&x.length>=3)return S.emissiveFactor=[0,1,2].map(I=>Math.max(0,U(x[I]))),R=!0;if(E[2]==="alphaCutoff")return S.alphaCutoff=xe(U(x,.5)),R=!0}return!1},K=(N,x,E=new Set)=>{let P=Y(x,"pointer");if(typeof P!="string"||!P.startsWith("/"))return null;let S=P.replace(/\{([a-zA-Z0-9_]+)\}/g,(M,w)=>{let I=Math.trunc(Number(ie(N,w,void 0,E)??Y(x,w)));return Number.isSafeInteger(I)&&I>=0?String(I):"-1"});return Re(S)?S:null},ie=(N,x,E,P)=>{let S=i[N]?.values;if(!Be(S,x))return E;let M=S[x];if(M==null)return E;if(typeof M!="object"||Array.isArray(M))return re(M);let w=M;return typeof w.node=="number"?Ze(w.node,w.socket||"value",P):Be(w,"value")?re(w.value):E},Ze=(N,x,E)=>{if(N<0||N>=i.length||E.has(N)||E.size>128||++p>Dn)return;let P=i[N],S=D(P);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(S))return re(o.get(N)?.[x]);E.add(N);try{let M=(w,I=0)=>ie(N,w,I,E);if(S==="variable/get"){let w=Y(P,"variable")??Y(P,"id");return typeof w=="number"||typeof w=="string"?re(c.get(w)):void 0}if(S==="pointer/get"){let w=K(N,P,E);return w?te(w):void 0}if(S.startsWith("math/")){let w=S.slice(5);if(w in Ct)return On(M("a"),Ct[w]);if(w in Vt){let I=/^(mul|div|rem|mod|pow)$/.test(w)?1:0;return dt(M("a",w==="mul"?1:0),M("b",I),Vt[w])}if(w==="pi")return Math.PI;if(w==="e")return Math.E;if(w==="random")return Math.random();if(w==="clamp")return dt(dt(M("a"),M("b",M("min",0)),Math.max),M("c",M("max",1)),Math.min);if(w==="mix"||w==="quatSlerp")return zt(M("a",0),M("b",1),U(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,G,V)=>H+(G||0)*(B[V]||0),0):U(I)*U(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(U(I))}if(w==="distance"){let I=M("a"),B=M("b");return Array.isArray(I)&&Array.isArray(B)?Math.hypot(...I.map((H,G)=>(H||0)-(B[G]||0))):Math.abs(U(I)-U(B))}if(w==="normalize"){let I=M("a");if(!Array.isArray(I))return U(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=>U(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 Bt(M("a"),M("b"));if(w==="ne")return!Bt(M("a"),M("b"));if(w==="lt")return U(M("a"))<U(M("b"));if(w==="le")return U(M("a"))<=U(M("b"));if(w==="gt")return U(M("a"))>U(M("b"));if(w==="ge")return U(M("a"))>=U(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"?ce(M("a",!1))&&ce(M("b",!1)):w==="or"?ce(M("a",!1))||ce(M("b",!1)):w==="xor"?ce(M("a",!1))!==ce(M("b",!1)):w==="not"?!ce(M("a",!1)):w==="select"?re(ce(M("condition",!1))?M("a"):M("b")):void 0}return S==="type/boolToInt"||S==="type/boolToFloat"?ce(M("a",!1))?1:0:S==="type/intToBool"||S==="type/floatToBool"?U(M("a",0))!==0:S==="type/intToFloat"?U(M("a",0)):S==="type/floatToInt"?Math.trunc(U(M("a",0))):void 0}finally{E.delete(N)}},Se=()=>{if(y){y=!1,R=!0;let N=et(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]),Ae(x.normalMatrix,x.transform))}}if(L){L=!1,R=!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,S=0;P!==void 0&&P>=0&&S<128;P=g.get(P),S++){let M=N[P];if(M?.visible===!1||M?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}x.visible=E}}R&&(R=!1,e?.render?.())},ne=(N,x={steps:0})=>{if(!N||typeof N.node!="number")return;x.steps===0&&(p=0);let E=[N],P=S=>{E.length+x.steps<Fe&&E.push(S)};for(;E.length>0&&x.steps<Fe;){x.steps++;let S=E.shift();if(!S||S.node<0||S.node>=i.length)continue;let M=S.node,w=i[M];if(!w)continue;let I=S.socket||"in",B=D(w),H=(V,O=void 0)=>ie(M,V,O,new Set),G=(V="out")=>{let O=w.flows?.[V];O&&P(O)};switch(B){case"flow/branch":G(ce(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let V of Object.keys(w.flows||{}).sort((O,q)=>Number(O)-Number(q)||O.localeCompare(q)))G(V);break;case"flow/switch":{let V=w.flows?.[String(H("selection",H("value",0)))]??w.flows?.default;V&&P(V);break}case"flow/for":{let V=Math.trunc(U(H("startIndex",0))),O=Math.trunc(U(H("endIndex",0))),q=Math.max(1,Math.trunc(U(H("step",1),1))),Z=w.flows?.body;if(Z&&O>V&&b<kn){let j=Math.min(Math.ceil((O-V)/q),Fe);b++;try{for(let ee=0;ee<j&&x.steps<Fe;ee++)_(M,"index",V+ee*q),ne(Z,x)}finally{b--}}let ue=w.flows?.completed??w.flows?.out;ue&&P(ue);break}case"flow/doN":{let V=I==="reset"?0:(d.get(M)||0)+1;if(d.set(M,V),_(M,"currentCount",V),_(M,"count",V),I!=="reset"){let O=Math.trunc(U(H("n",Y(w,"stopIterations")??Y(w,"n")??1),1));V<=O&&G()}break}case"flow/multiGate":{if(I==="reset"){l.set(M,0);break}let V=Object.keys(w.flows||{}).sort();if(!V.length)break;let O=Y(w,"isRandom")?Math.floor(Math.random()*V.length):l.get(M)||0;O<V.length&&(G(V[O]),l.set(M,Y(w,"isLoop")!==!1?(O+1)%V.length:O+1));break}case"flow/waitAll":{if(I==="reset"){a.delete(M);break}let V=a.get(M);V||a.set(M,V=new Set),V.add(I),V.size>=Math.max(1,Math.trunc(Number(Y(w,"inputFlows")??2)||2))&&(V.clear(),G("out"),G("completed"));break}case"flow/throttle":{if(I==="reset"){u.delete(M);break}let V=Math.max(0,U(H("duration",0))),O=u.get(M);O===void 0||v-O>=V?(u.set(M,v),_(M,"lastRemainingTime",0),G()):_(M,"lastRemainingTime",Math.max(0,V-(v-O)));break}case"flow/delay":case"flow/setDelay":{if(I==="cancel"){for(let Z=f.length-1;Z>=0;Z--)f[Z].nodeIdx===M&&f.splice(Z,1);_(M,"lastDelayIndex",-1);break}let V=Math.max(0,U(H("duration",Y(w,"duration")??0))),O=w.flows?.done??w.flows?.out;if(V<=0){_(M,"lastDelayIndex",-1),O&&P(O);break}f.length>=_n&&f.shift();let q=A++;_(M,"lastDelayIndex",q),f.push({id:q,nodeIdx:M,rem:V,done:O}),B==="flow/setDelay"&&w.flows?.out&&w.flows?.done&&G("out");break}case"flow/cancelDelay":{let V=Math.trunc(U(H("delayIndex",-1),-1));if(V<0)f.length=0;else for(let O=f.length-1;O>=0;O--)f[O].id===V&&f.splice(O,1);G();break}case"variable/set":F(Y(w,"variable")??Y(w,"id"),H("value")),G();break;case"variable/interpolate":{let V=Y(w,"variable")??Y(w,"id"),O=H("value",H("target")),q=Math.max(0,U(H("duration",Y(w,"duration")??.3),.3));V!==void 0&&O!==void 0&&k({key:`var:${String(V)}`,varKey:V,from:re(H("from")??c.get(V)??0),to:re(O),dur:q,elapsed:0,quat:!1,linear:Y(w,"easing")==="linear",done:w.flows?.done}),G();break}case"pointer/set":{let V=K(M,w),O=H("value");V&&O!==void 0&&(z(`ptr:${V}`),Q(V,O)),G();break}case"pointer/interpolate":{let V=K(M,w),O=H("value",H("target")),q=Math.max(0,U(H("duration",Y(w,"duration")??.3),.3));if(V&&O!==void 0){let Z=H("from")??te(V);Z!==void 0&&(q<=0?(Q(V,O),G("done")):k({key:`ptr:${V}`,ptr:V,from:re(Z),to:re(O),dur:q,elapsed:0,quat:V.endsWith("/rotation"),linear:Y(w,"easing")==="linear",done:w.flows?.done}))}G();break}case"animation/start":{let V=H("animation")??Y(w,"animation")??Y(w,"clipName"),O=typeof V=="number"?e?.animations?.[V]?.name??t?.animations?.[V]?.name:typeof V=="string"?V:void 0;e?.playAnimation?.(O),R=!0,G();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),B==="animation/resetAt"&&e?.evaluateAnimation?.(U(H("time",0))),R=!0,G();break;case"event/send":case"customEvent/send":{let V=C(Y(w,"event")??Y(w,"id")),O={};for(let q of Object.keys(w.values||{}))pe.has(q)||(O[q]=H(q));V&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:V,values:O}})),se(V,O,x)),G();break}default:G();break}}};this.readScenePointer=te,this.writeScenePointer=Q,this.fireOnStart=()=>{i.forEach(N=>{D(N)==="event/onStart"&&ne(N.flows?.out)}),Se()},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,S)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(D(P)))return;let M=Y(P,"nodeIndex")??Y(P,"node")??ie(S,"nodeIndex",void 0,new Set),w=Y(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(_(S,"nodeIndex",E),_(S,"meshIndex",x),Array.isArray(N.hitPoint)){let I=[U(N.hitPoint[0]),U(N.hitPoint[1]),U(N.hitPoint[2])];_(S,"hitPoint",I),_(S,"point",I),_(S,"intersectionPoint",I)}if(Array.isArray(N.normal)){let I=[U(N.normal[0]),U(N.normal[1],1),U(N.normal[2])];_(S,"normal",I),_(S,"hitNormal",I)}typeof N.distance=="number"&&_(S,"distance",N.distance),ne(P.flows?.out)}}),Se()},this.receiveCustomEvent=(N,x={})=>se(N,x,{steps:0});function se(N,x,E){if(!(T>=Un)){T++;try{let P=C(N);i.forEach((S,M)=>{if(!/^(customE|e)vent\/receive$/.test(D(S)))return;let w=Y(S,"event")??Y(S,"id");if(!(C(w)!==P&&String(w)!==String(N))){for(let[I,B]of Object.entries(x))pe.has(I)||_(M,I,re(B));ne(S.flows?.out,E)}}),Se()}finally{T--}}}this.tick=N=>{if(!Number.isFinite(N)||N<0)return;let x=Math.min(N,.25);v+=x,i.forEach((P,S)=>{D(P)==="event/onTick"&&(_(S,"timeDelta",x),_(S,"dt",x),_(S,"timeElapsed",v),ne(P.flows?.out))});let E=[];for(let P=h.length-1;P>=0;P--){let S=h[P];S.elapsed+=x;let M=S.dur>1e-6?xe(S.elapsed/S.dur):1,w=S.linear?M:M*M*(3-2*M),I=zt(S.from,S.to,w,S.quat);S.ptr?Q(S.ptr,I):S.varKey!==void 0&&F(S.varKey,I),M>=1&&(h.splice(P,1),S.done&&E.push(S.done))}for(let P=f.length-1;P>=0;P--){let S=f[P];S.rem-=x,S.rem<=0&&(f.splice(P,1),S.done&&E.push(S.done))}for(let P of E)ne(P);Se()},this.dispose=()=>{h.length=0,f.length=0,c.clear(),o.clear(),d.clear(),a.clear(),u.clear(),l.clear()}}},de=new WeakMap,Ge=new WeakMap;function Nn(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||It().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=(Ge.get(e)||0)+n,m=!1;for(let c=0;c<i.length;c++){let o=i[c],d=Ot(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(T=>T?.name===d.target);Array.isArray(v?.translation)&&(a=U(v.translation[0]),u=U(v.translation[1]),l=U(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){Ge.set(e,s);let c=et(r);e.worldMatrices=c;for(let o of e.meshes||[])o.nodeIndex>=0&&o.nodeIndex<c.length&&(o.transform.set(c[o.nodeIndex]),Ae(o.normalMatrix,o.transform))}}function He(e){if(!(!e||typeof e!="object"))return de.get(e)||de.get(e.viewer)||de.get(e._view)}function ft(e,t,r){let i=He(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var mt={name:"khr-interactivity",sendInteractivityEvent:ft,getInteractivityVM:He,onLoadModel(e,t){if(!e||typeof e!="object")return;de.get(e)?.dispose(),de.delete(e),Ge.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 Le(e,t,i);de.set(e,n),n.fireOnStart()},onMeshSelect(e,t){de.get(e)?.fireOnSelect(t)},onUpdate(e,t){de.get(e)?.tick(t),Nn(e,t)},onDestroy(e,t){de.get(t)?.dispose(),de.delete(t),Ge.delete(t)}};function _e(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 T=0;for(let b=g.length-1;b>=1;b--)if(A>=g[b]){T=b;break}if(l<0||l>=g.length||l===T)return T;if(T>l){let b=l;for(let y=l+1;y<=T&&A>=g[y]*(1+v);y++)b=y;return b}let p=l;for(let b=l;b>T&&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 T=u.levels.slice(0,8);for(let b=0;b<T.length;b++){let y=T[b];if(!y||typeof y!="object"||Array.isArray(y))continue;let L=y,R=r(L.distance,0,1e4,b===0?0:b*4),D=typeof L.hysteresis=="number"?r(L.hysteresis,0,.5,l):void 0,_=typeof L.ratio=="number"?r(L.ratio,.05,1,.5):void 0,F=typeof L.childIndex=="number"&&Number.isFinite(L.childIndex)?Math.max(0,Math.round(L.childIndex)):void 0,C=typeof L.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(L.node.trim())?L.node.trim().slice(0,64):void 0;h.push({distance:R,...D!==void 0?{hysteresis:D}:{},..._!==void 0?{ratio:_}:{},...F!==void 0?{childIndex:F}:{},...C?{node:C}:{}})}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 T=[];for(let p of u.ratios.slice(0,7))typeof p=="number"&&T.push(r(p,.05,1,.5));T.length>0&&(f=T)}if(h.length===0){let T=Array.isArray(u.distances)?u.distances:[],p=[];for(let y of T.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 R=y>0&&f?f[y-1]:void 0;h.push({distance:L,childIndex:y,...R!==void 0?{ratio:R}:{}})}}else if(!f){let T=[];for(let p=1;p<h.length;p++)typeof h[p].ratio=="number"&&T.push(h[p].ratio);T.length>0&&(f=T)}let g=h.map(T=>T.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,T=a.index?.array,p=Math.floor((T?T.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,R=1/0,D=-1/0,_=-1/0,F=-1/0;for(let x=0;x<g;x++){let E=f[x*3],P=f[x*3+1],S=f[x*3+2];E<y&&(y=E),P<L&&(L=P),S<R&&(R=S),E>D&&(D=E),P>_&&(_=P),S>F&&(F=S)}let C=Math.max(1e-5,D-y),$=Math.max(1e-5,_-L),z=Math.max(1e-5,F-R),k=Math.max(C,$,z),te=x=>{let E=Math.max(1,Math.round(C/k*x)),P=Math.max(1,Math.round($/k*x)),S=Math.max(1,Math.round(z/k*x)),M=new Map,w=new Int32Array(g),I=[],B=[],H=[],G=[];for(let j=0;j<g;j++){let ee=f[j*3],he=f[j*3+1],ge=f[j*3+2],oe=Math.min(E-1,Math.max(0,Math.floor((ee-y)/C*E))),ae=Math.min(P-1,Math.max(0,Math.floor((he-L)/$*P))),be=Math.min(S-1,Math.max(0,Math.floor((ge-R)/z*S))),Ee=oe+ae*E+be*E*P,J=M.get(Ee);J===void 0?(J=G.length,M.set(Ee,J),I.push(ee,he,ge),A&&B.push(A[j*3],A[j*3+1],A[j*3+2]),v&&H.push(v[j*2],v[j*2+1]),G.push(1)):(I[J*3]+=ee,I[J*3+1]+=he,I[J*3+2]+=ge,A&&(B[J*3]+=A[j*3],B[J*3+1]+=A[j*3+1],B[J*3+2]+=A[j*3+2]),G[J]++),w[j]=J}let V=[],O=new Set;for(let j=0;j<p;j++){let ee=T?T[j*3]:j*3,he=T?T[j*3+1]:j*3+1,ge=T?T[j*3+2]:j*3+2,oe=w[ee],ae=w[he],be=w[ge];if(oe===ae||ae===be||be===oe)continue;let Ee=Math.min(oe,ae,be),J=Math.max(oe,ae,be),ar=oe+ae+be-Ee-J,Rt=`${Ee}_${ar}_${J}`;O.has(Rt)||(O.add(Rt),V.push(oe,ae,be))}let q=G.length,Z=new Float32Array(q*3),ue=A?new Float32Array(q*3):null;for(let j=0;j<q;j++){let ee=1/G[j];if(Z[j*3]=I[j*3]*ee,Z[j*3+1]=I[j*3+1]*ee,Z[j*3+2]=I[j*3+2]*ee,ue){let he=B[j*3],ge=B[j*3+1],oe=B[j*3+2],ae=Math.hypot(he,ge,oe)||1;ue[j*3]=he/ae,ue[j*3+1]=ge/ae,ue[j*3+2]=oe/ae}}return{pos:Z,norm:ue,uv:v?new Float32Array(H):null,tris:V,triCount:V.length/3,vertCount:q}},Q=Math.max(2,Math.round(Math.sqrt(b/4))),K=te(Q);if(K.triCount>b*1.25&&Q>2){let x=Math.max(2,Math.round(Q*Math.sqrt(b/K.triCount)));if(x!==Q){let E=te(x);E.triCount>=Math.min(4,b)&&(K=E)}}else if(K.triCount<Math.min(4,b)){let x=te(Math.max(Q*2,8));x.triCount>K.triCount&&(K=x)}let ie=K.tris;if(h<1&&K.triCount>b){let x=[],E=K.triCount/b;for(let P=0;P<b;P++){let S=Math.min(K.triCount-1,Math.floor(P*E));x.push(K.tris[S*3],K.tris[S*3+1],K.tris[S*3+2])}ie=x}if(ie.length<3){ie=[];for(let x=0;x<b*3;x++)ie.push(T?T[x]:x);K={pos:f.slice(),norm:A?A.slice():null,uv:v?v.slice():null,tris:ie,triCount:b,vertCount:g}}let Ze=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),Se=Ze?.BufferGeometry??a.constructor,ne=Ze?.BufferAttribute??l.constructor,se=new Se;se.setAttribute("position",new ne(K.pos,3)),K.norm&&se.setAttribute("normal",new ne(K.norm,3)),K.uv&&se.setAttribute("uv",new ne(K.uv,2));let N=K.vertCount>65535?new Uint32Array(ie):new Uint16Array(ie);return typeof se.setIndex=="function"?se.setIndex(new ne(N,1)):se.index=new ne(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),T=this.children.filter(p=>!v.includes(p));this.children=[...v,...T];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",T=new g(h,a.material);T.name=`${v}_LOD0`,T.visible=!0,T.castShadow=!!a.castShadow,T.receiveShadow=!!a.receiveShadow,a.add(T);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 De=_e(),Ht=De.decimateGeometry,$e=De.selectLodLevelIndex,We=De.parseLod,_r=De.materializeLodGeometry,$t=De.LOD,Ie=new WeakMap;function Wt(e){return e&&typeof e=="object"?Ie.get(e):void 0}var Ue=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=We(s);if(!c&&m.length>0&&(c=We({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=$e(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=$e(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})}}},pt={name:"lod",onRegister(){Lt(_e);let e=me(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);_e(t,e)},onLoadModel(e,t){!e||typeof e!="object"||Ie.set(e,new Ue(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)}},ke=new Map,Xe=new WeakMap;function Xt(e,t){ke.set(e,t)}var ht={name:"materials",onContextRestored(e){Xe.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=Xe.get(e);r||(r=e.createTexture(),Xe.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&&ke.has(t.name)){let f=ke.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,T=3)=>{let p=Number(f);return(Number.isFinite(p)?Math.min(v,Math.max(A,p)):g).toFixed(T)},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),T=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=yt.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)}},xt=new WeakMap;function vt(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 At={name:"hotspots",updateHotspotsForElement:vt,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{vt(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),xt.set(e,t)},onCameraChange(e,t){t&&vt(t,e)},onElementDisconnected(e){let t=xt.get(e);t&&(t.disconnect(),xt.delete(e))}};function Me(e,t,r,i){let a=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,a))}function ar(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Tt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function sr(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function ln(e){let t=Tt(e);if(!t)return null;let r=t.target;return{target:ar(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:Me(t.radius,.01,50,.5),speed:Me(t.speed,-20,20,.5),height:Me(t.height,-10,10,0),phase:Me(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var lr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],cr=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],co=new Set(lr),uo=new Set(cr);function St(e,t){let r=sr(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 wt(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:Tt(e);if(!t||t.enabled===!1)return null;let r=Me(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:Me(t.threshold,0,4,.8),radius:Me(t.radius,0,2,.5)}:null}function Ye(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:Tt(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:St(t.color,"#38bdf8"),thickness:Me(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function cn(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 un=1024,Mt=256,qe=2048,ur=128,dr=64,fr=16,mr=1e4,pr=8,ge=new Set(["__proto__","constructor","prototype"]),dn={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))},fn={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},Qe={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Ze=(e,t)=>e!==null&&typeof e=="object"&&!ge.has(t)&&Object.prototype.hasOwnProperty.call(e,t),de=e=>Array.isArray(e)?[...e]:e,bn=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Ze(e,"value")?e.value:e,q=(e,t)=>Ze(e.configuration,t)?bn(e.configuration[t]):void 0,D=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},Ee=e=>Math.max(0,Math.min(1,e)),pe=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function Ne(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||ge.has(i)||ge.has(r))return null;t.push(i)}return{segments:t}}var Re=(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},mn=e=>{let t=D(e[0]),r=D(e[1]),i=D(e[2]),a=D(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]},pn=(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 cn(a,mn(e),mn(t),r),a}return e.slice(0,t.length).map((a,n)=>a+(t[n]-a)*r)}return r>=.5?t:e},Et=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,a)=>r(D(i),D(t[a]))):Array.isArray(e)?e.map(i=>r(D(i),D(t))):Array.isArray(t)?t.map(i=>r(D(e),D(i))):r(D(e),D(t)),hr=(e,t)=>Array.isArray(e)?e.map(r=>t(D(r))):t(D(e)),hn=(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,Oe=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>un)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${un})`);let a=Array.isArray(r.variables)?r.variables:[];if(a.length>Mt)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Mt})`);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 _=de(bn(L.value));c.set(w,_);let E=L.id??L.name;typeof E=="string"&&E&&!ge.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(ge.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"&&ge.has(L)||!c.has(L)&&c.size>=Mt*2)return;let _=de(w);if(c.set(L,_),typeof L=="number"){let E=a[L]?.id??a[L]?.name;typeof E=="string"&&!ge.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>=ur&&m.shift(),m.push(L)},ee=L=>{let w=Ne(L)?.segments;if(w){if(w[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[Re(w[1],t.nodes.length)];if(!_)return;let E=w[2];if(E in Qe){let N=Qe[E],A=_[E]||N;return N.map((S,T)=>D(A[T],S))}if(E==="weights"){let N=Array.isArray(_.weights)?_.weights:[0],A=w.length===4?Re(w[3],64):-2;return A===-2?N.map(S=>D(S)):A>=0?D(N[A]):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[Re(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[D(N[0],1),D(N[1],1),D(N[2],1),D(N[3],1)]}if(w[3]==="metallicFactor"||w[3]==="roughnessFactor")return D(E[w[3]],1)}if(w[2]==="emissiveFactor"){let N=_.emissiveFactor||[0,0,0];return[D(N[0]),D(N[1]),D(N[2])]}if(w[2]==="alphaCutoff")return D(_.alphaCutoff,.5)}}},J=(L,w)=>{let _=Ne(L)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let E=Re(_[1],t.nodes.length),N=t.nodes[E];if(!N)return!1;let A=_[2];if(A in Qe&&Array.isArray(w)){let S=Qe[A];if(w.length<S.length)return!1;let T=S.map((H,W)=>D(w[W],H));if(A==="rotation"){let H=Math.hypot(...T);T=H>1e-8?T.map(W=>W/H):[0,0,0,1]}N[A]=T,delete N.matrix;let $=e?.initialNodeTransforms?.[E];return $&&($[A[0]]=[...T]),x=!0,!0}if(A==="weights"){Array.isArray(N.weights)||(N.weights=[]);let S=(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=Re(_[3],64);if(T<0)return!1;S(T,N.weights[T]=D(w))}else if(Array.isArray(w))N.weights=w.slice(0,64).map(T=>D(T)),N.weights.forEach((T,$)=>S($,T));else return!1;return C=!0,!0}if(A==="visible"||A==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let S=pe(w);return N.visible=S,(!N.extensions||typeof N.extensions!="object")&&(N.extensions={}),N.extensions.KHR_node_visibility={visible:S},P=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let E=Re(_[1],t.materials.length),N=t.materials[E];if(!N)return!1;let A=N.pbrMetallicRoughness||(N.pbrMetallicRoughness={}),S=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=[Ee(D(w[0],1)),Ee(D(w[1],1)),Ee(D(w[2],1)),w[3]!==void 0?Ee(D(w[3],1)):A.baseColorFactor?.[3]??1];return A.baseColorFactor=T,S($=>$.baseColor=[...T]),C=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let T=_[3]==="metallicFactor",$=Ee(D(w,T?0:.5));return A[_[3]]=$,S(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,D(w[T]))),C=!0;if(_[2]==="alphaCutoff")return N.alphaCutoff=Ee(D(w,.5)),C=!0}return!1},K=(L,w,_=new Set)=>{let E=q(w,"pointer");if(typeof E!="string"||!E.startsWith("/"))return null;let N=E.replace(/\{([a-zA-Z0-9_]+)\}/g,(A,S)=>{let T=Math.trunc(Number(ae(L,S,void 0,_)??q(w,S)));return Number.isSafeInteger(T)&&T>=0?String(T):"-1"});return Ne(N)?N:null},ae=(L,w,_,E)=>{let N=i[L]?.values;if(!Ze(N,w))return _;let A=N[w];if(A==null)return _;if(typeof A!="object"||Array.isArray(A))return de(A);let S=A;return typeof S.node=="number"?De(S.node,S.socket||"value",E):Ze(S,"value")?de(S.value):_},De=(L,w,_)=>{if(L<0||L>=i.length||_.has(L)||_.size>128||++g>mr)return;let E=i[L],N=F(E);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(N))return de(s.get(L)?.[w]);_.add(L);try{let A=(S,T=0)=>ae(L,S,T,_);if(N==="variable/get"){let S=q(E,"variable")??q(E,"id");return typeof S=="number"||typeof S=="string"?de(c.get(S)):void 0}if(N==="pointer/get"){let S=K(L,E,_);return S?ee(S):void 0}if(N.startsWith("math/")){let S=N.slice(5);if(S in dn)return hr(A("a"),dn[S]);if(S in fn){let T=/^(mul|div|rem|mod|pow)$/.test(S)?1:0;return Et(A("a",S==="mul"?1:0),A("b",T),fn[S])}if(S==="pi")return Math.PI;if(S==="e")return Math.E;if(S==="random")return Math.random();if(S==="clamp")return Et(Et(A("a"),A("b",A("min",0)),Math.max),A("c",A("max",1)),Math.min);if(S==="mix"||S==="quatSlerp")return pn(A("a",0),A("b",1),D(A("c",A("t",.5)),.5),S==="quatSlerp");if(S==="dot"){let T=A("a"),$=A("b");return Array.isArray(T)&&Array.isArray($)?T.reduce((H,W,R)=>H+(W||0)*($[R]||0),0):D(T)*D($)}if(S==="cross"){let T=A("a",[0,0,0]),$=A("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(S==="length"){let T=A("a");return Array.isArray(T)?Math.hypot(...T):Math.abs(D(T))}if(S==="distance"){let T=A("a"),$=A("b");return Array.isArray(T)&&Array.isArray($)?Math.hypot(...T.map((H,W)=>(H||0)-($[W]||0))):Math.abs(D(T)-D($))}if(S==="normalize"){let T=A("a");if(!Array.isArray(T))return D(T)>=0?1:-1;let $=Math.hypot(...T);return $>1e-8?T.map(H=>H/$):T.map(()=>0)}if(S.startsWith("combine"))return["a","b","c","d"].slice(0,Number(S[7])||2).map(T=>D(A(T)));if(S.startsWith("extract")){let T=A("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(S==="eq")return hn(A("a"),A("b"));if(S==="ne")return!hn(A("a"),A("b"));if(S==="lt")return D(A("a"))<D(A("b"));if(S==="le")return D(A("a"))<=D(A("b"));if(S==="gt")return D(A("a"))>D(A("b"));if(S==="ge")return D(A("a"))>=D(A("b"));if(S==="isNaN")return Number.isNaN(Number(A("a")));if(S==="isInf"){let T=Number(A("a"));return!Number.isFinite(T)&&!Number.isNaN(T)}return S==="and"?pe(A("a",!1))&&pe(A("b",!1)):S==="or"?pe(A("a",!1))||pe(A("b",!1)):S==="xor"?pe(A("a",!1))!==pe(A("b",!1)):S==="not"?!pe(A("a",!1)):S==="select"?de(pe(A("condition",!1))?A("a"):A("b")):void 0}return N==="type/boolToInt"||N==="type/boolToFloat"?pe(A("a",!1))?1:0:N==="type/intToBool"||N==="type/floatToBool"?D(A("a",0))!==0:N==="type/intToFloat"?D(A("a",0)):N==="type/floatToInt"?Math.trunc(D(A("a",0))):void 0}finally{_.delete(L)}},fe=()=>{if(x){x=!1,C=!0;let L=ht(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]),Le(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 A=L[E];if(A?.visible===!1||A?.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<qe&&_.push(N)};for(;_.length>0&&w.steps<qe;){w.steps++;let N=_.shift();if(!N||N.node<0||N.node>=i.length)continue;let A=N.node,S=i[A];if(!S)continue;let T=N.socket||"in",$=F(S),H=(R,z=void 0)=>ae(A,R,z,new Set),W=(R="out")=>{let z=S.flows?.[R];z&&E(z)};switch($){case"flow/branch":W(pe(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let R of Object.keys(S.flows||{}).sort((z,Y)=>Number(z)-Number(Y)||z.localeCompare(Y)))W(R);break;case"flow/switch":{let R=S.flows?.[String(H("selection",H("value",0)))]??S.flows?.default;R&&E(R);break}case"flow/for":{let R=Math.trunc(D(H("startIndex",0))),z=Math.trunc(D(H("endIndex",0))),Y=Math.max(1,Math.trunc(D(H("step",1),1))),te=S.flows?.body;if(te&&z>R&&y<pr){let G=Math.min(Math.ceil((z-R)/Y),qe);y++;try{for(let oe=0;oe<G&&w.steps<qe;oe++)I(A,"index",R+oe*Y),Z(te,w)}finally{y--}}let me=S.flows?.completed??S.flows?.out;me&&E(me);break}case"flow/doN":{let R=T==="reset"?0:(d.get(A)||0)+1;if(d.set(A,R),I(A,"currentCount",R),I(A,"count",R),T!=="reset"){let z=Math.trunc(D(H("n",q(S,"stopIterations")??q(S,"n")??1),1));R<=z&&W()}break}case"flow/multiGate":{if(T==="reset"){u.set(A,0);break}let R=Object.keys(S.flows||{}).sort();if(!R.length)break;let z=q(S,"isRandom")?Math.floor(Math.random()*R.length):u.get(A)||0;z<R.length&&(W(R[z]),u.set(A,q(S,"isLoop")!==!1?(z+1)%R.length:z+1));break}case"flow/waitAll":{if(T==="reset"){o.delete(A);break}let R=o.get(A);R||o.set(A,R=new Set),R.add(T),R.size>=Math.max(1,Math.trunc(Number(q(S,"inputFlows")??2)||2))&&(R.clear(),W("out"),W("completed"));break}case"flow/throttle":{if(T==="reset"){l.delete(A);break}let R=Math.max(0,D(H("duration",0))),z=l.get(A);z===void 0||v-z>=R?(l.set(A,v),I(A,"lastRemainingTime",0),W()):I(A,"lastRemainingTime",Math.max(0,R-(v-z)));break}case"flow/delay":case"flow/setDelay":{if(T==="cancel"){for(let te=h.length-1;te>=0;te--)h[te].nodeIdx===A&&h.splice(te,1);I(A,"lastDelayIndex",-1);break}let R=Math.max(0,D(H("duration",q(S,"duration")??0))),z=S.flows?.done??S.flows?.out;if(R<=0){I(A,"lastDelayIndex",-1),z&&E(z);break}h.length>=dr&&h.shift();let Y=b++;I(A,"lastDelayIndex",Y),h.push({id:Y,nodeIdx:A,rem:R,done:z}),$==="flow/setDelay"&&S.flows?.out&&S.flows?.done&&W("out");break}case"flow/cancelDelay":{let R=Math.trunc(D(H("delayIndex",-1),-1));if(R<0)h.length=0;else for(let z=h.length-1;z>=0;z--)h[z].id===R&&h.splice(z,1);W();break}case"variable/set":B(q(S,"variable")??q(S,"id"),H("value")),W();break;case"variable/interpolate":{let R=q(S,"variable")??q(S,"id"),z=H("value",H("target")),Y=Math.max(0,D(H("duration",q(S,"duration")??.3),.3));R!==void 0&&z!==void 0&&O({key:`var:${String(R)}`,varKey:R,from:de(H("from")??c.get(R)??0),to:de(z),dur:Y,elapsed:0,quat:!1,linear:q(S,"easing")==="linear",done:S.flows?.done}),W();break}case"pointer/set":{let R=K(A,S),z=H("value");R&&z!==void 0&&(k(`ptr:${R}`),J(R,z)),W();break}case"pointer/interpolate":{let R=K(A,S),z=H("value",H("target")),Y=Math.max(0,D(H("duration",q(S,"duration")??.3),.3));if(R&&z!==void 0){let te=H("from")??ee(R);te!==void 0&&(Y<=0?(J(R,z),W("done")):O({key:`ptr:${R}`,ptr:R,from:de(te),to:de(z),dur:Y,elapsed:0,quat:R.endsWith("/rotation"),linear:q(S,"easing")==="linear",done:S.flows?.done}))}W();break}case"animation/start":{let R=H("animation")??q(S,"animation")??q(S,"clipName"),z=typeof R=="number"?e?.animations?.[R]?.name??t?.animations?.[R]?.name:typeof R=="string"?R:void 0;e?.playAnimation?.(z),C=!0,W();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),$==="animation/resetAt"&&e?.evaluateAnimation?.(D(H("time",0))),C=!0,W();break;case"event/send":case"customEvent/send":{let R=U(q(S,"event")??q(S,"id")),z={};for(let Y of Object.keys(S.values||{}))ge.has(Y)||(z[Y]=H(Y));R&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:R,values:z}})),Q(R,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)}),fe()},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 A=q(E,"nodeIndex")??q(E,"node")??ae(N,"nodeIndex",void 0,new Set),S=q(E,"meshName");if(typeof S=="string"&&S?L.meshName===S:A==null||Number(A)<0||Number.isNaN(Number(A))||V(_,Math.trunc(Number(A)))){if(I(N,"nodeIndex",_),I(N,"meshIndex",w),Array.isArray(L.hitPoint)){let T=[D(L.hitPoint[0]),D(L.hitPoint[1]),D(L.hitPoint[2])];I(N,"hitPoint",T),I(N,"point",T),I(N,"intersectionPoint",T)}if(Array.isArray(L.normal)){let T=[D(L.normal[0]),D(L.normal[1],1),D(L.normal[2])];I(N,"normal",T),I(N,"hitNormal",T)}typeof L.distance=="number"&&I(N,"distance",L.distance),Z(E.flows?.out)}}),fe()},this.receiveCustomEvent=(L,w={})=>Q(L,w,{steps:0});function Q(L,w,_){if(!(M>=fr)){M++;try{let E=U(L);i.forEach((N,A)=>{if(!/^(customE|e)vent\/receive$/.test(F(N)))return;let S=q(N,"event")??q(N,"id");if(!(U(S)!==E&&String(S)!==String(L))){for(let[T,$]of Object.entries(w))ge.has(T)||I(A,T,de($));Z(N.flows?.out,_)}}),fe()}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 A=N.dur>1e-6?Ee(N.elapsed/N.dur):1,S=N.linear?A:A*A*(3-2*A),T=pn(N.from,N.to,S,N.quat);N.ptr?J(N.ptr,T):N.varKey!==void 0&&B(N.varKey,T),A>=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);fe()},this.dispose=()=>{m.length=0,h.length=0,c.clear(),s.clear(),d.clear(),o.clear(),l.clear(),u.clear()}}},he=new WeakMap,Je=new WeakMap;function br(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||en().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=(Je.get(e)||0)+a,f=!1;for(let c=0;c<i.length;c++){let s=i[c],d=ln(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=D(v.translation[0]),l=D(v.translation[1]),u=D(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){Je.set(e,n);let c=ht(r);e.worldMatrices=c;for(let s of e.meshes||[])s.nodeIndex>=0&&s.nodeIndex<c.length&&(s.transform.set(c[s.nodeIndex]),Le(s.normalMatrix,s.transform))}}function et(e){if(!(!e||typeof e!="object"))return he.get(e)||he.get(e.viewer)||he.get(e._view)}function Lt(e,t,r){let i=et(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var Rt={name:"khr-interactivity",sendInteractivityEvent:Lt,getInteractivityVM:et,onLoadModel(e,t){if(!e||typeof e!="object")return;he.get(e)?.dispose(),he.delete(e),Je.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 Oe(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),br(e,t)},onDestroy(e,t){he.get(t)?.dispose(),he.delete(t),Je.delete(t)}};function Fe(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)),A=new Map,S=new Int32Array(p),T=[],$=[],H=[],W=[];for(let G=0;G<p;G++){let oe=h[G*3],ye=h[G*3+1],we=h[G*3+2],se=Math.min(_-1,Math.max(0,Math.floor((oe-x)/U*_))),le=Math.min(E-1,Math.max(0,Math.floor((ye-P)/V*E))),Se=Math.min(N-1,Math.max(0,Math.floor((we-C)/k*N))),ke=se+le*_+Se*_*E,ne=A.get(ke);ne===void 0?(ne=W.length,A.set(ke,ne),T.push(oe,ye,we),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[ne*3]+=oe,T[ne*3+1]+=ye,T[ne*3+2]+=we,b&&($[ne*3]+=b[G*3],$[ne*3+1]+=b[G*3+1],$[ne*3+2]+=b[G*3+2]),W[ne]++),S[G]=ne}let R=[],z=new Set;for(let G=0;G<g;G++){let oe=M?M[G*3]:G*3,ye=M?M[G*3+1]:G*3+1,we=M?M[G*3+2]:G*3+2,se=S[oe],le=S[ye],Se=S[we];if(se===le||le===Se||Se===se)continue;let ke=Math.min(se,le,Se),ne=Math.max(se,le,Se),Ir=se+le+Se-ke-ne,Zt=`${ke}_${Ir}_${ne}`;z.has(Zt)||(z.add(Zt),R.push(se,le,Se))}let Y=W.length,te=new Float32Array(Y*3),me=b?new Float32Array(Y*3):null;for(let G=0;G<Y;G++){let oe=1/W[G];if(te[G*3]=T[G*3]*oe,te[G*3+1]=T[G*3+1]*oe,te[G*3+2]=T[G*3+2]*oe,me){let ye=$[G*3],we=$[G*3+1],se=$[G*3+2],le=Math.hypot(ye,we,se)||1;me[G*3]=ye/le,me[G*3+1]=we/le,me[G*3+2]=se/le}}return{pos:te,norm:me,uv:v?new Float32Array(H):null,tris:R,triCount:R.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 ae=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])}ae=w}if(ae.length<3){ae=[];for(let w=0;w<y*3;w++)ae.push(M?M[w]:w);K={pos:h.slice(),norm:b?b.slice():null,uv:v?v.slice():null,tris:ae,triCount:y,vertCount:p}}let De=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),fe=De?.BufferGeometry??o.constructor,Z=De?.BufferAttribute??u.constructor,Q=new fe;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(ae):new Uint16Array(ae);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 ze=Fe(),yn=ze.decimateGeometry,tt=ze.selectLodLevelIndex,nt=ze.parseLod,Ao=ze.materializeLodGeometry,gn=ze.LOD,Ce=new WeakMap;function xn(e){return e&&typeof e=="object"?Ce.get(e):void 0}var Ve=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=nt(n);if(!c&&f.length>0&&(c=nt({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=tt(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=tt(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})}}},It={name:"lod",onRegister(){Jt(Fe);let e=ce(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);Fe(t,e)},onLoadModel(e,t){!e||typeof e!="object"||Ce.set(e,new Ve(e,t))},onUpdate(e){let t=Ce.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=Ce.get(e);a&&a.update(i)},onDestroy(e,t){t&&typeof t=="object"&&Ce.delete(t)}},Ge=new Map,rt=new WeakMap;function vn(e,t){Ge.set(e,t)}var _t={name:"materials",onContextRestored(e){rt.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=rt.get(e);r||(r=e.createTexture(),rt.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&&Ge.has(t.name)){let h=Ge.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(T[0],1,0,1)},${u(T[1],1,0,1)},${u(T[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&&ke.has(c.name)&&ke.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 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)}}}},jt=64*1024*1024,Kt=128*1024*1024,Pn=16777216;function Cn(e){return(e>>>1^-(e&1))&255}function Vn(e){return(e>>>1^-(e&1))&65535}function Fn(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Yt(e){return(e<<1^e>>31)>>>0}function Zt(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw X(`unknown filter "${String(e)}"`)}var W=Math.fround;function we(e){return Math.trunc(W(e+(e>=0?.5:-.5)))}function bt(e,t,r,i="NONE"){if(Zt(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 X(`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,T=h(v),p=h(v+g),b=W(h(v+2*g)-Math.abs(T)-Math.abs(p)),y=b>=0?0:b;T=W(T+(T>=0?y:-y)),p=W(p+(p>=0?y:-y));let L=W(Math.sqrt(W(W(W(T*T)+W(p*p))+W(b*b))));if(L===0){f(v,0),f(v+g,0),f(v+2*g,l);continue}let R=W(l/L);f(v,we(W(T*R))),f(v+g,we(W(p*R))),f(v+2*g,we(W(b*R)))}return}if(i==="QUATERNION"){if(r!==8)throw X(`QUATERNION filter requires byteStride 8 (got ${r})`);let u=W(32767/W(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),T=n.getInt16(h+4,!0),p=W(g*g),b=W(W(W(W(p*2)-W(A*A))-W(v*v))-W(T*T)),y=W(Math.sqrt(b>=0?b:0)),L=W(u/g),R=f&3,D=[0,0,0,0];D[R+1&3]=we(W(A*L)),D[R+2&3]=we(W(v*L)),D[R+3&3]=we(W(T*L)),D[R]=Math.trunc(W(W(y*L)+.5));for(let _=0;_<4;_++)n.setInt16(h+_*2,D[_]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw X(`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,W(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,T=f+A,p=f-g-A,b=c(l+3*a);b=b<<1&h|b&1;let y=h===0?0:W(m/h);d(l,Math.trunc(W(W(v*y)+.5))),d(l+a,Math.trunc(W(W(T*y)+.5))),d(l+2*a,Math.trunc(W(W(p*y)+.5))),d(l+3*a,Math.trunc(W(W(b*y)+.5)))}}var Jt=160,fe=16,zn=24,en=32,Bn=24,Gn=[0,2,4,8],Hn=[0,1,2,4,8];function tn(e){let t=Math.floor(8192/e)&~(fe-1);return t<256?t:256}function X(e){return new Error(`EXT_meshopt_compression: ${e}`)}function $n(e,t,r,i,n){if(n===0)return r.fill(0,i,i+fe),t;if(n===8)return r.set(e.subarray(t,t+fe),i),t+fe;let s=(1<<n)-1,m=8/n,c=t+fe*n/8;for(let o=0;o<fe;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 qt(e,t,r,i,n,s,m,c){let o=s/fe,d=o+3>>2;if(r-t<d)throw X("truncated ATTRIBUTES stream");let a=t;t+=d;for(let u=0;u<o;u++){if(r-t<zn)throw X("truncated ATTRIBUTES stream");let l=e[a+(u>>2)]>>(u&3)*2&3;t=$n(e,t,i,n+u*fe,m[c+l])}return t}function Wn(e,t,r,i){if(r%4!==0||r>256)throw X(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw X("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==Jt)throw X(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let m=s&15;if(m>1)throw X(`unsupported ATTRIBUTES codec version ${m}`);let c=r+(m===0?0:r/4),o=m===0?en:Bn,d=c<o?o:c;if(n-1<d)throw X("truncated ATTRIBUTES stream");let a=n-c,u=e.slice(a,a+r),l=a+r,h=tn(r),f=new Uint8Array(256*4),g=1;for(let A=0;A<t;){let v=Math.min(h,t-A),T=v+fe-1&~(fe-1),p=m===0?0:r/4;if(n-g<p)throw X("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 F=L>>_*2&3;if(F===3){if(n-g<v)throw X("truncated ATTRIBUTES stream");f.set(e.subarray(g,g+v),_*v),g+=v}else F===2?f.fill(0,_*v,_*v+v):g=m===0?qt(e,g,n,f,_*v,T,Gn,0):qt(e,g,n,f,_*v,T,Hn,F)}let R=m===0?0:e[l+y/4],D=R&3;if(D===0)for(let _=0;_<4;_++){let F=u[y+_];for(let C=0;C<v;C++)F=Cn(f[_*v+C])+F&255,i[(A+C)*r+y+_]=F}else if(D===1)for(let _=0;_<4;_+=2){let F=u[y+_]|u[y+_+1]<<8,C=_*v;for(let $=0;$<v;$++){let z=f[C+$]|f[C+v+$]<<8;F=Vn(z)+F&65535;let k=(A+$)*r+y+_;i[k]=F&255,i[k+1]=F>>8}}else if(D===2){let _=32-(R>>4)&31,F=(u[y]|u[y+1]<<8|u[y+2]<<16|u[y+3]<<24)>>>0;for(let C=0;C<v;C++){let $=(f[C]|f[v+C]<<8|f[2*v+C]<<16|f[3*v+C]<<24)>>>0;$=(($<<_|$>>>(32-_&31))^F)>>>0,F=$;let z=(A+C)*r+y;i[z]=$&255,i[z+1]=$>>>8&255,i[z+2]=$>>>16&255,i[z+3]=$>>>24}}else throw X(`invalid ATTRIBUTES channel ${R}`)}u.set(i.subarray((A+v-1)*r,(A+v)*r)),A+=v}if(n-g!==d)throw X("ATTRIBUTES trailing data")}var nn=224,rn=208;function on(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 je(e,t,r){let i=on(e,t),n=i>>>1^-(i&1);return r+n>>>0}function Xn(e,t,r){if(t%3!==0)throw X(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw X("truncated TRIANGLES stream");let n=e[0];if((n&240)!==nn)throw X(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw X(`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,R)=>{m[d]=L,c[d]=R,d=d+1&15},l=(L,R=1)=>{o[a]=L,a=a+R&15},h=0,f=0,g=s>=1?13:15,A=1+i,v=e.byteLength-16,T=v,p={pos:A},b=0,y=(L,R,D)=>{r(b++,L),r(b++,R),r(b++,D)};for(let L=1;L<A;L++){let R=e[L];if(R<240){let D=R>>4,_=d-1-D&15,F=m[_],C=c[_],$=0,z=R&15;if(z<g){let k=o[a-1-z&15];$=z===0?h:k;let te=z===0?1:0;h=h+te>>>0,l($,te)}else{if(p.pos>v)throw X("truncated TRIANGLES stream");$=z!==15?f+(z*2-27)>>>0:je(e,p,f),f=$,l($)}u($,C),u(F,$),y(F,C,$)}else if(R<254){let D=e[T+(R&15)],_=D>>4,F=D&15,C=h;h=h+1>>>0;let $=o[a-_&15],z=_===0?h:$,k=_===0?1:0;h=h+k>>>0;let te=o[a-F&15],Q=F===0?h:te,K=F===0?1:0;h=h+K>>>0,y(C,z,Q),l(C),l(z,k),l(Q,K),u(z,C),u(Q,z),u(C,Q)}else{if(p.pos>v)throw X("truncated TRIANGLES stream");let D=e[p.pos++],_=R===254?0:15,F=D>>4,C=D&15;D===0&&(h=0);let $=0;_===0&&($=h,h=h+1>>>0);let z;F===0?(z=h,h=h+1>>>0):z=o[a-F&15];let k;C===0?(k=h,h=h+1>>>0):k=o[a-C&15],_===15&&(f=$=je(e,p,f)),F===15&&(f=z=je(e,p,f)),C===15&&(f=k=je(e,p,f)),y($,z,k),l($),l(z,F===0||F===15?1:0),l(k,C===0||C===15?1:0),u(z,$),u(k,z),u($,k)}}if(p.pos!==v)throw X("TRIANGLES trailing data")}function jn(e,t,r){if(e.byteLength<1+t+4)throw X("truncated INDICES stream");let i=e[0];if((i&240)!==rn)throw X(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw X(`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 X("truncated INDICES stream");let d=on(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 X("INDICES trailing data")}function yt(e,t,r,i,n="NONE"){if(Zt(n),!Number.isInteger(t)||t<0||t>Pn||!Number.isInteger(r)||r<=0||r>256)throw X(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>jt)throw X(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${jt})`);if(t===0)return new Uint8Array(0);let m=new Uint8Array(s);if(i==="ATTRIBUTES")return Wn(e,t,r,m),bt(m,t,r,n),m;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw X(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw X(`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"?Xn(e,t,o):jn(e,t,o),m}throw X(`unknown mode "${String(i)}"`)}function Qt(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function an(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=[Jt],o=tn(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]=Fn(b-A&255),A=b}d[g]=A;let v=f/16,T=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[T+(p>>2)]|=3<<(p&3)*2;for(let y of b)c.push(y)}}}l+=h}for(let l=r;l<en;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=[rn|1],o=0;for(let d=0;d<t;d++){let a=m(d),u=a-o|0;o=a,Qt(c,Yt(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=[nn|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);Qt(o,Yt(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 Ke(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),T=Number(f.byteOffset??0),p=Number(f.byteLength??0),b=f.mode||"ATTRIBUTES",y=f.filter||"NONE";if(y==="COLOR"&&!h)throw X(`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(T)||T<0||!Number.isInteger(p)||p<0||T+p>n.byteLength)throw new Error(`${g}: bufferView ${u} compressed range [${T}, ${T+p}] out of bounds (${n.byteLength})`);let L=A*v;if(m+=L,m>Kt)throw X(`total decompressed size (${m}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Kt})`);let R=n.subarray(T,T+p),D=yt(R,A,v,b,y);s.push({index:u,bytes:D,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 Ye={decodeBufferViews(e,t){Ke(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}};me().decoders.set("meshopt",Ye);var gt={name:"meshopt",onParseGLB(e){me().decoders.set("meshopt",Ye),Ke(e)}};function qe(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 xt(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var qn=`#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&&Ge.has(c.name)&&Ge.get(c.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let c=rt.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)}}}},An=64*1024*1024,Tn=128*1024*1024,yr=16777216;function gr(e){return(e>>>1^-(e&1))&255}function xr(e){return(e>>>1^-(e&1))&65535}function vr(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Sn(e){return(e<<1^e>>31)>>>0}function En(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw X(`unknown filter "${String(e)}"`)}var j=Math.fround;function Ie(e){return Math.trunc(j(e+(e>=0?.5:-.5)))}function Pt(e,t,r,i="NONE"){if(En(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 X(`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,Ie(j(M*C))),h(v+p,Ie(j(g*C))),h(v+2*p,Ie(j(y*C)))}return}if(i==="QUATERNION"){if(r!==8)throw X(`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]=Ie(j(b*P)),F[C+2&3]=Ie(j(v*P)),F[C+3&3]=Ie(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 X(`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 Ln=160,be=16,Ar=24,Rn=32,Tr=24,Sr=[0,2,4,8],wr=[0,1,2,4,8];function In(e){let t=Math.floor(8192/e)&~(be-1);return t<256?t:256}function X(e){return new Error(`EXT_meshopt_compression: ${e}`)}function Mr(e,t,r,i,a){if(a===0)return r.fill(0,i,i+be),t;if(a===8)return r.set(e.subarray(t,t+be),i),t+be;let n=(1<<a)-1,f=8/a,c=t+be*a/8;for(let s=0;s<be;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 wn(e,t,r,i,a,n,f,c){let s=n/be,d=s+3>>2;if(r-t<d)throw X("truncated ATTRIBUTES stream");let o=t;t+=d;for(let l=0;l<s;l++){if(r-t<Ar)throw X("truncated ATTRIBUTES stream");let u=e[o+(l>>2)]>>(l&3)*2&3;t=Mr(e,t,i,a+l*be,f[c+u])}return t}function Er(e,t,r,i){if(r%4!==0||r>256)throw X(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let a=e.byteLength;if(a<1)throw X("truncated ATTRIBUTES stream");let n=e[0];if((n&240)!==Ln)throw X(`unsupported ATTRIBUTES header 0x${n.toString(16)}`);let f=n&15;if(f>1)throw X(`unsupported ATTRIBUTES codec version ${f}`);let c=r+(f===0?0:r/4),s=f===0?Rn:Tr,d=c<s?s:c;if(a-1<d)throw X("truncated ATTRIBUTES stream");let o=a-c,l=e.slice(o,o+r),u=o+r,m=In(r),h=new Uint8Array(256*4),p=1;for(let b=0;b<t;){let v=Math.min(m,t-b),M=v+be-1&~(be-1),g=f===0?0:r/4;if(a-p<g)throw X("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 X("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?wn(e,p,a,h,I*v,M,Sr,0):wn(e,p,a,h,I*v,M,wr,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=gr(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=xr(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 X(`invalid ATTRIBUTES channel ${C}`)}l.set(i.subarray((b+v-1)*r,(b+v)*r)),b+=v}if(a-p!==d)throw X("ATTRIBUTES trailing data")}var _n=224,Pn=208;function Un(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 ot(e,t,r){let i=Un(e,t),a=i>>>1^-(i&1);return r+a>>>0}function Lr(e,t,r){if(t%3!==0)throw X(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw X("truncated TRIANGLES stream");let a=e[0];if((a&240)!==_n)throw X(`unsupported TRIANGLES header 0x${a.toString(16)}`);let n=a&15;if(n>1)throw X(`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 X("truncated TRIANGLES stream");V=k!==15?h+(k*2-27)>>>0:ot(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 X("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=ot(e,g,h)),B===15&&(h=k=ot(e,g,h)),U===15&&(h=O=ot(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 X("TRIANGLES trailing data")}function Rr(e,t,r){if(e.byteLength<1+t+4)throw X("truncated INDICES stream");let i=e[0];if((i&240)!==Pn)throw X(`unsupported INDICES header 0x${i.toString(16)}`);let a=i&15;if(a>1)throw X(`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 X("truncated INDICES stream");let d=Un(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 X("INDICES trailing data")}function Ut(e,t,r,i,a="NONE"){if(En(a),!Number.isInteger(t)||t<0||t>yr||!Number.isInteger(r)||r<=0||r>256)throw X(`invalid count (${t}) or byteStride (${r})`);let n=t*r;if(n>An)throw X(`decompressed size (${n}) exceeds MAX_MESHOPT_BUFFER_BYTES (${An})`);if(t===0)return new Uint8Array(0);let f=new Uint8Array(n);if(i==="ATTRIBUTES")return Er(e,t,r,f),Pt(f,t,r,a),f;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw X(`${i} byteStride must be 2 or 4 (got ${r})`);if(a&&a!=="NONE")throw X(`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"?Lr(e,t,s):Rr(e,t,s),f}throw X(`unknown mode "${String(i)}"`)}function Mn(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Dn(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=[Ln],s=In(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]=vr(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<Rn;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=[Pn|1],s=0;for(let d=0;d<t;d++){let o=f(d),l=o-s|0;s=o,Mn(c,Sn(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=[_n|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);Mn(s,Sn(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 it(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 X(`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>Tn)throw X(`total decompressed size (${f}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Tn})`);let C=a.subarray(M,M+g),F=Ut(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 at={decodeBufferViews(e,t){it(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}};ce().decoders.set("meshopt",at);var Dt={name:"meshopt",onParseGLB(e){ce().decoders.set("meshopt",at),it(e)}};function st(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 kt(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var Pr=`#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
- }`,Qn=`#version 300 es
60
+ }`,Ur=`#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
- }`,sn=`#version 300 es
66
+ }`,kn=`#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
- }`,Zn=`#version 300 es
72
+ }`,Dr=`#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
- }`,Jn=`#version 300 es
95
+ }`,kr=`#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
- }`,Qe=3,Oe=new WeakMap;function vt(e,t=[.22,.74,.97]){let r=lt(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 un(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 dn(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 ln=new WeakSet;function cn(e){let t=Oe.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Oe.delete(e)}if(ln.has(e)||e.isContextLost?.())return null;let r=qe(e,qn,Qn,!1),i=qe(e,sn,Zn,!1),n=qe(e,sn,Jn,!1);if(!r||!i||!n){for(let m of[r,i,n])m&&e.deleteProgram(m);return ln.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},Oe.set(e,t),t}function er(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===Qe&&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<Qe;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 tr(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=ct({strength:s,threshold:xt(t.getAttribute("bloom-threshold"),.62),radius:xt(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=ct(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function nr(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 Ve({color:n,thickness:s,pulse:m})}var rr=new Set(["floor","pedestal","ground","table","grid","pad"]);function or(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>rr.has(t))}function ir(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=Ve(n);if(s)return s;let m=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=nr(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?Ve({color:m,thickness:3,pulse:!1}):null);if(c){let a=t.name||"";return or(a)?null:c}return null}var Tt={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=ir(t,l);h&&s.push({mesh:l,trait:h})}let m=s.length>0?cn(e):null;if(m){let l=m,h=ve(),f=ve(),g=new Float32Array(9),A=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,T=Math.max(1,v?.[2]||i),p=Math.max(1,v?.[3]||n);e.useProgram(l.outlineProg),l.uOutlineViewportSize&&e.uniform2f(l.uOutlineViewportSize,T,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,R,D]=vt(y.color),_=y.pulse?.8+.25*Math.sin(A*4):1;l.uOutlineColor&&e.uniform4f(l.uOutlineColor,L,R,D,1),l.uOutlineThickness&&e.uniform1f(l.uOutlineThickness,y.thickness*_),b.worldSpace===!0?h.set(b.transform):Te(h,t.modelRootMatrix,b.transform);let F=b.instanceMatrices;for(let C of b.primitives)if(!(C.pluginData?.skinning?.hasSkin||C.pluginData?.morph?.hasMorph))if(e.bindVertexArray(C.vao),F&&F.length>=16){let $=F.length>>4,z=ve();for(let k=0;k<$;k++)Te(z,h,F.subarray(k*16,k*16+16)),Te(f,r,z),Ae(g,z),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}else Te(f,r,h),Ae(g,h),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let c=tr(t);if(!c||c.strength<=0)return;let o=cn(e);if(!o||!er(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<Qe;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=Qe-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=Oe.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);Oe.delete(e)}}},sr=`#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.);}`,lr=`#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);}`,Ne=new WeakMap,fn=new Float32Array(20);function At(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 cr(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 ur(e){let t=Ne.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,sr)),e.attachShader(i,r(35632,lr)),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")},Ne.set(e,t),t}var Mt={name:"contact-shadow",onContextRestored(e){Ne.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let n=ur(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=cr(f);if(!g)continue;f.transform&&(g=At(f.transform,g)),t.modelRootMatrix&&(g=At(t.modelRootMatrix,g));let[A,v,T,p,b,y]=g,L=[A,T,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=At(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,T]of m){let p=-1/0;for(let[y,L,R,D,,_]of c)T>=_-.08&&Math.abs(f-y)<=R&&Math.abs(g-L)<=D&&_+.002>p&&(p=_+.002);s&&(p=Math.max(p,f>=.04&&f<=.36&&g>=-.34&&g<=-.04&&T>=.01?.036:Math.hypot(f,g)<=.66&&T>=-.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],T)):o.push([f,g,A,v,T,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,T,p]of o){let b=Math.max(0,T-p),y=i/(1+b*2);if(y<.02)continue;let L=1+Math.min(.75,b*.85),R=Math.max(.045,A*1.45*L),D=Math.max(.045,v*1.45*L);fn.set([f-R,p,g-D,0,0,f+R,p,g-D,1,0,f+R,p,g+D,1,1,f-R,p,g+D,0,1]),e.bufferSubData(34962,0,fn),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=Ne.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Ne.delete(e))}};function wt(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 mn(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 pn(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=wt(s).indexOf(c);if(o<0)return i;for(let d of m)if(d.variants.includes(o))return d.material;return i}var Et={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},hn=new WeakMap,St={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=hn.get(t);if(n||(n={lightProbe:null},hn.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&&Ce(e.gl,s.sphericalHarmonicsCoefficients)}}}};le(Mt),le(at),le(rt),le(ht),le(St),le(mt),le(gt),le(Et),le(Tt),le(pt);
117
+ }`,lt=3,Be=new WeakMap;function Nt(e,t=[.22,.74,.97]){let r=St(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 Cn(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 Fn(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 Nn=new WeakSet;function On(e){let t=Be.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Be.delete(e)}if(Nn.has(e)||e.isContextLost?.())return null;let r=st(e,Pr,Ur,!1),i=st(e,kn,Dr,!1),a=st(e,kn,kr,!1);if(!r||!i||!a){for(let f of[r,i,a])f&&e.deleteProgram(f);return Nn.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},Be.set(e,t),t}function Nr(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===lt&&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<lt;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 Or(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=wt({strength:n,threshold:kt(t.getAttribute("bloom-threshold"),.62),radius:kt(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=wt(a);n&&(!r||n.strength>r.strength)&&(r=n)}return r}function Cr(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 Ye({color:a,thickness:n,pulse:f})}var Fr=new Set(["floor","pedestal","ground","table","grid","pad"]);function Vr(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Fr.has(t))}function zr(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=Ye(a);if(n)return n;let f=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=Cr(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?Ye({color:f,thickness:3,pulse:!1}):null);if(c){let o=t.name||"";return Vr(o)?null:c}return null}var Ot={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=zr(t,u);m&&n.push({mesh:u,trait:m})}let f=n.length>0?On(e):null;if(f){let u=f,m=ie(),h=ie(),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]=Nt(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):re(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=ie();for(let O=0;O<V;O++)re(k,m,B.subarray(O*16,O*16+16)),re(h,r,k),Le(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 re(h,r,m),Le(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=Or(t);if(!c||c.strength<=0)return;let s=On(e);if(!s||!Nr(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<lt;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=lt-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=Be.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Be.delete(e)}}},ct=4,Vt=9,Gr=32*1024*1024,ft=ie(),Vn=new Int32Array([-1,-1]);function Ct(e,t,r,i){let a=Number(e);return Number.isFinite(a)?Math.max(t,Math.min(r,a)):i}var zn=new WeakMap,Ae=new WeakMap,He=new WeakMap,Ue=ie(),ut=ie(),Te=ie(),_e=ie(),Wn=new Float32Array(1),Br=new Uint32Array(Wn.buffer);function zt(e){if(typeof e!="string")return"auto";let t=e.trim().toLowerCase();return t==="pcf"||t==="off"?t:"auto"}function Wr(e){let t=zn.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 zn.set(e,s),s}function Pe(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 Gt(e){let t=e||{},r=t.modelRootMatrix??ft,i=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let l of t.meshes??[]){if(!Wt(l))continue;l.worldSpace===!0?Te.set(l.transform):re(Te,r,l.transform);let u=l.instanceMatrices;for(let m of l.primitives??[]){if(!m.positions||m.positions.length<3)continue;let h=Wr(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)re(_e,Te,u.subarray(v*16,v*16+16)),Pe(h,_e,i,a);if(b>1){let v=p-1;re(_e,Te,u.subarray(v*16,v*16+16)),Pe(h,_e,i,a)}}else Pe(h,Te,i,a)}}if(!Number.isFinite(i[0])){let l=t.bounds;l&&Array.isArray(l.min)&&Array.isArray(l.max)&&Pe([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 Bt(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];pt(Ue,u,r.center,m);let h=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0];Pe([...r.min,...r.max],Ue,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 nn(ut,h[0]-b,Math.max(h[0]+.05,p[0])+b,h[1]-b,Math.max(h[1]+.05,p[1])+b,v,M),re(e,ut,Ue)}function dt(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];pt(Ue,[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];Pe([...n.min,...n.max],Ue,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 tn(ut,F,1,C,Math.max(C+.1,x)),re(e,ut,Ue)}function Hr(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??ft,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 Wt(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 je(e,t){if(!Wt(e))return!1;let r=e.castShadow??e.extras?.shadow?.cast;return r===!1?!1:t?!0:r===!0}function Ht(e,t){if(!e||typeof e!="object")return!1;let r=e;if(!Wt(r))return!1;let i=r.receiveShadow??r.extras?.shadow?.receive;return i!==void 0?!!i:t}function Ft(e){return!(e.isTransmissive||e.alphaMode==="BLEND"||(e.baseColor?.[3]??1)<.98)}function xe(e,t){return Math.imul((e^t>>>0)>>>0,16777619)>>>0}function ve(e,t){return Wn[0]=t||0,xe(e,Br[0])}function We(e,t,r=64){let i=t.length;if(e=xe(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 jt(e){let t=e||{},r=t.shadowMaps??t.container?.getAttribute?.("shadow-maps")??"auto",i=zt(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<ct&&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<ct&&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(je(V,p)){for(let k of V.primitives??[])if(Ft(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>Gr;)g=Math.max(256,g>>1);let x=Gt(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=ie(),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],Bt(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));dt(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],dt(J,Z,K,Math.PI/3,O.range,x)}}let ae=Ct(ee?.bias,-.05,.05,-5e-4),De=Ct(ee?.normalBias,0,.5,.015),fe=Ct(ee?.radius,0,16,1.5);C.push({slot:V,viewProj:J,rayDir:K,depthBias:ae,normalBiasWorld:De/.015*1.75*P,uvRadius:fe*1.35/g})}let F=Hr(t),I=2166136261;I=xe(I,i==="pcf"?2:1),I=xe(I,g),I=xe(I,C.length);for(let V of C)I=We(I,V.viewProj,16),I=ve(I,V.depthBias),I=ve(I,V.normalBiasWorld);F?.enabled?(I=xe(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=xe(I,0);let B=t.modelRootMatrix??ft;I=We(I,B,16);let U=0;for(let V of m){if(!je(V,p)){U++;continue}I=xe(I,U++),I=We(I,V.transform,16),V.instanceMatrices&&(I=We(I,V.instanceMatrices,64));for(let k of V.primitives??[])Ft(k)&&(I=xe(I,k.indexCount),k.translations&&(I=We(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 Hn(e){let t=Ae.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 jr=`#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
+ }`,$r=`#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
+ }`,Xr=`
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
+ }`,Kr=["uShadowMap","uShadowVP","uShadowParams","uDirShdSlot","uPtShdSlot","uReceiveShadow"];function Yr(e){let t=Ae.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},Ae.set(e,t)),t}function jn(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 $n(e){let t=He.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,jr),e.compileShader(i),e.shaderSource(a,$r),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:jn(e,1,1)},He.set(e,t),t}var Gn={uniformsGLSL:Xr,dirGLSL:"*shdEval(uDirShdSlot[i],vWorldPos,N,normalize(uDirLightDir[i]))",ptGLSL:"*shdEval(uPtShdSlot[i],vWorldPos,N,L)",uniformNames:Kr,bind(e,t,r,i){let a=t.uShadowMap;if(a===void 0)return;let n=r&&typeof r=="object"?Ae.get(r):void 0,f=$n(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,Vt);let d=t.uDirShdSlot,o=t.uPtShdSlot,l=t.uReceiveShadow;if(!c){d&&e.uniform1iv?.(d,Vn),o&&e.uniform1iv?.(o,Vn),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,Ht(i,n.promoteAllReceivers)?1:0)}};function Bn(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}var $t={name:"shadow-maps",onRegister(){ce().shadowMapShader=Gn},onLoadModel(e){if(e&&typeof e=="object"){let t=Ae.get(e);t&&(t.lastDigest=0)}},onClearScene(e){if(e&&typeof e=="object"){let t=Ae.get(e);t&&(t.lastDigest=0,t.activeLights=0)}},onContextRestored(e,t){if(He.delete(e),t&&typeof t=="object"){let r=Ae.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=Ae.get(t);r&&(r.texArray&&e.deleteTexture?.(r.texArray),r.fbo&&e.deleteFramebuffer?.(r.fbo),Ae.delete(t))}else if(e){let r=He.get(e);r&&(r.prog&&e.deleteProgram?.(r.prog),r.dummyArrayTex&&e.deleteTexture?.(r.dummyArrayTex),He.delete(e))}},onBeforeDrawScene(e,t){if(!e||typeof e!="object")return;let r=e,i=ce();if(i.shadowMapShader||(i.shadowMapShader=Gn),r.uRender&&!("uShadowMap"in r.uRender)&&r.recompileRenderProgram?.(),i.gpuSceneAccelerator?.willRenderScene?.(e))return;let a=Yr(e),n=jt(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=$n(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=jn(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??ft,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(!je(h,n.promoteAllCasters))continue;h.worldSpace===!0?Te.set(h.transform):re(Te,l,h.transform);let p=h.instanceMatrices;for(let b of h.primitives??[])if(!(!b.vao||b.indexCount<=0||!Ft(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,Te),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++)re(_e,Te,p.subarray(M*16,M*16+16)),f.uModel&&t.uniformMatrix4fv(f.uModel,!1,_e),Bn(t,b)}else Bn(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])}},Qr=`#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.);}`,Zr=`#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);}`,$e=new WeakMap,Xn=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 Jr(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 eo(e){let t=$e.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,Qr)),e.attachShader(i,r(35632,Zr)),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")},$e.set(e,t),t}var Kt={name:"contact-shadow",onContextRestored(e){$e.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let a=eo(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=Jr(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);Xn.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,Xn),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=$e.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),$e.delete(e))}};function Yt(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 Kn(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 Yn(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=Yt(n).indexOf(c);if(s<0)return i;for(let d of f)if(d.variants.includes(s))return d.material;return i}var qt={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},qn=new WeakMap,Qt={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=qn.get(t);if(a||(a={lightProbe:null},qn.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&&Ke(e.gl,n.sphericalHarmonicsCoefficients)}}}};ue(Kt),ue($t),ue(At),ue(gt),ue(_t),ue(Qt),ue(Rt),ue(Dt),ue(qt),ue(Ot),ue(It);