Skip to content

Instantly share code, notes, and snippets.

@camargo
Last active March 14, 2023 16:16
Show Gist options
  • Save camargo/b64c896d4026982a9bb62569e3958659 to your computer and use it in GitHub Desktop.
Save camargo/b64c896d4026982a9bb62569e3958659 to your computer and use it in GitHub Desktop.
WebGL Animated Rotating Sphere with an Earth Texture
border: no
height: 512
license: gpl-3.0

This example demonstrates an animated rotating sphere with a texture map. See this blocks index.ts file for the code.

Libraries used include WebGL Programming Guide Utils, glMatrix, and a custom library I made.

!function(t){function a(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,a),o.loaded=!0,o.exports}var r={};return a.m=t,a.c=r,a.p="http://localhost:8080/",a(0)}([function(t,a,r){"use strict";function n(){i=new c.Shader(S,d,I);var t=[0,0,5],a=[0,0,0],r=[0,1,0],n=Math.PI/3,h=1,f=.1,m=100;l=new c.Camera(t,a,r,n,h,f,m),u=new c.Material(S,null,null,null,null,x),s=new c.Sphere(S,u,2,250,250),M=new c.Scene([s],null),S.clearColor(0,0,0,1),S.enable(S.DEPTH_TEST),c.WebGLUtils.animate(o,e)}function o(t){f+=Math.PI/4*t}function e(){S.clear(S.COLOR_BUFFER_BIT|S.DEPTH_BUFFER_BIT),s.modelToWorld=h.mat4.create(),h.mat4.rotateY(s.modelToWorld,s.modelToWorld,-f),i.draw(M,l)}var i,l,u,s,M,h=r(1),c=r(11),f=0,m=document.getElementById("webgl"),S=c.WebGLUtils.setupWebGL(m,null,null),x=new Image;x.src="./earth.jpg",x.onload=function(){return n()};var d="\n attribute vec3 a_Position;\n attribute vec2 a_TexCoord;\n\n uniform mat4 u_ModelViewProjectionMatrix;\n\n varying vec2 v_TexCoord;\n\n void main() {\n // Output tex coord to frag shader.\n v_TexCoord = a_TexCoord;\n\n // Output the final position.\n gl_Position = u_ModelViewProjectionMatrix * vec4(a_Position, 1.0);\n }\n",I="\n #ifdef GL_ES\n precision mediump float;\n #endif\n\n uniform sampler2D u_Sampler;\n\n varying vec2 v_TexCoord;\n\n void main() {\n // Get texture color for tex coord.\n gl_FragColor = texture2D(u_Sampler, v_TexCoord);\n }\n"},function(t,a,r){a.glMatrix=r(2),a.mat2=r(3),a.mat2d=r(4),a.mat3=r(5),a.mat4=r(6),a.quat=r(7),a.vec2=r(10),a.vec3=r(8),a.vec4=r(9)},function(t,a){var r={};r.EPSILON=1e-6,r.ARRAY_TYPE="undefined"!=typeof Float32Array?Float32Array:Array,r.RANDOM=Math.random,r.ENABLE_SIMD=!1,r.SIMD_AVAILABLE=r.ARRAY_TYPE===Float32Array&&"SIMD"in this,r.USE_SIMD=r.ENABLE_SIMD&&r.SIMD_AVAILABLE,r.setMatrixArrayType=function(t){r.ARRAY_TYPE=t};var n=Math.PI/180;r.toRadian=function(t){return t*n},r.equals=function(t,a){return Math.abs(t-a)<=r.EPSILON*Math.max(1,Math.abs(t),Math.abs(a))},t.exports=r},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},o.clone=function(t){var a=new n.ARRAY_TYPE(4);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},o.fromValues=function(t,a,r,o){var e=new n.ARRAY_TYPE(4);return e[0]=t,e[1]=a,e[2]=r,e[3]=o,e},o.set=function(t,a,r,n,o){return t[0]=a,t[1]=r,t[2]=n,t[3]=o,t},o.transpose=function(t,a){if(t===a){var r=a[1];t[1]=a[2],t[2]=r}else t[0]=a[0],t[1]=a[2],t[2]=a[1],t[3]=a[3];return t},o.invert=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=r*e-o*n;return i?(i=1/i,t[0]=e*i,t[1]=-n*i,t[2]=-o*i,t[3]=r*i,t):null},o.adjoint=function(t,a){var r=a[0];return t[0]=a[3],t[1]=-a[1],t[2]=-a[2],t[3]=r,t},o.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},o.multiply=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=r[0],u=r[1],s=r[2],M=r[3];return t[0]=n*l+e*u,t[1]=o*l+i*u,t[2]=n*s+e*M,t[3]=o*s+i*M,t},o.mul=o.multiply,o.rotate=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+e*l,t[1]=o*u+i*l,t[2]=n*-l+e*u,t[3]=o*-l+i*u,t},o.scale=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=r[0],u=r[1];return t[0]=n*l,t[1]=o*l,t[2]=e*u,t[3]=i*u,t},o.fromRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=n,t[1]=r,t[2]=-r,t[3]=n,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=a[1],t},o.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2))},o.LDU=function(t,a,r,n){return t[2]=n[2]/n[0],r[0]=n[0],r[1]=n[1],r[3]=n[3]-t[2]*r[1],[t,a,r]},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t[3]=a[3]+r[3],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t[3]=a[3]-r[3],t},o.sub=o.subtract,o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=t[3],l=a[0],u=a[1],s=a[2],M=a[3];return Math.abs(r-l)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(l))&&Math.abs(o-u)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(u))&&Math.abs(e-s)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(s))&&Math.abs(i-M)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(M))},o.multiplyScalar=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t},o.multiplyScalarAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t[3]=a[3]+r[3]*n,t},t.exports=o},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(6);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},o.clone=function(t){var a=new n.ARRAY_TYPE(6);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},o.fromValues=function(t,a,r,o,e,i){var l=new n.ARRAY_TYPE(6);return l[0]=t,l[1]=a,l[2]=r,l[3]=o,l[4]=e,l[5]=i,l},o.set=function(t,a,r,n,o,e,i){return t[0]=a,t[1]=r,t[2]=n,t[3]=o,t[4]=e,t[5]=i,t},o.invert=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=r*e-n*o;return u?(u=1/u,t[0]=e*u,t[1]=-n*u,t[2]=-o*u,t[3]=r*u,t[4]=(o*l-e*i)*u,t[5]=(n*i-r*l)*u,t):null},o.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},o.multiply=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1],h=r[2],c=r[3],f=r[4],m=r[5];return t[0]=n*s+e*M,t[1]=o*s+i*M,t[2]=n*h+e*c,t[3]=o*h+i*c,t[4]=n*f+e*m+l,t[5]=o*f+i*m+u,t},o.mul=o.multiply,o.rotate=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=Math.sin(r),M=Math.cos(r);return t[0]=n*M+e*s,t[1]=o*M+i*s,t[2]=n*-s+e*M,t[3]=o*-s+i*M,t[4]=l,t[5]=u,t},o.scale=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1];return t[0]=n*s,t[1]=o*s,t[2]=e*M,t[3]=i*M,t[4]=l,t[5]=u,t},o.translate=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1];return t[0]=n,t[1]=o,t[2]=e,t[3]=i,t[4]=n*s+e*M+l,t[5]=o*s+i*M+u,t},o.fromRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=n,t[1]=r,t[2]=-r,t[3]=n,t[4]=0,t[5]=0,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=a[1],t[4]=0,t[5]=0,t},o.fromTranslation=function(t,a){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=a[0],t[5]=a[1],t},o.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+1)},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t[3]=a[3]+r[3],t[4]=a[4]+r[4],t[5]=a[5]+r[5],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t[3]=a[3]-r[3],t[4]=a[4]-r[4],t[5]=a[5]-r[5],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t[4]=a[4]*r,t[5]=a[5]*r,t},o.multiplyScalarAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t[3]=a[3]+r[3]*n,t[4]=a[4]+r[4]*n,t[5]=a[5]+r[5]*n,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=t[3],l=t[4],u=t[5],s=a[0],M=a[1],h=a[2],c=a[3],f=a[4],m=a[5];return Math.abs(r-s)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(o-M)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(e-h)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(h))&&Math.abs(i-c)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(c))&&Math.abs(l-f)<=n.EPSILON*Math.max(1,Math.abs(l),Math.abs(f))&&Math.abs(u-m)<=n.EPSILON*Math.max(1,Math.abs(u),Math.abs(m))},t.exports=o},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(9);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromMat4=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[4],t[4]=a[5],t[5]=a[6],t[6]=a[8],t[7]=a[9],t[8]=a[10],t},o.clone=function(t){var a=new n.ARRAY_TYPE(9);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t},o.fromValues=function(t,a,r,o,e,i,l,u,s){var M=new n.ARRAY_TYPE(9);return M[0]=t,M[1]=a,M[2]=r,M[3]=o,M[4]=e,M[5]=i,M[6]=l,M[7]=u,M[8]=s,M},o.set=function(t,a,r,n,o,e,i,l,u,s){return t[0]=a,t[1]=r,t[2]=n,t[3]=o,t[4]=e,t[5]=i,t[6]=l,t[7]=u,t[8]=s,t},o.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.transpose=function(t,a){if(t===a){var r=a[1],n=a[2],o=a[5];t[1]=a[3],t[2]=a[6],t[3]=r,t[5]=a[7],t[6]=n,t[7]=o}else t[0]=a[0],t[1]=a[3],t[2]=a[6],t[3]=a[1],t[4]=a[4],t[5]=a[7],t[6]=a[2],t[7]=a[5],t[8]=a[8];return t},o.invert=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],h=M*i-l*s,c=-M*e+l*u,f=s*e-i*u,m=r*h+n*c+o*f;return m?(m=1/m,t[0]=h*m,t[1]=(-M*n+o*s)*m,t[2]=(l*n-o*i)*m,t[3]=c*m,t[4]=(M*r-o*u)*m,t[5]=(-l*r+o*e)*m,t[6]=f*m,t[7]=(-s*r+n*u)*m,t[8]=(i*r-n*e)*m,t):null},o.adjoint=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8];return t[0]=i*M-l*s,t[1]=o*s-n*M,t[2]=n*l-o*i,t[3]=l*u-e*M,t[4]=r*M-o*u,t[5]=o*e-r*l,t[6]=e*s-i*u,t[7]=n*u-r*s,t[8]=r*i-n*e,t},o.determinant=function(t){var a=t[0],r=t[1],n=t[2],o=t[3],e=t[4],i=t[5],l=t[6],u=t[7],s=t[8];return a*(s*e-i*u)+r*(-s*o+i*l)+n*(u*o-e*l)},o.multiply=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],h=a[8],c=r[0],f=r[1],m=r[2],S=r[3],x=r[4],d=r[5],I=r[6],D=r[7],F=r[8];return t[0]=c*n+f*i+m*s,t[1]=c*o+f*l+m*M,t[2]=c*e+f*u+m*h,t[3]=S*n+x*i+d*s,t[4]=S*o+x*l+d*M,t[5]=S*e+x*u+d*h,t[6]=I*n+D*i+F*s,t[7]=I*o+D*l+F*M,t[8]=I*e+D*u+F*h,t},o.mul=o.multiply,o.translate=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],h=a[8],c=r[0],f=r[1];return t[0]=n,t[1]=o,t[2]=e,t[3]=i,t[4]=l,t[5]=u,t[6]=c*n+f*i+s,t[7]=c*o+f*l+M,t[8]=c*e+f*u+h,t},o.rotate=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],h=a[8],c=Math.sin(r),f=Math.cos(r);return t[0]=f*n+c*i,t[1]=f*o+c*l,t[2]=f*e+c*u,t[3]=f*i-c*n,t[4]=f*l-c*o,t[5]=f*u-c*e,t[6]=s,t[7]=M,t[8]=h,t},o.scale=function(t,a,r){var n=r[0],o=r[1];return t[0]=n*a[0],t[1]=n*a[1],t[2]=n*a[2],t[3]=o*a[3],t[4]=o*a[4],t[5]=o*a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t},o.fromTranslation=function(t,a){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=a[0],t[7]=a[1],t[8]=1,t},o.fromRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=0,t[4]=a[1],t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},o.fromMat2d=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=0,t[3]=a[2],t[4]=a[3],t[5]=0,t[6]=a[4],t[7]=a[5],t[8]=1,t},o.fromQuat=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=r+r,l=n+n,u=o+o,s=r*i,M=n*i,h=n*l,c=o*i,f=o*l,m=o*u,S=e*i,x=e*l,d=e*u;return t[0]=1-h-m,t[3]=M-d,t[6]=c+x,t[1]=M+d,t[4]=1-s-m,t[7]=f-S,t[2]=c-x,t[5]=f+S,t[8]=1-s-h,t},o.normalFromMat4=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],h=a[9],c=a[10],f=a[11],m=a[12],S=a[13],x=a[14],d=a[15],I=r*l-n*i,D=r*u-o*i,F=r*s-e*i,v=n*u-o*l,b=n*s-e*l,p=o*s-e*u,g=M*S-h*m,w=M*x-c*m,A=M*d-f*m,E=h*x-c*S,R=h*d-f*S,T=c*d-f*x,L=I*T-D*R+F*E+v*A-b*w+p*g;return L?(L=1/L,t[0]=(l*T-u*R+s*E)*L,t[1]=(u*A-i*T-s*w)*L,t[2]=(i*R-l*A+s*g)*L,t[3]=(o*R-n*T-e*E)*L,t[4]=(r*T-o*A+e*w)*L,t[5]=(n*A-r*R-e*g)*L,t[6]=(S*p-x*b+d*v)*L,t[7]=(x*F-m*p-d*D)*L,t[8]=(m*b-S*F+d*I)*L,t):null},o.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2))},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t[3]=a[3]+r[3],t[4]=a[4]+r[4],t[5]=a[5]+r[5],t[6]=a[6]+r[6],t[7]=a[7]+r[7],t[8]=a[8]+r[8],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t[3]=a[3]-r[3],t[4]=a[4]-r[4],t[5]=a[5]-r[5],t[6]=a[6]-r[6],t[7]=a[7]-r[7],t[8]=a[8]-r[8],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t[4]=a[4]*r,t[5]=a[5]*r,t[6]=a[6]*r,t[7]=a[7]*r,t[8]=a[8]*r,t},o.multiplyScalarAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t[3]=a[3]+r[3]*n,t[4]=a[4]+r[4]*n,t[5]=a[5]+r[5]*n,t[6]=a[6]+r[6]*n,t[7]=a[7]+r[7]*n,t[8]=a[8]+r[8]*n,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]&&t[6]===a[6]&&t[7]===a[7]&&t[8]===a[8]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=t[3],l=t[4],u=t[5],s=t[6],M=t[7],h=t[8],c=a[0],f=a[1],m=a[2],S=a[3],x=a[4],d=a[5],I=t[6],D=a[7],F=a[8];return Math.abs(r-c)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(c))&&Math.abs(o-f)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(f))&&Math.abs(e-m)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(m))&&Math.abs(i-S)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(S))&&Math.abs(l-x)<=n.EPSILON*Math.max(1,Math.abs(l),Math.abs(x))&&Math.abs(u-d)<=n.EPSILON*Math.max(1,Math.abs(u),Math.abs(d))&&Math.abs(s-I)<=n.EPSILON*Math.max(1,Math.abs(s),Math.abs(I))&&Math.abs(M-D)<=n.EPSILON*Math.max(1,Math.abs(M),Math.abs(D))&&Math.abs(h-F)<=n.EPSILON*Math.max(1,Math.abs(h),Math.abs(F))},t.exports=o},function(t,a,r){var n=r(2),o={scalar:{},SIMD:{}};o.create=function(){var t=new n.ARRAY_TYPE(16);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},o.clone=function(t){var a=new n.ARRAY_TYPE(16);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a[4]=t[4],a[5]=t[5],a[6]=t[6],a[7]=t[7],a[8]=t[8],a[9]=t[9],a[10]=t[10],a[11]=t[11],a[12]=t[12],a[13]=t[13],a[14]=t[14],a[15]=t[15],a},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.fromValues=function(t,a,r,o,e,i,l,u,s,M,h,c,f,m,S,x){var d=new n.ARRAY_TYPE(16);return d[0]=t,d[1]=a,d[2]=r,d[3]=o,d[4]=e,d[5]=i,d[6]=l,d[7]=u,d[8]=s,d[9]=M,d[10]=h,d[11]=c,d[12]=f,d[13]=m,d[14]=S,d[15]=x,d},o.set=function(t,a,r,n,o,e,i,l,u,s,M,h,c,f,m,S,x){return t[0]=a,t[1]=r,t[2]=n,t[3]=o,t[4]=e,t[5]=i,t[6]=l,t[7]=u,t[8]=s,t[9]=M,t[10]=h,t[11]=c,t[12]=f,t[13]=m,t[14]=S,t[15]=x,t},o.identity=function(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},o.scalar.transpose=function(t,a){if(t===a){var r=a[1],n=a[2],o=a[3],e=a[6],i=a[7],l=a[11];t[1]=a[4],t[2]=a[8],t[3]=a[12],t[4]=r,t[6]=a[9],t[7]=a[13],t[8]=n,t[9]=e,t[11]=a[14],t[12]=o,t[13]=i,t[14]=l}else t[0]=a[0],t[1]=a[4],t[2]=a[8],t[3]=a[12],t[4]=a[1],t[5]=a[5],t[6]=a[9],t[7]=a[13],t[8]=a[2],t[9]=a[6],t[10]=a[10],t[11]=a[14],t[12]=a[3],t[13]=a[7],t[14]=a[11],t[15]=a[15];return t},o.SIMD.transpose=function(t,a){var r,n,o,e,i,l,u,s,M,h;return r=SIMD.Float32x4.load(a,0),n=SIMD.Float32x4.load(a,4),o=SIMD.Float32x4.load(a,8),e=SIMD.Float32x4.load(a,12),i=SIMD.Float32x4.shuffle(r,n,0,1,4,5),l=SIMD.Float32x4.shuffle(o,e,0,1,4,5),u=SIMD.Float32x4.shuffle(i,l,0,2,4,6),s=SIMD.Float32x4.shuffle(i,l,1,3,5,7),SIMD.Float32x4.store(t,0,u),SIMD.Float32x4.store(t,4,s),i=SIMD.Float32x4.shuffle(r,n,2,3,6,7),l=SIMD.Float32x4.shuffle(o,e,2,3,6,7),M=SIMD.Float32x4.shuffle(i,l,0,2,4,6),h=SIMD.Float32x4.shuffle(i,l,1,3,5,7),SIMD.Float32x4.store(t,8,M),SIMD.Float32x4.store(t,12,h),t},o.transpose=n.USE_SIMD?o.SIMD.transpose:o.scalar.transpose,o.scalar.invert=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],h=a[9],c=a[10],f=a[11],m=a[12],S=a[13],x=a[14],d=a[15],I=r*l-n*i,D=r*u-o*i,F=r*s-e*i,v=n*u-o*l,b=n*s-e*l,p=o*s-e*u,g=M*S-h*m,w=M*x-c*m,A=M*d-f*m,E=h*x-c*S,R=h*d-f*S,T=c*d-f*x,L=I*T-D*R+F*E+v*A-b*w+p*g;return L?(L=1/L,t[0]=(l*T-u*R+s*E)*L,t[1]=(o*R-n*T-e*E)*L,t[2]=(S*p-x*b+d*v)*L,t[3]=(c*b-h*p-f*v)*L,t[4]=(u*A-i*T-s*w)*L,t[5]=(r*T-o*A+e*w)*L,t[6]=(x*F-m*p-d*D)*L,t[7]=(M*p-c*F+f*D)*L,t[8]=(i*R-l*A+s*g)*L,t[9]=(n*A-r*R-e*g)*L,t[10]=(m*b-S*F+d*I)*L,t[11]=(h*F-M*b-f*I)*L,t[12]=(l*w-i*E-u*g)*L,t[13]=(r*E-n*w+o*g)*L,t[14]=(S*D-m*v-x*I)*L,t[15]=(M*v-h*D+c*I)*L,t):null},o.SIMD.invert=function(t,a){var r,n,o,e,i,l,u,s,M,h,c=SIMD.Float32x4.load(a,0),f=SIMD.Float32x4.load(a,4),m=SIMD.Float32x4.load(a,8),S=SIMD.Float32x4.load(a,12);return i=SIMD.Float32x4.shuffle(c,f,0,1,4,5),n=SIMD.Float32x4.shuffle(m,S,0,1,4,5),r=SIMD.Float32x4.shuffle(i,n,0,2,4,6),n=SIMD.Float32x4.shuffle(n,i,1,3,5,7),i=SIMD.Float32x4.shuffle(c,f,2,3,6,7),e=SIMD.Float32x4.shuffle(m,S,2,3,6,7),o=SIMD.Float32x4.shuffle(i,e,0,2,4,6),e=SIMD.Float32x4.shuffle(e,i,1,3,5,7),i=SIMD.Float32x4.mul(o,e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),l=SIMD.Float32x4.mul(n,i),u=SIMD.Float32x4.mul(r,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),l=SIMD.Float32x4.sub(SIMD.Float32x4.mul(n,i),l),u=SIMD.Float32x4.sub(SIMD.Float32x4.mul(r,i),u),u=SIMD.Float32x4.swizzle(u,2,3,0,1),i=SIMD.Float32x4.mul(n,o),i=SIMD.Float32x4.swizzle(i,1,0,3,2),l=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,i),l),M=SIMD.Float32x4.mul(r,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),l=SIMD.Float32x4.sub(l,SIMD.Float32x4.mul(e,i)),M=SIMD.Float32x4.sub(SIMD.Float32x4.mul(r,i),M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),i=SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(n,2,3,0,1),e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),o=SIMD.Float32x4.swizzle(o,2,3,0,1),l=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,i),l),s=SIMD.Float32x4.mul(r,i),i=SIMD.Float32x4.swizzle(i,2,3,0,1),l=SIMD.Float32x4.sub(l,SIMD.Float32x4.mul(o,i)),s=SIMD.Float32x4.sub(SIMD.Float32x4.mul(r,i),s),s=SIMD.Float32x4.swizzle(s,2,3,0,1),i=SIMD.Float32x4.mul(r,n),i=SIMD.Float32x4.swizzle(i,1,0,3,2),s=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,i),s),M=SIMD.Float32x4.sub(SIMD.Float32x4.mul(o,i),M),i=SIMD.Float32x4.swizzle(i,2,3,0,1),s=SIMD.Float32x4.sub(SIMD.Float32x4.mul(e,i),s),M=SIMD.Float32x4.sub(M,SIMD.Float32x4.mul(o,i)),i=SIMD.Float32x4.mul(r,e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),u=SIMD.Float32x4.sub(u,SIMD.Float32x4.mul(o,i)),s=SIMD.Float32x4.add(SIMD.Float32x4.mul(n,i),s),i=SIMD.Float32x4.swizzle(i,2,3,0,1),u=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,i),u),s=SIMD.Float32x4.sub(s,SIMD.Float32x4.mul(n,i)),i=SIMD.Float32x4.mul(r,o),i=SIMD.Float32x4.swizzle(i,1,0,3,2),u=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,i),u),M=SIMD.Float32x4.sub(M,SIMD.Float32x4.mul(n,i)),i=SIMD.Float32x4.swizzle(i,2,3,0,1),u=SIMD.Float32x4.sub(u,SIMD.Float32x4.mul(e,i)),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(n,i),M),h=SIMD.Float32x4.mul(r,l),h=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,2,3,0,1),h),h=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(h,1,0,3,2),h),i=SIMD.Float32x4.reciprocalApproximation(h),h=SIMD.Float32x4.sub(SIMD.Float32x4.add(i,i),SIMD.Float32x4.mul(h,SIMD.Float32x4.mul(i,i))),(h=SIMD.Float32x4.swizzle(h,0,0,0,0))?(SIMD.Float32x4.store(t,0,SIMD.Float32x4.mul(h,l)),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(h,u)),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(h,s)),SIMD.Float32x4.store(t,12,SIMD.Float32x4.mul(h,M)),t):null},o.invert=n.USE_SIMD?o.SIMD.invert:o.scalar.invert,o.scalar.adjoint=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],h=a[9],c=a[10],f=a[11],m=a[12],S=a[13],x=a[14],d=a[15];return t[0]=l*(c*d-f*x)-h*(u*d-s*x)+S*(u*f-s*c),t[1]=-(n*(c*d-f*x)-h*(o*d-e*x)+S*(o*f-e*c)),t[2]=n*(u*d-s*x)-l*(o*d-e*x)+S*(o*s-e*u),t[3]=-(n*(u*f-s*c)-l*(o*f-e*c)+h*(o*s-e*u)),t[4]=-(i*(c*d-f*x)-M*(u*d-s*x)+m*(u*f-s*c)),t[5]=r*(c*d-f*x)-M*(o*d-e*x)+m*(o*f-e*c),t[6]=-(r*(u*d-s*x)-i*(o*d-e*x)+m*(o*s-e*u)),t[7]=r*(u*f-s*c)-i*(o*f-e*c)+M*(o*s-e*u),t[8]=i*(h*d-f*S)-M*(l*d-s*S)+m*(l*f-s*h),t[9]=-(r*(h*d-f*S)-M*(n*d-e*S)+m*(n*f-e*h)),t[10]=r*(l*d-s*S)-i*(n*d-e*S)+m*(n*s-e*l),t[11]=-(r*(l*f-s*h)-i*(n*f-e*h)+M*(n*s-e*l)),t[12]=-(i*(h*x-c*S)-M*(l*x-u*S)+m*(l*c-u*h)),t[13]=r*(h*x-c*S)-M*(n*x-o*S)+m*(n*c-o*h),t[14]=-(r*(l*x-u*S)-i*(n*x-o*S)+m*(n*u-o*l)),t[15]=r*(l*c-u*h)-i*(n*c-o*h)+M*(n*u-o*l),t},o.SIMD.adjoint=function(t,a){var r,n,o,e,i,l,u,s,M,h,c,f,m,r=SIMD.Float32x4.load(a,0),n=SIMD.Float32x4.load(a,4),o=SIMD.Float32x4.load(a,8),e=SIMD.Float32x4.load(a,12);return M=SIMD.Float32x4.shuffle(r,n,0,1,4,5),l=SIMD.Float32x4.shuffle(o,e,0,1,4,5),i=SIMD.Float32x4.shuffle(M,l,0,2,4,6),l=SIMD.Float32x4.shuffle(l,M,1,3,5,7),M=SIMD.Float32x4.shuffle(r,n,2,3,6,7),s=SIMD.Float32x4.shuffle(o,e,2,3,6,7),u=SIMD.Float32x4.shuffle(M,s,0,2,4,6),s=SIMD.Float32x4.shuffle(s,M,1,3,5,7),M=SIMD.Float32x4.mul(u,s),M=SIMD.Float32x4.swizzle(M,1,0,3,2),h=SIMD.Float32x4.mul(l,M),c=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),h=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,M),h),c=SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,M),c),c=SIMD.Float32x4.swizzle(c,2,3,0,1),M=SIMD.Float32x4.mul(l,u),M=SIMD.Float32x4.swizzle(M,1,0,3,2),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,M),h),m=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(s,M)),m=SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,M),m),m=SIMD.Float32x4.swizzle(m,2,3,0,1),M=SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,2,3,0,1),s),M=SIMD.Float32x4.swizzle(M,1,0,3,2),u=SIMD.Float32x4.swizzle(u,2,3,0,1),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,M),h),f=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(u,M)),f=SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,M),f),f=SIMD.Float32x4.swizzle(f,2,3,0,1),M=SIMD.Float32x4.mul(i,l),M=SIMD.Float32x4.swizzle(M,1,0,3,2),f=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,M),f),m=SIMD.Float32x4.sub(SIMD.Float32x4.mul(u,M),m),M=SIMD.Float32x4.swizzle(M,2,3,0,1),f=SIMD.Float32x4.sub(SIMD.Float32x4.mul(s,M),f),m=SIMD.Float32x4.sub(m,SIMD.Float32x4.mul(u,M)),M=SIMD.Float32x4.mul(i,s),M=SIMD.Float32x4.swizzle(M,1,0,3,2),c=SIMD.Float32x4.sub(c,SIMD.Float32x4.mul(u,M)),f=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,M),f),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,M),c),f=SIMD.Float32x4.sub(f,SIMD.Float32x4.mul(l,M)),M=SIMD.Float32x4.mul(i,u),M=SIMD.Float32x4.swizzle(M,1,0,3,2),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,M),c),m=SIMD.Float32x4.sub(m,SIMD.Float32x4.mul(l,M)),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.sub(c,SIMD.Float32x4.mul(s,M)),m=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,M),m),SIMD.Float32x4.store(t,0,h),SIMD.Float32x4.store(t,4,c),SIMD.Float32x4.store(t,8,f),SIMD.Float32x4.store(t,12,m),t},o.adjoint=n.USE_SIMD?o.SIMD.adjoint:o.scalar.adjoint,o.determinant=function(t){var a=t[0],r=t[1],n=t[2],o=t[3],e=t[4],i=t[5],l=t[6],u=t[7],s=t[8],M=t[9],h=t[10],c=t[11],f=t[12],m=t[13],S=t[14],x=t[15],d=a*i-r*e,I=a*l-n*e,D=a*u-o*e,F=r*l-n*i,v=r*u-o*i,b=n*u-o*l,p=s*m-M*f,g=s*S-h*f,w=s*x-c*f,A=M*S-h*m,E=M*x-c*m,R=h*x-c*S;return d*R-I*E+D*A+F*w-v*g+b*p},o.SIMD.multiply=function(t,a,r){var n=SIMD.Float32x4.load(a,0),o=SIMD.Float32x4.load(a,4),e=SIMD.Float32x4.load(a,8),i=SIMD.Float32x4.load(a,12),l=SIMD.Float32x4.load(r,0),u=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,0,0,0,0),n),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,2,2,2,2),e),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,3,3,3,3),i))));SIMD.Float32x4.store(t,0,u);var s=SIMD.Float32x4.load(r,4),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,0,0,0,0),n),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,2,2,2,2),e),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,3,3,3,3),i))));SIMD.Float32x4.store(t,4,M);var h=SIMD.Float32x4.load(r,8),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(h,0,0,0,0),n),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(h,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(h,2,2,2,2),e),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(h,3,3,3,3),i))));SIMD.Float32x4.store(t,8,c);var f=SIMD.Float32x4.load(r,12),m=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,0,0,0,0),n),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,1,1,1,1),o),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,2,2,2,2),e),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,3,3,3,3),i))));return SIMD.Float32x4.store(t,12,m),t},o.scalar.multiply=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],h=a[8],c=a[9],f=a[10],m=a[11],S=a[12],x=a[13],d=a[14],I=a[15],D=r[0],F=r[1],v=r[2],b=r[3];return t[0]=D*n+F*l+v*h+b*S,t[1]=D*o+F*u+v*c+b*x,t[2]=D*e+F*s+v*f+b*d,t[3]=D*i+F*M+v*m+b*I,D=r[4],F=r[5],v=r[6],b=r[7],t[4]=D*n+F*l+v*h+b*S,t[5]=D*o+F*u+v*c+b*x,t[6]=D*e+F*s+v*f+b*d,t[7]=D*i+F*M+v*m+b*I,D=r[8],F=r[9],v=r[10],b=r[11],t[8]=D*n+F*l+v*h+b*S,t[9]=D*o+F*u+v*c+b*x,t[10]=D*e+F*s+v*f+b*d,t[11]=D*i+F*M+v*m+b*I,D=r[12],F=r[13],v=r[14],b=r[15],t[12]=D*n+F*l+v*h+b*S,t[13]=D*o+F*u+v*c+b*x,t[14]=D*e+F*s+v*f+b*d,t[15]=D*i+F*M+v*m+b*I,t},o.multiply=n.USE_SIMD?o.SIMD.multiply:o.scalar.multiply,o.mul=o.multiply,o.scalar.translate=function(t,a,r){var n,o,e,i,l,u,s,M,h,c,f,m,S=r[0],x=r[1],d=r[2];return a===t?(t[12]=a[0]*S+a[4]*x+a[8]*d+a[12],t[13]=a[1]*S+a[5]*x+a[9]*d+a[13],t[14]=a[2]*S+a[6]*x+a[10]*d+a[14],t[15]=a[3]*S+a[7]*x+a[11]*d+a[15]):(n=a[0],o=a[1],e=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],h=a[8],c=a[9],f=a[10],m=a[11],t[0]=n,t[1]=o,t[2]=e,t[3]=i,t[4]=l,t[5]=u,t[6]=s,t[7]=M,t[8]=h,t[9]=c,t[10]=f,t[11]=m,t[12]=n*S+l*x+h*d+a[12],t[13]=o*S+u*x+c*d+a[13],t[14]=e*S+s*x+f*d+a[14],t[15]=i*S+M*x+m*d+a[15]),t},o.SIMD.translate=function(t,a,r){var n=SIMD.Float32x4.load(a,0),o=SIMD.Float32x4.load(a,4),e=SIMD.Float32x4.load(a,8),i=SIMD.Float32x4.load(a,12),l=SIMD.Float32x4(r[0],r[1],r[2],0);a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11]),n=SIMD.Float32x4.mul(n,SIMD.Float32x4.swizzle(l,0,0,0,0)),o=SIMD.Float32x4.mul(o,SIMD.Float32x4.swizzle(l,1,1,1,1)),e=SIMD.Float32x4.mul(e,SIMD.Float32x4.swizzle(l,2,2,2,2));var u=SIMD.Float32x4.add(n,SIMD.Float32x4.add(o,SIMD.Float32x4.add(e,i)));return SIMD.Float32x4.store(t,12,u),t},o.translate=n.USE_SIMD?o.SIMD.translate:o.scalar.translate,o.scalar.scale=function(t,a,r){var n=r[0],o=r[1],e=r[2];return t[0]=a[0]*n,t[1]=a[1]*n,t[2]=a[2]*n,t[3]=a[3]*n,t[4]=a[4]*o,t[5]=a[5]*o,t[6]=a[6]*o,t[7]=a[7]*o,t[8]=a[8]*e,t[9]=a[9]*e,t[10]=a[10]*e,t[11]=a[11]*e,t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.SIMD.scale=function(t,a,r){var n,o,e,i=SIMD.Float32x4(r[0],r[1],r[2],0);return n=SIMD.Float32x4.load(a,0),SIMD.Float32x4.store(t,0,SIMD.Float32x4.mul(n,SIMD.Float32x4.swizzle(i,0,0,0,0))),o=SIMD.Float32x4.load(a,4),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(o,SIMD.Float32x4.swizzle(i,1,1,1,1))),e=SIMD.Float32x4.load(a,8),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(e,SIMD.Float32x4.swizzle(i,2,2,2,2))),t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},o.scale=n.USE_SIMD?o.SIMD.scale:o.scalar.scale,o.rotate=function(t,a,r,o){var e,i,l,u,s,M,h,c,f,m,S,x,d,I,D,F,v,b,p,g,w,A,E,R,T=o[0],L=o[1],z=o[2],P=Math.sqrt(T*T+L*L+z*z);return Math.abs(P)<n.EPSILON?null:(P=1/P,T*=P,L*=P,z*=P,e=Math.sin(r),i=Math.cos(r),l=1-i,u=a[0],s=a[1],M=a[2],h=a[3],c=a[4],f=a[5],m=a[6],S=a[7],x=a[8],d=a[9],I=a[10],D=a[11],F=T*T*l+i,v=L*T*l+z*e,b=z*T*l-L*e,p=T*L*l-z*e,g=L*L*l+i,w=z*L*l+T*e,A=T*z*l+L*e,E=L*z*l-T*e,R=z*z*l+i,t[0]=u*F+c*v+x*b,t[1]=s*F+f*v+d*b,t[2]=M*F+m*v+I*b,t[3]=h*F+S*v+D*b,t[4]=u*p+c*g+x*w,t[5]=s*p+f*g+d*w,t[6]=M*p+m*g+I*w,t[7]=h*p+S*g+D*w,t[8]=u*A+c*E+x*R,t[9]=s*A+f*E+d*R,t[10]=M*A+m*E+I*R,t[11]=h*A+S*E+D*R,a!==t&&(t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t)},o.scalar.rotateX=function(t,a,r){var n=Math.sin(r),o=Math.cos(r),e=a[4],i=a[5],l=a[6],u=a[7],s=a[8],M=a[9],h=a[10],c=a[11];return a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[4]=e*o+s*n,t[5]=i*o+M*n,t[6]=l*o+h*n,t[7]=u*o+c*n,t[8]=s*o-e*n,t[9]=M*o-i*n,t[10]=h*o-l*n,t[11]=c*o-u*n,t},o.SIMD.rotateX=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),o=SIMD.Float32x4.splat(Math.cos(r));a!==t&&(t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var e=SIMD.Float32x4.load(a,4),i=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,4,SIMD.Float32x4.add(SIMD.Float32x4.mul(e,o),SIMD.Float32x4.mul(i,n))),SIMD.Float32x4.store(t,8,SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,o),SIMD.Float32x4.mul(e,n))),t},o.rotateX=n.USE_SIMD?o.SIMD.rotateX:o.scalar.rotateX,o.scalar.rotateY=function(t,a,r){var n=Math.sin(r),o=Math.cos(r),e=a[0],i=a[1],l=a[2],u=a[3],s=a[8],M=a[9],h=a[10],c=a[11];return a!==t&&(t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[0]=e*o-s*n,t[1]=i*o-M*n,t[2]=l*o-h*n,t[3]=u*o-c*n,t[8]=e*n+s*o,t[9]=i*n+M*o,t[10]=l*n+h*o,t[11]=u*n+c*o,t},o.SIMD.rotateY=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),o=SIMD.Float32x4.splat(Math.cos(r));a!==t&&(t[4]=a[4],t[5]=a[5],t[6]=a[6],t[7]=a[7],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var e=SIMD.Float32x4.load(a,0),i=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.sub(SIMD.Float32x4.mul(e,o),SIMD.Float32x4.mul(i,n))),SIMD.Float32x4.store(t,8,SIMD.Float32x4.add(SIMD.Float32x4.mul(e,n),SIMD.Float32x4.mul(i,o))),t},o.rotateY=n.USE_SIMD?o.SIMD.rotateY:o.scalar.rotateY,o.scalar.rotateZ=function(t,a,r){var n=Math.sin(r),o=Math.cos(r),e=a[0],i=a[1],l=a[2],u=a[3],s=a[4],M=a[5],h=a[6],c=a[7];return a!==t&&(t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t[0]=e*o+s*n,t[1]=i*o+M*n,t[2]=l*o+h*n,t[3]=u*o+c*n,t[4]=s*o-e*n,t[5]=M*o-i*n,t[6]=h*o-l*n,t[7]=c*o-u*n,t},o.SIMD.rotateZ=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),o=SIMD.Float32x4.splat(Math.cos(r));a!==t&&(t[8]=a[8],t[9]=a[9],t[10]=a[10],t[11]=a[11],t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]);var e=SIMD.Float32x4.load(a,0),i=SIMD.Float32x4.load(a,4);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.add(SIMD.Float32x4.mul(e,o),SIMD.Float32x4.mul(i,n))),SIMD.Float32x4.store(t,4,SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,o),SIMD.Float32x4.mul(e,n))),t},o.rotateZ=n.USE_SIMD?o.SIMD.rotateZ:o.scalar.rotateZ,o.fromTranslation=function(t,a){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]=a[0],t[13]=a[1],t[14]=a[2],t[15]=1,t},o.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=a[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromRotation=function(t,a,r){var o,e,i,l=r[0],u=r[1],s=r[2],M=Math.sqrt(l*l+u*u+s*s);return Math.abs(M)<n.EPSILON?null:(M=1/M,l*=M,u*=M,s*=M,o=Math.sin(a),e=Math.cos(a),i=1-e,t[0]=l*l*i+e,t[1]=u*l*i+s*o,t[2]=s*l*i-u*o,t[3]=0,t[4]=l*u*i-s*o,t[5]=u*u*i+e,t[6]=s*u*i+l*o,t[7]=0,t[8]=l*s*i+u*o,t[9]=u*s*i-l*o,t[10]=s*s*i+e,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)},o.fromXRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromYRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.fromZRotation=function(t,a){var r=Math.sin(a),n=Math.cos(a);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,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},o.fromRotationTranslation=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=n+n,u=o+o,s=e+e,M=n*l,h=n*u,c=n*s,f=o*u,m=o*s,S=e*s,x=i*l,d=i*u,I=i*s;return t[0]=1-(f+S),t[1]=h+I,t[2]=c-d,t[3]=0,t[4]=h-I,t[5]=1-(M+S),t[6]=m+x,t[7]=0,t[8]=c+d,
t[9]=m-x,t[10]=1-(M+f),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},o.getTranslation=function(t,a){return t[0]=a[12],t[1]=a[13],t[2]=a[14],t},o.getRotation=function(t,a){var r=a[0]+a[5]+a[10],n=0;return r>0?(n=2*Math.sqrt(r+1),t[3]=.25*n,t[0]=(a[6]-a[9])/n,t[1]=(a[8]-a[2])/n,t[2]=(a[1]-a[4])/n):a[0]>a[5]&a[0]>a[10]?(n=2*Math.sqrt(1+a[0]-a[5]-a[10]),t[3]=(a[6]-a[9])/n,t[0]=.25*n,t[1]=(a[1]+a[4])/n,t[2]=(a[8]+a[2])/n):a[5]>a[10]?(n=2*Math.sqrt(1+a[5]-a[0]-a[10]),t[3]=(a[8]-a[2])/n,t[0]=(a[1]+a[4])/n,t[1]=.25*n,t[2]=(a[6]+a[9])/n):(n=2*Math.sqrt(1+a[10]-a[0]-a[5]),t[3]=(a[1]-a[4])/n,t[0]=(a[8]+a[2])/n,t[1]=(a[6]+a[9])/n,t[2]=.25*n),t},o.fromRotationTranslationScale=function(t,a,r,n){var o=a[0],e=a[1],i=a[2],l=a[3],u=o+o,s=e+e,M=i+i,h=o*u,c=o*s,f=o*M,m=e*s,S=e*M,x=i*M,d=l*u,I=l*s,D=l*M,F=n[0],v=n[1],b=n[2];return t[0]=(1-(m+x))*F,t[1]=(c+D)*F,t[2]=(f-I)*F,t[3]=0,t[4]=(c-D)*v,t[5]=(1-(h+x))*v,t[6]=(S+d)*v,t[7]=0,t[8]=(f+I)*b,t[9]=(S-d)*b,t[10]=(1-(h+m))*b,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},o.fromRotationTranslationScaleOrigin=function(t,a,r,n,o){var e=a[0],i=a[1],l=a[2],u=a[3],s=e+e,M=i+i,h=l+l,c=e*s,f=e*M,m=e*h,S=i*M,x=i*h,d=l*h,I=u*s,D=u*M,F=u*h,v=n[0],b=n[1],p=n[2],g=o[0],w=o[1],A=o[2];return t[0]=(1-(S+d))*v,t[1]=(f+F)*v,t[2]=(m-D)*v,t[3]=0,t[4]=(f-F)*b,t[5]=(1-(c+d))*b,t[6]=(x+I)*b,t[7]=0,t[8]=(m+D)*p,t[9]=(x-I)*p,t[10]=(1-(c+S))*p,t[11]=0,t[12]=r[0]+g-(t[0]*g+t[4]*w+t[8]*A),t[13]=r[1]+w-(t[1]*g+t[5]*w+t[9]*A),t[14]=r[2]+A-(t[2]*g+t[6]*w+t[10]*A),t[15]=1,t},o.fromQuat=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=r+r,l=n+n,u=o+o,s=r*i,M=n*i,h=n*l,c=o*i,f=o*l,m=o*u,S=e*i,x=e*l,d=e*u;return t[0]=1-h-m,t[1]=M+d,t[2]=c-x,t[3]=0,t[4]=M-d,t[5]=1-s-m,t[6]=f+S,t[7]=0,t[8]=c+x,t[9]=f-S,t[10]=1-s-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},o.frustum=function(t,a,r,n,o,e,i){var l=1/(r-a),u=1/(o-n),s=1/(e-i);return t[0]=2*e*l,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*e*u,t[6]=0,t[7]=0,t[8]=(r+a)*l,t[9]=(o+n)*u,t[10]=(i+e)*s,t[11]=-1,t[12]=0,t[13]=0,t[14]=i*e*2*s,t[15]=0,t},o.perspective=function(t,a,r,n,o){var e=1/Math.tan(a/2),i=1/(n-o);return t[0]=e/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(o+n)*i,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*o*n*i,t[15]=0,t},o.perspectiveFromFieldOfView=function(t,a,r,n){var o=Math.tan(a.upDegrees*Math.PI/180),e=Math.tan(a.downDegrees*Math.PI/180),i=Math.tan(a.leftDegrees*Math.PI/180),l=Math.tan(a.rightDegrees*Math.PI/180),u=2/(i+l),s=2/(o+e);return t[0]=u,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=-((i-l)*u*.5),t[9]=(o-e)*s*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t},o.ortho=function(t,a,r,n,o,e,i){var l=1/(a-r),u=1/(n-o),s=1/(e-i);return t[0]=-2*l,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*s,t[11]=0,t[12]=(a+r)*l,t[13]=(o+n)*u,t[14]=(i+e)*s,t[15]=1,t},o.lookAt=function(t,a,r,e){var i,l,u,s,M,h,c,f,m,S,x=a[0],d=a[1],I=a[2],D=e[0],F=e[1],v=e[2],b=r[0],p=r[1],g=r[2];return Math.abs(x-b)<n.EPSILON&&Math.abs(d-p)<n.EPSILON&&Math.abs(I-g)<n.EPSILON?o.identity(t):(c=x-b,f=d-p,m=I-g,S=1/Math.sqrt(c*c+f*f+m*m),c*=S,f*=S,m*=S,i=F*m-v*f,l=v*c-D*m,u=D*f-F*c,S=Math.sqrt(i*i+l*l+u*u),S?(S=1/S,i*=S,l*=S,u*=S):(i=0,l=0,u=0),s=f*u-m*l,M=m*i-c*u,h=c*l-f*i,S=Math.sqrt(s*s+M*M+h*h),S?(S=1/S,s*=S,M*=S,h*=S):(s=0,M=0,h=0),t[0]=i,t[1]=s,t[2]=c,t[3]=0,t[4]=l,t[5]=M,t[6]=f,t[7]=0,t[8]=u,t[9]=h,t[10]=m,t[11]=0,t[12]=-(i*x+l*d+u*I),t[13]=-(s*x+M*d+h*I),t[14]=-(c*x+f*d+m*I),t[15]=1,t)},o.str=function(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]+")"},o.frob=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2)+Math.pow(t[3],2)+Math.pow(t[4],2)+Math.pow(t[5],2)+Math.pow(t[6],2)+Math.pow(t[7],2)+Math.pow(t[8],2)+Math.pow(t[9],2)+Math.pow(t[10],2)+Math.pow(t[11],2)+Math.pow(t[12],2)+Math.pow(t[13],2)+Math.pow(t[14],2)+Math.pow(t[15],2))},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t[3]=a[3]+r[3],t[4]=a[4]+r[4],t[5]=a[5]+r[5],t[6]=a[6]+r[6],t[7]=a[7]+r[7],t[8]=a[8]+r[8],t[9]=a[9]+r[9],t[10]=a[10]+r[10],t[11]=a[11]+r[11],t[12]=a[12]+r[12],t[13]=a[13]+r[13],t[14]=a[14]+r[14],t[15]=a[15]+r[15],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t[3]=a[3]-r[3],t[4]=a[4]-r[4],t[5]=a[5]-r[5],t[6]=a[6]-r[6],t[7]=a[7]-r[7],t[8]=a[8]-r[8],t[9]=a[9]-r[9],t[10]=a[10]-r[10],t[11]=a[11]-r[11],t[12]=a[12]-r[12],t[13]=a[13]-r[13],t[14]=a[14]-r[14],t[15]=a[15]-r[15],t},o.sub=o.subtract,o.multiplyScalar=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t[4]=a[4]*r,t[5]=a[5]*r,t[6]=a[6]*r,t[7]=a[7]*r,t[8]=a[8]*r,t[9]=a[9]*r,t[10]=a[10]*r,t[11]=a[11]*r,t[12]=a[12]*r,t[13]=a[13]*r,t[14]=a[14]*r,t[15]=a[15]*r,t},o.multiplyScalarAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t[3]=a[3]+r[3]*n,t[4]=a[4]+r[4]*n,t[5]=a[5]+r[5]*n,t[6]=a[6]+r[6]*n,t[7]=a[7]+r[7]*n,t[8]=a[8]+r[8]*n,t[9]=a[9]+r[9]*n,t[10]=a[10]+r[10]*n,t[11]=a[11]+r[11]*n,t[12]=a[12]+r[12]*n,t[13]=a[13]+r[13]*n,t[14]=a[14]+r[14]*n,t[15]=a[15]+r[15]*n,t},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]&&t[4]===a[4]&&t[5]===a[5]&&t[6]===a[6]&&t[7]===a[7]&&t[8]===a[8]&&t[9]===a[9]&&t[10]===a[10]&&t[11]===a[11]&&t[12]===a[12]&&t[13]===a[13]&&t[14]===a[14]&&t[15]===a[15]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=t[3],l=t[4],u=t[5],s=t[6],M=t[7],h=t[8],c=t[9],f=t[10],m=t[11],S=t[12],x=t[13],d=t[14],I=t[15],D=a[0],F=a[1],v=a[2],b=a[3],p=a[4],g=a[5],w=a[6],A=a[7],E=a[8],R=a[9],T=a[10],L=a[11],z=a[12],P=a[13],_=a[14],y=a[15];return Math.abs(r-D)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(D))&&Math.abs(o-F)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(F))&&Math.abs(e-v)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(v))&&Math.abs(i-b)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(b))&&Math.abs(l-p)<=n.EPSILON*Math.max(1,Math.abs(l),Math.abs(p))&&Math.abs(u-g)<=n.EPSILON*Math.max(1,Math.abs(u),Math.abs(g))&&Math.abs(s-w)<=n.EPSILON*Math.max(1,Math.abs(s),Math.abs(w))&&Math.abs(M-A)<=n.EPSILON*Math.max(1,Math.abs(M),Math.abs(A))&&Math.abs(h-E)<=n.EPSILON*Math.max(1,Math.abs(h),Math.abs(E))&&Math.abs(c-R)<=n.EPSILON*Math.max(1,Math.abs(c),Math.abs(R))&&Math.abs(f-T)<=n.EPSILON*Math.max(1,Math.abs(f),Math.abs(T))&&Math.abs(m-L)<=n.EPSILON*Math.max(1,Math.abs(m),Math.abs(L))&&Math.abs(S-z)<=n.EPSILON*Math.max(1,Math.abs(S),Math.abs(z))&&Math.abs(x-P)<=n.EPSILON*Math.max(1,Math.abs(x),Math.abs(P))&&Math.abs(d-_)<=n.EPSILON*Math.max(1,Math.abs(d),Math.abs(_))&&Math.abs(I-y)<=n.EPSILON*Math.max(1,Math.abs(I),Math.abs(y))},t.exports=o},function(t,a,r){var n=r(2),o=r(5),e=r(8),i=r(9),l={};l.create=function(){var t=new n.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},l.rotationTo=function(){var t=e.create(),a=e.fromValues(1,0,0),r=e.fromValues(0,1,0);return function(n,o,i){var u=e.dot(o,i);return u<-.999999?(e.cross(t,a,o),e.length(t)<1e-6&&e.cross(t,r,o),e.normalize(t,t),l.setAxisAngle(n,t,Math.PI),n):u>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(e.cross(t,o,i),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=1+u,l.normalize(n,n))}}(),l.setAxes=function(){var t=o.create();return function(a,r,n,o){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=o[0],t[4]=o[1],t[7]=o[2],t[2]=-r[0],t[5]=-r[1],t[8]=-r[2],l.normalize(a,l.fromMat3(a,t))}}(),l.clone=i.clone,l.fromValues=i.fromValues,l.copy=i.copy,l.set=i.set,l.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},l.setAxisAngle=function(t,a,r){r=.5*r;var n=Math.sin(r);return t[0]=n*a[0],t[1]=n*a[1],t[2]=n*a[2],t[3]=Math.cos(r),t},l.getAxisAngle=function(t,a){var r=2*Math.acos(a[3]),n=Math.sin(r/2);return 0!=n?(t[0]=a[0]/n,t[1]=a[1]/n,t[2]=a[2]/n):(t[0]=1,t[1]=0,t[2]=0),r},l.add=i.add,l.multiply=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3],l=r[0],u=r[1],s=r[2],M=r[3];return t[0]=n*M+i*l+o*s-e*u,t[1]=o*M+i*u+e*l-n*s,t[2]=e*M+i*s+n*u-o*l,t[3]=i*M-n*l-o*u-e*s,t},l.mul=l.multiply,l.scale=i.scale,l.rotateX=function(t,a,r){r*=.5;var n=a[0],o=a[1],e=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*l,t[1]=o*u+e*l,t[2]=e*u-o*l,t[3]=i*u-n*l,t},l.rotateY=function(t,a,r){r*=.5;var n=a[0],o=a[1],e=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u-e*l,t[1]=o*u+i*l,t[2]=e*u+n*l,t[3]=i*u-o*l,t},l.rotateZ=function(t,a,r){r*=.5;var n=a[0],o=a[1],e=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+o*l,t[1]=o*u-n*l,t[2]=e*u+i*l,t[3]=i*u-e*l,t},l.calculateW=function(t,a){var r=a[0],n=a[1],o=a[2];return t[0]=r,t[1]=n,t[2]=o,t[3]=Math.sqrt(Math.abs(1-r*r-n*n-o*o)),t},l.dot=i.dot,l.lerp=i.lerp,l.slerp=function(t,a,r,n){var o,e,i,l,u,s=a[0],M=a[1],h=a[2],c=a[3],f=r[0],m=r[1],S=r[2],x=r[3];return e=s*f+M*m+h*S+c*x,e<0&&(e=-e,f=-f,m=-m,S=-S,x=-x),1-e>1e-6?(o=Math.acos(e),i=Math.sin(o),l=Math.sin((1-n)*o)/i,u=Math.sin(n*o)/i):(l=1-n,u=n),t[0]=l*s+u*f,t[1]=l*M+u*m,t[2]=l*h+u*S,t[3]=l*c+u*x,t},l.sqlerp=function(){var t=l.create(),a=l.create();return function(r,n,o,e,i,u){return l.slerp(t,n,i,u),l.slerp(a,o,e,u),l.slerp(r,t,a,2*u*(1-u)),r}}(),l.invert=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=r*r+n*n+o*o+e*e,l=i?1/i:0;return t[0]=-r*l,t[1]=-n*l,t[2]=-o*l,t[3]=e*l,t},l.conjugate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t[3]=a[3],t},l.length=i.length,l.len=l.length,l.squaredLength=i.squaredLength,l.sqrLen=l.squaredLength,l.normalize=i.normalize,l.fromMat3=function(t,a){var r,n=a[0]+a[4]+a[8];if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(a[5]-a[7])*r,t[1]=(a[6]-a[2])*r,t[2]=(a[1]-a[3])*r;else{var o=0;a[4]>a[0]&&(o=1),a[8]>a[3*o+o]&&(o=2);var e=(o+1)%3,i=(o+2)%3;r=Math.sqrt(a[3*o+o]-a[3*e+e]-a[3*i+i]+1),t[o]=.5*r,r=.5/r,t[3]=(a[3*e+i]-a[3*i+e])*r,t[e]=(a[3*e+o]+a[3*o+e])*r,t[i]=(a[3*i+o]+a[3*o+i])*r}return t},l.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},l.exactEquals=i.exactEquals,l.equals=i.equals,t.exports=l},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(3);return t[0]=0,t[1]=0,t[2]=0,t},o.clone=function(t){var a=new n.ARRAY_TYPE(3);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a},o.fromValues=function(t,a,r){var o=new n.ARRAY_TYPE(3);return o[0]=t,o[1]=a,o[2]=r,o},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t},o.set=function(t,a,r,n){return t[0]=a,t[1]=r,t[2]=n,t},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t},o.sub=o.subtract,o.multiply=function(t,a,r){return t[0]=a[0]*r[0],t[1]=a[1]*r[1],t[2]=a[2]*r[2],t},o.mul=o.multiply,o.divide=function(t,a,r){return t[0]=a[0]/r[0],t[1]=a[1]/r[1],t[2]=a[2]/r[2],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t[2]=Math.ceil(a[2]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t[2]=Math.floor(a[2]),t},o.min=function(t,a,r){return t[0]=Math.min(a[0],r[0]),t[1]=Math.min(a[1],r[1]),t[2]=Math.min(a[2],r[2]),t},o.max=function(t,a,r){return t[0]=Math.max(a[0],r[0]),t[1]=Math.max(a[1],r[1]),t[2]=Math.max(a[2],r[2]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t[2]=Math.round(a[2]),t},o.scale=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t},o.scaleAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t},o.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],o=a[2]-t[2];return Math.sqrt(r*r+n*n+o*o)},o.dist=o.distance,o.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],o=a[2]-t[2];return r*r+n*n+o*o},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],r=t[1],n=t[2];return Math.sqrt(a*a+r*r+n*n)},o.len=o.length,o.squaredLength=function(t){var a=t[0],r=t[1],n=t[2];return a*a+r*r+n*n},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t[2]=1/a[2],t},o.normalize=function(t,a){var r=a[0],n=a[1],o=a[2],e=r*r+n*n+o*o;return e>0&&(e=1/Math.sqrt(e),t[0]=a[0]*e,t[1]=a[1]*e,t[2]=a[2]*e),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]},o.cross=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=r[0],l=r[1],u=r[2];return t[0]=o*u-e*l,t[1]=e*i-n*u,t[2]=n*l-o*i,t},o.lerp=function(t,a,r,n){var o=a[0],e=a[1],i=a[2];return t[0]=o+n*(r[0]-o),t[1]=e+n*(r[1]-e),t[2]=i+n*(r[2]-i),t},o.hermite=function(t,a,r,n,o,e){var i=e*e,l=i*(2*e-3)+1,u=i*(e-2)+e,s=i*(e-1),M=i*(3-2*e);return t[0]=a[0]*l+r[0]*u+n[0]*s+o[0]*M,t[1]=a[1]*l+r[1]*u+n[1]*s+o[1]*M,t[2]=a[2]*l+r[2]*u+n[2]*s+o[2]*M,t},o.bezier=function(t,a,r,n,o,e){var i=1-e,l=i*i,u=e*e,s=l*i,M=3*e*l,h=3*u*i,c=u*e;return t[0]=a[0]*s+r[0]*M+n[0]*h+o[0]*c,t[1]=a[1]*s+r[1]*M+n[1]*h+o[1]*c,t[2]=a[2]*s+r[2]*M+n[2]*h+o[2]*c,t},o.random=function(t,a){a=a||1;var r=2*n.RANDOM()*Math.PI,o=2*n.RANDOM()-1,e=Math.sqrt(1-o*o)*a;return t[0]=Math.cos(r)*e,t[1]=Math.sin(r)*e,t[2]=o*a,t},o.transformMat4=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=r[3]*n+r[7]*o+r[11]*e+r[15];return i=i||1,t[0]=(r[0]*n+r[4]*o+r[8]*e+r[12])/i,t[1]=(r[1]*n+r[5]*o+r[9]*e+r[13])/i,t[2]=(r[2]*n+r[6]*o+r[10]*e+r[14])/i,t},o.transformMat3=function(t,a,r){var n=a[0],o=a[1],e=a[2];return t[0]=n*r[0]+o*r[3]+e*r[6],t[1]=n*r[1]+o*r[4]+e*r[7],t[2]=n*r[2]+o*r[5]+e*r[8],t},o.transformQuat=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=r[0],l=r[1],u=r[2],s=r[3],M=s*n+l*e-u*o,h=s*o+u*n-i*e,c=s*e+i*o-l*n,f=-i*n-l*o-u*e;return t[0]=M*s+f*-i+h*-u-c*-l,t[1]=h*s+f*-l+c*-i-M*-u,t[2]=c*s+f*-u+M*-l-h*-i,t},o.rotateX=function(t,a,r,n){var o=[],e=[];return o[0]=a[0]-r[0],o[1]=a[1]-r[1],o[2]=a[2]-r[2],e[0]=o[0],e[1]=o[1]*Math.cos(n)-o[2]*Math.sin(n),e[2]=o[1]*Math.sin(n)+o[2]*Math.cos(n),t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},o.rotateY=function(t,a,r,n){var o=[],e=[];return o[0]=a[0]-r[0],o[1]=a[1]-r[1],o[2]=a[2]-r[2],e[0]=o[2]*Math.sin(n)+o[0]*Math.cos(n),e[1]=o[1],e[2]=o[2]*Math.cos(n)-o[0]*Math.sin(n),t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},o.rotateZ=function(t,a,r,n){var o=[],e=[];return o[0]=a[0]-r[0],o[1]=a[1]-r[1],o[2]=a[2]-r[2],e[0]=o[0]*Math.cos(n)-o[1]*Math.sin(n),e[1]=o[0]*Math.sin(n)+o[1]*Math.cos(n),e[2]=o[2],t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t},o.forEach=function(){var t=o.create();return function(a,r,n,o,e,i){var l,u;for(r||(r=3),n||(n=0),u=o?Math.min(o*r+n,a.length):a.length,l=n;l<u;l+=r)t[0]=a[l],t[1]=a[l+1],t[2]=a[l+2],e(t,t,i),a[l]=t[0],a[l+1]=t[1],a[l+2]=t[2];return a}}(),o.angle=function(t,a){var r=o.fromValues(t[0],t[1],t[2]),n=o.fromValues(a[0],a[1],a[2]);o.normalize(r,r),o.normalize(n,n);var e=o.dot(r,n);return e>1?0:Math.acos(e)},o.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=a[0],l=a[1],u=a[2];return Math.abs(r-i)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(i))&&Math.abs(o-l)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(l))&&Math.abs(e-u)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(u))},t.exports=o},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},o.clone=function(t){var a=new n.ARRAY_TYPE(4);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a[3]=t[3],a},o.fromValues=function(t,a,r,o){var e=new n.ARRAY_TYPE(4);return e[0]=t,e[1]=a,e[2]=r,e[3]=o,e},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},o.set=function(t,a,r,n,o){return t[0]=a,t[1]=r,t[2]=n,t[3]=o,t},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t[2]=a[2]+r[2],t[3]=a[3]+r[3],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t[2]=a[2]-r[2],t[3]=a[3]-r[3],t},o.sub=o.subtract,o.multiply=function(t,a,r){return t[0]=a[0]*r[0],t[1]=a[1]*r[1],t[2]=a[2]*r[2],t[3]=a[3]*r[3],t},o.mul=o.multiply,o.divide=function(t,a,r){return t[0]=a[0]/r[0],t[1]=a[1]/r[1],t[2]=a[2]/r[2],t[3]=a[3]/r[3],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t[2]=Math.ceil(a[2]),t[3]=Math.ceil(a[3]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t[2]=Math.floor(a[2]),t[3]=Math.floor(a[3]),t},o.min=function(t,a,r){return t[0]=Math.min(a[0],r[0]),t[1]=Math.min(a[1],r[1]),t[2]=Math.min(a[2],r[2]),t[3]=Math.min(a[3],r[3]),t},o.max=function(t,a,r){return t[0]=Math.max(a[0],r[0]),t[1]=Math.max(a[1],r[1]),t[2]=Math.max(a[2],r[2]),t[3]=Math.max(a[3],r[3]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t[2]=Math.round(a[2]),t[3]=Math.round(a[3]),t},o.scale=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t[3]=a[3]*r,t},o.scaleAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t[2]=a[2]+r[2]*n,t[3]=a[3]+r[3]*n,t},o.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],o=a[2]-t[2],e=a[3]-t[3];return Math.sqrt(r*r+n*n+o*o+e*e)},o.dist=o.distance,o.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],o=a[2]-t[2],e=a[3]-t[3];return r*r+n*n+o*o+e*e},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],r=t[1],n=t[2],o=t[3];return Math.sqrt(a*a+r*r+n*n+o*o)},o.len=o.length,o.squaredLength=function(t){var a=t[0],r=t[1],n=t[2],o=t[3];return a*a+r*r+n*n+o*o},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t[3]=-a[3],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t[2]=1/a[2],t[3]=1/a[3],t},o.normalize=function(t,a){var r=a[0],n=a[1],o=a[2],e=a[3],i=r*r+n*n+o*o+e*e;return i>0&&(i=1/Math.sqrt(i),t[0]=r*i,t[1]=n*i,t[2]=o*i,t[3]=e*i),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]+t[3]*a[3]},o.lerp=function(t,a,r,n){var o=a[0],e=a[1],i=a[2],l=a[3];return t[0]=o+n*(r[0]-o),t[1]=e+n*(r[1]-e),t[2]=i+n*(r[2]-i),t[3]=l+n*(r[3]-l),t},o.random=function(t,a){return a=a||1,t[0]=n.RANDOM(),t[1]=n.RANDOM(),t[2]=n.RANDOM(),t[3]=n.RANDOM(),o.normalize(t,t),o.scale(t,t,a),t},o.transformMat4=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=a[3];return t[0]=r[0]*n+r[4]*o+r[8]*e+r[12]*i,t[1]=r[1]*n+r[5]*o+r[9]*e+r[13]*i,t[2]=r[2]*n+r[6]*o+r[10]*e+r[14]*i,t[3]=r[3]*n+r[7]*o+r[11]*e+r[15]*i,t},o.transformQuat=function(t,a,r){var n=a[0],o=a[1],e=a[2],i=r[0],l=r[1],u=r[2],s=r[3],M=s*n+l*e-u*o,h=s*o+u*n-i*e,c=s*e+i*o-l*n,f=-i*n-l*o-u*e;return t[0]=M*s+f*-i+h*-u-c*-l,t[1]=h*s+f*-l+c*-i-M*-u,t[2]=c*s+f*-u+M*-l-h*-i,t[3]=a[3],t},o.forEach=function(){var t=o.create();return function(a,r,n,o,e,i){var l,u;for(r||(r=4),n||(n=0),u=o?Math.min(o*r+n,a.length):a.length,l=n;l<u;l+=r)t[0]=a[l],t[1]=a[l+1],t[2]=a[l+2],t[3]=a[l+3],e(t,t,i),a[l]=t[0],a[l+1]=t[1],a[l+2]=t[2],a[l+3]=t[3];return a}}(),o.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},o.equals=function(t,a){var r=t[0],o=t[1],e=t[2],i=t[3],l=a[0],u=a[1],s=a[2],M=a[3];return Math.abs(r-l)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(l))&&Math.abs(o-u)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(u))&&Math.abs(e-s)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(s))&&Math.abs(i-M)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(M))},t.exports=o},function(t,a,r){var n=r(2),o={};o.create=function(){var t=new n.ARRAY_TYPE(2);return t[0]=0,t[1]=0,t},o.clone=function(t){var a=new n.ARRAY_TYPE(2);return a[0]=t[0],a[1]=t[1],a},o.fromValues=function(t,a){var r=new n.ARRAY_TYPE(2);return r[0]=t,r[1]=a,r},o.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t},o.set=function(t,a,r){return t[0]=a,t[1]=r,t},o.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t},o.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t},o.sub=o.subtract,o.multiply=function(t,a,r){return t[0]=a[0]*r[0],t[1]=a[1]*r[1],t},o.mul=o.multiply,o.divide=function(t,a,r){return t[0]=a[0]/r[0],t[1]=a[1]/r[1],t},o.div=o.divide,o.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t},o.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t},o.min=function(t,a,r){return t[0]=Math.min(a[0],r[0]),t[1]=Math.min(a[1],r[1]),t},o.max=function(t,a,r){return t[0]=Math.max(a[0],r[0]),t[1]=Math.max(a[1],r[1]),t},o.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t},o.scale=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t},o.scaleAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t},o.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1];return Math.sqrt(r*r+n*n)},o.dist=o.distance,o.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1];return r*r+n*n},o.sqrDist=o.squaredDistance,o.length=function(t){var a=t[0],r=t[1];return Math.sqrt(a*a+r*r)},o.len=o.length,o.squaredLength=function(t){var a=t[0],r=t[1];return a*a+r*r},o.sqrLen=o.squaredLength,o.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t},o.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t},o.normalize=function(t,a){var r=a[0],n=a[1],o=r*r+n*n;return o>0&&(o=1/Math.sqrt(o),t[0]=a[0]*o,t[1]=a[1]*o),t},o.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]},o.cross=function(t,a,r){var n=a[0]*r[1]-a[1]*r[0];return t[0]=t[1]=0,t[2]=n,t},o.lerp=function(t,a,r,n){var o=a[0],e=a[1];return t[0]=o+n*(r[0]-o),t[1]=e+n*(r[1]-e),t},o.random=function(t,a){a=a||1;var r=2*n.RANDOM()*Math.PI;return t[0]=Math.cos(r)*a,t[1]=Math.sin(r)*a,t},o.transformMat2=function(t,a,r){var n=a[0],o=a[1];return t[0]=r[0]*n+r[2]*o,t[1]=r[1]*n+r[3]*o,t},o.transformMat2d=function(t,a,r){var n=a[0],o=a[1];return t[0]=r[0]*n+r[2]*o+r[4],t[1]=r[1]*n+r[3]*o+r[5],t},o.transformMat3=function(t,a,r){var n=a[0],o=a[1];return t[0]=r[0]*n+r[3]*o+r[6],t[1]=r[1]*n+r[4]*o+r[7],t},o.transformMat4=function(t,a,r){var n=a[0],o=a[1];return t[0]=r[0]*n+r[4]*o+r[12],t[1]=r[1]*n+r[5]*o+r[13],t},o.forEach=function(){var t=o.create();return function(a,r,n,o,e,i){var l,u;for(r||(r=2),n||(n=0),u=o?Math.min(o*r+n,a.length):a.length,l=n;l<u;l+=r)t[0]=a[l],t[1]=a[l+1],e(t,t,i),a[l]=t[0],a[l+1]=t[1];return a}}(),o.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},o.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]},o.equals=function(t,a){var r=t[0],o=t[1],e=a[0],i=a[1];return Math.abs(r-e)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(e))&&Math.abs(o-i)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(i))},t.exports=o},function(t,a,r){"use strict";var n=r(12);a.Camera=n.Camera;var o=r(13);a.Light=o.Light;var e=r(14);a.Material=e.Material;var i=r(15);a.Mesh=i.Mesh;var l=r(16);a.Scene=l.Scene;var u=r(17);a.Shader=u.Shader;var s=r(18);a.Sphere=s.Sphere;var M=r(19);a.WebGLUtils=M.WebGLUtils},function(t,a,r){"use strict";var n=r(1),o=function(){function t(t,a,r,o,e,i,l){this.eye=t,this.center=a,this.up=r,this.fov=o,this.aspect=e,this.near=i,this.far=l,this.worldToCamera=n.mat4.create(),n.mat4.lookAt(this.worldToCamera,this.eye,this.center,this.up),this.cameraToWorld=n.mat4.create(),n.mat4.invert(this.cameraToWorld,this.worldToCamera),this.cameraToClip=n.mat4.create(),n.mat4.perspective(this.cameraToClip,this.fov,this.aspect,this.near,this.far),this.clipToCamera=n.mat4.create(),n.mat4.invert(this.clipToCamera,this.cameraToClip)}return t}();a.Camera=o},function(t,a){"use strict";var r=function(){function t(t,a,r,n){this.position=t,this.ambient=a,this.diffuse=r,this.specular=n}return t}();a.Light=r},function(t,a){"use strict";var r=function(){function t(t,a,r,n,o,e){this.ambient=a,this.diffuse=r,this.specular=n,this.shine=o,this.buildTexture(t,e)}return t.prototype.buildTexture=function(t,a){this.texture=t.createTexture(),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.bindTexture(t.TEXTURE_2D,this.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_NEAREST),t.generateMipmap(t.TEXTURE_2D),t.bindTexture(t.TEXTURE_2D,null)},t}();a.Material=r},function(t,a){"use strict";var r=function(){function t(t){this.material=t}return t}();a.Mesh=r},function(t,a){"use strict";var r=function(){function t(t,a){this.meshes=t,this.light=a}return t}();a.Scene=r},function(t,a,r){"use strict";var n=r(1),o=function(){function t(t,a,r){this.gl=t;var n=this.createProgram(t,a,r);return n?(t.useProgram(n),void(t.program=n)):void console.log("Shader.ts: constructor: Failed to create program: ",n)}return t.prototype.draw=function(t,a){var r=this;t.meshes.forEach(function(n){r.setPosition(n),r.setNormal(n),r.setTextureCoords(n),r.activateTexture(n.material),r.setUniformsSampler(),r.setUniformsModelViewMatrix(n,a),r.setUniformsNormalMatrix(n,a),r.setUniformsProjectionMatrix(a),r.setUniformsModelViewProjectionMatrix(n,a),r.setUniformsLights(t.light),r.setUniformsMaterials(n),r.gl.drawElements(r.gl.TRIANGLES,n.indicesCount,r.gl.UNSIGNED_SHORT,0)})},t.prototype.createProgram=function(t,a,r){var n=this.loadShader(t,t.VERTEX_SHADER,a),o=this.loadShader(t,t.FRAGMENT_SHADER,r);if(!n||!o)return console.log("Shader.ts: createProgram: No vertex shader or fragment shader: ",n,", ",o),null;var e=t.createProgram();if(!e)return console.log("Shader.ts: createProgram: No program: ",e),null;t.attachShader(e,n),t.attachShader(e,o),t.linkProgram(e);var i=t.getProgramParameter(e,t.LINK_STATUS);if(!i){var l=t.getProgramInfoLog(e);return console.log("Shader.ts: createProgram: Failed to link program: "+l),t.deleteProgram(e),t.deleteShader(o),t.deleteShader(n),null}return e},t.prototype.loadShader=function(t,a,r){var n=t.createShader(a);if(null==n)return console.log("Shader.ts: loadShader: shader === null."),null;t.shaderSource(n,r),t.compileShader(n);var o=t.getShaderParameter(n,t.COMPILE_STATUS);if(!o){var e=t.getShaderInfoLog(n);return console.log("Shader.ts: loadShader: Failed to compile shader: "+e),t.deleteShader(n),null}return n},t.prototype.setPosition=function(t){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.positionsBuffer);var a=this.gl.getAttribLocation(this.gl.program,"a_Position");a>-1&&(this.gl.vertexAttribPointer(a,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(a))},t.prototype.setNormal=function(t){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.normalsBuffer);var a=this.gl.getAttribLocation(this.gl.program,"a_Normal");a>-1&&(this.gl.vertexAttribPointer(a,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(a))},t.prototype.setTextureCoords=function(t){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t.textureCoordsBuffer);var a=this.gl.getAttribLocation(this.gl.program,"a_TexCoord");a>-1&&(this.gl.vertexAttribPointer(a,2,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(a))},t.prototype.activateTexture=function(t){this.gl.activeTexture(this.gl.TEXTURE0),this.gl.bindTexture(this.gl.TEXTURE_2D,t.texture)},t.prototype.setUniformsSampler=function(){var t=this.gl.getUniformLocation(this.gl.program,"u_Sampler");t>-1&&this.gl.uniform1i(t,0)},t.prototype.setUniformsModelViewMatrix=function(t,a){var r=n.mat4.create();n.mat4.multiply(r,a.worldToCamera,t.modelToWorld);var o=this.gl.getUniformLocation(this.gl.program,"u_ModelViewMatrix");this.gl.uniformMatrix4fv(o,!1,r);var e=n.mat4.create();n.mat4.invert(e,r);var i=this.gl.getUniformLocation(this.gl.program,"u_ModelViewMatrixInverse");this.gl.uniformMatrix4fv(i,!1,e)},t.prototype.setUniformsNormalMatrix=function(t,a){var r=n.mat4.create();n.mat4.multiply(r,a.worldToCamera,t.modelToWorld);var o=n.mat3.create();n.mat3.fromMat4(o,r);var e=this.gl.getUniformLocation(this.gl.program,"u_NormalMatrix");this.gl.uniformMatrix3fv(e,!1,o)},t.prototype.setUniformsProjectionMatrix=function(t){var a=this.gl.getUniformLocation(this.gl.program,"u_ProjectionMatrix");this.gl.uniformMatrix4fv(a,!1,t.cameraToClip);var r=this.gl.getUniformLocation(this.gl.program,"u_ProjectionMatrixInverse");this.gl.uniformMatrix4fv(r,!1,t.clipToCamera)},t.prototype.setUniformsModelViewProjectionMatrix=function(t,a){var r=n.mat4.create();n.mat4.multiply(r,a.worldToCamera,t.modelToWorld);var o=n.mat4.create();n.mat4.multiply(o,a.cameraToClip,r);var e=this.gl.getUniformLocation(this.gl.program,"u_ModelViewProjectionMatrix");this.gl.uniformMatrix4fv(e,!1,o);var i=n.mat4.create();n.mat4.invert(i,o);var l=this.gl.getUniformLocation(this.gl.program,"u_ModelViewProjectionMatrixInverse");this.gl.uniformMatrix4fv(l,!1,i)},t.prototype.setUniformsLights=function(t){if(t){if(t.position){var a=this.gl.getUniformLocation(this.gl.program,"u_Light.position");this.gl.uniform4fv(a,t.position)}if(t.ambient){var r=this.gl.getUniformLocation(this.gl.program,"u_Light.ambient");this.gl.uniform3fv(r,t.ambient)}if(t.diffuse){var n=this.gl.getUniformLocation(this.gl.program,"u_Light.diffuse");this.gl.uniform3fv(n,t.diffuse)}if(t.specular){var o=this.gl.getUniformLocation(this.gl.program,"u_Light.specular");this.gl.uniform3fv(o,t.specular)}}},t.prototype.setUniformsMaterials=function(t){if(t.material){if(t.material.ambient){var a=this.gl.getUniformLocation(this.gl.program,"u_Material.ambient");this.gl.uniform3fv(a,t.material.ambient)}if(t.material.diffuse){var r=this.gl.getUniformLocation(this.gl.program,"u_Material.diffuse");this.gl.uniform3fv(r,t.material.diffuse)}if(t.material.specular){var n=this.gl.getUniformLocation(this.gl.program,"u_Material.specular");this.gl.uniform3fv(n,t.material.specular)}if(t.material.shine){var o=this.gl.getUniformLocation(this.gl.program,"u_Material.shine");this.gl.uniform1f(o,t.material.shine)}}},t}();a.Shader=o},function(t,a,r){"use strict";var n=this&&this.__extends||function(t,a){function r(){this.constructor=t}for(var n in a)a.hasOwnProperty(n)&&(t[n]=a[n]);t.prototype=null===a?Object.create(a):(r.prototype=a.prototype,new r)},o=r(1),e=r(15),i=function(t){function a(a,r,n,o,e){t.call(this,r),this.radius=n,this.latitudeBands=o,this.longitudeBands=e,this.buildArrays(),this.buildBuffers(a),this.buildTransforms()}return n(a,t),a.prototype.buildArrays=function(){for(var t=[],a=[],r=[],n=[],o=0;o<=this.latitudeBands;++o)for(var e=o*Math.PI/this.latitudeBands,i=Math.sin(e),l=Math.cos(e),u=0;u<=this.longitudeBands;++u){var s=2*u*Math.PI/this.longitudeBands,M=Math.sin(s),h=Math.cos(s),c=h*i,f=l,m=M*i,S=1-u/this.longitudeBands,x=1-o/this.latitudeBands;t.push(this.radius*c),t.push(this.radius*f),t.push(this.radius*m),a.push(c),a.push(f),a.push(m),r.push(S),r.push(x)}for(var o=0;o<this.latitudeBands;++o)for(var u=0;u<this.longitudeBands;++u){var d=o*(this.longitudeBands+1)+u,I=d+this.longitudeBands+1;n.push(d),n.push(I),n.push(d+1),n.push(I),n.push(I+1),n.push(d+1)}this.indicesCount=n.length,this.positions=new Float32Array(t),this.normals=new Float32Array(a),this.textureCoords=new Float32Array(r),this.indices=new Uint16Array(n)},a.prototype.buildBuffers=function(t){this.positionsBuffer=t.createBuffer(),this.normalsBuffer=t.createBuffer(),this.textureCoordsBuffer=t.createBuffer(),this.indicesBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.positionsBuffer),t.bufferData(t.ARRAY_BUFFER,this.positions,t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,this.normalsBuffer),t.bufferData(t.ARRAY_BUFFER,this.normals,t.STATIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,this.textureCoordsBuffer),t.bufferData(t.ARRAY_BUFFER,this.textureCoords,t.STATIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.indicesBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indices,t.STATIC_DRAW)},a.prototype.buildTransforms=function(){this.modelToWorld=o.mat4.create(),this.worldToModel=o.mat4.create(),o.mat4.invert(this.worldToModel,this.modelToWorld)},a}(e.Mesh);a.Sphere=i},function(t,a){"use strict";var r=function(){function t(){}return t.requestAnimationFrame=function(){window.requestAnimationFrame||(window.requestAnimationFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t,a){window.setTimeout(t,1e3/60)}}())},t.cancelAnimationFrame=function(){window.cancelAnimationFrame||(window.cancelAnimationFrame=window.cancelRequestAnimationFrame||window.webkitCancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelAnimationFrame||window.mozCancelRequestAnimationFrame||window.msCancelAnimationFrame||window.msCancelRequestAnimationFrame||window.oCancelAnimationFrame||window.oCancelRequestAnimationFrame||window.clearTimeout)},t.makeFailHTML=function(t){return"<div style='margin: auto; width:500px;z-index:10000;margin-top:20em;text-align:center;'>"+t+"</div>";
},t.handleCreationError=function(t){var a=document.getElementsByTagName("body")[0];if(a){var r=window.WebGLRenderingContext?this.OTHER_PROBLEM:this.GET_A_WEBGL_BROWSER;t&&(r+="<br/><br/>Status: "+t),a.innerHTML=this.makeFailHTML(r)}},t.setupWebGL=function(t,a,r){r=r||this.handleCreationError,t.addEventListener&&t.addEventListener("webglcontextcreationerror",function(t){r(t.statusMessage)},!1);var n=this.create3DContext(t,a);return n||r(window.WebGLRenderingContext?"":""),n},t.create3DContext=function(t,a){for(var r=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<r.length;++o){try{n=t.getContext(r[o],a)}catch(e){}if(n)break}return n},t.animate=function(t,a){function r(){var e=(new Date).getTime();t&&t((e-o)/1e3),a&&a(),n(r),o=e}var n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(t){setTimeout(t,1e3/60)},o=(new Date).getTime();r()},t.GET_A_WEBGL_BROWSER='This page requires a browser that supports WebGL.<br/><a href="http://get.webgl.org">Click here to upgrade your browser.</a>',t.OTHER_PROBLEM='It doesn\'t appear your computer can support WebGL.<br/><a href="http://get.webgl.org">Click here for more information.</a>',t}();a.WebGLUtils=r}]);
<!doctype html>
<meta charset="utf-8">
<canvas id="webgl" width="512" height="512">
Please use a browser that supports canvas.
</canvas>
<script src="bundle.js"></script>
import * as glMatrix from 'gl-matrix';
import { Camera, Material, Scene, Sphere, Shader, WebGLUtils } from './src';
let angle: number = 0;
let shader: Shader;
let camera: Camera;
let earthMaterial: Material;
let earth: Sphere;
let scene: Scene;
let canvas = document.getElementById('webgl');
let gl = WebGLUtils.setupWebGL(canvas, null, null);
let earthImage = new Image();
earthImage.src = './earth.jpg';
earthImage.onload = () => setupScene();
const vertexShaderSource = `
attribute vec3 a_Position;
attribute vec2 a_TexCoord;
uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 v_TexCoord;
void main() {
// Output tex coord to frag shader.
v_TexCoord = a_TexCoord;
// Output the final position.
gl_Position = u_ModelViewProjectionMatrix * vec4(a_Position, 1.0);
}
`;
const fragmentShaderSource = `
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_Sampler;
varying vec2 v_TexCoord;
void main() {
// Get texture color for tex coord.
gl_FragColor = texture2D(u_Sampler, v_TexCoord);
}
`;
function setupScene() {
// Setup shader.
shader = new Shader(gl, vertexShaderSource, fragmentShaderSource);
// Setup camera.
let eye = [0.0, 0.0, 5.0];
let center = [0.0, 0.0, 0.0];
let up = [0.0, 1.0, 0.0];
let fov = Math.PI / 3;
let aspect = 1.0;
let near = 0.1;
let far = 100.0;
camera = new Camera(eye, center, up, fov, aspect, near, far);
// Setup Earth.
earthMaterial = new Material(gl, null, null, null, null, earthImage);
earth = new Sphere(gl, earthMaterial, 2, 250, 250);
// Setup scene.
scene = new Scene([earth], null);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);
WebGLUtils.animate(update, draw);
}
function update(seconds: number) {
angle += (Math.PI / 4) * seconds;
}
function draw() {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
earth.modelToWorld = glMatrix.mat4.create();
glMatrix.mat4.rotateY(earth.modelToWorld, earth.modelToWorld, -angle);
shader.draw(scene, camera);
}
@rickiesmooth
Copy link

is the custom library open sourced somewhere? or can you recommend a lightweight library that provides similair classes? I wanted to tweak this example a bit so it fits my use case.

@camargo
Copy link
Author

camargo commented May 29, 2020

@rickiesmooth Sorry I don't have the library code for this anymore. Have you tried using https://threejs.org/? It has a similar API and is easy to get started with.

@rickiesmooth
Copy link

I liked how small your example was (all js is just 13kb gzipped), three.js is a bit heavy for my usecase, but probably a good starting point for me to learn more about webgl. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment