This example demonstrates a WebGL Solar System drawing via a custom matrix stack. See this blocks index.ts
file for the code.
Libraries used include glMatrix, and a custom WebGL TypeScript library I made.
Last active
October 23, 2016 23:44
-
-
Save camargo/3cede95d26e12294690efdeeabdcd0f5 to your computer and use it in GitHub Desktop.
WebGL Solar System via Custom Matrix Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
border: no | |
height: 512 | |
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<meta charset="utf-8"> | |
<canvas id="webgl" width="512" height="512"> | |
Please use a browser that supports canvas. | |
</canvas> | |
<script src="index.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(t){function a(n){if(r[n])return r[n].exports;var e=r[n]={exports:{},id:n,loaded:!1};return t[n].call(e.exports,e,e.exports,a),e.loaded=!0,e.exports}var r={};return a.m=t,a.c=r,a.p="",a(0)}([function(t,a,r){"use strict";function n(){if(v.complete&&b.complete&&g.complete&&w.complete&&A.complete&&E.complete&&R.complete&&T.complete&&L.complete){i=new I.Shader(F,B,C);var t=[0,3.9,3.9],a=[0,0,0],r=[0,1,0],n=Math.PI/3,d=1,D=.1,p=100;l=new I.Camera(t,a,r,n,d,D,p),u=new I.Sphere(F,new I.Material(F,null,null,null,null,v),1,250,250),s=new I.Sphere(F,new I.Material(F,null,null,null,null,b),1,250,250),M=new I.Sphere(F,new I.Material(F,null,null,null,null,g),1,250,250),c=new I.Sphere(F,new I.Material(F,null,null,null,null,w),1,250,250),h=new I.Sphere(F,new I.Material(F,null,null,null,null,A),1,250,250),f=new I.Sphere(F,new I.Material(F,null,null,null,null,E),1,250,250),m=new I.Sphere(F,new I.Material(F,null,null,null,null,R),1,250,250),x=new I.Sphere(F,new I.Material(F,null,null,null,null,T),1,250,250),S=new I.Sphere(F,new I.Material(F,null,null,null,null,L),1,250,250),F.clearColor(0,0,0,1),F.enable(F.DEPTH_TEST),I.WebGLUtils.animate(e,o)}}function e(t){p+=Math.PI/4*t}function o(){F.clear(F.COLOR_BUFFER_BIT|F.DEPTH_BUFFER_BIT);var t=new I.Stack;t.push(z),t.push(I.Matrix.rotateY(p/50)),i.drawMesh(t.top(),u,l,null),t.push(I.Matrix.rotateY(p/5)),t.push(P),i.drawMesh(t.top(),s,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/12)),t.push(_),i.drawMesh(t.top(),M,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/14)),t.push(y),i.drawMesh(t.top(),c,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/10)),t.push(U),i.drawMesh(t.top(),h,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/20)),t.push(N),i.drawMesh(t.top(),f,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/15)),t.push(q),i.drawMesh(t.top(),m,l,null),t.pop(),t.pop(),t.push(I.Matrix.rotateY(p/14)),t.push(Y),i.drawMesh(t.top(),x,l,null),t.pop(),t.push(I.Matrix.rotateY(p/15)),t.push(O),i.drawMesh(t.top(),S,l,null),t.pop(),t.pop(),t.pop(),t.pop()}var i,l,u,s,M,c,h,f,m,x,S,d=r(1),I=r(11),D=document.getElementById("webgl"),F=I.WebGLUtils.setupWebGL(D,null,null),p=0,v=new Image,b=new Image,g=new Image,w=new Image,A=new Image,E=new Image,R=new Image,T=new Image,L=new Image;v.src="./sun.jpg",b.src="./mercury.jpg",g.src="./venus.jpg",w.src="./earth.jpg",A.src="./mars.jpg",E.src="./jupiter.jpg",R.src="./saturn.jpg",T.src="./uranus.jpg",L.src="./neptune.jpg",v.onload=function(){return n()},b.onload=function(){return n()},g.onload=function(){return n()},w.onload=function(){return n()},A.onload=function(){return n()},E.onload=function(){return n()},R.onload=function(){return n()},T.onload=function(){return n()},L.onload=function(){return n()};var z=d.mat4.create(),P=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.01),I.Matrix.translate(120,0,0)),_=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.02),I.Matrix.translate(67,0,0)),y=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.02),I.Matrix.translate(77,0,0)),U=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.01),I.Matrix.translate(170,0,0)),N=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.1),I.Matrix.translate(19,0,0)),q=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.09),I.Matrix.translate(24.5,0,0)),Y=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.05),I.Matrix.translate(50,0,0)),O=d.mat4.multiply(d.mat4.create(),I.Matrix.scaleUniform(.05),I.Matrix.translate(55,0,0)),B="\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",C="\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),e={};e.create=function(){var t=new n.ARRAY_TYPE(4);return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},e.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},e.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t},e.fromValues=function(t,a,r,e){var o=new n.ARRAY_TYPE(4);return o[0]=t,o[1]=a,o[2]=r,o[3]=e,o},e.set=function(t,a,r,n,e){return t[0]=a,t[1]=r,t[2]=n,t[3]=e,t},e.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},e.invert=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=r*o-e*n;return i?(i=1/i,t[0]=o*i,t[1]=-n*i,t[2]=-e*i,t[3]=r*i,t):null},e.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},e.determinant=function(t){return t[0]*t[3]-t[2]*t[1]},e.multiply=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=r[0],u=r[1],s=r[2],M=r[3];return t[0]=n*l+o*u,t[1]=e*l+i*u,t[2]=n*s+o*M,t[3]=e*s+i*M,t},e.mul=e.multiply,e.rotate=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+o*l,t[1]=e*u+i*l,t[2]=n*-l+o*u,t[3]=e*-l+i*u,t},e.scale=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=r[0],u=r[1];return t[0]=n*l,t[1]=e*l,t[2]=o*u,t[3]=i*u,t},e.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},e.fromScaling=function(t,a){return t[0]=a[0],t[1]=0,t[2]=0,t[3]=a[1],t},e.str=function(t){return"mat2("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},e.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))},e.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]},e.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},e.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},e.sub=e.subtract,e.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},e.equals=function(t,a){var r=t[0],e=t[1],o=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(e-u)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(u))&&Math.abs(o-s)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(s))&&Math.abs(i-M)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(M))},e.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},e.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=e},function(t,a,r){var n=r(2),e={};e.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},e.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},e.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},e.identity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=1,t[4]=0,t[5]=0,t},e.fromValues=function(t,a,r,e,o,i){var l=new n.ARRAY_TYPE(6);return l[0]=t,l[1]=a,l[2]=r,l[3]=e,l[4]=o,l[5]=i,l},e.set=function(t,a,r,n,e,o,i){return t[0]=a,t[1]=r,t[2]=n,t[3]=e,t[4]=o,t[5]=i,t},e.invert=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=a[4],l=a[5],u=r*o-n*e;return u?(u=1/u,t[0]=o*u,t[1]=-n*u,t[2]=-e*u,t[3]=r*u,t[4]=(e*l-o*i)*u,t[5]=(n*i-r*l)*u,t):null},e.determinant=function(t){return t[0]*t[3]-t[1]*t[2]},e.multiply=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1],c=r[2],h=r[3],f=r[4],m=r[5];return t[0]=n*s+o*M,t[1]=e*s+i*M,t[2]=n*c+o*h,t[3]=e*c+i*h,t[4]=n*f+o*m+l,t[5]=e*f+i*m+u,t},e.mul=e.multiply,e.rotate=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=Math.sin(r),M=Math.cos(r);return t[0]=n*M+o*s,t[1]=e*M+i*s,t[2]=n*-s+o*M,t[3]=e*-s+i*M,t[4]=l,t[5]=u,t},e.scale=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1];return t[0]=n*s,t[1]=e*s,t[2]=o*M,t[3]=i*M,t[4]=l,t[5]=u,t},e.translate=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=r[0],M=r[1];return t[0]=n,t[1]=e,t[2]=o,t[3]=i,t[4]=n*s+o*M+l,t[5]=e*s+i*M+u,t},e.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},e.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},e.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},e.str=function(t){return"mat2d("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+")"},e.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)},e.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},e.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},e.sub=e.subtract,e.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},e.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},e.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]},e.equals=function(t,a){var r=t[0],e=t[1],o=t[2],i=t[3],l=t[4],u=t[5],s=a[0],M=a[1],c=a[2],h=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(e-M)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(M))&&Math.abs(o-c)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(c))&&Math.abs(i-h)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(h))&&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=e},function(t,a,r){var n=r(2),e={};e.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},e.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},e.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},e.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},e.fromValues=function(t,a,r,e,o,i,l,u,s){var M=new n.ARRAY_TYPE(9);return M[0]=t,M[1]=a,M[2]=r,M[3]=e,M[4]=o,M[5]=i,M[6]=l,M[7]=u,M[8]=s,M},e.set=function(t,a,r,n,e,o,i,l,u,s){return t[0]=a,t[1]=r,t[2]=n,t[3]=e,t[4]=o,t[5]=i,t[6]=l,t[7]=u,t[8]=s,t},e.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},e.transpose=function(t,a){if(t===a){var r=a[1],n=a[2],e=a[5];t[1]=a[3],t[2]=a[6],t[3]=r,t[5]=a[7],t[6]=n,t[7]=e}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},e.invert=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],c=M*i-l*s,h=-M*o+l*u,f=s*o-i*u,m=r*c+n*h+e*f;return m?(m=1/m,t[0]=c*m,t[1]=(-M*n+e*s)*m,t[2]=(l*n-e*i)*m,t[3]=h*m,t[4]=(M*r-e*u)*m,t[5]=(-l*r+e*o)*m,t[6]=f*m,t[7]=(-s*r+n*u)*m,t[8]=(i*r-n*o)*m,t):null},e.adjoint=function(t,a){var r=a[0],n=a[1],e=a[2],o=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]=e*s-n*M,t[2]=n*l-e*i,t[3]=l*u-o*M,t[4]=r*M-e*u,t[5]=e*o-r*l,t[6]=o*s-i*u,t[7]=n*u-r*s,t[8]=r*i-n*o,t},e.determinant=function(t){var a=t[0],r=t[1],n=t[2],e=t[3],o=t[4],i=t[5],l=t[6],u=t[7],s=t[8];return a*(s*o-i*u)+r*(-s*e+i*l)+n*(u*e-o*l)},e.multiply=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],c=a[8],h=r[0],f=r[1],m=r[2],x=r[3],S=r[4],d=r[5],I=r[6],D=r[7],F=r[8];return t[0]=h*n+f*i+m*s,t[1]=h*e+f*l+m*M,t[2]=h*o+f*u+m*c,t[3]=x*n+S*i+d*s,t[4]=x*e+S*l+d*M,t[5]=x*o+S*u+d*c,t[6]=I*n+D*i+F*s,t[7]=I*e+D*l+F*M,t[8]=I*o+D*u+F*c,t},e.mul=e.multiply,e.translate=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],c=a[8],h=r[0],f=r[1];return t[0]=n,t[1]=e,t[2]=o,t[3]=i,t[4]=l,t[5]=u,t[6]=h*n+f*i+s,t[7]=h*e+f*l+M,t[8]=h*o+f*u+c,t},e.rotate=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],c=a[8],h=Math.sin(r),f=Math.cos(r);return t[0]=f*n+h*i,t[1]=f*e+h*l,t[2]=f*o+h*u,t[3]=f*i-h*n,t[4]=f*l-h*e,t[5]=f*u-h*o,t[6]=s,t[7]=M,t[8]=c,t},e.scale=function(t,a,r){var n=r[0],e=r[1];return t[0]=n*a[0],t[1]=n*a[1],t[2]=n*a[2],t[3]=e*a[3],t[4]=e*a[4],t[5]=e*a[5],t[6]=a[6],t[7]=a[7],t[8]=a[8],t},e.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},e.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},e.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},e.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},e.fromQuat=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=r+r,l=n+n,u=e+e,s=r*i,M=n*i,c=n*l,h=e*i,f=e*l,m=e*u,x=o*i,S=o*l,d=o*u;return t[0]=1-c-m,t[3]=M-d,t[6]=h+S,t[1]=M+d,t[4]=1-s-m,t[7]=f-x,t[2]=h-S,t[5]=f+x,t[8]=1-s-c,t},e.normalFromMat4=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],c=a[9],h=a[10],f=a[11],m=a[12],x=a[13],S=a[14],d=a[15],I=r*l-n*i,D=r*u-e*i,F=r*s-o*i,p=n*u-e*l,v=n*s-o*l,b=e*s-o*u,g=M*x-c*m,w=M*S-h*m,A=M*d-f*m,E=c*S-h*x,R=c*d-f*x,T=h*d-f*S,L=I*T-D*R+F*E+p*A-v*w+b*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]=(e*R-n*T-o*E)*L,t[4]=(r*T-e*A+o*w)*L,t[5]=(n*A-r*R-o*g)*L,t[6]=(x*b-S*v+d*p)*L,t[7]=(S*F-m*b-d*D)*L,t[8]=(m*v-x*F+d*I)*L,t):null},e.str=function(t){return"mat3("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+")"},e.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))},e.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},e.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},e.sub=e.subtract,e.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},e.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},e.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]},e.equals=function(t,a){var r=t[0],e=t[1],o=t[2],i=t[3],l=t[4],u=t[5],s=t[6],M=t[7],c=t[8],h=a[0],f=a[1],m=a[2],x=a[3],S=a[4],d=a[5],I=t[6],D=a[7],F=a[8];return Math.abs(r-h)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(h))&&Math.abs(e-f)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(f))&&Math.abs(o-m)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(m))&&Math.abs(i-x)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(x))&&Math.abs(l-S)<=n.EPSILON*Math.max(1,Math.abs(l),Math.abs(S))&&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(c-F)<=n.EPSILON*Math.max(1,Math.abs(c),Math.abs(F))},t.exports=e},function(t,a,r){var n=r(2),e={scalar:{},SIMD:{}};e.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},e.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},e.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},e.fromValues=function(t,a,r,e,o,i,l,u,s,M,c,h,f,m,x,S){var d=new n.ARRAY_TYPE(16);return d[0]=t,d[1]=a,d[2]=r,d[3]=e,d[4]=o,d[5]=i,d[6]=l,d[7]=u,d[8]=s,d[9]=M,d[10]=c,d[11]=h,d[12]=f,d[13]=m,d[14]=x,d[15]=S,d},e.set=function(t,a,r,n,e,o,i,l,u,s,M,c,h,f,m,x,S){return t[0]=a,t[1]=r,t[2]=n,t[3]=e,t[4]=o,t[5]=i,t[6]=l,t[7]=u,t[8]=s,t[9]=M,t[10]=c,t[11]=h,t[12]=f,t[13]=m,t[14]=x,t[15]=S,t},e.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},e.scalar.transpose=function(t,a){if(t===a){var r=a[1],n=a[2],e=a[3],o=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]=o,t[11]=a[14],t[12]=e,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},e.SIMD.transpose=function(t,a){var r,n,e,o,i,l,u,s,M,c;return r=SIMD.Float32x4.load(a,0),n=SIMD.Float32x4.load(a,4),e=SIMD.Float32x4.load(a,8),o=SIMD.Float32x4.load(a,12),i=SIMD.Float32x4.shuffle(r,n,0,1,4,5),l=SIMD.Float32x4.shuffle(e,o,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(e,o,2,3,6,7),M=SIMD.Float32x4.shuffle(i,l,0,2,4,6),c=SIMD.Float32x4.shuffle(i,l,1,3,5,7),SIMD.Float32x4.store(t,8,M),SIMD.Float32x4.store(t,12,c),t},e.transpose=n.USE_SIMD?e.SIMD.transpose:e.scalar.transpose,e.scalar.invert=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],c=a[9],h=a[10],f=a[11],m=a[12],x=a[13],S=a[14],d=a[15],I=r*l-n*i,D=r*u-e*i,F=r*s-o*i,p=n*u-e*l,v=n*s-o*l,b=e*s-o*u,g=M*x-c*m,w=M*S-h*m,A=M*d-f*m,E=c*S-h*x,R=c*d-f*x,T=h*d-f*S,L=I*T-D*R+F*E+p*A-v*w+b*g;return L?(L=1/L,t[0]=(l*T-u*R+s*E)*L,t[1]=(e*R-n*T-o*E)*L,t[2]=(x*b-S*v+d*p)*L,t[3]=(h*v-c*b-f*p)*L,t[4]=(u*A-i*T-s*w)*L,t[5]=(r*T-e*A+o*w)*L,t[6]=(S*F-m*b-d*D)*L,t[7]=(M*b-h*F+f*D)*L,t[8]=(i*R-l*A+s*g)*L,t[9]=(n*A-r*R-o*g)*L,t[10]=(m*v-x*F+d*I)*L,t[11]=(c*F-M*v-f*I)*L,t[12]=(l*w-i*E-u*g)*L,t[13]=(r*E-n*w+e*g)*L,t[14]=(x*D-m*p-S*I)*L,t[15]=(M*p-c*D+h*I)*L,t):null},e.SIMD.invert=function(t,a){var r,n,e,o,i,l,u,s,M,c,h=SIMD.Float32x4.load(a,0),f=SIMD.Float32x4.load(a,4),m=SIMD.Float32x4.load(a,8),x=SIMD.Float32x4.load(a,12);return i=SIMD.Float32x4.shuffle(h,f,0,1,4,5),n=SIMD.Float32x4.shuffle(m,x,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(h,f,2,3,6,7),o=SIMD.Float32x4.shuffle(m,x,2,3,6,7),e=SIMD.Float32x4.shuffle(i,o,0,2,4,6),o=SIMD.Float32x4.shuffle(o,i,1,3,5,7),i=SIMD.Float32x4.mul(e,o),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,e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),l=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,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(o,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),o),i=SIMD.Float32x4.swizzle(i,1,0,3,2),e=SIMD.Float32x4.swizzle(e,2,3,0,1),l=SIMD.Float32x4.add(SIMD.Float32x4.mul(e,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(e,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(o,i),s),M=SIMD.Float32x4.sub(SIMD.Float32x4.mul(e,i),M),i=SIMD.Float32x4.swizzle(i,2,3,0,1),s=SIMD.Float32x4.sub(SIMD.Float32x4.mul(o,i),s),M=SIMD.Float32x4.sub(M,SIMD.Float32x4.mul(e,i)),i=SIMD.Float32x4.mul(r,o),i=SIMD.Float32x4.swizzle(i,1,0,3,2),u=SIMD.Float32x4.sub(u,SIMD.Float32x4.mul(e,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(e,i),u),s=SIMD.Float32x4.sub(s,SIMD.Float32x4.mul(n,i)),i=SIMD.Float32x4.mul(r,e),i=SIMD.Float32x4.swizzle(i,1,0,3,2),u=SIMD.Float32x4.add(SIMD.Float32x4.mul(o,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(o,i)),M=SIMD.Float32x4.add(SIMD.Float32x4.mul(n,i),M),c=SIMD.Float32x4.mul(r,l),c=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(c,2,3,0,1),c),c=SIMD.Float32x4.add(SIMD.Float32x4.swizzle(c,1,0,3,2),c),i=SIMD.Float32x4.reciprocalApproximation(c),c=SIMD.Float32x4.sub(SIMD.Float32x4.add(i,i),SIMD.Float32x4.mul(c,SIMD.Float32x4.mul(i,i))),(c=SIMD.Float32x4.swizzle(c,0,0,0,0))?(SIMD.Float32x4.store(t,0,SIMD.Float32x4.mul(c,l)),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(c,u)),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(c,s)),SIMD.Float32x4.store(t,12,SIMD.Float32x4.mul(c,M)),t):null},e.invert=n.USE_SIMD?e.SIMD.invert:e.scalar.invert,e.scalar.adjoint=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=a[4],l=a[5],u=a[6],s=a[7],M=a[8],c=a[9],h=a[10],f=a[11],m=a[12],x=a[13],S=a[14],d=a[15];return t[0]=l*(h*d-f*S)-c*(u*d-s*S)+x*(u*f-s*h),t[1]=-(n*(h*d-f*S)-c*(e*d-o*S)+x*(e*f-o*h)),t[2]=n*(u*d-s*S)-l*(e*d-o*S)+x*(e*s-o*u),t[3]=-(n*(u*f-s*h)-l*(e*f-o*h)+c*(e*s-o*u)),t[4]=-(i*(h*d-f*S)-M*(u*d-s*S)+m*(u*f-s*h)),t[5]=r*(h*d-f*S)-M*(e*d-o*S)+m*(e*f-o*h),t[6]=-(r*(u*d-s*S)-i*(e*d-o*S)+m*(e*s-o*u)),t[7]=r*(u*f-s*h)-i*(e*f-o*h)+M*(e*s-o*u),t[8]=i*(c*d-f*x)-M*(l*d-s*x)+m*(l*f-s*c),t[9]=-(r*(c*d-f*x)-M*(n*d-o*x)+m*(n*f-o*c)),t[10]=r*(l*d-s*x)-i*(n*d-o*x)+m*(n*s-o*l),t[11]=-(r*(l*f-s*c)-i*(n*f-o*c)+M*(n*s-o*l)),t[12]=-(i*(c*S-h*x)-M*(l*S-u*x)+m*(l*h-u*c)),t[13]=r*(c*S-h*x)-M*(n*S-e*x)+m*(n*h-e*c),t[14]=-(r*(l*S-u*x)-i*(n*S-e*x)+m*(n*u-e*l)),t[15]=r*(l*h-u*c)-i*(n*h-e*c)+M*(n*u-e*l),t},e.SIMD.adjoint=function(t,a){var r,n,e,o,i,l,u,s,M,c,h,f,m,r=SIMD.Float32x4.load(a,0),n=SIMD.Float32x4.load(a,4),e=SIMD.Float32x4.load(a,8),o=SIMD.Float32x4.load(a,12);return M=SIMD.Float32x4.shuffle(r,n,0,1,4,5),l=SIMD.Float32x4.shuffle(e,o,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(e,o,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),c=SIMD.Float32x4.mul(l,M),h=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.sub(SIMD.Float32x4.mul(l,M),c),h=SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,M),h),h=SIMD.Float32x4.swizzle(h,2,3,0,1),M=SIMD.Float32x4.mul(l,u),M=SIMD.Float32x4.swizzle(M,1,0,3,2),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,M),c),m=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.sub(c,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),c=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,M),c),f=SIMD.Float32x4.mul(i,M),M=SIMD.Float32x4.swizzle(M,2,3,0,1),c=SIMD.Float32x4.sub(c,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),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(u,M)),f=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,M),f),M=SIMD.Float32x4.swizzle(M,2,3,0,1),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(u,M),h),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),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(s,M),h),m=SIMD.Float32x4.sub(m,SIMD.Float32x4.mul(l,M)),M=SIMD.Float32x4.swizzle(M,2,3,0,1),h=SIMD.Float32x4.sub(h,SIMD.Float32x4.mul(s,M)),m=SIMD.Float32x4.add(SIMD.Float32x4.mul(l,M),m),SIMD.Float32x4.store(t,0,c),SIMD.Float32x4.store(t,4,h),SIMD.Float32x4.store(t,8,f),SIMD.Float32x4.store(t,12,m),t},e.adjoint=n.USE_SIMD?e.SIMD.adjoint:e.scalar.adjoint,e.determinant=function(t){var a=t[0],r=t[1],n=t[2],e=t[3],o=t[4],i=t[5],l=t[6],u=t[7],s=t[8],M=t[9],c=t[10],h=t[11],f=t[12],m=t[13],x=t[14],S=t[15],d=a*i-r*o,I=a*l-n*o,D=a*u-e*o,F=r*l-n*i,p=r*u-e*i,v=n*u-e*l,b=s*m-M*f,g=s*x-c*f,w=s*S-h*f,A=M*x-c*m,E=M*S-h*m,R=c*S-h*x;return d*R-I*E+D*A+F*w-p*g+v*b},e.SIMD.multiply=function(t,a,r){var n=SIMD.Float32x4.load(a,0),e=SIMD.Float32x4.load(a,4),o=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),e),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(l,2,2,2,2),o),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),e),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,2,2,2,2),o),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(s,3,3,3,3),i))));SIMD.Float32x4.store(t,4,M);var c=SIMD.Float32x4.load(r,8),h=SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,0,0,0,0),n),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,1,1,1,1),e),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,2,2,2,2),o),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(c,3,3,3,3),i))));SIMD.Float32x4.store(t,8,h);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),e),SIMD.Float32x4.add(SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,2,2,2,2),o),SIMD.Float32x4.mul(SIMD.Float32x4.swizzle(f,3,3,3,3),i))));return SIMD.Float32x4.store(t,12,m),t},e.scalar.multiply=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],c=a[8],h=a[9],f=a[10],m=a[11],x=a[12],S=a[13],d=a[14],I=a[15],D=r[0],F=r[1],p=r[2],v=r[3];return t[0]=D*n+F*l+p*c+v*x,t[1]=D*e+F*u+p*h+v*S,t[2]=D*o+F*s+p*f+v*d,t[3]=D*i+F*M+p*m+v*I,D=r[4],F=r[5],p=r[6],v=r[7],t[4]=D*n+F*l+p*c+v*x,t[5]=D*e+F*u+p*h+v*S,t[6]=D*o+F*s+p*f+v*d,t[7]=D*i+F*M+p*m+v*I,D=r[8],F=r[9],p=r[10],v=r[11],t[8]=D*n+F*l+p*c+v*x,t[9]=D*e+F*u+p*h+v*S,t[10]=D*o+F*s+p*f+v*d,t[11]=D*i+F*M+p*m+v*I,D=r[12],F=r[13],p=r[14],v=r[15],t[12]=D*n+F*l+p*c+v*x,t[13]=D*e+F*u+p*h+v*S,t[14]=D*o+F*s+p*f+v*d,t[15]=D*i+F*M+p*m+v*I,t},e.multiply=n.USE_SIMD?e.SIMD.multiply:e.scalar.multiply,e.mul=e.multiply,e.scalar.translate=function(t,a,r){var n,e,o,i,l,u,s,M,c,h,f,m,x=r[0],S=r[1],d=r[2];return a===t?(t[12]=a[0]*x+a[4]*S+a[8]*d+a[12],t[13]=a[1]*x+a[5]*S+a[9]*d+a[13],t[14]=a[2]*x+a[6]*S+a[10]*d+a[14],t[15]=a[3]*x+a[7]*S+a[11]*d+a[15]):(n=a[0],e=a[1],o=a[2],i=a[3],l=a[4],u=a[5],s=a[6],M=a[7],c=a[8],h=a[9],f=a[10],m=a[11],t[0]=n,t[1]=e,t[2]=o,t[3]=i,t[4]=l,t[5]=u,t[6]=s,t[7]=M,t[8]=c,t[9]=h,t[10]=f,t[11]=m,t[12]=n*x+l*S+c*d+a[12],t[13]=e*x+u*S+h*d+a[13],t[14]=o*x+s*S+f*d+a[14],t[15]=i*x+M*S+m*d+a[15]),t},e.SIMD.translate=function(t,a,r){var n=SIMD.Float32x4.load(a,0),e=SIMD.Float32x4.load(a,4),o=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)),e=SIMD.Float32x4.mul(e,SIMD.Float32x4.swizzle(l,1,1,1,1)),o=SIMD.Float32x4.mul(o,SIMD.Float32x4.swizzle(l,2,2,2,2));var u=SIMD.Float32x4.add(n,SIMD.Float32x4.add(e,SIMD.Float32x4.add(o,i)));return SIMD.Float32x4.store(t,12,u),t},e.translate=n.USE_SIMD?e.SIMD.translate:e.scalar.translate,e.scalar.scale=function(t,a,r){var n=r[0],e=r[1],o=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]*e,t[5]=a[5]*e,t[6]=a[6]*e,t[7]=a[7]*e,t[8]=a[8]*o,t[9]=a[9]*o,t[10]=a[10]*o,t[11]=a[11]*o,t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15],t},e.SIMD.scale=function(t,a,r){var n,e,o,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))),e=SIMD.Float32x4.load(a,4),SIMD.Float32x4.store(t,4,SIMD.Float32x4.mul(e,SIMD.Float32x4.swizzle(i,1,1,1,1))),o=SIMD.Float32x4.load(a,8),SIMD.Float32x4.store(t,8,SIMD.Float32x4.mul(o,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},e.scale=n.USE_SIMD?e.SIMD.scale:e.scalar.scale,e.rotate=function(t,a,r,e){var o,i,l,u,s,M,c,h,f,m,x,S,d,I,D,F,p,v,b,g,w,A,E,R,T=e[0],L=e[1],z=e[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,o=Math.sin(r),i=Math.cos(r),l=1-i,u=a[0],s=a[1],M=a[2],c=a[3],h=a[4],f=a[5],m=a[6],x=a[7],S=a[8],d=a[9],I=a[10],D=a[11],F=T*T*l+i,p=L*T*l+z*o,v=z*T*l-L*o,b=T*L*l-z*o,g=L*L*l+i,w=z*L*l+T*o,A=T*z*l+L*o,E=L*z*l-T*o,R=z*z*l+i,t[0]=u*F+h*p+S*v,t[1]=s*F+f*p+d*v,t[2]=M*F+m*p+I*v,t[3]=c*F+x*p+D*v,t[4]=u*b+h*g+S*w,t[5]=s*b+f*g+d*w,t[6]=M*b+m*g+I*w,t[7]=c*b+x*g+D*w,t[8]=u*A+h*E+S*R,t[9]=s*A+f*E+d*R,t[10]=M*A+m*E+I*R,t[11]=c*A+x*E+D*R,a!==t&&(t[12]=a[12],t[13]=a[13],t[14]=a[14],t[15]=a[15]),t)},e.scalar.rotateX=function(t,a,r){var n=Math.sin(r),e=Math.cos(r),o=a[4],i=a[5],l=a[6],u=a[7],s=a[8],M=a[9],c=a[10],h=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]=o*e+s*n,t[5]=i*e+M*n,t[6]=l*e+c*n,t[7]=u*e+h*n,t[8]=s*e-o*n,t[9]=M*e-i*n,t[10]=c*e-l*n,t[11]=h*e-u*n,t},e.SIMD.rotateX=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),e=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 o=SIMD.Float32x4.load(a,4),i=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,4,SIMD.Float32x4.add(SIMD.Float32x4.mul(o,e),SIMD.Float32x4.mul(i,n))),SIMD.Float32x4.store(t,8,SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,e),SIMD.Float32x4.mul(o,n))),t},e.rotateX=n.USE_SIMD?e.SIMD.rotateX:e.scalar.rotateX,e.scalar.rotateY=function(t,a,r){var n=Math.sin(r),e=Math.cos(r),o=a[0],i=a[1],l=a[2],u=a[3],s=a[8],M=a[9],c=a[10],h=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]=o*e-s*n,t[1]=i*e-M*n,t[2]=l*e-c*n,t[3]=u*e-h*n,t[8]=o*n+s*e,t[9]=i*n+M*e,t[10]=l*n+c*e,t[11]=u*n+h*e,t},e.SIMD.rotateY=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),e=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 o=SIMD.Float32x4.load(a,0),i=SIMD.Float32x4.load(a,8);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.sub(SIMD.Float32x4.mul(o,e),SIMD.Float32x4.mul(i,n))), | |
SIMD.Float32x4.store(t,8,SIMD.Float32x4.add(SIMD.Float32x4.mul(o,n),SIMD.Float32x4.mul(i,e))),t},e.rotateY=n.USE_SIMD?e.SIMD.rotateY:e.scalar.rotateY,e.scalar.rotateZ=function(t,a,r){var n=Math.sin(r),e=Math.cos(r),o=a[0],i=a[1],l=a[2],u=a[3],s=a[4],M=a[5],c=a[6],h=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]=o*e+s*n,t[1]=i*e+M*n,t[2]=l*e+c*n,t[3]=u*e+h*n,t[4]=s*e-o*n,t[5]=M*e-i*n,t[6]=c*e-l*n,t[7]=h*e-u*n,t},e.SIMD.rotateZ=function(t,a,r){var n=SIMD.Float32x4.splat(Math.sin(r)),e=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 o=SIMD.Float32x4.load(a,0),i=SIMD.Float32x4.load(a,4);return SIMD.Float32x4.store(t,0,SIMD.Float32x4.add(SIMD.Float32x4.mul(o,e),SIMD.Float32x4.mul(i,n))),SIMD.Float32x4.store(t,4,SIMD.Float32x4.sub(SIMD.Float32x4.mul(i,e),SIMD.Float32x4.mul(o,n))),t},e.rotateZ=n.USE_SIMD?e.SIMD.rotateZ:e.scalar.rotateZ,e.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},e.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},e.fromRotation=function(t,a,r){var e,o,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,e=Math.sin(a),o=Math.cos(a),i=1-o,t[0]=l*l*i+o,t[1]=u*l*i+s*e,t[2]=s*l*i-u*e,t[3]=0,t[4]=l*u*i-s*e,t[5]=u*u*i+o,t[6]=s*u*i+l*e,t[7]=0,t[8]=l*s*i+u*e,t[9]=u*s*i-l*e,t[10]=s*s*i+o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)},e.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},e.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},e.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},e.fromRotationTranslation=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3],l=n+n,u=e+e,s=o+o,M=n*l,c=n*u,h=n*s,f=e*u,m=e*s,x=o*s,S=i*l,d=i*u,I=i*s;return t[0]=1-(f+x),t[1]=c+I,t[2]=h-d,t[3]=0,t[4]=c-I,t[5]=1-(M+x),t[6]=m+S,t[7]=0,t[8]=h+d,t[9]=m-S,t[10]=1-(M+f),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},e.getTranslation=function(t,a){return t[0]=a[12],t[1]=a[13],t[2]=a[14],t},e.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},e.fromRotationTranslationScale=function(t,a,r,n){var e=a[0],o=a[1],i=a[2],l=a[3],u=e+e,s=o+o,M=i+i,c=e*u,h=e*s,f=e*M,m=o*s,x=o*M,S=i*M,d=l*u,I=l*s,D=l*M,F=n[0],p=n[1],v=n[2];return t[0]=(1-(m+S))*F,t[1]=(h+D)*F,t[2]=(f-I)*F,t[3]=0,t[4]=(h-D)*p,t[5]=(1-(c+S))*p,t[6]=(x+d)*p,t[7]=0,t[8]=(f+I)*v,t[9]=(x-d)*v,t[10]=(1-(c+m))*v,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t},e.fromRotationTranslationScaleOrigin=function(t,a,r,n,e){var o=a[0],i=a[1],l=a[2],u=a[3],s=o+o,M=i+i,c=l+l,h=o*s,f=o*M,m=o*c,x=i*M,S=i*c,d=l*c,I=u*s,D=u*M,F=u*c,p=n[0],v=n[1],b=n[2],g=e[0],w=e[1],A=e[2];return t[0]=(1-(x+d))*p,t[1]=(f+F)*p,t[2]=(m-D)*p,t[3]=0,t[4]=(f-F)*v,t[5]=(1-(h+d))*v,t[6]=(S+I)*v,t[7]=0,t[8]=(m+D)*b,t[9]=(S-I)*b,t[10]=(1-(h+x))*b,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},e.fromQuat=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=r+r,l=n+n,u=e+e,s=r*i,M=n*i,c=n*l,h=e*i,f=e*l,m=e*u,x=o*i,S=o*l,d=o*u;return t[0]=1-c-m,t[1]=M+d,t[2]=h-S,t[3]=0,t[4]=M-d,t[5]=1-s-m,t[6]=f+x,t[7]=0,t[8]=h+S,t[9]=f-x,t[10]=1-s-c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},e.frustum=function(t,a,r,n,e,o,i){var l=1/(r-a),u=1/(e-n),s=1/(o-i);return t[0]=2*o*l,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*o*u,t[6]=0,t[7]=0,t[8]=(r+a)*l,t[9]=(e+n)*u,t[10]=(i+o)*s,t[11]=-1,t[12]=0,t[13]=0,t[14]=i*o*2*s,t[15]=0,t},e.perspective=function(t,a,r,n,e){var o=1/Math.tan(a/2),i=1/(n-e);return t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(e+n)*i,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*e*n*i,t[15]=0,t},e.perspectiveFromFieldOfView=function(t,a,r,n){var e=Math.tan(a.upDegrees*Math.PI/180),o=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/(e+o);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]=(e-o)*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},e.ortho=function(t,a,r,n,e,o,i){var l=1/(a-r),u=1/(n-e),s=1/(o-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]=(e+n)*u,t[14]=(i+o)*s,t[15]=1,t},e.lookAt=function(t,a,r,o){var i,l,u,s,M,c,h,f,m,x,S=a[0],d=a[1],I=a[2],D=o[0],F=o[1],p=o[2],v=r[0],b=r[1],g=r[2];return Math.abs(S-v)<n.EPSILON&&Math.abs(d-b)<n.EPSILON&&Math.abs(I-g)<n.EPSILON?e.identity(t):(h=S-v,f=d-b,m=I-g,x=1/Math.sqrt(h*h+f*f+m*m),h*=x,f*=x,m*=x,i=F*m-p*f,l=p*h-D*m,u=D*f-F*h,x=Math.sqrt(i*i+l*l+u*u),x?(x=1/x,i*=x,l*=x,u*=x):(i=0,l=0,u=0),s=f*u-m*l,M=m*i-h*u,c=h*l-f*i,x=Math.sqrt(s*s+M*M+c*c),x?(x=1/x,s*=x,M*=x,c*=x):(s=0,M=0,c=0),t[0]=i,t[1]=s,t[2]=h,t[3]=0,t[4]=l,t[5]=M,t[6]=f,t[7]=0,t[8]=u,t[9]=c,t[10]=m,t[11]=0,t[12]=-(i*S+l*d+u*I),t[13]=-(s*S+M*d+c*I),t[14]=-(h*S+f*d+m*I),t[15]=1,t)},e.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]+")"},e.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))},e.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},e.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},e.sub=e.subtract,e.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},e.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},e.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]},e.equals=function(t,a){var r=t[0],e=t[1],o=t[2],i=t[3],l=t[4],u=t[5],s=t[6],M=t[7],c=t[8],h=t[9],f=t[10],m=t[11],x=t[12],S=t[13],d=t[14],I=t[15],D=a[0],F=a[1],p=a[2],v=a[3],b=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(e-F)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(F))&&Math.abs(o-p)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(p))&&Math.abs(i-v)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(v))&&Math.abs(l-b)<=n.EPSILON*Math.max(1,Math.abs(l),Math.abs(b))&&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(c-E)<=n.EPSILON*Math.max(1,Math.abs(c),Math.abs(E))&&Math.abs(h-R)<=n.EPSILON*Math.max(1,Math.abs(h),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(x-z)<=n.EPSILON*Math.max(1,Math.abs(x),Math.abs(z))&&Math.abs(S-P)<=n.EPSILON*Math.max(1,Math.abs(S),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=e},function(t,a,r){var n=r(2),e=r(5),o=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=o.create(),a=o.fromValues(1,0,0),r=o.fromValues(0,1,0);return function(n,e,i){var u=o.dot(e,i);return u<-.999999?(o.cross(t,a,e),o.length(t)<1e-6&&o.cross(t,r,e),o.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):(o.cross(t,e,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=e.create();return function(a,r,n,e){return t[0]=n[0],t[3]=n[1],t[6]=n[2],t[1]=e[0],t[4]=e[1],t[7]=e[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],e=a[1],o=a[2],i=a[3],l=r[0],u=r[1],s=r[2],M=r[3];return t[0]=n*M+i*l+e*s-o*u,t[1]=e*M+i*u+o*l-n*s,t[2]=o*M+i*s+n*u-e*l,t[3]=i*M-n*l-e*u-o*s,t},l.mul=l.multiply,l.scale=i.scale,l.rotateX=function(t,a,r){r*=.5;var n=a[0],e=a[1],o=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*l,t[1]=e*u+o*l,t[2]=o*u-e*l,t[3]=i*u-n*l,t},l.rotateY=function(t,a,r){r*=.5;var n=a[0],e=a[1],o=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u-o*l,t[1]=e*u+i*l,t[2]=o*u+n*l,t[3]=i*u-e*l,t},l.rotateZ=function(t,a,r){r*=.5;var n=a[0],e=a[1],o=a[2],i=a[3],l=Math.sin(r),u=Math.cos(r);return t[0]=n*u+e*l,t[1]=e*u-n*l,t[2]=o*u+i*l,t[3]=i*u-o*l,t},l.calculateW=function(t,a){var r=a[0],n=a[1],e=a[2];return t[0]=r,t[1]=n,t[2]=e,t[3]=Math.sqrt(Math.abs(1-r*r-n*n-e*e)),t},l.dot=i.dot,l.lerp=i.lerp,l.slerp=function(t,a,r,n){var e,o,i,l,u,s=a[0],M=a[1],c=a[2],h=a[3],f=r[0],m=r[1],x=r[2],S=r[3];return o=s*f+M*m+c*x+h*S,o<0&&(o=-o,f=-f,m=-m,x=-x,S=-S),1-o>1e-6?(e=Math.acos(o),i=Math.sin(e),l=Math.sin((1-n)*e)/i,u=Math.sin(n*e)/i):(l=1-n,u=n),t[0]=l*s+u*f,t[1]=l*M+u*m,t[2]=l*c+u*x,t[3]=l*h+u*S,t},l.sqlerp=function(){var t=l.create(),a=l.create();return function(r,n,e,o,i,u){return l.slerp(t,n,i,u),l.slerp(a,e,o,u),l.slerp(r,t,a,2*u*(1-u)),r}}(),l.invert=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=r*r+n*n+e*e+o*o,l=i?1/i:0;return t[0]=-r*l,t[1]=-n*l,t[2]=-e*l,t[3]=o*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 e=0;a[4]>a[0]&&(e=1),a[8]>a[3*e+e]&&(e=2);var o=(e+1)%3,i=(e+2)%3;r=Math.sqrt(a[3*e+e]-a[3*o+o]-a[3*i+i]+1),t[e]=.5*r,r=.5/r,t[3]=(a[3*o+i]-a[3*i+o])*r,t[o]=(a[3*o+e]+a[3*e+o])*r,t[i]=(a[3*i+e]+a[3*e+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),e={};e.create=function(){var t=new n.ARRAY_TYPE(3);return t[0]=0,t[1]=0,t[2]=0,t},e.clone=function(t){var a=new n.ARRAY_TYPE(3);return a[0]=t[0],a[1]=t[1],a[2]=t[2],a},e.fromValues=function(t,a,r){var e=new n.ARRAY_TYPE(3);return e[0]=t,e[1]=a,e[2]=r,e},e.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t},e.set=function(t,a,r,n){return t[0]=a,t[1]=r,t[2]=n,t},e.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},e.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},e.sub=e.subtract,e.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},e.mul=e.multiply,e.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},e.div=e.divide,e.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t[2]=Math.ceil(a[2]),t},e.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t[2]=Math.floor(a[2]),t},e.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},e.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},e.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t[2]=Math.round(a[2]),t},e.scale=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t[2]=a[2]*r,t},e.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},e.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],e=a[2]-t[2];return Math.sqrt(r*r+n*n+e*e)},e.dist=e.distance,e.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],e=a[2]-t[2];return r*r+n*n+e*e},e.sqrDist=e.squaredDistance,e.length=function(t){var a=t[0],r=t[1],n=t[2];return Math.sqrt(a*a+r*r+n*n)},e.len=e.length,e.squaredLength=function(t){var a=t[0],r=t[1],n=t[2];return a*a+r*r+n*n},e.sqrLen=e.squaredLength,e.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t},e.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t[2]=1/a[2],t},e.normalize=function(t,a){var r=a[0],n=a[1],e=a[2],o=r*r+n*n+e*e;return o>0&&(o=1/Math.sqrt(o),t[0]=a[0]*o,t[1]=a[1]*o,t[2]=a[2]*o),t},e.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]},e.cross=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=r[0],l=r[1],u=r[2];return t[0]=e*u-o*l,t[1]=o*i-n*u,t[2]=n*l-e*i,t},e.lerp=function(t,a,r,n){var e=a[0],o=a[1],i=a[2];return t[0]=e+n*(r[0]-e),t[1]=o+n*(r[1]-o),t[2]=i+n*(r[2]-i),t},e.hermite=function(t,a,r,n,e,o){var i=o*o,l=i*(2*o-3)+1,u=i*(o-2)+o,s=i*(o-1),M=i*(3-2*o);return t[0]=a[0]*l+r[0]*u+n[0]*s+e[0]*M,t[1]=a[1]*l+r[1]*u+n[1]*s+e[1]*M,t[2]=a[2]*l+r[2]*u+n[2]*s+e[2]*M,t},e.bezier=function(t,a,r,n,e,o){var i=1-o,l=i*i,u=o*o,s=l*i,M=3*o*l,c=3*u*i,h=u*o;return t[0]=a[0]*s+r[0]*M+n[0]*c+e[0]*h,t[1]=a[1]*s+r[1]*M+n[1]*c+e[1]*h,t[2]=a[2]*s+r[2]*M+n[2]*c+e[2]*h,t},e.random=function(t,a){a=a||1;var r=2*n.RANDOM()*Math.PI,e=2*n.RANDOM()-1,o=Math.sqrt(1-e*e)*a;return t[0]=Math.cos(r)*o,t[1]=Math.sin(r)*o,t[2]=e*a,t},e.transformMat4=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=r[3]*n+r[7]*e+r[11]*o+r[15];return i=i||1,t[0]=(r[0]*n+r[4]*e+r[8]*o+r[12])/i,t[1]=(r[1]*n+r[5]*e+r[9]*o+r[13])/i,t[2]=(r[2]*n+r[6]*e+r[10]*o+r[14])/i,t},e.transformMat3=function(t,a,r){var n=a[0],e=a[1],o=a[2];return t[0]=n*r[0]+e*r[3]+o*r[6],t[1]=n*r[1]+e*r[4]+o*r[7],t[2]=n*r[2]+e*r[5]+o*r[8],t},e.transformQuat=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=r[0],l=r[1],u=r[2],s=r[3],M=s*n+l*o-u*e,c=s*e+u*n-i*o,h=s*o+i*e-l*n,f=-i*n-l*e-u*o;return t[0]=M*s+f*-i+c*-u-h*-l,t[1]=c*s+f*-l+h*-i-M*-u,t[2]=h*s+f*-u+M*-l-c*-i,t},e.rotateX=function(t,a,r,n){var e=[],o=[];return e[0]=a[0]-r[0],e[1]=a[1]-r[1],e[2]=a[2]-r[2],o[0]=e[0],o[1]=e[1]*Math.cos(n)-e[2]*Math.sin(n),o[2]=e[1]*Math.sin(n)+e[2]*Math.cos(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t},e.rotateY=function(t,a,r,n){var e=[],o=[];return e[0]=a[0]-r[0],e[1]=a[1]-r[1],e[2]=a[2]-r[2],o[0]=e[2]*Math.sin(n)+e[0]*Math.cos(n),o[1]=e[1],o[2]=e[2]*Math.cos(n)-e[0]*Math.sin(n),t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t},e.rotateZ=function(t,a,r,n){var e=[],o=[];return e[0]=a[0]-r[0],e[1]=a[1]-r[1],e[2]=a[2]-r[2],o[0]=e[0]*Math.cos(n)-e[1]*Math.sin(n),o[1]=e[0]*Math.sin(n)+e[1]*Math.cos(n),o[2]=e[2],t[0]=o[0]+r[0],t[1]=o[1]+r[1],t[2]=o[2]+r[2],t},e.forEach=function(){var t=e.create();return function(a,r,n,e,o,i){var l,u;for(r||(r=3),n||(n=0),u=e?Math.min(e*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],o(t,t,i),a[l]=t[0],a[l+1]=t[1],a[l+2]=t[2];return a}}(),e.angle=function(t,a){var r=e.fromValues(t[0],t[1],t[2]),n=e.fromValues(a[0],a[1],a[2]);e.normalize(r,r),e.normalize(n,n);var o=e.dot(r,n);return o>1?0:Math.acos(o)},e.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},e.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]},e.equals=function(t,a){var r=t[0],e=t[1],o=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(e-l)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(l))&&Math.abs(o-u)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(u))},t.exports=e},function(t,a,r){var n=r(2),e={};e.create=function(){var t=new n.ARRAY_TYPE(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},e.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},e.fromValues=function(t,a,r,e){var o=new n.ARRAY_TYPE(4);return o[0]=t,o[1]=a,o[2]=r,o[3]=e,o},e.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t[2]=a[2],t[3]=a[3],t},e.set=function(t,a,r,n,e){return t[0]=a,t[1]=r,t[2]=n,t[3]=e,t},e.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},e.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},e.sub=e.subtract,e.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},e.mul=e.multiply,e.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},e.div=e.divide,e.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},e.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},e.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},e.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},e.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},e.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},e.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},e.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],e=a[2]-t[2],o=a[3]-t[3];return Math.sqrt(r*r+n*n+e*e+o*o)},e.dist=e.distance,e.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1],e=a[2]-t[2],o=a[3]-t[3];return r*r+n*n+e*e+o*o},e.sqrDist=e.squaredDistance,e.length=function(t){var a=t[0],r=t[1],n=t[2],e=t[3];return Math.sqrt(a*a+r*r+n*n+e*e)},e.len=e.length,e.squaredLength=function(t){var a=t[0],r=t[1],n=t[2],e=t[3];return a*a+r*r+n*n+e*e},e.sqrLen=e.squaredLength,e.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t[2]=-a[2],t[3]=-a[3],t},e.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},e.normalize=function(t,a){var r=a[0],n=a[1],e=a[2],o=a[3],i=r*r+n*n+e*e+o*o;return i>0&&(i=1/Math.sqrt(i),t[0]=r*i,t[1]=n*i,t[2]=e*i,t[3]=o*i),t},e.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]+t[2]*a[2]+t[3]*a[3]},e.lerp=function(t,a,r,n){var e=a[0],o=a[1],i=a[2],l=a[3];return t[0]=e+n*(r[0]-e),t[1]=o+n*(r[1]-o),t[2]=i+n*(r[2]-i),t[3]=l+n*(r[3]-l),t},e.random=function(t,a){return a=a||1,t[0]=n.RANDOM(),t[1]=n.RANDOM(),t[2]=n.RANDOM(),t[3]=n.RANDOM(),e.normalize(t,t),e.scale(t,t,a),t},e.transformMat4=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=a[3];return t[0]=r[0]*n+r[4]*e+r[8]*o+r[12]*i,t[1]=r[1]*n+r[5]*e+r[9]*o+r[13]*i,t[2]=r[2]*n+r[6]*e+r[10]*o+r[14]*i,t[3]=r[3]*n+r[7]*e+r[11]*o+r[15]*i,t},e.transformQuat=function(t,a,r){var n=a[0],e=a[1],o=a[2],i=r[0],l=r[1],u=r[2],s=r[3],M=s*n+l*o-u*e,c=s*e+u*n-i*o,h=s*o+i*e-l*n,f=-i*n-l*e-u*o;return t[0]=M*s+f*-i+c*-u-h*-l,t[1]=c*s+f*-l+h*-i-M*-u,t[2]=h*s+f*-u+M*-l-c*-i,t[3]=a[3],t},e.forEach=function(){var t=e.create();return function(a,r,n,e,o,i){var l,u;for(r||(r=4),n||(n=0),u=e?Math.min(e*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],o(t,t,i),a[l]=t[0],a[l+1]=t[1],a[l+2]=t[2],a[l+3]=t[3];return a}}(),e.str=function(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},e.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]},e.equals=function(t,a){var r=t[0],e=t[1],o=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(e-u)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(u))&&Math.abs(o-s)<=n.EPSILON*Math.max(1,Math.abs(o),Math.abs(s))&&Math.abs(i-M)<=n.EPSILON*Math.max(1,Math.abs(i),Math.abs(M))},t.exports=e},function(t,a,r){var n=r(2),e={};e.create=function(){var t=new n.ARRAY_TYPE(2);return t[0]=0,t[1]=0,t},e.clone=function(t){var a=new n.ARRAY_TYPE(2);return a[0]=t[0],a[1]=t[1],a},e.fromValues=function(t,a){var r=new n.ARRAY_TYPE(2);return r[0]=t,r[1]=a,r},e.copy=function(t,a){return t[0]=a[0],t[1]=a[1],t},e.set=function(t,a,r){return t[0]=a,t[1]=r,t},e.add=function(t,a,r){return t[0]=a[0]+r[0],t[1]=a[1]+r[1],t},e.subtract=function(t,a,r){return t[0]=a[0]-r[0],t[1]=a[1]-r[1],t},e.sub=e.subtract,e.multiply=function(t,a,r){return t[0]=a[0]*r[0],t[1]=a[1]*r[1],t},e.mul=e.multiply,e.divide=function(t,a,r){return t[0]=a[0]/r[0],t[1]=a[1]/r[1],t},e.div=e.divide,e.ceil=function(t,a){return t[0]=Math.ceil(a[0]),t[1]=Math.ceil(a[1]),t},e.floor=function(t,a){return t[0]=Math.floor(a[0]),t[1]=Math.floor(a[1]),t},e.min=function(t,a,r){return t[0]=Math.min(a[0],r[0]),t[1]=Math.min(a[1],r[1]),t},e.max=function(t,a,r){return t[0]=Math.max(a[0],r[0]),t[1]=Math.max(a[1],r[1]),t},e.round=function(t,a){return t[0]=Math.round(a[0]),t[1]=Math.round(a[1]),t},e.scale=function(t,a,r){return t[0]=a[0]*r,t[1]=a[1]*r,t},e.scaleAndAdd=function(t,a,r,n){return t[0]=a[0]+r[0]*n,t[1]=a[1]+r[1]*n,t},e.distance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1];return Math.sqrt(r*r+n*n)},e.dist=e.distance,e.squaredDistance=function(t,a){var r=a[0]-t[0],n=a[1]-t[1];return r*r+n*n},e.sqrDist=e.squaredDistance,e.length=function(t){var a=t[0],r=t[1];return Math.sqrt(a*a+r*r)},e.len=e.length,e.squaredLength=function(t){var a=t[0],r=t[1];return a*a+r*r},e.sqrLen=e.squaredLength,e.negate=function(t,a){return t[0]=-a[0],t[1]=-a[1],t},e.inverse=function(t,a){return t[0]=1/a[0],t[1]=1/a[1],t},e.normalize=function(t,a){var r=a[0],n=a[1],e=r*r+n*n;return e>0&&(e=1/Math.sqrt(e),t[0]=a[0]*e,t[1]=a[1]*e),t},e.dot=function(t,a){return t[0]*a[0]+t[1]*a[1]},e.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},e.lerp=function(t,a,r,n){var e=a[0],o=a[1];return t[0]=e+n*(r[0]-e),t[1]=o+n*(r[1]-o),t},e.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},e.transformMat2=function(t,a,r){var n=a[0],e=a[1];return t[0]=r[0]*n+r[2]*e,t[1]=r[1]*n+r[3]*e,t},e.transformMat2d=function(t,a,r){var n=a[0],e=a[1];return t[0]=r[0]*n+r[2]*e+r[4],t[1]=r[1]*n+r[3]*e+r[5],t},e.transformMat3=function(t,a,r){var n=a[0],e=a[1];return t[0]=r[0]*n+r[3]*e+r[6],t[1]=r[1]*n+r[4]*e+r[7],t},e.transformMat4=function(t,a,r){var n=a[0],e=a[1];return t[0]=r[0]*n+r[4]*e+r[12],t[1]=r[1]*n+r[5]*e+r[13],t},e.forEach=function(){var t=e.create();return function(a,r,n,e,o,i){var l,u;for(r||(r=2),n||(n=0),u=e?Math.min(e*r+n,a.length):a.length,l=n;l<u;l+=r)t[0]=a[l],t[1]=a[l+1],o(t,t,i),a[l]=t[0],a[l+1]=t[1];return a}}(),e.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},e.exactEquals=function(t,a){return t[0]===a[0]&&t[1]===a[1]},e.equals=function(t,a){var r=t[0],e=t[1],o=a[0],i=a[1];return Math.abs(r-o)<=n.EPSILON*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(e-i)<=n.EPSILON*Math.max(1,Math.abs(e),Math.abs(i))},t.exports=e},function(t,a,r){"use strict";var n=r(12);a.Camera=n.Camera;var e=r(13);a.Light=e.Light;var o=r(14);a.Material=o.Material;var i=r(15);a.Matrix=i.Matrix;var l=r(16);a.Mesh=l.Mesh;var u=r(17);a.Scene=u.Scene;var s=r(18);a.Shader=s.Shader;var M=r(19);a.Sphere=M.Sphere;var c=r(20);a.Stack=c.Stack;var h=r(21);a.WebGLUtils=h.WebGLUtils},function(t,a,r){"use strict";var n=r(1),e=function(){function t(t,a,r,e,o,i,l){this.eye=t,this.center=a,this.up=r,this.fov=e,this.aspect=o,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=e},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,e,o){this.ambient=a,this.diffuse=r,this.specular=n,this.shine=e,this.buildTexture(t,o)}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,r){"use strict";var n=r(1),e=function(){function t(){}return t.translate=function(t,a,r){var e=n.mat4.create();return n.mat4.translate(e,n.mat4.create(),[t,a,r]),e},t.scale=function(t,a,r){var e=n.mat4.create();return n.mat4.scale(e,n.mat4.create(),[t,a,r]),e},t.scaleUniform=function(t){return this.scale(t,t,t)},t.rotateY=function(t){var a=n.mat4.create();return n.mat4.rotateY(a,n.mat4.create(),t),a},t}();a.Matrix=e},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),e=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.drawMesh=function(t,a,r,n){this.setPosition(a),this.setNormal(a),this.setTextureCoords(a),this.activateTexture(a.material),this.setUniformsSampler(),this.setUniformsModelViewMatrix(t,r),this.setUniformsNormalMatrix(t,r),this.setUniformsProjectionMatrix(r),this.setUniformsModelViewProjectionMatrix(t,r),this.setUniformsLights(n),this.setUniformsMaterials(a),this.gl.drawElements(this.gl.TRIANGLES,a.indicesCount,this.gl.UNSIGNED_SHORT,0)},t.prototype.drawScene=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.modelToWorld,a),r.setUniformsNormalMatrix(n.modelToWorld,a),r.setUniformsProjectionMatrix(a),r.setUniformsModelViewProjectionMatrix(n.modelToWorld,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),e=this.loadShader(t,t.FRAGMENT_SHADER,r);if(!n||!e)return console.log("Shader.ts: createProgram: No vertex shader or fragment shader: ",n,", ",e),null;var o=t.createProgram();if(!o)return console.log("Shader.ts: createProgram: No program: ",o),null;t.attachShader(o,n),t.attachShader(o,e),t.linkProgram(o);var i=t.getProgramParameter(o,t.LINK_STATUS);if(!i){var l=t.getProgramInfoLog(o);return console.log("Shader.ts: createProgram: Failed to link program: "+l),t.deleteProgram(o),t.deleteShader(e),t.deleteShader(n),null}return o},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 e=t.getShaderParameter(n,t.COMPILE_STATUS);if(!e){var o=t.getShaderInfoLog(n);return console.log("Shader.ts: loadShader: Failed to compile shader: "+o),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&&this.gl.uniform1i(t,0)},t.prototype.setUniformsModelViewMatrix=function(t,a){var r=n.mat4.create();n.mat4.multiply(r,a.worldToCamera,t);var e=this.gl.getUniformLocation(this.gl.program,"u_ModelViewMatrix");e&&this.gl.uniformMatrix4fv(e,!1,r);var o=n.mat4.create();n.mat4.invert(o,r);var i=this.gl.getUniformLocation(this.gl.program,"u_ModelViewMatrixInverse");i&&this.gl.uniformMatrix4fv(i,!1,o)},t.prototype.setUniformsNormalMatrix=function(t,a){var r=n.mat4.create();n.mat4.multiply(r,a.worldToCamera,t);var e=n.mat3.create();n.mat3.fromMat4(e,r);var o=this.gl.getUniformLocation(this.gl.program,"u_NormalMatrix");o&&this.gl.uniformMatrix3fv(o,!1,e)},t.prototype.setUniformsProjectionMatrix=function(t){var a=this.gl.getUniformLocation(this.gl.program,"u_ProjectionMatrix");a&&this.gl.uniformMatrix4fv(a,!1,t.cameraToClip);var r=this.gl.getUniformLocation(this.gl.program,"u_ProjectionMatrixInverse");r&&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);var e=n.mat4.create();n.mat4.multiply(e,a.cameraToClip,r);var o=this.gl.getUniformLocation(this.gl.program,"u_ModelViewProjectionMatrix");o&&this.gl.uniformMatrix4fv(o,!1,e);var i=n.mat4.create();n.mat4.invert(i,e);var l=this.gl.getUniformLocation(this.gl.program,"u_ModelViewProjectionMatrixInverse");l&&this.gl.uniformMatrix4fv(l,!1,i)},t.prototype.setUniformsLights=function(t){var a=this.gl.getUniformLocation(this.gl.program,"u_Light.position");a&&this.gl.uniform4fv(a,t.position);var r=this.gl.getUniformLocation(this.gl.program,"u_Light.ambient");r&&this.gl.uniform3fv(r,t.ambient);var n=this.gl.getUniformLocation(this.gl.program,"u_Light.diffuse");n&&this.gl.uniform3fv(n,t.diffuse);var e=this.gl.getUniformLocation(this.gl.program,"u_Light.specular");e&&this.gl.uniform3fv(e,t.specular)},t.prototype.setUniformsMaterials=function(t){var a=this.gl.getUniformLocation(this.gl.program,"u_Material.ambient");a&&this.gl.uniform3fv(a,t.material.ambient); | |
var r=this.gl.getUniformLocation(this.gl.program,"u_Material.diffuse");r&&this.gl.uniform3fv(r,t.material.diffuse);var n=this.gl.getUniformLocation(this.gl.program,"u_Material.specular");n&&this.gl.uniform3fv(n,t.material.specular);var e=this.gl.getUniformLocation(this.gl.program,"u_Material.shine");e&&this.gl.uniform1f(e,t.material.shine)},t}();a.Shader=e},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)},e=r(1),o=r(16),i=function(t){function a(a,r,n,e,o){t.call(this,r),this.radius=n,this.latitudeBands=e,this.longitudeBands=o,this.buildArrays(),this.buildBuffers(a),this.buildTransforms()}return n(a,t),a.prototype.buildArrays=function(){for(var t=[],a=[],r=[],n=[],e=0;e<=this.latitudeBands;++e)for(var o=e*Math.PI/this.latitudeBands,i=Math.sin(o),l=Math.cos(o),u=0;u<=this.longitudeBands;++u){var s=2*u*Math.PI/this.longitudeBands,M=Math.sin(s),c=Math.cos(s),h=c*i,f=l,m=M*i,x=1-u/this.longitudeBands,S=1-e/this.latitudeBands;t.push(this.radius*h),t.push(this.radius*f),t.push(this.radius*m),a.push(h),a.push(f),a.push(m),r.push(x),r.push(S)}for(var e=0;e<this.latitudeBands;++e)for(var u=0;u<this.longitudeBands;++u){var d=e*(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=e.mat4.create(),this.worldToModel=e.mat4.create(),e.mat4.invert(this.worldToModel,this.modelToWorld)},a}(o.Mesh);a.Sphere=i},function(t,a,r){"use strict";var n=r(1),e=function(){function t(){this.stack=[],this.stack.push(n.mat4.create())}return t.prototype.push=function(t){var a=n.mat4.create();n.mat4.multiply(a,this.stack[this.stack.length-1],t),this.stack.push(a)},t.prototype.pop=function(){return this.stack.pop()},t.prototype.top=function(){return this.stack[this.stack.length-1]},t}();a.Stack=e},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,e=0;e<r.length;++e){try{n=t.getContext(r[e],a)}catch(o){}if(n)break}return n},t.animate=function(t,a){function r(){var o=(new Date).getTime();t&&t((o-e)/1e3),a&&a(),n(r),e=o}var n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(t){setTimeout(t,1e3/60)},e=(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}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as glMatrix from 'gl-matrix'; | |
import { Camera, Material, Matrix, Sphere, Shader, Stack, WebGLUtils } from './src'; | |
let canvas = document.getElementById('webgl'); | |
let gl = WebGLUtils.setupWebGL(canvas, null, null); | |
let angle: number = 0; | |
let shader: Shader; | |
let camera: Camera; | |
let sun: Sphere; | |
let mercury: Sphere; | |
let venus: Sphere; | |
let earth: Sphere; | |
let mars: Sphere; | |
let jupiter: Sphere; | |
let saturn: Sphere; | |
let uranus: Sphere; | |
let neptune: Sphere; | |
let sunImage = new Image(); | |
let mercuryImage = new Image(); | |
let venusImage = new Image(); | |
let earthImage = new Image(); | |
let marsImage = new Image(); | |
let jupiterImage = new Image(); | |
let saturnImage = new Image(); | |
let uranusImage = new Image(); | |
let neptuneImage = new Image(); | |
sunImage.src = './sun.jpg'; | |
mercuryImage.src = './mercury.jpg'; | |
venusImage.src = './venus.jpg'; | |
earthImage.src = './earth.jpg'; | |
marsImage.src = './mars.jpg'; | |
jupiterImage.src = './jupiter.jpg'; | |
saturnImage.src = './saturn.jpg'; | |
uranusImage.src = './uranus.jpg'; | |
neptuneImage.src = './neptune.jpg'; | |
sunImage.onload = () => setupScene(); | |
mercuryImage.onload = () => setupScene(); | |
venusImage.onload = () => setupScene(); | |
earthImage.onload = () => setupScene(); | |
marsImage.onload = () => setupScene(); | |
jupiterImage.onload = () => setupScene(); | |
saturnImage.onload = () => setupScene(); | |
uranusImage.onload = () => setupScene(); | |
neptuneImage.onload = () => setupScene(); | |
let sunFrame = glMatrix.mat4.create(); | |
let mercuryFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.01), Matrix.translate(120.0, 0.0, 0.0)); | |
let venusFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.02), Matrix.translate(67.0, 0.0, 0.0)); | |
let earthFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.02), Matrix.translate(77.0, 0.0, 0.0)); | |
let marsFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.01), Matrix.translate(170.0, 0.0, 0.0)); | |
let jupiterFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.1), Matrix.translate(19.0, 0.0, 0.0)); | |
let saturnFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.09), Matrix.translate(24.5, 0.0, 0.0)); | |
let uranusFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.05), Matrix.translate(50.0, 0.0, 0.0)); | |
let neptuneFrame = glMatrix.mat4.multiply(glMatrix.mat4.create(), Matrix.scaleUniform(0.05), Matrix.translate(55.0, 0.0, 0.0)); | |
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() { | |
if (sunImage.complete && mercuryImage.complete && venusImage.complete && | |
earthImage.complete && marsImage.complete && jupiterImage.complete && | |
saturnImage.complete && uranusImage.complete && neptuneImage.complete) { | |
// Setup shader. | |
shader = new Shader(gl, vertexShaderSource, fragmentShaderSource); | |
// Setup camera. | |
let eye = [0.0, 3.9, 3.9]; | |
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 Planets. | |
sun = new Sphere(gl, new Material(gl, null, null, null, null, sunImage), 1, 250, 250); | |
mercury = new Sphere(gl, new Material(gl, null, null, null, null, mercuryImage), 1, 250, 250); | |
venus = new Sphere(gl, new Material(gl, null, null, null, null, venusImage), 1, 250, 250); | |
earth = new Sphere(gl, new Material(gl, null, null, null, null, earthImage), 1, 250, 250); | |
mars = new Sphere(gl, new Material(gl, null, null, null, null, marsImage), 1, 250, 250); | |
jupiter = new Sphere(gl, new Material(gl, null, null, null, null, jupiterImage), 1, 250, 250); | |
saturn = new Sphere(gl, new Material(gl, null, null, null, null, saturnImage), 1, 250, 250); | |
uranus = new Sphere(gl, new Material(gl, null, null, null, null, uranusImage), 1, 250, 250); | |
neptune = new Sphere(gl, new Material(gl, null, null, null, null, neptuneImage), 1, 250, 250); | |
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); | |
let stack = new Stack(); | |
stack.push(sunFrame); | |
stack.push(Matrix.rotateY(angle/50)); | |
shader.drawMesh(stack.top(), sun, camera, null); | |
stack.push(Matrix.rotateY(angle/5)); | |
stack.push(mercuryFrame); | |
shader.drawMesh(stack.top(), mercury, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/12)); | |
stack.push(venusFrame); | |
shader.drawMesh(stack.top(), venus, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/14)); | |
stack.push(earthFrame); | |
shader.drawMesh(stack.top(), earth, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/10)); | |
stack.push(marsFrame); | |
shader.drawMesh(stack.top(), mars, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/20)); | |
stack.push(jupiterFrame); | |
shader.drawMesh(stack.top(), jupiter, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/15)); | |
stack.push(saturnFrame); | |
shader.drawMesh(stack.top(), saturn, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/14)); | |
stack.push(uranusFrame); | |
shader.drawMesh(stack.top(), uranus, camera, null); | |
stack.pop(); | |
stack.push(Matrix.rotateY(angle/15)); | |
stack.push(neptuneFrame); | |
shader.drawMesh(stack.top(), neptune, camera, null); | |
stack.pop(); | |
stack.pop(); | |
stack.pop(); | |
stack.pop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment