UNPKG

wgpu-matrix

Version:

fast matrix math library for WebGPU

3 lines (2 loc) 39.1 kB
const n=(t=Array,r=n=>n.fill(0),class extends t{constructor(...n){super(...n),r(this)}});var t,r;let e=1e-6;var o={__proto__:null,get EPSILON(){return e},degToRad:function(n){return n*Math.PI/180},euclideanModulo:function(n,t){return(n%t+t)%t},inverseLerp:function(n,t,r){const o=t-n;return Math.abs(t-n)<e?n:(r-n)/o},lerp:function(n,t,r){return n+(t-n)*r},radToDeg:function(n){return 180*n/Math.PI},setEpsilon:function(n){const t=e;return e=n,t}};const c=new Map;function u(n){let t=c.get(n);return t||(t=function(n){function t(t=0,r=0){const e=new n(2);return void 0!==t&&(e[0]=t,void 0!==r&&(e[1]=r)),e}function r(t,r,e){const o=e??new n(2);return o[0]=t[0]-r[0],o[1]=t[1]-r[1],o}function o(t,r,e,o){const c=o??new n(2);return c[0]=t[0]+e*(r[0]-t[0]),c[1]=t[1]+e*(r[1]-t[1]),c}function c(t,r,e){const o=e??new n(2);return o[0]=t[0]*r,o[1]=t[1]*r,o}function u(t,r){const e=r??new n(2);return e[0]=1/t[0],e[1]=1/t[1],e}function a(n,t){return n[0]*t[0]+n[1]*t[1]}function s(n){const t=n[0],r=n[1];return Math.sqrt(t*t+r*r)}function i(n){const t=n[0],r=n[1];return t*t+r*r}function f(n,t){const r=n[0]-t[0],e=n[1]-t[1];return Math.sqrt(r*r+e*e)}function M(n,t){const r=n[0]-t[0],e=n[1]-t[1];return r*r+e*e}function h(t,r){const e=r??new n(2),o=t[0],c=t[1],u=Math.sqrt(o*o+c*c);return u>1e-5?(e[0]=o/u,e[1]=c/u):(e[0]=0,e[1]=0),e}function l(t,r){const e=r??new n(2);return e[0]=t[0],e[1]=t[1],e}function w(t,r,e){const o=e??new n(2);return o[0]=t[0]*r[0],o[1]=t[1]*r[1],o}function m(t,r,e){const o=e??new n(2);return o[0]=t[0]/r[0],o[1]=t[1]/r[1],o}function d(t,r,e){const o=e??new n(2);return h(t,o),c(o,r,o)}return{create:t,fromValues:t,set:function(t,r,e){const o=e??new n(2);return o[0]=t,o[1]=r,o},ceil:function(t,r){const e=r??new n(2);return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e},floor:function(t,r){const e=r??new n(2);return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e},round:function(t,r){const e=r??new n(2);return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e},clamp:function(t,r=0,e=1,o){const c=o??new n(2);return c[0]=Math.min(e,Math.max(r,t[0])),c[1]=Math.min(e,Math.max(r,t[1])),c},add:function(t,r,e){const o=e??new n(2);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o},addScaled:function(t,r,e,o){const c=o??new n(2);return c[0]=t[0]+r[0]*e,c[1]=t[1]+r[1]*e,c},angle:function(n,t){const r=n[0],e=n[1],o=t[0],c=t[1],u=Math.sqrt(r*r+e*e)*Math.sqrt(o*o+c*c),s=u&&a(n,t)/u;return Math.acos(s)},subtract:r,sub:r,equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]},lerp:o,lerpV:function(t,r,e,o){const c=o??new n(2);return c[0]=t[0]+e[0]*(r[0]-t[0]),c[1]=t[1]+e[1]*(r[1]-t[1]),c},max:function(t,r,e){const o=e??new n(2);return o[0]=Math.max(t[0],r[0]),o[1]=Math.max(t[1],r[1]),o},min:function(t,r,e){const o=e??new n(2);return o[0]=Math.min(t[0],r[0]),o[1]=Math.min(t[1],r[1]),o},mulScalar:c,scale:c,divScalar:function(t,r,e){const o=e??new n(2);return o[0]=t[0]/r,o[1]=t[1]/r,o},inverse:u,invert:u,cross:function(t,r,e){const o=e??new n(3),c=t[0]*r[1]-t[1]*r[0];return o[0]=0,o[1]=0,o[2]=c,o},dot:a,length:s,len:s,lengthSq:i,lenSq:i,distance:f,dist:f,distanceSq:M,distSq:M,normalize:h,negate:function(t,r){const e=r??new n(2);return e[0]=-t[0],e[1]=-t[1],e},copy:l,clone:l,multiply:w,mul:w,divide:m,div:m,random:function(t=1,r){const e=r??new n(2),o=2*Math.random()*Math.PI;return e[0]=Math.cos(o)*t,e[1]=Math.sin(o)*t,e},zero:function(t){const r=t??new n(2);return r[0]=0,r[1]=0,r},transformMat4:function(t,r,e){const o=e??new n(2),c=t[0],u=t[1];return o[0]=c*r[0]+u*r[4]+r[12],o[1]=c*r[1]+u*r[5]+r[13],o},transformMat3:function(t,r,e){const o=e??new n(2),c=t[0],u=t[1];return o[0]=r[0]*c+r[4]*u+r[8],o[1]=r[1]*c+r[5]*u+r[9],o},rotate:function(t,r,e,o){const c=o??new n(2),u=t[0]-r[0],a=t[1]-r[1],s=Math.sin(e),i=Math.cos(e);return c[0]=u*i-a*s+r[0],c[1]=u*s+a*i+r[1],c},setLength:d,truncate:function(t,r,e){const o=e??new n(2);return s(t)>r?d(t,r,o):l(t,o)},midpoint:function(t,r,e){return o(t,r,.5,e??new n(2))}}}(n),c.set(n,t)),t}const a=new Map;function s(n){let t=a.get(n);return t||(t=function(n){function t(t,r,e){const o=new n(3);return void 0!==t&&(o[0]=t,void 0!==r&&(o[1]=r,void 0!==e&&(o[2]=e))),o}function r(t,r,e){const o=e??new n(3);return o[0]=t[0]-r[0],o[1]=t[1]-r[1],o[2]=t[2]-r[2],o}function o(t,r,e,o){const c=o??new n(3);return c[0]=t[0]+e*(r[0]-t[0]),c[1]=t[1]+e*(r[1]-t[1]),c[2]=t[2]+e*(r[2]-t[2]),c}function c(t,r,e){const o=e??new n(3);return o[0]=t[0]*r,o[1]=t[1]*r,o[2]=t[2]*r,o}function u(t,r){const e=r??new n(3);return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function a(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]}function s(n){const t=n[0],r=n[1],e=n[2];return Math.sqrt(t*t+r*r+e*e)}function i(n){const t=n[0],r=n[1],e=n[2];return t*t+r*r+e*e}function f(n,t){const r=n[0]-t[0],e=n[1]-t[1],o=n[2]-t[2];return Math.sqrt(r*r+e*e+o*o)}function M(n,t){const r=n[0]-t[0],e=n[1]-t[1],o=n[2]-t[2];return r*r+e*e+o*o}function h(t,r){const e=r??new n(3),o=t[0],c=t[1],u=t[2],a=Math.sqrt(o*o+c*c+u*u);return a>1e-5?(e[0]=o/a,e[1]=c/a,e[2]=u/a):(e[0]=0,e[1]=0,e[2]=0),e}function l(t,r){const e=r??new n(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function w(t,r,e){const o=e??new n(3);return o[0]=t[0]*r[0],o[1]=t[1]*r[1],o[2]=t[2]*r[2],o}function m(t,r,e){const o=e??new n(3);return o[0]=t[0]/r[0],o[1]=t[1]/r[1],o[2]=t[2]/r[2],o}function d(t,r,e){const o=e??new n(3);return h(t,o),c(o,r,o)}return{create:t,fromValues:t,set:function(t,r,e,o){const c=o??new n(3);return c[0]=t,c[1]=r,c[2]=e,c},ceil:function(t,r){const e=r??new n(3);return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e},floor:function(t,r){const e=r??new n(3);return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e},round:function(t,r){const e=r??new n(3);return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e},clamp:function(t,r=0,e=1,o){const c=o??new n(3);return c[0]=Math.min(e,Math.max(r,t[0])),c[1]=Math.min(e,Math.max(r,t[1])),c[2]=Math.min(e,Math.max(r,t[2])),c},add:function(t,r,e){const o=e??new n(3);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o[2]=t[2]+r[2],o},addScaled:function(t,r,e,o){const c=o??new n(3);return c[0]=t[0]+r[0]*e,c[1]=t[1]+r[1]*e,c[2]=t[2]+r[2]*e,c},angle:function(n,t){const r=n[0],e=n[1],o=n[2],c=t[0],u=t[1],s=t[2],i=Math.sqrt(r*r+e*e+o*o)*Math.sqrt(c*c+u*u+s*s),f=i&&a(n,t)/i;return Math.acos(f)},subtract:r,sub:r,equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e&&Math.abs(n[2]-t[2])<e},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]},lerp:o,lerpV:function(t,r,e,o){const c=o??new n(3);return c[0]=t[0]+e[0]*(r[0]-t[0]),c[1]=t[1]+e[1]*(r[1]-t[1]),c[2]=t[2]+e[2]*(r[2]-t[2]),c},max:function(t,r,e){const o=e??new n(3);return o[0]=Math.max(t[0],r[0]),o[1]=Math.max(t[1],r[1]),o[2]=Math.max(t[2],r[2]),o},min:function(t,r,e){const o=e??new n(3);return o[0]=Math.min(t[0],r[0]),o[1]=Math.min(t[1],r[1]),o[2]=Math.min(t[2],r[2]),o},mulScalar:c,scale:c,divScalar:function(t,r,e){const o=e??new n(3);return o[0]=t[0]/r,o[1]=t[1]/r,o[2]=t[2]/r,o},inverse:u,invert:u,cross:function(t,r,e){const o=e??new n(3),c=t[2]*r[0]-t[0]*r[2],u=t[0]*r[1]-t[1]*r[0];return o[0]=t[1]*r[2]-t[2]*r[1],o[1]=c,o[2]=u,o},dot:a,length:s,len:s,lengthSq:i,lenSq:i,distance:f,dist:f,distanceSq:M,distSq:M,normalize:h,negate:function(t,r){const e=r??new n(3);return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e},copy:l,clone:l,multiply:w,mul:w,divide:m,div:m,random:function(t=1,r){const e=r??new n(3),o=2*Math.random()*Math.PI,c=2*Math.random()-1,u=Math.sqrt(1-c*c)*t;return e[0]=Math.cos(o)*u,e[1]=Math.sin(o)*u,e[2]=c*t,e},zero:function(t){const r=t??new n(3);return r[0]=0,r[1]=0,r[2]=0,r},transformMat4:function(t,r,e){const o=e??new n(3),c=t[0],u=t[1],a=t[2],s=r[3]*c+r[7]*u+r[11]*a+r[15]||1;return o[0]=(r[0]*c+r[4]*u+r[8]*a+r[12])/s,o[1]=(r[1]*c+r[5]*u+r[9]*a+r[13])/s,o[2]=(r[2]*c+r[6]*u+r[10]*a+r[14])/s,o},transformMat4Upper3x3:function(t,r,e){const o=e??new n(3),c=t[0],u=t[1],a=t[2];return o[0]=c*r[0]+u*r[4]+a*r[8],o[1]=c*r[1]+u*r[5]+a*r[9],o[2]=c*r[2]+u*r[6]+a*r[10],o},transformMat3:function(t,r,e){const o=e??new n(3),c=t[0],u=t[1],a=t[2];return o[0]=c*r[0]+u*r[4]+a*r[8],o[1]=c*r[1]+u*r[5]+a*r[9],o[2]=c*r[2]+u*r[6]+a*r[10],o},transformQuat:function(t,r,e){const o=e??new n(3),c=r[0],u=r[1],a=r[2],s=2*r[3],i=t[0],f=t[1],M=t[2],h=u*M-a*f,l=a*i-c*M,w=c*f-u*i;return o[0]=i+h*s+2*(u*w-a*l),o[1]=f+l*s+2*(a*h-c*w),o[2]=M+w*s+2*(c*l-u*h),o},getTranslation:function(t,r){const e=r??new n(3);return e[0]=t[12],e[1]=t[13],e[2]=t[14],e},getAxis:function(t,r,e){const o=e??new n(3),c=4*r;return o[0]=t[c+0],o[1]=t[c+1],o[2]=t[c+2],o},getScaling:function(t,r){const e=r??new n(3),o=t[0],c=t[1],u=t[2],a=t[4],s=t[5],i=t[6],f=t[8],M=t[9],h=t[10];return e[0]=Math.sqrt(o*o+c*c+u*u),e[1]=Math.sqrt(a*a+s*s+i*i),e[2]=Math.sqrt(f*f+M*M+h*h),e},rotateX:function(t,r,e,o){const c=o??new n(3),u=[],a=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],a[0]=u[0],a[1]=u[1]*Math.cos(e)-u[2]*Math.sin(e),a[2]=u[1]*Math.sin(e)+u[2]*Math.cos(e),c[0]=a[0]+r[0],c[1]=a[1]+r[1],c[2]=a[2]+r[2],c},rotateY:function(t,r,e,o){const c=o??new n(3),u=[],a=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],a[0]=u[2]*Math.sin(e)+u[0]*Math.cos(e),a[1]=u[1],a[2]=u[2]*Math.cos(e)-u[0]*Math.sin(e),c[0]=a[0]+r[0],c[1]=a[1]+r[1],c[2]=a[2]+r[2],c},rotateZ:function(t,r,e,o){const c=o??new n(3),u=[],a=[];return u[0]=t[0]-r[0],u[1]=t[1]-r[1],u[2]=t[2]-r[2],a[0]=u[0]*Math.cos(e)-u[1]*Math.sin(e),a[1]=u[0]*Math.sin(e)+u[1]*Math.cos(e),a[2]=u[2],c[0]=a[0]+r[0],c[1]=a[1]+r[1],c[2]=a[2]+r[2],c},setLength:d,truncate:function(t,r,e){const o=e??new n(3);return s(t)>r?d(t,r,o):l(t,o)},midpoint:function(t,r,e){return o(t,r,.5,e??new n(3))}}}(n),a.set(n,t)),t}const i=new Map;function f(n){let t=i.get(n);return t||(t=function(n){const t=u(n),r=s(n);function o(t,r,e){const o=e??new n(12);return o[0]=t[0]*r,o[1]=t[1]*r,o[2]=t[2]*r,o[4]=t[4]*r,o[5]=t[5]*r,o[6]=t[6]*r,o[8]=t[8]*r,o[9]=t[9]*r,o[10]=t[10]*r,o}function c(t,r){const e=r??new n(12);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[8]=t[8],e[9]=t[9],e[10]=t[10],e}function a(t){const r=t??new n(12);return r[0]=1,r[1]=0,r[2]=0,r[4]=0,r[5]=1,r[6]=0,r[8]=0,r[9]=0,r[10]=1,r}function i(t,r){const e=r??new n(12),o=t[0],c=t[1],u=t[2],a=t[4],s=t[5],i=t[6],f=t[8],M=t[9],h=t[10],l=h*s-i*M,w=-h*a+i*f,m=M*a-s*f,d=1/(o*l+c*w+u*m);return e[0]=l*d,e[1]=(-h*c+u*M)*d,e[2]=(i*c-u*s)*d,e[4]=w*d,e[5]=(h*o-u*f)*d,e[6]=(-i*o+u*a)*d,e[8]=m*d,e[9]=(-M*o+c*f)*d,e[10]=(s*o-c*a)*d,e}function f(t,r,e){const o=e??new n(12),c=t[0],u=t[1],a=t[2],s=t[4],i=t[5],f=t[6],M=t[8],h=t[9],l=t[10],w=r[0],m=r[1],d=r[2],v=r[4],q=r[5],p=r[6],b=r[8],g=r[9],y=r[10];return o[0]=c*w+s*m+M*d,o[1]=u*w+i*m+h*d,o[2]=a*w+f*m+l*d,o[4]=c*v+s*q+M*p,o[5]=u*v+i*q+h*p,o[6]=a*v+f*q+l*p,o[8]=c*b+s*g+M*y,o[9]=u*b+i*g+h*y,o[10]=a*b+f*g+l*y,o}function M(t,r){const e=r??new n(12),o=Math.cos(t),c=Math.sin(t);return e[0]=o,e[1]=c,e[2]=0,e[4]=-c,e[5]=o,e[6]=0,e[8]=0,e[9]=0,e[10]=1,e}function h(t,r,e){const o=e??new n(12),c=t[0],u=t[1],a=t[2],s=t[4],i=t[5],f=t[6],M=Math.cos(r),h=Math.sin(r);return o[0]=M*c+h*s,o[1]=M*u+h*i,o[2]=M*a+h*f,o[4]=M*s-h*c,o[5]=M*i-h*u,o[6]=M*f-h*a,t!==o&&(o[8]=t[8],o[9]=t[9],o[10]=t[10]),o}return{add:function(t,r,e){const o=e??new n(12);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o[2]=t[2]+r[2],o[4]=t[4]+r[4],o[5]=t[5]+r[5],o[6]=t[6]+r[6],o[8]=t[8]+r[8],o[9]=t[9]+r[9],o[10]=t[10]+r[10],o},clone:c,copy:c,create:function(t,r,e,o,c,u,a,s,i){const f=new n(12);return f[3]=0,f[7]=0,f[11]=0,void 0!==t&&(f[0]=t,void 0!==r&&(f[1]=r,void 0!==e&&(f[2]=e,void 0!==o&&(f[4]=o,void 0!==c&&(f[5]=c,void 0!==u&&(f[6]=u,void 0!==a&&(f[8]=a,void 0!==s&&(f[9]=s,void 0!==i&&(f[10]=i))))))))),f},determinant:function(n){const t=n[0],r=n[1],e=n[2],o=n[4],c=n[5],u=n[6],a=n[8],s=n[9],i=n[10];return t*(c*i-s*u)-o*(r*i-s*e)+a*(r*u-c*e)},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]&&n[4]===t[4]&&n[5]===t[5]&&n[6]===t[6]&&n[8]===t[8]&&n[9]===t[9]&&n[10]===t[10]},equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e&&Math.abs(n[2]-t[2])<e&&Math.abs(n[4]-t[4])<e&&Math.abs(n[5]-t[5])<e&&Math.abs(n[6]-t[6])<e&&Math.abs(n[8]-t[8])<e&&Math.abs(n[9]-t[9])<e&&Math.abs(n[10]-t[10])<e},fromMat4:function(t,r){const e=r??new n(12);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=0,e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=0,e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=0,e},fromQuat:function(t,r){const e=r??new n(12),o=t[0],c=t[1],u=t[2],a=t[3],s=o+o,i=c+c,f=u+u,M=o*s,h=c*s,l=c*i,w=u*s,m=u*i,d=u*f,v=a*s,q=a*i,p=a*f;return e[0]=1-l-d,e[1]=h+p,e[2]=w-q,e[3]=0,e[4]=h-p,e[5]=1-M-d,e[6]=m+v,e[7]=0,e[8]=w+q,e[9]=m-v,e[10]=1-M-l,e[11]=0,e},get3DScaling:function(n,t){const e=t??r.create(),o=n[0],c=n[1],u=n[2],a=n[4],s=n[5],i=n[6],f=n[8],M=n[9],h=n[10];return e[0]=Math.sqrt(o*o+c*c+u*u),e[1]=Math.sqrt(a*a+s*s+i*i),e[2]=Math.sqrt(f*f+M*M+h*h),e},getAxis:function(n,r,e){const o=e??t.create(),c=4*r;return o[0]=n[c+0],o[1]=n[c+1],o},getScaling:function(n,r){const e=r??t.create(),o=n[0],c=n[1],u=n[4],a=n[5];return e[0]=Math.sqrt(o*o+c*c),e[1]=Math.sqrt(u*u+a*a),e},getTranslation:function(n,r){const e=r??t.create();return e[0]=n[8],e[1]=n[9],e},identity:a,inverse:i,invert:i,mul:f,mulScalar:o,multiply:f,multiplyScalar:o,negate:function(t,r){const e=r??new n(12);return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[4]=-t[4],e[5]=-t[5],e[6]=-t[6],e[8]=-t[8],e[9]=-t[9],e[10]=-t[10],e},rotate:h,rotateX:function(t,r,e){const o=e??new n(12),c=t[4],u=t[5],a=t[6],s=t[8],i=t[9],f=t[10],M=Math.cos(r),h=Math.sin(r);return o[4]=M*c+h*s,o[5]=M*u+h*i,o[6]=M*a+h*f,o[8]=M*s-h*c,o[9]=M*i-h*u,o[10]=M*f-h*a,t!==o&&(o[0]=t[0],o[1]=t[1],o[2]=t[2]),o},rotateY:function(t,r,e){const o=e??new n(12),c=t[0],u=t[1],a=t[2],s=t[8],i=t[9],f=t[10],M=Math.cos(r),h=Math.sin(r);return o[0]=M*c-h*s,o[1]=M*u-h*i,o[2]=M*a-h*f,o[8]=M*s+h*c,o[9]=M*i+h*u,o[10]=M*f+h*a,t!==o&&(o[4]=t[4],o[5]=t[5],o[6]=t[6]),o},rotateZ:h,rotation:M,rotationX:function(t,r){const e=r??new n(12),o=Math.cos(t),c=Math.sin(t);return e[0]=1,e[1]=0,e[2]=0,e[4]=0,e[5]=o,e[6]=c,e[8]=0,e[9]=-c,e[10]=o,e},rotationY:function(t,r){const e=r??new n(12),o=Math.cos(t),c=Math.sin(t);return e[0]=o,e[1]=0,e[2]=-c,e[4]=0,e[5]=1,e[6]=0,e[8]=c,e[9]=0,e[10]=o,e},rotationZ:M,scale:function(t,r,e){const o=e??new n(12),c=r[0],u=r[1];return o[0]=c*t[0],o[1]=c*t[1],o[2]=c*t[2],o[4]=u*t[4],o[5]=u*t[5],o[6]=u*t[6],t!==o&&(o[8]=t[8],o[9]=t[9],o[10]=t[10]),o},scale3D:function(t,r,e){const o=e??new n(12),c=r[0],u=r[1],a=r[2];return o[0]=c*t[0],o[1]=c*t[1],o[2]=c*t[2],o[4]=u*t[4],o[5]=u*t[5],o[6]=u*t[6],o[8]=a*t[8],o[9]=a*t[9],o[10]=a*t[10],o},scaling:function(t,r){const e=r??new n(12);return e[0]=t[0],e[1]=0,e[2]=0,e[4]=0,e[5]=t[1],e[6]=0,e[8]=0,e[9]=0,e[10]=1,e},scaling3D:function(t,r){const e=r??new n(12);return e[0]=t[0],e[1]=0,e[2]=0,e[4]=0,e[5]=t[1],e[6]=0,e[8]=0,e[9]=0,e[10]=t[2],e},set:function(t,r,e,o,c,u,a,s,i,f){const M=f??new n(12);return M[0]=t,M[1]=r,M[2]=e,M[3]=0,M[4]=o,M[5]=c,M[6]=u,M[7]=0,M[8]=a,M[9]=s,M[10]=i,M[11]=0,M},setAxis:function(n,t,r,e){const o=e===n?n:c(n,e),u=4*r;return o[u+0]=t[0],o[u+1]=t[1],o},setTranslation:function(n,t,r){const e=r??a();return n!==e&&(e[0]=n[0],e[1]=n[1],e[2]=n[2],e[4]=n[4],e[5]=n[5],e[6]=n[6]),e[8]=t[0],e[9]=t[1],e[10]=1,e},translate:function(t,r,e){const o=e??new n(12),c=r[0],u=r[1],a=t[0],s=t[1],i=t[2],f=t[4],M=t[5],h=t[6],l=t[8],w=t[9],m=t[10];return t!==o&&(o[0]=a,o[1]=s,o[2]=i,o[4]=f,o[5]=M,o[6]=h),o[8]=a*c+f*u+l,o[9]=s*c+M*u+w,o[10]=i*c+h*u+m,o},translation:function(t,r){const e=r??new n(12);return e[0]=1,e[1]=0,e[2]=0,e[4]=0,e[5]=1,e[6]=0,e[8]=t[0],e[9]=t[1],e[10]=1,e},transpose:function(t,r){const e=r??new n(12);if(e===t){let n;return n=t[1],t[1]=t[4],t[4]=n,n=t[2],t[2]=t[8],t[8]=n,n=t[6],t[6]=t[9],t[9]=n,e}const o=t[0],c=t[1],u=t[2],a=t[4],s=t[5],i=t[6],f=t[8],M=t[9],h=t[10];return e[0]=o,e[1]=a,e[2]=f,e[4]=c,e[5]=s,e[6]=M,e[8]=u,e[9]=i,e[10]=h,e},uniformScale:function(t,r,e){const o=e??new n(12);return o[0]=r*t[0],o[1]=r*t[1],o[2]=r*t[2],o[4]=r*t[4],o[5]=r*t[5],o[6]=r*t[6],t!==o&&(o[8]=t[8],o[9]=t[9],o[10]=t[10]),o},uniformScale3D:function(t,r,e){const o=e??new n(12);return o[0]=r*t[0],o[1]=r*t[1],o[2]=r*t[2],o[4]=r*t[4],o[5]=r*t[5],o[6]=r*t[6],o[8]=r*t[8],o[9]=r*t[9],o[10]=r*t[10],o},uniformScaling:function(t,r){const e=r??new n(12);return e[0]=t,e[1]=0,e[2]=0,e[4]=0,e[5]=t,e[6]=0,e[8]=0,e[9]=0,e[10]=1,e},uniformScaling3D:function(t,r){const e=r??new n(12);return e[0]=t,e[1]=0,e[2]=0,e[4]=0,e[5]=t,e[6]=0,e[8]=0,e[9]=0,e[10]=t,e}}}(n),i.set(n,t)),t}const M=new Map;function h(n){let t=M.get(n);return t||(t=function(n){const t=s(n);function r(t,r,e){const o=e??new n(16);return o[0]=t[0]*r,o[1]=t[1]*r,o[2]=t[2]*r,o[3]=t[3]*r,o[4]=t[4]*r,o[5]=t[5]*r,o[6]=t[6]*r,o[7]=t[7]*r,o[8]=t[8]*r,o[9]=t[9]*r,o[10]=t[10]*r,o[11]=t[11]*r,o[12]=t[12]*r,o[13]=t[13]*r,o[14]=t[14]*r,o[15]=t[15]*r,o}const o=r;function c(t,r){const e=r??new n(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}const u=c;function a(t){const r=t??new n(16);return r[0]=1,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=1,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=1,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,r}function i(t,r){const e=r??new n(16),o=t[0],c=t[1],u=t[2],a=t[3],s=t[4],i=t[5],f=t[6],M=t[7],h=t[8],l=t[9],w=t[10],m=t[11],d=t[12],v=t[13],q=t[14],p=t[15],b=w*p,g=q*m,y=f*p,x=q*M,S=f*m,A=w*M,z=u*p,F=q*a,k=u*m,T=w*a,Z=u*M,I=f*a,P=h*v,V=d*l,D=s*v,X=d*i,Y=s*l,L=h*i,R=o*v,E=d*c,_=o*l,Q=h*c,N=o*i,U=s*c,j=b*i+x*l+S*v-(g*i+y*l+A*v),O=g*c+z*l+T*v-(b*c+F*l+k*v),$=y*c+F*i+Z*v-(x*c+z*i+I*v),B=A*c+k*i+I*l-(S*c+T*i+Z*l),C=1/(o*j+s*O+h*$+d*B);return e[0]=C*j,e[1]=C*O,e[2]=C*$,e[3]=C*B,e[4]=C*(g*s+y*h+A*d-(b*s+x*h+S*d)),e[5]=C*(b*o+F*h+k*d-(g*o+z*h+T*d)),e[6]=C*(x*o+z*s+I*d-(y*o+F*s+Z*d)),e[7]=C*(S*o+T*s+Z*h-(A*o+k*s+I*h)),e[8]=C*(P*M+X*m+Y*p-(V*M+D*m+L*p)),e[9]=C*(V*a+R*m+Q*p-(P*a+E*m+_*p)),e[10]=C*(D*a+E*M+N*p-(X*a+R*M+U*p)),e[11]=C*(L*a+_*M+U*m-(Y*a+Q*M+N*m)),e[12]=C*(D*w+L*q+V*f-(Y*q+P*f+X*w)),e[13]=C*(_*q+P*u+E*w-(R*w+Q*q+V*u)),e[14]=C*(R*f+U*q+X*u-(N*q+D*u+E*f)),e[15]=C*(N*w+Y*u+Q*f-(_*f+U*w+L*u)),e}const f=i;function M(t,r,e){const o=e??new n(16),c=t[0],u=t[1],a=t[2],s=t[3],i=t[4],f=t[5],M=t[6],h=t[7],l=t[8],w=t[9],m=t[10],d=t[11],v=t[12],q=t[13],p=t[14],b=t[15],g=r[0],y=r[1],x=r[2],S=r[3],A=r[4],z=r[5],F=r[6],k=r[7],T=r[8],Z=r[9],I=r[10],P=r[11],V=r[12],D=r[13],X=r[14],Y=r[15];return o[0]=c*g+i*y+l*x+v*S,o[1]=u*g+f*y+w*x+q*S,o[2]=a*g+M*y+m*x+p*S,o[3]=s*g+h*y+d*x+b*S,o[4]=c*A+i*z+l*F+v*k,o[5]=u*A+f*z+w*F+q*k,o[6]=a*A+M*z+m*F+p*k,o[7]=s*A+h*z+d*F+b*k,o[8]=c*T+i*Z+l*I+v*P,o[9]=u*T+f*Z+w*I+q*P,o[10]=a*T+M*Z+m*I+p*P,o[11]=s*T+h*Z+d*I+b*P,o[12]=c*V+i*D+l*X+v*Y,o[13]=u*V+f*D+w*X+q*Y,o[14]=a*V+M*D+m*X+p*Y,o[15]=s*V+h*D+d*X+b*Y,o}const h=M,l=t.create(),w=t.create(),m=t.create();function d(t,r,e){const o=e??new n(16);let c=t[0],u=t[1],a=t[2];const s=Math.sqrt(c*c+u*u+a*a);c/=s,u/=s,a/=s;const i=c*c,f=u*u,M=a*a,h=Math.cos(r),l=Math.sin(r),w=1-h;return o[0]=i+(1-i)*h,o[1]=c*u*w+a*l,o[2]=c*a*w-u*l,o[3]=0,o[4]=c*u*w-a*l,o[5]=f+(1-f)*h,o[6]=u*a*w+c*l,o[7]=0,o[8]=c*a*w+u*l,o[9]=u*a*w-c*l,o[10]=M+(1-M)*h,o[11]=0,o[12]=0,o[13]=0,o[14]=0,o[15]=1,o}function v(t,r,e,o){const c=o??new n(16);let u=r[0],a=r[1],s=r[2];const i=Math.sqrt(u*u+a*a+s*s);u/=i,a/=i,s/=i;const f=u*u,M=a*a,h=s*s,l=Math.cos(e),w=Math.sin(e),m=1-l,d=f+(1-f)*l,v=u*a*m+s*w,q=u*s*m-a*w,p=u*a*m-s*w,b=M+(1-M)*l,g=a*s*m+u*w,y=u*s*m+a*w,x=a*s*m-u*w,S=h+(1-h)*l,A=t[0],z=t[1],F=t[2],k=t[3],T=t[4],Z=t[5],I=t[6],P=t[7],V=t[8],D=t[9],X=t[10],Y=t[11];return c[0]=d*A+v*T+q*V,c[1]=d*z+v*Z+q*D,c[2]=d*F+v*I+q*X,c[3]=d*k+v*P+q*Y,c[4]=p*A+b*T+g*V,c[5]=p*z+b*Z+g*D,c[6]=p*F+b*I+g*X,c[7]=p*k+b*P+g*Y,c[8]=y*A+x*T+S*V,c[9]=y*z+x*Z+S*D,c[10]=y*F+x*I+S*X,c[11]=y*k+x*P+S*Y,t!==c&&(c[12]=t[12],c[13]=t[13],c[14]=t[14],c[15]=t[15]),c}return{add:function(t,r,e){const o=e??new n(16);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o[2]=t[2]+r[2],o[3]=t[3]+r[3],o[4]=t[4]+r[4],o[5]=t[5]+r[5],o[6]=t[6]+r[6],o[7]=t[7]+r[7],o[8]=t[8]+r[8],o[9]=t[9]+r[9],o[10]=t[10]+r[10],o[11]=t[11]+r[11],o[12]=t[12]+r[12],o[13]=t[13]+r[13],o[14]=t[14]+r[14],o[15]=t[15]+r[15],o},aim:function(r,e,o,c){const u=c??new n(16);return t.normalize(t.subtract(e,r,m),m),t.normalize(t.cross(o,m,l),l),t.normalize(t.cross(m,l,w),w),u[0]=l[0],u[1]=l[1],u[2]=l[2],u[3]=0,u[4]=w[0],u[5]=w[1],u[6]=w[2],u[7]=0,u[8]=m[0],u[9]=m[1],u[10]=m[2],u[11]=0,u[12]=r[0],u[13]=r[1],u[14]=r[2],u[15]=1,u},axisRotate:v,axisRotation:d,cameraAim:function(r,e,o,c){const u=c??new n(16);return t.normalize(t.subtract(r,e,m),m),t.normalize(t.cross(o,m,l),l),t.normalize(t.cross(m,l,w),w),u[0]=l[0],u[1]=l[1],u[2]=l[2],u[3]=0,u[4]=w[0],u[5]=w[1],u[6]=w[2],u[7]=0,u[8]=m[0],u[9]=m[1],u[10]=m[2],u[11]=0,u[12]=r[0],u[13]=r[1],u[14]=r[2],u[15]=1,u},clone:u,copy:c,create:function(t,r,e,o,c,u,a,s,i,f,M,h,l,w,m,d){const v=new n(16);return void 0!==t&&(v[0]=t,void 0!==r&&(v[1]=r,void 0!==e&&(v[2]=e,void 0!==o&&(v[3]=o,void 0!==c&&(v[4]=c,void 0!==u&&(v[5]=u,void 0!==a&&(v[6]=a,void 0!==s&&(v[7]=s,void 0!==i&&(v[8]=i,void 0!==f&&(v[9]=f,void 0!==M&&(v[10]=M,void 0!==h&&(v[11]=h,void 0!==l&&(v[12]=l,void 0!==w&&(v[13]=w,void 0!==m&&(v[14]=m,void 0!==d&&(v[15]=d)))))))))))))))),v},determinant:function(n){const t=n[0],r=n[1],e=n[2],o=n[3],c=n[4],u=n[5],a=n[6],s=n[7],i=n[8],f=n[9],M=n[10],h=n[11],l=n[12],w=n[13],m=n[14],d=n[15],v=M*d,q=m*h,p=a*d,b=m*s,g=a*h,y=M*s,x=e*d,S=m*o,A=e*h,z=M*o,F=e*s,k=a*o;return t*(v*u+b*f+g*w-(q*u+p*f+y*w))+c*(q*r+x*f+z*w-(v*r+S*f+A*w))+i*(p*r+S*u+F*w-(b*r+x*u+k*w))+l*(y*r+A*u+k*f-(g*r+z*u+F*f))},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]&&n[3]===t[3]&&n[4]===t[4]&&n[5]===t[5]&&n[6]===t[6]&&n[7]===t[7]&&n[8]===t[8]&&n[9]===t[9]&&n[10]===t[10]&&n[11]===t[11]&&n[12]===t[12]&&n[13]===t[13]&&n[14]===t[14]&&n[15]===t[15]},equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e&&Math.abs(n[2]-t[2])<e&&Math.abs(n[3]-t[3])<e&&Math.abs(n[4]-t[4])<e&&Math.abs(n[5]-t[5])<e&&Math.abs(n[6]-t[6])<e&&Math.abs(n[7]-t[7])<e&&Math.abs(n[8]-t[8])<e&&Math.abs(n[9]-t[9])<e&&Math.abs(n[10]-t[10])<e&&Math.abs(n[11]-t[11])<e&&Math.abs(n[12]-t[12])<e&&Math.abs(n[13]-t[13])<e&&Math.abs(n[14]-t[14])<e&&Math.abs(n[15]-t[15])<e},fromMat3:function(t,r){const e=r??new n(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=0,e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=0,e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},fromQuat:function(t,r){const e=r??new n(16),o=t[0],c=t[1],u=t[2],a=t[3],s=o+o,i=c+c,f=u+u,M=o*s,h=c*s,l=c*i,w=u*s,m=u*i,d=u*f,v=a*s,q=a*i,p=a*f;return e[0]=1-l-d,e[1]=h+p,e[2]=w-q,e[3]=0,e[4]=h-p,e[5]=1-M-d,e[6]=m+v,e[7]=0,e[8]=w+q,e[9]=m-v,e[10]=1-M-l,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},frustum:function(t,r,e,o,c,u,a){const s=a??new n(16),i=r-t,f=o-e,M=c-u;return s[0]=2*c/i,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*c/f,s[6]=0,s[7]=0,s[8]=(t+r)/i,s[9]=(o+e)/f,s[10]=u/M,s[11]=-1,s[12]=0,s[13]=0,s[14]=c*u/M,s[15]=0,s},frustumReverseZ:function(t,r,e,o,c,u=1/0,a){const s=a??new n(16),i=r-t,f=o-e;if(s[0]=2*c/i,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*c/f,s[6]=0,s[7]=0,s[8]=(t+r)/i,s[9]=(o+e)/f,s[11]=-1,s[12]=0,s[13]=0,s[15]=0,u===1/0)s[10]=0,s[14]=c;else{const n=1/(u-c);s[10]=c*n,s[14]=u*c*n}return s},getAxis:function(n,r,e){const o=e??t.create(),c=4*r;return o[0]=n[c+0],o[1]=n[c+1],o[2]=n[c+2],o},getScaling:function(n,r){const e=r??t.create(),o=n[0],c=n[1],u=n[2],a=n[4],s=n[5],i=n[6],f=n[8],M=n[9],h=n[10];return e[0]=Math.sqrt(o*o+c*c+u*u),e[1]=Math.sqrt(a*a+s*s+i*i),e[2]=Math.sqrt(f*f+M*M+h*h),e},getTranslation:function(n,r){const e=r??t.create();return e[0]=n[12],e[1]=n[13],e[2]=n[14],e},identity:a,inverse:i,invert:f,lookAt:function(r,e,o,c){const u=c??new n(16);return t.normalize(t.subtract(r,e,m),m),t.normalize(t.cross(o,m,l),l),t.normalize(t.cross(m,l,w),w),u[0]=l[0],u[1]=w[0],u[2]=m[0],u[3]=0,u[4]=l[1],u[5]=w[1],u[6]=m[1],u[7]=0,u[8]=l[2],u[9]=w[2],u[10]=m[2],u[11]=0,u[12]=-(l[0]*r[0]+l[1]*r[1]+l[2]*r[2]),u[13]=-(w[0]*r[0]+w[1]*r[1]+w[2]*r[2]),u[14]=-(m[0]*r[0]+m[1]*r[1]+m[2]*r[2]),u[15]=1,u},mul:h,mulScalar:o,multiply:M,multiplyScalar:r,negate:function(t,r){const e=r??new n(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},ortho:function(t,r,e,o,c,u,a){const s=a??new n(16);return s[0]=2/(r-t),s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/(o-e),s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1/(c-u),s[11]=0,s[12]=(r+t)/(t-r),s[13]=(o+e)/(e-o),s[14]=c/(c-u),s[15]=1,s},perspective:function(t,r,e,o,c){const u=c??new n(16),a=Math.tan(.5*Math.PI-.5*t);if(u[0]=a/r,u[1]=0,u[2]=0,u[3]=0,u[4]=0,u[5]=a,u[6]=0,u[7]=0,u[8]=0,u[9]=0,u[11]=-1,u[12]=0,u[13]=0,u[15]=0,Number.isFinite(o)){const n=1/(e-o);u[10]=o*n,u[14]=o*e*n}else u[10]=-1,u[14]=-e;return u},perspectiveReverseZ:function(t,r,e,o=1/0,c){const u=c??new n(16),a=1/Math.tan(.5*t);if(u[0]=a/r,u[1]=0,u[2]=0,u[3]=0,u[4]=0,u[5]=a,u[6]=0,u[7]=0,u[8]=0,u[9]=0,u[11]=-1,u[12]=0,u[13]=0,u[15]=0,o===1/0)u[10]=0,u[14]=e;else{const n=1/(o-e);u[10]=e*n,u[14]=o*e*n}return u},rotate:v,rotateX:function(t,r,e){const o=e??new n(16),c=t[4],u=t[5],a=t[6],s=t[7],i=t[8],f=t[9],M=t[10],h=t[11],l=Math.cos(r),w=Math.sin(r);return o[4]=l*c+w*i,o[5]=l*u+w*f,o[6]=l*a+w*M,o[7]=l*s+w*h,o[8]=l*i-w*c,o[9]=l*f-w*u,o[10]=l*M-w*a,o[11]=l*h-w*s,t!==o&&(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15]),o},rotateY:function(t,r,e){const o=e??new n(16),c=t[0],u=t[1],a=t[2],s=t[3],i=t[8],f=t[9],M=t[10],h=t[11],l=Math.cos(r),w=Math.sin(r);return o[0]=l*c-w*i,o[1]=l*u-w*f,o[2]=l*a-w*M,o[3]=l*s-w*h,o[8]=l*i+w*c,o[9]=l*f+w*u,o[10]=l*M+w*a,o[11]=l*h+w*s,t!==o&&(o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15]),o},rotateZ:function(t,r,e){const o=e??new n(16),c=t[0],u=t[1],a=t[2],s=t[3],i=t[4],f=t[5],M=t[6],h=t[7],l=Math.cos(r),w=Math.sin(r);return o[0]=l*c+w*i,o[1]=l*u+w*f,o[2]=l*a+w*M,o[3]=l*s+w*h,o[4]=l*i-w*c,o[5]=l*f-w*u,o[6]=l*M-w*a,o[7]=l*h-w*s,t!==o&&(o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15]),o},rotation:d,rotationX:function(t,r){const e=r??new n(16),o=Math.cos(t),c=Math.sin(t);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=c,e[7]=0,e[8]=0,e[9]=-c,e[10]=o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},rotationY:function(t,r){const e=r??new n(16),o=Math.cos(t),c=Math.sin(t);return e[0]=o,e[1]=0,e[2]=-c,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=c,e[9]=0,e[10]=o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},rotationZ:function(t,r){const e=r??new n(16),o=Math.cos(t),c=Math.sin(t);return e[0]=o,e[1]=c,e[2]=0,e[3]=0,e[4]=-c,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},scale:function(t,r,e){const o=e??new n(16),c=r[0],u=r[1],a=r[2];return o[0]=c*t[0],o[1]=c*t[1],o[2]=c*t[2],o[3]=c*t[3],o[4]=u*t[4],o[5]=u*t[5],o[6]=u*t[6],o[7]=u*t[7],o[8]=a*t[8],o[9]=a*t[9],o[10]=a*t[10],o[11]=a*t[11],t!==o&&(o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15]),o},scaling:function(t,r){const e=r??new n(16);return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},set:function(t,r,e,o,c,u,a,s,i,f,M,h,l,w,m,d,v){const q=v??new n(16);return q[0]=t,q[1]=r,q[2]=e,q[3]=o,q[4]=c,q[5]=u,q[6]=a,q[7]=s,q[8]=i,q[9]=f,q[10]=M,q[11]=h,q[12]=l,q[13]=w,q[14]=m,q[15]=d,q},setAxis:function(n,t,r,e){const o=e===n?e:c(n,e),u=4*r;return o[u+0]=t[0],o[u+1]=t[1],o[u+2]=t[2],o},setTranslation:function(n,t,r){const e=r??a();return n!==e&&(e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11]),e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e},translate:function(t,r,e){const o=e??new n(16),c=r[0],u=r[1],a=r[2],s=t[0],i=t[1],f=t[2],M=t[3],h=t[4],l=t[5],w=t[6],m=t[7],d=t[8],v=t[9],q=t[10],p=t[11],b=t[12],g=t[13],y=t[14],x=t[15];return t!==o&&(o[0]=s,o[1]=i,o[2]=f,o[3]=M,o[4]=h,o[5]=l,o[6]=w,o[7]=m,o[8]=d,o[9]=v,o[10]=q,o[11]=p),o[12]=s*c+h*u+d*a+b,o[13]=i*c+l*u+v*a+g,o[14]=f*c+w*u+q*a+y,o[15]=M*c+m*u+p*a+x,o},translation:function(t,r){const e=r??new n(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e},transpose:function(t,r){const e=r??new n(16);if(e===t){let n;return n=t[1],t[1]=t[4],t[4]=n,n=t[2],t[2]=t[8],t[8]=n,n=t[3],t[3]=t[12],t[12]=n,n=t[6],t[6]=t[9],t[9]=n,n=t[7],t[7]=t[13],t[13]=n,n=t[11],t[11]=t[14],t[14]=n,e}const o=t[0],c=t[1],u=t[2],a=t[3],s=t[4],i=t[5],f=t[6],M=t[7],h=t[8],l=t[9],w=t[10],m=t[11],d=t[12],v=t[13],q=t[14],p=t[15];return e[0]=o,e[1]=s,e[2]=h,e[3]=d,e[4]=c,e[5]=i,e[6]=l,e[7]=v,e[8]=u,e[9]=f,e[10]=w,e[11]=q,e[12]=a,e[13]=M,e[14]=m,e[15]=p,e},uniformScale:function(t,r,e){const o=e??new n(16);return o[0]=r*t[0],o[1]=r*t[1],o[2]=r*t[2],o[3]=r*t[3],o[4]=r*t[4],o[5]=r*t[5],o[6]=r*t[6],o[7]=r*t[7],o[8]=r*t[8],o[9]=r*t[9],o[10]=r*t[10],o[11]=r*t[11],t!==o&&(o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15]),o},uniformScaling:function(t,r){const e=r??new n(16);return e[0]=t,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}}}(n),M.set(n,t)),t}const l=new Map;function w(n){let t=l.get(n);return t||(t=function(n){const t=s(n);function r(t,r,e,o){const c=new n(4);return void 0!==t&&(c[0]=t,void 0!==r&&(c[1]=r,void 0!==e&&(c[2]=e,void 0!==o&&(c[3]=o)))),c}const o=r;function c(t,r,e){const o=e??new n(4),c=.5*r,u=Math.sin(c);return o[0]=u*t[0],o[1]=u*t[1],o[2]=u*t[2],o[3]=Math.cos(c),o}function u(t,r,e){const o=e??new n(4),c=t[0],u=t[1],a=t[2],s=t[3],i=r[0],f=r[1],M=r[2],h=r[3];return o[0]=c*h+s*i+u*M-a*f,o[1]=u*h+s*f+a*i-c*M,o[2]=a*h+s*M+c*f-u*i,o[3]=s*h-c*i-u*f-a*M,o}const a=u;function i(t,r,o,c){const u=c??new n(4),a=t[0],s=t[1],i=t[2],f=t[3];let M,h,l=r[0],w=r[1],m=r[2],d=r[3],v=a*l+s*w+i*m+f*d;if(v<0&&(v=-v,l=-l,w=-w,m=-m,d=-d),1-v>e){const n=Math.acos(v),t=Math.sin(n);M=Math.sin((1-o)*n)/t,h=Math.sin(o*n)/t}else M=1-o,h=o;return u[0]=M*a+h*l,u[1]=M*s+h*w,u[2]=M*i+h*m,u[3]=M*f+h*d,u}function f(t,r){const e=r??new n(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}const M=f;function h(t,r,e){const o=e??new n(4);return o[0]=t[0]-r[0],o[1]=t[1]-r[1],o[2]=t[2]-r[2],o[3]=t[3]-r[3],o}const l=h;function w(t,r,e){const o=e??new n(4);return o[0]=t[0]*r,o[1]=t[1]*r,o[2]=t[2]*r,o[3]=t[3]*r,o}const m=w;function d(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]+n[3]*t[3]}function v(n){const t=n[0],r=n[1],e=n[2],o=n[3];return Math.sqrt(t*t+r*r+e*e+o*o)}const q=v;function p(n){const t=n[0],r=n[1],e=n[2],o=n[3];return t*t+r*r+e*e+o*o}const b=p;function g(t,r){const e=r??new n(4),o=t[0],c=t[1],u=t[2],a=t[3],s=Math.sqrt(o*o+c*c+u*u+a*a);return s>1e-5?(e[0]=o/s,e[1]=c/s,e[2]=u/s,e[3]=a/s):(e[0]=0,e[1]=0,e[2]=0,e[3]=1),e}const y=t.create(),x=t.create(),S=t.create(),A=new n(4),z=new n(4);return{create:r,fromValues:o,set:function(t,r,e,o,c){const u=c??new n(4);return u[0]=t,u[1]=r,u[2]=e,u[3]=o,u},fromAxisAngle:c,toAxisAngle:function(n,r){const o=r??t.create(3),c=2*Math.acos(n[3]),u=Math.sin(.5*c);return u>e?(o[0]=n[0]/u,o[1]=n[1]/u,o[2]=n[2]/u):(o[0]=1,o[1]=0,o[2]=0),{angle:c,axis:o}},angle:function(n,t){const r=d(n,t);return Math.acos(2*r*r-1)},multiply:u,mul:a,rotateX:function(t,r,e){const o=e??new n(4),c=.5*r,u=t[0],a=t[1],s=t[2],i=t[3],f=Math.sin(c),M=Math.cos(c);return o[0]=u*M+i*f,o[1]=a*M+s*f,o[2]=s*M-a*f,o[3]=i*M-u*f,o},rotateY:function(t,r,e){const o=e??new n(4),c=.5*r,u=t[0],a=t[1],s=t[2],i=t[3],f=Math.sin(c),M=Math.cos(c);return o[0]=u*M-s*f,o[1]=a*M+i*f,o[2]=s*M+u*f,o[3]=i*M-a*f,o},rotateZ:function(t,r,e){const o=e??new n(4),c=.5*r,u=t[0],a=t[1],s=t[2],i=t[3],f=Math.sin(c),M=Math.cos(c);return o[0]=u*M+a*f,o[1]=a*M-u*f,o[2]=s*M+i*f,o[3]=i*M-s*f,o},slerp:i,inverse:function(t,r){const e=r??new n(4),o=t[0],c=t[1],u=t[2],a=t[3],s=o*o+c*c+u*u+a*a,i=s?1/s:0;return e[0]=-o*i,e[1]=-c*i,e[2]=-u*i,e[3]=a*i,e},conjugate:function(t,r){const e=r??new n(4);return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},fromMat:function(t,r){const e=r??new n(4),o=t[0]+t[5]+t[10];if(o>0){const n=Math.sqrt(o+1);e[3]=.5*n;const r=.5/n;e[0]=(t[6]-t[9])*r,e[1]=(t[8]-t[2])*r,e[2]=(t[1]-t[4])*r}else{let n=0;t[5]>t[0]&&(n=1),t[10]>t[4*n+n]&&(n=2);const r=(n+1)%3,o=(n+2)%3,c=Math.sqrt(t[4*n+n]-t[4*r+r]-t[4*o+o]+1);e[n]=.5*c;const u=.5/c;e[3]=(t[4*r+o]-t[4*o+r])*u,e[r]=(t[4*r+n]+t[4*n+r])*u,e[o]=(t[4*o+n]+t[4*n+o])*u}return e},fromEuler:function(t,r,e,o,c){const u=c??new n(4),a=.5*t,s=.5*r,i=.5*e,f=Math.sin(a),M=Math.cos(a),h=Math.sin(s),l=Math.cos(s),w=Math.sin(i),m=Math.cos(i);switch(o){case"xyz":u[0]=f*l*m+M*h*w,u[1]=M*h*m-f*l*w,u[2]=M*l*w+f*h*m,u[3]=M*l*m-f*h*w;break;case"xzy":u[0]=f*l*m-M*h*w,u[1]=M*h*m-f*l*w,u[2]=M*l*w+f*h*m,u[3]=M*l*m+f*h*w;break;case"yxz":u[0]=f*l*m+M*h*w,u[1]=M*h*m-f*l*w,u[2]=M*l*w-f*h*m,u[3]=M*l*m+f*h*w;break;case"yzx":u[0]=f*l*m+M*h*w,u[1]=M*h*m+f*l*w,u[2]=M*l*w-f*h*m,u[3]=M*l*m-f*h*w;break;case"zxy":u[0]=f*l*m-M*h*w,u[1]=M*h*m+f*l*w,u[2]=M*l*w+f*h*m,u[3]=M*l*m-f*h*w;break;case"zyx":u[0]=f*l*m-M*h*w,u[1]=M*h*m+f*l*w,u[2]=M*l*w-f*h*m,u[3]=M*l*m+f*h*w;break;default:throw new Error(`Unknown rotation order: ${o}`)}return u},copy:f,clone:M,add:function(t,r,e){const o=e??new n(4);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o[2]=t[2]+r[2],o[3]=t[3]+r[3],o},subtract:h,sub:l,mulScalar:w,scale:m,divScalar:function(t,r,e){const o=e??new n(4);return o[0]=t[0]/r,o[1]=t[1]/r,o[2]=t[2]/r,o[3]=t[3]/r,o},dot:d,lerp:function(t,r,e,o){const c=o??new n(4);return c[0]=t[0]+e*(r[0]-t[0]),c[1]=t[1]+e*(r[1]-t[1]),c[2]=t[2]+e*(r[2]-t[2]),c[3]=t[3]+e*(r[3]-t[3]),c},length:v,len:q,lengthSq:p,lenSq:b,normalize:g,equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e&&Math.abs(n[2]-t[2])<e&&Math.abs(n[3]-t[3])<e},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]&&n[3]===t[3]},identity:function(t){const r=t??new n(4);return r[0]=0,r[1]=0,r[2]=0,r[3]=1,r},rotationTo:function(r,e,o){const u=o??new n(4),a=t.dot(r,e);return a<-.999999?(t.cross(x,r,y),t.len(y)<1e-6&&t.cross(S,r,y),t.normalize(y,y),c(y,Math.PI,u),u):a>.999999?(u[0]=0,u[1]=0,u[2]=0,u[3]=1,u):(t.cross(r,e,y),u[0]=y[0],u[1]=y[1],u[2]=y[2],u[3]=1+a,g(u,u))},sqlerp:function(t,r,e,o,c,u){const a=u??new n(4);return i(t,o,c,A),i(r,e,c,z),i(A,z,2*c*(1-c),a),a}}}(n),l.set(n,t)),t}const m=new Map;function d(n){let t=m.get(n);return t||(t=function(n){function t(t,r,e,o){const c=new n(4);return void 0!==t&&(c[0]=t,void 0!==r&&(c[1]=r,void 0!==e&&(c[2]=e,void 0!==o&&(c[3]=o)))),c}function r(t,r,e){const o=e??new n(4);return o[0]=t[0]-r[0],o[1]=t[1]-r[1],o[2]=t[2]-r[2],o[3]=t[3]-r[3],o}function o(t,r,e,o){const c=o??new n(4);return c[0]=t[0]+e*(r[0]-t[0]),c[1]=t[1]+e*(r[1]-t[1]),c[2]=t[2]+e*(r[2]-t[2]),c[3]=t[3]+e*(r[3]-t[3]),c}function c(t,r,e){const o=e??new n(4);return o[0]=t[0]*r,o[1]=t[1]*r,o[2]=t[2]*r,o[3]=t[3]*r,o}function u(t,r){const e=r??new n(4);return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e[3]=1/t[3],e}function a(n){const t=n[0],r=n[1],e=n[2],o=n[3];return Math.sqrt(t*t+r*r+e*e+o*o)}function s(n){const t=n[0],r=n[1],e=n[2],o=n[3];return t*t+r*r+e*e+o*o}function i(n,t){const r=n[0]-t[0],e=n[1]-t[1],o=n[2]-t[2],c=n[3]-t[3];return Math.sqrt(r*r+e*e+o*o+c*c)}function f(n,t){const r=n[0]-t[0],e=n[1]-t[1],o=n[2]-t[2],c=n[3]-t[3];return r*r+e*e+o*o+c*c}function M(t,r){const e=r??new n(4),o=t[0],c=t[1],u=t[2],a=t[3],s=Math.sqrt(o*o+c*c+u*u+a*a);return s>1e-5?(e[0]=o/s,e[1]=c/s,e[2]=u/s,e[3]=a/s):(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function h(t,r){const e=r??new n(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function l(t,r,e){const o=e??new n(4);return o[0]=t[0]*r[0],o[1]=t[1]*r[1],o[2]=t[2]*r[2],o[3]=t[3]*r[3],o}function w(t,r,e){const o=e??new n(4);return o[0]=t[0]/r[0],o[1]=t[1]/r[1],o[2]=t[2]/r[2],o[3]=t[3]/r[3],o}function m(t,r,e){const o=e??new n(4);return M(t,o),c(o,r,o)}return{create:t,fromValues:t,set:function(t,r,e,o,c){const u=c??new n(4);return u[0]=t,u[1]=r,u[2]=e,u[3]=o,u},ceil:function(t,r){const e=r??new n(4);return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e[3]=Math.ceil(t[3]),e},floor:function(t,r){const e=r??new n(4);return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e[3]=Math.floor(t[3]),e},round:function(t,r){const e=r??new n(4);return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e[3]=Math.round(t[3]),e},clamp:function(t,r=0,e=1,o){const c=o??new n(4);return c[0]=Math.min(e,Math.max(r,t[0])),c[1]=Math.min(e,Math.max(r,t[1])),c[2]=Math.min(e,Math.max(r,t[2])),c[3]=Math.min(e,Math.max(r,t[3])),c},add:function(t,r,e){const o=e??new n(4);return o[0]=t[0]+r[0],o[1]=t[1]+r[1],o[2]=t[2]+r[2],o[3]=t[3]+r[3],o},addScaled:function(t,r,e,o){const c=o??new n(4);return c[0]=t[0]+r[0]*e,c[1]=t[1]+r[1]*e,c[2]=t[2]+r[2]*e,c[3]=t[3]+r[3]*e,c},subtract:r,sub:r,equalsApproximately:function(n,t){return Math.abs(n[0]-t[0])<e&&Math.abs(n[1]-t[1])<e&&Math.abs(n[2]-t[2])<e&&Math.abs(n[3]-t[3])<e},equals:function(n,t){return n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]&&n[3]===t[3]},lerp:o,lerpV:function(t,r,e,o){const c=o??new n(4);return c[0]=t[0]+e[0]*(r[0]-t[0]),c[1]=t[1]+e[1]*(r[1]-t[1]),c[2]=t[2]+e[2]*(r[2]-t[2]),c[3]=t[3]+e[3]*(r[3]-t[3]),c},max:function(t,r,e){const o=e??new n(4);return o[0]=Math.max(t[0],r[0]),o[1]=Math.max(t[1],r[1]),o[2]=Math.max(t[2],r[2]),o[3]=Math.max(t[3],r[3]),o},min:function(t,r,e){const o=e??new n(4);return o[0]=Math.min(t[0],r[0]),o[1]=Math.min(t[1],r[1]),o[2]=Math.min(t[2],r[2]),o[3]=Math.min(t[3],r[3]),o},mulScalar:c,scale:c,divScalar:function(t,r,e){const o=e??new n(4);return o[0]=t[0]/r,o[1]=t[1]/r,o[2]=t[2]/r,o[3]=t[3]/r,o},inverse:u,invert:u,dot:function(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]+n[3]*t[3]},length:a,len:a,lengthSq:s,lenSq:s,distance:i,dist:i,distanceSq:f,distSq:f,normalize:M,negate:function(t,r){const e=r??new n(4);return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e},copy:h,clone:h,multiply:l,mul:l,divide:w,div:w,zero:function(t){const r=t??new n(4);return r[0]=0,r[1]=0,r[2]=0,r[3]=0,r},transformMat4:function(t,r,e){const o=e??new n(4),c=t[0],u=t[1],a=t[2],s=t[3];return o[0]=r[0]*c+r[4]*u+r[8]*a+r[12]*s,o[1]=r[1]*c+r[5]*u+r[9]*a+r[13]*s,o[2]=r[2]*c+r[6]*u+r[10]*a+r[14]*s,o[3]=r[3]*c+r[7]*u+r[11]*a+r[15]*s,o},setLength:m,truncate:function(t,r,e){const o=e??new n(4);return a(t)>r?m(t,r,o):h(t,o)},midpoint:function(t,r,e){return o(t,r,.5,e??new n(4))}}}(n),m.set(n,t)),t}function v(n,t,r,e,o,c){return{mat3:f(n),mat4:h(t),quat:w(r),vec2:u(e),vec3:s(o),vec4:d(c)}}const{mat3:q,mat4:p,quat:b,vec2:g,vec3:y,vec4:x}=v(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:S,mat4:A,quat:z,vec2:F,vec3:k,vec4:T}=v(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:Z,mat4:I,quat:P,vec2:V,vec3:D,vec4:X}=v(n,Array,Array,Array,Array,Array);export{q as mat3,S as mat3d,Z as mat3n,p as mat4,A as mat4d,I as mat4n,b as quat,z as quatd,P as quatn,o as utils,g as vec2,F as vec2d,V as vec2n,y as vec3,k as vec3d,D as vec3n,x as vec4,T as vec4d,X as vec4n}; //# sourceMappingURL=wgpu-matrix.module.min.js.map