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