@mapvx/web-components-ssr 1.7.0-dev.1 → 1.7.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +17 -13
  2. package/dist/browser/{chunk-Cg9Nd_Mm.js → chunk-BcTPI0Ei.js} +78 -78
  3. package/dist/browser/chunk-BxefRtM9.js +3 -0
  4. package/dist/browser/{chunk-qJiyNNGo.js → chunk-C64ZrtDH.js} +9 -9
  5. package/dist/browser/{chunk-BK2bFfek.js → chunk-C7x5ioh5.js} +28 -28
  6. package/dist/browser/chunk-CHv413eO.js +13 -0
  7. package/dist/browser/chunk-CRCKWzfw.js +3 -0
  8. package/dist/browser/chunk-CYtO4qrL.js +3 -0
  9. package/dist/browser/chunk-CgRco1rJ.js +2 -0
  10. package/dist/browser/chunk-CwafJShv.js +3 -0
  11. package/dist/browser/chunk-D6zG2upO.js +1180 -0
  12. package/dist/browser/chunk-DIEcQ4a-.js +1318 -0
  13. package/dist/browser/chunk-DtPiRK4g.js +3 -0
  14. package/dist/browser/chunk-FjUzkN6v.js +2 -0
  15. package/dist/browser/chunk-KW-jIWmp.js +3 -0
  16. package/dist/browser/chunk-sqKVpUVP.js +4116 -0
  17. package/dist/browser/main.js +71 -71
  18. package/dist/browser/styles.css +1 -1
  19. package/dist/types/public-api.d.ts +90 -24
  20. package/package.json +29 -29
  21. package/dist/browser/chunk-7vIcv6rM.js +0 -1180
  22. package/dist/browser/chunk-Bjk3HkK2.js +0 -3
  23. package/dist/browser/chunk-CCaUxYwr.js +0 -3
  24. package/dist/browser/chunk-CTFjnL_B.js +0 -2
  25. package/dist/browser/chunk-ClYPPgpq.js +0 -3
  26. package/dist/browser/chunk-ConEJto8.js +0 -1318
  27. package/dist/browser/chunk-CuTcljJ2.js +0 -2
  28. package/dist/browser/chunk-CzASft0S.js +0 -13
  29. package/dist/browser/chunk-DAjekpI-.js +0 -3
  30. package/dist/browser/chunk-DHX-WiFW.js +0 -3
  31. package/dist/browser/chunk-DsKCGfdq.js +0 -3
  32. package/dist/browser/chunk-LltjhLJU.js +0 -4116
@@ -1,4 +1,4 @@
1
- import{i as u,n as s,o as w,t as r}from"./main.js";import{J as ui$1,L as j,O as Y$1,P as f,R as je,S as Ut$1,T as We,U as qe,V as lt$1,X as v,Y as ut$1,Z as vi,_ as P,a as Di$1,b as R,c as He,f as Ke$1,h as N$1,i as Ci,l as I,m as Mt$1,n as $e$1,p as L,r as Bi$1,u as J$1,v as Qe$1,y as Qr$1,z as jt$1}from"./chunk-CzASft0S.js";var Fa=1/Math.PI*180;var Va=1/180*Math.PI;globalThis.mathgl=globalThis.mathgl||{config:r({},{EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1})};var V=globalThis.mathgl.config;function In(t,{precision:e=V.precision}={}){return t=$a(t),`${parseFloat(t.toPrecision(e))}`}function q(t){return Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function ka(t){return Ti(t)}function Ga(t){return Pi(t)}function Ti(t,e){return Ln(t,n=>n*Va,e)}function Pi(t,e){return Ln(t,n=>n*Fa,e)}function za(t,e,n){return Ln(t,r=>Math.max(e,Math.min(n,r)))}function Ni(t,e,n){return q(t)?t.map((r,i)=>Ni(r,e[i],n)):n*e+(1-n)*t}function Mt(t,e,n){let r=V.EPSILON;n&&(V.EPSILON=n);try{if(t===e)return!0;if(q(t)&&q(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!Mt(t[i],e[i]))return!1;return!0}return t&&t.equals?t.equals(e):e&&e.equals?e.equals(t):typeof t==`number`&&typeof e==`number`?Math.abs(t-e)<=V.EPSILON*Math.max(1,Math.abs(t),Math.abs(e)):!1}finally{V.EPSILON=r}}function $a(t){return Math.round(t/V.EPSILON)*V.EPSILON}function Ha(t){return t.clone?t.clone():new Array(t.length)}function Ln(t,e,n){if(q(t)){let r=t;n=n||Ha(r);for(let i=0;i<n.length&&i<r.length;++i){let o=typeof t==`number`?t:t[i];n[i]=e(o,i,n)}return n}return e(t)}var ae=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+n];return this.check()}toArray(e=[],n=0){for(let r=0;r<this.ELEMENTS;++r)e[n+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:q(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(V)}formatString(e){let n=``;for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?`, `:``)+In(this[r],e);return`${e.printTypes?this.constructor.name:``}[${n}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!Mt(this[n],e[n]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==e[n])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,n,r){if(r===void 0)return this.lerp(this,e,n);for(let i=0;i<this.ELEMENTS;++i){let o=e[i],s=typeof n==`number`?n:n[i];this[i]=o+r*(s-o)}return this.check()}min(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(e[n],this[n]);return this.check()}max(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(e[n],this[n]);return this.check()}clamp(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),n[r]);return this.check()}add(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(e){if(typeof e==`number`)for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;else for(let n=0;n<this.ELEMENTS&&n<e.length;++n)this[n]*=e[n];return this.check()}multiplyByScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}check(){if(V.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)e=e&&Number.isFinite(this[n]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=e;return this.check()}addScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),n);return this.check()}get elements(){return this}};function Wa(t,e){if(t.length!==e)return!1;for(let n=0;n<t.length;++n)if(!Number.isFinite(t[n]))return!1;return!0}function N(t){if(!Number.isFinite(t))throw new Error(`Invalid number ${JSON.stringify(t)}`);return t}function ce(t,e,n=``){if(V.debug&&!Wa(t,e))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return t}var we=class extends ae{toString(){let e=`[`;if(V.printRowMajor){e+=`row-major:`;for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+n]}`}else{e+=`column-major:`;for(let n=0;n<this.ELEMENTS;++n)e+=` ${this[n]}`}return e+=`]`,e}getElementIndex(e,n){return n*this.RANK+e}getElement(e,n){return this[n*this.RANK+e]}setElement(e,n,r){return this[n*this.RANK+e]=N(r),this}getColumn(e,n=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)n[i]=this[r+i];return n}setColumn(e,n){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)this[r+i]=n[i];return this}};function At(t,e,n){let r=e[0],i=e[1],o=n[3]*r+n[7]*i||1;return t[0]=(n[0]*r+n[4]*i)/o,t[1]=(n[1]*r+n[5]*i)/o,t}function Et(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[3]*r+n[7]*i+n[11]*o||1;return t[0]=(n[0]*r+n[4]*i+n[8]*o)/s,t[1]=(n[1]*r+n[5]*i+n[9]*o)/s,t[2]=(n[2]*r+n[6]*i+n[10]*o)/s,t}function Bi(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t[2]=e[2],t}function Oi(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t[2]=e[2],t[3]=e[3],t}function It(t,e,n){let r=e[0],i=e[1],o=e[2];return t[0]=n[0]*r+n[3]*i+n[6]*o,t[1]=n[1]*r+n[4]*i+n[7]*o,t[2]=n[2]*r+n[5]*i+n[8]*o,t[3]=e[3],t}var zi={};w(zi,{add:()=>gc,adjoint:()=>Ka,clone:()=>qa,copy:()=>Ya,create:()=>ja,decompose:()=>ac,determinant:()=>Cn,equals:()=>xc,exactEquals:()=>vc,frob:()=>mc,fromQuat:()=>Fn,fromQuat2:()=>ic,fromRotation:()=>ec,fromRotationTranslation:()=>Fi,fromRotationTranslationScale:()=>cc,fromRotationTranslationScaleOrigin:()=>lc,fromScaling:()=>Qa,fromTranslation:()=>Ja,fromValues:()=>Xa,fromXRotation:()=>tc,fromYRotation:()=>nc,fromZRotation:()=>rc,frustum:()=>Vn,getRotation:()=>sc,getScaling:()=>Vi,getTranslation:()=>oc,identity:()=>Ui,invert:()=>wn,lookAt:()=>Gn,mul:()=>Sc,multiply:()=>Xe,multiplyScalar:()=>bc,multiplyScalarAndAdd:()=>_c,ortho:()=>kn,orthoNO:()=>ki,orthoZO:()=>pc,perspective:()=>Dn,perspectiveFromFieldOfView:()=>uc,perspectiveNO:()=>Di,perspectiveZO:()=>fc,rotate:()=>Nn,rotateX:()=>Bn,rotateY:()=>On,rotateZ:()=>Un,scale:()=>Pn,set:()=>Za,str:()=>hc,sub:()=>yc,subtract:()=>Gi,targetTo:()=>dc,translate:()=>Tn,transpose:()=>Rn});var F=typeof Float32Array<`u`?Float32Array:Array;var K=Math.random;function X(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}Math.PI/180;function ja(){let t=new F(16);return F!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function qa(t){let e=new F(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Ya(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Xa(t,e,n,r,i,o,s,a,c,l,f,u,p,d,h,g){let m=new F(16);return m[0]=t,m[1]=e,m[2]=n,m[3]=r,m[4]=i,m[5]=o,m[6]=s,m[7]=a,m[8]=c,m[9]=l,m[10]=f,m[11]=u,m[12]=p,m[13]=d,m[14]=h,m[15]=g,m}function Za(t,e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=o,t[5]=s,t[6]=a,t[7]=c,t[8]=l,t[9]=f,t[10]=u,t[11]=p,t[12]=d,t[13]=h,t[14]=g,t[15]=m,t}function Ui(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Rn(t,e){if(t===e){let n=e[1],r=e[2],i=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=n,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=o,t[11]=e[14],t[12]=i,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function wn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],p=e[10],d=e[11],h=e[12],g=e[13],m=e[14],_=e[15],S=n*a-r*s,y=n*c-i*s,v=n*l-o*s,x=r*c-i*a,M=r*l-o*a,I=i*l-o*c,L=f*g-u*h,P=f*m-p*h,E=f*_-d*h,O=u*m-p*g,w=u*_-d*g,T=p*_-d*m,C=S*T-y*w+v*O+x*E-M*P+I*L;return C?(C=1/C,t[0]=(a*T-c*w+l*O)*C,t[1]=(i*w-r*T-o*O)*C,t[2]=(g*I-m*M+_*x)*C,t[3]=(p*M-u*I-d*x)*C,t[4]=(c*E-s*T-l*P)*C,t[5]=(n*T-i*E+o*P)*C,t[6]=(m*v-h*I-_*y)*C,t[7]=(f*I-p*v+d*y)*C,t[8]=(s*w-a*E+l*L)*C,t[9]=(r*E-n*w-o*L)*C,t[10]=(h*M-g*v+_*S)*C,t[11]=(u*v-f*M-d*S)*C,t[12]=(a*P-s*O-c*L)*C,t[13]=(n*O-r*P+i*L)*C,t[14]=(g*y-h*x-m*S)*C,t[15]=(f*x-u*y+p*S)*C,t):null}function Ka(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],p=e[10],d=e[11],h=e[12],g=e[13],m=e[14],_=e[15],S=n*a-r*s,y=n*c-i*s,v=n*l-o*s,x=r*c-i*a,M=r*l-o*a,I=i*l-o*c,L=f*g-u*h,P=f*m-p*h,E=f*_-d*h,O=u*m-p*g,w=u*_-d*g,T=p*_-d*m;return t[0]=a*T-c*w+l*O,t[1]=i*w-r*T-o*O,t[2]=g*I-m*M+_*x,t[3]=p*M-u*I-d*x,t[4]=c*E-s*T-l*P,t[5]=n*T-i*E+o*P,t[6]=m*v-h*I-_*y,t[7]=f*I-p*v+d*y,t[8]=s*w-a*E+l*L,t[9]=r*E-n*w-o*L,t[10]=h*M-g*v+_*S,t[11]=u*v-f*M-d*S,t[12]=a*P-s*O-c*L,t[13]=n*O-r*P+i*L,t[14]=g*y-h*x-m*S,t[15]=f*x-u*y+p*S,t}function Cn(t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8],f=t[9],u=t[10],p=t[11],d=t[12],h=t[13],g=t[14],m=t[15],_=e*s-n*o,S=e*a-r*o,y=n*a-r*s,v=l*h-f*d,x=l*g-u*d,M=f*g-u*h,I=e*M-n*x+r*v,L=o*M-s*x+a*v,P=l*y-f*S+u*_,E=d*y-h*S+g*_;return c*I-i*L+m*P-p*E}function Xe(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=e[9],d=e[10],h=e[11],g=e[12],m=e[13],_=e[14],S=e[15],y=n[0],v=n[1],x=n[2],M=n[3];return t[0]=y*r+v*a+x*u+M*g,t[1]=y*i+v*c+x*p+M*m,t[2]=y*o+v*l+x*d+M*_,t[3]=y*s+v*f+x*h+M*S,y=n[4],v=n[5],x=n[6],M=n[7],t[4]=y*r+v*a+x*u+M*g,t[5]=y*i+v*c+x*p+M*m,t[6]=y*o+v*l+x*d+M*_,t[7]=y*s+v*f+x*h+M*S,y=n[8],v=n[9],x=n[10],M=n[11],t[8]=y*r+v*a+x*u+M*g,t[9]=y*i+v*c+x*p+M*m,t[10]=y*o+v*l+x*d+M*_,t[11]=y*s+v*f+x*h+M*S,y=n[12],v=n[13],x=n[14],M=n[15],t[12]=y*r+v*a+x*u+M*g,t[13]=y*i+v*c+x*p+M*m,t[14]=y*o+v*l+x*d+M*_,t[15]=y*s+v*f+x*h+M*S,t}function Tn(t,e,n){let r=n[0],i=n[1],o=n[2],s,a,c,l,f,u,p,d,h,g,m,_;return e===t?(t[12]=e[0]*r+e[4]*i+e[8]*o+e[12],t[13]=e[1]*r+e[5]*i+e[9]*o+e[13],t[14]=e[2]*r+e[6]*i+e[10]*o+e[14],t[15]=e[3]*r+e[7]*i+e[11]*o+e[15]):(s=e[0],a=e[1],c=e[2],l=e[3],f=e[4],u=e[5],p=e[6],d=e[7],h=e[8],g=e[9],m=e[10],_=e[11],t[0]=s,t[1]=a,t[2]=c,t[3]=l,t[4]=f,t[5]=u,t[6]=p,t[7]=d,t[8]=h,t[9]=g,t[10]=m,t[11]=_,t[12]=s*r+f*i+h*o+e[12],t[13]=a*r+u*i+g*o+e[13],t[14]=c*r+p*i+m*o+e[14],t[15]=l*r+d*i+_*o+e[15]),t}function Pn(t,e,n){let r=n[0],i=n[1],o=n[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Nn(t,e,n,r){let i=r[0],o=r[1],s=r[2],a=Math.sqrt(i*i+o*o+s*s),c,l,f,u,p,d,h,g,m,_,S,y,v,x,M,I,L,P,E,O,w,T,C,z;return a<1e-6?null:(a=1/a,i*=a,o*=a,s*=a,l=Math.sin(n),c=Math.cos(n),f=1-c,u=e[0],p=e[1],d=e[2],h=e[3],g=e[4],m=e[5],_=e[6],S=e[7],y=e[8],v=e[9],x=e[10],M=e[11],I=i*i*f+c,L=o*i*f+s*l,P=s*i*f-o*l,E=i*o*f-s*l,O=o*o*f+c,w=s*o*f+i*l,T=i*s*f+o*l,C=o*s*f-i*l,z=s*s*f+c,t[0]=u*I+g*L+y*P,t[1]=p*I+m*L+v*P,t[2]=d*I+_*L+x*P,t[3]=h*I+S*L+M*P,t[4]=u*E+g*O+y*w,t[5]=p*E+m*O+v*w,t[6]=d*E+_*O+x*w,t[7]=h*E+S*O+M*w,t[8]=u*T+g*C+y*z,t[9]=p*T+m*C+v*z,t[10]=d*T+_*C+x*z,t[11]=h*T+S*C+M*z,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Bn(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[4],s=e[5],a=e[6],c=e[7],l=e[8],f=e[9],u=e[10],p=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*i+l*r,t[5]=s*i+f*r,t[6]=a*i+u*r,t[7]=c*i+p*r,t[8]=l*i-o*r,t[9]=f*i-s*r,t[10]=u*i-a*r,t[11]=p*i-c*r,t}function On(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],c=e[3],l=e[8],f=e[9],u=e[10],p=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i-l*r,t[1]=s*i-f*r,t[2]=a*i-u*r,t[3]=c*i-p*r,t[8]=o*r+l*i,t[9]=s*r+f*i,t[10]=a*r+u*i,t[11]=c*r+p*i,t}function Un(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],c=e[3],l=e[4],f=e[5],u=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i+l*r,t[1]=s*i+f*r,t[2]=a*i+u*r,t[3]=c*i+p*r,t[4]=l*i-o*r,t[5]=f*i-s*r,t[6]=u*i-a*r,t[7]=p*i-c*r,t}function Ja(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function Qa(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function ec(t,e,n){let r=n[0],i=n[1],o=n[2],s=Math.sqrt(r*r+i*i+o*o),a,c,l;return s<1e-6?null:(s=1/s,r*=s,i*=s,o*=s,c=Math.sin(e),a=Math.cos(e),l=1-a,t[0]=r*r*l+a,t[1]=i*r*l+o*c,t[2]=o*r*l-i*c,t[3]=0,t[4]=r*i*l-o*c,t[5]=i*i*l+a,t[6]=o*i*l+r*c,t[7]=0,t[8]=r*o*l+i*c,t[9]=i*o*l-r*c,t[10]=o*o*l+a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function tc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=r,t[6]=n,t[7]=0,t[8]=0,t[9]=-n,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function nc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=r,t[1]=0,t[2]=-n,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=n,t[9]=0,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function rc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=r,t[1]=n,t[2]=0,t[3]=0,t[4]=-n,t[5]=r,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Fi(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=r+r,c=i+i,l=o+o,f=r*a,u=r*c,p=r*l,d=i*c,h=i*l,g=o*l,m=s*a,_=s*c,S=s*l;return t[0]=1-(d+g),t[1]=u+S,t[2]=p-_,t[3]=0,t[4]=u-S,t[5]=1-(f+g),t[6]=h+m,t[7]=0,t[8]=p+_,t[9]=h-m,t[10]=1-(f+d),t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ic(t,e){let n=new F(3),r=-e[0],i=-e[1],o=-e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=r*r+i*i+o*o+s*s;return u>0?(n[0]=(a*s+f*r+c*o-l*i)*2/u,n[1]=(c*s+f*i+l*r-a*o)*2/u,n[2]=(l*s+f*o+a*i-c*r)*2/u):(n[0]=(a*s+f*r+c*o-l*i)*2,n[1]=(c*s+f*i+l*r-a*o)*2,n[2]=(l*s+f*o+a*i-c*r)*2),Fi(t,e,n),t}function oc(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Vi(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],a=e[6],c=e[8],l=e[9],f=e[10];return t[0]=Math.sqrt(n*n+r*r+i*i),t[1]=Math.sqrt(o*o+s*s+a*a),t[2]=Math.sqrt(c*c+l*l+f*f),t}function sc(t,e){let n=new F(3);Vi(n,e);let r=1/n[0],i=1/n[1],o=1/n[2],s=e[0]*r,a=e[1]*i,c=e[2]*o,l=e[4]*r,f=e[5]*i,u=e[6]*o,p=e[8]*r,d=e[9]*i,h=e[10]*o,g=s+f+h,m=0;return g>0?(m=Math.sqrt(g+1)*2,t[3]=.25*m,t[0]=(u-d)/m,t[1]=(p-c)/m,t[2]=(a-l)/m):s>f&&s>h?(m=Math.sqrt(1+s-f-h)*2,t[3]=(u-d)/m,t[0]=.25*m,t[1]=(a+l)/m,t[2]=(p+c)/m):f>h?(m=Math.sqrt(1+f-s-h)*2,t[3]=(p-c)/m,t[0]=(a+l)/m,t[1]=.25*m,t[2]=(u+d)/m):(m=Math.sqrt(1+h-s-f)*2,t[3]=(a-l)/m,t[0]=(p+c)/m,t[1]=(u+d)/m,t[2]=.25*m),t}function ac(t,e,n,r){e[0]=r[12],e[1]=r[13],e[2]=r[14];let i=r[0],o=r[1],s=r[2],a=r[4],c=r[5],l=r[6],f=r[8],u=r[9],p=r[10];n[0]=Math.sqrt(i*i+o*o+s*s),n[1]=Math.sqrt(a*a+c*c+l*l),n[2]=Math.sqrt(f*f+u*u+p*p);let d=1/n[0],h=1/n[1],g=1/n[2],m=i*d,_=o*h,S=s*g,y=a*d,v=c*h,x=l*g,M=f*d,I=u*h,L=p*g,P=m+v+L,E=0;return P>0?(E=Math.sqrt(P+1)*2,t[3]=.25*E,t[0]=(x-I)/E,t[1]=(M-S)/E,t[2]=(_-y)/E):m>v&&m>L?(E=Math.sqrt(1+m-v-L)*2,t[3]=(x-I)/E,t[0]=.25*E,t[1]=(_+y)/E,t[2]=(M+S)/E):v>L?(E=Math.sqrt(1+v-m-L)*2,t[3]=(M-S)/E,t[0]=(_+y)/E,t[1]=.25*E,t[2]=(x+I)/E):(E=Math.sqrt(1+L-m-v)*2,t[3]=(_-y)/E,t[0]=(M+S)/E,t[1]=(x+I)/E,t[2]=.25*E),t}function cc(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3],c=i+i,l=o+o,f=s+s,u=i*c,p=i*l,d=i*f,h=o*l,g=o*f,m=s*f,_=a*c,S=a*l,y=a*f,v=r[0],x=r[1],M=r[2];return t[0]=(1-(h+m))*v,t[1]=(p+y)*v,t[2]=(d-S)*v,t[3]=0,t[4]=(p-y)*x,t[5]=(1-(u+m))*x,t[6]=(g+_)*x,t[7]=0,t[8]=(d+S)*M,t[9]=(g-_)*M,t[10]=(1-(u+h))*M,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function lc(t,e,n,r,i){let o=e[0],s=e[1],a=e[2],c=e[3],l=o+o,f=s+s,u=a+a,p=o*l,d=o*f,h=o*u,g=s*f,m=s*u,_=a*u,S=c*l,y=c*f,v=c*u,x=r[0],M=r[1],I=r[2],L=i[0],P=i[1],E=i[2],O=(1-(g+_))*x,w=(d+v)*x,T=(h-y)*x,C=(d-v)*M,z=(1-(p+_))*M,H=(m+S)*M,W=(h+y)*I,He=(m-S)*I,Sn=(1-(p+g))*I;return t[0]=O,t[1]=w,t[2]=T,t[3]=0,t[4]=C,t[5]=z,t[6]=H,t[7]=0,t[8]=W,t[9]=He,t[10]=Sn,t[11]=0,t[12]=n[0]+L-(O*L+C*P+W*E),t[13]=n[1]+P-(w*L+z*P+He*E),t[14]=n[2]+E-(T*L+H*P+Sn*E),t[15]=1,t}function Fn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n+n,a=r+r,c=i+i,l=n*s,f=r*s,u=r*a,p=i*s,d=i*a,h=i*c,g=o*s,m=o*a,_=o*c;return t[0]=1-u-h,t[1]=f+_,t[2]=p-m,t[3]=0,t[4]=f-_,t[5]=1-l-h,t[6]=d+g,t[7]=0,t[8]=p+m,t[9]=d-g,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Vn(t,e,n,r,i,o,s){let a=1/(n-e),c=1/(i-r),l=1/(o-s);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(n+e)*a,t[9]=(i+r)*c,t[10]=(s+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=s*o*2*l,t[15]=0,t}function Di(t,e,n,r,i){let o=1/Math.tan(e/2);if(t[0]=o/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==Infinity){let s=1/(r-i);t[10]=(i+r)*s,t[14]=2*i*r*s}else t[10]=-1,t[14]=-2*r;return t}var Dn=Di;function fc(t,e,n,r,i){let o=1/Math.tan(e/2);if(t[0]=o/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==Infinity){let s=1/(r-i);t[10]=i*s,t[14]=i*r*s}else t[10]=-1,t[14]=-r;return t}function uc(t,e,n,r){let i=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),s=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(s+a),l=2/(i+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((s-a)*c*.5),t[9]=(i-o)*l*.5,t[10]=r/(n-r),t[11]=-1,t[12]=0,t[13]=0,t[14]=r*n/(n-r),t[15]=0,t}function ki(t,e,n,r,i,o,s){let a=1/(e-n),c=1/(r-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+n)*a,t[13]=(i+r)*c,t[14]=(s+o)*l,t[15]=1,t}var kn=ki;function pc(t,e,n,r,i,o,s){let a=1/(e-n),c=1/(r-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+n)*a,t[13]=(i+r)*c,t[14]=o*l,t[15]=1,t}function Gn(t,e,n,r){let i,o,s,a,c,l,f,u,p,d,h=e[0],g=e[1],m=e[2],_=r[0],S=r[1],y=r[2],v=n[0],x=n[1],M=n[2];return Math.abs(h-v)<1e-6&&Math.abs(g-x)<1e-6&&Math.abs(m-M)<1e-6?Ui(t):(u=h-v,p=g-x,d=m-M,i=1/Math.sqrt(u*u+p*p+d*d),u*=i,p*=i,d*=i,o=S*d-y*p,s=y*u-_*d,a=_*p-S*u,i=Math.sqrt(o*o+s*s+a*a),i?(i=1/i,o*=i,s*=i,a*=i):(o=0,s=0,a=0),c=p*a-d*s,l=d*o-u*a,f=u*s-p*o,i=Math.sqrt(c*c+l*l+f*f),i?(i=1/i,c*=i,l*=i,f*=i):(c=0,l=0,f=0),t[0]=o,t[1]=c,t[2]=u,t[3]=0,t[4]=s,t[5]=l,t[6]=p,t[7]=0,t[8]=a,t[9]=f,t[10]=d,t[11]=0,t[12]=-(o*h+s*g+a*m),t[13]=-(c*h+l*g+f*m),t[14]=-(u*h+p*g+d*m),t[15]=1,t)}function dc(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=r[0],c=r[1],l=r[2],f=i-n[0],u=o-n[1],p=s-n[2],d=f*f+u*u+p*p;d>0&&(d=1/Math.sqrt(d),f*=d,u*=d,p*=d);let h=c*p-l*u,g=l*f-a*p,m=a*u-c*f;return d=h*h+g*g+m*m,d>0&&(d=1/Math.sqrt(d),h*=d,g*=d,m*=d),t[0]=h,t[1]=g,t[2]=m,t[3]=0,t[4]=u*m-p*g,t[5]=p*h-f*m,t[6]=f*g-u*h,t[7]=0,t[8]=f,t[9]=u,t[10]=p,t[11]=0,t[12]=i,t[13]=o,t[14]=s,t[15]=1,t}function hc(t){return`mat4(${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}, ${t[4]}, ${t[5]}, ${t[6]}, ${t[7]}, ${t[8]}, ${t[9]}, ${t[10]}, ${t[11]}, ${t[12]}, ${t[13]}, ${t[14]}, ${t[15]})`}function mc(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function gc(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t[4]=e[4]+n[4],t[5]=e[5]+n[5],t[6]=e[6]+n[6],t[7]=e[7]+n[7],t[8]=e[8]+n[8],t[9]=e[9]+n[9],t[10]=e[10]+n[10],t[11]=e[11]+n[11],t[12]=e[12]+n[12],t[13]=e[13]+n[13],t[14]=e[14]+n[14],t[15]=e[15]+n[15],t}function Gi(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t[4]=e[4]-n[4],t[5]=e[5]-n[5],t[6]=e[6]-n[6],t[7]=e[7]-n[7],t[8]=e[8]-n[8],t[9]=e[9]-n[9],t[10]=e[10]-n[10],t[11]=e[11]-n[11],t[12]=e[12]-n[12],t[13]=e[13]-n[13],t[14]=e[14]-n[14],t[15]=e[15]-n[15],t}function bc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*n,t[5]=e[5]*n,t[6]=e[6]*n,t[7]=e[7]*n,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=e[11]*n,t[12]=e[12]*n,t[13]=e[13]*n,t[14]=e[14]*n,t[15]=e[15]*n,t}function _c(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t[3]=e[3]+n[3]*r,t[4]=e[4]+n[4]*r,t[5]=e[5]+n[5]*r,t[6]=e[6]+n[6]*r,t[7]=e[7]+n[7]*r,t[8]=e[8]+n[8]*r,t[9]=e[9]+n[9]*r,t[10]=e[10]+n[10]*r,t[11]=e[11]+n[11]*r,t[12]=e[12]+n[12]*r,t[13]=e[13]+n[13]*r,t[14]=e[14]+n[14]*r,t[15]=e[15]+n[15]*r,t}function vc(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function xc(t,e){let n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],a=t[5],c=t[6],l=t[7],f=t[8],u=t[9],p=t[10],d=t[11],h=t[12],g=t[13],m=t[14],_=t[15],S=e[0],y=e[1],v=e[2],x=e[3],M=e[4],I=e[5],L=e[6],P=e[7],E=e[8],O=e[9],w=e[10],T=e[11],C=e[12],z=e[13],H=e[14],W=e[15];return Math.abs(n-S)<=1e-6*Math.max(1,Math.abs(n),Math.abs(S))&&Math.abs(r-y)<=1e-6*Math.max(1,Math.abs(r),Math.abs(y))&&Math.abs(i-v)<=1e-6*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(o-x)<=1e-6*Math.max(1,Math.abs(o),Math.abs(x))&&Math.abs(s-M)<=1e-6*Math.max(1,Math.abs(s),Math.abs(M))&&Math.abs(a-I)<=1e-6*Math.max(1,Math.abs(a),Math.abs(I))&&Math.abs(c-L)<=1e-6*Math.max(1,Math.abs(c),Math.abs(L))&&Math.abs(l-P)<=1e-6*Math.max(1,Math.abs(l),Math.abs(P))&&Math.abs(f-E)<=1e-6*Math.max(1,Math.abs(f),Math.abs(E))&&Math.abs(u-O)<=1e-6*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(p-w)<=1e-6*Math.max(1,Math.abs(p),Math.abs(w))&&Math.abs(d-T)<=1e-6*Math.max(1,Math.abs(d),Math.abs(T))&&Math.abs(h-C)<=1e-6*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(g-z)<=1e-6*Math.max(1,Math.abs(g),Math.abs(z))&&Math.abs(m-H)<=1e-6*Math.max(1,Math.abs(m),Math.abs(H))&&Math.abs(_-W)<=1e-6*Math.max(1,Math.abs(_),Math.abs(W))}var Sc=Xe;var yc=Gi;var Ki={};w(Ki,{add:()=>Lc,angle:()=>$c,ceil:()=>Rc,clone:()=>Mc,copy:()=>Ec,create:()=>$i,cross:()=>Dc,dist:()=>Jc,distance:()=>qi,div:()=>Kc,divide:()=>ji,dot:()=>Vc,equals:()=>qc,exactEquals:()=>jc,floor:()=>wc,forEach:()=>tl,fromValues:()=>Ac,inverse:()=>Uc,len:()=>Yc,length:()=>Xi,lerp:()=>kc,max:()=>Tc,min:()=>Cc,mul:()=>Zc,multiply:()=>Wi,negate:()=>Oc,normalize:()=>Fc,random:()=>Gc,rotate:()=>zc,round:()=>Pc,scale:()=>Nc,scaleAndAdd:()=>Bc,set:()=>Ic,sqrDist:()=>Qc,sqrLen:()=>el,squaredDistance:()=>Yi,squaredLength:()=>Zi,str:()=>Wc,sub:()=>Xc,subtract:()=>Hi,transformMat2:()=>zn,transformMat2d:()=>$n,transformMat3:()=>Ze,transformMat4:()=>Ke,zero:()=>Hc});function $i(){let t=new F(2);return F!=Float32Array&&(t[0]=0,t[1]=0),t}function Mc(t){let e=new F(2);return e[0]=t[0],e[1]=t[1],e}function Ac(t,e){let n=new F(2);return n[0]=t,n[1]=e,n}function Ec(t,e){return t[0]=e[0],t[1]=e[1],t}function Ic(t,e,n){return t[0]=e,t[1]=n,t}function Lc(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t}function Hi(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t}function Wi(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t}function ji(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t}function Rc(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t}function wc(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t}function Cc(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t}function Tc(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t}function Pc(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t}function Nc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t}function Bc(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t}function qi(t,e){let n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)}function Yi(t,e){let n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function Xi(t){let e=t[0],n=t[1];return Math.sqrt(e*e+n*n)}function Zi(t){let e=t[0],n=t[1];return e*e+n*n}function Oc(t,e){return t[0]=-e[0],t[1]=-e[1],t}function Uc(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function Fc(t,e){let n=e[0],r=e[1],i=n*n+r*r;return i>0&&(i=1/Math.sqrt(i)),t[0]=e[0]*i,t[1]=e[1]*i,t}function Vc(t,e){return t[0]*e[0]+t[1]*e[1]}function Dc(t,e,n){let r=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=r,t}function kc(t,e,n,r){let i=e[0],o=e[1];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t}function Gc(t,e){e=e===void 0?1:e;let n=K()*2*Math.PI;return t[0]=Math.cos(n)*e,t[1]=Math.sin(n)*e,t}function zn(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t}function $n(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i+n[4],t[1]=n[1]*r+n[3]*i+n[5],t}function Ze(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[3]*i+n[6],t[1]=n[1]*r+n[4]*i+n[7],t}function Ke(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[4]*i+n[12],t[1]=n[1]*r+n[5]*i+n[13],t}function zc(t,e,n,r){let i=e[0]-n[0],o=e[1]-n[1],s=Math.sin(r),a=Math.cos(r);return t[0]=i*a-o*s+n[0],t[1]=i*s+o*a+n[1],t}function $c(t,e){let n=t[0],r=t[1],i=e[0],o=e[1],s=Math.sqrt((n*n+r*r)*(i*i+o*o)),a=s&&(n*i+r*o)/s;return Math.acos(Math.min(Math.max(a,-1),1))}function Hc(t){return t[0]=0,t[1]=0,t}function Wc(t){return`vec2(${t[0]}, ${t[1]})`}function jc(t,e){return t[0]===e[0]&&t[1]===e[1]}function qc(t,e){let n=t[0],r=t[1],i=e[0],o=e[1];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))}var Yc=Xi;var Xc=Hi;var Zc=Wi;var Kc=ji;var Jc=qi;var Qc=Yi;var el=Zi;var tl=(function(){let t=$i();return function(e,n,r,i,o,s){let a,c;for(n||(n=2),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],o(t,t,s),e[a]=t[0],e[a+1]=t[1];return e}})();var Zn={};w(Zn,{add:()=>ol,angle:()=>Yn,bezier:()=>_l,ceil:()=>sl,clone:()=>nl,copy:()=>rl,create:()=>Lt,cross:()=>de,dist:()=>Ll,distance:()=>no,div:()=>Il,divide:()=>to,dot:()=>Je,equals:()=>Ml,exactEquals:()=>yl,floor:()=>al,forEach:()=>Cl,fromValues:()=>Rt,hermite:()=>bl,inverse:()=>hl,len:()=>Xn,length:()=>Ji,lerp:()=>ml,max:()=>ll,min:()=>cl,mul:()=>El,multiply:()=>eo,negate:()=>dl,normalize:()=>Hn,random:()=>vl,rotateX:()=>Wn,rotateY:()=>jn,rotateZ:()=>qn,round:()=>fl,scale:()=>ul,scaleAndAdd:()=>pl,set:()=>il,slerp:()=>gl,sqrDist:()=>Rl,sqrLen:()=>wl,squaredDistance:()=>ro,squaredLength:()=>io,str:()=>Sl,sub:()=>Al,subtract:()=>Qi,transformMat3:()=>Qe,transformMat4:()=>he,transformQuat:()=>et,zero:()=>xl});function Lt(){let t=new F(3);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function nl(t){let e=new F(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Ji(t){let e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function Rt(t,e,n){let r=new F(3);return r[0]=t,r[1]=e,r[2]=n,r}function rl(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function il(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function ol(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function Qi(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function eo(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function to(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t}function sl(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function al(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function cl(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t}function ll(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t}function fl(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t[2]=X(e[2]),t}function ul(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function pl(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t}function no(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function ro(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i}function io(t){let e=t[0],n=t[1],r=t[2];return e*e+n*n+r*r}function dl(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function hl(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function Hn(t,e){let n=e[0],r=e[1],i=e[2],o=n*n+r*r+i*i;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function Je(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function de(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],c=n[2];return t[0]=i*c-o*a,t[1]=o*s-r*c,t[2]=r*a-i*s,t}function ml(t,e,n,r){let i=e[0],o=e[1],s=e[2];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t}function gl(t,e,n,r){let i=Math.acos(Math.min(Math.max(Je(e,n),-1),1)),o=Math.sin(i),s=Math.sin((1-r)*i)/o,a=Math.sin(r*i)/o;return t[0]=s*e[0]+a*n[0],t[1]=s*e[1]+a*n[1],t[2]=s*e[2]+a*n[2],t}function bl(t,e,n,r,i,o){let s=o*o,a=s*(2*o-3)+1,c=s*(o-2)+o,l=s*(o-1),f=s*(3-2*o);return t[0]=e[0]*a+n[0]*c+r[0]*l+i[0]*f,t[1]=e[1]*a+n[1]*c+r[1]*l+i[1]*f,t[2]=e[2]*a+n[2]*c+r[2]*l+i[2]*f,t}function _l(t,e,n,r,i,o){let s=1-o,a=s*s,c=o*o,l=a*s,f=3*o*a,u=3*c*s,p=c*o;return t[0]=e[0]*l+n[0]*f+r[0]*u+i[0]*p,t[1]=e[1]*l+n[1]*f+r[1]*u+i[1]*p,t[2]=e[2]*l+n[2]*f+r[2]*u+i[2]*p,t}function vl(t,e){e=e===void 0?1:e;let n=K()*2*Math.PI,r=K()*2-1,i=Math.sqrt(1-r*r)*e;return t[0]=Math.cos(n)*i,t[1]=Math.sin(n)*i,t[2]=r*e,t}function he(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[3]*r+n[7]*i+n[11]*o+n[15];return s=s||1,t[0]=(n[0]*r+n[4]*i+n[8]*o+n[12])/s,t[1]=(n[1]*r+n[5]*i+n[9]*o+n[13])/s,t[2]=(n[2]*r+n[6]*i+n[10]*o+n[14])/s,t}function Qe(t,e,n){let r=e[0],i=e[1],o=e[2];return t[0]=r*n[0]+i*n[3]+o*n[6],t[1]=r*n[1]+i*n[4]+o*n[7],t[2]=r*n[2]+i*n[5]+o*n[8],t}function et(t,e,n){let r=n[0],i=n[1],o=n[2],s=n[3],a=e[0],c=e[1],l=e[2],f=i*l-o*c,u=o*a-r*l,p=r*c-i*a,d=i*p-o*u,h=o*f-r*p,g=r*u-i*f,m=s*2;return f*=m,u*=m,p*=m,d*=2,h*=2,g*=2,t[0]=a+f+d,t[1]=c+u+h,t[2]=l+p+g,t}function Wn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[0],o[1]=i[1]*Math.cos(r)-i[2]*Math.sin(r),o[2]=i[1]*Math.sin(r)+i[2]*Math.cos(r),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function jn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[2]*Math.sin(r)+i[0]*Math.cos(r),o[1]=i[1],o[2]=i[2]*Math.cos(r)-i[0]*Math.sin(r),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function qn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[0]*Math.cos(r)-i[1]*Math.sin(r),o[1]=i[0]*Math.sin(r)+i[1]*Math.cos(r),o[2]=i[2],t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function Yn(t,e){let n=t[0],r=t[1],i=t[2],o=e[0],s=e[1],a=e[2],c=Math.sqrt((n*n+r*r+i*i)*(o*o+s*s+a*a)),l=c&&Je(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function xl(t){return t[0]=0,t[1]=0,t[2]=0,t}function Sl(t){return`vec3(${t[0]}, ${t[1]}, ${t[2]})`}function yl(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Ml(t,e){let n=t[0],r=t[1],i=t[2],o=e[0],s=e[1],a=e[2];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-s)<=1e-6*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(i-a)<=1e-6*Math.max(1,Math.abs(i),Math.abs(a))}var Al=Qi;var El=eo;var Il=to;var Ll=no;var Rl=ro;var Xn=Ji;var wl=io;var Cl=(function(){let t=Lt();return function(e,n,r,i,o,s){let a,c;for(n||(n=3),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var ir={};w(ir,{add:()=>Kn,ceil:()=>Tl,clone:()=>so,copy:()=>co,create:()=>oo,cross:()=>Dl,dist:()=>ql,distance:()=>ho,div:()=>jl,divide:()=>po,dot:()=>er,equals:()=>$l,exactEquals:()=>go,floor:()=>Pl,forEach:()=>Kl,fromValues:()=>ao,inverse:()=>Vl,len:()=>Xl,length:()=>wt,lerp:()=>tr,max:()=>Bl,min:()=>Nl,mul:()=>Wl,multiply:()=>uo,negate:()=>Fl,normalize:()=>Qn,random:()=>kl,round:()=>Ol,scale:()=>Jn,scaleAndAdd:()=>Ul,set:()=>lo,sqrDist:()=>Yl,sqrLen:()=>Zl,squaredDistance:()=>mo,squaredLength:()=>Ct,str:()=>zl,sub:()=>Hl,subtract:()=>fo,transformMat4:()=>nr,transformQuat:()=>rr,zero:()=>Gl});function oo(){let t=new F(4);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function so(t){let e=new F(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function ao(t,e,n,r){let i=new F(4);return i[0]=t,i[1]=e,i[2]=n,i[3]=r,i}function co(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function lo(t,e,n,r,i){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t}function Kn(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t}function fo(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t}function uo(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t[3]=e[3]*n[3],t}function po(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t[3]=e[3]/n[3],t}function Tl(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t}function Pl(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t}function Nl(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t[3]=Math.min(e[3],n[3]),t}function Bl(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t[3]=Math.max(e[3],n[3]),t}function Ol(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t[2]=X(e[2]),t[3]=X(e[3]),t}function Jn(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t}function Ul(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t[3]=e[3]+n[3]*r,t}function ho(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return Math.sqrt(n*n+r*r+i*i+o*o)}function mo(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return n*n+r*r+i*i+o*o}function wt(t){let e=t[0],n=t[1],r=t[2],i=t[3];return Math.sqrt(e*e+n*n+r*r+i*i)}function Ct(t){let e=t[0],n=t[1],r=t[2],i=t[3];return e*e+n*n+r*r+i*i}function Fl(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}function Vl(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}function Qn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o;return s>0&&(s=1/Math.sqrt(s)),t[0]=n*s,t[1]=r*s,t[2]=i*s,t[3]=o*s,t}function er(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Dl(t,e,n,r){let i=n[0]*r[1]-n[1]*r[0],o=n[0]*r[2]-n[2]*r[0],s=n[0]*r[3]-n[3]*r[0],a=n[1]*r[2]-n[2]*r[1],c=n[1]*r[3]-n[3]*r[1],l=n[2]*r[3]-n[3]*r[2],f=e[0],u=e[1],p=e[2],d=e[3];return t[0]=u*l-p*c+d*a,t[1]=-(f*l)+p*s-d*o,t[2]=f*c-u*s+d*i,t[3]=-(f*a)+u*o-p*i,t}function tr(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t[3]=a+r*(n[3]-a),t}function kl(t,e){e=e===void 0?1:e;let n,r,i,o,s,a;do n=K()*2-1,r=K()*2-1,s=n*n+r*r;while(s>=1);do i=K()*2-1,o=K()*2-1,a=i*i+o*o;while(a>=1);let c=Math.sqrt((1-s)/a);return t[0]=e*n,t[1]=e*r,t[2]=e*i*c,t[3]=e*o*c,t}function nr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3];return t[0]=n[0]*r+n[4]*i+n[8]*o+n[12]*s,t[1]=n[1]*r+n[5]*i+n[9]*o+n[13]*s,t[2]=n[2]*r+n[6]*i+n[10]*o+n[14]*s,t[3]=n[3]*r+n[7]*i+n[11]*o+n[15]*s,t}function rr(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],c=n[2],l=n[3],f=l*r+a*o-c*i,u=l*i+c*r-s*o,p=l*o+s*i-a*r,d=-s*r-a*i-c*o;return t[0]=f*l+d*-s+u*-c-p*-a,t[1]=u*l+d*-a+p*-s-f*-c,t[2]=p*l+d*-c+f*-a-u*-s,t[3]=e[3],t}function Gl(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}function zl(t){return`vec4(${t[0]}, ${t[1]}, ${t[2]}, ${t[3]})`}function go(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function $l(t,e){let n=t[0],r=t[1],i=t[2],o=t[3],s=e[0],a=e[1],c=e[2],l=e[3];return Math.abs(n-s)<=1e-6*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(r-a)<=1e-6*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(i-c)<=1e-6*Math.max(1,Math.abs(i),Math.abs(c))&&Math.abs(o-l)<=1e-6*Math.max(1,Math.abs(o),Math.abs(l))}var Hl=fo;var Wl=uo;var jl=po;var ql=ho;var Yl=mo;var Xl=wt;var Zl=Ct;var Kl=(function(){let t=oo();return function(e,n,r,i,o,s){let a,c;for(n||(n=4),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}})();var _o=(function(t){return t[t.COL0ROW0=0]=`COL0ROW0`,t[t.COL0ROW1=1]=`COL0ROW1`,t[t.COL0ROW2=2]=`COL0ROW2`,t[t.COL0ROW3=3]=`COL0ROW3`,t[t.COL1ROW0=4]=`COL1ROW0`,t[t.COL1ROW1=5]=`COL1ROW1`,t[t.COL1ROW2=6]=`COL1ROW2`,t[t.COL1ROW3=7]=`COL1ROW3`,t[t.COL2ROW0=8]=`COL2ROW0`,t[t.COL2ROW1=9]=`COL2ROW1`,t[t.COL2ROW2=10]=`COL2ROW2`,t[t.COL2ROW3=11]=`COL2ROW3`,t[t.COL3ROW0=12]=`COL3ROW0`,t[t.COL3ROW1=13]=`COL3ROW1`,t[t.COL3ROW2=14]=`COL3ROW2`,t[t.COL3ROW3=15]=`COL3ROW3`,t})(_o||{});var Jl=45*Math.PI/180;var Ql=1;var or=.1;var sr=500;var ef=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);var U=class extends we{static get IDENTITY(){return nf()}static get ZERO(){return tf()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return _o}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this[4]=o,this[5]=s,this[6]=a,this[7]=c,this[8]=l,this[9]=f,this[10]=u,this[11]=p,this[12]=d,this[13]=h,this[14]=g,this[15]=m,this.check()}setRowMajor(e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return this[0]=e,this[1]=o,this[2]=l,this[3]=d,this[4]=n,this[5]=s,this[6]=f,this[7]=h,this[8]=r,this[9]=a,this[10]=u,this[11]=g,this[12]=i,this[13]=c,this[14]=p,this[15]=m,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(ef)}fromObject(e){return this.check()}fromQuaternion(e){return Fn(this,e),this.check()}frustum(e){let{left:n,right:r,bottom:i,top:o,near:s=or,far:a=sr}=e;return a===Infinity?rf(this,n,r,i,o,s):Vn(this,n,r,i,o,s,a),this.check()}lookAt(e){let{eye:n,center:r=[0,0,0],up:i=[0,1,0]}=e;return Gn(this,n,r,i),this.check()}ortho(e){let{left:n,right:r,bottom:i,top:o,near:s=or,far:a=sr}=e;return kn(this,n,r,i,o,s,a),this.check()}orthographic(e){let{fovy:n=Jl,aspect:r=Ql,focalDistance:i=1,near:o=or,far:s=sr}=e;bo(n);let a=n/2,c=i*Math.tan(a),l=c*r;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:o,far:s})}perspective(e){let{fovy:n=45*Math.PI/180,aspect:r=1,near:i=.1,far:o=500}=e;return bo(n),Dn(this,n,r,i,o),this.check()}determinant(){return Cn(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],o=1/r[1],s=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*o,e[2]=this[2]*s,e[3]=0,e[4]=this[4]*i,e[5]=this[5]*o,e[6]=this[6]*s,e[7]=0,e[8]=this[8]*i,e[9]=this[9]*o,e[10]=this[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],o=1/r[1],s=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*o,e[2]=this[2]*s,e[3]=this[4]*i,e[4]=this[5]*o,e[5]=this[6]*s,e[6]=this[8]*i,e[7]=this[9]*o,e[8]=this[10]*s,e}transpose(){return Rn(this,this),this.check()}invert(){return wn(this,this),this.check()}multiplyLeft(e){return Xe(this,e,this),this.check()}multiplyRight(e){return Xe(this,this,e),this.check()}rotateX(e){return Bn(this,this,e),this.check()}rotateY(e){return On(this,this,e),this.check()}rotateZ(e){return Un(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,n){return Nn(this,this,e,n),this.check()}scale(e){return Pn(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Tn(this,this,e),this.check()}transform(e,n){return e.length===4?(n=nr(n||[-0,-0,-0,-0],e,this),ce(n,4),n):this.transformAsPoint(e,n)}transformAsPoint(e,n){let{length:r}=e,i;switch(r){case 2:i=Ke(n||[-0,-0],e,this);break;case 3:i=he(n||[-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return ce(i,e.length),i}transformAsVector(e,n){let r;switch(e.length){case 2:r=At(n||[-0,-0],e,this);break;case 3:r=Et(n||[-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return ce(r,e.length),r}transformPoint(e,n){return this.transformAsPoint(e,n)}transformVector(e,n){return this.transformAsPoint(e,n)}transformDirection(e,n){return this.transformAsVector(e,n)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,n,r){return this.identity().translate([e,n,r])}};var Tt;var Pt;function tf(){return Tt||(Tt=new U([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Tt)),Tt}function nf(){return Pt||(Pt=new U,Object.freeze(Pt)),Pt}function bo(t){if(t>Math.PI*2)throw Error(`expected radians`)}function rf(t,e,n,r,i,o){let s=2*o/(n-e),a=2*o/(i-r),c=(n+e)/(n-e),l=(i+r)/(i-r),f=-1,u=-1,p=-2*o;return t[0]=s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=c,t[9]=l,t[10]=f,t[11]=u,t[12]=0,t[13]=0,t[14]=p,t[15]=0,t}function Nt(t,e){if(!t)throw new Error(`math.gl assertion ${e}`)}var le=class extends ae{get x(){return this[0]}set x(e){this[0]=N(e)}get y(){return this[1]}set y(e){this[1]=N(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*this[n];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let n=0;for(let r=0;r<this.ELEMENTS;++r){let i=this[r]-e[r];n+=i*i}return N(n)}dot(e){let n=0;for(let r=0;r<this.ELEMENTS;++r)n+=this[r]*e[r];return N(n)}normalize(){let e=this.magnitude();if(e!==0)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e;return this.check()}multiply(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]*=n[r];return this.check()}divide(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]/=n[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return Nt(e>=0&&e<this.ELEMENTS,`index is out of range`),N(this[e])}setComponent(e,n){return Nt(e>=0&&e<this.ELEMENTS,`index is out of range`),this[e]=n,this.check()}addVectors(e,n){return this.copy(e).add(n)}subVectors(e,n){return this.copy(e).subtract(n)}multiplyVectors(e,n){return this.copy(e).multiply(n)}addScaledVector(e,n){return this.add(new this.constructor(e).multiplyScalar(n))}};var ar=class extends le{constructor(e=0,n=0){super(2),q(e)&&arguments.length===1?this.copy(e):(V.debug&&(N(e),N(n)),this[0]=e,this[1]=n)}set(e,n){return this[0]=e,this[1]=n,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y)),this[0]=e.x,this[1]=e.y,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e}get ELEMENTS(){return 2}horizontalAngle(){return Math.atan2(this.y,this.x)}verticalAngle(){return Math.atan2(this.x,this.y)}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return Ke(this,this,e),this.check()}transformAsVector(e){return At(this,this,e),this.check()}transformByMatrix3(e){return Ze(this,this,e),this.check()}transformByMatrix2x3(e){return $n(this,this,e),this.check()}transformByMatrix2(e){return zn(this,this,e),this.check()}};var cr=[0,0,0];var Bt;var Z=class t extends le{static get ZERO(){return Bt||(Bt=new t(0,0,0),Object.freeze(Bt)),Bt}constructor(e=0,n=0,r=0){super(-0,-0,-0),arguments.length===1&&q(e)?this.copy(e):(V.debug&&(N(e),N(n),N(r)),this[0]=e,this[1]=n,this[2]=r)}set(e,n,r){return this[0]=e,this[1]=n,this[2]=r,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y),N(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=N(e)}angle(e){return Yn(this,e)}cross(e){return de(this,this,e),this.check()}rotateX({radians:e,origin:n=cr}){return Wn(this,this,n,e),this.check()}rotateY({radians:e,origin:n=cr}){return jn(this,this,n,e),this.check()}rotateZ({radians:e,origin:n=cr}){return qn(this,this,n,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return he(this,this,e),this.check()}transformAsVector(e){return Et(this,this,e),this.check()}transformByMatrix3(e){return Qe(this,this,e),this.check()}transformByMatrix2(e){return Bi(this,this,e),this.check()}transformByQuaternion(e){return et(this,this,e),this.check()}};var Ot;var Ut=class t extends le{static get ZERO(){return Ot||(Ot=new t(0,0,0,0),Object.freeze(Ot)),Ot}constructor(e=0,n=0,r=0,i=0){super(-0,-0,-0,-0),q(e)&&arguments.length===1?this.copy(e):(V.debug&&(N(e),N(n),N(r),N(i)),this[0]=e,this[1]=n,this[2]=r,this[3]=i)}set(e,n,r,i){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y),N(e.z),N(e.w)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e.w=this[3],e}get ELEMENTS(){return 4}get z(){return this[2]}set z(e){this[2]=N(e)}get w(){return this[3]}set w(e){this[3]=N(e)}transform(e){return he(this,this,e),this.check()}transformByMatrix3(e){return It(this,this,e),this.check()}transformByMatrix2(e){return Oi(this,this,e),this.check()}transformByQuaternion(e){return et(this,this,e),this.check()}applyMatrix4(e){return e.transform(this,this),this}};function vo(){let t=new F(9);return F!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function xo(t,e){if(t===e){let n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t}function So(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=f*s-a*l,p=-f*o+a*c,d=l*o-s*c,h=n*u+r*p+i*d;return h?(h=1/h,t[0]=u*h,t[1]=(-f*r+i*l)*h,t[2]=(a*r-i*s)*h,t[3]=p*h,t[4]=(f*n-i*c)*h,t[5]=(-a*n+i*o)*h,t[6]=d*h,t[7]=(-l*n+r*c)*h,t[8]=(s*n-r*o)*h,t):null}function yo(t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8];return e*(l*o-s*c)+n*(-l*i+s*a)+r*(c*i-o*a)}function lr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=n[0],d=n[1],h=n[2],g=n[3],m=n[4],_=n[5],S=n[6],y=n[7],v=n[8];return t[0]=p*r+d*s+h*l,t[1]=p*i+d*a+h*f,t[2]=p*o+d*c+h*u,t[3]=g*r+m*s+_*l,t[4]=g*i+m*a+_*f,t[5]=g*o+m*c+_*u,t[6]=S*r+y*s+v*l,t[7]=S*i+y*a+v*f,t[8]=S*o+y*c+v*u,t}function Mo(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=n[0],d=n[1];return t[0]=r,t[1]=i,t[2]=o,t[3]=s,t[4]=a,t[5]=c,t[6]=p*r+d*s+l,t[7]=p*i+d*a+f,t[8]=p*o+d*c+u,t}function Ao(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=Math.sin(n),d=Math.cos(n);return t[0]=d*r+p*s,t[1]=d*i+p*a,t[2]=d*o+p*c,t[3]=d*s-p*r,t[4]=d*a-p*i,t[5]=d*c-p*o,t[6]=l,t[7]=f,t[8]=u,t}function fr(t,e,n){let r=n[0],i=n[1];return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function Eo(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n+n,a=r+r,c=i+i,l=n*s,f=r*s,u=r*a,p=i*s,d=i*a,h=i*c,g=o*s,m=o*a,_=o*c;return t[0]=1-u-h,t[3]=f-_,t[6]=p+m,t[1]=f+_,t[4]=1-l-h,t[7]=d-g,t[2]=p-m,t[5]=d+g,t[8]=1-l-u,t}var Lo=(function(t){return t[t.COL0ROW0=0]=`COL0ROW0`,t[t.COL0ROW1=1]=`COL0ROW1`,t[t.COL0ROW2=2]=`COL0ROW2`,t[t.COL1ROW0=3]=`COL1ROW0`,t[t.COL1ROW1=4]=`COL1ROW1`,t[t.COL1ROW2=5]=`COL1ROW2`,t[t.COL2ROW0=6]=`COL2ROW0`,t[t.COL2ROW1=7]=`COL2ROW1`,t[t.COL2ROW2=8]=`COL2ROW2`,t})(Lo||{});var of=Object.freeze([1,0,0,0,1,0,0,0,1]);var tt=class extends we{static get IDENTITY(){return af()}static get ZERO(){return sf()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return Lo}constructor(e,...n){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):n.length>0?this.copy([e,...n]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(of)}fromObject(e){return this.check()}fromQuaternion(e){return Eo(this,e),this.check()}set(e,n,r,i,o,s,a,c,l){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this[4]=o,this[5]=s,this[6]=a,this[7]=c,this[8]=l,this.check()}setRowMajor(e,n,r,i,o,s,a,c,l){return this[0]=e,this[1]=i,this[2]=a,this[3]=n,this[4]=o,this[5]=c,this[6]=r,this[7]=s,this[8]=l,this.check()}determinant(){return yo(this)}transpose(){return xo(this,this),this.check()}invert(){return So(this,this),this.check()}multiplyLeft(e){return lr(this,e,this),this.check()}multiplyRight(e){return lr(this,this,e),this.check()}rotate(e){return Ao(this,this,e),this.check()}scale(e){return Array.isArray(e)?fr(this,this,e):fr(this,this,[e,e]),this.check()}translate(e){return Mo(this,this,e),this.check()}transform(e,n){let r;switch(e.length){case 2:r=Ze(n||[-0,-0],e,this);break;case 3:r=Qe(n||[-0,-0,-0],e,this);break;case 4:r=It(n||[-0,-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return ce(r,e.length),r}transformVector(e,n){return this.transform(e,n)}transformVector2(e,n){return this.transform(e,n)}transformVector3(e,n){return this.transform(e,n)}};var Ft;var Vt=null;function sf(){return Ft||(Ft=new tt([0,0,0,0,0,0,0,0,0]),Object.freeze(Ft)),Ft}function af(){return Vt||(Vt=new tt,Object.freeze(Vt)),Vt}function Ro(){let t=new F(4);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function wo(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function ur(t,e,n){n=n*.5;let r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t}function pr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=n[0],c=n[1],l=n[2],f=n[3];return t[0]=r*f+s*a+i*l-o*c,t[1]=i*f+s*c+o*a-r*l,t[2]=o*f+s*l+r*c-i*a,t[3]=s*f-r*a-i*c-o*l,t}function Co(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+s*a,t[1]=i*c+o*a,t[2]=o*c-i*a,t[3]=s*c-r*a,t}function To(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c-o*a,t[1]=i*c+s*a,t[2]=o*c+r*a,t[3]=s*c-i*a,t}function Po(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+i*a,t[1]=i*c-r*a,t[2]=o*c+s*a,t[3]=s*c-o*a,t}function No(t,e){let n=e[0],r=e[1],i=e[2];return t[0]=n,t[1]=r,t[2]=i,t[3]=Math.sqrt(Math.abs(1-n*n-r*r-i*i)),t}function nt(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3],c=n[0],l=n[1],f=n[2],u=n[3],p,d,h,g,m;return p=i*c+o*l+s*f+a*u,p<0&&(p=-p,c=-c,l=-l,f=-f,u=-u),1-p>1e-6?(d=Math.acos(p),m=Math.sin(d),h=Math.sin((1-r)*d)/m,g=Math.sin(r*d)/m):(h=1-r,g=r),t[0]=h*i+g*c,t[1]=h*o+g*l,t[2]=h*s+g*f,t[3]=h*a+g*u,t}function Bo(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o,a=s?1/s:0;return t[0]=-n*a,t[1]=-r*a,t[2]=-i*a,t[3]=o*a,t}function Oo(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function dr(t,e){let n=e[0]+e[4]+e[8],r;if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[5]-e[7])*r,t[1]=(e[6]-e[2])*r,t[2]=(e[1]-e[3])*r;else{let i=0;e[4]>e[0]&&(i=1),e[8]>e[i*3+i]&&(i=2);let o=(i+1)%3,s=(i+2)%3;r=Math.sqrt(e[i*3+i]-e[o*3+o]-e[s*3+s]+1),t[i]=.5*r,r=.5/r,t[3]=(e[o*3+s]-e[s*3+o])*r,t[o]=(e[o*3+i]+e[i*3+o])*r,t[s]=(e[s*3+i]+e[i*3+s])*r}return t}var Uo=Kn;var Fo=Jn;var Vo=er;var Do=tr;var ko=wt;var Go=Ct;var zo=Qn;var $o=(function(){let t=Lt(),e=Rt(1,0,0),n=Rt(0,1,0);return function(r,i,o){let s=Je(i,o);return s<-.999999?(de(t,e,i),Xn(t)<1e-6&&de(t,n,i),Hn(t,t),ur(r,t,Math.PI),r):s>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(de(t,i,o),r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=1+s,zo(r,r))}})();(function(){let t=Ro(),e=Ro();return function(n,r,i,o,s,a){return nt(t,r,s,a),nt(e,i,o,a),nt(n,t,e,2*a*(1-a)),n}})();(function(){let t=vo();return function(e,n,r,i){return t[0]=r[0],t[3]=r[1],t[6]=r[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],zo(e,dr(e,t))}})();var lf=[0,0,0,1];var hr=class extends ae{constructor(e=0,n=0,r=0,i=1){super(-0,-0,-0,-0),Array.isArray(e)&&arguments.length===1?this.copy(e):this.set(e,n,r,i)}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}set(e,n,r,i){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this.check()}fromObject(e){return this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this.check()}fromMatrix3(e){return dr(this,e),this.check()}fromAxisRotation(e,n){return ur(this,e,n),this.check()}identity(){return wo(this),this.check()}setAxisAngle(e,n){return this.fromAxisRotation(e,n)}get ELEMENTS(){return 4}get x(){return this[0]}set x(e){this[0]=N(e)}get y(){return this[1]}set y(e){this[1]=N(e)}get z(){return this[2]}set z(e){this[2]=N(e)}get w(){return this[3]}set w(e){this[3]=N(e)}len(){return ko(this)}lengthSquared(){return Go(this)}dot(e){return Vo(this,e)}rotationTo(e,n){return $o(this,e,n),this.check()}add(e){return Uo(this,this,e),this.check()}calculateW(){return No(this,this),this.check()}conjugate(){return Oo(this,this),this.check()}invert(){return Bo(this,this),this.check()}lerp(e,n,r){return r===void 0?this.lerp(this,e,n):(Do(this,e,n,r),this.check())}multiplyRight(e){return pr(this,this,e),this.check()}multiplyLeft(e){return pr(this,e,this),this.check()}normalize(){let e=this.len(),n=e>0?1/e:0;return this[0]=this[0]*n,this[1]=this[1]*n,this[2]=this[2]*n,this[3]=this[3]*n,e===0&&(this[3]=1),this.check()}rotateX(e){return Co(this,this,e),this.check()}rotateY(e){return To(this,this,e),this.check()}rotateZ(e){return Po(this,this,e),this.check()}scale(e){return Fo(this,this,e),this.check()}slerp(e,n,r){let i,o,s;switch(arguments.length){case 1:({start:i=lf,target:o,ratio:s}=e);break;case 2:i=this,o=e,s=n;break;default:i=e,o=n,s=r}return nt(this,i,o,s),this.check()}transformVector4(e,n=new Ut){return rr(n,e,this),ce(n,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(e,n){return this.setAxisAngle(e,n)}premultiply(e){return this.multiplyLeft(e)}multiply(e){return this.multiplyRight(e)}};var Ho={};w(Ho,{EPSILON1:()=>ff,EPSILON10:()=>vf,EPSILON11:()=>xf,EPSILON12:()=>Sf,EPSILON13:()=>yf,EPSILON14:()=>Mf,EPSILON15:()=>Af,EPSILON16:()=>Ef,EPSILON17:()=>If,EPSILON18:()=>Lf,EPSILON19:()=>Rf,EPSILON2:()=>uf,EPSILON20:()=>wf,EPSILON3:()=>pf,EPSILON4:()=>df,EPSILON5:()=>hf,EPSILON6:()=>mf,EPSILON7:()=>gf,EPSILON8:()=>bf,EPSILON9:()=>_f,PI_OVER_FOUR:()=>Tf,PI_OVER_SIX:()=>Pf,PI_OVER_TWO:()=>Cf,TWO_PI:()=>Nf});var ff=.1;var uf=.01;var pf=.001;var df=1e-4;var hf=1e-5;var mf=1e-6;var gf=1e-7;var bf=1e-8;var _f=1e-9;var vf=1e-10;var xf=1e-11;var Sf=1e-12;var yf=1e-13;var Mf=1e-14;var Af=1e-15;var Ef=1e-16;var If=1e-17;var Lf=1e-18;var Rf=1e-19;var wf=1e-20;var Cf=Math.PI/2;var Tf=Math.PI/4;var Pf=Math.PI/6;var Nf=Math.PI*2;var Uf={name:`fp32`,source:`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
1
+ import{i as u,n as s,o as w,t as r}from"./main.js";import{A as Ze$1,D as Y$1,I as f,M as ci$1,O as Ye,P as dt$1,S as U$1,T as Wt$1,Y as ut$1,Z as vi$1,_ as P,a as Ci,d as It$1,f as J$1,h as N$1,i as C,k as Yr$1,m as Ke$1,n as $e$1,o as Di$1,r as Bi$1,s as F$1,t as $,u as He,v as Qe$1,w as We,x as S,y as Qt$1}from"./chunk-CHv413eO.js";var Fa=1/Math.PI*180;var Va=1/180*Math.PI;globalThis.mathgl=globalThis.mathgl||{config:r({},{EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1})};var V=globalThis.mathgl.config;function In(t,{precision:e=V.precision}={}){return t=$a(t),`${parseFloat(t.toPrecision(e))}`}function q(t){return Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function ka(t){return Ni(t)}function Ga(t){return Bi(t)}function Ni(t,e){return Ln(t,n=>n*Va,e)}function Bi(t,e){return Ln(t,n=>n*Fa,e)}function za(t,e,n){return Ln(t,r=>Math.max(e,Math.min(n,r)))}function Oi(t,e,n){return q(t)?t.map((r,i)=>Oi(r,e[i],n)):n*e+(1-n)*t}function Mt(t,e,n){let r=V.EPSILON;n&&(V.EPSILON=n);try{if(t===e)return!0;if(q(t)&&q(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!Mt(t[i],e[i]))return!1;return!0}return t&&t.equals?t.equals(e):e&&e.equals?e.equals(t):typeof t==`number`&&typeof e==`number`?Math.abs(t-e)<=V.EPSILON*Math.max(1,Math.abs(t),Math.abs(e)):!1}finally{V.EPSILON=r}}function $a(t){return Math.round(t/V.EPSILON)*V.EPSILON}function Ha(t){return t.clone?t.clone():new Array(t.length)}function Ln(t,e,n){if(q(t)){let r=t;n=n||Ha(r);for(let i=0;i<n.length&&i<r.length;++i){let o=typeof t==`number`?t:t[i];n[i]=e(o,i,n)}return n}return e(t)}var ce=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+n];return this.check()}toArray(e=[],n=0){for(let r=0;r<this.ELEMENTS;++r)e[n+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:q(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(V)}formatString(e){let n=``;for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?`, `:``)+In(this[r],e);return`${e.printTypes?this.constructor.name:``}[${n}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!Mt(this[n],e[n]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==e[n])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,n,r){if(r===void 0)return this.lerp(this,e,n);for(let i=0;i<this.ELEMENTS;++i){let o=e[i],s=typeof n==`number`?n:n[i];this[i]=o+r*(s-o)}return this.check()}min(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(e[n],this[n]);return this.check()}max(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(e[n],this[n]);return this.check()}clamp(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),n[r]);return this.check()}add(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(e){if(typeof e==`number`)for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;else for(let n=0;n<this.ELEMENTS&&n<e.length;++n)this[n]*=e[n];return this.check()}multiplyByScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}check(){if(V.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)e=e&&Number.isFinite(this[n]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=e;return this.check()}addScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),n);return this.check()}get elements(){return this}};function Wa(t,e){if(t.length!==e)return!1;for(let n=0;n<t.length;++n)if(!Number.isFinite(t[n]))return!1;return!0}function N(t){if(!Number.isFinite(t))throw new Error(`Invalid number ${JSON.stringify(t)}`);return t}function le(t,e,n=``){if(V.debug&&!Wa(t,e))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return t}var we=class extends ce{toString(){let e=`[`;if(V.printRowMajor){e+=`row-major:`;for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+n]}`}else{e+=`column-major:`;for(let n=0;n<this.ELEMENTS;++n)e+=` ${this[n]}`}return e+=`]`,e}getElementIndex(e,n){return n*this.RANK+e}getElement(e,n){return this[n*this.RANK+e]}setElement(e,n,r){return this[n*this.RANK+e]=N(r),this}getColumn(e,n=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)n[i]=this[r+i];return n}setColumn(e,n){let r=e*this.RANK;for(let i=0;i<this.RANK;++i)this[r+i]=n[i];return this}};function At(t,e,n){let r=e[0],i=e[1],o=n[3]*r+n[7]*i||1;return t[0]=(n[0]*r+n[4]*i)/o,t[1]=(n[1]*r+n[5]*i)/o,t}function Et(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[3]*r+n[7]*i+n[11]*o||1;return t[0]=(n[0]*r+n[4]*i+n[8]*o)/s,t[1]=(n[1]*r+n[5]*i+n[9]*o)/s,t[2]=(n[2]*r+n[6]*i+n[10]*o)/s,t}function Ui(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t[2]=e[2],t}function Fi(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t[2]=e[2],t[3]=e[3],t}function It(t,e,n){let r=e[0],i=e[1],o=e[2];return t[0]=n[0]*r+n[3]*i+n[6]*o,t[1]=n[1]*r+n[4]*i+n[7]*o,t[2]=n[2]*r+n[5]*i+n[8]*o,t[3]=e[3],t}var Hi={};w(Hi,{add:()=>gc,adjoint:()=>Ka,clone:()=>qa,copy:()=>Ya,create:()=>ja,decompose:()=>ac,determinant:()=>Cn,equals:()=>xc,exactEquals:()=>vc,frob:()=>mc,fromQuat:()=>Fn,fromQuat2:()=>ic,fromRotation:()=>ec,fromRotationTranslation:()=>Di,fromRotationTranslationScale:()=>cc,fromRotationTranslationScaleOrigin:()=>lc,fromScaling:()=>Qa,fromTranslation:()=>Ja,fromValues:()=>Xa,fromXRotation:()=>tc,fromYRotation:()=>nc,fromZRotation:()=>rc,frustum:()=>Vn,getRotation:()=>sc,getScaling:()=>ki,getTranslation:()=>oc,identity:()=>Vi,invert:()=>wn,lookAt:()=>Gn,mul:()=>Sc,multiply:()=>Xe,multiplyScalar:()=>bc,multiplyScalarAndAdd:()=>_c,ortho:()=>kn,orthoNO:()=>zi,orthoZO:()=>pc,perspective:()=>Dn,perspectiveFromFieldOfView:()=>uc,perspectiveNO:()=>Gi,perspectiveZO:()=>fc,rotate:()=>Nn,rotateX:()=>Bn,rotateY:()=>On,rotateZ:()=>Un,scale:()=>Pn,set:()=>Za,str:()=>hc,sub:()=>yc,subtract:()=>$i,targetTo:()=>dc,translate:()=>Tn,transpose:()=>Rn});var F=typeof Float32Array<`u`?Float32Array:Array;var K=Math.random;function X(t){return t>=0?Math.round(t):t%.5===0?Math.floor(t):Math.round(t)}Math.PI/180;function ja(){let t=new F(16);return F!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function qa(t){let e=new F(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Ya(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Xa(t,e,n,r,i,o,s,a,c,l,f,u,p,d,h,g){let m=new F(16);return m[0]=t,m[1]=e,m[2]=n,m[3]=r,m[4]=i,m[5]=o,m[6]=s,m[7]=a,m[8]=c,m[9]=l,m[10]=f,m[11]=u,m[12]=p,m[13]=d,m[14]=h,m[15]=g,m}function Za(t,e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=o,t[5]=s,t[6]=a,t[7]=c,t[8]=l,t[9]=f,t[10]=u,t[11]=p,t[12]=d,t[13]=h,t[14]=g,t[15]=m,t}function Vi(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Rn(t,e){if(t===e){let n=e[1],r=e[2],i=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=n,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=o,t[11]=e[14],t[12]=i,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function wn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],p=e[10],d=e[11],h=e[12],g=e[13],m=e[14],v=e[15],S=n*a-r*s,y=n*c-i*s,_=n*l-o*s,x=r*c-i*a,M=r*l-o*a,I=i*l-o*c,L=f*g-u*h,P=f*m-p*h,E=f*v-d*h,O=u*m-p*g,w=u*v-d*g,T=p*v-d*m,C=S*T-y*w+_*O+x*E-M*P+I*L;return C?(C=1/C,t[0]=(a*T-c*w+l*O)*C,t[1]=(i*w-r*T-o*O)*C,t[2]=(g*I-m*M+v*x)*C,t[3]=(p*M-u*I-d*x)*C,t[4]=(c*E-s*T-l*P)*C,t[5]=(n*T-i*E+o*P)*C,t[6]=(m*_-h*I-v*y)*C,t[7]=(f*I-p*_+d*y)*C,t[8]=(s*w-a*E+l*L)*C,t[9]=(r*E-n*w-o*L)*C,t[10]=(h*M-g*_+v*S)*C,t[11]=(u*_-f*M-d*S)*C,t[12]=(a*P-s*O-c*L)*C,t[13]=(n*O-r*P+i*L)*C,t[14]=(g*y-h*x-m*S)*C,t[15]=(f*x-u*y+p*S)*C,t):null}function Ka(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],p=e[10],d=e[11],h=e[12],g=e[13],m=e[14],v=e[15],S=n*a-r*s,y=n*c-i*s,_=n*l-o*s,x=r*c-i*a,M=r*l-o*a,I=i*l-o*c,L=f*g-u*h,P=f*m-p*h,E=f*v-d*h,O=u*m-p*g,w=u*v-d*g,T=p*v-d*m;return t[0]=a*T-c*w+l*O,t[1]=i*w-r*T-o*O,t[2]=g*I-m*M+v*x,t[3]=p*M-u*I-d*x,t[4]=c*E-s*T-l*P,t[5]=n*T-i*E+o*P,t[6]=m*_-h*I-v*y,t[7]=f*I-p*_+d*y,t[8]=s*w-a*E+l*L,t[9]=r*E-n*w-o*L,t[10]=h*M-g*_+v*S,t[11]=u*_-f*M-d*S,t[12]=a*P-s*O-c*L,t[13]=n*O-r*P+i*L,t[14]=g*y-h*x-m*S,t[15]=f*x-u*y+p*S,t}function Cn(t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8],f=t[9],u=t[10],p=t[11],d=t[12],h=t[13],g=t[14],m=t[15],v=e*s-n*o,S=e*a-r*o,y=n*a-r*s,_=l*h-f*d,x=l*g-u*d,M=f*g-u*h,I=e*M-n*x+r*_,L=o*M-s*x+a*_,P=l*y-f*S+u*v,E=d*y-h*S+g*v;return c*I-i*L+m*P-p*E}function Xe(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=e[9],d=e[10],h=e[11],g=e[12],m=e[13],v=e[14],S=e[15],y=n[0],_=n[1],x=n[2],M=n[3];return t[0]=y*r+_*a+x*u+M*g,t[1]=y*i+_*c+x*p+M*m,t[2]=y*o+_*l+x*d+M*v,t[3]=y*s+_*f+x*h+M*S,y=n[4],_=n[5],x=n[6],M=n[7],t[4]=y*r+_*a+x*u+M*g,t[5]=y*i+_*c+x*p+M*m,t[6]=y*o+_*l+x*d+M*v,t[7]=y*s+_*f+x*h+M*S,y=n[8],_=n[9],x=n[10],M=n[11],t[8]=y*r+_*a+x*u+M*g,t[9]=y*i+_*c+x*p+M*m,t[10]=y*o+_*l+x*d+M*v,t[11]=y*s+_*f+x*h+M*S,y=n[12],_=n[13],x=n[14],M=n[15],t[12]=y*r+_*a+x*u+M*g,t[13]=y*i+_*c+x*p+M*m,t[14]=y*o+_*l+x*d+M*v,t[15]=y*s+_*f+x*h+M*S,t}function Tn(t,e,n){let r=n[0],i=n[1],o=n[2],s,a,c,l,f,u,p,d,h,g,m,v;return e===t?(t[12]=e[0]*r+e[4]*i+e[8]*o+e[12],t[13]=e[1]*r+e[5]*i+e[9]*o+e[13],t[14]=e[2]*r+e[6]*i+e[10]*o+e[14],t[15]=e[3]*r+e[7]*i+e[11]*o+e[15]):(s=e[0],a=e[1],c=e[2],l=e[3],f=e[4],u=e[5],p=e[6],d=e[7],h=e[8],g=e[9],m=e[10],v=e[11],t[0]=s,t[1]=a,t[2]=c,t[3]=l,t[4]=f,t[5]=u,t[6]=p,t[7]=d,t[8]=h,t[9]=g,t[10]=m,t[11]=v,t[12]=s*r+f*i+h*o+e[12],t[13]=a*r+u*i+g*o+e[13],t[14]=c*r+p*i+m*o+e[14],t[15]=l*r+d*i+v*o+e[15]),t}function Pn(t,e,n){let r=n[0],i=n[1],o=n[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Nn(t,e,n,r){let i=r[0],o=r[1],s=r[2],a=Math.sqrt(i*i+o*o+s*s),c,l,f,u,p,d,h,g,m,v,S,y,_,x,M,I,L,P,E,O,w,T,C,z;return a<1e-6?null:(a=1/a,i*=a,o*=a,s*=a,l=Math.sin(n),c=Math.cos(n),f=1-c,u=e[0],p=e[1],d=e[2],h=e[3],g=e[4],m=e[5],v=e[6],S=e[7],y=e[8],_=e[9],x=e[10],M=e[11],I=i*i*f+c,L=o*i*f+s*l,P=s*i*f-o*l,E=i*o*f-s*l,O=o*o*f+c,w=s*o*f+i*l,T=i*s*f+o*l,C=o*s*f-i*l,z=s*s*f+c,t[0]=u*I+g*L+y*P,t[1]=p*I+m*L+_*P,t[2]=d*I+v*L+x*P,t[3]=h*I+S*L+M*P,t[4]=u*E+g*O+y*w,t[5]=p*E+m*O+_*w,t[6]=d*E+v*O+x*w,t[7]=h*E+S*O+M*w,t[8]=u*T+g*C+y*z,t[9]=p*T+m*C+_*z,t[10]=d*T+v*C+x*z,t[11]=h*T+S*C+M*z,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Bn(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[4],s=e[5],a=e[6],c=e[7],l=e[8],f=e[9],u=e[10],p=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=o*i+l*r,t[5]=s*i+f*r,t[6]=a*i+u*r,t[7]=c*i+p*r,t[8]=l*i-o*r,t[9]=f*i-s*r,t[10]=u*i-a*r,t[11]=p*i-c*r,t}function On(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],c=e[3],l=e[8],f=e[9],u=e[10],p=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i-l*r,t[1]=s*i-f*r,t[2]=a*i-u*r,t[3]=c*i-p*r,t[8]=o*r+l*i,t[9]=s*r+f*i,t[10]=a*r+u*i,t[11]=c*r+p*i,t}function Un(t,e,n){let r=Math.sin(n),i=Math.cos(n),o=e[0],s=e[1],a=e[2],c=e[3],l=e[4],f=e[5],u=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=o*i+l*r,t[1]=s*i+f*r,t[2]=a*i+u*r,t[3]=c*i+p*r,t[4]=l*i-o*r,t[5]=f*i-s*r,t[6]=u*i-a*r,t[7]=p*i-c*r,t}function Ja(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function Qa(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function ec(t,e,n){let r=n[0],i=n[1],o=n[2],s=Math.sqrt(r*r+i*i+o*o),a,c,l;return s<1e-6?null:(s=1/s,r*=s,i*=s,o*=s,c=Math.sin(e),a=Math.cos(e),l=1-a,t[0]=r*r*l+a,t[1]=i*r*l+o*c,t[2]=o*r*l-i*c,t[3]=0,t[4]=r*i*l-o*c,t[5]=i*i*l+a,t[6]=o*i*l+r*c,t[7]=0,t[8]=r*o*l+i*c,t[9]=i*o*l-r*c,t[10]=o*o*l+a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function tc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=r,t[6]=n,t[7]=0,t[8]=0,t[9]=-n,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function nc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=r,t[1]=0,t[2]=-n,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=n,t[9]=0,t[10]=r,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function rc(t,e){let n=Math.sin(e),r=Math.cos(e);return t[0]=r,t[1]=n,t[2]=0,t[3]=0,t[4]=-n,t[5]=r,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Di(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=r+r,c=i+i,l=o+o,f=r*a,u=r*c,p=r*l,d=i*c,h=i*l,g=o*l,m=s*a,v=s*c,S=s*l;return t[0]=1-(d+g),t[1]=u+S,t[2]=p-v,t[3]=0,t[4]=u-S,t[5]=1-(f+g),t[6]=h+m,t[7]=0,t[8]=p+v,t[9]=h-m,t[10]=1-(f+d),t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ic(t,e){let n=new F(3),r=-e[0],i=-e[1],o=-e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=r*r+i*i+o*o+s*s;return u>0?(n[0]=(a*s+f*r+c*o-l*i)*2/u,n[1]=(c*s+f*i+l*r-a*o)*2/u,n[2]=(l*s+f*o+a*i-c*r)*2/u):(n[0]=(a*s+f*r+c*o-l*i)*2,n[1]=(c*s+f*i+l*r-a*o)*2,n[2]=(l*s+f*o+a*i-c*r)*2),Di(t,e,n),t}function oc(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function ki(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],a=e[6],c=e[8],l=e[9],f=e[10];return t[0]=Math.sqrt(n*n+r*r+i*i),t[1]=Math.sqrt(o*o+s*s+a*a),t[2]=Math.sqrt(c*c+l*l+f*f),t}function sc(t,e){let n=new F(3);ki(n,e);let r=1/n[0],i=1/n[1],o=1/n[2],s=e[0]*r,a=e[1]*i,c=e[2]*o,l=e[4]*r,f=e[5]*i,u=e[6]*o,p=e[8]*r,d=e[9]*i,h=e[10]*o,g=s+f+h,m=0;return g>0?(m=Math.sqrt(g+1)*2,t[3]=.25*m,t[0]=(u-d)/m,t[1]=(p-c)/m,t[2]=(a-l)/m):s>f&&s>h?(m=Math.sqrt(1+s-f-h)*2,t[3]=(u-d)/m,t[0]=.25*m,t[1]=(a+l)/m,t[2]=(p+c)/m):f>h?(m=Math.sqrt(1+f-s-h)*2,t[3]=(p-c)/m,t[0]=(a+l)/m,t[1]=.25*m,t[2]=(u+d)/m):(m=Math.sqrt(1+h-s-f)*2,t[3]=(a-l)/m,t[0]=(p+c)/m,t[1]=(u+d)/m,t[2]=.25*m),t}function ac(t,e,n,r){e[0]=r[12],e[1]=r[13],e[2]=r[14];let i=r[0],o=r[1],s=r[2],a=r[4],c=r[5],l=r[6],f=r[8],u=r[9],p=r[10];n[0]=Math.sqrt(i*i+o*o+s*s),n[1]=Math.sqrt(a*a+c*c+l*l),n[2]=Math.sqrt(f*f+u*u+p*p);let d=1/n[0],h=1/n[1],g=1/n[2],m=i*d,v=o*h,S=s*g,y=a*d,_=c*h,x=l*g,M=f*d,I=u*h,L=p*g,P=m+_+L,E=0;return P>0?(E=Math.sqrt(P+1)*2,t[3]=.25*E,t[0]=(x-I)/E,t[1]=(M-S)/E,t[2]=(v-y)/E):m>_&&m>L?(E=Math.sqrt(1+m-_-L)*2,t[3]=(x-I)/E,t[0]=.25*E,t[1]=(v+y)/E,t[2]=(M+S)/E):_>L?(E=Math.sqrt(1+_-m-L)*2,t[3]=(M-S)/E,t[0]=(v+y)/E,t[1]=.25*E,t[2]=(x+I)/E):(E=Math.sqrt(1+L-m-_)*2,t[3]=(v-y)/E,t[0]=(M+S)/E,t[1]=(x+I)/E,t[2]=.25*E),t}function cc(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3],c=i+i,l=o+o,f=s+s,u=i*c,p=i*l,d=i*f,h=o*l,g=o*f,m=s*f,v=a*c,S=a*l,y=a*f,_=r[0],x=r[1],M=r[2];return t[0]=(1-(h+m))*_,t[1]=(p+y)*_,t[2]=(d-S)*_,t[3]=0,t[4]=(p-y)*x,t[5]=(1-(u+m))*x,t[6]=(g+v)*x,t[7]=0,t[8]=(d+S)*M,t[9]=(g-v)*M,t[10]=(1-(u+h))*M,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function lc(t,e,n,r,i){let o=e[0],s=e[1],a=e[2],c=e[3],l=o+o,f=s+s,u=a+a,p=o*l,d=o*f,h=o*u,g=s*f,m=s*u,v=a*u,S=c*l,y=c*f,_=c*u,x=r[0],M=r[1],I=r[2],L=i[0],P=i[1],E=i[2],O=(1-(g+v))*x,w=(d+_)*x,T=(h-y)*x,C=(d-_)*M,z=(1-(p+v))*M,H=(m+S)*M,W=(h+y)*I,He=(m-S)*I,Sn=(1-(p+g))*I;return t[0]=O,t[1]=w,t[2]=T,t[3]=0,t[4]=C,t[5]=z,t[6]=H,t[7]=0,t[8]=W,t[9]=He,t[10]=Sn,t[11]=0,t[12]=n[0]+L-(O*L+C*P+W*E),t[13]=n[1]+P-(w*L+z*P+He*E),t[14]=n[2]+E-(T*L+H*P+Sn*E),t[15]=1,t}function Fn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n+n,a=r+r,c=i+i,l=n*s,f=r*s,u=r*a,p=i*s,d=i*a,h=i*c,g=o*s,m=o*a,v=o*c;return t[0]=1-u-h,t[1]=f+v,t[2]=p-m,t[3]=0,t[4]=f-v,t[5]=1-l-h,t[6]=d+g,t[7]=0,t[8]=p+m,t[9]=d-g,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Vn(t,e,n,r,i,o,s){let a=1/(n-e),c=1/(i-r),l=1/(o-s);return t[0]=o*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o*2*c,t[6]=0,t[7]=0,t[8]=(n+e)*a,t[9]=(i+r)*c,t[10]=(s+o)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=s*o*2*l,t[15]=0,t}function Gi(t,e,n,r,i){let o=1/Math.tan(e/2);if(t[0]=o/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){let s=1/(r-i);t[10]=(i+r)*s,t[14]=2*i*r*s}else t[10]=-1,t[14]=-2*r;return t}var Dn=Gi;function fc(t,e,n,r,i){let o=1/Math.tan(e/2);if(t[0]=o/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,i!=null&&i!==1/0){let s=1/(r-i);t[10]=i*s,t[14]=i*r*s}else t[10]=-1,t[14]=-r;return t}function uc(t,e,n,r){let i=Math.tan(e.upDegrees*Math.PI/180),o=Math.tan(e.downDegrees*Math.PI/180),s=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),c=2/(s+a),l=2/(i+o);return t[0]=c,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=l,t[6]=0,t[7]=0,t[8]=-((s-a)*c*.5),t[9]=(i-o)*l*.5,t[10]=r/(n-r),t[11]=-1,t[12]=0,t[13]=0,t[14]=r*n/(n-r),t[15]=0,t}function zi(t,e,n,r,i,o,s){let a=1/(e-n),c=1/(r-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+n)*a,t[13]=(i+r)*c,t[14]=(s+o)*l,t[15]=1,t}var kn=zi;function pc(t,e,n,r,i,o,s){let a=1/(e-n),c=1/(r-i),l=1/(o-s);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=l,t[11]=0,t[12]=(e+n)*a,t[13]=(i+r)*c,t[14]=o*l,t[15]=1,t}function Gn(t,e,n,r){let i,o,s,a,c,l,f,u,p,d,h=e[0],g=e[1],m=e[2],v=r[0],S=r[1],y=r[2],_=n[0],x=n[1],M=n[2];return Math.abs(h-_)<1e-6&&Math.abs(g-x)<1e-6&&Math.abs(m-M)<1e-6?Vi(t):(u=h-_,p=g-x,d=m-M,i=1/Math.sqrt(u*u+p*p+d*d),u*=i,p*=i,d*=i,o=S*d-y*p,s=y*u-v*d,a=v*p-S*u,i=Math.sqrt(o*o+s*s+a*a),i?(i=1/i,o*=i,s*=i,a*=i):(o=0,s=0,a=0),c=p*a-d*s,l=d*o-u*a,f=u*s-p*o,i=Math.sqrt(c*c+l*l+f*f),i?(i=1/i,c*=i,l*=i,f*=i):(c=0,l=0,f=0),t[0]=o,t[1]=c,t[2]=u,t[3]=0,t[4]=s,t[5]=l,t[6]=p,t[7]=0,t[8]=a,t[9]=f,t[10]=d,t[11]=0,t[12]=-(o*h+s*g+a*m),t[13]=-(c*h+l*g+f*m),t[14]=-(u*h+p*g+d*m),t[15]=1,t)}function dc(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=r[0],c=r[1],l=r[2],f=i-n[0],u=o-n[1],p=s-n[2],d=f*f+u*u+p*p;d>0&&(d=1/Math.sqrt(d),f*=d,u*=d,p*=d);let h=c*p-l*u,g=l*f-a*p,m=a*u-c*f;return d=h*h+g*g+m*m,d>0&&(d=1/Math.sqrt(d),h*=d,g*=d,m*=d),t[0]=h,t[1]=g,t[2]=m,t[3]=0,t[4]=u*m-p*g,t[5]=p*h-f*m,t[6]=f*g-u*h,t[7]=0,t[8]=f,t[9]=u,t[10]=p,t[11]=0,t[12]=i,t[13]=o,t[14]=s,t[15]=1,t}function hc(t){return`mat4(${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}, ${t[4]}, ${t[5]}, ${t[6]}, ${t[7]}, ${t[8]}, ${t[9]}, ${t[10]}, ${t[11]}, ${t[12]}, ${t[13]}, ${t[14]}, ${t[15]})`}function mc(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]+t[3]*t[3]+t[4]*t[4]+t[5]*t[5]+t[6]*t[6]+t[7]*t[7]+t[8]*t[8]+t[9]*t[9]+t[10]*t[10]+t[11]*t[11]+t[12]*t[12]+t[13]*t[13]+t[14]*t[14]+t[15]*t[15])}function gc(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t[4]=e[4]+n[4],t[5]=e[5]+n[5],t[6]=e[6]+n[6],t[7]=e[7]+n[7],t[8]=e[8]+n[8],t[9]=e[9]+n[9],t[10]=e[10]+n[10],t[11]=e[11]+n[11],t[12]=e[12]+n[12],t[13]=e[13]+n[13],t[14]=e[14]+n[14],t[15]=e[15]+n[15],t}function $i(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t[4]=e[4]-n[4],t[5]=e[5]-n[5],t[6]=e[6]-n[6],t[7]=e[7]-n[7],t[8]=e[8]-n[8],t[9]=e[9]-n[9],t[10]=e[10]-n[10],t[11]=e[11]-n[11],t[12]=e[12]-n[12],t[13]=e[13]-n[13],t[14]=e[14]-n[14],t[15]=e[15]-n[15],t}function bc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*n,t[5]=e[5]*n,t[6]=e[6]*n,t[7]=e[7]*n,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=e[11]*n,t[12]=e[12]*n,t[13]=e[13]*n,t[14]=e[14]*n,t[15]=e[15]*n,t}function _c(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t[3]=e[3]+n[3]*r,t[4]=e[4]+n[4]*r,t[5]=e[5]+n[5]*r,t[6]=e[6]+n[6]*r,t[7]=e[7]+n[7]*r,t[8]=e[8]+n[8]*r,t[9]=e[9]+n[9]*r,t[10]=e[10]+n[10]*r,t[11]=e[11]+n[11]*r,t[12]=e[12]+n[12]*r,t[13]=e[13]+n[13]*r,t[14]=e[14]+n[14]*r,t[15]=e[15]+n[15]*r,t}function vc(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function xc(t,e){let n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],a=t[5],c=t[6],l=t[7],f=t[8],u=t[9],p=t[10],d=t[11],h=t[12],g=t[13],m=t[14],v=t[15],S=e[0],y=e[1],_=e[2],x=e[3],M=e[4],I=e[5],L=e[6],P=e[7],E=e[8],O=e[9],w=e[10],T=e[11],C=e[12],z=e[13],H=e[14],W=e[15];return Math.abs(n-S)<=1e-6*Math.max(1,Math.abs(n),Math.abs(S))&&Math.abs(r-y)<=1e-6*Math.max(1,Math.abs(r),Math.abs(y))&&Math.abs(i-_)<=1e-6*Math.max(1,Math.abs(i),Math.abs(_))&&Math.abs(o-x)<=1e-6*Math.max(1,Math.abs(o),Math.abs(x))&&Math.abs(s-M)<=1e-6*Math.max(1,Math.abs(s),Math.abs(M))&&Math.abs(a-I)<=1e-6*Math.max(1,Math.abs(a),Math.abs(I))&&Math.abs(c-L)<=1e-6*Math.max(1,Math.abs(c),Math.abs(L))&&Math.abs(l-P)<=1e-6*Math.max(1,Math.abs(l),Math.abs(P))&&Math.abs(f-E)<=1e-6*Math.max(1,Math.abs(f),Math.abs(E))&&Math.abs(u-O)<=1e-6*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(p-w)<=1e-6*Math.max(1,Math.abs(p),Math.abs(w))&&Math.abs(d-T)<=1e-6*Math.max(1,Math.abs(d),Math.abs(T))&&Math.abs(h-C)<=1e-6*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(g-z)<=1e-6*Math.max(1,Math.abs(g),Math.abs(z))&&Math.abs(m-H)<=1e-6*Math.max(1,Math.abs(m),Math.abs(H))&&Math.abs(v-W)<=1e-6*Math.max(1,Math.abs(v),Math.abs(W))}var Sc=Xe;var yc=$i;var Qi={};w(Qi,{add:()=>Lc,angle:()=>$c,ceil:()=>Rc,clone:()=>Mc,copy:()=>Ec,create:()=>Wi,cross:()=>Dc,dist:()=>Jc,distance:()=>Xi,div:()=>Kc,divide:()=>Yi,dot:()=>Vc,equals:()=>qc,exactEquals:()=>jc,floor:()=>wc,forEach:()=>tl,fromValues:()=>Ac,inverse:()=>Uc,len:()=>Yc,length:()=>Ki,lerp:()=>kc,max:()=>Tc,min:()=>Cc,mul:()=>Zc,multiply:()=>qi,negate:()=>Oc,normalize:()=>Fc,random:()=>Gc,rotate:()=>zc,round:()=>Pc,scale:()=>Nc,scaleAndAdd:()=>Bc,set:()=>Ic,sqrDist:()=>Qc,sqrLen:()=>el,squaredDistance:()=>Zi,squaredLength:()=>Ji,str:()=>Wc,sub:()=>Xc,subtract:()=>ji,transformMat2:()=>zn,transformMat2d:()=>$n,transformMat3:()=>Ze,transformMat4:()=>Ke,zero:()=>Hc});function Wi(){let t=new F(2);return F!=Float32Array&&(t[0]=0,t[1]=0),t}function Mc(t){let e=new F(2);return e[0]=t[0],e[1]=t[1],e}function Ac(t,e){let n=new F(2);return n[0]=t,n[1]=e,n}function Ec(t,e){return t[0]=e[0],t[1]=e[1],t}function Ic(t,e,n){return t[0]=e,t[1]=n,t}function Lc(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t}function ji(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t}function qi(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t}function Yi(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t}function Rc(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t}function wc(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t}function Cc(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t}function Tc(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t}function Pc(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t}function Nc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t}function Bc(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t}function Xi(t,e){let n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)}function Zi(t,e){let n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function Ki(t){let e=t[0],n=t[1];return Math.sqrt(e*e+n*n)}function Ji(t){let e=t[0],n=t[1];return e*e+n*n}function Oc(t,e){return t[0]=-e[0],t[1]=-e[1],t}function Uc(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function Fc(t,e){let n=e[0],r=e[1],i=n*n+r*r;return i>0&&(i=1/Math.sqrt(i)),t[0]=e[0]*i,t[1]=e[1]*i,t}function Vc(t,e){return t[0]*e[0]+t[1]*e[1]}function Dc(t,e,n){let r=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=r,t}function kc(t,e,n,r){let i=e[0],o=e[1];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t}function Gc(t,e){e=e===void 0?1:e;let n=K()*2*Math.PI;return t[0]=Math.cos(n)*e,t[1]=Math.sin(n)*e,t}function zn(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t}function $n(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i+n[4],t[1]=n[1]*r+n[3]*i+n[5],t}function Ze(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[3]*i+n[6],t[1]=n[1]*r+n[4]*i+n[7],t}function Ke(t,e,n){let r=e[0],i=e[1];return t[0]=n[0]*r+n[4]*i+n[12],t[1]=n[1]*r+n[5]*i+n[13],t}function zc(t,e,n,r){let i=e[0]-n[0],o=e[1]-n[1],s=Math.sin(r),a=Math.cos(r);return t[0]=i*a-o*s+n[0],t[1]=i*s+o*a+n[1],t}function $c(t,e){let n=t[0],r=t[1],i=e[0],o=e[1],s=Math.sqrt((n*n+r*r)*(i*i+o*o)),a=s&&(n*i+r*o)/s;return Math.acos(Math.min(Math.max(a,-1),1))}function Hc(t){return t[0]=0,t[1]=0,t}function Wc(t){return`vec2(${t[0]}, ${t[1]})`}function jc(t,e){return t[0]===e[0]&&t[1]===e[1]}function qc(t,e){let n=t[0],r=t[1],i=e[0],o=e[1];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))}var Yc=Ki;var Xc=ji;var Zc=qi;var Kc=Yi;var Jc=Xi;var Qc=Zi;var el=Ji;var tl=(function(){let t=Wi();return function(e,n,r,i,o,s){let a,c;for(n||(n=2),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],o(t,t,s),e[a]=t[0],e[a+1]=t[1];return e}})();var Zn={};w(Zn,{add:()=>ol,angle:()=>Yn,bezier:()=>_l,ceil:()=>sl,clone:()=>nl,copy:()=>rl,create:()=>Lt,cross:()=>de,dist:()=>Ll,distance:()=>io,div:()=>Il,divide:()=>ro,dot:()=>Je,equals:()=>Ml,exactEquals:()=>yl,floor:()=>al,forEach:()=>Cl,fromValues:()=>Rt,hermite:()=>bl,inverse:()=>hl,len:()=>Xn,length:()=>eo,lerp:()=>ml,max:()=>ll,min:()=>cl,mul:()=>El,multiply:()=>no,negate:()=>dl,normalize:()=>Hn,random:()=>vl,rotateX:()=>Wn,rotateY:()=>jn,rotateZ:()=>qn,round:()=>fl,scale:()=>ul,scaleAndAdd:()=>pl,set:()=>il,slerp:()=>gl,sqrDist:()=>Rl,sqrLen:()=>wl,squaredDistance:()=>oo,squaredLength:()=>so,str:()=>Sl,sub:()=>Al,subtract:()=>to,transformMat3:()=>Qe,transformMat4:()=>he,transformQuat:()=>et,zero:()=>xl});function Lt(){let t=new F(3);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function nl(t){let e=new F(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function eo(t){let e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function Rt(t,e,n){let r=new F(3);return r[0]=t,r[1]=e,r[2]=n,r}function rl(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function il(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function ol(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function to(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function no(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function ro(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t}function sl(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function al(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function cl(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t}function ll(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t}function fl(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t[2]=X(e[2]),t}function ul(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function pl(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t}function io(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function oo(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return n*n+r*r+i*i}function so(t){let e=t[0],n=t[1],r=t[2];return e*e+n*n+r*r}function dl(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function hl(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function Hn(t,e){let n=e[0],r=e[1],i=e[2],o=n*n+r*r+i*i;return o>0&&(o=1/Math.sqrt(o)),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t}function Je(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function de(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],c=n[2];return t[0]=i*c-o*a,t[1]=o*s-r*c,t[2]=r*a-i*s,t}function ml(t,e,n,r){let i=e[0],o=e[1],s=e[2];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t}function gl(t,e,n,r){let i=Math.acos(Math.min(Math.max(Je(e,n),-1),1)),o=Math.sin(i),s=Math.sin((1-r)*i)/o,a=Math.sin(r*i)/o;return t[0]=s*e[0]+a*n[0],t[1]=s*e[1]+a*n[1],t[2]=s*e[2]+a*n[2],t}function bl(t,e,n,r,i,o){let s=o*o,a=s*(2*o-3)+1,c=s*(o-2)+o,l=s*(o-1),f=s*(3-2*o);return t[0]=e[0]*a+n[0]*c+r[0]*l+i[0]*f,t[1]=e[1]*a+n[1]*c+r[1]*l+i[1]*f,t[2]=e[2]*a+n[2]*c+r[2]*l+i[2]*f,t}function _l(t,e,n,r,i,o){let s=1-o,a=s*s,c=o*o,l=a*s,f=3*o*a,u=3*c*s,p=c*o;return t[0]=e[0]*l+n[0]*f+r[0]*u+i[0]*p,t[1]=e[1]*l+n[1]*f+r[1]*u+i[1]*p,t[2]=e[2]*l+n[2]*f+r[2]*u+i[2]*p,t}function vl(t,e){e=e===void 0?1:e;let n=K()*2*Math.PI,r=K()*2-1,i=Math.sqrt(1-r*r)*e;return t[0]=Math.cos(n)*i,t[1]=Math.sin(n)*i,t[2]=r*e,t}function he(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[3]*r+n[7]*i+n[11]*o+n[15];return s=s||1,t[0]=(n[0]*r+n[4]*i+n[8]*o+n[12])/s,t[1]=(n[1]*r+n[5]*i+n[9]*o+n[13])/s,t[2]=(n[2]*r+n[6]*i+n[10]*o+n[14])/s,t}function Qe(t,e,n){let r=e[0],i=e[1],o=e[2];return t[0]=r*n[0]+i*n[3]+o*n[6],t[1]=r*n[1]+i*n[4]+o*n[7],t[2]=r*n[2]+i*n[5]+o*n[8],t}function et(t,e,n){let r=n[0],i=n[1],o=n[2],s=n[3],a=e[0],c=e[1],l=e[2],f=i*l-o*c,u=o*a-r*l,p=r*c-i*a,d=i*p-o*u,h=o*f-r*p,g=r*u-i*f,m=s*2;return f*=m,u*=m,p*=m,d*=2,h*=2,g*=2,t[0]=a+f+d,t[1]=c+u+h,t[2]=l+p+g,t}function Wn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[0],o[1]=i[1]*Math.cos(r)-i[2]*Math.sin(r),o[2]=i[1]*Math.sin(r)+i[2]*Math.cos(r),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function jn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[2]*Math.sin(r)+i[0]*Math.cos(r),o[1]=i[1],o[2]=i[2]*Math.cos(r)-i[0]*Math.sin(r),t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function qn(t,e,n,r){let i=[],o=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],o[0]=i[0]*Math.cos(r)-i[1]*Math.sin(r),o[1]=i[0]*Math.sin(r)+i[1]*Math.cos(r),o[2]=i[2],t[0]=o[0]+n[0],t[1]=o[1]+n[1],t[2]=o[2]+n[2],t}function Yn(t,e){let n=t[0],r=t[1],i=t[2],o=e[0],s=e[1],a=e[2],c=Math.sqrt((n*n+r*r+i*i)*(o*o+s*s+a*a)),l=c&&Je(t,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}function xl(t){return t[0]=0,t[1]=0,t[2]=0,t}function Sl(t){return`vec3(${t[0]}, ${t[1]}, ${t[2]})`}function yl(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Ml(t,e){let n=t[0],r=t[1],i=t[2],o=e[0],s=e[1],a=e[2];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-s)<=1e-6*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(i-a)<=1e-6*Math.max(1,Math.abs(i),Math.abs(a))}var Al=to;var El=no;var Il=ro;var Ll=io;var Rl=oo;var Xn=eo;var wl=so;var Cl=(function(){let t=Lt();return function(e,n,r,i,o,s){let a,c;for(n||(n=3),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}})();var ir={};w(ir,{add:()=>Kn,ceil:()=>Tl,clone:()=>co,copy:()=>fo,create:()=>ao,cross:()=>Dl,dist:()=>ql,distance:()=>go,div:()=>jl,divide:()=>mo,dot:()=>er,equals:()=>$l,exactEquals:()=>_o,floor:()=>Pl,forEach:()=>Kl,fromValues:()=>lo,inverse:()=>Vl,len:()=>Xl,length:()=>wt,lerp:()=>tr,max:()=>Bl,min:()=>Nl,mul:()=>Wl,multiply:()=>ho,negate:()=>Fl,normalize:()=>Qn,random:()=>kl,round:()=>Ol,scale:()=>Jn,scaleAndAdd:()=>Ul,set:()=>uo,sqrDist:()=>Yl,sqrLen:()=>Zl,squaredDistance:()=>bo,squaredLength:()=>Ct,str:()=>zl,sub:()=>Hl,subtract:()=>po,transformMat4:()=>nr,transformQuat:()=>rr,zero:()=>Gl});function ao(){let t=new F(4);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function co(t){let e=new F(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function lo(t,e,n,r){let i=new F(4);return i[0]=t,i[1]=e,i[2]=n,i[3]=r,i}function fo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function uo(t,e,n,r,i){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t}function Kn(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t}function po(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t}function ho(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t[3]=e[3]*n[3],t}function mo(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t[3]=e[3]/n[3],t}function Tl(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t}function Pl(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t}function Nl(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t[3]=Math.min(e[3],n[3]),t}function Bl(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t[3]=Math.max(e[3],n[3]),t}function Ol(t,e){return t[0]=X(e[0]),t[1]=X(e[1]),t[2]=X(e[2]),t[3]=X(e[3]),t}function Jn(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t}function Ul(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t[3]=e[3]+n[3]*r,t}function go(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return Math.sqrt(n*n+r*r+i*i+o*o)}function bo(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=e[3]-t[3];return n*n+r*r+i*i+o*o}function wt(t){let e=t[0],n=t[1],r=t[2],i=t[3];return Math.sqrt(e*e+n*n+r*r+i*i)}function Ct(t){let e=t[0],n=t[1],r=t[2],i=t[3];return e*e+n*n+r*r+i*i}function Fl(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}function Vl(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}function Qn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o;return s>0&&(s=1/Math.sqrt(s)),t[0]=n*s,t[1]=r*s,t[2]=i*s,t[3]=o*s,t}function er(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Dl(t,e,n,r){let i=n[0]*r[1]-n[1]*r[0],o=n[0]*r[2]-n[2]*r[0],s=n[0]*r[3]-n[3]*r[0],a=n[1]*r[2]-n[2]*r[1],c=n[1]*r[3]-n[3]*r[1],l=n[2]*r[3]-n[3]*r[2],f=e[0],u=e[1],p=e[2],d=e[3];return t[0]=u*l-p*c+d*a,t[1]=-(f*l)+p*s-d*o,t[2]=f*c-u*s+d*i,t[3]=-(f*a)+u*o-p*i,t}function tr(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t[2]=s+r*(n[2]-s),t[3]=a+r*(n[3]-a),t}function kl(t,e){e=e===void 0?1:e;let n,r,i,o,s,a;do n=K()*2-1,r=K()*2-1,s=n*n+r*r;while(s>=1);do i=K()*2-1,o=K()*2-1,a=i*i+o*o;while(a>=1);let c=Math.sqrt((1-s)/a);return t[0]=e*n,t[1]=e*r,t[2]=e*i*c,t[3]=e*o*c,t}function nr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3];return t[0]=n[0]*r+n[4]*i+n[8]*o+n[12]*s,t[1]=n[1]*r+n[5]*i+n[9]*o+n[13]*s,t[2]=n[2]*r+n[6]*i+n[10]*o+n[14]*s,t[3]=n[3]*r+n[7]*i+n[11]*o+n[15]*s,t}function rr(t,e,n){let r=e[0],i=e[1],o=e[2],s=n[0],a=n[1],c=n[2],l=n[3],f=l*r+a*o-c*i,u=l*i+c*r-s*o,p=l*o+s*i-a*r,d=-s*r-a*i-c*o;return t[0]=f*l+d*-s+u*-c-p*-a,t[1]=u*l+d*-a+p*-s-f*-c,t[2]=p*l+d*-c+f*-a-u*-s,t[3]=e[3],t}function Gl(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}function zl(t){return`vec4(${t[0]}, ${t[1]}, ${t[2]}, ${t[3]})`}function _o(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function $l(t,e){let n=t[0],r=t[1],i=t[2],o=t[3],s=e[0],a=e[1],c=e[2],l=e[3];return Math.abs(n-s)<=1e-6*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(r-a)<=1e-6*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(i-c)<=1e-6*Math.max(1,Math.abs(i),Math.abs(c))&&Math.abs(o-l)<=1e-6*Math.max(1,Math.abs(o),Math.abs(l))}var Hl=po;var Wl=ho;var jl=mo;var ql=go;var Yl=bo;var Xl=wt;var Zl=Ct;var Kl=(function(){let t=ao();return function(e,n,r,i,o,s){let a,c;for(n||(n=4),r||(r=0),i?c=Math.min(i*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],o(t,t,s),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}})();var ar;(function(t){t[t.COL0ROW0=0]=`COL0ROW0`,t[t.COL0ROW1=1]=`COL0ROW1`,t[t.COL0ROW2=2]=`COL0ROW2`,t[t.COL0ROW3=3]=`COL0ROW3`,t[t.COL1ROW0=4]=`COL1ROW0`,t[t.COL1ROW1=5]=`COL1ROW1`,t[t.COL1ROW2=6]=`COL1ROW2`,t[t.COL1ROW3=7]=`COL1ROW3`,t[t.COL2ROW0=8]=`COL2ROW0`,t[t.COL2ROW1=9]=`COL2ROW1`,t[t.COL2ROW2=10]=`COL2ROW2`,t[t.COL2ROW3=11]=`COL2ROW3`,t[t.COL3ROW0=12]=`COL3ROW0`,t[t.COL3ROW1=13]=`COL3ROW1`,t[t.COL3ROW2=14]=`COL3ROW2`,t[t.COL3ROW3=15]=`COL3ROW3`})(ar||(ar={}));var Jl=45*Math.PI/180;var Ql=1;var or=.1;var sr=500;var ef=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);var U=class extends we{static get IDENTITY(){return nf()}static get ZERO(){return tf()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ar}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this[4]=o,this[5]=s,this[6]=a,this[7]=c,this[8]=l,this[9]=f,this[10]=u,this[11]=p,this[12]=d,this[13]=h,this[14]=g,this[15]=m,this.check()}setRowMajor(e,n,r,i,o,s,a,c,l,f,u,p,d,h,g,m){return this[0]=e,this[1]=o,this[2]=l,this[3]=d,this[4]=n,this[5]=s,this[6]=f,this[7]=h,this[8]=r,this[9]=a,this[10]=u,this[11]=g,this[12]=i,this[13]=c,this[14]=p,this[15]=m,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(ef)}fromObject(e){return this.check()}fromQuaternion(e){return Fn(this,e),this.check()}frustum(e){let{left:n,right:r,bottom:i,top:o,near:s=or,far:a=sr}=e;return a===1/0?rf(this,n,r,i,o,s):Vn(this,n,r,i,o,s,a),this.check()}lookAt(e){let{eye:n,center:r=[0,0,0],up:i=[0,1,0]}=e;return Gn(this,n,r,i),this.check()}ortho(e){let{left:n,right:r,bottom:i,top:o,near:s=or,far:a=sr}=e;return kn(this,n,r,i,o,s,a),this.check()}orthographic(e){let{fovy:n=Jl,aspect:r=Ql,focalDistance:i=1,near:o=or,far:s=sr}=e;vo(n);let a=n/2,c=i*Math.tan(a),l=c*r;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:o,far:s})}perspective(e){let{fovy:n=45*Math.PI/180,aspect:r=1,near:i=.1,far:o=500}=e;return vo(n),Dn(this,n,r,i,o),this.check()}determinant(){return Cn(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],o=1/r[1],s=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*o,e[2]=this[2]*s,e[3]=0,e[4]=this[4]*i,e[5]=this[5]*o,e[6]=this[6]*s,e[7]=0,e[8]=this[8]*i,e[9]=this[9]*o,e[10]=this[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),i=1/r[0],o=1/r[1],s=1/r[2];return e[0]=this[0]*i,e[1]=this[1]*o,e[2]=this[2]*s,e[3]=this[4]*i,e[4]=this[5]*o,e[5]=this[6]*s,e[6]=this[8]*i,e[7]=this[9]*o,e[8]=this[10]*s,e}transpose(){return Rn(this,this),this.check()}invert(){return wn(this,this),this.check()}multiplyLeft(e){return Xe(this,e,this),this.check()}multiplyRight(e){return Xe(this,this,e),this.check()}rotateX(e){return Bn(this,this,e),this.check()}rotateY(e){return On(this,this,e),this.check()}rotateZ(e){return Un(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,n){return Nn(this,this,e,n),this.check()}scale(e){return Pn(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Tn(this,this,e),this.check()}transform(e,n){return e.length===4?(n=nr(n||[-0,-0,-0,-0],e,this),le(n,4),n):this.transformAsPoint(e,n)}transformAsPoint(e,n){let{length:r}=e,i;switch(r){case 2:i=Ke(n||[-0,-0],e,this);break;case 3:i=he(n||[-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return le(i,e.length),i}transformAsVector(e,n){let r;switch(e.length){case 2:r=At(n||[-0,-0],e,this);break;case 3:r=Et(n||[-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return le(r,e.length),r}transformPoint(e,n){return this.transformAsPoint(e,n)}transformVector(e,n){return this.transformAsPoint(e,n)}transformDirection(e,n){return this.transformAsVector(e,n)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,n,r){return this.identity().translate([e,n,r])}};var Tt;var Pt;function tf(){return Tt||(Tt=new U([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Tt)),Tt}function nf(){return Pt||(Pt=new U,Object.freeze(Pt)),Pt}function vo(t){if(t>Math.PI*2)throw Error(`expected radians`)}function rf(t,e,n,r,i,o){let s=2*o/(n-e),a=2*o/(i-r),c=(n+e)/(n-e),l=(i+r)/(i-r),f=-1,u=-1,p=-2*o;return t[0]=s,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=c,t[9]=l,t[10]=f,t[11]=u,t[12]=0,t[13]=0,t[14]=p,t[15]=0,t}function Nt(t,e){if(!t)throw new Error(`math.gl assertion ${e}`)}var fe=class extends ce{get x(){return this[0]}set x(e){this[0]=N(e)}get y(){return this[1]}set y(e){this[1]=N(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*this[n];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let n=0;for(let r=0;r<this.ELEMENTS;++r){let i=this[r]-e[r];n+=i*i}return N(n)}dot(e){let n=0;for(let r=0;r<this.ELEMENTS;++r)n+=this[r]*e[r];return N(n)}normalize(){let e=this.magnitude();if(e!==0)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e;return this.check()}multiply(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]*=n[r];return this.check()}divide(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]/=n[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return Nt(e>=0&&e<this.ELEMENTS,`index is out of range`),N(this[e])}setComponent(e,n){return Nt(e>=0&&e<this.ELEMENTS,`index is out of range`),this[e]=n,this.check()}addVectors(e,n){return this.copy(e).add(n)}subVectors(e,n){return this.copy(e).subtract(n)}multiplyVectors(e,n){return this.copy(e).multiply(n)}addScaledVector(e,n){return this.add(new this.constructor(e).multiplyScalar(n))}};var cr=class extends fe{constructor(e=0,n=0){super(2),q(e)&&arguments.length===1?this.copy(e):(V.debug&&(N(e),N(n)),this[0]=e,this[1]=n)}set(e,n){return this[0]=e,this[1]=n,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y)),this[0]=e.x,this[1]=e.y,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e}get ELEMENTS(){return 2}horizontalAngle(){return Math.atan2(this.y,this.x)}verticalAngle(){return Math.atan2(this.x,this.y)}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return Ke(this,this,e),this.check()}transformAsVector(e){return At(this,this,e),this.check()}transformByMatrix3(e){return Ze(this,this,e),this.check()}transformByMatrix2x3(e){return $n(this,this,e),this.check()}transformByMatrix2(e){return zn(this,this,e),this.check()}};var lr=[0,0,0];var Bt;var Z=class t extends fe{static get ZERO(){return Bt||(Bt=new t(0,0,0),Object.freeze(Bt)),Bt}constructor(e=0,n=0,r=0){super(-0,-0,-0),arguments.length===1&&q(e)?this.copy(e):(V.debug&&(N(e),N(n),N(r)),this[0]=e,this[1]=n,this[2]=r)}set(e,n,r){return this[0]=e,this[1]=n,this[2]=r,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y),N(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=N(e)}angle(e){return Yn(this,e)}cross(e){return de(this,this,e),this.check()}rotateX({radians:e,origin:n=lr}){return Wn(this,this,n,e),this.check()}rotateY({radians:e,origin:n=lr}){return jn(this,this,n,e),this.check()}rotateZ({radians:e,origin:n=lr}){return qn(this,this,n,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return he(this,this,e),this.check()}transformAsVector(e){return Et(this,this,e),this.check()}transformByMatrix3(e){return Qe(this,this,e),this.check()}transformByMatrix2(e){return Ui(this,this,e),this.check()}transformByQuaternion(e){return et(this,this,e),this.check()}};var Ot;var Ut=class t extends fe{static get ZERO(){return Ot||(Ot=new t(0,0,0,0),Object.freeze(Ot)),Ot}constructor(e=0,n=0,r=0,i=0){super(-0,-0,-0,-0),q(e)&&arguments.length===1?this.copy(e):(V.debug&&(N(e),N(n),N(r),N(i)),this[0]=e,this[1]=n,this[2]=r,this[3]=i)}set(e,n,r,i){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}fromObject(e){return V.debug&&(N(e.x),N(e.y),N(e.z),N(e.w)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e.w=this[3],e}get ELEMENTS(){return 4}get z(){return this[2]}set z(e){this[2]=N(e)}get w(){return this[3]}set w(e){this[3]=N(e)}transform(e){return he(this,this,e),this.check()}transformByMatrix3(e){return It(this,this,e),this.check()}transformByMatrix2(e){return Fi(this,this,e),this.check()}transformByQuaternion(e){return et(this,this,e),this.check()}applyMatrix4(e){return e.transform(this,this),this}};function xo(){let t=new F(9);return F!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function So(t,e){if(t===e){let n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t}function yo(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=f*s-a*l,p=-f*o+a*c,d=l*o-s*c,h=n*u+r*p+i*d;return h?(h=1/h,t[0]=u*h,t[1]=(-f*r+i*l)*h,t[2]=(a*r-i*s)*h,t[3]=p*h,t[4]=(f*n-i*c)*h,t[5]=(-a*n+i*o)*h,t[6]=d*h,t[7]=(-l*n+r*c)*h,t[8]=(s*n-r*o)*h,t):null}function Mo(t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],s=t[5],a=t[6],c=t[7],l=t[8];return e*(l*o-s*c)+n*(-l*i+s*a)+r*(c*i-o*a)}function fr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=n[0],d=n[1],h=n[2],g=n[3],m=n[4],v=n[5],S=n[6],y=n[7],_=n[8];return t[0]=p*r+d*s+h*l,t[1]=p*i+d*a+h*f,t[2]=p*o+d*c+h*u,t[3]=g*r+m*s+v*l,t[4]=g*i+m*a+v*f,t[5]=g*o+m*c+v*u,t[6]=S*r+y*s+_*l,t[7]=S*i+y*a+_*f,t[8]=S*o+y*c+_*u,t}function Ao(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=n[0],d=n[1];return t[0]=r,t[1]=i,t[2]=o,t[3]=s,t[4]=a,t[5]=c,t[6]=p*r+d*s+l,t[7]=p*i+d*a+f,t[8]=p*o+d*c+u,t}function Eo(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],p=Math.sin(n),d=Math.cos(n);return t[0]=d*r+p*s,t[1]=d*i+p*a,t[2]=d*o+p*c,t[3]=d*s-p*r,t[4]=d*a-p*i,t[5]=d*c-p*o,t[6]=l,t[7]=f,t[8]=u,t}function ur(t,e,n){let r=n[0],i=n[1];return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=i*e[3],t[4]=i*e[4],t[5]=i*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function Io(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n+n,a=r+r,c=i+i,l=n*s,f=r*s,u=r*a,p=i*s,d=i*a,h=i*c,g=o*s,m=o*a,v=o*c;return t[0]=1-u-h,t[3]=f-v,t[6]=p+m,t[1]=f+v,t[4]=1-l-h,t[7]=d-g,t[2]=p-m,t[5]=d+g,t[8]=1-l-u,t}var pr;(function(t){t[t.COL0ROW0=0]=`COL0ROW0`,t[t.COL0ROW1=1]=`COL0ROW1`,t[t.COL0ROW2=2]=`COL0ROW2`,t[t.COL1ROW0=3]=`COL1ROW0`,t[t.COL1ROW1=4]=`COL1ROW1`,t[t.COL1ROW2=5]=`COL1ROW2`,t[t.COL2ROW0=6]=`COL2ROW0`,t[t.COL2ROW1=7]=`COL2ROW1`,t[t.COL2ROW2=8]=`COL2ROW2`})(pr||(pr={}));var of=Object.freeze([1,0,0,0,1,0,0,0,1]);var tt=class extends we{static get IDENTITY(){return af()}static get ZERO(){return sf()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return pr}constructor(e,...n){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):n.length>0?this.copy([e,...n]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(of)}fromObject(e){return this.check()}fromQuaternion(e){return Io(this,e),this.check()}set(e,n,r,i,o,s,a,c,l){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this[4]=o,this[5]=s,this[6]=a,this[7]=c,this[8]=l,this.check()}setRowMajor(e,n,r,i,o,s,a,c,l){return this[0]=e,this[1]=i,this[2]=a,this[3]=n,this[4]=o,this[5]=c,this[6]=r,this[7]=s,this[8]=l,this.check()}determinant(){return Mo(this)}transpose(){return So(this,this),this.check()}invert(){return yo(this,this),this.check()}multiplyLeft(e){return fr(this,e,this),this.check()}multiplyRight(e){return fr(this,this,e),this.check()}rotate(e){return Eo(this,this,e),this.check()}scale(e){return Array.isArray(e)?ur(this,this,e):ur(this,this,[e,e]),this.check()}translate(e){return Ao(this,this,e),this.check()}transform(e,n){let r;switch(e.length){case 2:r=Ze(n||[-0,-0],e,this);break;case 3:r=Qe(n||[-0,-0,-0],e,this);break;case 4:r=It(n||[-0,-0,-0,-0],e,this);break;default:throw new Error(`Illegal vector`)}return le(r,e.length),r}transformVector(e,n){return this.transform(e,n)}transformVector2(e,n){return this.transform(e,n)}transformVector3(e,n){return this.transform(e,n)}};var Ft;var Vt=null;function sf(){return Ft||(Ft=new tt([0,0,0,0,0,0,0,0,0]),Object.freeze(Ft)),Ft}function af(){return Vt||(Vt=new tt,Object.freeze(Vt)),Vt}function Ro(){let t=new F(4);return F!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function wo(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function dr(t,e,n){n=n*.5;let r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t}function hr(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],a=n[0],c=n[1],l=n[2],f=n[3];return t[0]=r*f+s*a+i*l-o*c,t[1]=i*f+s*c+o*a-r*l,t[2]=o*f+s*l+r*c-i*a,t[3]=s*f-r*a-i*c-o*l,t}function Co(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+s*a,t[1]=i*c+o*a,t[2]=o*c-i*a,t[3]=s*c-r*a,t}function To(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c-o*a,t[1]=i*c+s*a,t[2]=o*c+r*a,t[3]=s*c-i*a,t}function Po(t,e,n){n*=.5;let r=e[0],i=e[1],o=e[2],s=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+i*a,t[1]=i*c-r*a,t[2]=o*c+s*a,t[3]=s*c-o*a,t}function No(t,e){let n=e[0],r=e[1],i=e[2];return t[0]=n,t[1]=r,t[2]=i,t[3]=Math.sqrt(Math.abs(1-n*n-r*r-i*i)),t}function nt(t,e,n,r){let i=e[0],o=e[1],s=e[2],a=e[3],c=n[0],l=n[1],f=n[2],u=n[3],p,d,h,g,m;return p=i*c+o*l+s*f+a*u,p<0&&(p=-p,c=-c,l=-l,f=-f,u=-u),1-p>1e-6?(d=Math.acos(p),m=Math.sin(d),h=Math.sin((1-r)*d)/m,g=Math.sin(r*d)/m):(h=1-r,g=r),t[0]=h*i+g*c,t[1]=h*o+g*l,t[2]=h*s+g*f,t[3]=h*a+g*u,t}function Bo(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=n*n+r*r+i*i+o*o,a=s?1/s:0;return t[0]=-n*a,t[1]=-r*a,t[2]=-i*a,t[3]=o*a,t}function Oo(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function mr(t,e){let n=e[0]+e[4]+e[8],r;if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[5]-e[7])*r,t[1]=(e[6]-e[2])*r,t[2]=(e[1]-e[3])*r;else{let i=0;e[4]>e[0]&&(i=1),e[8]>e[i*3+i]&&(i=2);let o=(i+1)%3,s=(i+2)%3;r=Math.sqrt(e[i*3+i]-e[o*3+o]-e[s*3+s]+1),t[i]=.5*r,r=.5/r,t[3]=(e[o*3+s]-e[s*3+o])*r,t[o]=(e[o*3+i]+e[i*3+o])*r,t[s]=(e[s*3+i]+e[i*3+s])*r}return t}var Uo=Kn;var Fo=Jn;var Vo=er;var Do=tr;var ko=wt;var Go=Ct;var zo=Qn;var $o=(function(){let t=Lt(),e=Rt(1,0,0),n=Rt(0,1,0);return function(r,i,o){let s=Je(i,o);return s<-.999999?(de(t,e,i),Xn(t)<1e-6&&de(t,n,i),Hn(t,t),dr(r,t,Math.PI),r):s>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(de(t,i,o),r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=1+s,zo(r,r))}})();(function(){let t=Ro(),e=Ro();return function(n,r,i,o,s,a){return nt(t,r,s,a),nt(e,i,o,a),nt(n,t,e,2*a*(1-a)),n}})();(function(){let t=xo();return function(e,n,r,i){return t[0]=r[0],t[3]=r[1],t[6]=r[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],zo(e,mr(e,t))}})();var lf=[0,0,0,1];var gr=class extends ce{constructor(e=0,n=0,r=0,i=1){super(-0,-0,-0,-0),Array.isArray(e)&&arguments.length===1?this.copy(e):this.set(e,n,r,i)}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}set(e,n,r,i){return this[0]=e,this[1]=n,this[2]=r,this[3]=i,this.check()}fromObject(e){return this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this.check()}fromMatrix3(e){return mr(this,e),this.check()}fromAxisRotation(e,n){return dr(this,e,n),this.check()}identity(){return wo(this),this.check()}setAxisAngle(e,n){return this.fromAxisRotation(e,n)}get ELEMENTS(){return 4}get x(){return this[0]}set x(e){this[0]=N(e)}get y(){return this[1]}set y(e){this[1]=N(e)}get z(){return this[2]}set z(e){this[2]=N(e)}get w(){return this[3]}set w(e){this[3]=N(e)}len(){return ko(this)}lengthSquared(){return Go(this)}dot(e){return Vo(this,e)}rotationTo(e,n){return $o(this,e,n),this.check()}add(e){return Uo(this,this,e),this.check()}calculateW(){return No(this,this),this.check()}conjugate(){return Oo(this,this),this.check()}invert(){return Bo(this,this),this.check()}lerp(e,n,r){return r===void 0?this.lerp(this,e,n):(Do(this,e,n,r),this.check())}multiplyRight(e){return hr(this,this,e),this.check()}multiplyLeft(e){return hr(this,e,this),this.check()}normalize(){let e=this.len(),n=e>0?1/e:0;return this[0]=this[0]*n,this[1]=this[1]*n,this[2]=this[2]*n,this[3]=this[3]*n,e===0&&(this[3]=1),this.check()}rotateX(e){return Co(this,this,e),this.check()}rotateY(e){return To(this,this,e),this.check()}rotateZ(e){return Po(this,this,e),this.check()}scale(e){return Fo(this,this,e),this.check()}slerp(e,n,r){let i,o,s;switch(arguments.length){case 1:({start:i=lf,target:o,ratio:s}=e);break;case 2:i=this,o=e,s=n;break;default:i=e,o=n,s=r}return nt(this,i,o,s),this.check()}transformVector4(e,n=new Ut){return rr(n,e,this),le(n,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(e,n){return this.setAxisAngle(e,n)}premultiply(e){return this.multiplyLeft(e)}multiply(e){return this.multiplyRight(e)}};var Ho={};w(Ho,{EPSILON1:()=>ff,EPSILON10:()=>vf,EPSILON11:()=>xf,EPSILON12:()=>Sf,EPSILON13:()=>yf,EPSILON14:()=>Mf,EPSILON15:()=>Af,EPSILON16:()=>Ef,EPSILON17:()=>If,EPSILON18:()=>Lf,EPSILON19:()=>Rf,EPSILON2:()=>uf,EPSILON20:()=>wf,EPSILON3:()=>pf,EPSILON4:()=>df,EPSILON5:()=>hf,EPSILON6:()=>mf,EPSILON7:()=>gf,EPSILON8:()=>bf,EPSILON9:()=>_f,PI_OVER_FOUR:()=>Tf,PI_OVER_SIX:()=>Pf,PI_OVER_TWO:()=>Cf,TWO_PI:()=>Nf});var ff=.1;var uf=.01;var pf=.001;var df=1e-4;var hf=1e-5;var mf=1e-6;var gf=1e-7;var bf=1e-8;var _f=1e-9;var vf=1e-10;var xf=1e-11;var Sf=1e-12;var yf=1e-13;var Mf=1e-14;var Af=1e-15;var Ef=1e-16;var If=1e-17;var Lf=1e-18;var Rf=1e-19;var wf=1e-20;var Cf=Math.PI/2;var Tf=Math.PI/4;var Pf=Math.PI/6;var Nf=Math.PI*2;var Uf={name:`fp32`,source:`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
2
2
  const FP32_TWO_PI: f32 = 6.2831854820251465;
3
3
  const FP32_PI_2: f32 = 1.5707963705062866;
4
4
  const FP32_PI_16: f32 = 0.1963495463132858;
@@ -269,7 +269,7 @@ float tan_fp32(float a) {
269
269
  return tan(a);
270
270
  #endif
271
271
  }
272
- `};var ee={RGBA8UNORM:0,RGBA16FLOAT:1,RGBA32FLOAT:2};var Vf=r({},{rgba8unorm:4,rgba16float:8,rgba32float:16});ee.RGBA8UNORM,ee.RGBA16FLOAT,ee.RGBA32FLOAT;ee.RGBA8UNORM,ee.RGBA16FLOAT,ee.RGBA32FLOAT;var Df={useByteColors:`f32`};var kf={useByteColors:!0};ee.RGBA8UNORM,Vf.rgba8unorm/Uint32Array.BYTES_PER_ELEMENT;jo(`colors`);var Wo=jo(`floatColors`);qo(`colors`);var Gf=qo(`floatColors`);`${ee.RGBA8UNORM}${ee.RGBA16FLOAT}`;function jo(t){return`layout(std140) uniform ${t}Uniforms {
272
+ `};var te={RGBA8UNORM:0,RGBA16FLOAT:1,RGBA32FLOAT:2};var Vf=r({},{rgba8unorm:4,rgba16float:8,rgba32float:16});te.RGBA8UNORM,te.RGBA16FLOAT,te.RGBA32FLOAT;te.RGBA8UNORM,te.RGBA16FLOAT,te.RGBA32FLOAT;var Df={useByteColors:`f32`};var kf={useByteColors:!0};te.RGBA8UNORM,Vf.rgba8unorm/Uint32Array.BYTES_PER_ELEMENT;jo(`colors`);var Wo=jo(`floatColors`);qo(`colors`);var Gf=qo(`floatColors`);`${te.RGBA8UNORM}${te.RGBA16FLOAT}`;function jo(t){return`layout(std140) uniform ${t}Uniforms {
273
273
  float useByteColors;
274
274
  } ${t};
275
275
 
@@ -329,7 +329,7 @@ fn ${t}_premultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
329
329
  fn ${t}_unpremultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
330
330
  return ${t}_unpremultiplyAlpha(inputColor);
331
331
  }
332
- `}var Dt={name:`floatColors`,props:{},uniforms:{},vs:Wo,fs:Wo,source:Gf,uniformTypes:Df,defaultUniforms:kf};var mr=`precision highp int;
332
+ `}var Dt={name:`floatColors`,props:{},uniforms:{},vs:Wo,fs:Wo,source:Gf,uniformTypes:Df,defaultUniforms:kf};var br=`precision highp int;
333
333
 
334
334
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
335
335
  struct AmbientLight {
@@ -488,7 +488,7 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
488
488
  );
489
489
  return distanceAttenuation / max(coneFactor, 0.0001);
490
490
  }
491
- `;function rt(t,e=!0){return t??e}function kt(t=[0,0,0],e=!0){return e?t.map(n=>n/255):[...t]}function gr(t,e=!0){let n=kt(t.slice(0,3),e),r=Number.isFinite(t[3]),i=r?t[3]:1;return[n[0],n[1],n[2],e&&r?i/255:i]}var me=5;var ge={props:{},uniforms:{},name:`lighting`,defines:{},uniformTypes:{enabled:`i32`,directionalLightCount:`i32`,pointLightCount:`i32`,spotLightCount:`i32`,ambientColor:`vec3<f32>`,lights:[{color:`vec3<f32>`,position:`vec3<f32>`,direction:`vec3<f32>`,attenuation:`vec3<f32>`,coneCos:`vec2<f32>`},me]},defaultUniforms:zt(),bindingLayout:[{name:`lighting`,group:2}],firstBindingSlot:0,source:Yo,vs:mr,fs:mr,getUniforms:$f};function $f(t,e={}){if(t=t&&r({},t),!t)return zt();t.lights&&(t=s(r(r({},t),Wf(t.lights)),{lights:void 0}));let{useByteColors:n,ambientLight:r$1,pointLights:i,spotLights:o,directionalLights:s$1}=t||{};if(!(r$1||i&&i.length>0||o&&o.length>0||s$1&&s$1.length>0))return s(r({},zt()),{enabled:0});let c=r(r({},zt()),Hf({useByteColors:n,ambientLight:r$1,pointLights:i,spotLights:o,directionalLights:s$1}));return t.enabled!==void 0&&(c.enabled=t.enabled?1:0),c}function Hf({useByteColors:t,ambientLight:e,pointLights:n=[],spotLights:r$2=[],directionalLights:i=[]}){let o=Xo(),s$2=0,a=0,c=0,l=0;for(let f of n){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),position:f.position,attenuation:f.attenuation||[1,0,0]}),s$2++,a++}for(let f of r$2){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:qf(f)}),s$2++,c++}for(let f of i){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),direction:f.direction}),s$2++,l++}return n.length+r$2.length+i.length>me&&f.warn(`MAX_LIGHTS exceeded, truncating to ${me}`)(),{ambientColor:Gt(e,t),directionalLightCount:l,pointLightCount:a,spotLightCount:c,lights:o}}function Wf(t){let e={pointLights:[],spotLights:[],directionalLights:[]};for(let n of t||[])switch(n.type){case`ambient`:e.ambientLight=n;break;case`directional`:e.directionalLights?.push(n);break;case`point`:e.pointLights?.push(n);break;case`spot`:e.spotLights?.push(n);break;default:}return e}function Gt(t={},e){let{color:n=[0,0,0],intensity:r=1}=t;return kt(n,rt(e,!0)).map(o=>o*r)}function zt(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Xo()}}function Xo(){return Array.from({length:me},()=>jf())}function jf(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function qf(t){let e=t.innerConeAngle??0,n=t.outerConeAngle??Math.PI/4;return[Math.cos(e),Math.cos(n)]}var $t=`layout(std140) uniform phongMaterialUniforms {
491
+ `;function rt(t,e=!0){return t??e}function kt(t=[0,0,0],e=!0){return e?t.map(n=>n/255):[...t]}function _r(t,e=!0){let n=kt(t.slice(0,3),e),r=Number.isFinite(t[3]),i=r?t[3]:1;return[n[0],n[1],n[2],e&&r?i/255:i]}var me=5;var ge={props:{},uniforms:{},name:`lighting`,defines:{},uniformTypes:{enabled:`i32`,directionalLightCount:`i32`,pointLightCount:`i32`,spotLightCount:`i32`,ambientColor:`vec3<f32>`,lights:[{color:`vec3<f32>`,position:`vec3<f32>`,direction:`vec3<f32>`,attenuation:`vec3<f32>`,coneCos:`vec2<f32>`},me]},defaultUniforms:zt(),bindingLayout:[{name:`lighting`,group:2}],firstBindingSlot:0,source:Yo,vs:br,fs:br,getUniforms:$f};function $f(t,e={}){if(t=t&&r({},t),!t)return zt();t.lights&&(t=s(r(r({},t),Wf(t.lights)),{lights:void 0}));let{useByteColors:n,ambientLight:r$1,pointLights:i,spotLights:o,directionalLights:s$1}=t||{};if(!(r$1||i&&i.length>0||o&&o.length>0||s$1&&s$1.length>0))return s(r({},zt()),{enabled:0});let c=r(r({},zt()),Hf({useByteColors:n,ambientLight:r$1,pointLights:i,spotLights:o,directionalLights:s$1}));return t.enabled!==void 0&&(c.enabled=t.enabled?1:0),c}function Hf({useByteColors:t,ambientLight:e,pointLights:n=[],spotLights:r$2=[],directionalLights:i=[]}){let o=Xo(),s$2=0,a=0,c=0,l=0;for(let f of n){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),position:f.position,attenuation:f.attenuation||[1,0,0]}),s$2++,a++}for(let f of r$2){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:qf(f)}),s$2++,c++}for(let f of i){if(s$2>=me)break;o[s$2]=s(r({},o[s$2]),{color:Gt(f,t),direction:f.direction}),s$2++,l++}return n.length+r$2.length+i.length>me&&f.warn(`MAX_LIGHTS exceeded, truncating to ${me}`)(),{ambientColor:Gt(e,t),directionalLightCount:l,pointLightCount:a,spotLightCount:c,lights:o}}function Wf(t){let e={pointLights:[],spotLights:[],directionalLights:[]};for(let n of t||[])switch(n.type){case`ambient`:e.ambientLight=n;break;case`directional`:e.directionalLights?.push(n);break;case`point`:e.pointLights?.push(n);break;case`spot`:e.spotLights?.push(n)}return e}function Gt(t={},e){let{color:n=[0,0,0],intensity:r=1}=t;return kt(n,rt(e,!0)).map(o=>o*r)}function zt(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Xo()}}function Xo(){return Array.from({length:me},()=>jf())}function jf(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function qf(t){let e=t.innerConeAngle??0,n=t.outerConeAngle??Math.PI/4;return[Math.cos(e),Math.cos(n)]}var $t=`layout(std140) uniform phongMaterialUniforms {
492
492
  uniform bool unlit;
493
493
  uniform float ambient;
494
494
  uniform float diffuse;
@@ -677,7 +677,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
677
677
  }
678
678
  `;var Zo={props:{},name:`gouraudMaterial`,bindingLayout:[{name:`gouraudMaterial`,group:3}],vs:Ht.replace(`phongMaterial`,`gouraudMaterial`),fs:$t.replace(`phongMaterial`,`gouraudMaterial`),source:Wt.replaceAll(`phongMaterial`,`gouraudMaterial`),defines:{LIGHTING_VERTEX:!0},dependencies:[ge,Dt],uniformTypes:{unlit:`i32`,ambient:`f32`,diffuse:`f32`,shininess:`f32`,specularColor:`vec3<f32>`},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:[38.25,38.25,38.25]},getUniforms(t){return r(r({},Zo.defaultUniforms),t)}};var Ko={name:`phongMaterial`,firstBindingSlot:0,bindingLayout:[{name:`phongMaterial`,group:3}],dependencies:[ge,Dt],source:Wt,vs:$t,fs:Ht,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:`i32`,ambient:`f32`,diffuse:`f32`,shininess:`f32`,specularColor:`vec3<f32>`},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:[38.25,38.25,38.25]},getUniforms(t){return r(r({},Ko.defaultUniforms),t)}};var Y=`(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)`;var Te=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*${Y}`,`g`)];var jt=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*${Y}`,`g`)];var Jo=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${Y}`,`g`)];var Zf=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${Y}`,`g`),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${Y}`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${Y}`,`g`)];function Pe(t){let e=t.split(``),n=0,r=0,i=!1,o=!1,s=!1;for(;n<t.length;){let a=t[n],c=t[n+1];if(o){s?s=!1:a===`\\`?s=!0:a===`"`&&(o=!1),n++;continue}if(i){a===`
679
679
  `||a===`\r`?i=!1:e[n]=` `,n++;continue}if(r>0){if(a===`/`&&c===`*`){e[n]=` `,e[n+1]=` `,r++,n+=2;continue}if(a===`*`&&c===`/`){e[n]=` `,e[n+1]=` `,r--,n+=2;continue}a!==`
680
- `&&a!==`\r`&&(e[n]=` `),n++;continue}if(a===`"`){o=!0,n++;continue}if(a===`/`&&c===`/`){e[n]=` `,e[n+1]=` `,i=!0,n+=2;continue}if(a===`/`&&c===`*`){e[n]=` `,e[n+1]=` `,r=1,n+=2;continue}n++}return e.join(``)}function be(t,e){let n=Pe(t),r=[];for(let i of e){i.lastIndex=0;let o;for(o=i.exec(n);o;){let s=i===e[0],a=o.index,c=o[0].length;r.push({match:t.slice(a,a+c),index:a,length:c,bindingToken:o[s?1:2],groupToken:o[s?2:1],accessDeclaration:o[3]?.trim(),name:o[4]}),o=i.exec(n)}}return r.sort((i,o)=>i.index-o.index)}function br(t,e,n){let r=be(t,e);if(!r.length)return t;let i=``,o=0;for(let s of r)i+=t.slice(o,s.index),i+=n(s),o=s.index+s.length;return i+=t.slice(o),i}function _r(t){return/@binding\(\s*auto\s*\)/.test(Pe(t))}function Qo(t,e){return be(t,e===Te||e===jt?Zf:e).find(r=>r.bindingToken===`auto`)}function Yt(t,e={}){let n=es(t),r=Kf(n);if(!r)return null;let i=Jf(n,r);if(!i)return null;let o=eu(n,r,i);if(!o)return null;if(e.scanVertexAttributes===!1)return{attributes:[],bindings:o};let s=Qf(n,r);if(!s)return null;let a=ou(n,r,i,s,e.vertexEntryPoint);return a?{attributes:a,bindings:o}:null}function es(t){let e=Pe(t),n=/[A-Za-z_][A-Za-z0-9_]*|(?:0[xX][0-9A-Fa-f]+|\d+)|[@(){}<>\[\]:,;=]/g,r=[],i=n.exec(e);for(;i;)r.push({value:i[0],index:i.index}),i=n.exec(e);return r}function Kf(t){let e=[],n=0;for(let r of t){if(r.value===`}`&&n===0)return null;e.push(n),r.value===`{`?n++:r.value===`}`&&n--}return n===0?e:null}function Jf(t,e){let n=new Map;for(let r=0;r<t.length;r++){if(e[r]!==0||t[r].value!==`alias`)continue;let i=t[r+1]?.value;if(!it(i)||t[r+2]?.value!==`=`||n.has(i))return null;let o=rs(t,e,r+3,`;`);if(o<0||o===r+3)return null;n.set(i,qt(t.slice(r+3,o))),r=o}return n}function Qf(t,e){let n=new Map;for(let r=0;r<t.length;r++){if(e[r]!==0||t[r].value!==`struct`)continue;let i=t[r+1]?.value,o=r+2;if(!it(i)||n.has(i)||t[o]?.value!==`{`)return null;let s=yr(t,o,`{`,`}`);if(s<0)return null;n.set(i,t.slice(o+1,s)),r=s}return n}function eu(t,e,n){let r=[],i=new Set,o=new Set;for(let s=0;s<t.length;s++){if(e[s]!==0||t[s].value!==`var`)continue;let a=is(t,e,s),c=t.slice(a,s),l=vr(c,`group`),f=vr(c,`binding`);if(l===null||f===null||l===void 0!=(f===void 0))return null;if(l===void 0||f===void 0)continue;let u=s+1,p=[];if(t[u]?.value===`<`){let S=yr(t,u,`<`,`>`);if(S<0)return null;let y=Xt(t.slice(u+1,S),`,`);if(!y)return null;p=y.map(qt),u=S+1}let d=t[u]?.value;if(!it(d)||t[u+1]?.value!==`:`)return null;let h=rs(t,e,u+2,`;`);if(h<0||h===u+2)return null;let g=Sr(qt(t.slice(u+2,h)),n);if(!g)return null;let m=tu({name:d,group:l,location:f,addressSpace:p,resourceType:g}),_=`${l}:${f}`;if(!m||i.has(_)||o.has(d))return null;r.push(m),i.add(_),o.add(d),s=h}return iu(r),r.sort((s,a)=>s.group-a.group||s.location-a.location||s.name.localeCompare(a.name))}function tu(t){let{name:e,group:n,location:r$3,addressSpace:i,resourceType:o}=t,s$3={name:e,group:n,location:r$3};if(i[0]===`uniform`&&i.length===1)return s(r({},s$3),{type:`uniform`});if(i[0]===`storage`&&i.length<=2){let a=i[1]||`read`;return a===`read`?s(r({},s$3),{type:`read-only-storage`}):a===`read_write`?s(r({},s$3),{type:`storage`}):null}return i.length>0?null:o===`sampler`||o===`sampler_comparison`?r(s(r({},s$3),{type:`sampler`}),o===`sampler_comparison`?{samplerType:`comparison`}:{}):o===`texture_external`?s(r({},s$3),{type:`external-texture`}):nu(s$3,o)||ru(s$3,o)}function nu(t,e){let n=/^texture_storage_(1d|2d|2d_array|3d)<([A-Za-z0-9_]+),(read|write|read_write)>$/.exec(e);if(!n)return null;let r$4={read:`read-only`,write:`write-only`,read_write:`read-write`}[n[3]];return s(r({},t),{type:`storage`,format:n[2],access:r$4,viewDimension:xr(n[1])})}function ru(t,e){let n=/^texture_(multisampled_)?(1d|2d|2d_array|cube|cube_array|3d)<(f32|i32|u32)>$/.exec(e);if(n){if(n[1]&&n[2]!==`2d`)return null;let i={f32:`float`,i32:`sint`,u32:`uint`}[n[3]];return s(r({},t),{type:`texture`,viewDimension:xr(n[2]),sampleType:i,multisampled:!!n[1]})}let r$5=/^texture_depth_(multisampled_)?(2d|2d_array|cube|cube_array)$/.exec(e);return!r$5||r$5[1]&&r$5[2]!==`2d`?null:s(r({},t),{type:`texture`,viewDimension:xr(r$5[2]),sampleType:`depth`,multisampled:!!r$5[1]})}function iu(t){for(let e of t){if(e.type!==`sampler`||e.samplerType||!e.name.endsWith(`Sampler`))continue;let n=e.name.slice(0,-7);t.find(i=>i.type===`texture`&&i.name===n&&i.group===e.group)?.sampleType===`depth`&&(e.samplerType=`non-filtering`)}}function ou(t,e,n,r,i){let o=su(t,e);if(!o)return null;let s=o.filter(d=>d.vertex),a=i?s.find(d=>d.name===i):s.length===1?s[0]:void 0;if(!a)return s.length===0&&!i?[]:null;let c=Xt(a.parameters,`,`);if(!c)return null;let l=[],f=new Set,u=new Set,p=new Set;for(let d of c)if(d.length>0&&!ts({declaration:d,aliases:n,structures:r,attributes:l,attributeLocations:f,attributeNames:u,visitedStructures:p}))return null;return l.sort((d,h)=>d.location-h.location||d.name.localeCompare(h.name))}function su(t,e){let n=[],r=new Set;for(let i=0;i<t.length;i++){if(e[i]!==0||t[i].value!==`fn`)continue;let o=t[i+1]?.value,s=i+2;if(!it(o)||r.has(o)||t[s]?.value!==`(`)return null;let a=yr(t,s,`(`,`)`);if(a<0)return null;let c=is(t,e,i);n.push({name:o,vertex:ns(t.slice(c,i),`vertex`),parameters:t.slice(s+1,a)}),r.add(o),i=a}return n}function ts(t){let{declaration:e,aliases:n,structures:r$6,attributes:i,attributeLocations:o,attributeNames:s$4,visitedStructures:a}=t,c=lu(e,`:`);if(c<1||c===e.length-1)return!1;let l=fu(e.slice(0,c)),f=vr(e.slice(0,c),`location`),u=ns(e.slice(0,c),`builtin`),p=Sr(qt(e.slice(c+1)),n);if(!l||f===null||!p||f!==void 0&&u)return!1;if(f!==void 0){let g=cu(p);return!g||o.has(f)||s$4.has(l)?!1:(i.push({name:l,location:f,type:g}),o.add(f),s$4.add(l),!0)}if(u)return!0;let d=r$6.get(p);if(!d||a.has(p))return!1;let h=Xt(d,`,`);if(!h)return!1;a.add(p);for(let g of h)if(g.length>0&&!ts(s(r({},t),{declaration:g})))return!1;return a.delete(p),!0}function Sr(t,e,n=new Set){let r=es(t),i=``;for(let o of r){let s=e.get(o.value);if(!s){i+=au(o.value);continue}if(n.has(o.value))return null;let a=new Set(n);a.add(o.value);let c=Sr(s,e,a);if(!c)return null;i+=c}return i}function au(t){let e=/^(vec[234]|mat[234]x[234])([fiuh])$/.exec(t);if(!e)return t;let n={f:`f32`,i:`i32`,u:`u32`,h:`f16`}[e[2]];return`${e[1]}<${n}>`}function cu(t){return/^(?:i32|u32|f32|f16|vec[234]<(?:i32|u32|f32|f16)>)$/.test(t)?t:null}function vr(t,e){let n;for(let r=0;r<t.length;r++)if(!(t[r].value!==`@`||t[r+1]?.value!==e)){if(n!==void 0||t[r+2]?.value!==`(`||!/^\d+$/.test(t[r+3]?.value||``)||t[r+4]?.value!==`)`)return null;n=Number(t[r+3].value)}return n}function ns(t,e){return t.some((n,r)=>n.value===`@`&&t[r+1]?.value===e)}function xr(t){return t.replace(`_`,`-`)}function yr(t,e,n,r){let i=0;for(let o=e;o<t.length;o++)if(t[o].value===n)i++;else if(t[o].value===r&&--i===0)return o;return-1}function Xt(t,e){let n=[],r=0,i={"(":0,"<":0,"[":0,"{":0},o=Object.keys(i),s={")":`(`,">":`<`,"]":`[`,"}":`{`};for(let a=0;a<t.length;a++){let c=t[a].value;if(c===e&&o.every(l=>i[l]===0)){n.push(t.slice(r,a)),r=a+1;continue}if(c in i)i[c]++;else if(c in s){let l=s[c];if(i[l]--,i[l]<0)return null}}return o.every(a=>i[a]===0)?(n.push(t.slice(r)),n):null}function lu(t,e){let n=Xt(t,e);return n&&n.length===2?n[0].length:-1}function rs(t,e,n,r){for(let i=n;i<t.length;i++)if(e[i]===0&&t[i].value===r)return i;return-1}function is(t,e,n){for(let r=n-1;r>=0;r--)if(t[r].value===`;`&&e[r]===0||t[r].value===`}`&&e[r]===1)return r+1;return 0}function fu(t){for(let e=t.length-1;e>=0;e--)if(it(t[e].value))return t[e].value;return null}function qt(t){return t.map(e=>e.value).join(``)}function it(t){return!!(t&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t))}function te(t,e){if(!t){let n=new Error(e||`shadertools: assertion failed.`);throw Error.captureStackTrace?.(n,te),n}}var Mr={number:{type:`number`,validate(t,e){return Number.isFinite(t)&&typeof e==`object`&&(e.max===void 0||t<=e.max)&&(e.min===void 0||t>=e.min)}},array:{type:`array`,validate(t,e){return Array.isArray(t)||ArrayBuffer.isView(t)}}};function ss(t){let e={};for(let[n,r]of Object.entries(t))e[n]=uu(r);return e}function uu(t){let e=os(t);if(e!==`object`)return s(r({value:t},Mr[e]),{type:e});if(typeof t==`object`)return t?t.type!==void 0?s(r(r({},t),Mr[t.type]),{type:t.type}):t.value===void 0?{type:`object`,value:t}:(e=os(t.value),s(r(r({},t),Mr[e]),{type:e})):{type:`object`,value:null};throw new Error(`props`)}function os(t){return Array.isArray(t)||ArrayBuffer.isView(t)?`array`:typeof t}var pu={vertex:`#ifdef MODULE_LOGDEPTH
680
+ `&&a!==`\r`&&(e[n]=` `),n++;continue}if(a===`"`){o=!0,n++;continue}if(a===`/`&&c===`/`){e[n]=` `,e[n+1]=` `,i=!0,n+=2;continue}if(a===`/`&&c===`*`){e[n]=` `,e[n+1]=` `,r=1,n+=2;continue}n++}return e.join(``)}function be(t,e){let n=Pe(t),r=[];for(let i of e){i.lastIndex=0;let o;for(o=i.exec(n);o;){let s=i===e[0],a=o.index,c=o[0].length;r.push({match:t.slice(a,a+c),index:a,length:c,bindingToken:o[s?1:2],groupToken:o[s?2:1],accessDeclaration:o[3]?.trim(),name:o[4]}),o=i.exec(n)}}return r.sort((i,o)=>i.index-o.index)}function vr(t,e,n){let r=be(t,e);if(!r.length)return t;let i=``,o=0;for(let s of r)i+=t.slice(o,s.index),i+=n(s),o=s.index+s.length;return i+=t.slice(o),i}function xr(t){return/@binding\(\s*auto\s*\)/.test(Pe(t))}function Qo(t,e){return be(t,e===Te||e===jt?Zf:e).find(r=>r.bindingToken===`auto`)}function Yt(t,e={}){let n=es(t),r=Kf(n);if(!r)return null;let i=Jf(n,r);if(!i)return null;let o=eu(n,r,i);if(!o)return null;if(e.scanVertexAttributes===!1)return{attributes:[],bindings:o};let s=Qf(n,r);if(!s)return null;let a=ou(n,r,i,s,e.vertexEntryPoint);return a?{attributes:a,bindings:o}:null}function es(t){let e=Pe(t),n=/[A-Za-z_][A-Za-z0-9_]*|(?:0[xX][0-9A-Fa-f]+|\d+)|[@(){}<>\[\]:,;=]/g,r=[],i=n.exec(e);for(;i;)r.push({value:i[0],index:i.index}),i=n.exec(e);return r}function Kf(t){let e=[],n=0;for(let r of t){if(r.value===`}`&&n===0)return null;e.push(n),r.value===`{`?n++:r.value===`}`&&n--}return n===0?e:null}function Jf(t,e){let n=new Map;for(let r=0;r<t.length;r++){if(e[r]!==0||t[r].value!==`alias`)continue;let i=t[r+1]?.value;if(!it(i)||t[r+2]?.value!==`=`||n.has(i))return null;let o=rs(t,e,r+3,`;`);if(o<0||o===r+3)return null;n.set(i,qt(t.slice(r+3,o))),r=o}return n}function Qf(t,e){let n=new Map;for(let r=0;r<t.length;r++){if(e[r]!==0||t[r].value!==`struct`)continue;let i=t[r+1]?.value,o=r+2;if(!it(i)||n.has(i)||t[o]?.value!==`{`)return null;let s=Ar(t,o,`{`,`}`);if(s<0)return null;n.set(i,t.slice(o+1,s)),r=s}return n}function eu(t,e,n){let r=[],i=new Set,o=new Set;for(let s=0;s<t.length;s++){if(e[s]!==0||t[s].value!==`var`)continue;let a=is(t,e,s),c=t.slice(a,s),l=Sr(c,`group`),f=Sr(c,`binding`);if(l===null||f===null||l===void 0!=(f===void 0))return null;if(l===void 0||f===void 0)continue;let u=s+1,p=[];if(t[u]?.value===`<`){let S=Ar(t,u,`<`,`>`);if(S<0)return null;let y=Xt(t.slice(u+1,S),`,`);if(!y)return null;p=y.map(qt),u=S+1}let d=t[u]?.value;if(!it(d)||t[u+1]?.value!==`:`)return null;let h=rs(t,e,u+2,`;`);if(h<0||h===u+2)return null;let g=Mr(qt(t.slice(u+2,h)),n);if(!g)return null;let m=tu({name:d,group:l,location:f,addressSpace:p,resourceType:g}),v=`${l}:${f}`;if(!m||i.has(v)||o.has(d))return null;r.push(m),i.add(v),o.add(d),s=h}return iu(r),r.sort((s,a)=>s.group-a.group||s.location-a.location||s.name.localeCompare(a.name))}function tu(t){let{name:e,group:n,location:r$3,addressSpace:i,resourceType:o}=t,s$3={name:e,group:n,location:r$3};if(i[0]===`uniform`&&i.length===1)return s(r({},s$3),{type:`uniform`});if(i[0]===`storage`&&i.length<=2){let a=i[1]||`read`;return a===`read`?s(r({},s$3),{type:`read-only-storage`}):a===`read_write`?s(r({},s$3),{type:`storage`}):null}return i.length>0?null:o===`sampler`||o===`sampler_comparison`?r(s(r({},s$3),{type:`sampler`}),o===`sampler_comparison`?{samplerType:`comparison`}:{}):o===`texture_external`?s(r({},s$3),{type:`external-texture`}):nu(s$3,o)||ru(s$3,o)}function nu(t,e){let n=/^texture_storage_(1d|2d|2d_array|3d)<([A-Za-z0-9_]+),(read|write|read_write)>$/.exec(e);if(!n)return null;let r$4={read:`read-only`,write:`write-only`,read_write:`read-write`}[n[3]];return s(r({},t),{type:`storage`,format:n[2],access:r$4,viewDimension:yr(n[1])})}function ru(t,e){let n=/^texture_(multisampled_)?(1d|2d|2d_array|cube|cube_array|3d)<(f32|i32|u32)>$/.exec(e);if(n){if(n[1]&&n[2]!==`2d`)return null;let i={f32:`float`,i32:`sint`,u32:`uint`}[n[3]];return s(r({},t),{type:`texture`,viewDimension:yr(n[2]),sampleType:i,multisampled:!!n[1]})}let r$5=/^texture_depth_(multisampled_)?(2d|2d_array|cube|cube_array)$/.exec(e);return!r$5||r$5[1]&&r$5[2]!==`2d`?null:s(r({},t),{type:`texture`,viewDimension:yr(r$5[2]),sampleType:`depth`,multisampled:!!r$5[1]})}function iu(t){for(let e of t){if(e.type!==`sampler`||e.samplerType||!e.name.endsWith(`Sampler`))continue;let n=e.name.slice(0,-7);t.find(i=>i.type===`texture`&&i.name===n&&i.group===e.group)?.sampleType===`depth`&&(e.samplerType=`non-filtering`)}}function ou(t,e,n,r,i){let o=su(t,e);if(!o)return null;let s=o.filter(d=>d.vertex),a=i?s.find(d=>d.name===i):s.length===1?s[0]:void 0;if(!a)return s.length===0&&!i?[]:null;let c=Xt(a.parameters,`,`);if(!c)return null;let l=[],f=new Set,u=new Set,p=new Set;for(let d of c)if(d.length>0&&!ts({declaration:d,aliases:n,structures:r,attributes:l,attributeLocations:f,attributeNames:u,visitedStructures:p}))return null;return l.sort((d,h)=>d.location-h.location||d.name.localeCompare(h.name))}function su(t,e){let n=[],r=new Set;for(let i=0;i<t.length;i++){if(e[i]!==0||t[i].value!==`fn`)continue;let o=t[i+1]?.value,s=i+2;if(!it(o)||r.has(o)||t[s]?.value!==`(`)return null;let a=Ar(t,s,`(`,`)`);if(a<0)return null;let c=is(t,e,i);n.push({name:o,vertex:ns(t.slice(c,i),`vertex`),parameters:t.slice(s+1,a)}),r.add(o),i=a}return n}function ts(t){let{declaration:e,aliases:n,structures:r$6,attributes:i,attributeLocations:o,attributeNames:s$4,visitedStructures:a}=t,c=lu(e,`:`);if(c<1||c===e.length-1)return!1;let l=fu(e.slice(0,c)),f=Sr(e.slice(0,c),`location`),u=ns(e.slice(0,c),`builtin`),p=Mr(qt(e.slice(c+1)),n);if(!l||f===null||!p||f!==void 0&&u)return!1;if(f!==void 0){let g=cu(p);return!g||o.has(f)||s$4.has(l)?!1:(i.push({name:l,location:f,type:g}),o.add(f),s$4.add(l),!0)}if(u)return!0;let d=r$6.get(p);if(!d||a.has(p))return!1;let h=Xt(d,`,`);if(!h)return!1;a.add(p);for(let g of h)if(g.length>0&&!ts(s(r({},t),{declaration:g})))return!1;return a.delete(p),!0}function Mr(t,e,n=new Set){let r=es(t),i=``;for(let o of r){let s=e.get(o.value);if(!s){i+=au(o.value);continue}if(n.has(o.value))return null;let a=new Set(n);a.add(o.value);let c=Mr(s,e,a);if(!c)return null;i+=c}return i}function au(t){let e=/^(vec[234]|mat[234]x[234])([fiuh])$/.exec(t);if(!e)return t;let n={f:`f32`,i:`i32`,u:`u32`,h:`f16`}[e[2]];return`${e[1]}<${n}>`}function cu(t){return/^(?:i32|u32|f32|f16|vec[234]<(?:i32|u32|f32|f16)>)$/.test(t)?t:null}function Sr(t,e){let n;for(let r=0;r<t.length;r++)if(!(t[r].value!==`@`||t[r+1]?.value!==e)){if(n!==void 0||t[r+2]?.value!==`(`||!/^\d+$/.test(t[r+3]?.value||``)||t[r+4]?.value!==`)`)return null;n=Number(t[r+3].value)}return n}function ns(t,e){return t.some((n,r)=>n.value===`@`&&t[r+1]?.value===e)}function yr(t){return t.replace(`_`,`-`)}function Ar(t,e,n,r){let i=0;for(let o=e;o<t.length;o++)if(t[o].value===n)i++;else if(t[o].value===r&&--i===0)return o;return-1}function Xt(t,e){let n=[],r=0,i={"(":0,"<":0,"[":0,"{":0},o=Object.keys(i),s={")":`(`,">":`<`,"]":`[`,"}":`{`};for(let a=0;a<t.length;a++){let c=t[a].value;if(c===e&&o.every(l=>i[l]===0)){n.push(t.slice(r,a)),r=a+1;continue}if(c in i)i[c]++;else if(c in s){let l=s[c];if(i[l]--,i[l]<0)return null}}return o.every(a=>i[a]===0)?(n.push(t.slice(r)),n):null}function lu(t,e){let n=Xt(t,e);return n&&n.length===2?n[0].length:-1}function rs(t,e,n,r){for(let i=n;i<t.length;i++)if(e[i]===0&&t[i].value===r)return i;return-1}function is(t,e,n){for(let r=n-1;r>=0;r--)if(t[r].value===`;`&&e[r]===0||t[r].value===`}`&&e[r]===1)return r+1;return 0}function fu(t){for(let e=t.length-1;e>=0;e--)if(it(t[e].value))return t[e].value;return null}function qt(t){return t.map(e=>e.value).join(``)}function it(t){return!!(t&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t))}function ne(t,e){if(!t){let n=new Error(e||`shadertools: assertion failed.`);throw Error.captureStackTrace?.(n,ne),n}}var Er={number:{type:`number`,validate(t,e){return Number.isFinite(t)&&typeof e==`object`&&(e.max===void 0||t<=e.max)&&(e.min===void 0||t>=e.min)}},array:{type:`array`,validate(t,e){return Array.isArray(t)||ArrayBuffer.isView(t)}}};function ss(t){let e={};for(let[n,r]of Object.entries(t))e[n]=uu(r);return e}function uu(t){let e=os(t);if(e!==`object`)return s(r({value:t},Er[e]),{type:e});if(typeof t==`object`)return t?t.type!==void 0?s(r(r({},t),Er[t.type]),{type:t.type}):t.value===void 0?{type:`object`,value:t}:(e=os(t.value),s(r(r({},t),Er[e]),{type:e})):{type:`object`,value:null};throw new Error(`props`)}function os(t){return Array.isArray(t)||ArrayBuffer.isView(t)?`array`:typeof t}var pu={vertex:`#ifdef MODULE_LOGDEPTH
681
681
  logdepth_adjustPosition(gl_Position);
682
682
  #endif
683
683
  `,fragment:`#ifdef MODULE_MATERIAL
@@ -700,10 +700,10 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
700
700
  #ifdef MODULE_LOGDEPTH
701
701
  logdepth_setFragDepth();
702
702
  #endif
703
- `};var ls=/void\s+main\s*\([^)]*\)\s*\{\n?/;var fs=/}\n?[^{}]*$/;var Ar=[];var ot=`__LUMA_INJECT_DECLARATIONS__`;function us(t){let e={vertex:{},fragment:{}};for(let n in t){let r=t[n],i=du(n);typeof r==`string`&&(r={order:0,injection:r}),e[i][n]=r}return e}function du(t){let e=t.slice(0,2);switch(e){case`vs`:return`vertex`;case`fs`:return`fragment`;default:throw new Error(e)}}function st(t,e,n,r=!1,i=`glsl`,o={}){let s=e===`vertex`;for(let a in n){let c=n[a];c.sort((f,u)=>f.order-u.order),Ar.length=c.length;for(let f=0,u=c.length;f<u;++f)Ar[f]=c[f].injection;let l=`${Ar.join(`
703
+ `};var ls=/void\s+main\s*\([^)]*\)\s*\{\n?/;var fs=/}\n?[^{}]*$/;var Ir=[];var ot=`__LUMA_INJECT_DECLARATIONS__`;function us(t){let e={vertex:{},fragment:{}};for(let n in t){let r=t[n],i=du(n);typeof r==`string`&&(r={order:0,injection:r}),e[i][n]=r}return e}function du(t){let e=t.slice(0,2);switch(e){case`vs`:return`vertex`;case`fs`:return`fragment`;default:throw new Error(e)}}function st(t,e,n,r=!1,i=`glsl`,o={}){let s=e===`vertex`;for(let a in n){let c=n[a];c.sort((f,u)=>f.order-u.order),Ir.length=c.length;for(let f=0,u=c.length;f<u;++f)Ir[f]=c[f].injection;let l=`${Ir.join(`
704
704
  `)}
705
705
  `;switch(a){case`vs:#decl`:(i===`wgsl`||s)&&(t=t.replace(ot,l));break;case`vs:#main-start`:(i===`wgsl`||s)&&(t=i===`wgsl`?Zt(t,`vertex`,l,`start`,o.vertex):t.replace(ls,f=>f+l));break;case`vs:#main-end`:(i===`wgsl`||s)&&(t=i===`wgsl`?Zt(t,`vertex`,l,`end`,o.vertex):t.replace(fs,f=>l+f));break;case`fs:#decl`:(i===`wgsl`||!s)&&(t=t.replace(ot,l));break;case`fs:#main-start`:(i===`wgsl`||!s)&&(t=i===`wgsl`?Zt(t,`fragment`,l,`start`,o.fragment):t.replace(ls,f=>f+l));break;case`fs:#main-end`:(i===`wgsl`||!s)&&(t=i===`wgsl`?Zt(t,`fragment`,l,`end`,o.fragment):t.replace(fs,f=>l+f));break;default:t=t.replace(a,f=>f+l)}}return t=t.replace(ot,``),r&&(t=t.replace(/\}\s*$/,a=>a+pu[e])),t}function Zt(t,e,n,r,i){let o=hu(t,e,i);if(!o)return t;if(r===`start`){let s=o.openBraceIndex+1;return`${t.slice(0,s)}
706
- ${n}${t.slice(s)}`}return`${t.slice(0,o.closeBraceIndex)}${n}${t.slice(o.closeBraceIndex)}`}function hu(t,e,n){let r=e===`vertex`?`@vertex`:`@fragment`,i=t.indexOf(r);if(i<0)return null;let o=n?t.search(new RegExp(`\\bfn\\s+${mu(n)}\\s*\\(`)):t.indexOf(`fn`,i);if(o<0)return null;let s=t.indexOf(`{`,o);if(s<0)return null;let a=0;for(let c=s;c<t.length;c++){let l=t[c];if(l===`{`)a++;else if(l===`}`&&(a--,a===0))return{openBraceIndex:s,closeBraceIndex:c}}return null}function mu(t){return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ne(t){t.map(e=>gu(e))}function gu(t){if(t.instance)return;Ne(t.dependencies||[]);let{propTypes:e={},deprecations:n=[],inject:r$7={}}=t,i={normalizedInjections:us(r$7),parsedDeprecations:bu(n)};e&&(i.propValidators=ss(e)),t.instance=i;let o={};e&&(o=Object.entries(e).reduce((s,[a,c])=>{let l=c?.value;return l&&(s[a]=l),s},{})),t.defaultUniforms=r(r({},t.defaultUniforms),o)}function Er(t,e,n){t.deprecations?.forEach(r=>{r.regex?.test(e)&&(r.deprecated?n.deprecated(r.old,r.new)():n.removed(r.old,r.new)())})}function bu(t){return t.forEach(e=>{e.type===`function`?e.regex=new RegExp(`\\b${e.old}\\(`):e.regex=new RegExp(`${e.type} ${e.old};`)}),t}function _e(t){Ne(t);let e={},n={};ps({modules:t,level:0,moduleMap:e,moduleDepth:n});let r=Object.keys(n).sort((i,o)=>n[o]-n[i]).map(i=>e[i]);return Ne(r),r}function ps(t){let{modules:e,level:n,moduleMap:r,moduleDepth:i}=t;if(n>=5)throw new Error(`Possible loop in shader dependency graph`);for(let o of e)r[o.name]=o,(i[o.name]===void 0||i[o.name]<n)&&(i[o.name]=n);for(let o of e)o.dependencies&&ps({modules:o.dependencies,level:n+1,moduleMap:r,moduleDepth:i})}var _u=/^(vs|fs):(?:#(?:decl|main-start|main-end)|[A-Za-z_][\w-]*)$/;function at(t=[],e){let n=[],r={},i={},o={},s={};for(let a of t)ds({modules:n,defines:r,injections:i,vertexInputs:o,varyings:s},a),ds({modules:n,defines:r,injections:i,vertexInputs:o,varyings:s},a[e]);for(let a of Object.keys(s))if(o[a])throw new Error(`ShaderPlugin name "${a}" cannot be both a vertex input and a varying`);return{modules:n,defines:r,injections:i,vertexInputs:o,varyings:s}}function ct(t=[],e=[]){let n=[...t],r=new Set(n.map(i=>i.name));for(let i of e)r.has(i.name)||(n.push(i),r.add(i.name));return n}function ds(t,e){if(e){e.modules?.length&&t.modules.push(...e.modules),e.defines&&Object.assign(t.defines,e.defines);for(let[n,r]of Object.entries(e.vertexInputs||{})){hs(n,`vertex input`);let i=t.vertexInputs[n];if(i&&i!==r)throw new Error(`ShaderPlugin vertex input "${n}" has conflicting types "${i}" and "${r}"`);t.vertexInputs[n]=r}for(let[n,r]of Object.entries(e.varyings||{})){hs(n,`varying`);let i=vu(n,r),o=t.varyings[n];if(o&&(o.type!==i.type||o.interpolation!==i.interpolation))throw new Error(`ShaderPlugin varying "${n}" has conflicting declarations "${o.type}/${o.interpolation}" and "${i.type}/${i.interpolation}"`);t.varyings[n]=i}for(let n of e.injections||[])xu(n.target),t.injections[n.target]||(t.injections[n.target]=[]),t.injections[n.target].push({injection:n.injection,order:n.order??0})}}function hs(t,e){if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)||t.startsWith(`_luma_`))throw new Error(`ShaderPlugin ${e} "${t}" must be a valid non-reserved identifier`)}function vu(t,e){let{primitiveType:n}=J$1.getAttributeShaderTypeInfo(e.type),r=n===`i32`||n===`u32`,i=e.interpolation||(r?`flat`:`smooth`);if(r&&i===`smooth`)throw new Error(`ShaderPlugin integer varying "${t}" must use flat interpolation`);return{type:e.type,interpolation:i}}function xu(t){if(!_u.test(t))throw new Error(`ShaderPlugin injection target "${t}" must be a named shader anchor or hook`)}var Su=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/;var yu=/((?:layout\s*\([^)]*\)\s*)*)uniform\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}\s*([A-Za-z_][A-Za-z0-9_]*)?\s*;/g;function lt(t){return`${t.name}Uniforms`}function gs(t,e){let n=e===`wgsl`?t.source:e===`vertex`?t.vs:t.fs;if(!n)return null;let r=lt(t);return Mu(n,e===`wgsl`?`wgsl`:`glsl`,r)}function bs(t,e){let n=Object.keys(t.uniformTypes||{});if(!n.length)return null;let r=gs(t,e);return r?{moduleName:t.name,uniformBlockName:lt(t),stage:e,expectedUniformNames:n,actualUniformNames:r,matches:Iu(n,r)}:null}function Ir(t,e,n={}){let r=bs(t,e);if(!r||r.matches)return r;let i=Lu(r);return n.log?.error?.(i,r)(),n.throwOnError!==!1&&te(!1,i),r}function ft(t){let e=[],n=Ru(t);for(let r of n.matchAll(yu)){let i=r[1]?.trim()||null;e.push({blockName:r[2],body:r[3],instanceName:r[4]||null,layoutQualifier:i,hasLayoutQualifier:!!i,isStd140:!!(i&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(i))})}return e}function Lr(t,e,n,r){let i=ft(t).filter(s=>!s.isStd140),o=new Set;for(let s of i){if(o.has(s.blockName))continue;o.add(s.blockName);let a=r?.label?`${r.label} `:``,c=s.hasLayoutQualifier?`declares ${wu(s.layoutQualifier)} instead of layout(std140)`:`does not declare layout(std140)`,l=`${a}${e} shader uniform block ${s.blockName} ${c}. luma.gl host-side shader block packing assumes explicit layout(std140) for GLSL uniform blocks. Add \`layout(std140)\` to the block declaration.`;n?.warn?.(l,s)()}return i}function Mu(t,e,n){let r=e===`wgsl`?Au(t,n):Eu(t,n);if(!r)return null;let i=[];for(let o of r.split(`
706
+ ${n}${t.slice(s)}`}return`${t.slice(0,o.closeBraceIndex)}${n}${t.slice(o.closeBraceIndex)}`}function hu(t,e,n){let r=e===`vertex`?`@vertex`:`@fragment`,i=t.indexOf(r);if(i<0)return null;let o=n?t.search(new RegExp(`\\bfn\\s+${mu(n)}\\s*\\(`)):t.indexOf(`fn`,i);if(o<0)return null;let s=t.indexOf(`{`,o);if(s<0)return null;let a=0;for(let c=s;c<t.length;c++){let l=t[c];if(l===`{`)a++;else if(l===`}`&&(a--,a===0))return{openBraceIndex:s,closeBraceIndex:c}}return null}function mu(t){return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ne(t){t.map(e=>gu(e))}function gu(t){if(t.instance)return;Ne(t.dependencies||[]);let{propTypes:e={},deprecations:n=[],inject:r$7={}}=t,i={normalizedInjections:us(r$7),parsedDeprecations:bu(n)};e&&(i.propValidators=ss(e)),t.instance=i;let o={};e&&(o=Object.entries(e).reduce((s,[a,c])=>{let l=c?.value;return l&&(s[a]=l),s},{})),t.defaultUniforms=r(r({},t.defaultUniforms),o)}function Lr(t,e,n){t.deprecations?.forEach(r=>{r.regex?.test(e)&&(r.deprecated?n.deprecated(r.old,r.new)():n.removed(r.old,r.new)())})}function bu(t){return t.forEach(e=>{e.type===`function`?e.regex=new RegExp(`\\b${e.old}\\(`):e.regex=new RegExp(`${e.type} ${e.old};`)}),t}function _e(t){Ne(t);let e={},n={};ps({modules:t,level:0,moduleMap:e,moduleDepth:n});let r=Object.keys(n).sort((i,o)=>n[o]-n[i]).map(i=>e[i]);return Ne(r),r}function ps(t){let{modules:e,level:n,moduleMap:r,moduleDepth:i}=t;if(n>=5)throw new Error(`Possible loop in shader dependency graph`);for(let o of e)r[o.name]=o,(i[o.name]===void 0||i[o.name]<n)&&(i[o.name]=n);for(let o of e)o.dependencies&&ps({modules:o.dependencies,level:n+1,moduleMap:r,moduleDepth:i})}var _u=/^(vs|fs):(?:#(?:decl|main-start|main-end)|[A-Za-z_][\w-]*)$/;function at(t=[],e){let n=[],r={},i={},o={},s={};for(let a of t)ds({modules:n,defines:r,injections:i,vertexInputs:o,varyings:s},a),ds({modules:n,defines:r,injections:i,vertexInputs:o,varyings:s},a[e]);for(let a of Object.keys(s))if(o[a])throw new Error(`ShaderPlugin name "${a}" cannot be both a vertex input and a varying`);return{modules:n,defines:r,injections:i,vertexInputs:o,varyings:s}}function ct(t=[],e=[]){let n=[...t],r=new Set(n.map(i=>i.name));for(let i of e)r.has(i.name)||(n.push(i),r.add(i.name));return n}function ds(t,e){if(e){e.modules?.length&&t.modules.push(...e.modules),e.defines&&Object.assign(t.defines,e.defines);for(let[n,r]of Object.entries(e.vertexInputs||{})){hs(n,`vertex input`);let i=t.vertexInputs[n];if(i&&i!==r)throw new Error(`ShaderPlugin vertex input "${n}" has conflicting types "${i}" and "${r}"`);t.vertexInputs[n]=r}for(let[n,r]of Object.entries(e.varyings||{})){hs(n,`varying`);let i=vu(n,r),o=t.varyings[n];if(o&&(o.type!==i.type||o.interpolation!==i.interpolation))throw new Error(`ShaderPlugin varying "${n}" has conflicting declarations "${o.type}/${o.interpolation}" and "${i.type}/${i.interpolation}"`);t.varyings[n]=i}for(let n of e.injections||[])xu(n.target),t.injections[n.target]||(t.injections[n.target]=[]),t.injections[n.target].push({injection:n.injection,order:n.order??0})}}function hs(t,e){if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)||t.startsWith(`_luma_`))throw new Error(`ShaderPlugin ${e} "${t}" must be a valid non-reserved identifier`)}function vu(t,e){let{primitiveType:n}=J$1.getAttributeShaderTypeInfo(e.type),r=n===`i32`||n===`u32`,i=e.interpolation||(r?`flat`:`smooth`);if(r&&i===`smooth`)throw new Error(`ShaderPlugin integer varying "${t}" must use flat interpolation`);return{type:e.type,interpolation:i}}function xu(t){if(!_u.test(t))throw new Error(`ShaderPlugin injection target "${t}" must be a named shader anchor or hook`)}var Su=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/;var yu=/((?:layout\s*\([^)]*\)\s*)*)uniform\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}\s*([A-Za-z_][A-Za-z0-9_]*)?\s*;/g;function lt(t){return`${t.name}Uniforms`}function gs(t,e){let n=e===`wgsl`?t.source:e===`vertex`?t.vs:t.fs;if(!n)return null;let r=lt(t);return Mu(n,e===`wgsl`?`wgsl`:`glsl`,r)}function bs(t,e){let n=Object.keys(t.uniformTypes||{});if(!n.length)return null;let r=gs(t,e);return r?{moduleName:t.name,uniformBlockName:lt(t),stage:e,expectedUniformNames:n,actualUniformNames:r,matches:Iu(n,r)}:null}function Rr(t,e,n={}){let r=bs(t,e);if(!r||r.matches)return r;let i=Lu(r);return n.log?.error?.(i,r)(),n.throwOnError!==!1&&ne(!1,i),r}function ft(t){let e=[],n=Ru(t);for(let r of n.matchAll(yu)){let i=r[1]?.trim()||null;e.push({blockName:r[2],body:r[3],instanceName:r[4]||null,layoutQualifier:i,hasLayoutQualifier:!!i,isStd140:!!(i&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(i))})}return e}function wr(t,e,n,r){let i=ft(t).filter(s=>!s.isStd140),o=new Set;for(let s of i){if(o.has(s.blockName))continue;o.add(s.blockName);let a=r?.label?`${r.label} `:``,c=s.hasLayoutQualifier?`declares ${wu(s.layoutQualifier)} instead of layout(std140)`:`does not declare layout(std140)`,l=`${a}${e} shader uniform block ${s.blockName} ${c}. luma.gl host-side shader block packing assumes explicit layout(std140) for GLSL uniform blocks. Add \`layout(std140)\` to the block declaration.`;n?.warn?.(l,s)()}return i}function Mu(t,e,n){let r=e===`wgsl`?Au(t,n):Eu(t,n);if(!r)return null;let i=[];for(let o of r.split(`
707
707
  `)){let s=o.replace(/\/\/.*$/,``).trim();if(!s||s.startsWith(`#`))continue;let a=e===`wgsl`?s.match(/^([A-Za-z0-9_]+)\s*:/):s.match(Su);a&&i.push(a[1])}return i}function Au(t,e){let n=new RegExp(`\\bstruct\\s+${e}\\b`,`m`).exec(t);if(!n)return null;let r=t.indexOf(`{`,n.index);if(r<0)return null;let i=0;for(let o=r;o<t.length;o++){let s=t[o];if(s===`{`){i++;continue}if(s===`}`&&(i--,i===0))return t.slice(r+1,o)}return null}function Eu(t,e){return ft(t).find(r=>r.blockName===e)?.body||null}function Iu(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function Lu(t){let{expectedUniformNames:e,actualUniformNames:n}=t,r=e.filter(a=>!n.includes(a)),i=n.filter(a=>!e.includes(a)),o=[`Expected ${e.length} fields, found ${n.length}.`],s=Cu(e,n);return s&&o.push(s),r.length&&o.push(`Missing from shader block (${r.length}): ${ms(r)}.`),i.length&&o.push(`Unexpected in shader block (${i.length}): ${ms(i)}.`),e.length<=12&&n.length<=12&&(r.length||i.length)&&(o.push(`Expected: ${e.join(`, `)}.`),o.push(`Actual: ${n.join(`, `)}.`)),`${t.moduleName}: ${t.stage} shader uniform block ${t.uniformBlockName} does not match module.uniformTypes. ${o.join(` `)}`}function Ru(t){return t.replace(/\/\*[\s\S]*?\*\//g,``).replace(/\/\/.*$/gm,``)}function wu(t){return t.replace(/\s+/g,` `).trim()}function Cu(t,e){let n=Math.min(t.length,e.length);for(let r=0;r<n;r++)if(t[r]!==e[r])return`First mismatch at field ${r+1}: expected ${t[r]}, found ${e[r]}.`;return t.length>e.length?`Shader block ends after field ${e.length}; expected next field ${t[e.length]}.`:e.length>t.length?`Shader block has extra field ${e.length}: ${e[t.length]}.`:null}function ms(t,e=8){if(t.length<=e)return t.join(`, `);let n=t.length-e;return`${t.slice(0,e).join(`, `)}, ... (${n} more)`}function _s(t){switch(t?.gpu.toLowerCase()){case`apple`:return`#define APPLE_GPU
708
708
  // Apple optimizes away the calculation necessary for emulated fp64
709
709
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
@@ -729,13 +729,13 @@ ${n}${t.slice(s)}`}return`${t.slice(0,o.closeBraceIndex)}${n}${t.slice(o.closeBr
729
729
  // If the GPU doesn't have full 32 bits precision, will causes overflow
730
730
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
731
731
  `}}function xs(t,e){if(Number(t.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error(`luma.gl v9 only supports GLSL 3.00 shader sources`);switch(e){case`vertex`:return t=vs(t,Tu),t;case`fragment`:return t=vs(t,Pu),t;default:throw new Error(e)}}var Ss=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
732
- `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,`textureLod(`],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,`texture(`]];var Tu=[...Ss,[Rr(`attribute`),`in $1`],[Rr(`varying`),`out $1`]];var Pu=[...Ss,[Rr(`varying`),`in $1`]];function vs(t,e){for(let[n,r]of e)t=t.replace(n,r);return t}function Rr(t){return new RegExp(`\\b${t}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,`g`)}function Kt(t,e,n=`glsl`){let r=``;for(let i in t){let o=t[i];if(r+=`${n===`wgsl`?`fn`:`void`} ${o.signature} {
732
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,`textureLod(`],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,`texture(`]];var Tu=[...Ss,[Cr(`attribute`),`in $1`],[Cr(`varying`),`out $1`]];var Pu=[...Ss,[Cr(`varying`),`in $1`]];function vs(t,e){for(let[n,r]of e)t=t.replace(n,r);return t}function Cr(t){return new RegExp(`\\b${t}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,`g`)}function Kt(t,e,n=`glsl`){let r=``;for(let i in t){let o=t[i];if(r+=`${n===`wgsl`?`fn`:`void`} ${o.signature} {
733
733
  `,o.header&&(r+=` ${o.header}`),e[i]){let a=e[i];a.sort((c,l)=>c.order-l.order);for(let c of a)r+=` ${c.injection}
734
734
  `}o.footer&&(r+=` ${o.footer}`),r+=`}
735
- `}return r}function wr(t){let e={vertex:{},fragment:{}};for(let n of t){let r,i;typeof n!=`string`?(r=n,i=r.hook):(r={},i=n),i=i.trim();let o=i.indexOf(`:`),s=i.slice(0,o),a=i.slice(o+1),c=i.replace(/\(.+/,``),l=Object.assign(r,{signature:a});switch(s){case`vs`:e.vertex[c]=l;break;case`fs`:e.fragment[c]=l;break;default:throw new Error(s)}}return e}function ys(t,e){return{name:Nu(t,e),language:`glsl`,version:Bu(t)}}function Nu(t,e=`unnamed`){let r=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(t);return r?r[1]:e}function Bu(t){let e=100,n=t.match(/[^\s]+/g);if(n&&n.length>=2&&n[0]===`#version`){let r=parseInt(n[1],10);Number.isFinite(r)&&(e=r)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var Ms=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}\\s*:\\s*([^;]+);`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${Y}\\s*:\\s*([^;]+);`,`g`)];function Jt(t,e=[]){let n=Pe(t),r=new Map;for(let o of e)r.set(As(o.name,o.group,o.location),o.moduleName);let i=[];for(let o of Ms){o.lastIndex=0;let s;for(s=o.exec(n);s;){let a=o===Ms[0],c=Number(s[a?1:2]),l=Number(s[a?2:1]),f=s[3]?.trim(),u=s[4],p=s[5].trim(),d=r.get(As(u,l,c));i.push(Ou({name:u,group:l,binding:c,owner:d?`module`:`application`,moduleName:d,accessDeclaration:f,resourceType:p})),s=o.exec(n)}}return i.sort((o,s)=>o.group!==s.group?o.group-s.group:o.binding!==s.binding?o.binding-s.binding:o.name.localeCompare(s.name))}function Ou(t){let e={name:t.name,group:t.group,binding:t.binding,owner:t.owner,kind:`unknown`,moduleName:t.moduleName,resourceType:t.resourceType};if(t.accessDeclaration){let n=t.accessDeclaration.split(`,`).map(r=>r.trim());if(n[0]===`uniform`)return s(r({},e),{kind:`uniform`,access:`uniform`});if(n[0]===`storage`){let r$8=n[1]||`read_write`;return s(r({},e),{kind:r$8===`read`?`read-only-storage`:`storage`,access:r$8})}}return t.resourceType===`sampler`||t.resourceType===`sampler_comparison`?s(r({},e),{kind:`sampler`,samplerKind:t.resourceType===`sampler_comparison`?`comparison`:`filtering`}):t.resourceType.startsWith(`texture_storage_`)?s(r({},e),{kind:`storage-texture`,access:Fu(t.resourceType),viewDimension:Es(t.resourceType)}):t.resourceType.startsWith(`texture_`)?s(r({},e),{kind:`texture`,viewDimension:Es(t.resourceType),sampleType:Uu(t.resourceType),multisampled:t.resourceType.startsWith(`texture_multisampled_`)}):e}function As(t,e,n){return`${e}:${n}:${t}`}function Es(t){if(t.includes(`cube_array`))return`cube-array`;if(t.includes(`2d_array`))return`2d-array`;if(t.includes(`cube`))return`cube`;if(t.includes(`3d`))return`3d`;if(t.includes(`2d`))return`2d`;if(t.includes(`1d`))return`1d`}function Uu(t){if(t.startsWith(`texture_depth_`))return`depth`;if(t.includes(`<i32>`))return`sint`;if(t.includes(`<u32>`))return`uint`;if(t.includes(`<f32>`))return`float`}function Fu(t){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(t)?.[1]}var ve=`([a-zA-Z_][a-zA-Z0-9_]*)`;var Vu=/^\s*\#\s*if\s+(.+?)\s*(?:\/\/.*)?$/;var Du=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ve}\\s*$`);var ku=new RegExp(`^\\s*\\#\\s*ifndef\\s*${ve}\\s*(?:\\/\\/.*)?$`);var Gu=/^\s*\#\s*else\s*(?:\/\/.*)?$/;var zu=/^\s*\#\s*endif\s*$/;var $u=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ve}\\s*(?:\\/\\/.*)?$`);var Hu=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function xe(t,e){let n=t.split(`
735
+ `}return r}function Tr(t){let e={vertex:{},fragment:{}};for(let n of t){let r,i;typeof n!=`string`?(r=n,i=r.hook):(r={},i=n),i=i.trim();let o=i.indexOf(`:`),s=i.slice(0,o),a=i.slice(o+1),c=i.replace(/\(.+/,``),l=Object.assign(r,{signature:a});switch(s){case`vs`:e.vertex[c]=l;break;case`fs`:e.fragment[c]=l;break;default:throw new Error(s)}}return e}function ys(t,e){return{name:Nu(t,e),language:`glsl`,version:Bu(t)}}function Nu(t,e=`unnamed`){let r=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(t);return r?r[1]:e}function Bu(t){let e=100,n=t.match(/[^\s]+/g);if(n&&n.length>=2&&n[0]===`#version`){let r=parseInt(n[1],10);Number.isFinite(r)&&(e=r)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var Ms=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${Y}\\s*:\\s*([^;]+);`,`g`),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${Y}\\s*:\\s*([^;]+);`,`g`)];function Jt(t,e=[]){let n=Pe(t),r=new Map;for(let o of e)r.set(As(o.name,o.group,o.location),o.moduleName);let i=[];for(let o of Ms){o.lastIndex=0;let s;for(s=o.exec(n);s;){let a=o===Ms[0],c=Number(s[a?1:2]),l=Number(s[a?2:1]),f=s[3]?.trim(),u=s[4],p=s[5].trim(),d=r.get(As(u,l,c));i.push(Ou({name:u,group:l,binding:c,owner:d?`module`:`application`,moduleName:d,accessDeclaration:f,resourceType:p})),s=o.exec(n)}}return i.sort((o,s)=>o.group!==s.group?o.group-s.group:o.binding!==s.binding?o.binding-s.binding:o.name.localeCompare(s.name))}function Ou(t){let e={name:t.name,group:t.group,binding:t.binding,owner:t.owner,kind:`unknown`,moduleName:t.moduleName,resourceType:t.resourceType};if(t.accessDeclaration){let n=t.accessDeclaration.split(`,`).map(r=>r.trim());if(n[0]===`uniform`)return s(r({},e),{kind:`uniform`,access:`uniform`});if(n[0]===`storage`){let r$8=n[1]||`read_write`;return s(r({},e),{kind:r$8===`read`?`read-only-storage`:`storage`,access:r$8})}}return t.resourceType===`sampler`||t.resourceType===`sampler_comparison`?s(r({},e),{kind:`sampler`,samplerKind:t.resourceType===`sampler_comparison`?`comparison`:`filtering`}):t.resourceType.startsWith(`texture_storage_`)?s(r({},e),{kind:`storage-texture`,access:Fu(t.resourceType),viewDimension:Es(t.resourceType)}):t.resourceType.startsWith(`texture_`)?s(r({},e),{kind:`texture`,viewDimension:Es(t.resourceType),sampleType:Uu(t.resourceType),multisampled:t.resourceType.startsWith(`texture_multisampled_`)}):e}function As(t,e,n){return`${e}:${n}:${t}`}function Es(t){if(t.includes(`cube_array`))return`cube-array`;if(t.includes(`2d_array`))return`2d-array`;if(t.includes(`cube`))return`cube`;if(t.includes(`3d`))return`3d`;if(t.includes(`2d`))return`2d`;if(t.includes(`1d`))return`1d`}function Uu(t){if(t.startsWith(`texture_depth_`))return`depth`;if(t.includes(`<i32>`))return`sint`;if(t.includes(`<u32>`))return`uint`;if(t.includes(`<f32>`))return`float`}function Fu(t){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(t)?.[1]}var ve=`([a-zA-Z_][a-zA-Z0-9_]*)`;var Vu=/^\s*\#\s*if\s+(.+?)\s*(?:\/\/.*)?$/;var Du=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ve}\\s*$`);var ku=new RegExp(`^\\s*\\#\\s*ifndef\\s*${ve}\\s*(?:\\/\\/.*)?$`);var Gu=/^\s*\#\s*else\s*(?:\/\/.*)?$/;var zu=/^\s*\#\s*endif\s*$/;var $u=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ve}\\s*(?:\\/\\/.*)?$`);var Hu=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function xe(t,e){let n=t.split(`
736
736
  `),r=[],i=[],o=!0;for(let s of n){let a=s.match(Vu),c=s.match($u)||s.match(Du),l=s.match(ku),f=s.match(Gu),u=s.match(Hu)||s.match(zu);if(a){let p=Wu(a[1],e?.defines||{}),d=o&&p;i.push({parentActive:o,branchTaken:p,active:d}),o=d}else if(c||l){let p=(c||l)?.[1],d=!!e?.defines?.[p],h=c?d:!d,g=o&&h;i.push({parentActive:o,branchTaken:h,active:g}),o=g}else if(f){let p=i[i.length-1];if(!p)throw new Error(`Encountered #else without matching #if, #ifdef or #ifndef`);p.active=p.parentActive&&!p.branchTaken,p.branchTaken=!0,o=p.active}else u?(i.pop(),o=i.length?i[i.length-1].active:!0):o&&r.push(s)}if(i.length>0)throw new Error(`Unterminated conditional block in shader source`);return r.join(`
737
737
  `)}function Wu(t,e){let n=t.trim();if(/^[+-]?\d+(?:\.\d+)?$/.test(n))return Number(n)!==0;if(n===`true`)return!0;if(n===`false`)return!1;let r=n.match(new RegExp(`^!\\s*${ve}$`));if(r)return!e[r[1]];let i=n.match(new RegExp(`^${ve}$`));if(i)return!!e[i[1]];let o=n.match(new RegExp(`^defined\\s*\\(\\s*${ve}\\s*\\)$`));if(o)return e[o[1]]!==void 0;let s=n.match(new RegExp(`^!\\s*defined\\s*\\(\\s*${ve}\\s*\\)$`));if(s)return e[s[1]]===void 0;throw new Error(`Unsupported #if expression "${t}"`)}function Rs(t,e){let n=[];for(let[r,i]of Object.entries(e))ju(t,r),n.push(`in ${Qt(i)} ${r};`);return n.join(`
738
- `)}function ws(t,e,n){let r=Object.entries(n);if(r.length===0)return{source:t,declarations:``,initialization:``};let i=qu(t,e),o=t.slice(i.openParenthesis+1,i.closeParenthesis),s=Yu(t,o),a=new Set(s.locations),c=[],l=[],f=[];for(let[g,m]of r){if(s.names.has(g)||Ku(t,g))throw new Error(`ShaderPlugin vertex input "${g}" conflicts with an existing WGSL shader input or variable`);let _=Ju(a);a.add(_);let S=`_luma_${g}`;c.push(`@location(${_}) ${S}: ${m}`),l.push(`var<private> ${g}: ${m};`),f.push(`${g} = ${S};`)}let u=o.trim()?`,
738
+ `)}function ws(t,e,n){let r=Object.entries(n);if(r.length===0)return{source:t,declarations:``,initialization:``};let i=qu(t,e),o=t.slice(i.openParenthesis+1,i.closeParenthesis),s=Yu(t,o),a=new Set(s.locations),c=[],l=[],f=[];for(let[g,m]of r){if(s.names.has(g)||Ku(t,g))throw new Error(`ShaderPlugin vertex input "${g}" conflicts with an existing WGSL shader input or variable`);let v=Ju(a);a.add(v);let S=`_luma_${g}`;c.push(`@location(${v}) ${S}: ${m}`),l.push(`var<private> ${g}: ${m};`),f.push(`${g} = ${S};`)}let u=o.trim()?`,
739
739
  `:`
740
740
  `,p=o.trim()?``:`
741
741
  `,d=`${o}${u}${c.join(`,
@@ -745,25 +745,25 @@ ${n}${t.slice(s)}`}return`${t.slice(0,o.closeBraceIndex)}${n}${t.slice(o.closeBr
745
745
  `&&(s=!1);continue}if(o>0){c===`/`&&l===`*`?(o++,a++):c===`*`&&l===`/`&&(o--,a++);continue}if(c===`/`&&l===`/`){s=!0,a++;continue}if(c===`/`&&l===`*`){o=1,a++;continue}if(c===n&&i++,c===r&&--i===0)return a}return-1}function Qu(t,e){let n=0,r=0,i=!1;for(let o=0;o<e;o++){let s=t[o],a=t[o+1];if(i){s===`
746
746
  `&&(i=!1);continue}if(r>0){s===`/`&&a===`*`?(r++,o++):s===`*`&&a===`/`&&(r--,o++);continue}s===`/`&&a===`/`?(i=!0,o++):s===`/`&&a===`*`?(r=1,o++):s===`{`?n++:s===`}`&&n--}return n}function en(t){return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ps(t,e,n){let r=[],i=[];for(let[o,s]of Object.entries(n)){pp(t,o);let a=s.interpolation===`flat`?`flat `:``,c=e===`vertex`?`out`:`in`;r.push(`${a}${c} ${Qt(s.type)} ${o};`),e===`vertex`&&i.push(`${o} = ${fp(s.type)};`)}return{declarations:r.join(`
747
747
  `),initialization:i.join(`
748
- `)}}function Ns(t,e,n,r){let i=Object.entries(r);if(i.length===0)return{source:t,declarations:``,vertexInitialization:``,fragmentInitialization:``};let o=t,s=tn(o,e,`vertex`),a=ep(o,s),c=tn(o,n,`fragment`),l=tp(o,c),f=Cr(o,a),u=Cr(o,l.type),p=new Set([...nn(s.parameters),...nn(f.body),...nn(c.parameters),...nn(u.body)]),d=new Set([...Ts(f.body),...Ts(u.body)]),h=[],g=[],m=[],_=[];for(let[x,M]of i){if(p.has(x)||cp(o,x))throw new Error(`ShaderPlugin varying "${x}" conflicts with existing WGSL stage I/O or a module variable`);let I=lp(d);d.add(I);let L=M.interpolation===`flat`?` @interpolate(flat)`:``;h.push(` @location(${I})${L} ${x}: ${M.type},`),g.push(`var<private> ${x}: ${M.type};`),m.push(`${x} = ${up(M.type)};`),_.push(`${x} = ${l.name}.${x};`)}np(o,a,s.openBrace,s.closeBrace),o=rp(o,a,s,i.map(([x])=>x)),s=tn(o,e,`vertex`),o=ip(o,s,i.map(([x])=>x));let y=(a===l.type?[a]:[a,l.type]).map(x=>Cr(o,x).closeBrace).sort((x,M)=>M-x);for(let x of y)o=o.slice(0,x)+`${h.join(`
748
+ `)}}function Ns(t,e,n,r){let i=Object.entries(r);if(i.length===0)return{source:t,declarations:``,vertexInitialization:``,fragmentInitialization:``};let o=t,s=tn(o,e,`vertex`),a=ep(o,s),c=tn(o,n,`fragment`),l=tp(o,c),f=Pr(o,a),u=Pr(o,l.type),p=new Set([...nn(s.parameters),...nn(f.body),...nn(c.parameters),...nn(u.body)]),d=new Set([...Ts(f.body),...Ts(u.body)]),h=[],g=[],m=[],v=[];for(let[x,M]of i){if(p.has(x)||cp(o,x))throw new Error(`ShaderPlugin varying "${x}" conflicts with existing WGSL stage I/O or a module variable`);let I=lp(d);d.add(I);let L=M.interpolation===`flat`?` @interpolate(flat)`:``;h.push(` @location(${I})${L} ${x}: ${M.type},`),g.push(`var<private> ${x}: ${M.type};`),m.push(`${x} = ${up(M.type)};`),v.push(`${x} = ${l.name}.${x};`)}np(o,a,s.openBrace,s.closeBrace),o=rp(o,a,s,i.map(([x])=>x)),s=tn(o,e,`vertex`),o=ip(o,s,i.map(([x])=>x));let y=(a===l.type?[a]:[a,l.type]).map(x=>Pr(o,x).closeBrace).sort((x,M)=>M-x);for(let x of y)o=o.slice(0,x)+`${h.join(`
749
749
  `)}
750
750
  `+o.slice(x);if(c=tn(o,n,`fragment`),!new RegExp(`\\b${Se(l.name)}\\s*:`).test(c.parameters))throw new Error(`Unable to preserve WGSL fragment input "${l.name}"`);return{source:o,declarations:g.join(`
751
751
  `),vertexInitialization:m.join(`
752
- `),fragmentInitialization:_.join(`
753
- `)}}function tn(t,e,n){let i=new RegExp(`\\bfn\\s+${Se(e)}\\s*\\(`,`g`).exec(t);if(!i)throw new Error(`ShaderPlugin varyings require WGSL ${n} entry point "${e}"`);let o=t.indexOf(`(`,i.index),s=rn(t,o,`(`,`)`),a=t.indexOf(`{`,s),c=rn(t,a,`{`,`}`);if(s<0||a<0||c<0)throw new Error(`Unable to parse WGSL ${n} entry point "${e}"`);return{openParenthesis:o,closeParenthesis:s,openBrace:a,closeBrace:c,parameters:t.slice(o+1,s)}}function ep(t,e){let n=t.slice(e.closeParenthesis+1,e.openBrace),r=/->\s*([A-Za-z_][\w]*)\s*$/.exec(n.trim());if(!r||Tr(t,r[1])===null)throw new Error(`ShaderPlugin varyings require the WGSL vertex entry point to return a named struct`);return r[1]}function tp(t,e){let n=[];for(let r of ap(e.parameters,`,`)){let i=/(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:\s*([A-Za-z_][\w]*)\s*$/.exec(r.trim());i&&Tr(t,i[2])&&n.push({name:i[1],type:i[2]})}if(n.length!==1)throw new Error(`ShaderPlugin varyings require exactly one named WGSL fragment input struct; found ${n.length}`);return n[0]}function Cr(t,e){let n=Tr(t,e);if(!n)throw new Error(`Unable to find WGSL stage I/O struct "${e}"`);return n}function Tr(t,e){let r=new RegExp(`\\bstruct\\s+${Se(e)}\\s*\\{`,`g`).exec(t);if(!r)return null;let i=t.indexOf(`{`,r.index),o=rn(t,i,`{`,`}`);return o<0?null:{openBrace:i,closeBrace:o,body:t.slice(i+1,o)}}function np(t,e,n,r){let i=new RegExp(`\\b${Se(e)}\\s*\\(`,`g`),o=i.exec(t);for(;o;){if(o.index<n||o.index>r)throw new Error(`ShaderPlugin varying output struct "${e}" is constructed outside the selected vertex entry point`);o=i.exec(t)}}function rp(t,e,n,r){let i=new RegExp(`\\b${Se(e)}\\s*\\(`,`g`),o=[],s=i.exec(t);for(;s;){if(s.index>n.openBrace&&s.index<n.closeBrace){let a=t.indexOf(`(`,s.index),c=rn(t,a,`(`,`)`);if(c<0||c>n.closeBrace)throw new Error(`Unable to parse WGSL output constructor "${e}"`);o.push({openParenthesis:a,closeParenthesis:c})}s=i.exec(t)}for(let a of o.sort((c,l)=>l.closeParenthesis-c.closeParenthesis)){let l=t.slice(a.openParenthesis+1,a.closeParenthesis).trim()?`, `:``;t=t.slice(0,a.closeParenthesis)+l+r.join(`, `)+t.slice(a.closeParenthesis)}return t}function ip(t,e,n){let r=op(t,e.openBrace+1,e.closeBrace);for(let i=r.length-1;i>=0;i--){let o=r[i],s=t.slice(o.expressionStart,o.semicolon).trim();if(!s)throw new Error(`ShaderPlugin varying vertex entry point cannot use an empty return`);let a=`_luma_vertexOutput${i}`,l=`{
752
+ `),fragmentInitialization:v.join(`
753
+ `)}}function tn(t,e,n){let i=new RegExp(`\\bfn\\s+${Se(e)}\\s*\\(`,`g`).exec(t);if(!i)throw new Error(`ShaderPlugin varyings require WGSL ${n} entry point "${e}"`);let o=t.indexOf(`(`,i.index),s=rn(t,o,`(`,`)`),a=t.indexOf(`{`,s),c=rn(t,a,`{`,`}`);if(s<0||a<0||c<0)throw new Error(`Unable to parse WGSL ${n} entry point "${e}"`);return{openParenthesis:o,closeParenthesis:s,openBrace:a,closeBrace:c,parameters:t.slice(o+1,s)}}function ep(t,e){let n=t.slice(e.closeParenthesis+1,e.openBrace),r=/->\s*([A-Za-z_][\w]*)\s*$/.exec(n.trim());if(!r||Nr(t,r[1])===null)throw new Error(`ShaderPlugin varyings require the WGSL vertex entry point to return a named struct`);return r[1]}function tp(t,e){let n=[];for(let r of ap(e.parameters,`,`)){let i=/(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:\s*([A-Za-z_][\w]*)\s*$/.exec(r.trim());i&&Nr(t,i[2])&&n.push({name:i[1],type:i[2]})}if(n.length!==1)throw new Error(`ShaderPlugin varyings require exactly one named WGSL fragment input struct; found ${n.length}`);return n[0]}function Pr(t,e){let n=Nr(t,e);if(!n)throw new Error(`Unable to find WGSL stage I/O struct "${e}"`);return n}function Nr(t,e){let r=new RegExp(`\\bstruct\\s+${Se(e)}\\s*\\{`,`g`).exec(t);if(!r)return null;let i=t.indexOf(`{`,r.index),o=rn(t,i,`{`,`}`);return o<0?null:{openBrace:i,closeBrace:o,body:t.slice(i+1,o)}}function np(t,e,n,r){let i=new RegExp(`\\b${Se(e)}\\s*\\(`,`g`),o=i.exec(t);for(;o;){if(o.index<n||o.index>r)throw new Error(`ShaderPlugin varying output struct "${e}" is constructed outside the selected vertex entry point`);o=i.exec(t)}}function rp(t,e,n,r){let i=new RegExp(`\\b${Se(e)}\\s*\\(`,`g`),o=[],s=i.exec(t);for(;s;){if(s.index>n.openBrace&&s.index<n.closeBrace){let a=t.indexOf(`(`,s.index),c=rn(t,a,`(`,`)`);if(c<0||c>n.closeBrace)throw new Error(`Unable to parse WGSL output constructor "${e}"`);o.push({openParenthesis:a,closeParenthesis:c})}s=i.exec(t)}for(let a of o.sort((c,l)=>l.closeParenthesis-c.closeParenthesis)){let l=t.slice(a.openParenthesis+1,a.closeParenthesis).trim()?`, `:``;t=t.slice(0,a.closeParenthesis)+l+r.join(`, `)+t.slice(a.closeParenthesis)}return t}function ip(t,e,n){let r=op(t,e.openBrace+1,e.closeBrace);for(let i=r.length-1;i>=0;i--){let o=r[i],s=t.slice(o.expressionStart,o.semicolon).trim();if(!s)throw new Error(`ShaderPlugin varying vertex entry point cannot use an empty return`);let a=`_luma_vertexOutput${i}`,l=`{
754
754
  var ${a} = ${s};
755
755
  ${n.map(f=>`${a}.${f} = ${f};`).join(`
756
756
  `)}
757
757
  return ${a};
758
- }`;t=t.slice(0,o.start)+l+t.slice(o.semicolon+1)}return t}function op(t,e,n){let r=[],i=e;for(;i<n;)if(i=Pr(t,i,n),t.slice(i,i+6)===`return`&&!/[A-Za-z0-9_]/.test(t[i+6]||``)){let o=i+6,s=sp(t,o,n);if(s<0)throw new Error(`Unable to parse WGSL return statement in selected vertex entry point`);r.push({start:i,expressionStart:o,semicolon:s}),i=s+1}else i++;return r}function sp(t,e,n){let r=0,i=0;for(let o=e;o<n;o++){let s=Pr(t,o,n);if(s!==o){o=s-1;continue}let a=t[o];if(a===`(`&&r++,a===`)`&&r--,a===`[`&&i++,a===`]`&&i--,a===`;`&&r===0&&i===0)return o}return-1}function Pr(t,e,n){let r=e;if(t[r]===`/`&&t[r+1]===`/`){let i=t.indexOf(`
758
+ }`;t=t.slice(0,o.start)+l+t.slice(o.semicolon+1)}return t}function op(t,e,n){let r=[],i=e;for(;i<n;)if(i=Br(t,i,n),t.slice(i,i+6)===`return`&&!/[A-Za-z0-9_]/.test(t[i+6]||``)){let o=i+6,s=sp(t,o,n);if(s<0)throw new Error(`Unable to parse WGSL return statement in selected vertex entry point`);r.push({start:i,expressionStart:o,semicolon:s}),i=s+1}else i++;return r}function sp(t,e,n){let r=0,i=0;for(let o=e;o<n;o++){let s=Br(t,o,n);if(s!==o){o=s-1;continue}let a=t[o];if(a===`(`&&r++,a===`)`&&r--,a===`[`&&i++,a===`]`&&i--,a===`;`&&r===0&&i===0)return o}return-1}function Br(t,e,n){let r=e;if(t[r]===`/`&&t[r+1]===`/`){let i=t.indexOf(`
759
759
  `,r+2);return i<0||i>n?n:i+1}if(t[r]===`/`&&t[r+1]===`*`){let i=1;for(r+=2;r<n&&i>0;)t[r]===`/`&&t[r+1]===`*`?(i++,r+=2):t[r]===`*`&&t[r+1]===`/`?(i--,r+=2):r++}return r}function ap(t,e){let n=[],r=0,i=0,o=0;for(let s=0;s<t.length;s++){let a=t[s];a===`(`&&i++,a===`)`&&i--,a===`<`&&o++,a===`>`&&o--,a===e&&i===0&&o===0&&(n.push(t.slice(r,s)),r=s+1)}return n.push(t.slice(r)),n}function Ts(t){let e=[],n=/@location\s*\(\s*(\d+)\s*\)/g,r=n.exec(t);for(;r;)e.push(Number(r[1])),r=n.exec(t);return e}function nn(t){let e=[],n=/(?:^|,)\s*(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:/gm,r=n.exec(t);for(;r;)e.push(r[1]),r=n.exec(t);return e}function cp(t,e){let n=new RegExp(`\\b(?:var(?:<[^>]+>)?|let|const)\\s+${Se(e)}\\b`,`g`),r=n.exec(t);for(;r;){if(dp(t,r.index)===0)return!0;r=n.exec(t)}return!1}function lp(t){let e=0;for(;t.has(e);)e++;return e}function fp(t){let{primitiveType:e,components:n}=J$1.getAttributeShaderTypeInfo(t),r=e===`u32`?`0u`:e===`i32`?`0`:`0.0`;return n===1?r:`${Qt(t)}(${r})`}function up(t){let{primitiveType:e,components:n}=J$1.getAttributeShaderTypeInfo(t),r=`${e}(0)`;return n===1?r:`${t}(${r})`}function pp(t,e){if(new RegExp(`\\b(?:flat\\s+|smooth\\s+)?(?:in|out|varying)\\s+(?:(?:lowp|mediump|highp)\\s+)?[A-Za-z_][A-Za-z0-9_]*\\s+${Se(e)}\\s*(?:\\[|;)`).test(t))throw new Error(`ShaderPlugin varying "${e}" conflicts with existing GLSL stage I/O`)}function rn(t,e,n,r){let i=0,o=0,s=!1;for(let a=e;a<t.length;a++){let c=t[a],l=t[a+1];if(s){c===`
760
- `&&(s=!1);continue}if(o>0){c===`/`&&l===`*`?(o++,a++):c===`*`&&l===`/`&&(o--,a++);continue}if(c===`/`&&l===`/`){s=!0,a++;continue}if(c===`/`&&l===`*`){o=1,a++;continue}if(c===n&&i++,c===r&&--i===0)return a}return-1}function dp(t,e){let n=0;for(let r=0;r<e;r++){let i=Pr(t,r,e);if(i!==r){r=i-1;continue}t[r]===`{`&&n++,t[r]===`}`&&n--}return n}function Se(t){return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}var Nr=`
760
+ `&&(s=!1);continue}if(o>0){c===`/`&&l===`*`?(o++,a++):c===`*`&&l===`/`&&(o--,a++);continue}if(c===`/`&&l===`/`){s=!0,a++;continue}if(c===`/`&&l===`*`){o=1,a++;continue}if(c===n&&i++,c===r&&--i===0)return a}return-1}function dp(t,e){let n=0;for(let r=0;r<e;r++){let i=Br(t,r,e);if(i!==r){r=i-1;continue}t[r]===`{`&&n++,t[r]===`}`&&n--}return n}function Se(t){return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}var Or=`
761
761
 
762
762
  ${ot}
763
763
  `;var ut=100;var hp=`precision highp float;
764
- `;function Us(t){let e=_e(t.modules||[]),{source:n,bindingAssignments:r$9}=mp(t.platformInfo,s(r({},t),{source:t.source,stage:`vertex`,modules:e}));return{source:n,getUniforms:Vs(e),bindingAssignments:r$9,bindingTable:Jt(n,r$9),shaderLayout:Yt(n,{vertexEntryPoint:t.vertexEntryPoint,scanVertexAttributes:t.scanVertexAttributes})}}function Fs(t){let{vs:e,fs:n}=t,r$10=_e(t.modules||[]);return{vs:Bs(t.platformInfo,s(r({},t),{source:e,stage:`vertex`,modules:r$10})),fs:Bs(t.platformInfo,s(r({},t),{source:n,stage:`fragment`,modules:r$10})),getUniforms:Vs(r$10)}}function mp(t,e){let{source:n,stage:r,modules:i,defines:o={},hookFunctions:s=[],inject:a={},pluginInjections:c={},pluginVertexInputs:l={},pluginVaryings:f={},vertexEntryPoint:u=`vertexMain`,fragmentEntryPoint:p=`fragmentMain`,log:d}=e;te(typeof n==`string`,`shader source must be a string`);let g=ws(xe(n,{defines:o}),u,l),m=Ns(g.source,u,p,f),_=m.source,S=``,y=wr(s),v={},x={},M={};Ds(c,v,x,M);for(let w in a){let T=typeof a[w]==`string`?{injection:a[w],order:0}:a[w],C=/^(v|f)s:(#)?([\w-]+)$/.exec(w);if(C){let z=C[2],H=C[3];z?H===`decl`?x[w]=[T]:M[w]=[T]:v[w]=[T]}else M[w]=[T]}gp(g.declarations,g.initialization,x,M),bp(m,x,M);let I=i,L=Mp(_),P=yp(L.source),E=Lp(I,e._bindingRegistry,P,o),O=[];for(let w of I){d&&Er(w,_,d);let C=Ap(xe(ks(w,`wgsl`,d),{defines:o}),w,{usedBindingsByGroup:P,bindingRegistry:e._bindingRegistry,reservedBindingKeysByGroup:E});O.push(...C.bindingAssignments);let z=C.source;S+=z;let H=_p(w);for(let W in H){let He=/^(v|f)s:#([\w-]+)$/.exec(W);if(He){let yn=He[2]===`decl`?x:M;yn[W]=yn[W]||[],yn[W].push(H[W])}else v[W]=v[W]||[],v[W].push(H[W])}}return S+=Nr,S=st(S,r,vp(x),!1,`wgsl`,{vertex:u,fragment:p}),S+=xp(y,v),S+=Np(O),S+=L.source,S=st(S,r,M,!1,`wgsl`,{vertex:u,fragment:p}),Pp(S),{source:S,bindingAssignments:O}}function Bs(t,e){let{source:n,stage:r,language:i=`glsl`,modules:o,defines:s={},hookFunctions:a=[],inject:c={},pluginInjections:l={},pluginVertexInputs:f={},pluginVaryings:u={},prologue:p=!0,log:d}=e;te(typeof n==`string`,`shader source must be a string`);let h=i===`glsl`?ys(n).version:-1,g=t.shaderLanguageVersion,m=h===100?`#version 100`:`#version 300 es`,S=n.split(`
764
+ `;function Us(t){let e=_e(t.modules||[]),{source:n,bindingAssignments:r$9}=mp(t.platformInfo,s(r({},t),{source:t.source,stage:`vertex`,modules:e}));return{source:n,getUniforms:Vs(e),bindingAssignments:r$9,bindingTable:Jt(n,r$9),shaderLayout:Yt(n,{vertexEntryPoint:t.vertexEntryPoint,scanVertexAttributes:t.scanVertexAttributes})}}function Fs(t){let{vs:e,fs:n}=t,r$10=_e(t.modules||[]);return{vs:Bs(t.platformInfo,s(r({},t),{source:e,stage:`vertex`,modules:r$10})),fs:Bs(t.platformInfo,s(r({},t),{source:n,stage:`fragment`,modules:r$10})),getUniforms:Vs(r$10)}}function mp(t,e){let{source:n,stage:r,modules:i,defines:o={},hookFunctions:s=[],inject:a={},pluginInjections:c={},pluginVertexInputs:l={},pluginVaryings:f={},vertexEntryPoint:u=`vertexMain`,fragmentEntryPoint:p=`fragmentMain`,log:d}=e;ne(typeof n==`string`,`shader source must be a string`);let g=ws(xe(n,{defines:o}),u,l),m=Ns(g.source,u,p,f),v=m.source,S=``,y=Tr(s),_={},x={},M={};Ds(c,_,x,M);for(let w in a){let T=typeof a[w]==`string`?{injection:a[w],order:0}:a[w],C=/^(v|f)s:(#)?([\w-]+)$/.exec(w);if(C){let z=C[2],H=C[3];z?H===`decl`?x[w]=[T]:M[w]=[T]:_[w]=[T]}else M[w]=[T]}gp(g.declarations,g.initialization,x,M),bp(m,x,M);let I=i,L=Mp(v),P=yp(L.source),E=Lp(I,e._bindingRegistry,P,o),O=[];for(let w of I){d&&Lr(w,v,d);let C=Ap(xe(ks(w,`wgsl`,d),{defines:o}),w,{usedBindingsByGroup:P,bindingRegistry:e._bindingRegistry,reservedBindingKeysByGroup:E});O.push(...C.bindingAssignments);let z=C.source;S+=z;let H=_p(w);for(let W in H){let He=/^(v|f)s:#([\w-]+)$/.exec(W);if(He){let yn=He[2]===`decl`?x:M;yn[W]=yn[W]||[],yn[W].push(H[W])}else _[W]=_[W]||[],_[W].push(H[W])}}return S+=Or,S=st(S,r,vp(x),!1,`wgsl`,{vertex:u,fragment:p}),S+=xp(y,_),S+=Np(O),S+=L.source,S=st(S,r,M,!1,`wgsl`,{vertex:u,fragment:p}),Pp(S),{source:S,bindingAssignments:O}}function Bs(t,e){let{source:n,stage:r,language:i=`glsl`,modules:o,defines:s={},hookFunctions:a=[],inject:c={},pluginInjections:l={},pluginVertexInputs:f={},pluginVaryings:u={},prologue:p=!0,log:d}=e;ne(typeof n==`string`,`shader source must be a string`);let h=i===`glsl`?ys(n).version:-1,g=t.shaderLanguageVersion,m=h===100?`#version 100`:`#version 300 es`,S=n.split(`
765
765
  `).slice(1).join(`
766
- `),y={};o.forEach(E=>{Object.assign(y,E.defines)}),Object.assign(y,s);let v=``;switch(i){case`wgsl`:break;case`glsl`:v=p?`${m}
766
+ `),y={};o.forEach(E=>{Object.assign(y,E.defines)}),Object.assign(y,s);let _=``;switch(i){case`wgsl`:break;case`glsl`:_=p?`${m}
767
767
 
768
768
  // ----- PROLOGUE -------------------------
769
769
  ${`#define SHADER_TYPE_${r.toUpperCase()}`}
@@ -776,24 +776,24 @@ ${r===`fragment`?hp:``}
776
776
  ${Sp(y)}
777
777
 
778
778
  `:`${m}
779
- `;break}let x=wr(a),M={},I={},L={};Ds(l,M,I,L);for(let E in c){let O=typeof c[E]==`string`?{injection:c[E],order:0}:c[E],w=/^(v|f)s:(#)?([\w-]+)$/.exec(E);if(w){let T=w[2],C=w[3];T?C===`decl`?I[E]=[O]:L[E]=[O]:M[E]=[O]}else L[E]=[O]}if(r===`vertex`){let E=Rs(S,f);E&&(I[`vs:#decl`]=I[`vs:#decl`]||[],I[`vs:#decl`].push({injection:E,order:Number.MIN_SAFE_INTEGER}))}let P=Ps(S,r,u);if(P.declarations){let E=r===`vertex`?`vs:#decl`:`fs:#decl`;I[E]=I[E]||[],I[E].push({injection:P.declarations,order:Number.MIN_SAFE_INTEGER})}P.initialization&&(L[`vs:#main-start`]=L[`vs:#main-start`]||[],L[`vs:#main-start`].push({injection:P.initialization,order:Number.MIN_SAFE_INTEGER}));for(let E of o){d&&Er(E,S,d);let O=ks(E,r,d);v+=O;let w=E.instance?.normalizedInjections[r]||{};for(let T in w){let C=/^(v|f)s:#([\w-]+)$/.exec(T);if(C){let H=C[2]===`decl`?I:L;H[T]=H[T]||[],H[T].push(w[T])}else M[T]=M[T]||[],M[T].push(w[T])}}return v+=`// ----- MAIN SHADER SOURCE -------------------------`,v+=Nr,v=st(v,r,I),v+=Kt(x[r],M),v+=S,v=st(v,r,L),i===`glsl`&&h!==g&&(v=xs(v,r)),i===`glsl`&&Lr(v,r,d),v.trim()}function Vs(t){return function(n){let r={};for(let i of t){let o=i.getUniforms?.(n,r);Object.assign(r,o)}return r}}function Ds(t,e,n,r){for(let i in t){let o=/^(v|f)s:(#)?([\w-]+)$/.exec(i);if(o){let s=o[2],a=o[3],c=s?a===`decl`?n:r:e;c[i]=c[i]||[],c[i].push(...t[i])}else r[i]=r[i]||[],r[i].push(...t[i])}}function gp(t,e,n,r){t&&(n[`vs:#decl`]=n[`vs:#decl`]||[],n[`vs:#decl`].push({injection:t,order:Number.MIN_SAFE_INTEGER})),e&&(r[`vs:#main-start`]=r[`vs:#main-start`]||[],r[`vs:#main-start`].push({injection:e,order:Number.MIN_SAFE_INTEGER}))}function bp(t,e,n){t.declarations&&(e[`vs:#decl`]=e[`vs:#decl`]||[],e[`vs:#decl`].push({injection:t.declarations,order:Number.MIN_SAFE_INTEGER})),t.vertexInitialization&&(n[`vs:#main-start`]=n[`vs:#main-start`]||[],n[`vs:#main-start`].push({injection:t.vertexInitialization,order:Number.MIN_SAFE_INTEGER})),t.fragmentInitialization&&(n[`fs:#main-start`]=n[`fs:#main-start`]||[],n[`fs:#main-start`].push({injection:t.fragmentInitialization,order:Number.MIN_SAFE_INTEGER}))}function _p(t){return r(r({},t.instance?.normalizedInjections.vertex||{}),t.instance?.normalizedInjections.fragment||{})}function vp(t){let e=[...t[`vs:#decl`]||[],...t[`fs:#decl`]||[]];return e.length?{"vs:#decl":e}:{}}function xp(t,e){return Kt(t.vertex,e,`wgsl`)+Kt(t.fragment,e,`wgsl`)}function Sp(t={}){let e=``;for(let n in t){let r=t[n];(r||Number.isFinite(r))&&(e+=`#define ${n.toUpperCase()} ${t[n]}
780
- `)}return e}function ks(t,e,n){let r;switch(e){case`vertex`:r=t.vs||``;break;case`fragment`:r=t.fs||``;break;case`wgsl`:r=t.source||``;break;default:te(!1)}if(!t.name)throw new Error(`Shader module must have a name`);Ir(t,e,{log:n});let i=t.name.toUpperCase().replace(/[^0-9a-z]/gi,`_`),o=`// ----- MODULE ${t.name} ---------------
779
+ `}let x=Tr(a),M={},I={},L={};Ds(l,M,I,L);for(let E in c){let O=typeof c[E]==`string`?{injection:c[E],order:0}:c[E],w=/^(v|f)s:(#)?([\w-]+)$/.exec(E);if(w){let T=w[2],C=w[3];T?C===`decl`?I[E]=[O]:L[E]=[O]:M[E]=[O]}else L[E]=[O]}if(r===`vertex`){let E=Rs(S,f);E&&(I[`vs:#decl`]=I[`vs:#decl`]||[],I[`vs:#decl`].push({injection:E,order:Number.MIN_SAFE_INTEGER}))}let P=Ps(S,r,u);if(P.declarations){let E=r===`vertex`?`vs:#decl`:`fs:#decl`;I[E]=I[E]||[],I[E].push({injection:P.declarations,order:Number.MIN_SAFE_INTEGER})}P.initialization&&(L[`vs:#main-start`]=L[`vs:#main-start`]||[],L[`vs:#main-start`].push({injection:P.initialization,order:Number.MIN_SAFE_INTEGER}));for(let E of o){d&&Lr(E,S,d);let O=ks(E,r,d);_+=O;let w=E.instance?.normalizedInjections[r]||{};for(let T in w){let C=/^(v|f)s:#([\w-]+)$/.exec(T);if(C){let H=C[2]===`decl`?I:L;H[T]=H[T]||[],H[T].push(w[T])}else M[T]=M[T]||[],M[T].push(w[T])}}return _+=`// ----- MAIN SHADER SOURCE -------------------------`,_+=Or,_=st(_,r,I),_+=Kt(x[r],M),_+=S,_=st(_,r,L),i===`glsl`&&h!==g&&(_=xs(_,r)),i===`glsl`&&wr(_,r,d),_.trim()}function Vs(t){return function(n){let r={};for(let i of t){let o=i.getUniforms?.(n,r);Object.assign(r,o)}return r}}function Ds(t,e,n,r){for(let i in t){let o=/^(v|f)s:(#)?([\w-]+)$/.exec(i);if(o){let s=o[2],a=o[3],c=s?a===`decl`?n:r:e;c[i]=c[i]||[],c[i].push(...t[i])}else r[i]=r[i]||[],r[i].push(...t[i])}}function gp(t,e,n,r){t&&(n[`vs:#decl`]=n[`vs:#decl`]||[],n[`vs:#decl`].push({injection:t,order:Number.MIN_SAFE_INTEGER})),e&&(r[`vs:#main-start`]=r[`vs:#main-start`]||[],r[`vs:#main-start`].push({injection:e,order:Number.MIN_SAFE_INTEGER}))}function bp(t,e,n){t.declarations&&(e[`vs:#decl`]=e[`vs:#decl`]||[],e[`vs:#decl`].push({injection:t.declarations,order:Number.MIN_SAFE_INTEGER})),t.vertexInitialization&&(n[`vs:#main-start`]=n[`vs:#main-start`]||[],n[`vs:#main-start`].push({injection:t.vertexInitialization,order:Number.MIN_SAFE_INTEGER})),t.fragmentInitialization&&(n[`fs:#main-start`]=n[`fs:#main-start`]||[],n[`fs:#main-start`].push({injection:t.fragmentInitialization,order:Number.MIN_SAFE_INTEGER}))}function _p(t){return r(r({},t.instance?.normalizedInjections.vertex||{}),t.instance?.normalizedInjections.fragment||{})}function vp(t){let e=[...t[`vs:#decl`]||[],...t[`fs:#decl`]||[]];return e.length?{"vs:#decl":e}:{}}function xp(t,e){return Kt(t.vertex,e,`wgsl`)+Kt(t.fragment,e,`wgsl`)}function Sp(t={}){let e=``;for(let n in t){let r=t[n];(r||Number.isFinite(r))&&(e+=`#define ${n.toUpperCase()} ${t[n]}
780
+ `)}return e}function ks(t,e,n){let r;switch(e){case`vertex`:r=t.vs||``;break;case`fragment`:r=t.fs||``;break;case`wgsl`:r=t.source||``;break;default:ne(!1)}if(!t.name)throw new Error(`Shader module must have a name`);Rr(t,e,{log:n});let i=t.name.toUpperCase().replace(/[^0-9a-z]/gi,`_`),o=`// ----- MODULE ${t.name} ---------------
781
781
 
782
782
  `;return e!==`wgsl`&&(o+=`#define MODULE_${i}
783
783
  `),o+=`${r}
784
- `,o}function yp(t){let e=new Map;for(let n of be(t,Jo)){let r=Number(n.bindingToken),i=Number(n.groupToken);Br(i,r,n.name),Be(e,i,r,`application binding "${n.name}"`)}return e}function Mp(t){let e=be(t,jt),n=new Map;for(let o of e){if(o.bindingToken===`auto`)continue;let s=Number(o.bindingToken),a=Number(o.groupToken);Br(a,s,o.name),Be(n,a,s,`application binding "${o.name}"`)}let r={sawSupportedBindingDeclaration:e.length>0},i=br(t,jt,o=>Ip(o,n,r));if(_r(t)&&!r.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in application WGSL. Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:i}}function Ap(t,e,n){let r=[],o={sawSupportedBindingDeclaration:be(t,Te).length>0,nextHintedBindingLocation:typeof e.firstBindingSlot==`number`?e.firstBindingSlot:null},s=br(t,Te,a=>Ep(a,{module:e,context:n,bindingAssignments:r,relocationState:o}));if(_r(t)&&!o.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${e.name}". Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:s,bindingAssignments:r}}function Ep(t,e){let{module:n,context:r,bindingAssignments:i,relocationState:o}=e,{match:s,bindingToken:a,groupToken:c,name:l}=t,f=Number(c);if(a===`auto`){let p=Gs(f,n.name,l),d=r.bindingRegistry?.get(p),h=d!==void 0?d:Cp(f,r.usedBindingsByGroup,n.name,o.nextHintedBindingLocation??void 0,r.bindingRegistry);return Os(n.name,f,h,l),d!==void 0&&Rp(r.reservedBindingKeysByGroup,f,h,p)?(i.push({moduleName:n.name,name:l,group:f,location:h}),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${h})`)):(Be(r.usedBindingsByGroup,f,h,`module "${n.name}" binding "${l}"`),r.bindingRegistry?.set(p,h),i.push({moduleName:n.name,name:l,group:f,location:h}),o.nextHintedBindingLocation!==null&&d===void 0&&(o.nextHintedBindingLocation=h+1),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${h})`))}let u=Number(a);return Os(n.name,f,u,l),Be(r.usedBindingsByGroup,f,u,`module "${n.name}" binding "${l}"`),i.push({moduleName:n.name,name:l,group:f,location:u}),s}function Ip(t,e,n){let{match:r,bindingToken:i,groupToken:o,name:s}=t,a=Number(o);if(i===`auto`){let c=Tp(a,e);return Br(a,c,s),Be(e,a,c,`application binding "${s}"`),r.replace(/@binding\(\s*auto\s*\)/,`@binding(${c})`)}return n.sawSupportedBindingDeclaration=!0,r}function Lp(t,e,n,r){let i=new Map;if(!e)return i;for(let o of t)for(let s of wp(o,r)){let a=Gs(s.group,o.name,s.name),c=e.get(a);if(c!==void 0){let l=i.get(s.group)||new Map,f=l.get(c);if(f&&f!==a)throw new Error(`Duplicate WGSL binding reservation for modules "${f}" and "${a}": group ${s.group}, binding ${c}.`);Be(n,s.group,c,`registered module binding "${a}"`),l.set(c,a),i.set(s.group,l)}}return i}function Rp(t,e,n,r){let i=t.get(e);if(!i)return!1;let o=i.get(n);if(!o)return!1;if(o!==r)throw new Error(`Registered module binding "${r}" collided with "${o}": group ${e}, binding ${n}.`);return!0}function wp(t,e){let n=[],r=xe(t.source||``,{defines:e});for(let i of be(r,Te))n.push({name:i.name,group:Number(i.groupToken)});return n}function Br(t,e,n){if(t===0&&e>=ut)throw new Error(`Application binding "${n}" in group 0 uses reserved binding ${e}. Application-owned explicit group-0 bindings must stay below ${ut}.`)}function Os(t,e,n,r){if(e===0&&n<ut)throw new Error(`Module "${t}" binding "${r}" in group 0 uses reserved application binding ${n}. Module-owned explicit group-0 bindings must be ${ut} or higher.`)}function Be(t,e,n,r){let i=t.get(e)||new Set;if(i.has(n))throw new Error(`Duplicate WGSL binding assignment for ${r}: group ${e}, binding ${n}.`);i.add(n),t.set(e,i)}function Cp(t,e,n,r,i){let o=e.get(t)||new Set,s=new Set,a=`${t}:`,c=`${a}${n}:`;for(let[f,u]of i||[])f.startsWith(c)&&s.add(u);let l=r??(t===0?ut:o.size>0?Math.max(...o)+1:0);for(;o.has(l)||s.has(l);)l++;for(let[f,u]of i||[])u===l&&f.startsWith(a)&&i?.delete(f);return l}function Tp(t,e){let n=e.get(t)||new Set,r=0;for(;n.has(r);)r++;return r}function Pp(t){let e=Qo(t,Te);if(!e)return;let n=Bp(t,e.index);throw n?new Error(`Unresolved @binding(auto) for module "${n}" binding "${e.name}" remained in assembled WGSL source.`):Op(t,e.index)?new Error(`Unresolved @binding(auto) for application binding "${e.name}" remained in assembled WGSL source.`):new Error(`Unresolved @binding(auto) remained in assembled WGSL source near "${Up(e.match)}".`)}function Np(t){if(t.length===0)return``;let e=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
784
+ `,o}function yp(t){let e=new Map;for(let n of be(t,Jo)){let r=Number(n.bindingToken),i=Number(n.groupToken);Ur(i,r,n.name),Be(e,i,r,`application binding "${n.name}"`)}return e}function Mp(t){let e=be(t,jt),n=new Map;for(let o of e){if(o.bindingToken===`auto`)continue;let s=Number(o.bindingToken),a=Number(o.groupToken);Ur(a,s,o.name),Be(n,a,s,`application binding "${o.name}"`)}let r={sawSupportedBindingDeclaration:e.length>0},i=vr(t,jt,o=>Ip(o,n,r));if(xr(t)&&!r.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in application WGSL. Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:i}}function Ap(t,e,n){let r=[],o={sawSupportedBindingDeclaration:be(t,Te).length>0,nextHintedBindingLocation:typeof e.firstBindingSlot==`number`?e.firstBindingSlot:null},s=vr(t,Te,a=>Ep(a,{module:e,context:n,bindingAssignments:r,relocationState:o}));if(xr(t)&&!o.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${e.name}". Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:s,bindingAssignments:r}}function Ep(t,e){let{module:n,context:r,bindingAssignments:i,relocationState:o}=e,{match:s,bindingToken:a,groupToken:c,name:l}=t,f=Number(c);if(a===`auto`){let p=Gs(f,n.name,l),d=r.bindingRegistry?.get(p),h=d!==void 0?d:Cp(f,r.usedBindingsByGroup,n.name,o.nextHintedBindingLocation??void 0,r.bindingRegistry);return Os(n.name,f,h,l),d!==void 0&&Rp(r.reservedBindingKeysByGroup,f,h,p)?(i.push({moduleName:n.name,name:l,group:f,location:h}),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${h})`)):(Be(r.usedBindingsByGroup,f,h,`module "${n.name}" binding "${l}"`),r.bindingRegistry?.set(p,h),i.push({moduleName:n.name,name:l,group:f,location:h}),o.nextHintedBindingLocation!==null&&d===void 0&&(o.nextHintedBindingLocation=h+1),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${h})`))}let u=Number(a);return Os(n.name,f,u,l),Be(r.usedBindingsByGroup,f,u,`module "${n.name}" binding "${l}"`),i.push({moduleName:n.name,name:l,group:f,location:u}),s}function Ip(t,e,n){let{match:r,bindingToken:i,groupToken:o,name:s}=t,a=Number(o);if(i===`auto`){let c=Tp(a,e);return Ur(a,c,s),Be(e,a,c,`application binding "${s}"`),r.replace(/@binding\(\s*auto\s*\)/,`@binding(${c})`)}return n.sawSupportedBindingDeclaration=!0,r}function Lp(t,e,n,r){let i=new Map;if(!e)return i;for(let o of t)for(let s of wp(o,r)){let a=Gs(s.group,o.name,s.name),c=e.get(a);if(c!==void 0){let l=i.get(s.group)||new Map,f=l.get(c);if(f&&f!==a)throw new Error(`Duplicate WGSL binding reservation for modules "${f}" and "${a}": group ${s.group}, binding ${c}.`);Be(n,s.group,c,`registered module binding "${a}"`),l.set(c,a),i.set(s.group,l)}}return i}function Rp(t,e,n,r){let i=t.get(e);if(!i)return!1;let o=i.get(n);if(!o)return!1;if(o!==r)throw new Error(`Registered module binding "${r}" collided with "${o}": group ${e}, binding ${n}.`);return!0}function wp(t,e){let n=[],r=xe(t.source||``,{defines:e});for(let i of be(r,Te))n.push({name:i.name,group:Number(i.groupToken)});return n}function Ur(t,e,n){if(t===0&&e>=ut)throw new Error(`Application binding "${n}" in group 0 uses reserved binding ${e}. Application-owned explicit group-0 bindings must stay below ${ut}.`)}function Os(t,e,n,r){if(e===0&&n<ut)throw new Error(`Module "${t}" binding "${r}" in group 0 uses reserved application binding ${n}. Module-owned explicit group-0 bindings must be ${ut} or higher.`)}function Be(t,e,n,r){let i=t.get(e)||new Set;if(i.has(n))throw new Error(`Duplicate WGSL binding assignment for ${r}: group ${e}, binding ${n}.`);i.add(n),t.set(e,i)}function Cp(t,e,n,r,i){let o=e.get(t)||new Set,s=new Set,a=`${t}:`,c=`${a}${n}:`;for(let[f,u]of i||[])f.startsWith(c)&&s.add(u);let l=r??(t===0?ut:o.size>0?Math.max(...o)+1:0);for(;o.has(l)||s.has(l);)l++;for(let[f,u]of i||[])u===l&&f.startsWith(a)&&i?.delete(f);return l}function Tp(t,e){let n=e.get(t)||new Set,r=0;for(;n.has(r);)r++;return r}function Pp(t){let e=Qo(t,Te);if(!e)return;let n=Bp(t,e.index);throw n?new Error(`Unresolved @binding(auto) for module "${n}" binding "${e.name}" remained in assembled WGSL source.`):Op(t,e.index)?new Error(`Unresolved @binding(auto) for application binding "${e.name}" remained in assembled WGSL source.`):new Error(`Unresolved @binding(auto) remained in assembled WGSL source near "${Up(e.match)}".`)}function Np(t){if(t.length===0)return``;let e=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
785
785
  `;for(let n of t)e+=`// ${n.moduleName}.${n.name} -> @group(${n.group}) @binding(${n.location})
786
786
  `;return e+=`
787
- `,e}function Gs(t,e,n){return`${t}:${e}:${n}`}function Bp(t,e){let n=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,r,i;for(i=n.exec(t);i&&i.index<=e;)r=i[1],i=n.exec(t);return r}function Op(t,e){let n=t.indexOf(Nr);return n>=0?e>n:!0}function Up(t){return t.replace(/\s+/g,` `).trim()}var fe=(()=>{class t{static defaultShaderAssemblers={};_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(n){return te(n===`glsl`||n===`wgsl`),n===`wgsl`?(t.defaultShaderAssemblers.wgsl=t.defaultShaderAssemblers.wgsl||new Oe,t.defaultShaderAssemblers.wgsl):(t.defaultShaderAssemblers.glsl=t.defaultShaderAssemblers.glsl||new on,t.defaultShaderAssemblers.glsl)}addDefaultModule(n){this._defaultModules.find(r=>r.name===(typeof n==`string`?n:n.name))||this._defaultModules.push(n)}removeDefaultModule(n){let r=typeof n==`string`?n:n.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==r)}addShaderHook(n,r){r&&(n=Object.assign(r,{hook:n})),this._hookFunctions.push(n)}_getModuleList(n=[]){let r=new Array(this._defaultModules.length+n.length),i={},o=0;for(let s=0,a=this._defaultModules.length;s<a;++s){let c=this._defaultModules[s],l=c.name;r[o++]=c,i[l]=!0}for(let s=0,a=n.length;s<a;++s){let c=n[s],l=c.name;i[l]||(r[o++]=c,i[l]=!0)}return r.length=o,Ne(r),r}}return t})();var on=class extends fe{shaderLanguage=`glsl`;assembleGLSLShaderPair(e){let n=this._getModuleList(e.modules),r$11=this._hookFunctions;return s(r({},Fs(s(r({},e),{vs:e.vs,fs:e.fs,modules:n,hookFunctions:r$11}))),{modules:n})}};var Oe=class t extends fe{shaderLanguage=`wgsl`;_wgslBindingRegistry=new Map;assembleWGSLShader(e){let n=this._getModuleList(e.modules),r$12=this._hookFunctions,i=t.getShaderPreprocessorDefines(e,n),o=e.platformInfo.shaderLanguage===`wgsl`&&e.source?xe(e.source,{defines:i}):e.source,{source:s$5,getUniforms:a,bindingAssignments:c}=Us(s(r({},e),{source:o,defines:i,_bindingRegistry:this._wgslBindingRegistry,modules:n,hookFunctions:r$12})),l=e.platformInfo.shaderLanguage===`wgsl`?xe(s$5,{defines:i}):s$5;return{source:l,getUniforms:a,modules:n,bindingAssignments:c,bindingTable:Jt(l,c),shaderLayout:Yt(l,{vertexEntryPoint:e.vertexEntryPoint,scanVertexAttributes:e.scanVertexAttributes})}}static getShaderPreprocessorDefines(e,n){return r(r(r({},t.getPlatformPreprocessorDefines(e.platformInfo)),n.reduce((r,i)=>(Object.assign(r,i.defines),r),{})),e.defines)}static getPlatformPreprocessorDefines(e){let n=e.limits||{};return{LUMA_SUPPORTS_VERTEX_STORAGE_BUFFERS:e.type===`webgpu`&&(n.maxStorageBuffersInVertexStage||0)>0,LUMA_FP32_TAN_PRECISION_WORKAROUND:e.type===`webgpu`&&e.gpu.toLowerCase()!==`nvidia`&&e.gpu.toLowerCase()!==`amd`,LUMA_FP64_INTEGER_ARITHMETIC:e.type===`webgpu`&&e.gpu.toLowerCase()===`apple`}}};var Vp=`#version 300 es
787
+ `,e}function Gs(t,e,n){return`${t}:${e}:${n}`}function Bp(t,e){let n=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,r,i;for(i=n.exec(t);i&&i.index<=e;)r=i[1],i=n.exec(t);return r}function Op(t,e){let n=t.indexOf(Or);return n>=0?e>n:!0}function Up(t){return t.replace(/\s+/g,` `).trim()}var J=class t{static defaultShaderAssemblers={};_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(e){return ne(e===`glsl`||e===`wgsl`),e===`wgsl`?(t.defaultShaderAssemblers.wgsl=t.defaultShaderAssemblers.wgsl||new Oe,t.defaultShaderAssemblers.wgsl):(t.defaultShaderAssemblers.glsl=t.defaultShaderAssemblers.glsl||new on,t.defaultShaderAssemblers.glsl)}addDefaultModule(e){this._defaultModules.find(n=>n.name===(typeof e==`string`?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let n=typeof e==`string`?e:e.name;this._defaultModules=this._defaultModules.filter(r=>r.name!==n)}addShaderHook(e,n){n&&(e=Object.assign(n,{hook:e})),this._hookFunctions.push(e)}_getModuleList(e=[]){let n=new Array(this._defaultModules.length+e.length),r={},i=0;for(let o=0,s=this._defaultModules.length;o<s;++o){let a=this._defaultModules[o],c=a.name;n[i++]=a,r[c]=!0}for(let o=0,s=e.length;o<s;++o){let a=e[o],c=a.name;r[c]||(n[i++]=a,r[c]=!0)}return n.length=i,Ne(n),n}};var on=class extends J{shaderLanguage=`glsl`;assembleGLSLShaderPair(e){let n=this._getModuleList(e.modules),r$11=this._hookFunctions,i=Fs(s(r({},e),{vs:e.vs,fs:e.fs,modules:n,hookFunctions:r$11}));return s(r({},i),{modules:n})}};var Oe=class t extends J{shaderLanguage=`wgsl`;_wgslBindingRegistry=new Map;assembleWGSLShader(e){let n=this._getModuleList(e.modules),r$12=this._hookFunctions,i=t.getShaderPreprocessorDefines(e,n),o=e.platformInfo.shaderLanguage===`wgsl`&&e.source?xe(e.source,{defines:i}):e.source,{source:s$5,getUniforms:a,bindingAssignments:c}=Us(s(r({},e),{source:o,defines:i,_bindingRegistry:this._wgslBindingRegistry,modules:n,hookFunctions:r$12})),l=e.platformInfo.shaderLanguage===`wgsl`?xe(s$5,{defines:i}):s$5;return{source:l,getUniforms:a,modules:n,bindingAssignments:c,bindingTable:Jt(l,c),shaderLayout:Yt(l,{vertexEntryPoint:e.vertexEntryPoint,scanVertexAttributes:e.scanVertexAttributes})}}static getShaderPreprocessorDefines(e,n){return r(r(r({},t.getPlatformPreprocessorDefines(e.platformInfo)),n.reduce((r,i)=>(Object.assign(r,i.defines),r),{})),e.defines)}static getPlatformPreprocessorDefines(e){let n=e.limits||{};return{LUMA_SUPPORTS_VERTEX_STORAGE_BUFFERS:e.type===`webgpu`&&(n.maxStorageBuffersInVertexStage||0)>0,LUMA_FP32_TAN_PRECISION_WORKAROUND:e.type===`webgpu`&&e.gpu.toLowerCase()!==`nvidia`&&e.gpu.toLowerCase()!==`amd`,LUMA_FP64_INTEGER_ARITHMETIC:e.type===`webgpu`&&e.gpu.toLowerCase()===`apple`}}};var Vp=`#version 300 es
788
788
  out vec4 transform_output;
789
789
  void main() {
790
790
  transform_output = vec4(0);
791
- }`;function Or(t){let{input:e,inputChannels:n,output:r}=t||{};if(!e)return Vp;if(!n)throw new Error(`inputChannels`);return`#version 300 es
791
+ }`;function Fr(t){let{input:e,inputChannels:n,output:r}=t||{};if(!e)return Vp;if(!n)throw new Error(`inputChannels`);return`#version 300 es
792
792
  in ${Dp(n)} ${e};
793
793
  out vec4 ${r};
794
794
  void main() {
795
795
  ${r} = ${zs(e,n)};
796
- }`}function Dp(t){switch(t){case 1:return`float`;case 2:return`vec2`;case 3:return`vec3`;case 4:return`vec4`;default:throw new Error(`invalid channels: ${t}`)}}function zs(t,e){switch(e){case 1:return`vec4(${t}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${t}, 0.0, 1.0)`;case 3:return`vec4(${t}, 1.0)`;case 4:return t;default:throw new Error(`invalid channels: ${e}`)}}function Ur(t,e=[],n=0){let r=Math.fround(t),i=t-r;return e[n]=r,e[n+1]=i,e}function $s(t){return t-Math.fround(t)}function Hs(t){let e=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){let i=n*4+r;Ur(t[r*4+n],e,i*2)}return e}var Fr=`
796
+ }`}function Dp(t){switch(t){case 1:return`float`;case 2:return`vec2`;case 3:return`vec3`;case 4:return`vec4`;default:throw new Error(`invalid channels: ${t}`)}}function zs(t,e){switch(e){case 1:return`vec4(${t}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${t}, 0.0, 1.0)`;case 3:return`vec4(${t}, 1.0)`;case 4:return t;default:throw new Error(`invalid channels: ${e}`)}}function Vr(t,e=[],n=0){let r=Math.fround(t),i=t-r;return e[n]=r,e[n+1]=i,e}function $s(t){return t-Math.fround(t)}function Hs(t){let e=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){let i=n*4+r;Vr(t[r*4+n],e,i*2)}return e}var Dr=`
797
797
  layout(std140) uniform fp64arithmeticUniforms {
798
798
  uniform float ONE;
799
799
  uniform float SPLIT;
@@ -2341,7 +2341,7 @@ fn compare_fp64(a: vec2f, b: vec2f) -> i32 {
2341
2341
  return fp64_compare_f32_bits(aLowBits, bLowBits);
2342
2342
  }
2343
2343
  #endif
2344
- `,fs:Fr,vs:Fr,defaultUniforms:{ONE:1,SPLIT:4097},uniformTypes:{ONE:`f32`,SPLIT:`f32`},fp64ify:Ur,fp64LowPart:$s,fp64ifyMatrix4:Hs};var Wp={props:{},uniforms:{},name:`picking`,uniformTypes:{isActive:`f32`,isAttribute:`f32`,isHighlightActive:`f32`,useByteColors:`f32`,highlightedObjectColor:`vec3<f32>`,highlightColor:`vec4<f32>`},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:[0,1,1,1]},vs:`layout(std140) uniform pickingUniforms {
2344
+ `,fs:Dr,vs:Dr,defaultUniforms:{ONE:1,SPLIT:4097},uniformTypes:{ONE:`f32`,SPLIT:`f32`},fp64ify:Vr,fp64LowPart:$s,fp64ifyMatrix4:Hs};var Wp={props:{},uniforms:{},name:`picking`,uniformTypes:{isActive:`f32`,isAttribute:`f32`,isHighlightActive:`f32`,useByteColors:`f32`,highlightedObjectColor:`vec3<f32>`,highlightColor:`vec4<f32>`},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:[0,1,1,1]},vs:`layout(std140) uniform pickingUniforms {
2345
2345
  float isActive;
2346
2346
  float isAttribute;
2347
2347
  float isHighlightActive;
@@ -2468,7 +2468,7 @@ vec4 picking_filterColor(vec4 color) {
2468
2468
  vec4 highlightColor = picking_filterHighlightColor(color);
2469
2469
  return picking_filterPickingColor(highlightColor);
2470
2470
  }
2471
- `,getUniforms:jp};function jp(t={},e){let n={},r=rt(t.useByteColors,!0);if(t.highlightedObjectColor!==void 0)if(t.highlightedObjectColor===null)n.isHighlightActive=!1;else{n.isHighlightActive=!0;n.highlightedObjectColor=t.highlightedObjectColor.slice(0,3)}return t.highlightColor&&(n.highlightColor=gr(t.highlightColor,r)),t.isActive!==void 0&&(n.isActive=!!t.isActive,n.isAttribute=!!t.isAttribute),t.useByteColors!==void 0&&(n.useByteColors=!!t.useByteColors),n}var ye=64;var Zp={props:{},uniforms:{},bindings:{},name:`skin`,bindingLayout:[{name:`skin`,group:0},{name:`skinJointMatrices`,group:0,visibility:1}],dependencies:[],source:`
2471
+ `,getUniforms:jp};function jp(t={},e){let n={},r=rt(t.useByteColors,!0);if(t.highlightedObjectColor!==void 0)if(t.highlightedObjectColor===null)n.isHighlightActive=!1;else{n.isHighlightActive=!0;n.highlightedObjectColor=t.highlightedObjectColor.slice(0,3)}return t.highlightColor&&(n.highlightColor=_r(t.highlightColor,r)),t.isActive!==void 0&&(n.isActive=!!t.isActive,n.isAttribute=!!t.isAttribute),t.useByteColors!==void 0&&(n.useByteColors=!!t.useByteColors),n}var ye=64;var Zp={props:{},uniforms:{},bindings:{},name:`skin`,bindingLayout:[{name:`skin`,group:0},{name:`skinJointMatrices`,group:0,visibility:1}],dependencies:[],source:`
2472
2472
  struct skinUniforms {
2473
2473
  jointMatrix: array<mat4x4<f32>, ${ye}>,
2474
2474
  };
@@ -2537,7 +2537,7 @@ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
2537
2537
  + (weights.w * skin.jointMatrix[joints.w]);
2538
2538
  }
2539
2539
 
2540
- `,fs:``,defines:{SKIN_MAX_JOINTS:ye},getUniforms:(t={},e)=>{let{jointMatrices:n,skinJointMatrices:r$13,scenegraphsFromGLTF:i,skinIndex:o=0,meshWorldMatrix:s}=t,a=r$13?{skinJointMatrices:r$13}:{};if(n)return r({jointMatrix:Kp(n)},a);let c=i?.gltf?.skins?.[o];if(!c)return r({jointMatrix:[]},a);let{inverseBindMatrices:l,joints:f,skeleton:u}=c,p=i.gltfNodeIndexToNodeMap,d=new Map,h=u===void 0?void 0:p?.get(u),g=h?[h]:i.scenes||[];for(let y of g)y.preorderTraversal((v,{worldMatrix:x})=>{d.set(v.id,x)});let m=s?new U(s).invert():null,_=new Float32Array(ye*16),S=l?.value;for(let y=0;y<Math.min(f.length,ye);y++){let v=p?.get(f[y]);if(!v)continue;let x=d.get(v.id)||v.matrix,M=m?new U(m).multiplyRight(x):new U(x);S&&S.length>=(y+1)*16&&M.multiplyRight(new U(Array.from(S.slice(y*16,(y+1)*16)))),_.set(M,y*16)}return r({jointMatrix:_},a)},uniformTypes:{jointMatrix:[`mat4x4<f32>`,ye]}};function Kp(t){let e=new Float32Array(ye*16);return e.set(t instanceof Float32Array?t.subarray(0,e.length):t.slice(0,e.length)),e}var ed={name:`gpuAnimation`,props:{},uniforms:{},bindings:{},source:`
2540
+ `,fs:``,defines:{SKIN_MAX_JOINTS:ye},getUniforms:(t={},e)=>{let{jointMatrices:n,skinJointMatrices:r$13,scenegraphsFromGLTF:i,skinIndex:o=0,meshWorldMatrix:s}=t,a=r$13?{skinJointMatrices:r$13}:{};if(n)return r({jointMatrix:Kp(n)},a);let c=i?.gltf?.skins?.[o];if(!c)return r({jointMatrix:[]},a);let{inverseBindMatrices:l,joints:f,skeleton:u}=c,p=i.gltfNodeIndexToNodeMap,d=new Map,h=u===void 0?void 0:p?.get(u),g=h?[h]:i.scenes||[];for(let y of g)y.preorderTraversal((_,{worldMatrix:x})=>{d.set(_.id,x)});let m=s?new U(s).invert():null,v=new Float32Array(ye*16),S=l?.value;for(let y=0;y<Math.min(f.length,ye);y++){let _=p?.get(f[y]);if(!_)continue;let x=d.get(_.id)||_.matrix,M=m?new U(m).multiplyRight(x):new U(x);S&&S.length>=(y+1)*16&&M.multiplyRight(new U(Array.from(S.slice(y*16,(y+1)*16)))),v.set(M,y*16)}return r({jointMatrix:v},a)},uniformTypes:{jointMatrix:[`mat4x4<f32>`,ye]}};function Kp(t){let e=new Float32Array(ye*16);return e.set(t instanceof Float32Array?t.subarray(0,e.length):t.slice(0,e.length)),e}var ed={name:`gpuAnimation`,props:{},uniforms:{},bindings:{},source:`
2541
2541
  #ifdef HAS_GPU_CROWD_ANIMATION
2542
2542
  @group(0) @binding(auto) var<storage, read> gpuAnimationFrames: array<vec4f>;
2543
2543
 
@@ -6144,5 +6144,5 @@ fn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {
6144
6144
  };
6145
6145
 
6146
6146
  @group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
6147
- `,vs:Js,fs:Js,getUniforms:t=>t,uniformTypes:{modelViewProjectionMatrix:`mat4x4<f32>`,modelMatrix:`mat4x4<f32>`,normalMatrix:`mat4x4<f32>`,camera:`vec3<f32>`}}],source:Ks,vs:Xs,fs:Zs,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,HAS_BUMPMAP:!1,HAS_DIFFUSETRANSMISSIONMAP:!1,HAS_DIFFUSETRANSMISSIONCOLORMAP:!1,HAS_MULTISCATTERCOLORMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:t=>t,uniformTypes:{unlit:`i32`,baseColorMapEnabled:`i32`,baseColorFactor:`vec4<f32>`,normalMapEnabled:`i32`,normalScale:`f32`,emissiveMapEnabled:`i32`,emissiveFactor:`vec3<f32>`,metallicRoughnessValues:`vec2<f32>`,metallicRoughnessMapEnabled:`i32`,occlusionMapEnabled:`i32`,occlusionStrength:`f32`,alphaCutoffEnabled:`i32`,alphaCutoff:`f32`,specularColorFactor:`vec3<f32>`,specularIntensityFactor:`f32`,specularColorMapEnabled:`i32`,specularIntensityMapEnabled:`i32`,ior:`f32`,transmissionFactor:`f32`,transmissionMapEnabled:`i32`,thicknessFactor:`f32`,attenuationDistance:`f32`,attenuationColor:`vec3<f32>`,clearcoatFactor:`f32`,clearcoatRoughnessFactor:`f32`,clearcoatMapEnabled:`i32`,clearcoatRoughnessMapEnabled:`i32`,sheenColorFactor:`vec3<f32>`,sheenRoughnessFactor:`f32`,sheenColorMapEnabled:`i32`,sheenRoughnessMapEnabled:`i32`,iridescenceFactor:`f32`,iridescenceIor:`f32`,iridescenceThicknessRange:`vec2<f32>`,iridescenceMapEnabled:`i32`,anisotropyStrength:`f32`,anisotropyRotation:`f32`,anisotropyDirection:`vec2<f32>`,anisotropyMapEnabled:`i32`,emissiveStrength:`f32`,dispersion:`f32`,IBLenabled:`i32`,scaleIBLAmbient:`vec2<f32>`,scaleDiffBaseMR:`vec4<f32>`,scaleFGDSpec:`vec4<f32>`,baseColorUVSet:`i32`,baseColorUVTransform:`mat3x3<f32>`,metallicRoughnessUVSet:`i32`,metallicRoughnessUVTransform:`mat3x3<f32>`,normalUVSet:`i32`,normalUVTransform:`mat3x3<f32>`,occlusionUVSet:`i32`,occlusionUVTransform:`mat3x3<f32>`,emissiveUVSet:`i32`,emissiveUVTransform:`mat3x3<f32>`,specularColorUVSet:`i32`,specularColorUVTransform:`mat3x3<f32>`,specularIntensityUVSet:`i32`,specularIntensityUVTransform:`mat3x3<f32>`,transmissionUVSet:`i32`,transmissionUVTransform:`mat3x3<f32>`,thicknessUVSet:`i32`,thicknessUVTransform:`mat3x3<f32>`,clearcoatUVSet:`i32`,clearcoatUVTransform:`mat3x3<f32>`,clearcoatRoughnessUVSet:`i32`,clearcoatRoughnessUVTransform:`mat3x3<f32>`,clearcoatNormalUVSet:`i32`,clearcoatNormalUVTransform:`mat3x3<f32>`,sheenColorUVSet:`i32`,sheenColorUVTransform:`mat3x3<f32>`,sheenRoughnessUVSet:`i32`,sheenRoughnessUVTransform:`mat3x3<f32>`,iridescenceUVSet:`i32`,iridescenceUVTransform:`mat3x3<f32>`,iridescenceThicknessUVSet:`i32`,iridescenceThicknessUVTransform:`mat3x3<f32>`,anisotropyUVSet:`i32`,anisotropyUVTransform:`mat3x3<f32>`,bumpFactor:`f32`,bumpMapEnabled:`i32`,diffuseTransmissionFactor:`f32`,diffuseTransmissionMapEnabled:`i32`,diffuseTransmissionColorFactor:`vec3<f32>`,diffuseTransmissionColorMapEnabled:`i32`,multiscatterColorFactor:`vec3<f32>`,multiscatterColorMapEnabled:`i32`,scatterAnisotropy:`f32`,bumpUVSet:`i32`,bumpUVTransform:`mat3x3<f32>`,diffuseTransmissionUVSet:`i32`,diffuseTransmissionUVTransform:`mat3x3<f32>`,diffuseTransmissionColorUVSet:`i32`,diffuseTransmissionColorUVTransform:`mat3x3<f32>`,multiscatterColorUVSet:`i32`,multiscatterColorUVTransform:`mat3x3<f32>`}};var Vr={};function G(t=`id`){Vr[t]=Vr[t]||1;return`${t}-${Vr[t]++}`}var ne=class{id;topology;vertexCount;indices;attributes;bufferLayout;userData={};constructor(e){let{attributes:n={},indices:r=null,vertexCount:i=null}=e;this.id=e.id||G(`geometry`),this.topology=e.topology,r&&(this.indices=ArrayBuffer.isView(r)?{value:r,size:1}:r),this.attributes={};for(let[o,s]of Object.entries(n)){let a=ArrayBuffer.isView(s)?{value:s}:s;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(o)}: must be typed array or object with value as typed array`);if((o===`POSITION`||o===`positions`)&&!a.size&&(a.size=3),o===`indices`){if(this.indices)throw new Error(`Multiple indices detected`);this.indices=a}else{let c=Me(o),l=Object.keys(this.attributes).find(f=>Me(f)===c);l&&delete this.attributes[l],this.attributes[o]=a}}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=i||this._calculateVertexCount(this.attributes,this.indices),this.bufferLayout=e.bufferLayout||id(this.attributes)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?r({indices:this.indices},this.attributes):this.attributes}_print(e){return`Geometry ${this.id} attribute ${e}`}_setAttributes(e,n){return this}_calculateVertexCount(e,n){if(n)return n.value.length;let r=Infinity;for(let i of Object.values(e)){if(!i)continue;let{value:o,size:s,constant:a}=i;!a&&o&&s!==void 0&&s>=1&&(r=Math.min(r,o.length/s))}return r}};function Me(t){switch(t){case`POSITION`:return`positions`;case`NORMAL`:return`normals`;case`TEXCOORD_0`:return`texCoords`;case`TEXCOORD_1`:return`texCoords1`;case`COLOR_0`:return`colors`;default:return t}}function id(t){let e=[];for(let[n,r]of Object.entries(t)){if(!r)continue;let{value:i,size:o,normalized:s}=r;if(o===void 0)throw new Error(`Attribute ${n} is missing a size`);e.push({name:Me(n),format:R.getVertexFormatFromAttribute(i,o,s)})}return e}function pt(t,e={}){let n=e.bufferName||`geometry`;if(od(t,n))return t;let r=e.minAttributeAlignment||4,i=sd(t,e.attributes),o=[],s=0,a=Infinity;for(let[f,u]of i){if(!u)continue;if(u.constant)throw new Error(`Attribute ${f} is constant`);let{value:p,size:d,normalized:h}=u;if(!ArrayBuffer.isView(p))throw new Error(`Attribute ${f} is missing typed array data`);if(d===void 0)throw new Error(`Attribute ${f} is missing a size`);let g=R.getVertexFormatFromAttribute(p,d,h),m=R.getVertexFormatInfo(g);s=ea(s,r),o.push({sourceName:f,attributeName:Me(f),value:p,size:d,format:g,byteOffset:s,byteLength:m.byteLength}),s+=m.byteLength;let _=p.length/d;if(!Number.isInteger(_))throw new Error(`Attribute ${f} length is not divisible by size`);a=Math.min(a,_)}if(o.length===0||!Number.isFinite(a))throw new Error(`Geometry ${t.id} has no interleavable attributes`);let c=ea(s,r),l=new ArrayBuffer(a*c);for(let f of o)ad(l,a,c,f);return new ne({id:t.id,topology:t.topology||`triangle-list`,vertexCount:t.vertexCount,indices:t.indices,attributes:{[n]:{value:new Uint8Array(l),size:c,byteStride:c}},bufferLayout:[{name:n,stepMode:`vertex`,byteStride:c,attributes:o.map(f=>({attribute:f.attributeName,format:f.format,byteOffset:f.byteOffset}))}]})}function od(t,e){if(t.bufferLayout.length!==1)return!1;let n=t.bufferLayout[0];return n.name===e&&!!n.attributes?.length&&!!t.attributes[e]}function sd(t,e){return e?e.map(n=>[n,t.attributes[n]]):Object.entries(t.attributes)}function ad(t,e,n,r){let i=r.value.constructor,o=i.BYTES_PER_ELEMENT;if(r.byteOffset%o!==0||n%o!==0)throw new Error(`Attribute ${r.sourceName} is not aligned to its component type`);let s=new i(t),a=r.value,c=r.byteOffset/o,l=n/o;for(let f=0;f<e;f++){let u=f*r.size,p=f*l+c;for(let d=0;d<r.size;d++)s[p+d]=a[u+d]}}function ea(t,e){return Math.ceil(t/e)*e}var sn=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(e){if(this.id=e.id||G(`geometry`),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&P.INDEX))throw new Error(`Index buffer must have INDEX usage`)}destroy(){this.indices?.destroy();for(let e of Object.values(this.attributes))e.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}};function ta(t,e){if(e instanceof sn)return e;let n=pt(e),r=cd(t,n),{attributes:i,bufferLayout:o}=ld(t,n);return new sn({topology:n.topology||`triangle-list`,bufferLayout:o,vertexCount:n.vertexCount,indices:r,attributes:i})}function cd(t,e){if(!e.indices)return;let n=e.indices.value;return t.createBuffer({usage:P.INDEX,data:n})}function ld(t,e){let n={};for(let[r,i]of Object.entries(e.attributes)){let o=e.bufferLayout.find(s=>s.name===r)?.name||Me(r);i&&(n[o]=t.createBuffer({data:i.value,id:`${r}-buffer`}))}return{attributes:n,bufferLayout:e.bufferLayout,vertexCount:e.vertexCount}}function na(t,e){let n={},r=`Values`;if(t.attributes.length===0&&!t.varyings?.length)return{"No attributes or varyings":{[r]:`N/A`}};for(let i of t.attributes)if(i){let o=`${i.location} ${i.name}: ${i.type}`;n[`in ${o}`]={[r]:i.stepMode||`vertex`}}for(let i of t.varyings||[]){let o=`${i.location} ${i.name}`;n[`out ${o}`]={[r]:JSON.stringify(i)}}return n}var ra=`__debugFramebufferState`;function oa(t,e,n){if(t.device.type!==`webgl`)return;let r=pd(t.device);if(!r.flushing){if(hd(t)){fd(t,n,r);return}e&&dd(e)&&e.handle!==null&&(r.queuedFramebuffers.includes(e)||r.queuedFramebuffers.push(e))}}function fd(t,e,n){if(n.queuedFramebuffers.length===0)return;let{gl:i}=t.device,o=i.getParameter(36010),s=i.getParameter(36006),[a,c]=t.device.getDefaultCanvasContext().getDrawingBufferSize(),l=ia(e.top,8),f=ia(e.left,8);n.flushing=!0;try{for(let u of n.queuedFramebuffers){let[p,d,h,g,m]=ud({framebuffer:u,targetWidth:a,targetHeight:c,topPx:l,leftPx:f,minimap:e.minimap});i.bindFramebuffer(36008,u.handle),i.bindFramebuffer(36009,null),i.blitFramebuffer(0,0,u.width,u.height,p,d,h,g,16384,9728),l+=m+8}}finally{i.bindFramebuffer(36008,o),i.bindFramebuffer(36009,s),n.flushing=!1}}function ud(t){let{framebuffer:e,targetWidth:n,targetHeight:r,topPx:i,leftPx:o,minimap:s}=t,a=s?Math.max(Math.floor(n/4),1):n,c=s?Math.max(Math.floor(r/4),1):r,l=Math.min(a/e.width,c/e.height),f=Math.max(Math.floor(e.width*l),1),u=Math.max(Math.floor(e.height*l),1),p=o,d=Math.max(r-i-u,0);return[p,d,p+f,d+u,u]}function pd(t){return t.userData[ra]||={flushing:!1,queuedFramebuffers:[]},t.userData[ra]}function dd(t){return`colorAttachments`in t}function hd(t){let e=t.props.framebuffer;return!e||e.handle===null}function ia(t,e){if(!t)return e;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:e}function Ue(t,e,n){if(t===e)return!0;if(!n||!t||!e)return!1;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!Ue(t[r],e[r],n-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof t==`object`&&typeof e==`object`){let r=Object.keys(t),i=Object.keys(e);if(r.length!==i.length)return!1;for(let o of r)if(!e.hasOwnProperty(o)||!Ue(t[o],e[o],n-1))return!1;return!0}return!1}var Fe=class{bufferLayouts;constructor(e){this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(n=>n.name===e)||null}getAttributeNamesForBuffer(e){return vi(e)}mergeBufferLayouts(e,n){let r=[...e];for(let i of n){let o=r.findIndex(s=>s.name===i.name);o<0?r.push(i):r[o]=i}return r}};function sa(t,e){let n=Ci(t),r=e.slice();return r.sort((i,o)=>{return Bi$1(vi(i).map(c=>n[c]))-Bi$1(vi(o).map(c=>n[c]))}),r}function Ve(t,e){if(!t||!e.some(r=>r.bindingLayout?.length))return t;let n=s(r({},t),{bindings:t.bindings.map(r$14=>r({},r$14))});`attributes`in(t||{})&&(n.attributes=t?.attributes||[]);for(let r of e)for(let i of r.bindingLayout||[])for(let o of md(i.name)){let s=n.bindings.find(a=>a.name===o);s?.group===0&&(s.group=i.group),s&&i.visibility!==void 0&&(s.visibility=i.visibility)}return n}function aa(t,e,n=[]){return t?e?s(r({},t),{attributes:t.attributes.length?_d(t.attributes,e.attributes.filter(r=>n.includes(r.name))):e.attributes,bindings:bd(t.bindings,e.bindings)}):t:e}function Ae(t){return!!(t.uniformTypes&&!gd(t.uniformTypes))}function ca(t){let e=[];for(let n of t){let r=lt(n),i=new Set([n.vs,n.fs].flatMap(s=>s?ft(s).filter(a=>a.isStd140).map(a=>a.blockName):[])),o=i.has(r)?r:i.size===1?i.values().next().value:void 0;Ae(n)&&o&&e.push({name:o,uniformTypes:n.uniformTypes})}return e}function an(t,e){let n=[],r=new Set;for(let i of[...t||[],...e||[]])r.has(i.name)||(r.add(i.name),n.push(i));return n}function md(t){let e=new Set([t,`${t}Uniforms`]);return t.endsWith(`Uniforms`)||e.add(`${t}Sampler`),[...e]}function gd(t){for(let e in t)return!1;return!0}function bd(t,e){let n=t.map(o=>r({},o)),r$15=new Set(t.map(o=>o.name)),i=new Set(t.map(o=>`${o.group}:${o.location}`));for(let o of e){let s=`${o.group}:${o.location}`;!r$15.has(o.name)&&!i.has(s)&&n.push(r({},o))}return n}function _d(t,e){let n=t.map(o=>r({},o)),r$16=new Map(t.map(o=>[o.name,o])),i=new Map(t.map(o=>[o.location,o]));for(let o of e){let s=r$16.get(o.name);if(s){if(s.type!==o.type||s.location!==o.location)throw new Error(`Shader attribute "${o.name}" conflicts with its inferred type or location`);continue}let a=i.get(o.location);if(a)throw new Error(`Shader attributes "${a.name}" and "${o.name}" both use location ${o.location}`);n.push(r({},o))}return n}function la(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function fa(t){return Array.isArray(t)?t.length===0||typeof t[0]==`number`:!1}function dt(t){return la(t)||fa(t)}function vd(t){return dt(t)||typeof t==`number`||typeof t==`boolean`}function ua(t,e={}){let n={bindings:{},uniforms:{}};return Object.keys(t).forEach(r=>{let i=t[r];Object.prototype.hasOwnProperty.call(e,r)||vd(i)?n.uniforms[r]=i:n.bindings[r]=i}),n}var J=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;directBindings={};constructor(e,n){Object.assign(this.options,n);let r=_e(Object.values(e).filter(xd));for(let i of r)e[i.name]=i;f.log(1,`Creating ShaderInputs with modules`,Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(let[i,o]of Object.entries(e))o&&(this._addModule(o),o.name&&i!==o.name&&!this.options.disableWarnings&&f.warn(`Module name: ${i} vs ${o.name}`)())}destroy(){}setProps(e){e.bindings&&Object.assign(this.directBindings,e.bindings);for(let n of Object.keys(e)){if(n===`bindings`)continue;let r$17=n,i=e[r$17]||{},o=this.modules[r$17];if(!o)this.options.disableWarnings||f.warn(`Module ${n} not found`)();else{let s=this.moduleUniforms[r$17],a=this.moduleBindings[r$17],{uniforms:l,bindings:f}=ua(o.getUniforms?.(i,s)||i,o.uniformTypes);this.moduleUniforms[r$17]=pa(s,l,o.uniformTypes),this.moduleBindings[r$17]=r(r({},a),f)}}}getModules(){return Object.values(this.modules)}addModules(e){let n=_e(e);for(let r of n){let i=r.name;this.modules[i]||(this.modules[i]=r,this._addModule(r))}}getUniformValues(){return this.moduleUniforms}getBindingValues(){let e={};for(let n of Object.values(this.moduleBindings))Object.assign(e,n);return Object.assign(e,this.directBindings),e}getModuleBindingValues(e){let n=this.moduleBindings[e];return n?r({},n):{}}getDebugTable(){let e={};for(let[n,r]of Object.entries(this.moduleUniforms))for(let[i,o]of Object.entries(r))e[`${n}.${i}`]={type:this.modules[n].uniformTypes?.[i],value:String(o)};return e}_addModule(e){let n=e.name;this.moduleUniforms[n]=pa({},e.defaultUniforms||{},e.uniformTypes),this.moduleBindings[n]={}}};function pa(t={},e={},n={}){let r$18=r({},t);for(let[i,o]of Object.entries(e))o!==void 0&&(r$18[i]=Dr(t[i],o,n[i]));return r$18}function Dr(t,e,n){if(!n||typeof n==`string`)return ht(e);if(Array.isArray(n)){if(kr(e)||!Array.isArray(e))return ht(e);let s=Array.isArray(t)&&!kr(t)?[...t]:[],a=s.slice();for(let c=0;c<e.length;c++){let l=e[c];l!==void 0&&(a[c]=Dr(s[c],l,n[0]))}return a}if(!Gr(e))return ht(e);let r$19=n,i=Gr(t)?t:{},o=r({},i);for(let[s,a]of Object.entries(e))a!==void 0&&(o[s]=Dr(i[s],a,r$19[s]));return o}function ht(t){return ArrayBuffer.isView(t)?Array.prototype.slice.call(t):Array.isArray(t)?kr(t)?t.slice():t.map(n=>n===void 0?void 0:ht(n)):Gr(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n===void 0?void 0:ht(n)])):t}function kr(t){return ArrayBuffer.isView(t)||Array.isArray(t)&&(t.length===0||typeof t[0]==`number`)}function Gr(t){return!!t&&typeof t==`object`&&!Array.isArray(t)&&!ArrayBuffer.isView(t)}function xd(t){return!!t?.dependencies}var Sd=P.DEBUG_DATA_MAX_LENGTH;var k=class{device;id;ready;usage;props;isReady=!0;destroyed=!1;generation=0;updateTimestamp;debugData=new ArrayBuffer(0);_debugDataEnabled;_maxDebugDataByteLength;_ownsBuffer;_buffer;get buffer(){return this._buffer}get byteLength(){return this._buffer.byteLength}get[Symbol.toStringTag](){return`DynamicBuffer`}toString(){return`DynamicBuffer:"${this.id}":${this.byteLength}B`}toJSON(){return this.toString()}constructor(e,n){let l=n,{debugData:r$20=!1,buffer:i,ownsBuffer:o=!0}=l,s$6=u(l,[`debugData`,`buffer`,`ownsBuffer`]);if(i&&i.device!==e)throw new Error(`DynamicBuffer adopted buffers must belong to the supplied device`);if(i&&(s$6.byteLength!==void 0||s$6.data!==void 0))throw new Error(`DynamicBuffer cannot combine an adopted buffer with byteLength or data`);let a=n.id||i?.id||G(`dynamic-buffer`),c=s(r({},s$6),{id:a,usage:s$6.usage??i?.usage,indexType:s$6.indexType??i?.indexType});(c.usage||0)&P.INDEX&&!c.indexType&&(s$6.data instanceof Uint32Array?c.indexType=`uint32`:s$6.data instanceof Uint16Array?c.indexType=`uint16`:s$6.data instanceof Uint8Array&&(c.indexType=`uint8`)),delete c.data,delete c.byteOffset,this.device=e,this.id=a,this.props=c,this.usage=c.usage||0,this._debugDataEnabled=!!r$20,this._maxDebugDataByteLength=typeof r$20==`object`&&r$20.maxByteLength!==void 0?r$20.maxByteLength:Sd,this._ownsBuffer=o,this._buffer=i??this.device.createBuffer(s(r({},s$6),{id:a})),this.ready=Promise.resolve(this._buffer),this.updateTimestamp=this._buffer.updateTimestamp,this._resetDebugData(this._buffer.byteLength),s$6.data&&this._writeDebugData(s$6.data,s$6.byteOffset||0)}write(e,n=0){this._buffer.write(e,n),this._touch(),this._writeDebugData(e,n)}async mapAndWriteAsync(e,n=0,r=this.byteLength-n){let i=null;await this._buffer.mapAndWriteAsync(async(o,s)=>{await e(o,s),i=new Uint8Array(o.slice(0,r))},n,r),this._touch(),i&&this._writeDebugData(i,n)}async readAsync(e=0,n=this.byteLength-e){let r=await this._buffer.readAsync(e,n);return this._writeDebugData(r,e)&&this._touch(),r}async mapAndReadAsync(e,n=0,r=this.byteLength-n){let i=null,o=await this._buffer.mapAndReadAsync(async(s,a)=>(i=new Uint8Array(s.slice(0)),await e(s,a)),n,r);return i&&this._writeDebugData(i,n)&&this._touch(),o}resize(e){let{byteLength:n,preserveData:r$21=!1}=e;if(n===this.byteLength)return!1;let i=Math.min(e.copyByteLength??Math.min(this.byteLength,n),this.byteLength,n),o=this._buffer,s$7=this.debugData.slice(0),u$1=this.props,{data:a,byteOffset:c}=u$1,l=u(u$1,[`data`,`byteOffset`]),f=this.device.createBuffer(s(r({},l),{byteLength:n}));return r$21&&i>0&&this._copyBufferContents(o,f,i),this._buffer=f,this._resetDebugData(n),r$21&&s$7.byteLength>0&&this._writeDebugData(s$7,0),this._ownsBuffer&&o.destroy(),this._ownsBuffer=!0,this.generation++,this._touch(),!0}ensureSize(e,n){return e<=this.byteLength?!1:this.resize({byteLength:e,preserveData:n?.preserveData})}getBinding(e){return e?.offset===void 0&&e?.size===void 0?this._buffer:{buffer:this._buffer,offset:e?.offset,size:e?.size}}destroy(){this.destroyed||(this._ownsBuffer&&this._buffer.destroy(),this.destroyed=!0,this.debugData=new ArrayBuffer(0))}_copyBufferContents(e,n,r){let i=this.device.type===`webgpu`?Math.ceil(r/4)*4:r,o=this.device.createCommandEncoder();o.copyBufferToBuffer({sourceBuffer:e,destinationBuffer:n,size:i}),this.device.submit(o.finish())}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_resetDebugData(e){if(!this._debugDataEnabled){this.debugData=new ArrayBuffer(0);return}this.debugData=new ArrayBuffer(Math.min(e,this._maxDebugDataByteLength))}_writeDebugData(e,n){if(!this._debugDataEnabled||this.debugData.byteLength===0||n>=this.debugData.byteLength)return!1;let r=ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),i=new Uint8Array(this.debugData),o=Math.min(r.byteLength,i.byteLength-n);return i.set(r.subarray(0,o),n),o>0}};function Ee(t){return t!==null&&typeof t==`object`&&`buffer`in t}function da(t){return t instanceof k?t:Ee(t)&&t.buffer instanceof k?t.buffer:null}function yd(t){return t instanceof k?t.buffer:t}function cn(t){return{buffer:yd(t.buffer),offset:t.offset,size:t.size}}function re(t){return t!==null&&typeof t==`object`&&`resolveTextureBinding`in t&&typeof t.resolveTextureBinding==`function`}function Md(t){return t?.type===`texture`||t?.type===`external-texture`}function ln(t,e,n){let r=jt$1(t,e,{ignoreWarnings:!0});return Md(r)?r:t.bindings.length===0&&n?.fallbackGroup!==void 0?{type:`texture`,name:e,group:n.fallbackGroup,location:0}:null}var Q=2;var Ad=1e4;var zr=`render pipeline initialization failed`;var Ed=[`stencil8`,`depth16unorm`,`depth24plus`,`depth24plus-stencil8`,`depth32float`,`depth32float-stencil8`];var De=class t{static defaultProps=s(r({},L.defaultProps),{source:void 0,vs:null,fs:null,id:`unnamed`,handle:void 0,userData:{},defines:{},modules:[],plugins:[],geometry:null,indexBuffer:null,indexCount:void 0,firstVertex:0,firstIndex:0,attributes:{},constantAttributes:{},bindings:{},uniforms:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,material:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:fe.getDefaultShaderAssembler(`glsl`),debugShaders:void 0,disableWarnings:void 0});device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexCount;firstVertex;firstIndex;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;material=null;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_dynamicIndexBufferSource=null;_dynamicAttributeBufferSources={};_colorAttachmentFormats;_depthStencilAttachmentFormat;_pipelineNeedsUpdate=`newly created`;_needsRedraw=`initializing`;_drawBlockedReason=!1;_destroyed=!1;_lastDrawTimestamp=-1;_bindingTable=[];get[Symbol.toStringTag](){return`Model`}toString(){return`Model(${this.id})`}constructor(e,n){let r$22=t.defaultProps.shaderAssembler;this.props=s(r(r({},t.defaultProps),n),{shaderAssembler:n.shaderAssembler??($r(r$22,e.info.shadingLanguage)?r$22:fe.getDefaultShaderAssembler(e.info.shadingLanguage))}),n=this.props,this.id=n.id||G(`model`),this.device=e,Object.assign(this.userData,n.userData),this.material=n.material||null;let i=Cd(e),o=at(this.props.plugins,i.shaderLanguage),s$8=ct(this.props.modules,o.modules),a=Object.fromEntries(s$8.map(p=>[p.name,p])),c=n.shaderInputs||new J(a,{disableWarnings:this.props.disableWarnings});n.shaderInputs&&o.modules.length>0&&c.addModules(o.modules),this.setShaderInputs(c);let l=an(this.props.modules,c.getModules()),f=r(r({},o.defines),this.props.defines);if(this.device.type===`webgl`&&(this.props._uniformBlockLayouts=ca(l)),this.props.shaderLayout=Ve(this.props.shaderLayout,l)||null,this.device.type===`webgpu`&&this.props.source){let p=this.props.shaderAssembler;He($r(p,`wgsl`));let{source:d,getUniforms:h,bindingTable:g,shaderLayout:m}=p.assembleWGSLShader(s(r({platformInfo:i},this.props),{modules:l,defines:f,pluginInjections:o.injections,pluginVertexInputs:o.vertexInputs,pluginVaryings:o.varyings}));this.source=d,this._getModuleUniforms=h,this._bindingTable=g;let S=Id(m??e.getShaderLayout?.(this.source),o.vertexInputs),y=aa(this.props.shaderLayout,S,Object.keys(o.vertexInputs));this.props.shaderLayout=Ve(y||null,l)||null}else{let p=this.props.shaderAssembler;He($r(p,`glsl`));let{vs:d,fs:h,getUniforms:g}=p.assembleGLSLShaderPair(s(r({platformInfo:i},this.props),{modules:l,defines:f,pluginInjections:o.injections,pluginVertexInputs:o.vertexInputs,pluginVaryings:o.varyings}));this.vs=d,this.fs=h,this._getModuleUniforms=g,this._bindingTable=[]}this.vertexCount=this.props.vertexCount,this.indexCount=this.props.indexCount,this.firstVertex=this.props.firstVertex,this.firstIndex=this.props.firstIndex,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,this._colorAttachmentFormats=this.props.colorAttachmentFormats,this._depthStencilAttachmentFormat=this.props.depthStencilAttachmentFormat,n.geometry&&this.setGeometry(n.geometry),this.pipelineFactory=n.pipelineFactory||qe.getDefaultPipelineFactory(this.device),this.shaderFactory=n.shaderFactory||Ke$1.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),`isInstanced`in n&&(this.isInstanced=n.isInstanced),n.instanceCount&&this.setInstanceCount(n.instanceCount),n.vertexCount&&this.setVertexCount(n.vertexCount),n.indexBuffer&&this.setIndexBuffer(n.indexBuffer),n.attributes&&this.setAttributes(n.attributes),n.constantAttributes&&this.setConstantAttributes(n.constantAttributes),n.bindings&&this.setBindings(n.bindings),n.transformFeedback&&(this.transformFeedback=n.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.pipeline.fs!==this.pipeline.vs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw(`contents of bound textures or buffers updated`);let e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||=e}getBindingDebugTable(){return this._bindingTable}predraw(e){this._syncDynamicBuffers(),this.updateShaderInputs(e),this.material?.updateShaderInputs(e),this.pipeline=this._updatePipeline()}draw(e){if(this._drawBlockedReason&&!this._pipelineNeedsUpdate)return f.info(Q,`>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)(),!1;let n=this._areBindingsLoading();if(n)return f.info(Q,`>>> DRAWING ABORTED ${this.id}: ${n} not loaded`)(),!1;this._syncAttachmentFormats(e);try{e.pushDebugGroup(`${this}.predraw(${e})`),this.device.type===`webgpu`?(this.updateShaderInputs(),this.material?.updateShaderInputs(),this._syncDynamicBuffers(),this.pipeline=this._updatePipeline()):this.predraw(this.device.commandEncoder)}finally{e.popDebugGroup()}let r,i=this.pipeline.isErrored;try{if(e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline(),i=this.pipeline.isErrored,i)f.info(Q,`>>> DRAWING ABORTED ${this.id}: ${zr}`)(),r=!1;else{let o=this.vertexArray.getDrawValidationError();if(o)f.info(Q,`>>> DRAWING ABORTED ${this.id}: ${o}`)(),this._drawBlockedReason=o,r=!1;else{let s=this._getCurrentShaderLayout(),a=this._getBindings(s),c=this._getBindGroups(s,a),{indexBuffer:l}=this.vertexArray,f=l?this.indexCount??l.byteLength/(l.indexType===`uint32`?4:2):void 0;e.setPipeline(this.pipeline),e.setBindings(c,{_bindGroupCacheKeys:this._getBindGroupCacheKeys()}),e.setVertexArray(this.vertexArray),r=this.isInstanced===!0&&this.instanceCount===0?!0:e.draw({isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.isInstanced?this.instanceCount:void 0,indexCount:f,firstVertex:this.firstVertex,firstIndex:this.firstIndex,transformFeedback:this.transformFeedback||void 0,uniforms:this.props.uniforms,parameters:this.parameters,topology:this.topology})}}}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),r?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):i?(this._needsRedraw=zr,this._drawBlockedReason=zr):this._drawBlockedReason?this._needsRedraw=this._drawBlockedReason:this._needsRedraw=`waiting for resource initialization`,r}setGeometry(e){this._gpuGeometry?.destroy();let n=e&&ta(this.device,e);if(n){this.setTopology(n.topology||`triangle-list`);let r=new Fe(this.bufferLayout);this.bufferLayout=r.mergeBufferLayouts(n.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(n)}this._gpuGeometry=n}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate(`topology`))}setBufferLayout(e){let n=new Fe(this.bufferLayout),r=this._gpuGeometry?n.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e;Ue(r,this.bufferLayout,-1)||(this.bufferLayout=r,this._setPipelineNeedsUpdate(`bufferLayout`),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry))}setParameters(e){Ue(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate(`parameters`))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw(`instanceCount`)}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw(`vertexCount`)}setIndexCount(e){this.indexCount=e,this.setNeedsRedraw(`indexCount`)}setDrawOffsets({firstVertex:e,firstIndex:n}){this.firstVertex=e,this.firstIndex=n,this.setNeedsRedraw(`drawOffsets`)}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new lt$1(this.device,this.shaderInputs.modules);for(let[n,r]of Object.entries(this.shaderInputs.modules))if(Ae(r)&&!this.material?.ownsModule(n)){let i=this._uniformStore.getManagedUniformBuffer(n);this.bindings[`${n}Uniforms`]=i}this.setNeedsRedraw(`shaderInputs`)}setMaterial(e){this.material=e,this.setNeedsRedraw(`material`)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues())),this.setNeedsRedraw(`shaderInputs`)}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw(`bindings`)}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw(`transformFeedback`)}setIndexBuffer(e){let n=e instanceof k?e.buffer:e;this.indexBuffer=n,this._dynamicIndexBufferSource=e instanceof k?{source:e,generation:e.generation}:null,this.vertexArray.setIndexBuffer(n),this.setNeedsRedraw(`indexBuffer`)}setAttributes(e,n){this._drawBlockedReason=!1;let r=n?.disableWarnings??this.props.disableWarnings;e.indices&&f.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=sa(this.pipeline.shaderLayout,this.bufferLayout);let i=new Fe(this.bufferLayout);for(let[o,s]of Object.entries(e)){let a=s instanceof k?s.buffer:s,c=i.getBufferLayout(o);if(!c){r||f.warn(`Model(${this.id}): Missing layout for buffer "${o}".`)();continue}let l=i.getAttributeNamesForBuffer(c),f$1=!1;for(let u of l){let p=this._attributeInfos[u];if(p){let d=this.device.type===`webgpu`?this.vertexArray.getBufferSlot(p.bufferName):p.location;if(d===null){r||f.warn(`Model(${this.id}): Missing vertex array slot for buffer "${p.bufferName}".`)();continue}this.vertexArray.setBuffer(d,a),s instanceof k?this._dynamicAttributeBufferSources[d]={source:s,generation:s.generation}:delete this._dynamicAttributeBufferSources[d],f$1=!0}}!f$1&&!r&&f.warn(`Model(${this.id}): Ignoring buffer "${a.id}" for unknown attribute "${o}"`)()}this.setNeedsRedraw(`attributes`)}setConstantAttributes(e,n){for(let[r,i]of Object.entries(e)){let o=this._attributeInfos[r];o?this.vertexArray.setConstantWebGL(o.location,i):(n?.disableWarnings??this.props.disableWarnings)||f.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${r}"`)()}this.setNeedsRedraw(`constants`)}_areBindingsLoading(){for(let e of Object.values(this.bindings))if(re(e)&&!e.isReady)return e.id;for(let e of Object.values(this.material?.bindings||{}))if(re(e)&&!e.isReady)return e.id;return!1}_getBindings(e=this._getCurrentShaderLayout()){let n={};for(let[r,i]of Object.entries(this.bindings)){let o=Ld(r,i,e);o&&(n[r]=o)}return n}_getBindGroups(e=this._getCurrentShaderLayout(),n=this._getBindings(e)){let r$23=e.bindings.length?ui$1(e,n):{0:n};if(!this.material)return r$23;for(let[i,o]of Object.entries(this.material.getBindingsByGroup(e))){let s=Number(i);r$23[s]=r(r({},r$23[s]||{}),o)}return r$23}_getBindGroupCacheKeys(){let e=this.material?.getBindGroupCacheKey(3);return e?{3:e}:{}}_getBindingsUpdateTimestamp(){let e=0;this._dynamicIndexBufferSource&&(e=Math.max(e,this._dynamicIndexBufferSource.source.updateTimestamp));for(let n of Object.values(this._dynamicAttributeBufferSources))e=Math.max(e,n.source.updateTimestamp);for(let n of Object.values(this.bindings))n instanceof je?e=Math.max(e,n.texture.updateTimestamp):n instanceof P||n instanceof v||n instanceof Qe$1||n instanceof k?e=Math.max(e,n.updateTimestamp):re(n)?e=n.isReady?Math.max(e,n.updateTimestamp):Infinity:Ee(n)&&(e=Math.max(e,(n.buffer instanceof k,n.buffer.updateTimestamp)));return Math.max(e,this.material?.getBindingsUpdateTimestamp()||0)}_setGeometryAttributes(e){let n=r({},e.attributes);for(let[r]of Object.entries(n))!this.pipeline.shaderLayout.attributes.find(i=>i.name===r)&&r!==`positions`&&delete n[r];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(n,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw(`geometry attributes`)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||=e,this._drawBlockedReason=!1,this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,n=null;this.pipeline&&(f.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,n=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let r$24=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:`vertex`,source:this.source||this.vs,debugShaders:this.props.debugShaders}),i=null;this.source?i=r$24:this.fs&&(i=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:`fragment`,source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline(s(r({},this.props),{bindings:void 0,bufferLayout:this.bufferLayout,colorAttachmentFormats:this._colorAttachmentFormats,depthStencilAttachmentFormat:this._depthStencilAttachmentFormat,topology:this.topology,parameters:this.parameters,bindGroups:void 0,vs:r$24,fs:i})),this._attributeInfos=Di$1(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),n&&n!==e&&this.shaderFactory.release(n)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=f.level>3?0:Ad;f.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,f.group(Q,`>>> DRAWING MODEL ${this.id}`,{collapsed:f.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=na(this.pipeline.shaderLayout,this.id);f.table(Q,e)();let n=this.shaderInputs.getDebugTable();f.table(Q,n)();let r=this._getAttributeDebugTable();f.table(Q,this._attributeInfos)(),f.table(Q,r)(),f.groupEnd(Q)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(e){let n=this.device.props.debugFramebuffers;if(this._drawCount++,!n)return;let r=e.props.framebuffer;oa(e,r,{id:r?.id||`${this.id}-framebuffer`,minimap:!0})}_getAttributeDebugTable(){let e={};for(let[n,r]of Object.entries(this._attributeInfos)){let i=this.vertexArray.attributes[r.location];e[r.location]={name:n,type:r.shaderType,values:i?this._getBufferOrConstantValues(i,r.bufferDataType):`null`}}if(this.vertexArray.indexBuffer){let{indexBuffer:n}=this.vertexArray,r=n.indexType===`uint32`?new Uint32Array(n.debugData):new Uint16Array(n.debugData);e.indices={name:`indices`,type:n.indexType,values:r.toString()}}return e}_getBufferOrConstantValues(e,n){let r=I.getTypedArrayConstructor(n);return(e instanceof P?new r(e.debugData):e).toString()}_getNonMaterialBindings(e){if(!this.material)return e;let n={};for(let[r,i]of Object.entries(e))this.material.ownsBinding(r)||(n[r]=i);return n}_getCurrentShaderLayout(){return this.pipeline?.shaderLayout||this.props.shaderLayout||{bindings:[]}}_syncDynamicBuffers(){if(this._dynamicIndexBufferSource&&this._dynamicIndexBufferSource.generation!==this._dynamicIndexBufferSource.source.generation){let e=this._dynamicIndexBufferSource.source.buffer;this.indexBuffer=e,this.vertexArray.setIndexBuffer(e),this._dynamicIndexBufferSource.generation=this._dynamicIndexBufferSource.source.generation,this.setNeedsRedraw(`dynamic index buffer`)}for(let[e,n]of Object.entries(this._dynamicAttributeBufferSources))n.generation!==n.source.generation&&(this.vertexArray.setBuffer(Number(e),n.source.buffer),n.generation=n.source.generation,this.setNeedsRedraw(`dynamic attribute buffer`))}_syncAttachmentFormats(e){if(this.device.type!==`webgpu`)return;let n=e.framebuffer||e.props.framebuffer,r=e.props,i=r.colorAttachmentFormats??n?.colorAttachments?.map(s=>Rd(s?.texture?.format)),o=r.depthStencilAttachmentFormat===!1?void 0:r.depthStencilAttachmentFormat??wd(n?.depthStencilAttachment?.texture?.format);(!Ue(this._colorAttachmentFormats,i,1)||this._depthStencilAttachmentFormat!==o)&&(this._colorAttachmentFormats=i,this._depthStencilAttachmentFormat=o,this._setPipelineNeedsUpdate(`attachment formats`))}};function $r(t,e){return t.shaderLanguage!==void 0&&t.shaderLanguage!==e?!1:e===`glsl`?`assembleGLSLShaderPair`in t&&typeof t.assembleGLSLShaderPair==`function`:`assembleWGSLShader`in t&&typeof t.assembleWGSLShader==`function`}function Id(t,e){return!t||Object.keys(e).length===0?t:s(r({},t),{attributes:t.attributes.map(n=>{let r$25=n.name.startsWith(`_luma_`)?n.name.slice(6):null;return r$25&&e[r$25]?s(r({},n),{name:r$25}):n})})}function Ld(t,e,n){if(re(e)){let r=ln(n,t,{fallbackGroup:0});return r?e.resolveTextureBinding(r):null}return e instanceof k?e.buffer:Ee(e)?cn(e):e}function Rd(t){return t&&!ha(t)?t:null}function wd(t){return t&&ha(t)?t:void 0}function ha(t){return Ed.includes(t)}function Cd(t){return{type:t.type,shaderLanguage:t.info.shadingLanguage,shaderLanguageVersion:t.info.shadingLanguageVersion,gpu:t.info.gpu,limits:t.limits,features:t.features}}var Td=35980;var Pd=35981;var Hr=class t{device;model;transformFeedback;static defaultProps=s(r({},De.defaultProps),{feedbackBufferMode:`separate`,outputs:void 0,feedbackBuffers:void 0});static isSupported(e){return e?.info?.type===`webgl`}constructor(e,n=t.defaultProps){if(!t.isSupported(e))throw new Error(`BufferTransform not yet implemented on WebGPU`);this.device=e,this.model=new De(this.device,s(r({id:n.id||`buffer-transform-model`,fs:n.fs||Or(),topology:n.topology||`point-list`,varyings:n.outputs||n.varyings},n),{bufferMode:n.bufferMode||(n.feedbackBufferMode===`interleaved`?Td:Pd)})),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:n.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(e){e?.inputBuffers&&this.model.setAttributes(e.inputBuffers),e?.outputBuffers&&this.transformFeedback.setBuffers(e.outputBuffers);let n=this.device.beginRenderPass(r({discard:!0},e));this.model.draw(n),n.end()}getBuffer(e){return this.transformFeedback.getBuffer(e)}readAsync(e){let n=this.getBuffer(e);if(!n)throw new Error(`BufferTransform#getBuffer`);if(n instanceof P)return n.readAsync();let{buffer:r,byteOffset:i=0,byteLength:o=r.byteLength}=n;return r.readAsync(i,o)}};var Wr=class extends ne{constructor(e={}){let{id:n=G(`cube-geometry`),indices:r$26=!0}=e;super(r$26?s(r({},e),{id:n,topology:`triangle-list`,indices:{size:1,value:Nd},attributes:r(r({},zd),e.attributes)}):s(r({},e),{id:n,topology:`triangle-list`,indices:void 0,attributes:r(r({},$d),e.attributes)}))}};var Nd=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]);var Bd=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]);var Od=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]);var Ud=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]);var Fd=new Uint32Array([0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5]);var Vd=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]);var Dd=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]);var kd=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]);var Gd=new Uint32Array([3,3,3,3,3,3,4,4,4,4,4,4,2,2,2,2,2,2,5,5,5,5,5,5,0,0,0,0,0,0,1,1,1,1,1,1]);var zd={POSITION:{size:3,value:Bd},NORMAL:{size:3,value:Od},TEXCOORD_0:{size:2,value:Ud},faceIndex:{size:1,value:Fd}};var $d={POSITION:{size:3,value:Vd},TEXCOORD_0:{size:2,value:Dd},COLOR_0:{size:3,value:kd},faceIndex:{size:1,value:Gd}};var jr=2;var Hd=1e4;var qr=class t{static defaultProps=s(r({},N$1.defaultProps),{id:`unnamed`,handle:void 0,userData:{},source:``,modules:[],defines:{},plugins:[],bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:fe.getDefaultShaderAssembler(`wgsl`),debugShaders:void 0});device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate=`newly created`;_getModuleUniforms;props;_destroyed=!1;constructor(e,n){if(e.type!==`webgpu`)throw new Error(`Computation is only supported in WebGPU`);this.props=r(r({},t.defaultProps),n),n=this.props,this.id=n.id||G(`model`),this.device=e,Object.assign(this.userData,n.userData);let r$27=Wd(e),i=at(this.props.plugins,r$27.shaderLanguage);if(Object.keys(i.vertexInputs).length>0||Object.keys(i.varyings).length>0)throw new Error(`Computation does not support ShaderPlugin vertex inputs or varyings`);let o=ct(this.props.modules,i.modules),s$9=Object.fromEntries(o.map(h=>[h.name,h]));this.shaderInputs=n.shaderInputs||new J(s$9),n.shaderInputs&&i.modules.length>0&&this.shaderInputs.addModules(i.modules),this.setShaderInputs(this.shaderInputs);let a=an(this.props.modules,this.shaderInputs?.getModules()),c=r(r({},i.defines),this.props.defines);this.props.shaderLayout=Ve(this.props.shaderLayout,a)||null,this.pipelineFactory=n.pipelineFactory||qe.getDefaultPipelineFactory(this.device),this.shaderFactory=n.shaderFactory||Ke$1.getDefaultShaderFactory(this.device);let l=this.props.shaderAssembler;He(l instanceof Oe);let{source:f,getUniforms:u,shaderLayout:p}=l.assembleWGSLShader(s(r({platformInfo:r$27},this.props),{modules:a,defines:c,scanVertexAttributes:!1,pluginInjections:i.injections}));this.source=f,this._getModuleUniforms=u;let d=p??e.getShaderLayout?.(this.source,{scanVertexAttributes:!1});this.props.shaderLayout=Ve(this.props.shaderLayout||d||null,a)||null,this.pipeline=this._updatePipeline(),n.bindings&&this.setBindings(n.bindings)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(e){this.updateShaderInputs(e)}dispatch(e,n,r,i){try{this._logDrawCallStart(),this._setPipeline(e),e.dispatch(n,r,i)}finally{this._logDrawCallEnd()}}dispatchIndirect(e,n,r=0){try{this._logDrawCallStart(),this._setPipeline(e),e.dispatchIndirect(n,r)}finally{this._logDrawCallEnd()}}_setPipeline(e){this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),e.setPipeline(this.pipeline),e.setBindings({})}setVertexCount(e){}setInstanceCount(e){}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new lt$1(this.device,this.shaderInputs.modules);for(let[n,r]of Object.entries(this.shaderInputs.modules))if(Ae(r)){let i=this._uniformStore.getManagedUniformBuffer(n);this.bindings[`${n}Uniforms`]=i}}setShaderModuleProps(e){let n=this._getModuleUniforms(e),r=Object.keys(n).filter(o=>{let s=n[o];return!dt(s)&&typeof s!=`number`&&typeof s!=`boolean`}),i={};for(let o of r)i[o]=n[o],delete n[o]}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e)}setBindings(e){Object.assign(this.bindings,e)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||e}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null;this.pipeline&&(f.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:`compute`,source:this.source,debugShaders:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline(s(r({},this.props),{shader:this.shader})),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=f.level>3?0:Hd;f.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,f.group(jr,`>>> DRAWING MODEL ${this.id}`,{collapsed:f.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=this.shaderInputs.getDebugTable();f.table(jr,e)(),f.groupEnd(jr)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(e,n){let r=I.getTypedArrayConstructor(n);return(e instanceof P?new r(e.debugData):e).toString()}};function Wd(t){return{type:t.type,shaderLanguage:t.info.shadingLanguage,shaderLanguageVersion:t.info.shadingLanguageVersion,gpu:t.info.gpu,limits:t.limits,features:t.features}}var Yr=class{name;playing=!0;speed=1;startTime=0;constructor(e={}){this.name=e.name||`unnamed`,Object.assign(this,e)}setTime(e){if(!this.playing)return;let r=(e/1e3-this.startTime)*this.speed;this.applyTime(r)}};var Xr=class{clips;animations;constructor(e){this.clips=e,this.animations=e}animate(e){f.warn(`${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`)(),this.setTime(e)}setTime(e){this.clips.forEach(n=>n.setTime(e))}getAnimations(){return this.clips}};function ma(t,e,n=`vector`){let{input:r,output:i,interpolation:o=`LINEAR`}=e;if(!r.length||!i.length||!Number.isFinite(t))return null;let s=r.length-1;if(t<=r[0]||s===0)return Zr(i,o,0,n);if(t>=r[s])return Zr(i,o,s,n);let a=0,c=s;for(;c-a>1;){let d=Math.floor((a+c)/2);r[d]<=t?a=d:c=d}let l=r[a],u=r[c]-l;if(u<=0||o===`STEP`)return Zr(i,o,a,n);let p=(t-l)/u;switch(o){case`LINEAR`:{let d=i[a],h=i[c];return!d||!h?null:n===`quaternion`?fn(d,h,p):jd(d,h,p)}case`CUBICSPLINE`:{let d=i[a*3+1],h=i[a*3+2],g=i[c*3],m=i[c*3+1];if(!d||!h||!g||!m)return null;let _=qd(d,h,g,m,u,p);return n===`quaternion`?ke(_):_}default:return null}}function fn(t,e,n){let r=ke(t),i=ke(e),o=r.reduce((u,p,d)=>u+p*i[d],0),s=o<0?-1:1;if(o=Math.min(Math.abs(o),1),o>.9995)return ke(r.map((u,p)=>u+n*(i[p]*s-u)));let a=Math.acos(o),c=Math.sin(a),l=Math.sin((1-n)*a)/c,f=Math.sin(n*a)/c*s;return ke(r.map((u,p)=>u*l+i[p]*f))}function Zr(t,e,n,r){let i=t[e===`CUBICSPLINE`?n*3+1:n];return i?r===`quaternion`?ke(i):[...i]:null}function jd(t,e,n){return t.map((r,i)=>(1-n)*r+n*e[i])}function qd(t,e,n,r,i,o){let s=o*o,a=s*o;return t.map((c,l)=>(2*a-3*s+1)*c+(a-2*s+o)*e[l]*i+(-2*a+3*s)*r[l]+(a-s)*n[l]*i)}function ke(t){let e=Math.hypot(...t);return e>0?t.map(n=>n/e):[0,0,0,1]}var Kr=class{name;times;values;interpolation;valueType;binding;constructor(e){this.name=e.name||e.binding.id||`unnamed`,this.times=e.times,this.values=e.values,this.interpolation=e.interpolation||`LINEAR`,this.valueType=e.valueType||`vector`,this.binding=e.binding}get duration(){return this.times[this.times.length-1]||0}get sampler(){return{input:this.times,output:this.values,interpolation:this.interpolation}}evaluate(e){return ma(e,this.sampler,this.valueType)}};var Jr=class{name;tracks;duration;constructor(e){this.name=e.name||`unnamed`,this.tracks=e.tracks,this.duration=e.duration??Math.max(0,...e.tracks.map(n=>n.duration))}};var un=class{clip;mixer;time=0;timeScale;weight;loop;repetitions;paused=!1;playing=!1;elapsedTime=0;fade=null;constructor(e,n,r={}){this.mixer=e,this.clip=n,this.loop=r.loop||`repeat`,this.repetitions=r.repetitions??Number.POSITIVE_INFINITY,this.timeScale=r.timeScale??1,this.weight=r.weight??1}play(){return this.playing=!0,this.paused=!1,this}pause(){return this.paused=!0,this}resume(){return this.playing=!0,this.paused=!1,this}stop(){return this.playing=!1,this.paused=!1,this.fade=null,this.reset()}reset(){return this.elapsedTime=0,this.time=0,this}setTime(e){return this.elapsedTime=e,this.time=this.resolveLocalTime(e),this}setLoop(e,n=Number.POSITIVE_INFINITY){return this.loop=e,this.repetitions=n,this.time=this.resolveLocalTime(this.elapsedTime),this}setEffectiveWeight(e){return this.weight=Math.max(0,e),this.fade=null,this}setEffectiveTimeScale(e){return this.timeScale=e,this}fadeIn(e){return this.scheduleFade(1,e)}fadeOut(e){return this.scheduleFade(0,e)}crossFadeTo(e,n){return e.weight=0,e.play().fadeIn(n),this.fadeOut(n)}crossFadeFrom(e,n){return e.crossFadeTo(this,n),this}advance(e){!this.playing||this.paused||(this.advanceFade(Math.abs(e)),this.elapsedTime+=e*this.timeScale,this.time=this.resolveLocalTime(this.elapsedTime),this.hasFinished()&&(this.playing=!1))}get shouldApply(){return(this.playing||this.hasFinished())&&this.weight>0}scheduleFade(e,n){return n<=0?(this.weight=e,this.fade=null,this):(this.fade={duration:n,elapsedTime:0,startWeight:this.weight,endWeight:e},this)}advanceFade(e){if(!this.fade)return;this.fade.elapsedTime+=e;let n=Math.min(this.fade.elapsedTime/this.fade.duration,1);this.weight=this.fade.startWeight+(this.fade.endWeight-this.fade.startWeight)*n,n===1&&(this.fade=null)}hasFinished(){let e=this.clip.duration;return e<=0?this.loop===`once`:this.loop===`once`?this.elapsedTime>=e||this.elapsedTime<0:Number.isFinite(this.repetitions)&&Math.abs(this.elapsedTime)>=e*this.repetitions}resolveLocalTime(e){let n=this.clip.duration;if(n<=0)return 0;if(this.loop===`once`)return Math.min(Math.max(e,0),n);if(Number.isFinite(this.repetitions)&&Math.abs(e)>=n*this.repetitions)return this.loop===`ping-pong`&&this.repetitions%2===0||e<0?0:n;let r=e>=0&&e<n?e:(e%n+n)%n;if(this.loop===`repeat`)return r;let i=Math.floor(e/n);return Math.abs(i%2)===0?r:n-r}};var Qr=class{time=0;timeScale=1;clips=new Map;actions=new Map;initialValues=new Map;constructor(e=[]){e.forEach(n=>this.addClip(n))}addClip(e){return this.clips.set(e.name,e),this}clipAction(e,n){let r=typeof e==`string`?this.clips.get(e):e;if(!r)throw new Error(`Unknown animation clip: ${e}`);this.addClip(r);let i=this.actions.get(r);return i||(i=new un(this,r,n),this.actions.set(r,i)),i}getAction(e){let n=this.clips.get(e);return n?this.actions.get(n):void 0}update(e){return this.advance(e),this.applyValues(),this}advance(e){let n=e*this.timeScale;return this.time+=n,this.actions.forEach(r=>r.advance(n)),this}setTime(e){return this.time=e,this.actions.forEach(n=>{n.paused||n.setTime(e*n.timeScale)}),this.applyValues(),this}stopAllAction(){return this.actions.forEach(e=>e.stop()),this}applyValues(){let e=new Map;this.actions.forEach(n=>{!n.shouldApply&&!(n.playing&&n.weight===0)||n.clip.tracks.forEach(r=>{let i=r.evaluate(n.time);if(!i)return;let o=r.binding.id||r.binding;if(!this.initialValues.has(o)){let l=r.binding.getValue?.();l&&this.initialValues.set(o,[...l])}if(n.weight===0&&!this.initialValues.has(o))return;let s=e.get(o);if(!s){e.set(o,{binding:r.binding,value:[...i],valueType:r.valueType,weight:n.weight});return}if(n.weight===0)return;let a=s.weight+n.weight,c=n.weight/a;s.value=r.valueType===`quaternion`?fn(s.value,i,c):s.value.map((l,f)=>l+(i[f]-l)*c),s.weight=a})}),e.forEach(({binding:n,value:r,valueType:i,weight:o},s)=>{let a=o<1?this.initialValues.get(s):void 0;a&&a.length===r.length&&(r=i===`quaternion`?fn(a,r,o):r.map((c,l)=>a[l]+(c-a[l])*o)),n.setValue(r)})}};function ga(t){let e=t.value;if(e instanceof Float32Array)return e;let n=new Float32Array(e.length),r=_a(e),i=e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array;for(let o=0;o<e.length;o++){let s=Number(e[o]);n[o]=t.normalized&&r?i?Math.max(s/r,-1):s/r:s}return n}function ba(t,e,n){let r={};for(let i of[`POSITION`,`NORMAL`,`TANGENT`]){let o=t[i];if(!o)continue;let s=new Float32Array(o),a=i===`TANGENT`?4:3,c=Math.floor(o.length/a);for(let l=0;l<Math.min(e.length,n.length);l++){let f=n[l],u=e[l][i];if(!f||!u)continue;let p=i===`TANGENT`&&u.length===c*4?4:3;for(let d=0;d<c;d++){let h=d*a,g=d*p;for(let m=0;m<3;m++)s[h+m]+=(u[g+m]||0)*f}}i!==`POSITION`&&Zd(s,a),r[i]=s}return r}function Yd(t,e,n,r$28){let i={};for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=e.attributes[u];p&&(i[u]=ga(p))}let o=ba(i,n,r$28),s$10={};for(let[u,p]of Object.entries(e.attributes))p&&(s$10[u]=p);for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=o[u],d=s$10[u];p&&d&&(s$10[u]=s(r({},d),{value:Xd(d,p)}))}let l=pt(new ne({id:e.id,topology:e.topology||`triangle-list`,vertexCount:e.vertexCount,indices:e.indices,attributes:s$10,bufferLayout:e.bufferLayout})).attributes.geometry?.value,f=t._gpuGeometry?.attributes.geometry||t.bufferAttributes.geometry;if(l&&f){f.write(l);return}for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=o[u];if(p){let d=u===`POSITION`?`positions`:u===`NORMAL`?`normals`:`TANGENT`;t.bufferAttributes[d]?.write(p)}}}function Xd(t,e){if(t.value instanceof Float32Array)return e;let n=t.value.slice(),r=_a(n),i=n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array;for(let o=0;o<e.length;o++){let s=e[o];n[o]=t.normalized&&r?Math.round(Math.max(i?-1:0,Math.min(1,s))*r):s}return n}function _a(t){return t instanceof Int8Array?127:t instanceof Uint8Array||t instanceof Uint8ClampedArray?255:t instanceof Int16Array?32767:t instanceof Uint16Array?65535:t instanceof Int32Array?2147483647:t instanceof Uint32Array?4294967295:0}function Zd(t,e){for(let n=0;n<t.length;n+=e){let r=Math.hypot(t[n],t[n+1],t[n+2]);r>0&&(t[n]/=r,t[n+1]/=r,t[n+2]/=r)}}function Kd(t){let{joints:e,meshNode:n,worldMatrices:r,inverseBindMatrices:i,target:o}=t,s=e.length,a=o&&o.length===s*16?o:new Float32Array(s*16),c=n?r.get(n)||n.matrix:void 0,l=c?new U(c).invert():null;for(let f=0;f<s;f++){let u=e[f],p=r.get(u)||u.matrix,d=l?new U(l).multiplyRight(p):new U(p),h=f*16;if(i&&i.length>=h+16){let g=new U;for(let m=0;m<16;m++)g[m]=i[h+m];d.multiplyRight(g)}a.set(d,h)}return a}var Jd=1;var Qd=1;var ei=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(e){let{delay:n=0,duration:r=Number.POSITIVE_INFINITY,rate:i=1,repeat:o=1}=e,s=Jd++,a={time:0,delay:n,duration:r,rate:i,repeat:o};return this._setChannelTime(a,this.time),this.channels.set(s,a),s}removeChannel(e){this.channels.delete(e);for(let[n,r]of this.animations)r.channel===e&&this.detachAnimation(n)}isFinished(e){let n=this.channels.get(e);return n===void 0?!1:this.time>=n.delay+n.duration*n.repeat}getTime(e){if(e===void 0)return this.time;let n=this.channels.get(e);return n===void 0?-1:n.time}setTime(e){this.time=Math.max(0,e);let n=this.channels.values();for(let i of n)this._setChannelTime(i,this.time);let r=this.animations.values();for(let i of r){let{animation:o,channel:s}=i;o.setTime(this.getTime(s))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(e,n){let r=Qd++;return this.animations.set(r,{animation:e,channel:n}),e.setTime(this.getTime(n)),r}detachAnimation(e){this.animations.delete(e)}update(e){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=e),this.setTime(this.time+(e-this.lastEngineTime)),this.lastEngineTime=e)}_setChannelTime(e,n){let r=n-e.delay;r>=e.duration*e.repeat?e.time=e.duration*e.rate:(e.time=Math.max(0,r)%e.duration,e.time*=e.rate)}};function va(t){let e=typeof window<`u`?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:null;return e?e.call(window,t):setTimeout(()=>t(typeof performance<`u`?performance.now():Date.now()),1e3/60)}function xa(t){let e=typeof window<`u`?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(e){e.call(window,t);return}clearTimeout(t)}var eh=0;var th=`Animation Loop`;var Sa={requestAnimationFrame:t=>va(t),cancelAnimationFrame:t=>xa(t)};var ti=class t{static defaultAnimationLoopProps={device:null,onAddHTML:()=>``,onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:e=>{console.error(e)},stats:void 0,autoResizeViewport:!1,animationFrameProvider:Sa};device=null;canvas=null;props;animationProps=null;timeline=null;stats;sharedStats;cpuTime;gpuTime;frameRate;display;_needsRedraw=`initialized`;_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;_lastFrameTime=0;constructor(e){if(this.props=r(r({},t.defaultAnimationLoopProps),e),e=this.props,!e.device)throw new Error(`No device provided`);this.stats=e.stats||new j({id:`animation-loop-${eh++}`}),this.sharedStats=Qr$1.stats.get(th),this.frameRate=this.stats.get(`Frame Rate`),this.frameRate.setSampleSize(1),this.cpuTime=this.stats.get(`CPU Time`),this.gpuTime=this.stats.get(`GPU Time`),this.setProps({autoResizeViewport:e.autoResizeViewport,animationFrameProvider:e.animationFrameProvider}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null),this.device?._disableDebugGPUTime()}delete(){this.destroy()}reportError(e){this._error=e,this.props.onError(e),this.props.onError===t.defaultAnimationLoopProps.onError&&typeof window<`u`&&typeof ErrorEvent<`u`&&window.dispatchEvent(new ErrorEvent(`error`,{error:e,message:e.message}))}setNeedsRedraw(e){return this._needsRedraw=this._needsRedraw||e,this}needsRedraw(){let e=this._needsRedraw;return this._needsRedraw=!1,e}setProps(e){if(`autoResizeViewport`in e&&(this.props.autoResizeViewport=e.autoResizeViewport||!1),`animationFrameProvider`in e){let n=e.animationFrameProvider||Sa;if(n!==this.props.animationFrameProvider){let r=this._animationFrameId!==null;r&&this._cancelAnimationFrame(),this.props.animationFrameProvider=n,r&&this._requestAnimationFrame()}}return this}async start(){if(this._running)return this;this._running=!0;try{if(!this._initialized){if(this._initialized=!0,await this._initDevice(),this._initialize(),!this._running)return null;await this.props.onInitialize(this._getAnimationProps())}return this._running?(this._cancelAnimationFrame(),this._requestAnimationFrame(),this):null}catch(e){let n=e instanceof Error?e:new Error(`Unknown error`);throw this.props.onError(n),n}}stop(){if(this._running){let e=this.animationProps;this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1,this._lastFrameTime=0,e&&this.props.onFinalize(e)}return this}redraw(e,n=null){return this.device?.isLost||this._error?this:(this._beginFrameTimers(e),this._setupFrame(),this.animationProps&&(this.animationProps.animationFrame=n),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(e){return this.timeline=e,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw(`waitForRender`),this._nextFramePromise||(this._nextFramePromise=new Promise(e=>{this._resolveNextFrame=e})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw(`toDataURL`),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error(`OffscreenCanvas`)}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeViewport(),this.device?._enableDebugGPUTime()}_setDisplay(e){this.display&&(this.display.destroy(),this.display.animationLoop=null),e&&(e.animationLoop=this),this.display=e}_requestAnimationFrame(){this._running&&(this._animationFrameId=this.props.animationFrameProvider.requestAnimationFrame(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(this.props.animationFrameProvider.cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_animationFrame(e,n){if(this._running)try{this.redraw(e,n??null),this._requestAnimationFrame()}catch(r){let i=r instanceof Error?r:new Error(String(r));this.reportError(i),this.stop()}}_renderFrame(e){if(this.display){this.display._renderFrame(e);return}let n=this.props.onRender(this._getAnimationProps());this.device&&n!==!1&&this.device.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let e=this.device?.getDefaultCanvasContext();if(!this.device||!e)throw new Error(`loop`);let n=e?.canvas,r=e.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:e,canvas:n,useDevicePixels:r,timeline:this.timeline,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,animationFrame:null,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error(`animationProps`);return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:e,height:n,aspect:r}=this._getSizeAndAspect();(e!==this.animationProps.width||n!==this.animationProps.height)&&this.setNeedsRedraw(`drawing buffer resized`),r!==this.animationProps.aspect&&this.setNeedsRedraw(`drawing buffer aspect changed`),this.animationProps.width=e,this.animationProps.height=n,this.animationProps.aspect=r,this.animationProps.needsRedraw=this._needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error(`No device provided`);this.canvas=this.device.getDefaultCanvasContext().canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let e=document.createElement(`div`);document.body.appendChild(e),e.style.position=`relative`;let n=document.createElement(`div`);n.style.position=`absolute`,n.style.left=`10px`,n.style.bottom=`10px`,n.style.width=`300px`,n.style.background=`white`,this.canvas instanceof HTMLCanvasElement&&e.appendChild(this.canvas),e.appendChild(n);let r=this.props.onAddHTML(n);r&&(n.innerHTML=r)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[e,n]=this.device.getDefaultCanvasContext().getDrawingBufferSize();return{width:e,height:n,aspect:e>0&&n>0?e/n:1}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(e){let n=e??(typeof performance<`u`?performance.now():Date.now());if(this._lastFrameTime){let r=n-this._lastFrameTime;r>0&&this.frameRate.addTime(r)}this._lastFrameTime=n,this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeStart()}_endFrameTimers(){this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeEnd(),this._updateSharedStats()}_consumeEncodedGpuTime(){if(!this.device)return;let e=this.device.commandEncoder._gpuTimeMs;e!==void 0&&(this.gpuTime.addTime(e),this.device.commandEncoder._gpuTimeMs=void 0)}_updateSharedStats(){if(this.stats!==this.sharedStats){for(let e of Object.keys(this.sharedStats.stats))this.stats.stats[e]||delete this.sharedStats.stats[e];this.stats.forEach(e=>{let n=this.sharedStats.get(e.name,e.type);n.sampleSize=e.sampleSize,n.time=e.time,n.count=e.count,n.samples=e.samples,n.lastTiming=e.lastTiming,n.lastSampleTime=e.lastSampleTime,n.lastSampleCount=e.lastSampleCount,n._count=e._count,n._time=e._time,n._samples=e._samples,n._startTime=e._startTime,n._timerPending=e._timerPending})}}_startEventHandling(){this.canvas&&(this.canvas.addEventListener(`mousemove`,this._onMousemove.bind(this)),this.canvas.addEventListener(`mouseleave`,this._onMouseleave.bind(this)))}_onMousemove(e){e instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[e.offsetX,e.offsetY])}_onMouseleave(e){this._getAnimationProps()._mousePosition=null}};var Ge=3;var mt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(e,n={}){this.device=e,this.modules=n.modules||[];let r=new J(Object.fromEntries(this.modules.map(i=>[i.name,i])));this._materialBindingNames=nh(r),this._materialModuleNames=rh(r)}createMaterial(e={}){return new pn(this.device,s(r({},e),{factory:this}))}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(e){if(this._materialBindingNames.has(e))return!0;let n=ni(e);return n?this._materialModuleNames.has(n):!1}ownsModule(e){return this._materialModuleNames.has(e)}getBindingsByGroup(e){return Object.keys(e).length>0?{[Ge]:e}:{}}};function ni(t){return t.endsWith(`Uniforms`)?t.slice(0,-8):null}function nh(t){let e=new Set;for(let n of Object.values(t.modules))for(let r of n.bindingLayout||[])r.group===Ge&&e.add(r.name);return e}function rh(t){let e=new Set;for(let n of Object.values(t.modules))n.name&&n.bindingLayout?.some(r=>r.group===Ge&&r.name===n.name)&&e.add(n.name);return e}var pn=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};_dynamicResourceGenerations={};constructor(e,n={}){this.id=n.id||G(`material`),this.device=e,this.factory=n.factory||new mt(e,{modules:n.modules||n.shaderInputs?.getModules()||[]});let r=Object.fromEntries((n.shaderInputs?.getModules()||this.factory.modules).map(i=>[i.name,i]));this.shaderInputs=n.shaderInputs||new J(r),this._uniformStore=new lt$1(this.device,this.shaderInputs.modules);for(let[i,o]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(i)&&Ae(o)){let s=this._uniformStore.getManagedUniformBuffer(i);this.bindings[`${i}Uniforms`]=s}this.updateShaderInputs(),n.bindings&&this._replaceOwnedBindings(n.bindings)}destroy(){this._uniformStore.destroy()}clone(e={}){let n=this.factory.createMaterial({id:e.id,shaderInputs:e.shaderInputs,bindings:r(r({},this.getResourceBindings()),e.bindings)});return e.shaderInputs||n.setProps(this.shaderInputs.getUniformValues()),e.moduleProps&&n.setProps(e.moduleProps),n.updateShaderInputs(),n}ownsBinding(e){return this.factory.ownsBinding(e)}ownsModule(e){return this.factory.ownsModule(e)}setProps(e){this.shaderInputs.setProps(e)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){let e={};for(let[n,r]of Object.entries(this.bindings))ni(n)||(e[n]=r);return e}getBindings(e={bindings:[]}){this._syncDynamicResourceGenerations();let n={},r=n;for(let[i,o]of Object.entries(this.bindings))if(re(o)){let s=ln(e,i,{fallbackGroup:Ge}),a=s?o.resolveTextureBinding(s):null;a&&(r[i]=a)}else o instanceof k?r[i]=o.buffer:Ee(o)?r[i]=cn(o):r[i]=o;return this._syncDynamicResourceGenerations(),n}getBindingsByGroup(e={bindings:[]}){return this.factory.getBindingsByGroup(this.getBindings(e))}getBindGroupCacheKey(e){return this._syncDynamicResourceGenerations(),e===Ge?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let e=0;for(let n of Object.values(this.bindings))n instanceof je?e=Math.max(e,n.texture.updateTimestamp):n instanceof P||n instanceof v||n instanceof Qe$1||n instanceof k?e=Math.max(e,n.updateTimestamp):re(n)?e=n.isReady?Math.max(e,n.updateTimestamp):Infinity:Ee(n)&&(e=Math.max(e,(n.buffer instanceof k,n.buffer.updateTimestamp)));return e}_replaceOwnedBindings(e){this._setOwnedBindings(e)&&(this._bindGroupCacheToken={})}_setOwnedBindings(e){let n=!1;for(let[r,i]of Object.entries(e))i!==void 0&&this.ownsBinding(r)&&this.bindings[r]!==i&&(this.bindings[r]=i,n=!0);return n}_syncDynamicResourceGenerations(){let e={},n=!1;for(let[r,i]of Object.entries(this.bindings)){let o=ih(i);o!==null&&(e[r]=o,this._dynamicResourceGenerations[r]!==o&&(n=!0))}Object.keys(e).length!==Object.keys(this._dynamicResourceGenerations).length&&(n=!0),this._dynamicResourceGenerations=e,n&&(this._bindGroupCacheToken={})}};function ih(t){return re(t)?t.generation:da(t)?.generation??null}var ri={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function gt(t){return t?Array.isArray(t)?t[0]??null:t:null}function ya(t){let{dimension:e,data:n}=t;if(!n)return null;switch(e){case`1d`:{let r=gt(n);if(!r)return null;let{width:i}=bt(r);return{width:i,height:1}}case`2d`:{if(ArrayBuffer.isView(n))return null;let r=gt(n);return r?bt(r):null}case`3d`:case`2d-array`:{if(!Array.isArray(n)||n.length===0)return null;let r=gt(n[0]);return r?bt(r):null}case`cube`:{let r=Object.keys(n)[0]??null;if(!r)return null;let i=n[r],o=gt(i);return o?bt(o):null}case`cube-array`:{if(!Array.isArray(n)||n.length===0)return null;let r=n[0],i=Object.keys(r)[0]??null;if(!i)return null;let o=gt(r[i]);return o?bt(o):null}default:return null}}function bt(t){if(We(t))return $e$1(t);if(typeof t==`object`&&`width`in t&&`height`in t)return{width:t.width,height:t.height};throw new Error(`Unsupported mip-level data`)}function oh(t){return typeof t==`object`&&t!==null&&`data`in t&&`width`in t&&`height`in t}function sh(t){return ArrayBuffer.isView(t)}function ii(t){let{textureFormat:e,format:n}=t;if(e&&n&&e!==n)throw new Error(`Conflicting texture formats "${e}" and "${n}" provided for the same mip level`);return e??n}function Ma(t){let e=ri[t];if(e===void 0)throw new Error(`Invalid cube face: ${t}`);return e}function ah(t,e){return 6*t+Ma(e)}function oi(t){throw new Error(`setTexture1DData not supported in WebGL.`)}function ch(t){return Array.isArray(t)?t:[t]}function Ie(t,e,n,r$29){let i=ch(e),o=t,s=[];for(let a=0;a<i.length;a++){let c=i[a];if(We(c))s.push({type:`external-image`,image:c,z:o,mipLevel:a});else if(oh(c))s.push({type:`texture-data`,data:c,textureFormat:ii(c),z:o,mipLevel:a});else if(sh(c)&&n)s.push({type:`texture-data`,data:r({data:c,width:Math.max(1,n.width>>a),height:Math.max(1,n.height>>a)},r$29?{format:r$29}:{}),textureFormat:r$29,z:o,mipLevel:a});else throw new Error(`Unsupported 2D mip-level payload`)}return s}function si(t){let e=[];for(let n=0;n<t.length;n++)e.push(...Ie(n,t[n]));return e}function ai(t){let e=[];for(let n=0;n<t.length;n++)e.push(...Ie(n,t[n]));return e}function ci(t){let e=[];for(let[n,r]of Object.entries(t)){let i=Ma(n);e.push(...Ie(i,r))}return e}function li(t){let e=[];return t.forEach((n,r)=>{for(let[i,o]of Object.entries(n)){let s=ah(r,i);e.push(...Ie(s,o))}}),e}var fi=class t{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;generation=0;updateTimestamp;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error(`Texture not initialized yet`);return this._texture}get sampler(){if(!this._sampler)throw new Error(`Sampler not initialized yet`);return this._sampler}get view(){if(!this._view)throw new Error(`View not initialized yet`);return this._view}get[Symbol.toStringTag](){return`DynamicTexture`}toString(){let e=this._texture?.width??this.props.width??`?`,n=this._texture?.height??this.props.height??`?`;return`DynamicTexture:"${this.id}":${e}x${n}px:(${this.isReady?`ready`:`loading...`})`}resolveTextureBinding(e){return this.isReady?this.texture:null}constructor(e,n){this.device=e;let r$30=G(`dynamic-texture`),i=n;this.props=s(r(s(r({},t.defaultProps),{id:r$30}),n),{data:null}),this.id=this.props.id,this.ready=new Promise((o,s)=>{this.resolveReady=o,this.rejectReady=s}),this.updateTimestamp=this.device.incrementTimestamp(),this.initAsync(i)}async initAsync(e){try{let n=await this._loadAllData(e);this._checkNotDestroyed();let r$31=n.data?lh(s(r({},n),{width:e.width,height:e.height,format:e.format})):[],i=`format`in e&&e.format!==void 0,o=`usage`in e&&e.usage!==void 0,a=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};return ya(n)||{width:this.props.width||1,height:this.props.height||1}})();if(!a||a.width<=0||a.height<=0)throw new Error(`${this} size could not be determined or was zero`);let c=fh(this.device,r$31,a,{format:i?e.format:void 0}),l=c.format??this.props.format,f$2=s(r(r({},this.props),a),{format:l,mipLevels:1,data:void 0});this.device.isTextureFormatCompressed(l)&&!o&&(f$2.usage=v.SAMPLE|v.COPY_DST);let u=this.props.mipmaps&&!c.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(l);if(this.device.type===`webgpu`&&u){let g=this.props.dimension===`3d`?v.SAMPLE|v.STORAGE|v.COPY_DST|v.COPY_SRC:v.SAMPLE|v.RENDER|v.COPY_DST|v.COPY_SRC;f$2.usage|=g}let p=this.device.getMipLevelCount(f$2.width,f$2.height),d=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels===`auto`?p:Math.max(1,Math.min(p,this.props.mipLevels??1)),h=s(r({},f$2),{mipLevels:d});this._texture=this.device.createTexture(h),this._sampler=this.texture.sampler,this._view=this.texture.view,this._touchGeneration(),c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!u&&f.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),u&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),f.info(1,`${this} created`)()}catch(n){let r=n instanceof Error?n:new Error(String(n));this.rejectReady(r)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.isReady=!1,this.destroyed=!0}generateMipmaps(){this.device.type===`webgl`?(this.texture.generateMipmapsWebGL(),this._touch()):this.device.type===`webgpu`?(this.device.generateMipmapsWebGPU(this.texture),this._touch()):f.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();let n=e instanceof Y$1?e:this.device.createSampler(e);this.texture.setSampler(n),this._sampler=n,this._touchGeneration()}async readBuffer(e={}){this.isReady||await this.ready;let n=e.width??this.texture.width,r$32=e.height??this.texture.height,i=e.depthOrArrayLayers??this.texture.depth,o=this.texture.computeMemoryLayout({width:n,height:r$32,depthOrArrayLayers:i}),s$11=this.device.createBuffer({byteLength:o.byteLength,usage:P.COPY_DST|P.MAP_READ});this.texture.readBuffer(s(r({},e),{width:n,height:r$32,depthOrArrayLayers:i}),s$11);let a=this.device.createFence();return await a.signaled,a.destroy(),s$11}async readAsync(e={}){this.isReady||await this.ready;let n=e.width??this.texture.width,r=e.height??this.texture.height,i=e.depthOrArrayLayers??this.texture.depth,o=this.texture.computeMemoryLayout({width:n,height:r,depthOrArrayLayers:i}),s=await this.readBuffer(e),a=await s.readAsync(0,o.byteLength);return s.destroy(),a.buffer instanceof ArrayBuffer?a.buffer:a.slice().buffer}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;let n=this.texture;return this._texture=n.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,n.destroy(),this._touchGeneration(),f.info(`${this} resized`),!0}getCubeFaceIndex(e){let n=ri[e];if(n===void 0)throw new Error(`Invalid cube face: ${e}`);return n}getCubeArrayFaceIndex(e,n){return 6*e+this.getCubeFaceIndex(n)}setTexture1DData(e){if(this._checkReady(),this.texture.props.dimension!==`1d`)throw new Error(`${this} is not 1d`);let n=oi(e);this._setTextureSubresources(n)}setTexture2DData(e,n=0){if(this._checkReady(),this.texture.props.dimension!==`2d`)throw new Error(`${this} is not 2d`);let r=Ie(n,e);this._setTextureSubresources(r)}setTexture3DData(e){if(this.texture.props.dimension!==`3d`)throw new Error(`${this} is not 3d`);let n=si(e);this._setTextureSubresources(n)}setTextureArrayData(e){if(this.texture.props.dimension!==`2d-array`)throw new Error(`${this} is not 2d-array`);let n=ai(e);this._setTextureSubresources(n)}setTextureCubeData(e){if(this.texture.props.dimension!==`cube`)throw new Error(`${this} is not cube`);let n=ci(e);this._setTextureSubresources(n)}setTextureCubeArrayData(e){if(this.texture.props.dimension!==`cube-array`)throw new Error(`${this} is not cube-array`);let n=li(e);this._setTextureSubresources(n)}_setTextureSubresources(e){for(let n of e){let{z:r,mipLevel:i}=n;switch(n.type){case`external-image`:let{image:o,flipY:s}=n;this.texture.copyExternalImage({image:o,z:r,mipLevel:i,flipY:s});break;case`texture-data`:let{data:a,textureFormat:c}=n;if(c&&c!==this.texture.format)throw new Error(`${this} mip level ${i} uses format "${c}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:r,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:i});break;default:throw new Error(`Unsupported 2D mip-level payload`)}}e.length>0&&this._touch()}async _loadAllData(e){let n=await ui(e.data);return{dimension:e.dimension??`2d`,data:n??null}}_checkNotDestroyed(){this.destroyed&&f.warn(`${this} already destroyed`)}_checkReady(){this.isReady||f.warn(`${this} Cannot perform this operation before ready`)}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}static defaultProps=s(r({},v.defaultProps),{dimension:`2d`,data:null,mipmaps:!1})};function lh(t){if(!t.data)return[];let e=t.width&&t.height?{width:t.width,height:t.height}:void 0,n=`format`in t?t.format:void 0;switch(t.dimension){case`1d`:return oi(t.data);case`2d`:return Ie(0,t.data,e,n);case`3d`:return si(t.data);case`2d-array`:return ai(t.data);case`cube`:return ci(t.data);case`cube-array`:return li(t.data);default:throw new Error(`Unhandled dimension ${t.dimension}`)}}function fh(t,e,n,r){if(e.length===0)return{subresources:e,mipLevels:1,format:r.format,hasExplicitMipChain:!1};let i=new Map;for(let f of e){let u=i.get(f.z)??[];u.push(f),i.set(f.z,u)}let o=e.some(f=>f.mipLevel>0),s=r.format,a=Number.POSITIVE_INFINITY,c=[];for(let[f,u]of i){let p=[...u].sort((S,y)=>S.mipLevel-y.mipLevel),d=p[0];if(!d||d.mipLevel!==0)throw new Error(`DynamicTexture: slice ${f} is missing mip level 0`);let h=Ea(t,d);if(h.width!==n.width||h.height!==n.height)throw new Error(`DynamicTexture: slice ${f} base level dimensions ${h.width}x${h.height} do not match expected ${n.width}x${n.height}`);let g=Aa(d);if(g){if(s&&s!==g)throw new Error(`DynamicTexture: slice ${f} base level format "${g}" does not match texture format "${s}"`);s=g}let m=s&&t.isTextureFormatCompressed(s)?uh(t,h.width,h.height,s):t.getMipLevelCount(h.width,h.height),_=0;for(let S=0;S<p.length;S++){let y=p[S];if(!y||y.mipLevel!==S||S>=m)break;let v=Ea(t,y),x=Math.max(1,h.width>>S),M=Math.max(1,h.height>>S);if(v.width!==x||v.height!==M)break;let I=Aa(y);if(I&&(s||(s=I),I!==s))break;_++,c.push(y)}a=Math.min(a,_)}let l=Number.isFinite(a)?Math.max(1,a):1;return{subresources:c.filter(f=>f.mipLevel<l),mipLevels:l,format:s,hasExplicitMipChain:o}}function Aa(t){if(t.type===`texture-data`)return t.textureFormat??ii(t.data)}function Ea(t,e){switch(e.type){case`external-image`:return t.getExternalImageSize(e.image);case`texture-data`:return{width:e.data.width,height:e.data.height};default:throw new Error(`Unsupported texture subresource`)}}function uh(t,e,n,r){let{blockWidth:i=1,blockHeight:o=1}=t.getTextureFormatInfo(r),s=1;for(let a=1;;a++){let c=Math.max(1,e>>a),l=Math.max(1,n>>a);if(c<i||l<o)break;s++}return s}async function ui(t){if(t=await t,Array.isArray(t))return await Promise.all(t.map(ui));if(t&&typeof t==`object`&&t.constructor===Object){let e=t,n=await Promise.all(Object.values(e).map(ui)),r=Object.keys(e),i={};for(let o=0;o<r.length;o++)i[r[o]]=n[o];return i}return t}function pi(t,e){if(!t)throw new Error(e)}var ue=class{id;matrix=new U;display=!0;position=new Z;rotation=new Z;scale=new Z(1,1,1);userData={};props={};constructor(e={}){let{id:n}=e;this.id=n||G(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return pi(e.length===3,`setPosition requires vector argument`),this.position=e,this}setRotation(e){return pi(e.length===3||e.length===4,`setRotation requires vector argument`),this.rotation=e,this}setScale(e){return pi(e.length===3,`setScale requires vector argument`),this.scale=e,this}setMatrix(e,n=!0){n?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){let{position:n,rotation:r,scale:i,update:o=!0}=e;return n&&this.setPosition(n),r&&this.setRotation(r),i&&this.setScale(i),o&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),this.rotation.length===4){let e=new U().fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:n,scale:r}={}){return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(e,n){n=n||this.matrix;let r=new U(e).multiplyRight(n),i=r.invert(),o=i.transpose();return{viewMatrix:e,modelMatrix:n,objectMatrix:n,worldMatrix:r,worldInverseMatrix:i,worldInverseTransposeMatrix:o}}_setScenegraphNodeProps(e){e.display!==void 0&&(this.display=e.display),e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};function dn(){return[[Infinity,Infinity,Infinity],[-Infinity,-Infinity,-Infinity]]}function hn(t,e,n){let r=new U(n);for(let i=0;i<8;i++){let o=new Z(e[i&1?1:0][0],e[i&2?1:0][1],e[i&4?1:0][2]);r.transformAsPoint(o,o);for(let s=0;s<3;s++)t[0][s]=Math.min(t[0][s],o[s]),t[1][s]=Math.max(t[1][s],o[s])}}function mn(t){return Number.isFinite(t[0][0])}var di=class t extends ue{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;let{children:n=[]}=e;f.assert(n.every(r=>r instanceof ue),`every child must an instance of ScenegraphNode`),super(e),this.children=n}getBounds(){let e=dn();return this.traverse((n,{worldMatrix:r})=>{let i=n.getBounds();if(!i)return;let o=new U(r).multiplyRight(n.matrix);hn(e,i,o)}),mn(e)?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(let n of e)Array.isArray(n)?this.add(...n):this.children.push(n);return this}remove(e){let n=this.children,r=n.indexOf(e);return r>-1&&n.splice(r,1),this}removeAll(){return this.children=[],this}traverse(e,{worldMatrix:n=new U}={}){if(!this.display)return;let r=new U(n).multiplyRight(this.matrix);for(let i of this.children)i.display&&(i instanceof t?i.traverse(e,{worldMatrix:r}):e(i,{worldMatrix:r}))}traverseDepthSorted(e,{viewMatrix:n,worldMatrix:r=new U,order:i=`back-to-front`}){let o=new U(n),s=[];this.traverse((c,l)=>{let f=c.getBounds(),u=f?new Z(f[0]).add(f[1]).divide([2,2,2]):new Z,p=new U(l.worldMatrix).multiplyRight(c.matrix);p.transformAsPoint(u,u),o.transformAsPoint(u,u),s.push({node:c,context:{worldMatrix:p,bounds:f,depth:-u[2]},index:s.length})},{worldMatrix:new U(r)});let a=i===`back-to-front`?-1:1;s.sort((c,l)=>a*(c.context.depth-l.context.depth)||c.index-l.index);for(let{node:c,context:l}of s)e(c,l)}preorderTraversal(e,{worldMatrix:n=new U}={}){let r=new U(n).multiplyRight(this.matrix);e(this,{worldMatrix:r});for(let i of this.children)i instanceof t?i.preorderTraversal(e,{worldMatrix:r}):e(i,{worldMatrix:r})}};var hi=class extends ue{model;instanceMatrices;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.instanceMatrices=e.instanceMatrices||null,this.bounds=e.bounds?this.instanceMatrices?ph(e.bounds,this.instanceMatrices):e.bounds:null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};function ph(t,e){let n=dn();for(let r of e)hn(n,t,r);return mn(n)?n:null}var mi=class{poolSize=20;bufferPools;constructor(){this.bufferPools=new Map}createOrReuse(e,n){if(n>e.limits.maxBufferSize)throw new Error(`Buffer pool cannot allocate ${n} bytes: device.limits.maxBufferSize is ${e.limits.maxBufferSize}`);let r=this.bufferPools.get(e),i=r?r.findIndex(s=>s.byteLength>=n):-1;if(i<0)return e.createBuffer({usage:P.VERTEX|P.STORAGE|P.COPY_DST|P.COPY_SRC,byteLength:n});let[o]=r.splice(i,1);return o}recycle(e){let n=e.device;this.bufferPools.has(n)||this.bufferPools.set(n,[]);let r=this.bufferPools.get(n),i=r.findIndex(o=>o.byteLength>e.byteLength);i<0?r.push(e):r.splice(i,0,e),this.purge()}purge(){for(let[e,n]of this.bufferPools){let r=e.isLost?0:this.poolSize;for(;n.length>r;)n.shift().destroy();n.length===0&&this.bufferPools.delete(e)}}};var ze=new mi;var Ia=/^vertex-list<([^<>]+)>$/;var La=/^value-list<([^<>]+)>$/;function gn(t){return Ia.test(t)}function bn(t){return La.test(t)}function Ra(t){let e=Ia.exec(t),n=La.exec(t),r=e?.[1]??n?.[1]??t;try{R.getVertexFormatInfo(r)}catch{throw new Error(`Unsupported GPUVector format ${t}`)}return r}function ie(t){let e=Ra(t),n=gn(t),r$33=bn(t),i=R.getVertexFormatInfo(e),o=i.type,s=i.normalized,a=dh(o,s);return r({format:t,elementFormat:e,vertexList:n,valueList:r$33,type:o,signedDataType:hh(e,o),primitiveType:a,components:i.components,byteLength:i.byteLength,integer:i.integer,signed:i.signed,normalized:s},i.webglOnly?{webglOnly:!0}:{})}function dh(t,e){if(e)return`f32`;switch(t){case`float32`:return`f32`;case`float16`:return`f16`;case`uint8`:case`uint16`:case`uint32`:return`u32`;case`sint8`:case`sint16`:case`sint32`:return`i32`;default:throw new Error(`Unsupported GPUVector component type ${t}`)}}function hh(t,e){if(t===`unorm10-10-10-2`)return`uint32`;switch(e){case`unorm8`:return`uint8`;case`snorm8`:return`sint8`;case`unorm16`:return`uint16`;case`snorm16`:return`sint16`;default:return e}}var oe=class{buffer;format;length;byteOffset;byteStride;constructor(e){let n=R.getVertexFormatInfo(e.format).byteLength,r=e.byteOffset??0,i=e.byteStride??n;if(gi(e.length,`GPUDataView length`),gi(r,`GPUDataView byteOffset`),gi(i,`GPUDataView byteStride`),i<n)throw new Error(`GPUDataView byteStride ${i} is smaller than ${e.format} byte length ${n}`);let o=e.length===0?0:(e.length-1)*i+n,s=r+o;if(!Number.isSafeInteger(o)||!Number.isSafeInteger(s))throw new Error(`GPUDataView byte range must use safe integers`);if(s>e.buffer.byteLength)throw new Error(`GPUDataView exceeds its backing buffer byte length`);this.buffer=e.buffer,this.format=e.format,this.length=e.length,this.byteOffset=r,this.byteStride=i}get elementByteLength(){return R.getVertexFormatInfo(this.format).byteLength}get byteLength(){return this.length===0?0:(this.length-1)*this.byteStride+this.elementByteLength}};function gi(t,e){if(!Number.isSafeInteger(t)||t<0)throw new Error(`${e} must be a non-negative safe integer`)}function vn(t){return!!(t&&typeof t==`object`&&t.type===`struct`)}function Ca(t,e){let n=Object.entries(t);if(n.length===0)throw new Error(`GPUData struct format must declare at least one field`);return e===`packed`?mh(n):gh(n)}function mh(t){let e=[],n=0,r=0;for(let[i,o]of t){let s=R.getVertexFormatInfo(o);if(s.webglOnly)throw new Error(`Packed GPUData struct field "${i}" uses WebGL-only format ${o}`);n=wa(n,Math.min(4,s.byteLength)),e.push([i,Object.freeze({format:o,byteOffset:n,byteLength:s.byteLength})]),n+=s.byteLength,r+=s.components}return Object.freeze({type:`struct`,layout:`packed`,fields:Object.freeze(Object.fromEntries(e)),components:r,byteStride:wa(n,4),rowByteLength:n})}function gh(t){let n=ut$1(Object.fromEntries(t.map(([s,a])=>[s,bh(a)])),{layout:`wgsl-storage`}),r=[],i=0,o=0;for(let[s,a]of t){let c=R.getVertexFormatInfo(a),l=n.fields[s].offset*4;r.push([s,Object.freeze({format:a,byteOffset:l,byteLength:c.byteLength})]),i=Math.max(i,l+c.byteLength),o+=c.components}return Object.freeze({type:`struct`,layout:`wgsl-storage`,fields:Object.freeze(Object.fromEntries(r)),components:o,byteStride:n.byteLength,rowByteLength:i})}function bh(t){let e=R.getVertexFormatInfo(t);switch(e.type){case`float32`:return _n(`f32`,e.components);case`sint32`:return _n(`i32`,e.components);case`uint32`:return _n(`u32`,e.components);default:return _n(`u32`,Math.ceil(e.byteLength/4))}}function _n(t,e){return e===1?t:`vec${e}<${t}>`}function wa(t,e){return Math.ceil(t/e)*e}var bi=class{buffer;ownsDataBuffer;constructor(e,n){this.buffer=e,this.ownsDataBuffer=n}get ownsBuffer(){return this.ownsDataBuffer}transferBufferOwnership(e){if(e.buffer!==this.buffer)throw new Error(`GPUData ownership can only be transferred to the same buffer`);e.ownsDataBuffer=this.ownsDataBuffer,this.ownsDataBuffer=!1}destroy(){this.ownsDataBuffer&&(this.buffer.destroy(),this.ownsDataBuffer=!1)}};var _i=class extends bi{dataType;format;length;valueLength;stride;byteOffset;byteStride;rowByteLength;readbackMetadata;valueOffsets;nullBitmap;valueByteLength;constructor(e){let{buffer:n,format:r,length:i,valueLength:o,stride:s,byteOffset:a=0,byteStride:c,rowByteLength:l,ownsBuffer:f=!1,readbackMetadata:u,valueOffsets:p,nullBitmap:d,valueByteLength:h,dataType:g}=e;super(n,f);let m;r?typeof r==`string`?m=r:m=Ca(r,e.layout??`wgsl-storage`):m=void 0;let _=vn(m)?m:void 0,S=typeof m==`string`?ie(m):void 0;if(this.dataType=g,this.format=m,this.length=i,this.valueLength=o??i,this.stride=s??S?.components??_?.components??c??l??1,this.byteOffset=a,this.rowByteLength=l??_?.rowByteLength??S?.byteLength??c??this.stride,this.byteStride=c??_?.byteStride??this.rowByteLength,_){if(this.rowByteLength<_.rowByteLength)throw new Error(`GPUData rowByteLength ${this.rowByteLength} is smaller than struct format row byte length ${_.rowByteLength}`);if(this.byteStride<Math.max(_.byteStride,this.rowByteLength))throw new Error(`GPUData byteStride ${this.byteStride} is smaller than its struct row layout`)}this.readbackMetadata=u,this.valueOffsets=p,this.nullBitmap=d,this.valueByteLength=h}getChild(e){if(!vn(this.format))return null;let n=this.format.fields[e];return n?new oe({buffer:this.buffer,format:n.format,length:this.length,byteOffset:this.byteOffset+n.byteOffset,byteStride:this.byteStride}):null}getChildAt(e){if(!vn(this.format))return null;let n=Object.values(this.format.fields)[e];return n?new oe({buffer:this.buffer,format:n.format,length:this.length,byteOffset:this.byteOffset+n.byteOffset,byteStride:this.byteStride}):null}};var $e=_i;var Le=class{name;dataType;format;length;valueLength;stride;byteOffset;byteStride;rowByteLength;bufferLayout;data=[];device;bufferProps;isAppendable=!1;ownsDataChunks=!0;ownedVectors=[];appendableByteLength=0;constructor(e){switch(e.type){case`buffer`:{let{name:n,buffer:r,format:i,length:o,valueLength:s=o,byteOffset:a=0,ownsBuffer:c=!1}=e,{stride:l,byteStride:f,rowByteLength:u}=Ta(e);this.name=n,this.dataType=e.dataType,this.format=i,this.length=o,this.valueLength=s,this.stride=l,this.byteOffset=a,this.byteStride=f,this.rowByteLength=u,this.data.push(new $e({buffer:r,format:i,length:o,valueLength:s,stride:l,byteOffset:a,byteStride:f,rowByteLength:u,ownsBuffer:c,dataType:e.dataType}));return}case`interleaved`:{let{name:n,buffer:r,format:i,length:o,valueLength:s=o,byteOffset:a=0,byteStride:c,attributes:l,ownsBuffer:f=!1}=e;this.name=n,this.dataType=e.dataType,this.format=i,this.length=o,this.valueLength=s,this.stride=c,this.byteOffset=a,this.byteStride=c,this.rowByteLength=c,this.bufferLayout={name:n,byteStride:c,attributes:l},this.data.push(new $e({buffer:r,format:i,length:o,valueLength:s,stride:c,byteOffset:a,byteStride:c,rowByteLength:c,ownsBuffer:f,dataType:e.dataType}));return}case`data`:{let n=e.format??_h(e.data),r=n?ie(n):void 0,{name:i,data:o,stride:s=o[0]?.stride??r?.components??1,valueLength:a=o.reduce((p,d)=>p+d.valueLength,0),byteStride:c=o[0]?.byteStride??r?.byteLength,rowByteLength:l=o[0]?.rowByteLength??r?.byteLength,bufferLayout:f,ownsData:u=!1}=e;if(c===void 0||l===void 0)throw new Error(`GPUVector requires format or explicit byte layout metadata`);n&&vh(o,n),this.name=i,this.dataType=e.dataType,this.format=n,this.length=o.reduce((p,d)=>p+d.length,0),this.valueLength=a,this.stride=s,this.byteOffset=o.length===1?o[0].byteOffset:0,this.byteStride=c,this.rowByteLength=l,this.bufferLayout=f,this.ownsDataChunks=u,this.data.push(...o);return}case`appendable`:{let{name:n,device:r,format:i,valueLength:o=0,bufferProps:s}=e,{stride:a,byteStride:c,rowByteLength:l}=Ta(e);this.name=n,this.dataType=e.dataType,this.format=i,this.length=0,this.valueLength=o,this.stride=a,this.byteOffset=0,this.byteStride=c,this.rowByteLength=l,this.device=r,this.bufferProps=s,this.isAppendable=!0;return}}}get ownsBuffer(){return this.ownsDataChunks&&this.data.some(e=>e.ownsBuffer)||this.ownedVectors.some(e=>e.ownsBuffer)}get capacityRows(){return this.isAppendable?this.length:void 0}get appendedByteLength(){return this.appendableByteLength}addData(e){if(this.format&&e.format!==this.format)throw new Error(`GPUVector.addData() requires matching formats`);if(e.byteStride!==this.byteStride)throw new Error(`GPUVector.addData() requires matching byteStride`);if(e.rowByteLength!==this.rowByteLength)throw new Error(`GPUVector.addData() requires matching rowByteLength`);return this.data.push(e),this.length+=e.length,this.valueLength+=e.valueLength,this}appendDataChunk(e,n=this.appendableByteLength+e.buffer.byteLength){if(!this.isAppendable)throw new Error(`GPUVector.appendDataChunk() requires appendable vector storage`);if(this.format&&e.format!==this.format)throw new Error(`GPUVector.appendDataChunk() requires matching formats`);if(e.byteStride!==this.byteStride||e.rowByteLength!==this.rowByteLength)throw new Error(`GPUVector.appendDataChunk() requires matching byte layout metadata`);return this.data.push(e),this.length+=e.length,this.valueLength+=e.valueLength,this.appendableByteLength=n,this}resetLastBatch(){if(!this.isAppendable)throw new Error(`GPUVector.resetLastBatch() requires appendable vector storage`);for(let e of this.data.splice(0))e.destroy();return this.length=0,this.valueLength=0,this.appendableByteLength=0,this}retainOwnedVectors(e){return this.ownedVectors.push(...e),this}transferBufferOwnership(e){let n=this.data[0],r=e.data[0];if(!n||!r||n.buffer!==r.buffer)throw new Error(`GPUVector ownership can only be transferred to the same buffer`);n.transferBufferOwnership(r)}destroy(){if(this.ownsDataChunks)for(let e of this.data)e.destroy();for(let e of this.ownedVectors.splice(0))e.destroy()}};function Ta(t){let e=t.format?ie(t.format):void 0,n=t.rowByteLength??t.byteStride??e?.byteLength;if(n===void 0)throw new Error(`GPUVector requires format or explicit rowByteLength`);return{stride:t.stride??e?.components??1,byteStride:t.byteStride??n,rowByteLength:n}}function _h(t){return t[0]?.format}function vh(t,e){if(t.find(r=>r.format!==e))throw new Error(`GPUVector data chunks must share the declared format`)}var pe=class t{static get bufferPoolSize(){return ze.poolSize}static set bufferPoolSize(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`GPUDataEvaluator.bufferPoolSize must be a non-negative safe integer`);ze.poolSize=e,ze.purge()}type;size;get offset(){return this._offset}get stride(){return this._stride}normalized;isConstant;length;get byteLength(){return this._byteLength}ValueType;source=null;format;_id;_destroyed=!1;_value;_offset;_stride;_byteLength;_gpuVector;_bufferOwnership=`owned`;_targetBuffer;static fromArray(e,{type:n,size:r=1,offset:i=0,stride:o=0,normalized:s=!1}){let a=n,c;if(Array.isArray(e)){a=a||`float32`;c=new(Mt$1(a))(e)}else e instanceof Float64Array?(a=`uint32`,r*=2,i*=2,o*=2,c=new Uint32Array(e.buffer,e.byteOffset,e.byteLength/4)):(a=a||Ut$1(e),c=e);let l=`<${a} * ${r}>`;return new t({id:l,type:a,size:r,offset:i,stride:o,normalized:s,value:c})}static fromConstant(e,n=`float32`){let r=Mt$1(n),i;return Array.isArray(e)?i=`[${e.join(`,`)}]`:(i=String(e),e=[e]),new t({id:i,isConstant:!0,type:n,size:e.length,value:new r(e)})}static fromGPUData(e,n={}){Sh(e);let r$34=new oe({buffer:e.buffer,format:e.format,length:e.length,byteOffset:e.byteOffset,byteStride:e.byteStride});return new t(s(r({},Pa(r$34)),{id:n.id,gpuData:e}))}static fromGPUDataView(e,n={}){return new t(s(r({},Pa(e)),{id:n.id,buffer:e.buffer}))}constructor(e){let{id:n,value:r,buffer:i,gpuData:o,format:s,source:a=null,isConstant:c=!1}=e;if(!a&&!r&&!i&&!o)throw new Error(`GPUDataEvaluator must have a value source`);let{type:l,size:f,offset:u,stride:p,normalized:d,length:h}=e;if(a instanceof t?(l=l??a.type,f=f??a.size,u=u??a.offset,p=p??a.stride,d=d??a.normalized,h=h??a.length):(f=f??1,u=u??0,d=d??!1,h=c?1:h),!l)throw new Error(`GPUDataEvaluator: type not defined`);if(this._id=n,this.type=l,this.size=f,this.ValueType=Mt$1(this.type),this._offset=u,this._stride=p||this.ValueType.BYTES_PER_ELEMENT*f,this.normalized=d,this.source=a,this.format=s,h===void 0)if(c)h=1;else{if(!r)throw new Error(`GPUDataEvaluator: length not defined`);h=Math.ceil(r.byteLength/this.stride)}this.isConstant=c,this.length=h;let g=this.ValueType.BYTES_PER_ELEMENT*this.size;this._byteLength=h===0?0:(h-1)*this.stride+g,this._value=r,this._bufferOwnership=a instanceof t||i||o?`borrowed`:`owned`,o?this._gpuVector=new Le({type:`data`,name:this._id??`data`,format:o.format,data:[o],stride:o.stride,byteStride:o.byteStride,rowByteLength:o.rowByteLength}):i&&(this._gpuVector=this.createGPUVectorView({buffer:i,name:this._id,format:this.format}))}get value(){return this._value||(this.source instanceof t?this.source.value:void 0)}get evaluated(){return!!this._gpuVector}get id(){return this._id}get gpuVector(){if(!this._gpuVector)throw new Error(`${this} not evaluated`);return this._gpuVector}get buffer(){return xn(this.gpuVector)}setTargetBuffer({buffer:e,byteOffset:n=0,byteStride:r=this.stride}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)throw new Error(`GPUDataEvaluator ${this} already evaluated`);if(!this.source||this.source instanceof t)throw new Error(`GPUDataEvaluator target buffers require a deferred operation source`);this._targetBuffer={buffer:e,byteOffset:n,byteStride:r}}async evaluate(e,n={}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)return this._gpuVector;let r$35;if(this.source instanceof t){let i=await this.source.evaluate(e);return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:xn(i)})),this._gpuVector}if(r$35=this._getEvaluationBuffer(e),this._value)r$35.write(this._value);else{let i=await this.source.execute(e,r$35);if(!i.success)throw i.error||new Error(`${this.source} evaluation failed`);i.value&&(this._value=i.value)}return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:r$35})),this._gpuVector}evaluateSync(e,n={}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)return this._gpuVector;let r$36;if(this.source instanceof t){let i=this.source.evaluateSync(e);return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:xn(i)})),this._gpuVector}if(r$36=this._getEvaluationBuffer(e),this._value)r$36.write(this._value);else{let i=this.source.executeSync(e,r$36);if(!i.success)throw i.error||new Error(`${this.source} evaluation failed`);i.value&&(this._value=i.value)}return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:r$36})),this._gpuVector}createGPUVectorView(e){let n=e.name??this._id??`vector`,r=e.format??this.format??Ah(this.type,this.size,this.normalized);if(e.interleaved){let i=typeof e.interleaved==`object`&&e.interleaved.attributes?e.interleaved.attributes:Mh(this);return new Le({type:`interleaved`,name:n,buffer:e.buffer,format:e.format??this.format,length:this.length,byteOffset:this.offset,byteStride:this.stride,attributes:i,ownsBuffer:!1})}return new Le({type:`buffer`,name:n,buffer:e.buffer,format:r,length:this.length,stride:this.size,byteOffset:this.offset,byteStride:this.stride,rowByteLength:this.ValueType.BYTES_PER_ELEMENT*this.size,ownsBuffer:!1})}_getEvaluationBuffer(e){let n=this._targetBuffer;if(!n)return ze.createOrReuse(e,this.byteLength);if(n.buffer.device!==e)throw new Error(`GPUDataEvaluator target buffer belongs to a different device`);let r=this.ValueType.BYTES_PER_ELEMENT*this.size,i=this.length===0?0:(this.length-1)*n.byteStride+r;if(n.byteOffset+i>n.buffer.byteLength)throw new Error(`GPUDataEvaluator target buffer is too small for the output layout`);return this._offset=n.byteOffset,this._stride=n.byteStride,this._byteLength=i,this._bufferOwnership=`borrowed`,this._targetBuffer=void 0,n.buffer}async readValue(e=0,n){let{ValueType:r}=this,{size:i,offset:o,stride:s,length:a}=this,c=r.BYTES_PER_ELEMENT*i;if(n=n??a,e=Math.max(0,Math.min(a,e)),n=Math.max(e,Math.min(a,n)),this._value)return xh(this,this._value,e,n);let l=n-e;if(l===0)return new r(0);let f=o+e*s,u=s===c?l*c:(l-1)*s+c,p=await this.buffer.readAsync(f,u),d=new r(p.buffer,p.byteOffset,p.byteLength/r.BYTES_PER_ELEMENT);if(s===c)return d;let h=new Uint8Array(c*l);for(let g=0;g<l;g++){let m=g*s;h.set(p.subarray(m,m+c),g*c)}return new r(h.buffer)}async ensureCPUValue(){let e=this.value;if(e)return e;let n=await this.buffer.readAsync(0,this.offset+this.byteLength);if(n.byteLength%this.ValueType.BYTES_PER_ELEMENT!==0)throw new Error(`${this} backing buffer byte length is not aligned to its scalar type`);let r=n.slice();return this._value=new this.ValueType(r.buffer,r.byteOffset,r.byteLength/this.ValueType.BYTES_PER_ELEMENT),this._value}ensureCPUValueSync(){let e=this.value;if(e)return e;throw new Error(`${this} CPU value is not available for synchronous evaluation`)}toString(){return this._id??this.source?.toString()??this.constructor.name}destroy(){this._gpuVector&&(this._bufferOwnership===`owned`&&ze.recycle(xn(this._gpuVector)),this._gpuVector=void 0),this._targetBuffer=void 0,this._destroyed=!0}};function xh(t,e,n,r){let{ValueType:i,size:o,offset:s,stride:a}=t,c=a/i.BYTES_PER_ELEMENT,l=s/i.BYTES_PER_ELEMENT,f=r-n;if(c===o){let p=l+n*c;return e.subarray(p,p+f*o)}let u=new i(f*o);for(let p=0;p<f;p++){let d=l+(n+p)*c;u.set(e.subarray(d,d+o),p*o)}return u}function Ov(t){if(t instanceof pe)return t;if(typeof t==`number`||Array.isArray(t))return pe.fromConstant(t);if(t instanceof $e)return pe.fromGPUData(t);if(t instanceof oe)return pe.fromGPUDataView(t);throw new Error(`getGPUDataEvaluator() requires GPUDataEvaluator, GPUData, GPUDataView, number, or number[]`)}function Sh(t){if(!t.format)throw new Error(`GPUDataEvaluator.fromGPUData() requires GPUData format metadata`);if(gn(t.format)||bn(t.format))throw new Error(`GPUDataEvaluator.fromGPUData() does not support variable-length input`);let n=ie(t.format).byteLength;if(t.rowByteLength!==n)throw new Error(`GPUDataEvaluator.fromGPUData() requires rowByteLength ${n} for GPUData`)}function Pa(t){let e=ie(t.format),n=Mt$1(e.signedDataType),r=n.BYTES_PER_ELEMENT*e.components;if(e.byteLength!==r)throw new Error(`GPUDataEvaluator does not support packed vertex format ${t.format}: ${e.byteLength} physical bytes cannot expose ${e.components} ${e.signedDataType} components`);if(t.byteOffset%n.BYTES_PER_ELEMENT!==0||t.byteStride%n.BYTES_PER_ELEMENT!==0)throw new Error(`GPUDataEvaluator requires ${t.format} offset and stride aligned to ${n.BYTES_PER_ELEMENT} bytes`);return{type:e.signedDataType,size:e.components,offset:t.byteOffset,stride:t.byteStride,normalized:e.normalized,length:t.length,format:t.format}}function xn(t){let e=yh(t).buffer;return e instanceof k?e.buffer:e}function yh(t){let[e,...n]=t.data;if(!e||n.length>0)throw new Error(`GPUDataEvaluator requires exactly one GPUData chunk for "${t.name}"`);return e}function Mh(t){let e=[];return Na(t,e,{byteOffset:0}),e}function Na(t,e,n){let r=t.source;if(r&&!(r instanceof pe)&&r.name===`interleave`){for(let i of Object.values(r.inputs))i instanceof pe&&Na(i,e,n);return}e.push({attribute:t.id??t.toString(),format:Ba(t.type,t.size,t.normalized),byteOffset:n.byteOffset}),n.byteOffset+=t.ValueType.BYTES_PER_ELEMENT*t.size}function Ba(t,e,n=!1){if(e<1||e>4)throw new Error(`Cannot synthesize a GPUVector vertex format with ${e} components`);let r=t;if(n)switch(t){case`uint8`:r=`unorm8`;break;case`sint8`:r=`snorm8`;break;case`uint16`:r=`unorm16`;break;case`sint16`:r=`snorm16`;break;case`float32`:r=`float32`;break;default:throw new Error(`Unsupported normalized vertex format for ${t}`)}return(r===`uint8`||r===`sint8`||r===`uint16`||r===`sint16`||r===`unorm8`||r===`snorm8`||r===`unorm16`||r===`snorm16`)&&e===3?`${r}x3-webgl`:`${r}${e===1?``:`x${e}`}`}function Ah(t,e,n=!1){return e>=1&&e<=4?Ba(t,e,n):void 0}var Vv={add:{arity:2,symbol:`arithmetic_add`},subtract:{arity:2,symbol:`arithmetic_subtract`},multiply:{arity:2,symbol:`arithmetic_multiply`},divide:{arity:2,symbol:`arithmetic_divide`},pow:{arity:2,symbol:`pow`},sqrt:{arity:1,symbol:`sqrt`},abs:{arity:1,symbol:`abs`},sin:{arity:1,symbol:`sin`},cos:{arity:1,symbol:`cos`},tan:{arity:1,symbol:`arithmetic_tan`},exp:{arity:1,symbol:`exp`},log:{arity:1,symbol:`log`}};function Oa(t,{operations:e,inputs:n}){switch(t.kind){case`input`:if(!(t.name in n))throw new Error(`Unknown expression input '${t.name}'`);return;case`literal`:if(Array.isArray(t.value)){for(let r of t.value)if(!Number.isFinite(r))throw new Error(`Expression literal array must contain only finite values, got ${r}`)}else if(!Number.isFinite(t.value))throw new Error(`Expression literal must be finite, got ${t.value}`);return;case`call`:{let r=e[t.op];if(!r)throw new Error(`Unknown expression op '${t.op}'`);if(t.args.length!==r.arity)throw new Error(`Expression op '${t.op}' expects ${r.arity} args, got ${t.args.length}`);for(let i of t.args)Oa(i,{operations:e,inputs:n});return}default:throw new Error(`Unsupported expression node ${t.kind}`)}}function kv(t,e){return Oa(t,e),Ua(t,e)}function Ua(t,e){switch(t.kind){case`input`:{let n=e.inputs[t.name];return e.laneIndex<n.size?e.formatInput(t.name):e.formatOutOfBoundsInput(t.name)}case`literal`:return e.formatLiteral(t.value);case`call`:{let n=e.operations[t.op],r=t.args.map(i=>Ua(i,e));return e.formatCall(n.symbol,r)}default:throw new Error(`Unsupported expression node ${t.kind}`)}}export{rd as $,Zo as A,hi as B,Wp as C,Yr as D,Yd as E,ei as F,kt as G,ir as H,fe as I,ne as J,kv as K,fi as L,ar as M,di as N,Z as O,ed as P,qr as Q,ga as R,Vv as S,Xr as T,k as U,hr as V,ka as W,pe as X,on as Y,pt as Z,Pi as _,Hr as a,zi as at,Uf as b,Ki as c,Le as d,ti as et,Mt as f,Ov as g,Oe as h,Ho as i,ze as it,Zp as j,Zn as k,Ko as l,Nt as m,Ga as n,ue as nt,Jr as o,Ni as p,mt as q,Gp as r,za as rt,Kd as s,De as t,tt,Kr as u,Qr as v,Wr as w,V as x,U as y,ge as z};
6148
- //# debugId=1cc5c4fa-9f51-523c-9f69-02c2d20f1bc3
6147
+ `,vs:Js,fs:Js,getUniforms:t=>t,uniformTypes:{modelViewProjectionMatrix:`mat4x4<f32>`,modelMatrix:`mat4x4<f32>`,normalMatrix:`mat4x4<f32>`,camera:`vec3<f32>`}}],source:Ks,vs:Xs,fs:Zs,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,HAS_BUMPMAP:!1,HAS_DIFFUSETRANSMISSIONMAP:!1,HAS_DIFFUSETRANSMISSIONCOLORMAP:!1,HAS_MULTISCATTERCOLORMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:t=>t,uniformTypes:{unlit:`i32`,baseColorMapEnabled:`i32`,baseColorFactor:`vec4<f32>`,normalMapEnabled:`i32`,normalScale:`f32`,emissiveMapEnabled:`i32`,emissiveFactor:`vec3<f32>`,metallicRoughnessValues:`vec2<f32>`,metallicRoughnessMapEnabled:`i32`,occlusionMapEnabled:`i32`,occlusionStrength:`f32`,alphaCutoffEnabled:`i32`,alphaCutoff:`f32`,specularColorFactor:`vec3<f32>`,specularIntensityFactor:`f32`,specularColorMapEnabled:`i32`,specularIntensityMapEnabled:`i32`,ior:`f32`,transmissionFactor:`f32`,transmissionMapEnabled:`i32`,thicknessFactor:`f32`,attenuationDistance:`f32`,attenuationColor:`vec3<f32>`,clearcoatFactor:`f32`,clearcoatRoughnessFactor:`f32`,clearcoatMapEnabled:`i32`,clearcoatRoughnessMapEnabled:`i32`,sheenColorFactor:`vec3<f32>`,sheenRoughnessFactor:`f32`,sheenColorMapEnabled:`i32`,sheenRoughnessMapEnabled:`i32`,iridescenceFactor:`f32`,iridescenceIor:`f32`,iridescenceThicknessRange:`vec2<f32>`,iridescenceMapEnabled:`i32`,anisotropyStrength:`f32`,anisotropyRotation:`f32`,anisotropyDirection:`vec2<f32>`,anisotropyMapEnabled:`i32`,emissiveStrength:`f32`,dispersion:`f32`,IBLenabled:`i32`,scaleIBLAmbient:`vec2<f32>`,scaleDiffBaseMR:`vec4<f32>`,scaleFGDSpec:`vec4<f32>`,baseColorUVSet:`i32`,baseColorUVTransform:`mat3x3<f32>`,metallicRoughnessUVSet:`i32`,metallicRoughnessUVTransform:`mat3x3<f32>`,normalUVSet:`i32`,normalUVTransform:`mat3x3<f32>`,occlusionUVSet:`i32`,occlusionUVTransform:`mat3x3<f32>`,emissiveUVSet:`i32`,emissiveUVTransform:`mat3x3<f32>`,specularColorUVSet:`i32`,specularColorUVTransform:`mat3x3<f32>`,specularIntensityUVSet:`i32`,specularIntensityUVTransform:`mat3x3<f32>`,transmissionUVSet:`i32`,transmissionUVTransform:`mat3x3<f32>`,thicknessUVSet:`i32`,thicknessUVTransform:`mat3x3<f32>`,clearcoatUVSet:`i32`,clearcoatUVTransform:`mat3x3<f32>`,clearcoatRoughnessUVSet:`i32`,clearcoatRoughnessUVTransform:`mat3x3<f32>`,clearcoatNormalUVSet:`i32`,clearcoatNormalUVTransform:`mat3x3<f32>`,sheenColorUVSet:`i32`,sheenColorUVTransform:`mat3x3<f32>`,sheenRoughnessUVSet:`i32`,sheenRoughnessUVTransform:`mat3x3<f32>`,iridescenceUVSet:`i32`,iridescenceUVTransform:`mat3x3<f32>`,iridescenceThicknessUVSet:`i32`,iridescenceThicknessUVTransform:`mat3x3<f32>`,anisotropyUVSet:`i32`,anisotropyUVTransform:`mat3x3<f32>`,bumpFactor:`f32`,bumpMapEnabled:`i32`,diffuseTransmissionFactor:`f32`,diffuseTransmissionMapEnabled:`i32`,diffuseTransmissionColorFactor:`vec3<f32>`,diffuseTransmissionColorMapEnabled:`i32`,multiscatterColorFactor:`vec3<f32>`,multiscatterColorMapEnabled:`i32`,scatterAnisotropy:`f32`,bumpUVSet:`i32`,bumpUVTransform:`mat3x3<f32>`,diffuseTransmissionUVSet:`i32`,diffuseTransmissionUVTransform:`mat3x3<f32>`,diffuseTransmissionColorUVSet:`i32`,diffuseTransmissionColorUVTransform:`mat3x3<f32>`,multiscatterColorUVSet:`i32`,multiscatterColorUVTransform:`mat3x3<f32>`}};var kr={};function G(t=`id`){kr[t]=kr[t]||1;return`${t}-${kr[t]++}`}var re=class{id;topology;vertexCount;indices;attributes;bufferLayout;userData={};constructor(e){let{attributes:n={},indices:r=null,vertexCount:i=null}=e;this.id=e.id||G(`geometry`),this.topology=e.topology,r&&(this.indices=ArrayBuffer.isView(r)?{value:r,size:1}:r),this.attributes={};for(let[o,s]of Object.entries(n)){let a=ArrayBuffer.isView(s)?{value:s}:s;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(o)}: must be typed array or object with value as typed array`);if((o===`POSITION`||o===`positions`)&&!a.size&&(a.size=3),o===`indices`){if(this.indices)throw new Error(`Multiple indices detected`);this.indices=a}else{let c=Me(o),l=Object.keys(this.attributes).find(f=>Me(f)===c);l&&delete this.attributes[l],this.attributes[o]=a}}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=i||this._calculateVertexCount(this.attributes,this.indices),this.bufferLayout=e.bufferLayout||id(this.attributes)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?r({indices:this.indices},this.attributes):this.attributes}_print(e){return`Geometry ${this.id} attribute ${e}`}_setAttributes(e,n){return this}_calculateVertexCount(e,n){if(n)return n.value.length;let r=1/0;for(let i of Object.values(e)){if(!i)continue;let{value:o,size:s,constant:a}=i;!a&&o&&s!==void 0&&s>=1&&(r=Math.min(r,o.length/s))}return r}};function Me(t){switch(t){case`POSITION`:return`positions`;case`NORMAL`:return`normals`;case`TEXCOORD_0`:return`texCoords`;case`TEXCOORD_1`:return`texCoords1`;case`COLOR_0`:return`colors`;default:return t}}function id(t){let e=[];for(let[n,r]of Object.entries(t)){if(!r)continue;let{value:i,size:o,normalized:s}=r;if(o===void 0)throw new Error(`Attribute ${n} is missing a size`);e.push({name:Me(n),format:S.getVertexFormatFromAttribute(i,o,s)})}return e}function pt(t,e={}){let n=e.bufferName||`geometry`;if(od(t,n))return t;let r=e.minAttributeAlignment||4,i=sd(t,e.attributes),o=[],s=0,a=1/0;for(let[f,u]of i){if(!u)continue;if(u.constant)throw new Error(`Attribute ${f} is constant`);let{value:p,size:d,normalized:h}=u;if(!ArrayBuffer.isView(p))throw new Error(`Attribute ${f} is missing typed array data`);if(d===void 0)throw new Error(`Attribute ${f} is missing a size`);let g=S.getVertexFormatFromAttribute(p,d,h),m=S.getVertexFormatInfo(g);s=ea(s,r),o.push({sourceName:f,attributeName:Me(f),value:p,size:d,format:g,byteOffset:s,byteLength:m.byteLength}),s+=m.byteLength;let v=p.length/d;if(!Number.isInteger(v))throw new Error(`Attribute ${f} length is not divisible by size`);a=Math.min(a,v)}if(o.length===0||!Number.isFinite(a))throw new Error(`Geometry ${t.id} has no interleavable attributes`);let c=ea(s,r),l=new ArrayBuffer(a*c);for(let f of o)ad(l,a,c,f);return new re({id:t.id,topology:t.topology||`triangle-list`,vertexCount:t.vertexCount,indices:t.indices,attributes:{[n]:{value:new Uint8Array(l),size:c,byteStride:c}},bufferLayout:[{name:n,stepMode:`vertex`,byteStride:c,attributes:o.map(f=>({attribute:f.attributeName,format:f.format,byteOffset:f.byteOffset}))}]})}function od(t,e){if(t.bufferLayout.length!==1)return!1;let n=t.bufferLayout[0];return n.name===e&&!!n.attributes?.length&&!!t.attributes[e]}function sd(t,e){return e?e.map(n=>[n,t.attributes[n]]):Object.entries(t.attributes)}function ad(t,e,n,r){let i=r.value.constructor,o=i.BYTES_PER_ELEMENT;if(r.byteOffset%o!==0||n%o!==0)throw new Error(`Attribute ${r.sourceName} is not aligned to its component type`);let s=new i(t),a=r.value,c=r.byteOffset/o,l=n/o;for(let f=0;f<e;f++){let u=f*r.size,p=f*l+c;for(let d=0;d<r.size;d++)s[p+d]=a[u+d]}}function ea(t,e){return Math.ceil(t/e)*e}var sn=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(e){if(this.id=e.id||G(`geometry`),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&P.INDEX))throw new Error(`Index buffer must have INDEX usage`)}destroy(){this.indices?.destroy();for(let e of Object.values(this.attributes))e.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}};function ta(t,e){if(e instanceof sn)return e;let n=pt(e),r=cd(t,n),{attributes:i,bufferLayout:o}=ld(t,n);return new sn({topology:n.topology||`triangle-list`,bufferLayout:o,vertexCount:n.vertexCount,indices:r,attributes:i})}function cd(t,e){if(!e.indices)return;let n=e.indices.value;return t.createBuffer({usage:P.INDEX,data:n})}function ld(t,e){let n={};for(let[r,i]of Object.entries(e.attributes)){let o=e.bufferLayout.find(s=>s.name===r)?.name||Me(r);i&&(n[o]=t.createBuffer({data:i.value,id:`${r}-buffer`}))}return{attributes:n,bufferLayout:e.bufferLayout,vertexCount:e.vertexCount}}function na(t,e){let n={},r=`Values`;if(t.attributes.length===0&&!t.varyings?.length)return{"No attributes or varyings":{[r]:`N/A`}};for(let i of t.attributes)if(i){let o=`${i.location} ${i.name}: ${i.type}`;n[`in ${o}`]={[r]:i.stepMode||`vertex`}}for(let i of t.varyings||[]){let o=`${i.location} ${i.name}`;n[`out ${o}`]={[r]:JSON.stringify(i)}}return n}var ra=`__debugFramebufferState`;function oa(t,e,n){if(t.device.type!==`webgl`)return;let r=pd(t.device);if(!r.flushing){if(hd(t)){fd(t,n,r);return}e&&dd(e)&&e.handle!==null&&(r.queuedFramebuffers.includes(e)||r.queuedFramebuffers.push(e))}}function fd(t,e,n){if(n.queuedFramebuffers.length===0)return;let{gl:i}=t.device,o=i.getParameter(36010),s=i.getParameter(36006),[a,c]=t.device.getDefaultCanvasContext().getDrawingBufferSize(),l=ia(e.top,8),f=ia(e.left,8);n.flushing=!0;try{for(let u of n.queuedFramebuffers){let[p,d,h,g,m]=ud({framebuffer:u,targetWidth:a,targetHeight:c,topPx:l,leftPx:f,minimap:e.minimap});i.bindFramebuffer(36008,u.handle),i.bindFramebuffer(36009,null),i.blitFramebuffer(0,0,u.width,u.height,p,d,h,g,16384,9728),l+=m+8}}finally{i.bindFramebuffer(36008,o),i.bindFramebuffer(36009,s),n.flushing=!1}}function ud(t){let{framebuffer:e,targetWidth:n,targetHeight:r,topPx:i,leftPx:o,minimap:s}=t,a=s?Math.max(Math.floor(n/4),1):n,c=s?Math.max(Math.floor(r/4),1):r,l=Math.min(a/e.width,c/e.height),f=Math.max(Math.floor(e.width*l),1),u=Math.max(Math.floor(e.height*l),1),p=o,d=Math.max(r-i-u,0);return[p,d,p+f,d+u,u]}function pd(t){return t.userData[ra]||={flushing:!1,queuedFramebuffers:[]},t.userData[ra]}function dd(t){return`colorAttachments`in t}function hd(t){let e=t.props.framebuffer;return!e||e.handle===null}function ia(t,e){if(!t)return e;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:e}function Ue(t,e,n){if(t===e)return!0;if(!n||!t||!e)return!1;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!Ue(t[r],e[r],n-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof t==`object`&&typeof e==`object`){let r=Object.keys(t),i=Object.keys(e);if(r.length!==i.length)return!1;for(let o of r)if(!e.hasOwnProperty(o)||!Ue(t[o],e[o],n-1))return!1;return!0}return!1}var Fe=class{bufferLayouts;constructor(e){this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(n=>n.name===e)||null}getAttributeNamesForBuffer(e){return vi$1(e)}mergeBufferLayouts(e,n){let r=[...e];for(let i of n){let o=r.findIndex(s=>s.name===i.name);o<0?r.push(i):r[o]=i}return r}};function sa(t,e){let n=Ci(t),r=e.slice();return r.sort((i,o)=>{return Bi$1(vi$1(i).map(c=>n[c]))-Bi$1(vi$1(o).map(c=>n[c]))}),r}function Ve(t,e){if(!t||!e.some(r=>r.bindingLayout?.length))return t;let n=s(r({},t),{bindings:t.bindings.map(r$14=>r({},r$14))});`attributes`in(t||{})&&(n.attributes=t?.attributes||[]);for(let r of e)for(let i of r.bindingLayout||[])for(let o of md(i.name)){let s=n.bindings.find(a=>a.name===o);s?.group===0&&(s.group=i.group),s&&i.visibility!==void 0&&(s.visibility=i.visibility)}return n}function aa(t,e,n=[]){return t?e?s(r({},t),{attributes:t.attributes.length?_d(t.attributes,e.attributes.filter(r=>n.includes(r.name))):e.attributes,bindings:bd(t.bindings,e.bindings)}):t:e}function Ae(t){return!!(t.uniformTypes&&!gd(t.uniformTypes))}function ca(t){let e=[];for(let n of t){let r=lt(n),i=new Set([n.vs,n.fs].flatMap(s=>s?ft(s).filter(a=>a.isStd140).map(a=>a.blockName):[])),o=i.has(r)?r:i.size===1?i.values().next().value:void 0;Ae(n)&&o&&e.push({name:o,uniformTypes:n.uniformTypes})}return e}function an(t,e){let n=[],r=new Set;for(let i of[...t||[],...e||[]])r.has(i.name)||(r.add(i.name),n.push(i));return n}function md(t){let e=new Set([t,`${t}Uniforms`]);return t.endsWith(`Uniforms`)||e.add(`${t}Sampler`),[...e]}function gd(t){for(let e in t)return!1;return!0}function bd(t,e){let n=t.map(o=>r({},o)),r$15=new Set(t.map(o=>o.name)),i=new Set(t.map(o=>`${o.group}:${o.location}`));for(let o of e){let s=`${o.group}:${o.location}`;!r$15.has(o.name)&&!i.has(s)&&n.push(r({},o))}return n}function _d(t,e){let n=t.map(o=>r({},o)),r$16=new Map(t.map(o=>[o.name,o])),i=new Map(t.map(o=>[o.location,o]));for(let o of e){let s=r$16.get(o.name);if(s){if(s.type!==o.type||s.location!==o.location)throw new Error(`Shader attribute "${o.name}" conflicts with its inferred type or location`);continue}let a=i.get(o.location);if(a)throw new Error(`Shader attributes "${a.name}" and "${o.name}" both use location ${o.location}`);n.push(r({},o))}return n}function la(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function fa(t){return Array.isArray(t)?t.length===0||typeof t[0]==`number`:!1}function dt(t){return la(t)||fa(t)}function vd(t){return dt(t)||typeof t==`number`||typeof t==`boolean`}function ua(t,e={}){let n={bindings:{},uniforms:{}};return Object.keys(t).forEach(r=>{let i=t[r];Object.prototype.hasOwnProperty.call(e,r)||vd(i)?n.uniforms[r]=i:n.bindings[r]=i}),n}var Q=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;directBindings={};constructor(e,n){Object.assign(this.options,n);let r=_e(Object.values(e).filter(xd));for(let i of r)e[i.name]=i;f.log(1,`Creating ShaderInputs with modules`,Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(let[i,o]of Object.entries(e))o&&(this._addModule(o),o.name&&i!==o.name&&!this.options.disableWarnings&&f.warn(`Module name: ${i} vs ${o.name}`)())}destroy(){}setProps(e){e.bindings&&Object.assign(this.directBindings,e.bindings);for(let n of Object.keys(e)){if(n===`bindings`)continue;let r$17=n,i=e[r$17]||{},o=this.modules[r$17];if(!o)this.options.disableWarnings||f.warn(`Module ${n} not found`)();else{let s=this.moduleUniforms[r$17],a=this.moduleBindings[r$17],{uniforms:l,bindings:f}=ua(o.getUniforms?.(i,s)||i,o.uniformTypes);this.moduleUniforms[r$17]=pa(s,l,o.uniformTypes),this.moduleBindings[r$17]=r(r({},a),f)}}}getModules(){return Object.values(this.modules)}addModules(e){let n=_e(e);for(let r of n){let i=r.name;this.modules[i]||(this.modules[i]=r,this._addModule(r))}}getUniformValues(){return this.moduleUniforms}getBindingValues(){let e={};for(let n of Object.values(this.moduleBindings))Object.assign(e,n);return Object.assign(e,this.directBindings),e}getModuleBindingValues(e){let n=this.moduleBindings[e];return n?r({},n):{}}getDebugTable(){let e={};for(let[n,r]of Object.entries(this.moduleUniforms))for(let[i,o]of Object.entries(r))e[`${n}.${i}`]={type:this.modules[n].uniformTypes?.[i],value:String(o)};return e}_addModule(e){let n=e.name;this.moduleUniforms[n]=pa({},e.defaultUniforms||{},e.uniformTypes),this.moduleBindings[n]={}}};function pa(t={},e={},n={}){let r$18=r({},t);for(let[i,o]of Object.entries(e))o!==void 0&&(r$18[i]=Gr(t[i],o,n[i]));return r$18}function Gr(t,e,n){if(!n||typeof n==`string`)return ht(e);if(Array.isArray(n)){if(zr(e)||!Array.isArray(e))return ht(e);let s=Array.isArray(t)&&!zr(t)?[...t]:[],a=s.slice();for(let c=0;c<e.length;c++){let l=e[c];l!==void 0&&(a[c]=Gr(s[c],l,n[0]))}return a}if(!$r(e))return ht(e);let r$19=n,i=$r(t)?t:{},o=r({},i);for(let[s,a]of Object.entries(e))a!==void 0&&(o[s]=Gr(i[s],a,r$19[s]));return o}function ht(t){return ArrayBuffer.isView(t)?Array.prototype.slice.call(t):Array.isArray(t)?zr(t)?t.slice():t.map(n=>n===void 0?void 0:ht(n)):$r(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n===void 0?void 0:ht(n)])):t}function zr(t){return ArrayBuffer.isView(t)||Array.isArray(t)&&(t.length===0||typeof t[0]==`number`)}function $r(t){return!!t&&typeof t==`object`&&!Array.isArray(t)&&!ArrayBuffer.isView(t)}function xd(t){return!!t?.dependencies}var Sd=P.DEBUG_DATA_MAX_LENGTH;var k=class{device;id;ready;usage;props;isReady=!0;destroyed=!1;generation=0;updateTimestamp;debugData=new ArrayBuffer(0);_debugDataEnabled;_maxDebugDataByteLength;_ownsBuffer;_buffer;get buffer(){return this._buffer}get byteLength(){return this._buffer.byteLength}get[Symbol.toStringTag](){return`DynamicBuffer`}toString(){return`DynamicBuffer:"${this.id}":${this.byteLength}B`}toJSON(){return this.toString()}constructor(e,n){let l=n,{debugData:r$20=!1,buffer:i,ownsBuffer:o=!0}=l,s$6=u(l,[`debugData`,`buffer`,`ownsBuffer`]);if(i&&i.device!==e)throw new Error(`DynamicBuffer adopted buffers must belong to the supplied device`);if(i&&(s$6.byteLength!==void 0||s$6.data!==void 0))throw new Error(`DynamicBuffer cannot combine an adopted buffer with byteLength or data`);let a=n.id||i?.id||G(`dynamic-buffer`),c=s(r({},s$6),{id:a,usage:s$6.usage??i?.usage,indexType:s$6.indexType??i?.indexType});(c.usage||0)&P.INDEX&&!c.indexType&&(s$6.data instanceof Uint32Array?c.indexType=`uint32`:s$6.data instanceof Uint16Array?c.indexType=`uint16`:s$6.data instanceof Uint8Array&&(c.indexType=`uint8`)),delete c.data,delete c.byteOffset,this.device=e,this.id=a,this.props=c,this.usage=c.usage||0,this._debugDataEnabled=!!r$20,this._maxDebugDataByteLength=typeof r$20==`object`&&r$20.maxByteLength!==void 0?r$20.maxByteLength:Sd,this._ownsBuffer=o,this._buffer=i??this.device.createBuffer(s(r({},s$6),{id:a})),this.ready=Promise.resolve(this._buffer),this.updateTimestamp=this._buffer.updateTimestamp,this._resetDebugData(this._buffer.byteLength),s$6.data&&this._writeDebugData(s$6.data,s$6.byteOffset||0)}write(e,n=0){this._buffer.write(e,n),this._touch(),this._writeDebugData(e,n)}async mapAndWriteAsync(e,n=0,r=this.byteLength-n){let i=null;await this._buffer.mapAndWriteAsync(async(o,s)=>{await e(o,s),i=new Uint8Array(o.slice(0,r))},n,r),this._touch(),i&&this._writeDebugData(i,n)}async readAsync(e=0,n=this.byteLength-e){let r=await this._buffer.readAsync(e,n);return this._writeDebugData(r,e)&&this._touch(),r}async mapAndReadAsync(e,n=0,r=this.byteLength-n){let i=null,o=await this._buffer.mapAndReadAsync(async(s,a)=>(i=new Uint8Array(s.slice(0)),await e(s,a)),n,r);return i&&this._writeDebugData(i,n)&&this._touch(),o}resize(e){let{byteLength:n,preserveData:r$21=!1}=e;if(n===this.byteLength)return!1;let i=Math.min(e.copyByteLength??Math.min(this.byteLength,n),this.byteLength,n),o=this._buffer,s$7=this.debugData.slice(0),u$1=this.props,{data:a,byteOffset:c}=u$1,l=u(u$1,[`data`,`byteOffset`]),f=this.device.createBuffer(s(r({},l),{byteLength:n}));return r$21&&i>0&&this._copyBufferContents(o,f,i),this._buffer=f,this._resetDebugData(n),r$21&&s$7.byteLength>0&&this._writeDebugData(s$7,0),this._ownsBuffer&&o.destroy(),this._ownsBuffer=!0,this.generation++,this._touch(),!0}ensureSize(e,n){return e<=this.byteLength?!1:this.resize({byteLength:e,preserveData:n?.preserveData})}getBinding(e){return e?.offset===void 0&&e?.size===void 0?this._buffer:{buffer:this._buffer,offset:e?.offset,size:e?.size}}destroy(){this.destroyed||(this._ownsBuffer&&this._buffer.destroy(),this.destroyed=!0,this.debugData=new ArrayBuffer(0))}_copyBufferContents(e,n,r){let i=this.device.type===`webgpu`?Math.ceil(r/4)*4:r,o=this.device.createCommandEncoder();o.copyBufferToBuffer({sourceBuffer:e,destinationBuffer:n,size:i}),this.device.submit(o.finish())}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_resetDebugData(e){if(!this._debugDataEnabled){this.debugData=new ArrayBuffer(0);return}this.debugData=new ArrayBuffer(Math.min(e,this._maxDebugDataByteLength))}_writeDebugData(e,n){if(!this._debugDataEnabled||this.debugData.byteLength===0||n>=this.debugData.byteLength)return!1;let r=ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),i=new Uint8Array(this.debugData),o=Math.min(r.byteLength,i.byteLength-n);return i.set(r.subarray(0,o),n),o>0}};function Ee(t){return t!==null&&typeof t==`object`&&`buffer`in t}function da(t){return t instanceof k?t:Ee(t)&&t.buffer instanceof k?t.buffer:null}function yd(t){return t instanceof k?t.buffer:t}function cn(t){return{buffer:yd(t.buffer),offset:t.offset,size:t.size}}function ie(t){return t!==null&&typeof t==`object`&&`resolveTextureBinding`in t&&typeof t.resolveTextureBinding==`function`}function Md(t){return t?.type===`texture`||t?.type===`external-texture`}function ln(t,e,n){let r=Qt$1(t,e,{ignoreWarnings:!0});return Md(r)?r:t.bindings.length===0&&n?.fallbackGroup!==void 0?{type:`texture`,name:e,group:n.fallbackGroup,location:0}:null}var ee=2;var Ad=1e4;var Hr=`render pipeline initialization failed`;var Ed=[`stencil8`,`depth16unorm`,`depth24plus`,`depth24plus-stencil8`,`depth32float`,`depth32float-stencil8`];var De=class t{static defaultProps=s(r({},U$1.defaultProps),{source:void 0,vs:null,fs:null,id:`unnamed`,handle:void 0,userData:{},defines:{},modules:[],plugins:[],geometry:null,indexBuffer:null,indexCount:void 0,firstVertex:0,firstIndex:0,attributes:{},constantAttributes:{},bindings:{},uniforms:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,material:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:J.getDefaultShaderAssembler(`glsl`),debugShaders:void 0,disableWarnings:void 0});device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexCount;firstVertex;firstIndex;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;material=null;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_dynamicIndexBufferSource=null;_dynamicAttributeBufferSources={};_colorAttachmentFormats;_depthStencilAttachmentFormat;_pipelineNeedsUpdate=`newly created`;_needsRedraw=`initializing`;_drawBlockedReason=!1;_destroyed=!1;_vertexCountSet=!1;_lastDrawTimestamp=-1;_bindingTable=[];get[Symbol.toStringTag](){return`Model`}toString(){return`Model(${this.id})`}constructor(e,n){let r$22=t.defaultProps.shaderAssembler,i=n.vertexCount!==void 0;this.props=s(r(r({},t.defaultProps),n),{shaderAssembler:n.shaderAssembler??(Wr(r$22,e.info.shadingLanguage)?r$22:J.getDefaultShaderAssembler(e.info.shadingLanguage))}),this._vertexCountSet=i,n=this.props,this.id=n.id||G(`model`),this.device=e,Object.assign(this.userData,n.userData),this.material=n.material||null;let o=Cd(e),s$8=at(this.props.plugins,o.shaderLanguage),a=ct(this.props.modules,s$8.modules),c=Object.fromEntries(a.map(d=>[d.name,d])),l=n.shaderInputs||new Q(c,{disableWarnings:this.props.disableWarnings});n.shaderInputs&&s$8.modules.length>0&&l.addModules(s$8.modules),this.setShaderInputs(l);let f=an(this.props.modules,l.getModules()),u=r(r({},s$8.defines),this.props.defines);if(this.device.type===`webgl`&&(this.props._uniformBlockLayouts=ca(f)),this.props.shaderLayout=Ve(this.props.shaderLayout,f)||null,this.device.type===`webgpu`&&this.props.source){let d=this.props.shaderAssembler;He(Wr(d,`wgsl`));let{source:h,getUniforms:g,bindingTable:m,shaderLayout:v}=d.assembleWGSLShader(s(r({platformInfo:o},this.props),{modules:f,defines:u,pluginInjections:s$8.injections,pluginVertexInputs:s$8.vertexInputs,pluginVaryings:s$8.varyings}));this.source=h,this._getModuleUniforms=g,this._bindingTable=m;let y=Id(v??e.getShaderLayout?.(this.source),s$8.vertexInputs),_=aa(this.props.shaderLayout,y,Object.keys(s$8.vertexInputs));this.props.shaderLayout=Ve(_||null,f)||null}else{let d=this.props.shaderAssembler;He(Wr(d,`glsl`));let{vs:h,fs:g,getUniforms:m}=d.assembleGLSLShaderPair(s(r({platformInfo:o},this.props),{modules:f,defines:u,pluginInjections:s$8.injections,pluginVertexInputs:s$8.vertexInputs,pluginVaryings:s$8.varyings}));this.vs=h,this.fs=g,this._getModuleUniforms=m,this._bindingTable=[]}this.vertexCount=this.props.vertexCount,this.indexCount=this.props.indexCount,this.firstVertex=this.props.firstVertex,this.firstIndex=this.props.firstIndex,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,this._colorAttachmentFormats=this.props.colorAttachmentFormats,this._depthStencilAttachmentFormat=this.props.depthStencilAttachmentFormat,n.geometry&&this.setGeometry(n.geometry),this.pipelineFactory=n.pipelineFactory||Ke$1.getDefaultPipelineFactory(this.device),this.shaderFactory=n.shaderFactory||Ze$1.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),`isInstanced`in n&&(this.isInstanced=n.isInstanced),n.instanceCount&&this.setInstanceCount(n.instanceCount),n.vertexCount&&this.setVertexCount(n.vertexCount),n.indexBuffer&&this.setIndexBuffer(n.indexBuffer),n.attributes&&this.setAttributes(n.attributes),n.constantAttributes&&this.setConstantAttributes(n.constantAttributes),n.bindings&&this.setBindings(n.bindings),n.transformFeedback&&(this.transformFeedback=n.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.pipeline.fs!==this.pipeline.vs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw(`contents of bound textures or buffers updated`);let e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||=e}getBindingDebugTable(){return this._bindingTable}predraw(e){this._syncDynamicBuffers(),this.updateShaderInputs(e),this.material?.updateShaderInputs(e),this.pipeline=this._updatePipeline()}draw(e){if(this._drawBlockedReason&&!this._pipelineNeedsUpdate)return f.info(ee,`>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)(),!1;let n=this._areBindingsLoading();if(n)return f.info(ee,`>>> DRAWING ABORTED ${this.id}: ${n} not loaded`)(),!1;this._syncAttachmentFormats(e);try{e.pushDebugGroup(`${this}.predraw(${e})`),this.device.type===`webgpu`?(this.updateShaderInputs(),this.material?.updateShaderInputs(),this._syncDynamicBuffers(),this.pipeline=this._updatePipeline()):this.predraw(this.device.commandEncoder)}finally{e.popDebugGroup()}let r,i=this.pipeline.isErrored;try{if(e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline(),i=this.pipeline.isErrored,i)f.info(ee,`>>> DRAWING ABORTED ${this.id}: ${Hr}`)(),r=!1;else{let o=this.vertexArray.getDrawValidationError();if(o)f.info(ee,`>>> DRAWING ABORTED ${this.id}: ${o}`)(),this._drawBlockedReason=o,r=!1;else{let s=this._getCurrentShaderLayout(),a=this._getBindings(s),c=this._getBindGroups(s,a),{indexBuffer:l}=this.vertexArray,f=l?this.indexCount??(this._vertexCountSet?this.vertexCount:l.byteLength/(l.indexType===`uint32`?4:2)):void 0;e.setPipeline(this.pipeline),e.setBindings(c,{_bindGroupCacheKeys:this._getBindGroupCacheKeys()}),e.setVertexArray(this.vertexArray),r=this.isInstanced===!0&&this.instanceCount===0?!0:e.draw({isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.isInstanced?this.instanceCount:void 0,indexCount:f,firstVertex:this.firstVertex,firstIndex:this.firstIndex,transformFeedback:this.transformFeedback||void 0,uniforms:this.props.uniforms,parameters:this.parameters,topology:this.topology})}}}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),r?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):i?(this._needsRedraw=Hr,this._drawBlockedReason=Hr):this._drawBlockedReason?this._needsRedraw=this._drawBlockedReason:this._needsRedraw=`waiting for resource initialization`,r}setGeometry(e){this._gpuGeometry?.destroy();let n=e&&ta(this.device,e);if(n){this.setTopology(n.topology||`triangle-list`);let r=new Fe(this.bufferLayout);this.bufferLayout=r.mergeBufferLayouts(n.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(n)}this._gpuGeometry=n}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate(`topology`))}setBufferLayout(e){let n=new Fe(this.bufferLayout),r=this._gpuGeometry?n.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e;Ue(r,this.bufferLayout,-1)||(this.bufferLayout=r,this._setPipelineNeedsUpdate(`bufferLayout`),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry))}setParameters(e){Ue(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate(`parameters`))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw(`instanceCount`)}setVertexCount(e){this.vertexCount=e,this._vertexCountSet=!0,this.setNeedsRedraw(`vertexCount`)}setIndexCount(e){this.indexCount=e,this.setNeedsRedraw(`indexCount`)}setDrawOffsets({firstVertex:e,firstIndex:n}){this.firstVertex=e,this.firstIndex=n,this.setNeedsRedraw(`drawOffsets`)}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new dt$1(this.device,this.shaderInputs.modules);for(let[n,r]of Object.entries(this.shaderInputs.modules))if(Ae(r)&&!this.material?.ownsModule(n)){let i=this._uniformStore.getManagedUniformBuffer(n);this.bindings[`${n}Uniforms`]=i}this.setNeedsRedraw(`shaderInputs`)}setMaterial(e){this.material=e,this.setNeedsRedraw(`material`)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues())),this.setNeedsRedraw(`shaderInputs`)}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw(`bindings`)}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw(`transformFeedback`)}setIndexBuffer(e){let n=e instanceof k?e.buffer:e;this.indexBuffer=n,this._dynamicIndexBufferSource=e instanceof k?{source:e,generation:e.generation}:null,this.vertexArray.setIndexBuffer(n),this.setNeedsRedraw(`indexBuffer`)}setAttributes(e,n){this._drawBlockedReason=!1;let r=n?.disableWarnings??this.props.disableWarnings;e.indices&&f.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=sa(this.pipeline.shaderLayout,this.bufferLayout);let i=new Fe(this.bufferLayout);for(let[o,s]of Object.entries(e)){let a=s instanceof k?s.buffer:s,c=i.getBufferLayout(o);if(!c){r||f.warn(`Model(${this.id}): Missing layout for buffer "${o}".`)();continue}let l=i.getAttributeNamesForBuffer(c),f$1=!1;for(let u of l){let p=this._attributeInfos[u];if(p){let d=this.device.type===`webgpu`?this.vertexArray.getBufferSlot(p.bufferName):p.location;if(d===null){r||f.warn(`Model(${this.id}): Missing vertex array slot for buffer "${p.bufferName}".`)();continue}this.vertexArray.setBuffer(d,a),s instanceof k?this._dynamicAttributeBufferSources[d]={source:s,generation:s.generation}:delete this._dynamicAttributeBufferSources[d],f$1=!0}}!f$1&&!r&&f.warn(`Model(${this.id}): Ignoring buffer "${a.id}" for unknown attribute "${o}"`)()}this.setNeedsRedraw(`attributes`)}setConstantAttributes(e,n){for(let[r,i]of Object.entries(e)){let o=this._attributeInfos[r];o?this.vertexArray.setConstantWebGL(o.location,i):(n?.disableWarnings??this.props.disableWarnings)||f.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${r}"`)()}this.setNeedsRedraw(`constants`)}_areBindingsLoading(){for(let e of Object.values(this.bindings))if(ie(e)&&!e.isReady)return e.id;for(let e of Object.values(this.material?.bindings||{}))if(ie(e)&&!e.isReady)return e.id;return!1}_getBindings(e=this._getCurrentShaderLayout()){let n={};for(let[r,i]of Object.entries(this.bindings)){let o=Ld(r,i,e);o&&(n[r]=o)}return n}_getBindGroups(e=this._getCurrentShaderLayout(),n=this._getBindings(e)){let r$23=e.bindings.length?ci$1(e,n):{0:n};if(!this.material)return r$23;for(let[i,o]of Object.entries(this.material.getBindingsByGroup(e))){let s=Number(i);r$23[s]=r(r({},r$23[s]||{}),o)}return r$23}_getBindGroupCacheKeys(){let e=this.material?.getBindGroupCacheKey(3);return e?{3:e}:{}}_getBindingsUpdateTimestamp(){let e=0;this._dynamicIndexBufferSource&&(e=Math.max(e,this._dynamicIndexBufferSource.source.updateTimestamp));for(let n of Object.values(this._dynamicAttributeBufferSources))e=Math.max(e,n.source.updateTimestamp);for(let n of Object.values(this.bindings))n instanceof Qe$1?e=Math.max(e,n.texture.updateTimestamp):n instanceof P||n instanceof C||n instanceof Ye||n instanceof k?e=Math.max(e,n.updateTimestamp):ie(n)?e=n.isReady?Math.max(e,n.updateTimestamp):1/0:Ee(n)&&(e=Math.max(e,(n.buffer instanceof k,n.buffer.updateTimestamp)));return Math.max(e,this.material?.getBindingsUpdateTimestamp()||0)}_setGeometryAttributes(e){let n=r({},e.attributes);for(let[r]of Object.entries(n))!this.pipeline.shaderLayout.attributes.find(i=>i.name===r)&&r!==`positions`&&delete n[r];this.vertexCount=e.vertexCount,this._vertexCountSet=!0,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(n,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw(`geometry attributes`)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||=e,this._drawBlockedReason=!1,this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,n=null;this.pipeline&&(f.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,n=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let r$24=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:`vertex`,source:this.source||this.vs,debugShaders:this.props.debugShaders}),i=null;this.source?i=r$24:this.fs&&(i=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:`fragment`,source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline(s(r({},this.props),{bindings:void 0,bufferLayout:this.bufferLayout,colorAttachmentFormats:this._colorAttachmentFormats,depthStencilAttachmentFormat:this._depthStencilAttachmentFormat,topology:this.topology,parameters:this.parameters,bindGroups:void 0,vs:r$24,fs:i})),this._attributeInfos=Di$1(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),n&&n!==e&&this.shaderFactory.release(n)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=f.level>3?0:Ad;f.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,f.group(ee,`>>> DRAWING MODEL ${this.id}`,{collapsed:f.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=na(this.pipeline.shaderLayout,this.id);f.table(ee,e)();let n=this.shaderInputs.getDebugTable();f.table(ee,n)();let r=this._getAttributeDebugTable();f.table(ee,this._attributeInfos)(),f.table(ee,r)(),f.groupEnd(ee)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(e){let n=this.device.props.debugFramebuffers;if(this._drawCount++,!n)return;let r=e.props.framebuffer;oa(e,r,{id:r?.id||`${this.id}-framebuffer`,minimap:!0})}_getAttributeDebugTable(){let e={};for(let[n,r]of Object.entries(this._attributeInfos)){let i=this.vertexArray.attributes[r.location];e[r.location]={name:n,type:r.shaderType,values:i?this._getBufferOrConstantValues(i,r.bufferDataType):`null`}}if(this.vertexArray.indexBuffer){let{indexBuffer:n}=this.vertexArray,r=n.indexType===`uint32`?new Uint32Array(n.debugData):new Uint16Array(n.debugData);e.indices={name:`indices`,type:n.indexType,values:r.toString()}}return e}_getBufferOrConstantValues(e,n){let r=$.getTypedArrayConstructor(n);return(e instanceof P?new r(e.debugData):e).toString()}_getNonMaterialBindings(e){if(!this.material)return e;let n={};for(let[r,i]of Object.entries(e))this.material.ownsBinding(r)||(n[r]=i);return n}_getCurrentShaderLayout(){return this.pipeline?.shaderLayout||this.props.shaderLayout||{bindings:[]}}_syncDynamicBuffers(){if(this._dynamicIndexBufferSource&&this._dynamicIndexBufferSource.generation!==this._dynamicIndexBufferSource.source.generation){let e=this._dynamicIndexBufferSource.source.buffer;this.indexBuffer=e,this.vertexArray.setIndexBuffer(e),this._dynamicIndexBufferSource.generation=this._dynamicIndexBufferSource.source.generation,this.setNeedsRedraw(`dynamic index buffer`)}for(let[e,n]of Object.entries(this._dynamicAttributeBufferSources))n.generation!==n.source.generation&&(this.vertexArray.setBuffer(Number(e),n.source.buffer),n.generation=n.source.generation,this.setNeedsRedraw(`dynamic attribute buffer`))}_syncAttachmentFormats(e){if(this.device.type!==`webgpu`)return;let n=e.framebuffer||e.props.framebuffer,r=e.props,i=r.colorAttachmentFormats??n?.colorAttachments?.map(s=>Rd(s?.texture?.format)),o=r.depthStencilAttachmentFormat===!1?void 0:r.depthStencilAttachmentFormat??wd(n?.depthStencilAttachment?.texture?.format);(!Ue(this._colorAttachmentFormats,i,1)||this._depthStencilAttachmentFormat!==o)&&(this._colorAttachmentFormats=i,this._depthStencilAttachmentFormat=o,this._setPipelineNeedsUpdate(`attachment formats`))}};function Wr(t,e){return t.shaderLanguage!==void 0&&t.shaderLanguage!==e?!1:e===`glsl`?`assembleGLSLShaderPair`in t&&typeof t.assembleGLSLShaderPair==`function`:`assembleWGSLShader`in t&&typeof t.assembleWGSLShader==`function`}function Id(t,e){return!t||Object.keys(e).length===0?t:s(r({},t),{attributes:t.attributes.map(n=>{let r$25=n.name.startsWith(`_luma_`)?n.name.slice(6):null;return r$25&&e[r$25]?s(r({},n),{name:r$25}):n})})}function Ld(t,e,n){if(ie(e)){let r=ln(n,t,{fallbackGroup:0});return r?e.resolveTextureBinding(r):null}return e instanceof k?e.buffer:Ee(e)?cn(e):e}function Rd(t){return t&&!ha(t)?t:null}function wd(t){return t&&ha(t)?t:void 0}function ha(t){return Ed.includes(t)}function Cd(t){return{type:t.type,shaderLanguage:t.info.shadingLanguage,shaderLanguageVersion:t.info.shadingLanguageVersion,gpu:t.info.gpu,limits:t.limits,features:t.features}}var Td=35980;var Pd=35981;var jr=class t{device;model;transformFeedback;static defaultProps=s(r({},De.defaultProps),{feedbackBufferMode:`separate`,outputs:void 0,feedbackBuffers:void 0});static isSupported(e){return e?.info?.type===`webgl`}constructor(e,n=t.defaultProps){if(!t.isSupported(e))throw new Error(`BufferTransform not yet implemented on WebGPU`);this.device=e,this.model=new De(this.device,s(r({id:n.id||`buffer-transform-model`,fs:n.fs||Fr(),topology:n.topology||`point-list`,varyings:n.outputs||n.varyings},n),{bufferMode:n.bufferMode||(n.feedbackBufferMode===`interleaved`?Td:Pd)})),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:n.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(e){e?.inputBuffers&&this.model.setAttributes(e.inputBuffers),e?.outputBuffers&&this.transformFeedback.setBuffers(e.outputBuffers);let n=this.device.beginRenderPass(r({discard:!0},e));this.model.draw(n),n.end()}getBuffer(e){return this.transformFeedback.getBuffer(e)}readAsync(e){let n=this.getBuffer(e);if(!n)throw new Error(`BufferTransform#getBuffer`);if(n instanceof P)return n.readAsync();let{buffer:r,byteOffset:i=0,byteLength:o=r.byteLength}=n;return r.readAsync(i,o)}};var qr=class extends re{constructor(e={}){let{id:n=G(`cube-geometry`),indices:r$26=!0}=e;super(r$26?s(r({},e),{id:n,topology:`triangle-list`,indices:{size:1,value:Nd},attributes:r(r({},zd),e.attributes)}):s(r({},e),{id:n,topology:`triangle-list`,indices:void 0,attributes:r(r({},$d),e.attributes)}))}};var Nd=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]);var Bd=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]);var Od=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]);var Ud=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]);var Fd=new Uint32Array([0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5]);var Vd=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]);var Dd=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]);var kd=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]);var Gd=new Uint32Array([3,3,3,3,3,3,4,4,4,4,4,4,2,2,2,2,2,2,5,5,5,5,5,5,0,0,0,0,0,0,1,1,1,1,1,1]);var zd={POSITION:{size:3,value:Bd},NORMAL:{size:3,value:Od},TEXCOORD_0:{size:2,value:Ud},faceIndex:{size:1,value:Fd}};var $d={POSITION:{size:3,value:Vd},TEXCOORD_0:{size:2,value:Dd},COLOR_0:{size:3,value:kd},faceIndex:{size:1,value:Gd}};var Yr=2;var Hd=1e4;var Xr=class t{static defaultProps=s(r({},F$1.defaultProps),{id:`unnamed`,handle:void 0,userData:{},source:``,modules:[],defines:{},plugins:[],bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:J.getDefaultShaderAssembler(`wgsl`),debugShaders:void 0});device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate=`newly created`;_getModuleUniforms;props;_destroyed=!1;constructor(e,n){if(e.type!==`webgpu`)throw new Error(`Computation is only supported in WebGPU`);this.props=r(r({},t.defaultProps),n),n=this.props,this.id=n.id||G(`model`),this.device=e,Object.assign(this.userData,n.userData);let r$27=Wd(e),i=at(this.props.plugins,r$27.shaderLanguage);if(Object.keys(i.vertexInputs).length>0||Object.keys(i.varyings).length>0)throw new Error(`Computation does not support ShaderPlugin vertex inputs or varyings`);let o=ct(this.props.modules,i.modules),s$9=Object.fromEntries(o.map(h=>[h.name,h]));this.shaderInputs=n.shaderInputs||new Q(s$9),n.shaderInputs&&i.modules.length>0&&this.shaderInputs.addModules(i.modules),this.setShaderInputs(this.shaderInputs);let a=an(this.props.modules,this.shaderInputs?.getModules()),c=r(r({},i.defines),this.props.defines);this.props.shaderLayout=Ve(this.props.shaderLayout,a)||null,this.pipelineFactory=n.pipelineFactory||Ke$1.getDefaultPipelineFactory(this.device),this.shaderFactory=n.shaderFactory||Ze$1.getDefaultShaderFactory(this.device);let l=this.props.shaderAssembler;He(l instanceof Oe);let{source:f,getUniforms:u,shaderLayout:p}=l.assembleWGSLShader(s(r({platformInfo:r$27},this.props),{modules:a,defines:c,scanVertexAttributes:!1,pluginInjections:i.injections}));this.source=f,this._getModuleUniforms=u;let d=p??e.getShaderLayout?.(this.source,{scanVertexAttributes:!1});this.props.shaderLayout=Ve(this.props.shaderLayout||d||null,a)||null,this.pipeline=this._updatePipeline(),n.bindings&&this.setBindings(n.bindings)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(e){this.updateShaderInputs(e)}dispatch(e,n,r,i){try{this._logDrawCallStart(),this._setPipeline(e),e.dispatch(n,r,i)}finally{this._logDrawCallEnd()}}dispatchIndirect(e,n,r=0){try{this._logDrawCallStart(),this._setPipeline(e),e.dispatchIndirect(n,r)}finally{this._logDrawCallEnd()}}_setPipeline(e){this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),e.setPipeline(this.pipeline),e.setBindings({})}setVertexCount(e){}setInstanceCount(e){}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new dt$1(this.device,this.shaderInputs.modules);for(let[n,r]of Object.entries(this.shaderInputs.modules))if(Ae(r)){let i=this._uniformStore.getManagedUniformBuffer(n);this.bindings[`${n}Uniforms`]=i}}setShaderModuleProps(e){let n=this._getModuleUniforms(e),r=Object.keys(n).filter(o=>{let s=n[o];return!dt(s)&&typeof s!=`number`&&typeof s!=`boolean`}),i={};for(let o of r)i[o]=n[o],delete n[o]}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e)}setBindings(e){Object.assign(this.bindings,e)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||e}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null;this.pipeline&&(f.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:`compute`,source:this.source,debugShaders:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline(s(r({},this.props),{shader:this.shader})),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=f.level>3?0:Hd;f.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,f.group(Yr,`>>> DRAWING MODEL ${this.id}`,{collapsed:f.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=this.shaderInputs.getDebugTable();f.table(Yr,e)(),f.groupEnd(Yr)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(e,n){let r=$.getTypedArrayConstructor(n);return(e instanceof P?new r(e.debugData):e).toString()}};function Wd(t){return{type:t.type,shaderLanguage:t.info.shadingLanguage,shaderLanguageVersion:t.info.shadingLanguageVersion,gpu:t.info.gpu,limits:t.limits,features:t.features}}var Zr=class{name;playing=!0;speed=1;startTime=0;constructor(e={}){this.name=e.name||`unnamed`,Object.assign(this,e)}setTime(e){if(!this.playing)return;let r=(e/1e3-this.startTime)*this.speed;this.applyTime(r)}};var Kr=class{clips;animations;constructor(e){this.clips=e,this.animations=e}animate(e){f.warn(`${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`)(),this.setTime(e)}setTime(e){this.clips.forEach(n=>n.setTime(e))}getAnimations(){return this.clips}};function ma(t,e,n=`vector`){let{input:r,output:i,interpolation:o=`LINEAR`}=e;if(!r.length||!i.length||!Number.isFinite(t))return null;let s=r.length-1;if(t<=r[0]||s===0)return Jr(i,o,0,n);if(t>=r[s])return Jr(i,o,s,n);let a=0,c=s;for(;c-a>1;){let d=Math.floor((a+c)/2);r[d]<=t?a=d:c=d}let l=r[a],u=r[c]-l;if(u<=0||o===`STEP`)return Jr(i,o,a,n);let p=(t-l)/u;switch(o){case`LINEAR`:{let d=i[a],h=i[c];return!d||!h?null:n===`quaternion`?fn(d,h,p):jd(d,h,p)}case`CUBICSPLINE`:{let d=i[a*3+1],h=i[a*3+2],g=i[c*3],m=i[c*3+1];if(!d||!h||!g||!m)return null;let v=qd(d,h,g,m,u,p);return n===`quaternion`?ke(v):v}default:return null}}function fn(t,e,n){let r=ke(t),i=ke(e),o=r.reduce((u,p,d)=>u+p*i[d],0),s=o<0?-1:1;if(o=Math.min(Math.abs(o),1),o>.9995)return ke(r.map((u,p)=>u+n*(i[p]*s-u)));let a=Math.acos(o),c=Math.sin(a),l=Math.sin((1-n)*a)/c,f=Math.sin(n*a)/c*s;return ke(r.map((u,p)=>u*l+i[p]*f))}function Jr(t,e,n,r){let i=t[e===`CUBICSPLINE`?n*3+1:n];return i?r===`quaternion`?ke(i):[...i]:null}function jd(t,e,n){return t.map((r,i)=>(1-n)*r+n*e[i])}function qd(t,e,n,r,i,o){let s=o*o,a=s*o;return t.map((c,l)=>(2*a-3*s+1)*c+(a-2*s+o)*e[l]*i+(-2*a+3*s)*r[l]+(a-s)*n[l]*i)}function ke(t){let e=Math.hypot(...t);return e>0?t.map(n=>n/e):[0,0,0,1]}var Qr=class{name;times;values;interpolation;valueType;binding;constructor(e){this.name=e.name||e.binding.id||`unnamed`,this.times=e.times,this.values=e.values,this.interpolation=e.interpolation||`LINEAR`,this.valueType=e.valueType||`vector`,this.binding=e.binding}get duration(){return this.times[this.times.length-1]||0}get sampler(){return{input:this.times,output:this.values,interpolation:this.interpolation}}evaluate(e){return ma(e,this.sampler,this.valueType)}};var ei=class{name;tracks;duration;constructor(e){this.name=e.name||`unnamed`,this.tracks=e.tracks,this.duration=e.duration??Math.max(0,...e.tracks.map(n=>n.duration))}};var un=class{clip;mixer;time=0;timeScale;weight;loop;repetitions;paused=!1;playing=!1;elapsedTime=0;fade=null;constructor(e,n,r={}){this.mixer=e,this.clip=n,this.loop=r.loop||`repeat`,this.repetitions=r.repetitions??Number.POSITIVE_INFINITY,this.timeScale=r.timeScale??1,this.weight=r.weight??1}play(){return this.playing=!0,this.paused=!1,this}pause(){return this.paused=!0,this}resume(){return this.playing=!0,this.paused=!1,this}stop(){return this.playing=!1,this.paused=!1,this.fade=null,this.reset()}reset(){return this.elapsedTime=0,this.time=0,this}setTime(e){return this.elapsedTime=e,this.time=this.resolveLocalTime(e),this}setLoop(e,n=Number.POSITIVE_INFINITY){return this.loop=e,this.repetitions=n,this.time=this.resolveLocalTime(this.elapsedTime),this}setEffectiveWeight(e){return this.weight=Math.max(0,e),this.fade=null,this}setEffectiveTimeScale(e){return this.timeScale=e,this}fadeIn(e){return this.scheduleFade(1,e)}fadeOut(e){return this.scheduleFade(0,e)}crossFadeTo(e,n){return e.weight=0,e.play().fadeIn(n),this.fadeOut(n)}crossFadeFrom(e,n){return e.crossFadeTo(this,n),this}advance(e){!this.playing||this.paused||(this.advanceFade(Math.abs(e)),this.elapsedTime+=e*this.timeScale,this.time=this.resolveLocalTime(this.elapsedTime),this.hasFinished()&&(this.playing=!1))}get shouldApply(){return(this.playing||this.hasFinished())&&this.weight>0}scheduleFade(e,n){return n<=0?(this.weight=e,this.fade=null,this):(this.fade={duration:n,elapsedTime:0,startWeight:this.weight,endWeight:e},this)}advanceFade(e){if(!this.fade)return;this.fade.elapsedTime+=e;let n=Math.min(this.fade.elapsedTime/this.fade.duration,1);this.weight=this.fade.startWeight+(this.fade.endWeight-this.fade.startWeight)*n,n===1&&(this.fade=null)}hasFinished(){let e=this.clip.duration;return e<=0?this.loop===`once`:this.loop===`once`?this.elapsedTime>=e||this.elapsedTime<0:Number.isFinite(this.repetitions)&&Math.abs(this.elapsedTime)>=e*this.repetitions}resolveLocalTime(e){let n=this.clip.duration;if(n<=0)return 0;if(this.loop===`once`)return Math.min(Math.max(e,0),n);if(Number.isFinite(this.repetitions)&&Math.abs(e)>=n*this.repetitions)return this.loop===`ping-pong`&&this.repetitions%2===0||e<0?0:n;let r=e>=0&&e<n?e:(e%n+n)%n;if(this.loop===`repeat`)return r;let i=Math.floor(e/n);return Math.abs(i%2)===0?r:n-r}};var ti=class{time=0;timeScale=1;clips=new Map;actions=new Map;initialValues=new Map;constructor(e=[]){e.forEach(n=>this.addClip(n))}addClip(e){return this.clips.set(e.name,e),this}clipAction(e,n){let r=typeof e==`string`?this.clips.get(e):e;if(!r)throw new Error(`Unknown animation clip: ${e}`);this.addClip(r);let i=this.actions.get(r);return i||(i=new un(this,r,n),this.actions.set(r,i)),i}getAction(e){let n=this.clips.get(e);return n?this.actions.get(n):void 0}update(e){return this.advance(e),this.applyValues(),this}advance(e){let n=e*this.timeScale;return this.time+=n,this.actions.forEach(r=>r.advance(n)),this}setTime(e){return this.time=e,this.actions.forEach(n=>{n.paused||n.setTime(e*n.timeScale)}),this.applyValues(),this}stopAllAction(){return this.actions.forEach(e=>e.stop()),this}applyValues(){let e=new Map;this.actions.forEach(n=>{!n.shouldApply&&!(n.playing&&n.weight===0)||n.clip.tracks.forEach(r=>{let i=r.evaluate(n.time);if(!i)return;let o=r.binding.id||r.binding;if(!this.initialValues.has(o)){let l=r.binding.getValue?.();l&&this.initialValues.set(o,[...l])}if(n.weight===0&&!this.initialValues.has(o))return;let s=e.get(o);if(!s){e.set(o,{binding:r.binding,value:[...i],valueType:r.valueType,weight:n.weight});return}if(n.weight===0)return;let a=s.weight+n.weight,c=n.weight/a;s.value=r.valueType===`quaternion`?fn(s.value,i,c):s.value.map((l,f)=>l+(i[f]-l)*c),s.weight=a})}),e.forEach(({binding:n,value:r,valueType:i,weight:o},s)=>{let a=o<1?this.initialValues.get(s):void 0;a&&a.length===r.length&&(r=i===`quaternion`?fn(a,r,o):r.map((c,l)=>a[l]+(c-a[l])*o)),n.setValue(r)})}};function ga(t){let e=t.value;if(e instanceof Float32Array)return e;let n=new Float32Array(e.length),r=_a(e),i=e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array;for(let o=0;o<e.length;o++){let s=Number(e[o]);n[o]=t.normalized&&r?i?Math.max(s/r,-1):s/r:s}return n}function ba(t,e,n){let r={};for(let i of[`POSITION`,`NORMAL`,`TANGENT`]){let o=t[i];if(!o)continue;let s=new Float32Array(o),a=i===`TANGENT`?4:3,c=Math.floor(o.length/a);for(let l=0;l<Math.min(e.length,n.length);l++){let f=n[l],u=e[l][i];if(!f||!u)continue;let p=i===`TANGENT`&&u.length===c*4?4:3;for(let d=0;d<c;d++){let h=d*a,g=d*p;for(let m=0;m<3;m++)s[h+m]+=(u[g+m]||0)*f}}i!==`POSITION`&&Zd(s,a),r[i]=s}return r}function Yd(t,e,n,r$28){let i={};for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=e.attributes[u];p&&(i[u]=ga(p))}let o=ba(i,n,r$28),s$10={};for(let[u,p]of Object.entries(e.attributes))p&&(s$10[u]=p);for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=o[u],d=s$10[u];p&&d&&(s$10[u]=s(r({},d),{value:Xd(d,p)}))}let l=pt(new re({id:e.id,topology:e.topology||`triangle-list`,vertexCount:e.vertexCount,indices:e.indices,attributes:s$10,bufferLayout:e.bufferLayout})).attributes.geometry?.value,f=t._gpuGeometry?.attributes.geometry||t.bufferAttributes.geometry;if(l&&f){f.write(l);return}for(let u of[`POSITION`,`NORMAL`,`TANGENT`]){let p=o[u];if(p){let d=u===`POSITION`?`positions`:u===`NORMAL`?`normals`:`TANGENT`;t.bufferAttributes[d]?.write(p)}}}function Xd(t,e){if(t.value instanceof Float32Array)return e;let n=t.value.slice(),r=_a(n),i=n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array;for(let o=0;o<e.length;o++){let s=e[o];n[o]=t.normalized&&r?Math.round(Math.max(i?-1:0,Math.min(1,s))*r):s}return n}function _a(t){return t instanceof Int8Array?127:t instanceof Uint8Array||t instanceof Uint8ClampedArray?255:t instanceof Int16Array?32767:t instanceof Uint16Array?65535:t instanceof Int32Array?2147483647:t instanceof Uint32Array?4294967295:0}function Zd(t,e){for(let n=0;n<t.length;n+=e){let r=Math.hypot(t[n],t[n+1],t[n+2]);r>0&&(t[n]/=r,t[n+1]/=r,t[n+2]/=r)}}function Kd(t){let{joints:e,meshNode:n,worldMatrices:r,inverseBindMatrices:i,target:o}=t,s=e.length,a=o&&o.length===s*16?o:new Float32Array(s*16),c=n?r.get(n)||n.matrix:void 0,l=c?new U(c).invert():null;for(let f=0;f<s;f++){let u=e[f],p=r.get(u)||u.matrix,d=l?new U(l).multiplyRight(p):new U(p),h=f*16;if(i&&i.length>=h+16){let g=new U;for(let m=0;m<16;m++)g[m]=i[h+m];d.multiplyRight(g)}a.set(d,h)}return a}var Jd=1;var Qd=1;var ni=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(e){let{delay:n=0,duration:r=Number.POSITIVE_INFINITY,rate:i=1,repeat:o=1}=e,s=Jd++,a={time:0,delay:n,duration:r,rate:i,repeat:o};return this._setChannelTime(a,this.time),this.channels.set(s,a),s}removeChannel(e){this.channels.delete(e);for(let[n,r]of this.animations)r.channel===e&&this.detachAnimation(n)}isFinished(e){let n=this.channels.get(e);return n===void 0?!1:this.time>=n.delay+n.duration*n.repeat}getTime(e){if(e===void 0)return this.time;let n=this.channels.get(e);return n===void 0?-1:n.time}setTime(e){this.time=Math.max(0,e);let n=this.channels.values();for(let i of n)this._setChannelTime(i,this.time);let r=this.animations.values();for(let i of r){let{animation:o,channel:s}=i;o.setTime(this.getTime(s))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(e,n){let r=Qd++;return this.animations.set(r,{animation:e,channel:n}),e.setTime(this.getTime(n)),r}detachAnimation(e){this.animations.delete(e)}update(e){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=e),this.setTime(this.time+(e-this.lastEngineTime)),this.lastEngineTime=e)}_setChannelTime(e,n){let r=n-e.delay;r>=e.duration*e.repeat?e.time=e.duration*e.rate:(e.time=Math.max(0,r)%e.duration,e.time*=e.rate)}};function va(t){let e=typeof window<`u`?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:null;return e?e.call(window,t):setTimeout(()=>t(typeof performance<`u`?performance.now():Date.now()),1e3/60)}function xa(t){let e=typeof window<`u`?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(e){e.call(window,t);return}clearTimeout(t)}var eh=0;var th=`Animation Loop`;var Sa={requestAnimationFrame:t=>va(t),cancelAnimationFrame:t=>xa(t)};var ri=class t{static defaultAnimationLoopProps={device:null,onAddHTML:()=>``,onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:e=>{console.error(e)},stats:void 0,autoResizeViewport:!1,animationFrameProvider:Sa};device=null;canvas=null;props;animationProps=null;timeline=null;stats;sharedStats;cpuTime;gpuTime;frameRate;display;_needsRedraw=`initialized`;_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;_lastFrameTime=0;constructor(e){if(this.props=r(r({},t.defaultAnimationLoopProps),e),e=this.props,!e.device)throw new Error(`No device provided`);this.stats=e.stats||new N$1({id:`animation-loop-${eh++}`}),this.sharedStats=Yr$1.stats.get(th),this.frameRate=this.stats.get(`Frame Rate`),this.frameRate.setSampleSize(1),this.cpuTime=this.stats.get(`CPU Time`),this.gpuTime=this.stats.get(`GPU Time`),this.setProps({autoResizeViewport:e.autoResizeViewport,animationFrameProvider:e.animationFrameProvider}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null),this.device?._disableDebugGPUTime()}delete(){this.destroy()}reportError(e){this._error=e,this.props.onError(e),this.props.onError===t.defaultAnimationLoopProps.onError&&typeof window<`u`&&typeof ErrorEvent<`u`&&window.dispatchEvent(new ErrorEvent(`error`,{error:e,message:e.message}))}setNeedsRedraw(e){return this._needsRedraw=this._needsRedraw||e,this}needsRedraw(){let e=this._needsRedraw;return this._needsRedraw=!1,e}setProps(e){if(`autoResizeViewport`in e&&(this.props.autoResizeViewport=e.autoResizeViewport||!1),`animationFrameProvider`in e){let n=e.animationFrameProvider||Sa;if(n!==this.props.animationFrameProvider){let r=this._animationFrameId!==null;r&&this._cancelAnimationFrame(),this.props.animationFrameProvider=n,r&&this._requestAnimationFrame()}}return this}async start(){if(this._running)return this;this._running=!0;try{if(!this._initialized){if(this._initialized=!0,await this._initDevice(),this._initialize(),!this._running)return null;await this.props.onInitialize(this._getAnimationProps())}return this._running?(this._cancelAnimationFrame(),this._requestAnimationFrame(),this):null}catch(e){let n=e instanceof Error?e:new Error(`Unknown error`);throw this.props.onError(n),n}}stop(){if(this._running){let e=this.animationProps;this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1,this._lastFrameTime=0,e&&this.props.onFinalize(e)}return this}redraw(e,n=null){return this.device?.isLost||this._error?this:(this._beginFrameTimers(e),this._setupFrame(),this.animationProps&&(this.animationProps.animationFrame=n),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(e){return this.timeline=e,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw(`waitForRender`),this._nextFramePromise||(this._nextFramePromise=new Promise(e=>{this._resolveNextFrame=e})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw(`toDataURL`),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error(`OffscreenCanvas`)}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeViewport(),this.device?._enableDebugGPUTime()}_setDisplay(e){this.display&&(this.display.destroy(),this.display.animationLoop=null),e&&(e.animationLoop=this),this.display=e}_requestAnimationFrame(){this._running&&(this._animationFrameId=this.props.animationFrameProvider.requestAnimationFrame(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(this.props.animationFrameProvider.cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_animationFrame(e,n){if(this._running)try{this.redraw(e,n??null),this._requestAnimationFrame()}catch(r){let i=r instanceof Error?r:new Error(String(r));this.reportError(i),this.stop()}}_renderFrame(e){if(this.display){this.display._renderFrame(e);return}let n=this.props.onRender(this._getAnimationProps());this.device&&n!==!1&&this.device.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let e=this.device?.getDefaultCanvasContext();if(!this.device||!e)throw new Error(`loop`);let n=e?.canvas,r=e.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:e,canvas:n,useDevicePixels:r,timeline:this.timeline,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,animationFrame:null,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error(`animationProps`);return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:e,height:n,aspect:r}=this._getSizeAndAspect();(e!==this.animationProps.width||n!==this.animationProps.height)&&this.setNeedsRedraw(`drawing buffer resized`),r!==this.animationProps.aspect&&this.setNeedsRedraw(`drawing buffer aspect changed`),this.animationProps.width=e,this.animationProps.height=n,this.animationProps.aspect=r,this.animationProps.needsRedraw=this._needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error(`No device provided`);this.canvas=this.device.getDefaultCanvasContext().canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let e=document.createElement(`div`);document.body.appendChild(e),e.style.position=`relative`;let n=document.createElement(`div`);n.style.position=`absolute`,n.style.left=`10px`,n.style.bottom=`10px`,n.style.width=`300px`,n.style.background=`white`,this.canvas instanceof HTMLCanvasElement&&e.appendChild(this.canvas),e.appendChild(n);let r=this.props.onAddHTML(n);r&&(n.innerHTML=r)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[e,n]=this.device.getDefaultCanvasContext().getDrawingBufferSize();return{width:e,height:n,aspect:e>0&&n>0?e/n:1}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(e){let n=e??(typeof performance<`u`?performance.now():Date.now());if(this._lastFrameTime){let r=n-this._lastFrameTime;r>0&&this.frameRate.addTime(r)}this._lastFrameTime=n,this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeStart()}_endFrameTimers(){this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeEnd(),this._updateSharedStats()}_consumeEncodedGpuTime(){if(!this.device)return;let e=this.device.commandEncoder._gpuTimeMs;e!==void 0&&(this.gpuTime.addTime(e),this.device.commandEncoder._gpuTimeMs=void 0)}_updateSharedStats(){if(this.stats!==this.sharedStats){for(let e of Object.keys(this.sharedStats.stats))this.stats.stats[e]||delete this.sharedStats.stats[e];this.stats.forEach(e=>{let n=this.sharedStats.get(e.name,e.type);n.sampleSize=e.sampleSize,n.time=e.time,n.count=e.count,n.samples=e.samples,n.lastTiming=e.lastTiming,n.lastSampleTime=e.lastSampleTime,n.lastSampleCount=e.lastSampleCount,n._count=e._count,n._time=e._time,n._samples=e._samples,n._startTime=e._startTime,n._timerPending=e._timerPending})}}_startEventHandling(){this.canvas&&(this.canvas.addEventListener(`mousemove`,this._onMousemove.bind(this)),this.canvas.addEventListener(`mouseleave`,this._onMouseleave.bind(this)))}_onMousemove(e){e instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[e.offsetX,e.offsetY])}_onMouseleave(e){this._getAnimationProps()._mousePosition=null}};var Ge=3;var mt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(e,n={}){this.device=e,this.modules=n.modules||[];let r=new Q(Object.fromEntries(this.modules.map(i=>[i.name,i])));this._materialBindingNames=nh(r),this._materialModuleNames=rh(r)}createMaterial(e={}){return new pn(this.device,s(r({},e),{factory:this}))}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(e){if(this._materialBindingNames.has(e))return!0;let n=ii(e);return n?this._materialModuleNames.has(n):!1}ownsModule(e){return this._materialModuleNames.has(e)}getBindingsByGroup(e){return Object.keys(e).length>0?{[Ge]:e}:{}}};function ii(t){return t.endsWith(`Uniforms`)?t.slice(0,-8):null}function nh(t){let e=new Set;for(let n of Object.values(t.modules))for(let r of n.bindingLayout||[])r.group===Ge&&e.add(r.name);return e}function rh(t){let e=new Set;for(let n of Object.values(t.modules))n.name&&n.bindingLayout?.some(r=>r.group===Ge&&r.name===n.name)&&e.add(n.name);return e}var pn=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};_dynamicResourceGenerations={};constructor(e,n={}){this.id=n.id||G(`material`),this.device=e,this.factory=n.factory||new mt(e,{modules:n.modules||n.shaderInputs?.getModules()||[]});let r=Object.fromEntries((n.shaderInputs?.getModules()||this.factory.modules).map(i=>[i.name,i]));this.shaderInputs=n.shaderInputs||new Q(r),this._uniformStore=new dt$1(this.device,this.shaderInputs.modules);for(let[i,o]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(i)&&Ae(o)){let s=this._uniformStore.getManagedUniformBuffer(i);this.bindings[`${i}Uniforms`]=s}this.updateShaderInputs(),n.bindings&&this._replaceOwnedBindings(n.bindings)}destroy(){this._uniformStore.destroy()}clone(e={}){let n=this.factory.createMaterial({id:e.id,shaderInputs:e.shaderInputs,bindings:r(r({},this.getResourceBindings()),e.bindings)});return e.shaderInputs||n.setProps(this.shaderInputs.getUniformValues()),e.moduleProps&&n.setProps(e.moduleProps),n.updateShaderInputs(),n}ownsBinding(e){return this.factory.ownsBinding(e)}ownsModule(e){return this.factory.ownsModule(e)}setProps(e){this.shaderInputs.setProps(e)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){let e={};for(let[n,r]of Object.entries(this.bindings))ii(n)||(e[n]=r);return e}getBindings(e={bindings:[]}){this._syncDynamicResourceGenerations();let n={},r=n;for(let[i,o]of Object.entries(this.bindings))if(ie(o)){let s=ln(e,i,{fallbackGroup:Ge}),a=s?o.resolveTextureBinding(s):null;a&&(r[i]=a)}else o instanceof k?r[i]=o.buffer:Ee(o)?r[i]=cn(o):r[i]=o;return this._syncDynamicResourceGenerations(),n}getBindingsByGroup(e={bindings:[]}){return this.factory.getBindingsByGroup(this.getBindings(e))}getBindGroupCacheKey(e){return this._syncDynamicResourceGenerations(),e===Ge?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let e=0;for(let n of Object.values(this.bindings))n instanceof Qe$1?e=Math.max(e,n.texture.updateTimestamp):n instanceof P||n instanceof C||n instanceof Ye||n instanceof k?e=Math.max(e,n.updateTimestamp):ie(n)?e=n.isReady?Math.max(e,n.updateTimestamp):1/0:Ee(n)&&(e=Math.max(e,(n.buffer instanceof k,n.buffer.updateTimestamp)));return e}_replaceOwnedBindings(e){this._setOwnedBindings(e)&&(this._bindGroupCacheToken={})}_setOwnedBindings(e){let n=!1;for(let[r,i]of Object.entries(e))i!==void 0&&this.ownsBinding(r)&&this.bindings[r]!==i&&(this.bindings[r]=i,n=!0);return n}_syncDynamicResourceGenerations(){let e={},n=!1;for(let[r,i]of Object.entries(this.bindings)){let o=ih(i);o!==null&&(e[r]=o,this._dynamicResourceGenerations[r]!==o&&(n=!0))}Object.keys(e).length!==Object.keys(this._dynamicResourceGenerations).length&&(n=!0),this._dynamicResourceGenerations=e,n&&(this._bindGroupCacheToken={})}};function ih(t){return ie(t)?t.generation:da(t)?.generation??null}var oi={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function gt(t){return t?Array.isArray(t)?t[0]??null:t:null}function ya(t){let{dimension:e,data:n}=t;if(!n)return null;switch(e){case`1d`:{let r=gt(n);if(!r)return null;let{width:i}=bt(r);return{width:i,height:1}}case`2d`:{if(ArrayBuffer.isView(n))return null;let r=gt(n);return r?bt(r):null}case`3d`:case`2d-array`:{if(!Array.isArray(n)||n.length===0)return null;let r=gt(n[0]);return r?bt(r):null}case`cube`:{let r=Object.keys(n)[0]??null;if(!r)return null;let i=n[r],o=gt(i);return o?bt(o):null}case`cube-array`:{if(!Array.isArray(n)||n.length===0)return null;let r=n[0],i=Object.keys(r)[0]??null;if(!i)return null;let o=gt(r[i]);return o?bt(o):null}default:return null}}function bt(t){if(We(t))return $e$1(t);if(typeof t==`object`&&`width`in t&&`height`in t)return{width:t.width,height:t.height};throw new Error(`Unsupported mip-level data`)}function oh(t){return typeof t==`object`&&t!==null&&`data`in t&&`width`in t&&`height`in t}function sh(t){return ArrayBuffer.isView(t)}function si(t){let{textureFormat:e,format:n}=t;if(e&&n&&e!==n)throw new Error(`Conflicting texture formats "${e}" and "${n}" provided for the same mip level`);return e??n}function Ma(t){let e=oi[t];if(e===void 0)throw new Error(`Invalid cube face: ${t}`);return e}function ah(t,e){return 6*t+Ma(e)}function ai(t){throw new Error(`setTexture1DData not supported in WebGL.`)}function ch(t){return Array.isArray(t)?t:[t]}function Ie(t,e,n,r$29){let i=ch(e),o=t,s=[];for(let a=0;a<i.length;a++){let c=i[a];if(We(c))s.push({type:`external-image`,image:c,z:o,mipLevel:a});else if(oh(c))s.push({type:`texture-data`,data:c,textureFormat:si(c),z:o,mipLevel:a});else if(sh(c)&&n)s.push({type:`texture-data`,data:r({data:c,width:Math.max(1,n.width>>a),height:Math.max(1,n.height>>a)},r$29?{format:r$29}:{}),textureFormat:r$29,z:o,mipLevel:a});else throw new Error(`Unsupported 2D mip-level payload`)}return s}function ci(t){let e=[];for(let n=0;n<t.length;n++)e.push(...Ie(n,t[n]));return e}function li(t){let e=[];for(let n=0;n<t.length;n++)e.push(...Ie(n,t[n]));return e}function fi(t){let e=[];for(let[n,r]of Object.entries(t)){let i=Ma(n);e.push(...Ie(i,r))}return e}function ui(t){let e=[];return t.forEach((n,r)=>{for(let[i,o]of Object.entries(n)){let s=ah(r,i);e.push(...Ie(s,o))}}),e}var pi=class t{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;generation=0;updateTimestamp;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error(`Texture not initialized yet`);return this._texture}get sampler(){if(!this._sampler)throw new Error(`Sampler not initialized yet`);return this._sampler}get view(){if(!this._view)throw new Error(`View not initialized yet`);return this._view}get[Symbol.toStringTag](){return`DynamicTexture`}toString(){let e=this._texture?.width??this.props.width??`?`,n=this._texture?.height??this.props.height??`?`;return`DynamicTexture:"${this.id}":${e}x${n}px:(${this.isReady?`ready`:`loading...`})`}resolveTextureBinding(e){return this.isReady?this.texture:null}constructor(e,n){this.device=e;let r$30=G(`dynamic-texture`),i=n;this.props=s(r(s(r({},t.defaultProps),{id:r$30}),n),{data:null}),this.id=this.props.id,this.ready=new Promise((o,s)=>{this.resolveReady=o,this.rejectReady=s}),this.updateTimestamp=this.device.incrementTimestamp(),this.initAsync(i)}async initAsync(e){try{let n=await this._loadAllData(e);this._checkNotDestroyed();let r$31=n.data?lh(s(r({},n),{width:e.width,height:e.height,format:e.format})):[],i=`format`in e&&e.format!==void 0,o=`usage`in e&&e.usage!==void 0,a=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};return ya(n)||{width:this.props.width||1,height:this.props.height||1}})();if(!a||a.width<=0||a.height<=0)throw new Error(`${this} size could not be determined or was zero`);let c=fh(this.device,r$31,a,{format:i?e.format:void 0}),l=c.format??this.props.format,f$2=s(r(r({},this.props),a),{format:l,mipLevels:1,data:void 0});this.device.isTextureFormatCompressed(l)&&!o&&(f$2.usage=C.SAMPLE|C.COPY_DST);let u=this.props.mipmaps&&!c.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(l);if(this.device.type===`webgpu`&&u){let g=this.props.dimension===`3d`?C.SAMPLE|C.STORAGE|C.COPY_DST|C.COPY_SRC:C.SAMPLE|C.RENDER|C.COPY_DST|C.COPY_SRC;f$2.usage|=g}let p=this.device.getMipLevelCount(f$2.width,f$2.height),d=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels===`auto`?p:Math.max(1,Math.min(p,this.props.mipLevels??1)),h=s(r({},f$2),{mipLevels:d});this._texture=this.device.createTexture(h),this._sampler=this.texture.sampler,this._view=this.texture.view,this._touchGeneration(),c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!u&&f.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),u&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),f.info(1,`${this} created`)()}catch(n){let r=n instanceof Error?n:new Error(String(n));this.rejectReady(r)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.isReady=!1,this.destroyed=!0}generateMipmaps(){this.device.type===`webgl`?(this.texture.generateMipmapsWebGL(),this._touch()):this.device.type===`webgpu`?(this.device.generateMipmapsWebGPU(this.texture),this._touch()):f.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();let n=e instanceof Y$1?e:this.device.createSampler(e);this.texture.setSampler(n),this._sampler=n,this._touchGeneration()}async readBuffer(e={}){this.isReady||await this.ready;let n=e.width??this.texture.width,r$32=e.height??this.texture.height,i=e.depthOrArrayLayers??this.texture.depth,o=this.texture.computeMemoryLayout({width:n,height:r$32,depthOrArrayLayers:i}),s$11=this.device.createBuffer({byteLength:o.byteLength,usage:P.COPY_DST|P.MAP_READ});this.texture.readBuffer(s(r({},e),{width:n,height:r$32,depthOrArrayLayers:i}),s$11);let a=this.device.createFence();return await a.signaled,a.destroy(),s$11}async readAsync(e={}){this.isReady||await this.ready;let n=e.width??this.texture.width,r=e.height??this.texture.height,i=e.depthOrArrayLayers??this.texture.depth,o=this.texture.computeMemoryLayout({width:n,height:r,depthOrArrayLayers:i}),s=await this.readBuffer(e),a=await s.readAsync(0,o.byteLength);return s.destroy(),a.buffer instanceof ArrayBuffer?a.buffer:a.slice().buffer}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;let n=this.texture;return this._texture=n.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,n.destroy(),this._touchGeneration(),f.info(`${this} resized`),!0}getCubeFaceIndex(e){let n=oi[e];if(n===void 0)throw new Error(`Invalid cube face: ${e}`);return n}getCubeArrayFaceIndex(e,n){return 6*e+this.getCubeFaceIndex(n)}setTexture1DData(e){if(this._checkReady(),this.texture.props.dimension!==`1d`)throw new Error(`${this} is not 1d`);let n=ai(e);this._setTextureSubresources(n)}setTexture2DData(e,n=0){if(this._checkReady(),this.texture.props.dimension!==`2d`)throw new Error(`${this} is not 2d`);let r=Ie(n,e);this._setTextureSubresources(r)}setTexture3DData(e){if(this.texture.props.dimension!==`3d`)throw new Error(`${this} is not 3d`);let n=ci(e);this._setTextureSubresources(n)}setTextureArrayData(e){if(this.texture.props.dimension!==`2d-array`)throw new Error(`${this} is not 2d-array`);let n=li(e);this._setTextureSubresources(n)}setTextureCubeData(e){if(this.texture.props.dimension!==`cube`)throw new Error(`${this} is not cube`);let n=fi(e);this._setTextureSubresources(n)}setTextureCubeArrayData(e){if(this.texture.props.dimension!==`cube-array`)throw new Error(`${this} is not cube-array`);let n=ui(e);this._setTextureSubresources(n)}_setTextureSubresources(e){for(let n of e){let{z:r,mipLevel:i}=n;switch(n.type){case`external-image`:let{image:o,flipY:s}=n;this.texture.copyExternalImage({image:o,z:r,mipLevel:i,flipY:s});break;case`texture-data`:let{data:a,textureFormat:c}=n;if(c&&c!==this.texture.format)throw new Error(`${this} mip level ${i} uses format "${c}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:r,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:i});break;default:throw new Error(`Unsupported 2D mip-level payload`)}}e.length>0&&this._touch()}async _loadAllData(e){let n=await di(e.data);return{dimension:e.dimension??`2d`,data:n??null}}_checkNotDestroyed(){this.destroyed&&f.warn(`${this} already destroyed`)}_checkReady(){this.isReady||f.warn(`${this} Cannot perform this operation before ready`)}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}static defaultProps=s(r({},C.defaultProps),{dimension:`2d`,data:null,mipmaps:!1})};function lh(t){if(!t.data)return[];let e=t.width&&t.height?{width:t.width,height:t.height}:void 0,n=`format`in t?t.format:void 0;switch(t.dimension){case`1d`:return ai(t.data);case`2d`:return Ie(0,t.data,e,n);case`3d`:return ci(t.data);case`2d-array`:return li(t.data);case`cube`:return fi(t.data);case`cube-array`:return ui(t.data);default:throw new Error(`Unhandled dimension ${t.dimension}`)}}function fh(t,e,n,r){if(e.length===0)return{subresources:e,mipLevels:1,format:r.format,hasExplicitMipChain:!1};let i=new Map;for(let f of e){let u=i.get(f.z)??[];u.push(f),i.set(f.z,u)}let o=e.some(f=>f.mipLevel>0),s=r.format,a=Number.POSITIVE_INFINITY,c=[];for(let[f,u]of i){let p=[...u].sort((S,y)=>S.mipLevel-y.mipLevel),d=p[0];if(!d||d.mipLevel!==0)throw new Error(`DynamicTexture: slice ${f} is missing mip level 0`);let h=Ea(t,d);if(h.width!==n.width||h.height!==n.height)throw new Error(`DynamicTexture: slice ${f} base level dimensions ${h.width}x${h.height} do not match expected ${n.width}x${n.height}`);let g=Aa(d);if(g){if(s&&s!==g)throw new Error(`DynamicTexture: slice ${f} base level format "${g}" does not match texture format "${s}"`);s=g}let m=s&&t.isTextureFormatCompressed(s)?uh(t,h.width,h.height,s):t.getMipLevelCount(h.width,h.height),v=0;for(let S=0;S<p.length;S++){let y=p[S];if(!y||y.mipLevel!==S||S>=m)break;let _=Ea(t,y),x=Math.max(1,h.width>>S),M=Math.max(1,h.height>>S);if(_.width!==x||_.height!==M)break;let I=Aa(y);if(I&&(s||(s=I),I!==s))break;v++,c.push(y)}a=Math.min(a,v)}let l=Number.isFinite(a)?Math.max(1,a):1;return{subresources:c.filter(f=>f.mipLevel<l),mipLevels:l,format:s,hasExplicitMipChain:o}}function Aa(t){if(t.type===`texture-data`)return t.textureFormat??si(t.data)}function Ea(t,e){switch(e.type){case`external-image`:return t.getExternalImageSize(e.image);case`texture-data`:return{width:e.data.width,height:e.data.height};default:throw new Error(`Unsupported texture subresource`)}}function uh(t,e,n,r){let{blockWidth:i=1,blockHeight:o=1}=t.getTextureFormatInfo(r),s=1;for(let a=1;;a++){let c=Math.max(1,e>>a),l=Math.max(1,n>>a);if(c<i||l<o)break;s++}return s}async function di(t){if(t=await t,Array.isArray(t))return await Promise.all(t.map(di));if(t&&typeof t==`object`&&t.constructor===Object){let e=t,n=await Promise.all(Object.values(e).map(di)),r=Object.keys(e),i={};for(let o=0;o<r.length;o++)i[r[o]]=n[o];return i}return t}function hi(t,e){if(!t)throw new Error(e)}var ue=class{id;matrix=new U;display=!0;position=new Z;rotation=new Z;scale=new Z(1,1,1);userData={};props={};constructor(e={}){let{id:n}=e;this.id=n||G(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return hi(e.length===3,`setPosition requires vector argument`),this.position=e,this}setRotation(e){return hi(e.length===3||e.length===4,`setRotation requires vector argument`),this.rotation=e,this}setScale(e){return hi(e.length===3,`setScale requires vector argument`),this.scale=e,this}setMatrix(e,n=!0){n?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){let{position:n,rotation:r,scale:i,update:o=!0}=e;return n&&this.setPosition(n),r&&this.setRotation(r),i&&this.setScale(i),o&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),this.rotation.length===4){let e=new U().fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:n,scale:r}={}){return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(e,n){n=n||this.matrix;let r=new U(e).multiplyRight(n),i=r.invert(),o=i.transpose();return{viewMatrix:e,modelMatrix:n,objectMatrix:n,worldMatrix:r,worldInverseMatrix:i,worldInverseTransposeMatrix:o}}_setScenegraphNodeProps(e){e.display!==void 0&&(this.display=e.display),e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};function dn(){return[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]]}function hn(t,e,n){let r=new U(n);for(let i=0;i<8;i++){let o=new Z(e[i&1?1:0][0],e[i&2?1:0][1],e[i&4?1:0][2]);r.transformAsPoint(o,o);for(let s=0;s<3;s++)t[0][s]=Math.min(t[0][s],o[s]),t[1][s]=Math.max(t[1][s],o[s])}}function mn(t){return Number.isFinite(t[0][0])}var mi=class t extends ue{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;let{children:n=[]}=e;f.assert(n.every(r=>r instanceof ue),`every child must an instance of ScenegraphNode`),super(e),this.children=n}getBounds(){let e=dn();return this.traverse((n,{worldMatrix:r})=>{let i=n.getBounds();if(!i)return;let o=new U(r).multiplyRight(n.matrix);hn(e,i,o)}),mn(e)?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(let n of e)Array.isArray(n)?this.add(...n):this.children.push(n);return this}remove(e){let n=this.children,r=n.indexOf(e);return r>-1&&n.splice(r,1),this}removeAll(){return this.children=[],this}traverse(e,{worldMatrix:n=new U}={}){if(!this.display)return;let r=new U(n).multiplyRight(this.matrix);for(let i of this.children)i.display&&(i instanceof t?i.traverse(e,{worldMatrix:r}):e(i,{worldMatrix:r}))}traverseDepthSorted(e,{viewMatrix:n,worldMatrix:r=new U,order:i=`back-to-front`}){let o=new U(n),s=[];this.traverse((c,l)=>{let f=c.getBounds(),u=f?new Z(f[0]).add(f[1]).divide([2,2,2]):new Z,p=new U(l.worldMatrix).multiplyRight(c.matrix);p.transformAsPoint(u,u),o.transformAsPoint(u,u),s.push({node:c,context:{worldMatrix:p,bounds:f,depth:-u[2]},index:s.length})},{worldMatrix:new U(r)});let a=i===`back-to-front`?-1:1;s.sort((c,l)=>a*(c.context.depth-l.context.depth)||c.index-l.index);for(let{node:c,context:l}of s)e(c,l)}preorderTraversal(e,{worldMatrix:n=new U}={}){let r=new U(n).multiplyRight(this.matrix);e(this,{worldMatrix:r});for(let i of this.children)i instanceof t?i.preorderTraversal(e,{worldMatrix:r}):e(i,{worldMatrix:r})}};var gi=class extends ue{model;instanceMatrices;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.instanceMatrices=e.instanceMatrices||null,this.bounds=e.bounds?this.instanceMatrices?ph(e.bounds,this.instanceMatrices):e.bounds:null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};function ph(t,e){let n=dn();for(let r of e)hn(n,t,r);return mn(n)?n:null}var bi=class{poolSize=20;bufferPools;constructor(){this.bufferPools=new Map}createOrReuse(e,n){if(n>e.limits.maxBufferSize)throw new Error(`Buffer pool cannot allocate ${n} bytes: device.limits.maxBufferSize is ${e.limits.maxBufferSize}`);let r=this.bufferPools.get(e),i=r?r.findIndex(s=>s.byteLength>=n):-1;if(i<0)return e.createBuffer({usage:P.VERTEX|P.STORAGE|P.COPY_DST|P.COPY_SRC,byteLength:n});let[o]=r.splice(i,1);return o}recycle(e){let n=e.device;this.bufferPools.has(n)||this.bufferPools.set(n,[]);let r=this.bufferPools.get(n),i=r.findIndex(o=>o.byteLength>e.byteLength);i<0?r.push(e):r.splice(i,0,e),this.purge()}purge(){for(let[e,n]of this.bufferPools){let r=e.isLost?0:this.poolSize;for(;n.length>r;)n.shift().destroy();n.length===0&&this.bufferPools.delete(e)}}};var ze=new bi;var Ia=/^vertex-list<([^<>]+)>$/;var La=/^value-list<([^<>]+)>$/;function gn(t){return Ia.test(t)}function bn(t){return La.test(t)}function Ra(t){let e=Ia.exec(t),n=La.exec(t),r=e?.[1]??n?.[1]??t;try{S.getVertexFormatInfo(r)}catch{throw new Error(`Unsupported GPUVector format ${t}`)}return r}function oe(t){let e=Ra(t),n=gn(t),r$33=bn(t),i=S.getVertexFormatInfo(e),o=i.type,s=i.normalized,a=dh(o,s);return r({format:t,elementFormat:e,vertexList:n,valueList:r$33,type:o,signedDataType:hh(e,o),primitiveType:a,components:i.components,byteLength:i.byteLength,integer:i.integer,signed:i.signed,normalized:s},i.webglOnly?{webglOnly:!0}:{})}function dh(t,e){if(e)return`f32`;switch(t){case`float32`:return`f32`;case`float16`:return`f16`;case`uint8`:case`uint16`:case`uint32`:return`u32`;case`sint8`:case`sint16`:case`sint32`:return`i32`;default:throw new Error(`Unsupported GPUVector component type ${t}`)}}function hh(t,e){if(t===`unorm10-10-10-2`)return`uint32`;switch(e){case`unorm8`:return`uint8`;case`snorm8`:return`sint8`;case`unorm16`:return`uint16`;case`snorm16`:return`sint16`;default:return e}}var se=class{buffer;format;length;byteOffset;byteStride;constructor(e){let n=S.getVertexFormatInfo(e.format).byteLength,r=e.byteOffset??0,i=e.byteStride??n;if(_i(e.length,`GPUDataView length`),_i(r,`GPUDataView byteOffset`),_i(i,`GPUDataView byteStride`),i<n)throw new Error(`GPUDataView byteStride ${i} is smaller than ${e.format} byte length ${n}`);let o=e.length===0?0:(e.length-1)*i+n,s=r+o;if(!Number.isSafeInteger(o)||!Number.isSafeInteger(s))throw new Error(`GPUDataView byte range must use safe integers`);if(s>e.buffer.byteLength)throw new Error(`GPUDataView exceeds its backing buffer byte length`);this.buffer=e.buffer,this.format=e.format,this.length=e.length,this.byteOffset=r,this.byteStride=i}get elementByteLength(){return S.getVertexFormatInfo(this.format).byteLength}get byteLength(){return this.length===0?0:(this.length-1)*this.byteStride+this.elementByteLength}};function _i(t,e){if(!Number.isSafeInteger(t)||t<0)throw new Error(`${e} must be a non-negative safe integer`)}function vn(t){return!!(t&&typeof t==`object`&&t.type===`struct`)}function Ca(t,e){let n=Object.entries(t);if(n.length===0)throw new Error(`GPUData struct format must declare at least one field`);return e===`packed`?mh(n):gh(n)}function mh(t){let e=[],n=0,r=0;for(let[i,o]of t){let s=S.getVertexFormatInfo(o);if(s.webglOnly)throw new Error(`Packed GPUData struct field "${i}" uses WebGL-only format ${o}`);n=wa(n,Math.min(4,s.byteLength)),e.push([i,Object.freeze({format:o,byteOffset:n,byteLength:s.byteLength})]),n+=s.byteLength,r+=s.components}return Object.freeze({type:`struct`,layout:`packed`,fields:Object.freeze(Object.fromEntries(e)),components:r,byteStride:wa(n,4),rowByteLength:n})}function gh(t){let e=Object.fromEntries(t.map(([s,a])=>[s,bh(a)])),n=ut$1(e,{layout:`wgsl-storage`}),r=[],i=0,o=0;for(let[s,a]of t){let c=S.getVertexFormatInfo(a),l=n.fields[s].offset*4;r.push([s,Object.freeze({format:a,byteOffset:l,byteLength:c.byteLength})]),i=Math.max(i,l+c.byteLength),o+=c.components}return Object.freeze({type:`struct`,layout:`wgsl-storage`,fields:Object.freeze(Object.fromEntries(r)),components:o,byteStride:n.byteLength,rowByteLength:i})}function bh(t){let e=S.getVertexFormatInfo(t);switch(e.type){case`float32`:return _n(`f32`,e.components);case`sint32`:return _n(`i32`,e.components);case`uint32`:return _n(`u32`,e.components);default:return _n(`u32`,Math.ceil(e.byteLength/4))}}function _n(t,e){return e===1?t:`vec${e}<${t}>`}function wa(t,e){return Math.ceil(t/e)*e}var vi=class{buffer;ownsDataBuffer;constructor(e,n){this.buffer=e,this.ownsDataBuffer=n}get ownsBuffer(){return this.ownsDataBuffer}transferBufferOwnership(e){if(e.buffer!==this.buffer)throw new Error(`GPUData ownership can only be transferred to the same buffer`);e.ownsDataBuffer=this.ownsDataBuffer,this.ownsDataBuffer=!1}destroy(){this.ownsDataBuffer&&(this.buffer.destroy(),this.ownsDataBuffer=!1)}};var xi=class extends vi{dataType;format;length;valueLength;stride;byteOffset;byteStride;rowByteLength;readbackMetadata;valueOffsets;nullBitmap;valueByteLength;constructor(e){let{buffer:n,format:r,length:i,valueLength:o,stride:s,byteOffset:a=0,byteStride:c,rowByteLength:l,ownsBuffer:f=!1,readbackMetadata:u,valueOffsets:p,nullBitmap:d,valueByteLength:h,dataType:g}=e;super(n,f);let m;r?typeof r==`string`?m=r:m=Ca(r,e.layout??`wgsl-storage`):m=void 0;let v=vn(m)?m:void 0,S=typeof m==`string`?oe(m):void 0;if(this.dataType=g,this.format=m,this.length=i,this.valueLength=o??i,this.stride=s??S?.components??v?.components??c??l??1,this.byteOffset=a,this.rowByteLength=l??v?.rowByteLength??S?.byteLength??c??this.stride,this.byteStride=c??v?.byteStride??this.rowByteLength,v){if(this.rowByteLength<v.rowByteLength)throw new Error(`GPUData rowByteLength ${this.rowByteLength} is smaller than struct format row byte length ${v.rowByteLength}`);if(this.byteStride<Math.max(v.byteStride,this.rowByteLength))throw new Error(`GPUData byteStride ${this.byteStride} is smaller than its struct row layout`)}this.readbackMetadata=u,this.valueOffsets=p,this.nullBitmap=d,this.valueByteLength=h}getChild(e){if(!vn(this.format))return null;let n=this.format.fields[e];return n?new se({buffer:this.buffer,format:n.format,length:this.length,byteOffset:this.byteOffset+n.byteOffset,byteStride:this.byteStride}):null}getChildAt(e){if(!vn(this.format))return null;let n=Object.values(this.format.fields)[e];return n?new se({buffer:this.buffer,format:n.format,length:this.length,byteOffset:this.byteOffset+n.byteOffset,byteStride:this.byteStride}):null}};var $e=xi;var Le=class{name;dataType;format;length;valueLength;stride;byteOffset;byteStride;rowByteLength;bufferLayout;data=[];device;bufferProps;isAppendable=!1;ownsDataChunks=!0;ownedVectors=[];appendableByteLength=0;constructor(e){switch(e.type){case`buffer`:{let{name:n,buffer:r,format:i,length:o,valueLength:s=o,byteOffset:a=0,ownsBuffer:c=!1}=e,{stride:l,byteStride:f,rowByteLength:u}=Ta(e);this.name=n,this.dataType=e.dataType,this.format=i,this.length=o,this.valueLength=s,this.stride=l,this.byteOffset=a,this.byteStride=f,this.rowByteLength=u,this.data.push(new $e({buffer:r,format:i,length:o,valueLength:s,stride:l,byteOffset:a,byteStride:f,rowByteLength:u,ownsBuffer:c,dataType:e.dataType}));return}case`interleaved`:{let{name:n,buffer:r,format:i,length:o,valueLength:s=o,byteOffset:a=0,byteStride:c,attributes:l,ownsBuffer:f=!1}=e;this.name=n,this.dataType=e.dataType,this.format=i,this.length=o,this.valueLength=s,this.stride=c,this.byteOffset=a,this.byteStride=c,this.rowByteLength=c,this.bufferLayout={name:n,byteStride:c,attributes:l},this.data.push(new $e({buffer:r,format:i,length:o,valueLength:s,stride:c,byteOffset:a,byteStride:c,rowByteLength:c,ownsBuffer:f,dataType:e.dataType}));return}case`data`:{let n=e.format??_h(e.data),r=n?oe(n):void 0,{name:i,data:o,stride:s=o[0]?.stride??r?.components??1,valueLength:a=o.reduce((p,d)=>p+d.valueLength,0),byteStride:c=o[0]?.byteStride??r?.byteLength,rowByteLength:l=o[0]?.rowByteLength??r?.byteLength,bufferLayout:f,ownsData:u=!1}=e;if(c===void 0||l===void 0)throw new Error(`GPUVector requires format or explicit byte layout metadata`);n&&vh(o,n),this.name=i,this.dataType=e.dataType,this.format=n,this.length=o.reduce((p,d)=>p+d.length,0),this.valueLength=a,this.stride=s,this.byteOffset=o.length===1?o[0].byteOffset:0,this.byteStride=c,this.rowByteLength=l,this.bufferLayout=f,this.ownsDataChunks=u,this.data.push(...o);return}case`appendable`:{let{name:n,device:r,format:i,valueLength:o=0,bufferProps:s}=e,{stride:a,byteStride:c,rowByteLength:l}=Ta(e);this.name=n,this.dataType=e.dataType,this.format=i,this.length=0,this.valueLength=o,this.stride=a,this.byteOffset=0,this.byteStride=c,this.rowByteLength=l,this.device=r,this.bufferProps=s,this.isAppendable=!0;return}}}get ownsBuffer(){return this.ownsDataChunks&&this.data.some(e=>e.ownsBuffer)||this.ownedVectors.some(e=>e.ownsBuffer)}get capacityRows(){return this.isAppendable?this.length:void 0}get appendedByteLength(){return this.appendableByteLength}addData(e){if(this.format&&e.format!==this.format)throw new Error(`GPUVector.addData() requires matching formats`);if(e.byteStride!==this.byteStride)throw new Error(`GPUVector.addData() requires matching byteStride`);if(e.rowByteLength!==this.rowByteLength)throw new Error(`GPUVector.addData() requires matching rowByteLength`);return this.data.push(e),this.length+=e.length,this.valueLength+=e.valueLength,this}appendDataChunk(e,n=this.appendableByteLength+e.buffer.byteLength){if(!this.isAppendable)throw new Error(`GPUVector.appendDataChunk() requires appendable vector storage`);if(this.format&&e.format!==this.format)throw new Error(`GPUVector.appendDataChunk() requires matching formats`);if(e.byteStride!==this.byteStride||e.rowByteLength!==this.rowByteLength)throw new Error(`GPUVector.appendDataChunk() requires matching byte layout metadata`);return this.data.push(e),this.length+=e.length,this.valueLength+=e.valueLength,this.appendableByteLength=n,this}resetLastBatch(){if(!this.isAppendable)throw new Error(`GPUVector.resetLastBatch() requires appendable vector storage`);for(let e of this.data.splice(0))e.destroy();return this.length=0,this.valueLength=0,this.appendableByteLength=0,this}retainOwnedVectors(e){return this.ownedVectors.push(...e),this}transferBufferOwnership(e){let n=this.data[0],r=e.data[0];if(!n||!r||n.buffer!==r.buffer)throw new Error(`GPUVector ownership can only be transferred to the same buffer`);n.transferBufferOwnership(r)}destroy(){if(this.ownsDataChunks)for(let e of this.data)e.destroy();for(let e of this.ownedVectors.splice(0))e.destroy()}};function Ta(t){let e=t.format?oe(t.format):void 0,n=t.rowByteLength??t.byteStride??e?.byteLength;if(n===void 0)throw new Error(`GPUVector requires format or explicit rowByteLength`);return{stride:t.stride??e?.components??1,byteStride:t.byteStride??n,rowByteLength:n}}function _h(t){return t[0]?.format}function vh(t,e){if(t.find(r=>r.format!==e))throw new Error(`GPUVector data chunks must share the declared format`)}var pe=class t{static get bufferPoolSize(){return ze.poolSize}static set bufferPoolSize(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`GPUDataEvaluator.bufferPoolSize must be a non-negative safe integer`);ze.poolSize=e,ze.purge()}type;size;get offset(){return this._offset}get stride(){return this._stride}normalized;isConstant;length;get byteLength(){return this._byteLength}ValueType;source=null;format;_id;_destroyed=!1;_value;_offset;_stride;_byteLength;_gpuVector;_bufferOwnership=`owned`;_targetBuffer;static fromArray(e,{type:n,size:r=1,offset:i=0,stride:o=0,normalized:s=!1}){let a=n,c;if(Array.isArray(e)){a=a||`float32`;c=new(Wt$1(a))(e)}else e instanceof Float64Array?(a=`uint32`,r*=2,i*=2,o*=2,c=new Uint32Array(e.buffer,e.byteOffset,e.byteLength/4)):(a=a||It$1(e),c=e);let l=`<${a} * ${r}>`;return new t({id:l,type:a,size:r,offset:i,stride:o,normalized:s,value:c})}static fromConstant(e,n=`float32`){let r=Wt$1(n),i;return Array.isArray(e)?i=`[${e.join(`,`)}]`:(i=String(e),e=[e]),new t({id:i,isConstant:!0,type:n,size:e.length,value:new r(e)})}static fromGPUData(e,n={}){Sh(e);let r$34=new se({buffer:e.buffer,format:e.format,length:e.length,byteOffset:e.byteOffset,byteStride:e.byteStride});return new t(s(r({},Pa(r$34)),{id:n.id,gpuData:e}))}static fromGPUDataView(e,n={}){return new t(s(r({},Pa(e)),{id:n.id,buffer:e.buffer}))}constructor(e){let{id:n,value:r,buffer:i,gpuData:o,format:s,source:a=null,isConstant:c=!1}=e;if(!a&&!r&&!i&&!o)throw new Error(`GPUDataEvaluator must have a value source`);let{type:l,size:f,offset:u,stride:p,normalized:d,length:h}=e;if(a instanceof t?(l=l??a.type,f=f??a.size,u=u??a.offset,p=p??a.stride,d=d??a.normalized,h=h??a.length):(f=f??1,u=u??0,d=d??!1,h=c?1:h),!l)throw new Error(`GPUDataEvaluator: type not defined`);if(this._id=n,this.type=l,this.size=f,this.ValueType=Wt$1(this.type),this._offset=u,this._stride=p||this.ValueType.BYTES_PER_ELEMENT*f,this.normalized=d,this.source=a,this.format=s,h===void 0)if(c)h=1;else{if(!r)throw new Error(`GPUDataEvaluator: length not defined`);h=Math.ceil(r.byteLength/this.stride)}this.isConstant=c,this.length=h;let g=this.ValueType.BYTES_PER_ELEMENT*this.size;this._byteLength=h===0?0:(h-1)*this.stride+g,this._value=r,this._bufferOwnership=a instanceof t||i||o?`borrowed`:`owned`,o?this._gpuVector=new Le({type:`data`,name:this._id??`data`,format:o.format,data:[o],stride:o.stride,byteStride:o.byteStride,rowByteLength:o.rowByteLength}):i&&(this._gpuVector=this.createGPUVectorView({buffer:i,name:this._id,format:this.format}))}get value(){return this._value||(this.source instanceof t?this.source.value:void 0)}get evaluated(){return!!this._gpuVector}get id(){return this._id}get gpuVector(){if(!this._gpuVector)throw new Error(`${this} not evaluated`);return this._gpuVector}get buffer(){return xn(this.gpuVector)}setTargetBuffer({buffer:e,byteOffset:n=0,byteStride:r=this.stride}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)throw new Error(`GPUDataEvaluator ${this} already evaluated`);if(!this.source||this.source instanceof t)throw new Error(`GPUDataEvaluator target buffers require a deferred operation source`);this._targetBuffer={buffer:e,byteOffset:n,byteStride:r}}async evaluate(e,n={}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)return this._gpuVector;let r$35;if(this.source instanceof t){let i=await this.source.evaluate(e);return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:xn(i)})),this._gpuVector}if(r$35=this._getEvaluationBuffer(e),this._value)r$35.write(this._value);else{let i=await this.source.execute(e,r$35);if(!i.success)throw i.error||new Error(`${this.source} evaluation failed`);i.value&&(this._value=i.value)}return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:r$35})),this._gpuVector}evaluateSync(e,n={}){if(this._destroyed)throw new Error(`GPUDataEvaluator ${this} already destroyed`);if(this._gpuVector)return this._gpuVector;let r$36;if(this.source instanceof t){let i=this.source.evaluateSync(e);return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:xn(i)})),this._gpuVector}if(r$36=this._getEvaluationBuffer(e),this._value)r$36.write(this._value);else{let i=this.source.executeSync(e,r$36);if(!i.success)throw i.error||new Error(`${this.source} evaluation failed`);i.value&&(this._value=i.value)}return this._gpuVector=this.createGPUVectorView(s(r({},n),{buffer:r$36})),this._gpuVector}createGPUVectorView(e){let n=e.name??this._id??`vector`,r=e.format??this.format??Ah(this.type,this.size,this.normalized);if(e.interleaved){let i=typeof e.interleaved==`object`&&e.interleaved.attributes?e.interleaved.attributes:Mh(this);return new Le({type:`interleaved`,name:n,buffer:e.buffer,format:e.format??this.format,length:this.length,byteOffset:this.offset,byteStride:this.stride,attributes:i,ownsBuffer:!1})}return new Le({type:`buffer`,name:n,buffer:e.buffer,format:r,length:this.length,stride:this.size,byteOffset:this.offset,byteStride:this.stride,rowByteLength:this.ValueType.BYTES_PER_ELEMENT*this.size,ownsBuffer:!1})}_getEvaluationBuffer(e){let n=this._targetBuffer;if(!n)return ze.createOrReuse(e,this.byteLength);if(n.buffer.device!==e)throw new Error(`GPUDataEvaluator target buffer belongs to a different device`);let r=this.ValueType.BYTES_PER_ELEMENT*this.size,i=this.length===0?0:(this.length-1)*n.byteStride+r;if(n.byteOffset+i>n.buffer.byteLength)throw new Error(`GPUDataEvaluator target buffer is too small for the output layout`);return this._offset=n.byteOffset,this._stride=n.byteStride,this._byteLength=i,this._bufferOwnership=`borrowed`,this._targetBuffer=void 0,n.buffer}async readValue(e=0,n){let{ValueType:r}=this,{size:i,offset:o,stride:s,length:a}=this,c=r.BYTES_PER_ELEMENT*i;if(n=n??a,e=Math.max(0,Math.min(a,e)),n=Math.max(e,Math.min(a,n)),this._value)return xh(this,this._value,e,n);let l=n-e;if(l===0)return new r(0);let f=o+e*s,u=s===c?l*c:(l-1)*s+c,p=await this.buffer.readAsync(f,u),d=new r(p.buffer,p.byteOffset,p.byteLength/r.BYTES_PER_ELEMENT);if(s===c)return d;let h=new Uint8Array(c*l);for(let g=0;g<l;g++){let m=g*s;h.set(p.subarray(m,m+c),g*c)}return new r(h.buffer)}async ensureCPUValue(){let e=this.value;if(e)return e;let n=await this.buffer.readAsync(0,this.offset+this.byteLength);if(n.byteLength%this.ValueType.BYTES_PER_ELEMENT!==0)throw new Error(`${this} backing buffer byte length is not aligned to its scalar type`);let r=n.slice();return this._value=new this.ValueType(r.buffer,r.byteOffset,r.byteLength/this.ValueType.BYTES_PER_ELEMENT),this._value}ensureCPUValueSync(){let e=this.value;if(e)return e;throw new Error(`${this} CPU value is not available for synchronous evaluation`)}toString(){return this._id??this.source?.toString()??this.constructor.name}destroy(){this._gpuVector&&(this._bufferOwnership===`owned`&&ze.recycle(xn(this._gpuVector)),this._gpuVector=void 0),this._targetBuffer=void 0,this._destroyed=!0}};function xh(t,e,n,r){let{ValueType:i,size:o,offset:s,stride:a}=t,c=a/i.BYTES_PER_ELEMENT,l=s/i.BYTES_PER_ELEMENT,f=r-n;if(c===o){let p=l+n*c;return e.subarray(p,p+f*o)}let u=new i(f*o);for(let p=0;p<f;p++){let d=l+(n+p)*c;u.set(e.subarray(d,d+o),p*o)}return u}function Ov(t){if(t instanceof pe)return t;if(typeof t==`number`||Array.isArray(t))return pe.fromConstant(t);if(t instanceof $e)return pe.fromGPUData(t);if(t instanceof se)return pe.fromGPUDataView(t);throw new Error(`getGPUDataEvaluator() requires GPUDataEvaluator, GPUData, GPUDataView, number, or number[]`)}function Sh(t){if(!t.format)throw new Error(`GPUDataEvaluator.fromGPUData() requires GPUData format metadata`);if(gn(t.format)||bn(t.format))throw new Error(`GPUDataEvaluator.fromGPUData() does not support variable-length input`);let n=oe(t.format).byteLength;if(t.rowByteLength!==n)throw new Error(`GPUDataEvaluator.fromGPUData() requires rowByteLength ${n} for GPUData`)}function Pa(t){let e=oe(t.format),n=Wt$1(e.signedDataType),r=n.BYTES_PER_ELEMENT*e.components;if(e.byteLength!==r)throw new Error(`GPUDataEvaluator does not support packed vertex format ${t.format}: ${e.byteLength} physical bytes cannot expose ${e.components} ${e.signedDataType} components`);if(t.byteOffset%n.BYTES_PER_ELEMENT!==0||t.byteStride%n.BYTES_PER_ELEMENT!==0)throw new Error(`GPUDataEvaluator requires ${t.format} offset and stride aligned to ${n.BYTES_PER_ELEMENT} bytes`);return{type:e.signedDataType,size:e.components,offset:t.byteOffset,stride:t.byteStride,normalized:e.normalized,length:t.length,format:t.format}}function xn(t){let e=yh(t).buffer;return e instanceof k?e.buffer:e}function yh(t){let[e,...n]=t.data;if(!e||n.length>0)throw new Error(`GPUDataEvaluator requires exactly one GPUData chunk for "${t.name}"`);return e}function Mh(t){let e=[];return Na(t,e,{byteOffset:0}),e}function Na(t,e,n){let r=t.source;if(r&&!(r instanceof pe)&&r.name===`interleave`){for(let i of Object.values(r.inputs))i instanceof pe&&Na(i,e,n);return}e.push({attribute:t.id??t.toString(),format:Ba(t.type,t.size,t.normalized),byteOffset:n.byteOffset}),n.byteOffset+=t.ValueType.BYTES_PER_ELEMENT*t.size}function Ba(t,e,n=!1){if(e<1||e>4)throw new Error(`Cannot synthesize a GPUVector vertex format with ${e} components`);let r=t;if(n)switch(t){case`uint8`:r=`unorm8`;break;case`sint8`:r=`snorm8`;break;case`uint16`:r=`unorm16`;break;case`sint16`:r=`snorm16`;break;case`float32`:r=`float32`;break;default:throw new Error(`Unsupported normalized vertex format for ${t}`)}return(r===`uint8`||r===`sint8`||r===`uint16`||r===`sint16`||r===`unorm8`||r===`snorm8`||r===`unorm16`||r===`snorm16`)&&e===3?`${r}x3-webgl`:`${r}${e===1?``:`x${e}`}`}function Ah(t,e,n=!1){return e>=1&&e<=4?Ba(t,e,n):void 0}var Vv={add:{arity:2,symbol:`arithmetic_add`},subtract:{arity:2,symbol:`arithmetic_subtract`},multiply:{arity:2,symbol:`arithmetic_multiply`},divide:{arity:2,symbol:`arithmetic_divide`},pow:{arity:2,symbol:`pow`},sqrt:{arity:1,symbol:`sqrt`},abs:{arity:1,symbol:`abs`},sin:{arity:1,symbol:`sin`},cos:{arity:1,symbol:`cos`},tan:{arity:1,symbol:`arithmetic_tan`},exp:{arity:1,symbol:`exp`},log:{arity:1,symbol:`log`}};function Oa(t,{operations:e,inputs:n}){switch(t.kind){case`input`:if(!(t.name in n))throw new Error(`Unknown expression input '${t.name}'`);return;case`literal`:if(Array.isArray(t.value)){for(let r of t.value)if(!Number.isFinite(r))throw new Error(`Expression literal array must contain only finite values, got ${r}`)}else if(!Number.isFinite(t.value))throw new Error(`Expression literal must be finite, got ${t.value}`);return;case`call`:{let r=e[t.op];if(!r)throw new Error(`Unknown expression op '${t.op}'`);if(t.args.length!==r.arity)throw new Error(`Expression op '${t.op}' expects ${r.arity} args, got ${t.args.length}`);for(let i of t.args)Oa(i,{operations:e,inputs:n});return}default:throw new Error(`Unsupported expression node ${t.kind}`)}}function kv(t,e){return Oa(t,e),Ua(t,e)}function Ua(t,e){switch(t.kind){case`input`:{let n=e.inputs[t.name];return e.laneIndex<n.size?e.formatInput(t.name):e.formatOutOfBoundsInput(t.name)}case`literal`:return e.formatLiteral(t.value);case`call`:{let n=e.operations[t.op],r=t.args.map(i=>Ua(i,e));return e.formatCall(n.symbol,r)}default:throw new Error(`Unsupported expression node ${t.kind}`)}}export{re as $,Zr as A,k as B,Wp as C,Zn as D,Z as E,ge as F,mt as G,kt as H,gi as I,pe as J,ni as K,gr as L,ed as M,ei as N,Zo as O,ga as P,rd as Q,ir as R,Vv as S,Yd as T,kv as U,ka as V,mi as W,pt as X,pi as Y,qr as Z,Qi as _,Hi as a,ze as at,Uf as b,Kd as c,Le as d,ri as et,Mt as f,Ov as g,Oi as h,Gp as i,za as it,cr as j,Zp as k,Ko as l,Oe as m,De as n,tt as nt,Ho as o,Nt as p,on as q,Ga as r,ue as rt,J as s,Bi as t,ti as tt,Kr as u,Qr as v,Xr as w,V as x,U as y,jr as z};
6148
+ //# debugId=7132919e-7016-51ee-a5b0-cf112a28f786